:root {
  color-scheme: dark;
  --bg: #121316;
  --panel: #1b1d22;
  --raised: #272a31;
  --raised-hover: #31353d;
  --line: #33363e;
  --text: #ecebe6;
  --muted: #a0a2ab;
  --accent: #f5b83d;
  --accent-hover: #ffc95c;
  --accent-ink: #201603;
  --warn: #ffb4a0;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --panel-width: 284px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 var(--sans);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

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

svg.icon {
  display: block;
  width: 16px;
  height: 16px;
  fill: currentColor;
  shape-rendering: crispEdges;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Layout */

#app {
  display: grid;
  grid-template:
    "top top top" 52px
    "left stage right" minmax(0, 1fr)
    / var(--panel-width) minmax(0, 1fr) var(--panel-width);
  height: 100dvh;
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 14px;
  background: var(--panel);
  border-bottom: 2px solid var(--line);
}

.panel {
  background: var(--panel);
  overflow-y: auto;
  scrollbar-width: thin;
}

.panel-left {
  grid-area: left;
  border-right: 2px solid var(--line);
}

.panel-right {
  grid-area: right;
  border-left: 2px solid var(--line);
}

.panel section {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.panel section:last-child {
  border-bottom: 0;
}

h2 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.note {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.note.warning {
  color: var(--warn);
}

/* Top bar */

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.01em;
}

.brand img {
  image-rendering: pixelated;
}

.spacer {
  flex: 1;
}

.group {
  display: flex;
  gap: 6px;
}

.file-name {
  display: flex;
  align-items: center;
  height: 32px;
  padding: 0 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 12px;
}

.file-name:focus-within {
  border-color: var(--accent);
}

.file-name input {
  width: 13ch;
  padding: 0;
  background: none;
  border: 0;
  outline: 0;
  text-align: right;
}

.file-ext {
  color: var(--muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 32px;
  padding: 0 12px;
  background: var(--raised);
  border: 1px solid var(--line);
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  background: var(--raised-hover);
}

.btn:disabled {
  color: #63666e;
  cursor: default;
}

.btn-icon {
  width: 32px;
  padding: 0;
}

.btn-small {
  height: 26px;
  padding: 0 10px;
  font-size: 12px;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.menu-wrap {
  position: relative;
}

.menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  left: 0;
  min-width: 170px;
  background: var(--raised);
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgb(0 0 0 / 50%);
}

.menu button {
  display: block;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: 0;
  text-align: left;
}

.menu button:hover,
.menu button:focus-visible {
  background: var(--raised-hover);
}

.segmented {
  display: flex;
  align-items: center;
}

.segmented-label {
  margin-right: 8px;
  color: var(--muted);
}

.segmented button {
  height: 32px;
  padding: 0 12px;
  background: var(--raised);
  border: 1px solid var(--line);
  margin-left: -1px;
}

.segmented button:first-of-type {
  margin-left: 0;
}

.segmented button:hover {
  background: var(--raised-hover);
}

.segmented button[aria-pressed="true"] {
  position: relative;
  background: var(--text);
  border-color: var(--text);
  color: #17181b;
  font-weight: 600;
}

/* Tools */

.tools {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 9px 0 6px;
  background: var(--raised);
  border: 1px solid var(--line);
  font-size: 11px;
}

.tool svg.icon {
  width: 24px;
  height: 24px;
}

.tool:hover {
  background: var(--raised-hover);
}

.tool[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

.toggles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 6px;
}

.toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 32px;
  background: none;
  border: 1px solid var(--line);
  color: var(--muted);
}

.toggle:hover {
  background: var(--raised);
  color: var(--text);
}

.toggle[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

/* Body parts */

.parts {
  display: flex;
  gap: 16px;
}

.figure {
  flex: none;
  display: grid;
  grid-template-columns: repeat(4, 15px);
  grid-template-rows: 32px 48px 48px;
  gap: 1px;
  grid-template-areas:
    ". head head ."
    "rightArm body body leftArm"
    ". rightLeg leftLeg .";
}

.figure button {
  padding: 0;
  background: #686c76;
  border: 0;
}

.figure button:hover {
  background: #8b8f9a;
}

.figure button[aria-pressed="false"] {
  background: repeating-linear-gradient(45deg, var(--raised) 0 3px, var(--panel) 3px 6px);
  outline: 1px dashed var(--line);
  outline-offset: -1px;
}

.parts-side {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.parts-side p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

/* Flat skin map: 4 screen pixels per skin pixel, so it scales evenly. */

.skin-map {
  position: relative;
  width: 256px;
  height: 256px;
  background: repeating-conic-gradient(#3b3e46 0% 25%, #2e3037 0% 50%) 0 0 / 8px 8px;
  cursor: crosshair;
  touch-action: none;
}

.skin-map canvas,
.skin-map svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.skin-map canvas {
  image-rendering: pixelated;
}

.skin-map .unused {
  fill: var(--panel);
}

.skin-map .face {
  fill: none;
  stroke-width: 1px;
  vector-effect: non-scaling-stroke;
}

.skin-map .face-base {
  stroke: rgb(255 255 255 / 22%);
}

.skin-map .face-overlay {
  stroke: rgb(245 184 61 / 32%);
}

.skin-map .marker {
  fill: none;
  stroke: #fff;
  stroke-width: 1.5px;
  vector-effect: non-scaling-stroke;
  paint-order: stroke;
  filter: drop-shadow(0 0 1px #000);
}

.skin-map .marker-mirror {
  stroke-dasharray: 2 2;
}

/* Stage */

.stage {
  grid-area: stage;
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

#viewport {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline-offset: -3px;
}

#viewport[data-cursor="paint"] {
  cursor: crosshair;
}

#viewport[data-cursor="orbit"] {
  cursor: grab;
}

#viewport[data-cursor="dragging"] {
  cursor: grabbing;
}

.readout {
  position: absolute;
  top: 12px;
  left: 14px;
  font: 12px/1.5 var(--mono);
  color: var(--text);
  text-shadow: 0 1px 2px rgb(0 0 0 / 80%);
  pointer-events: none;
}

.layer-switch {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 5px 5px 12px;
  background: rgb(27 29 34 / 92%);
  border: 1px solid var(--line);
}

.layer-label {
  color: var(--muted);
  white-space: nowrap;
}

.layer-switch .segmented button {
  height: 28px;
  min-width: 60px;
}

.layer-switch .segmented button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.eye {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  background: none;
  border: 1px solid transparent;
  color: var(--text);
}

.eye:hover {
  background: var(--raised);
}

.eye[aria-pressed="false"] {
  color: #6c6f78;
  background: linear-gradient(to top right, transparent 47%, currentColor 47% 53%, transparent 53%);
}

.hints {
  position: absolute;
  left: 14px;
  bottom: 12px;
  max-width: min(40%, 300px);
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 12px;
  color: #b9bbc3;
  text-shadow: 0 1px 2px rgb(0 0 0 / 80%);
  pointer-events: none;
}

.hints b {
  font-weight: 600;
  color: var(--text);
}

.views {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 1px;
  max-width: 55%;
}

.views button {
  height: 28px;
  padding: 0 9px;
  background: rgb(27 29 34 / 92%);
  border: 1px solid var(--line);
  font-size: 12px;
}

.views button:hover {
  background: var(--raised-hover);
}

.views button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.toast {
  position: absolute;
  z-index: 10;
  left: 50%;
  bottom: 108px;
  transform: translateX(-50%);
  width: max-content;
  max-width: min(90%, 460px);
  padding: 9px 14px;
  background: var(--text);
  color: #17181b;
  font-weight: 500;
  box-shadow: 0 6px 20px rgb(0 0 0 / 45%);
}

.toast.error {
  background: #ffcfc4;
  color: #3c0d03;
}

/* Color */

.sv {
  position: relative;
  height: 148px;
  cursor: crosshair;
  touch-action: none;
  background:
    linear-gradient(to top, #000, transparent),
    linear-gradient(to right, #fff, hsl(var(--hue, 0) 100% 50%));
}

.sv-thumb {
  position: absolute;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px #000;
  pointer-events: none;
}

.hue {
  position: relative;
  height: 16px;
  margin-top: 8px;
  cursor: ew-resize;
  touch-action: none;
  background: linear-gradient(to right, #f00, #ff0 16.67%, #0f0 33.33%, #0ff 50%, #00f 66.67%, #f0f 83.33%, #f00);
}

.hue-thumb {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 6px;
  margin-left: -3px;
  background: #fff;
  box-shadow: 0 0 0 1px #000;
  pointer-events: none;
}

.color-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.current-color {
  flex: none;
  width: 56px;
  height: 32px;
  border: 1px solid rgb(255 255 255 / 25%);
}

.hex {
  flex: 1;
}

.hex input {
  width: 100%;
  height: 32px;
  padding: 0 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  font-family: var(--mono);
  outline: 0;
}

.hex input:focus {
  border-color: var(--accent);
}

.hex input.invalid {
  border-color: var(--warn);
}

.shades {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-top: 8px;
}

.shades button {
  height: 24px;
  padding: 0;
  border: 0;
}

.shades button:hover {
  position: relative;
  z-index: 1;
  outline: 2px solid #fff;
  outline-offset: -2px;
}

.swatches {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}

.swatches button {
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid rgb(255 255 255 / 12%);
}

.swatches button:hover {
  outline: 2px solid #fff;
  outline-offset: 0;
}

.swatches button[aria-pressed="true"] {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Full-window states */

.drop-veil,
.fatal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgb(10 11 13 / 80%);
}

.drop-veil {
  pointer-events: none;
  font-size: 20px;
  font-weight: 600;
}

.drop-veil > div {
  padding: 32px 48px;
  border: 2px dashed var(--accent);
  background: var(--panel);
}

.fatal {
  background: var(--bg);
  padding: 24px;
}

.fatal > div {
  max-width: 460px;
}

.fatal h1 {
  margin: 0 0 8px;
  font-size: 20px;
}

.fatal pre {
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-family: var(--mono);
  overflow-x: auto;
}

/* Narrow windows: the viewport on top, panels scroll beneath it. */

@media (max-width: 1000px) {
  body {
    overflow: auto;
  }

  #app {
    grid-template:
      "top top" auto
      "stage stage" 62dvh
      "left right" auto
      / var(--panel-width) minmax(var(--panel-width), 1fr);
    height: auto;
    min-height: 100dvh;
    min-width: 568px;
  }

  .topbar {
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 8px 14px;
  }

  .panel {
    overflow: visible;
  }

  .hints {
    display: none;
  }

  .views {
    max-width: none;
    left: 12px;
  }
}

@media (max-width: 600px) {
  #app {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  .stage {
    flex: none;
    order: 1;
    height: 62dvh;
  }

  .panel {
    order: 2;
    border: 0;
    border-top: 2px solid var(--line);
  }

  .layer-label {
    display: none;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .toast {
    animation: toast-in 140ms ease-out;
  }

  @keyframes toast-in {
    from {
      opacity: 0;
      transform: translate(-50%, -6px);
    }
  }
}
