:root {
  color-scheme: dark;
  --bg: #11100f;
  --panel: #191816;
  --panel-raised: #201f1c;
  --control: #282622;
  --control-hover: #34312b;
  --line: #302e29;
  --line-bright: #454139;
  --text: #f3efe6;
  --muted: #99938a;
  --accent: #f5b94c;
  --accent-hover: #ffc965;
  --accent-ink: #241603;
  --danger: #ff6b5e;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app-header {
  position: relative;
  z-index: 10;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 16px 0 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.topbar-identity,
.header-actions,
.brand,
.icon-button--brand {
  display: flex;
  align-items: center;
}

.topbar-identity {
  min-width: 0;
  gap: 10px;
}

.brand {
  min-width: 0;
  gap: 9px;
  color: inherit;
  text-decoration: none;
}

.brand h1 {
  overflow: hidden;
  margin: 0;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.02em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-mark {
  width: 34px;
  height: 34px;
  object-fit: contain;
  image-rendering: pixelated;
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
}

.header-actions {
  gap: 6px;
}

.header-divider {
  width: 1px;
  height: 20px;
  margin: 0 5px;
  background: var(--line-bright);
}

.icon-action,
.zoom-button,
.tool-button,
.secondary-button,
.primary-button,
.panel-button {
  border: 0;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease, opacity 120ms ease, transform 120ms ease;
}

.icon-action {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 7px;
  background: transparent;
}

.icon-action:hover:not(:disabled),
.zoom-button:hover,
.tool-button:hover {
  background: var(--control-hover);
}

.icon-action:disabled {
  cursor: default;
  opacity: 0.28;
}

.icon-button--brand {
  width: auto;
  gap: 5px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 600;
}

.icon-button--brand svg {
  width: 16px;
  height: 16px;
}

.settings-toggle {
  display: none;
}

.icon-action svg,
.tool-button svg,
.secondary-button svg,
.primary-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.secondary-button,
.primary-button {
  min-width: 0;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 14px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 650;
}

.secondary-button {
  background: var(--control);
}

.secondary-button:hover {
  background: var(--control-hover);
}

.primary-button {
  background: var(--accent);
  color: var(--accent-ink);
}

.primary-button:hover {
  background: var(--accent-hover);
}

.primary-button:active,
.secondary-button:active,
.panel-button:active,
.tool-button:active,
.icon-action:active {
  transform: translateY(1px);
}

.app-shell {
  height: calc(100% - 58px);
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr) 276px;
}

.panel {
  position: relative;
  z-index: 5;
  background: var(--panel);
}

.tools-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-right: 1px solid var(--line);
}

.tool-list,
.panel-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
}

.tool-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}

.tool-button.is-active {
  background: var(--accent);
  color: var(--accent-ink);
}

.color-control {
  position: relative;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.color-control::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px #000;
  pointer-events: none;
}

.color-control input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.color-swatch {
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #f5b94c;
}

.checker-toggle span {
  width: 18px;
  height: 18px;
  border: 1px solid var(--line-bright);
  border-radius: 4px;
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #aaa 25%, transparent 25%),
    linear-gradient(-45deg, #aaa 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #aaa 75%),
    linear-gradient(-45deg, transparent 75%, #aaa 75%);
  background-position: 0 0, 0 5px, 5px -5px, -5px 0;
  background-size: 10px 10px;
}

.workspace {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) 34px;
  background: #12110f;
}

.canvas-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: auto;
  padding: 54px;
  background:
    radial-gradient(circle at 50% 45%, rgb(74 63 43 / 0.13), transparent 48%),
    #12110f;
  scrollbar-color: var(--line-bright) transparent;
  scrollbar-width: thin;
}

.canvas-wrap {
  --cell: 16px;
  --checker: 12px;
  position: relative;
  flex: none;
  width: 512px;
  height: 512px;
  overflow: hidden;
  background-color: #eeeae1;
  background-image:
    linear-gradient(45deg, #c9c5bc 25%, transparent 25%),
    linear-gradient(-45deg, #c9c5bc 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #c9c5bc 75%),
    linear-gradient(-45deg, transparent 75%, #c9c5bc 75%);
  background-position: 0 0, 0 var(--checker), var(--checker) calc(-1 * var(--checker)), calc(-1 * var(--checker)) 0;
  background-size: calc(var(--checker) * 2) calc(var(--checker) * 2);
  box-shadow: 0 18px 58px rgb(0 0 0 / 0.48), 0 0 0 1px #000;
  touch-action: none;
  user-select: none;
}

.canvas-wrap.is-dark-bg {
  background-color: #292825;
  background-image:
    linear-gradient(45deg, #1e1d1b 25%, transparent 25%),
    linear-gradient(-45deg, #1e1d1b 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1e1d1b 75%),
    linear-gradient(-45deg, transparent 75%, #1e1d1b 75%);
}

#paintCanvas,
.pixel-grid {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

#paintCanvas {
  cursor: crosshair;
}

.pixel-grid {
  z-index: 2;
  background-image:
    linear-gradient(to right, rgb(20 18 15 / 0.25) 1px, transparent 1px),
    linear-gradient(to bottom, rgb(20 18 15 / 0.25) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
  pointer-events: none;
}

.pixel-grid.is-hidden {
  display: none;
}

.statusbar {
  display: grid;
  grid-template-columns: 1fr auto auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 0 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.status-center {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.intro-seo {
  margin: 0;
  color: var(--muted);
  font-size: 10px;
}

.intro-seo a {
  color: inherit;
}

.intro-seo a:hover {
  color: var(--accent);
}

.zoom-control {
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 2px;
}

.zoom-control span {
  width: 48px;
  text-align: center;
}

.zoom-button {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
}

.settings-panel {
  overflow-y: auto;
  border-left: 1px solid var(--line);
  scrollbar-color: var(--line-bright) transparent;
  scrollbar-width: thin;
}

.settings-section {
  padding: 19px 18px;
  border-bottom: 1px solid var(--line);
}

.settings-section h2 {
  margin: 0 0 15px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.section-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.color-section-title output {
  color: var(--muted);
  font-size: 9px;
  font-variant-numeric: tabular-nums;
}

.field-label {
  display: block;
  margin: 13px 0 7px;
  color: var(--muted);
  font-size: 10px;
}

.settings-section > .field-label:first-of-type {
  margin-top: 0;
}

.field-select,
.export-fields input,
.export-fields select,
.new-document-fields input {
  width: 100%;
  height: 35px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 10px;
  background: var(--control);
  color: var(--text);
  font-size: 11px;
}

.dimension-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.dimension-row > label > span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 10px;
}

.input-with-suffix {
  height: 35px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--control);
}

.input-with-suffix:focus-within {
  border-color: var(--accent);
}

.input-with-suffix input {
  min-width: 0;
  flex: 1;
  border: 0;
  outline: 0;
  padding: 0 1px 0 9px;
  background: transparent;
  color: var(--text);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.input-with-suffix span {
  padding-right: 8px;
  color: var(--muted);
  font-size: 10px;
}

.panel-button {
  width: 100%;
  height: 35px;
  margin-top: 12px;
  border: 1px solid var(--line-bright);
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font-size: 11px;
  font-weight: 650;
}

.panel-button:hover {
  background: var(--control-hover);
}

.color-palette {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 5px;
  margin-top: 12px;
}

.palette-color {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid rgb(255 255 255 / 0.09);
  border-radius: 4px;
  background: var(--swatch);
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.08);
  cursor: pointer;
}

.palette-color:hover {
  z-index: 1;
  transform: scale(1.13);
}

.palette-color.is-active::after {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1.5px solid #fff;
  border-radius: 1px;
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.75);
}

.range-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  align-items: center;
  gap: 10px;
}

.range-row output {
  color: var(--muted);
  font-size: 10px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  height: 18px;
  margin: 0;
  appearance: none;
  background: transparent;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--accent) 0 var(--range-fill, 0%), var(--line-bright) var(--range-fill, 0%));
}

input[type="range"]::-webkit-slider-thumb {
  width: 12px;
  height: 12px;
  margin-top: -4.5px;
  appearance: none;
  border: 2px solid var(--panel);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

input[type="range"]::-moz-range-track {
  height: 3px;
  border-radius: 2px;
  background: var(--line-bright);
}

input[type="range"]::-moz-range-progress {
  height: 3px;
  background: var(--accent);
}

input[type="range"]::-moz-range-thumb {
  width: 10px;
  height: 10px;
  border: 2px solid var(--panel);
  border-radius: 50%;
  background: var(--accent);
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 15px;
  cursor: pointer;
}

.switch-row--first {
  margin-top: 0;
}

.switch-row > span {
  min-width: 0;
}

.switch-row strong,
.switch-row small {
  display: block;
}

.switch-row strong {
  font-size: 11px;
  font-weight: 600;
}

.switch-row small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.35;
}

.switch-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-row i {
  position: relative;
  width: 32px;
  height: 18px;
  flex: none;
  border-radius: 9px;
  background: var(--line-bright);
  transition: background 130ms ease;
}

.switch-row i::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #aaa;
  transition: transform 130ms ease, background 130ms ease;
}

.switch-row input:checked + i {
  background: var(--accent);
}

.switch-row input:checked + i::after {
  background: var(--accent-ink);
  transform: translateX(14px);
}

.switch-row input:focus-visible + i {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.modal-dialog {
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line-bright);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 24px 90px rgb(0 0 0 / 0.75);
}

.modal-dialog::backdrop {
  background: rgb(0 0 0 / 0.72);
  backdrop-filter: blur(5px);
}

.modal-dialog form {
  padding: 20px;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
}

.dialog-header h2 {
  margin: 0;
  font-size: 16px;
}

.dialog-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.dialog-header .icon-action {
  flex: none;
  margin: -7px -7px 0 0;
}

.new-document-fields {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 10px;
  margin-top: 22px;
}

.new-document-fields > span {
  padding-bottom: 9px;
  color: var(--muted);
}

.new-document-fields label > span,
.export-fields label > span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 10px;
}

.export-preview {
  height: 184px;
  display: grid;
  place-items: center;
  margin: 20px 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 9px;
  background-color: #292825;
  background-image:
    linear-gradient(45deg, #1e1d1b 25%, transparent 25%),
    linear-gradient(-45deg, #1e1d1b 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1e1d1b 75%),
    linear-gradient(-45deg, transparent 75%, #1e1d1b 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

.export-preview canvas {
  max-width: 156px;
  max-height: 156px;
  image-rendering: pixelated;
  box-shadow: 0 7px 22px rgb(0 0 0 / 0.35);
}

.export-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.export-note {
  display: grid;
  gap: 4px;
  margin-top: 14px;
  padding: 11px 12px;
  border: 1px solid rgb(245 185 76 / 0.25);
  border-radius: 7px;
  background: rgb(245 185 76 / 0.06);
}

.export-note strong {
  color: var(--accent);
  font-size: 10px;
}

.export-note span {
  color: var(--muted);
  font-size: 9px;
  line-height: 1.45;
}

.dialog-action {
  width: 100%;
  height: 40px;
  margin-top: 18px;
}

.dialog-action span {
  opacity: 0.6;
  font-size: 10px;
}

.toast {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: 48px;
  padding: 9px 13px;
  border: 1px solid var(--line-bright);
  border-radius: 7px;
  background: #25231f;
  color: var(--text);
  box-shadow: 0 8px 30px rgb(0 0 0 / 0.4);
  font-size: 11px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 880px) {
  .app-shell {
    grid-template-columns: 54px minmax(0, 1fr);
  }

  .settings-panel {
    position: fixed;
    z-index: 12;
    top: 58px;
    right: 0;
    bottom: 0;
    width: 260px;
    box-shadow: -10px 0 30px rgb(0 0 0 / 0.35);
    opacity: 0;
    pointer-events: none;
    transform: translateX(102%);
    transition: transform 160ms ease, opacity 160ms ease;
  }

  .settings-panel.is-open {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0);
  }

  .settings-toggle {
    display: grid;
  }

  .workspace {
    grid-column: 2;
  }

  .status-center {
    display: none;
  }

  .statusbar {
    grid-template-columns: 1fr auto 1fr;
  }
}

@media (max-width: 640px) {
  .intro-seo,
  .header-divider,
  #importButton {
    display: none;
  }

  .app-shell {
    grid-template-columns: 52px minmax(0, 1fr);
  }

  .app-header {
    padding-inline: 10px;
  }

  .secondary-button,
  .primary-button {
    padding: 0 10px;
  }

  .canvas-stage {
    padding: 28px;
  }

  .statusbar {
    grid-template-columns: 1fr auto;
  }
}

@media (max-width: 430px) {
  .brand h1,
  #newButton {
    display: none;
  }

  .brand-mark {
    width: 30px;
    height: 30px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
