/* ============================================================
   BLOCKPIC

   A quiet, precise tool. The backdrop is a soft, blurred wash of
   matcha green and brown behind a mostly-white surface layer —
   two blurred colour blobs (::before on <body>) sitting under
   glass panels, rather than a flat fill. Both light and dark
   themes carry the same green+brown identity, just at different
   depths, so the motif holds regardless of which one resolves.

   Themes: dark is the default. Light is applied by
   [data-theme="light"] on <html>, or by the OS preference when
   the visitor has not chosen. Every colour is defined on plain
   :root first, so nothing depends on a media query resolving.
   ============================================================ */

/* Self-hosted so no third party is told who visits.
   Sora — SIL Open Font License 1.1, © the Sora Project Authors. */
@font-face {
  font-family: 'Sora';
  src: url('../fonts/sora-latin.woff2') format('woff2');
  font-weight: 100 800;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Sora';
  src: url('../fonts/sora-latin-ext.woff2') format('woff2');
  font-weight: 100 800;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  /* Deep, muted matcha-and-brown, seen through the dark theme's glass. */
  --bg: #14150f;
  --surface: rgba(32, 34, 25, 0.82);
  --surface-2: rgba(42, 44, 33, 0.9);
  --sunken: #101108;
  --line: rgba(232, 236, 220, 0.08);
  --line-strong: rgba(232, 236, 220, 0.17);

  --text: #edeee4;
  --text-2: #aeb29f;
  --text-3: #80846f;

  /* Oak brown — the primary accent (buttons, selections, links). */
  --accent: #c99863;
  --accent-hover: #dbaa76;
  --on-accent: #1a1109;
  --accent-soft: rgba(201, 152, 99, 0.15);
  /* A brighter tungsten amber, reserved for the light-dial's bulb — a
     second, distinguishable warm tone rather than a repeat of --accent. */
  --highlight: #ffb84d;
  --highlight-glow: rgba(255, 184, 77, 0.45);
  --danger: #d9705a;
  --danger-soft: rgba(217, 112, 90, 0.15);

  --shadow-panel: 0 24px 60px -32px rgba(0, 0, 0, 0.9);
  --shadow-stage: 0 40px 90px -30px rgba(0, 0, 0, 0.85);
  --shadow-pop: 0 24px 60px rgba(0, 0, 0, 0.6);

  /* The blurred backdrop blobs — see body::before below. Independent of
     --accent/--highlight above: the wash stays matcha green + brown even
     though the buttons themselves are brown. */
  --blob-a: rgba(94, 122, 74, 0.55);
  --blob-b: rgba(122, 88, 54, 0.42);
  --blob-c: rgba(94, 122, 74, 0.30);
  --blob-d: rgba(122, 88, 54, 0.26);

  --radius-lg: 14px;
  --radius: 10px;
  --radius-sm: 7px;
  --header-h: 56px;

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --dur-press: 120ms;
  --dur-fast: 140ms;
  --dur-mid: 200ms;

  --font: 'Sora', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  color-scheme: dark;
}

/* Light theme — same matcha-and-brown identity, seen against near-white
   instead of near-black. Declared twice on purpose: once for an explicit
   choice, once for "no choice yet, follow the OS". */
:root[data-theme="light"] {
  --bg: #f4f1e6;
  --surface: rgba(255, 255, 255, 0.78);
  --surface-2: rgba(255, 255, 255, 0.9);
  --sunken: #eeece3;
  --line: rgba(40, 44, 30, 0.09);
  --line-strong: rgba(40, 44, 30, 0.18);

  --text: #23261d;
  --text-2: #565a4b;
  --text-3: #7c8070;

  --accent: #8a5c33;
  --accent-hover: #6e4826;
  --on-accent: #fffaf3;
  --accent-soft: rgba(138, 92, 51, 0.12);
  --highlight: #9c6b3f;
  --highlight-glow: rgba(156, 107, 63, 0.32);
  --danger: #b8442c;
  --danger-soft: rgba(184, 68, 44, 0.10);

  --shadow-panel: 0 20px 44px -30px rgba(46, 44, 18, 0.28);
  --shadow-stage: 0 30px 70px -34px rgba(46, 44, 18, 0.26);
  --shadow-pop: 0 24px 60px rgba(46, 44, 18, 0.2);

  /* Stronger than the dark theme's blobs, not weaker — a "too white" light
     wash needs more pigment, not less, to read as coloured rather than
     tinted-white. */
  --blob-a: rgba(112, 150, 92, 0.62);
  --blob-b: rgba(168, 122, 76, 0.54);
  --blob-c: rgba(112, 150, 92, 0.40);
  --blob-d: rgba(168, 122, 76, 0.36);

  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f1e6;
    --surface: rgba(255, 255, 255, 0.78);
    --surface-2: rgba(255, 255, 255, 0.9);
    --sunken: #eeece3;
    --line: rgba(40, 44, 30, 0.09);
    --line-strong: rgba(40, 44, 30, 0.18);

    --text: #23261d;
    --text-2: #565a4b;
    --text-3: #7c8070;

    --accent: #8a5c33;
    --accent-hover: #6e4826;
    --on-accent: #fffaf3;
    --accent-soft: rgba(138, 92, 51, 0.12);
    --highlight: #9c6b3f;
    --highlight-glow: rgba(156, 107, 63, 0.32);
    --danger: #b8442c;
    --danger-soft: rgba(184, 68, 44, 0.10);

    --shadow-panel: 0 20px 44px -30px rgba(46, 44, 18, 0.28);
    --shadow-stage: 0 30px 70px -34px rgba(46, 44, 18, 0.26);
    --shadow-pop: 0 24px 60px rgba(46, 44, 18, 0.2);

    --blob-a: rgba(112, 150, 92, 0.62);
    --blob-b: rgba(168, 122, 76, 0.54);
    --blob-c: rgba(112, 150, 92, 0.40);
    --blob-d: rgba(168, 122, 76, 0.36);

    color-scheme: light;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* Author styles beat the UA stylesheet regardless of specificity, so any
   rule like `.inspector { display: flex }` silently defeats the `hidden`
   attribute. Several things here are toggled with `hidden` (both
   inspectors, both preview hints), so this makes it win everywhere once
   instead of needing a per-component override each time. */
[hidden] { display: none !important; }

/* Only html carries a solid background (the canvas fallback). body itself
   must stay transparent: body's own in-flow background paints ABOVE a
   negative-z-index ::before in the stacking order, so a solid colour here
   would blot the blurred blobs out completely rather than sitting behind
   them. */
html {
  height: 100%;
  background: var(--bg);
}
body {
  min-height: 100%;
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: color var(--dur-mid) var(--ease-out);
}

/* The backdrop: two soft, blurred colour blobs (matcha green + brown)
   fixed behind everything. A single static blur — not animated — so it
   costs one paint, not a running one. Panels sit on top of this as glass
   (see .inspector, .modal, .cookie-notice, .doc-lead), so the wash reads
   through their edges rather than living only at the page margins. */
body::before {
  content: '';
  position: fixed;
  inset: -12%;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(circle at 12% 15%, var(--blob-a) 0%, transparent 62%),
    radial-gradient(circle at 88% 8%, var(--blob-b) 0%, transparent 58%),
    radial-gradient(circle at 20% 92%, var(--blob-d) 0%, transparent 62%),
    radial-gradient(circle at 92% 88%, var(--blob-c) 0%, transparent 58%),
    radial-gradient(circle at 55% 50%, var(--blob-c) 0%, transparent 66%);
  filter: blur(72px);
  transition: opacity var(--dur-mid) var(--ease-out);
}
@media (prefers-reduced-transparency: reduce) {
  body::before { display: none; }
}

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }

::selection { background: var(--accent); color: var(--on-accent); }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 10px; }

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

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

.skip-link {
  position: absolute;
  top: 8px; left: 8px;
  z-index: 500;
  padding: 9px 14px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transform: translateY(-150%);
  transition: transform var(--dur-mid) var(--ease-out);
}
.skip-link:focus { transform: translateY(0); color: var(--on-accent); }

/* ============================================================
   TOPBAR
   ============================================================ */
/* No background and no bottom border: the blurred green/brown backdrop
   (body::before) runs unbroken from the very top of the page, so the bar
   reads as floating controls rather than a separate band. Three columns
   with equal outer tracks keep the mode switch optically centred no matter
   how wide the wordmark or the action buttons get. */
.topbar {
  height: var(--header-h);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: transparent;
  position: sticky;
  top: 0;
  z-index: 50;
}

.wordmark {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  white-space: nowrap;
  justify-self: start;
}

/* The two-mode switch is the top bar's main job now — it replaces what used
   to be a branded wordmark header. */
.mode-switch {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
}
.mode-tab {
  padding: 7px 16px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-2);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.mode-tab.active { background: var(--accent); color: var(--on-accent); }
@media (hover: hover) and (pointer: fine) {
  .mode-tab:not(.active):hover { color: var(--text); }
}

.topbar-actions { display: flex; align-items: center; gap: 8px; justify-self: end; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn-primary, .btn-secondary, .btn-quiet, .btn-ghost, .btn-danger, .icon-btn, .dropzone,
.pose-btn, .style-btn {
  font-family: var(--font);
  cursor: pointer;
  border: 1px solid transparent;
  transition:
    background-color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    transform var(--dur-press) var(--ease-out);
}
.btn-primary:active, .btn-secondary:active, .btn-quiet:active, .btn-ghost:active,
.btn-danger:active, .icon-btn:active, .pose-btn:active, .style-btn:active,
.dropzone:active { transform: scale(0.97); }

.btn-primary {
  padding: 12px 18px;
  background: var(--accent);
  color: var(--on-accent);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn-secondary {
  padding: 9px 14px;
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}
.btn-secondary.active { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.btn-quiet {
  padding: 9px 14px;
  background: transparent;
  border-color: var(--line);
  color: var(--text-2);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}
.btn-ghost {
  padding: 8px 12px;
  background: transparent;
  border-color: var(--line);
  color: var(--text-2);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 500;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
/* Buy Me a Coffee's own yellow — a fixed brand colour, not a theme token,
   so it reads as "their button" the same way in both light and dark. */
.coffee-link {
  background: #ffdd00;
  border-color: #ffdd00;
  color: #1a1109;
  font-weight: 600;
}
@media (hover: hover) and (pointer: fine) {
  .coffee-link:hover { background: #ffe94d; border-color: #ffe94d; color: #1a1109; }
}
.btn-danger {
  padding: 11px 16px;
  background: var(--danger);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
}
.btn-link {
  background: none;
  border: none;
  padding: 0 2px;
  color: var(--accent);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.block { width: 100%; }
.btn-quiet.block, .btn-danger.block, .btn-primary.block { display: flex; justify-content: center; }
.modal .block + .block { margin-top: 8px; }

.icon-btn {
  width: 34px; height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border-color: var(--line);
  border-radius: var(--radius-sm);
  color: var(--text-2);
}
/* One button, two glyphs: show the one that describes the destination. */
.icon-btn .icon-moon { display: none; }
:root[data-theme="light"] .icon-btn .icon-sun { display: none; }
:root[data-theme="light"] .icon-btn .icon-moon { display: block; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .icon-btn .icon-sun { display: none; }
  :root:not([data-theme="dark"]) .icon-btn .icon-moon { display: block; }
}

@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover { background: var(--accent-hover); }
  .btn-secondary:hover { border-color: var(--line-strong); }
  .btn-quiet:hover { border-color: var(--line-strong); color: var(--text); }
  .btn-ghost:hover { border-color: var(--line-strong); color: var(--text); }
  .btn-danger:hover { filter: brightness(1.08); }
  .icon-btn:hover { border-color: var(--line-strong); color: var(--text); }
}

/* ============================================================
   WORKSPACE
   ============================================================ */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 372px;
  gap: 18px;
  padding: 18px;
  max-width: 1680px;
  margin: 0 auto;
  height: calc(100vh - var(--header-h));
  height: calc(100dvh - var(--header-h));
}

.stage {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  container-type: size;
}

.preview-panel {
  width: min(100%, 820px);
  width: min(100%, 100cqh, 820px);
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  overflow: hidden;
  box-shadow: var(--shadow-stage);
}
.preview-frame {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--sunken);
}
/* With a transparent background the WebGL canvas really is cleared to
   nothing, so this shows through it — the usual checkerboard for "there is
   nothing here", which is exactly what the exported PNG will contain. */
.preview-frame.transparent-bg {
  background:
    linear-gradient(45deg, rgba(128, 128, 128, 0.28) 25%, transparent 25%) 0 0 / 24px 24px,
    linear-gradient(-45deg, rgba(128, 128, 128, 0.28) 25%, transparent 25%) 0 0 / 24px 24px,
    linear-gradient(45deg, transparent 75%, rgba(128, 128, 128, 0.28) 75%) 0 0 / 24px 24px,
    linear-gradient(-45deg, transparent 75%, rgba(128, 128, 128, 0.28) 75%) 0 0 / 24px 24px,
    #f2f2f0;
}

#viewport {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}
#viewport:active { cursor: grabbing; }

.preview-hint {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 14px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(15, 16, 18, 0.66);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.10);
  color: rgba(255, 255, 255, 0.72);
  font-size: 11px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0.8;
  transition: opacity var(--dur-mid) var(--ease-out);
}
.preview-frame:hover .preview-hint { opacity: 1; }
.preview-hint kbd {
  font-family: var(--font);
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  padding: 1px 5px;
  margin-right: 5px;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--sunken);
  color: var(--text-3);
  font-size: 13px;
  transition: opacity var(--dur-mid) var(--ease-out), visibility var(--dur-mid) var(--ease-out);
}
.loading-overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.loading-spinner { display: flex; gap: 6px; }
.loading-spinner span {
  width: 10px; height: 10px;
  background: var(--accent);
  border-radius: 2px;
  animation: block-bounce 0.9s ease-in-out infinite;
}
.loading-spinner span:nth-child(2) { animation-delay: 0.12s; }
.loading-spinner span:nth-child(3) { animation-delay: 0.24s; }
@keyframes block-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.35; }
  40% { transform: translateY(-7px); opacity: 1; }
}

/* ============================================================
   INSPECTOR
   ============================================================ */
.inspector {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-panel);
  overflow: hidden;
}
.inspector-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px;
}

.section + .section {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}
.section-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 14px;
}

.field + .field { margin-top: 16px; }
.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
}
.field-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-3);
  margin-bottom: 9px;
}
.field-head .field-label { margin-bottom: 0; }
.help { font-size: 11.5px; line-height: 1.45; color: var(--text-3); margin-top: 7px; }
.dial-readout { text-align: center; font-variant-numeric: tabular-nums; min-height: 1.45em; }

/* ---------- Inputs ---------- */
.text-input {
  padding: 10px 12px;
  background: var(--sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13.5px;
  font-family: var(--font);
  outline: none;
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.text-input::placeholder { color: var(--text-3); }
.text-input:focus-visible { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.text-input:disabled { opacity: 0.5; cursor: not-allowed; }
.text-input.block { width: 100%; }
select.text-input { width: 100%; cursor: pointer; }

.input-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.input-row .text-input { flex: 1; min-width: 110px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  color: var(--text-3);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }

.dropzone {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 94px;
  padding: 16px 12px;
  text-align: center;
  background: var(--sunken);
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--text-3);
  font-size: 12.5px;
  line-height: 1.45;
}
.dropzone small { display: block; font-size: 11px; opacity: 0.8; margin-top: 2px; }
.dropzone strong { color: var(--text); font-weight: 600; }
.dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
@media (hover: hover) and (pointer: fine) {
  .dropzone:hover { border-color: var(--line-strong); color: var(--text-2); }
}

/* ---------- Selection grids ---------- */
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.pose-btn, .style-btn {
  padding: 9px 4px;
  background: var(--surface-2);
  border-color: var(--line);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 11.5px;
  font-weight: 500;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pose-btn.active, .style-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}
@media (hover: hover) and (pointer: fine) {
  .pose-btn:hover, .style-btn:hover { border-color: var(--line-strong); color: var(--text); }
  .pose-btn.active:hover, .style-btn.active:hover { background: var(--accent-hover); color: var(--on-accent); }
}

.drawer {
  margin-top: 12px;
  padding: 14px;
  background: var(--sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

/* ---------- Skin editor canvas ----------
   The canvas element's own width/height attributes stay 64x64 — that IS the
   real skin texture, pixel for pixel, and what gets read for painting,
   the eyedropper, and the download. CSS only stretches it on screen;
   image-rendering: pixelated keeps that stretch crisp instead of blurry. */
.skin-canvas-wrap {
  position: relative;
  width: 320px;
  height: 320px;
  max-width: 100%;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background:
    linear-gradient(45deg, var(--line) 25%, transparent 25%) 0 0 / 16px 16px,
    linear-gradient(-45deg, var(--line) 25%, transparent 25%) 0 0 / 16px 16px,
    linear-gradient(45deg, transparent 75%, var(--line) 75%) 0 0 / 16px 16px,
    linear-gradient(-45deg, transparent 75%, var(--line) 75%) 0 0 / 16px 16px,
    var(--sunken); /* a faint checkerboard shows through transparent pixels */
}
#skinEditorCanvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  cursor: crosshair;
  touch-action: none;
}
/* ---------- Icon-only controls (tools, history, layers, body parts) ----------
   Every one of these carries a title + aria-label in the markup, so the
   glyph is never the only thing carrying the meaning. */
.icon-row { display: flex; gap: 6px; flex-wrap: wrap; }
.icon-tool {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  cursor: pointer;
  transition:
    background-color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    opacity var(--dur-fast) var(--ease-out),
    transform var(--dur-press) var(--ease-out);
}
.icon-tool:active { transform: scale(0.94); }
.icon-tool.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.icon-tool:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}
@media (hover: hover) and (pointer: fine) {
  .icon-tool:not(:disabled):not(.active):hover { border-color: var(--line-strong); color: var(--text); }
  .icon-tool.active:hover { background: var(--accent-hover); }
  /* Destructive, so it says so on approach — same signal Reset gives. */
  #skinClearBtn:hover { border-color: var(--danger); color: var(--danger); }
}
@media (prefers-reduced-motion: reduce) {
  .icon-tool:active { transform: none; }
}

/* A one-pixel-per-cell grid, drawn in CSS rather than baked into the canvas
   itself — it sits on top as an overlay, so it never touches the actual
   texture data the eyedropper and export read from. */
.skin-canvas-wrap::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    repeating-linear-gradient(to right, var(--line-strong) 0 1px, transparent 1px 5px),
    repeating-linear-gradient(to bottom, var(--line-strong) 0 1px, transparent 1px 5px);
}

/* ---------- Switches, swatches, sliders ---------- */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  width: 32px; height: 19px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  position: relative;
  flex-shrink: 0;
  transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
.switch-track::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 13px; height: 13px;
  background: var(--text-3);
  border-radius: 50%;
  transition: transform var(--dur-mid) var(--ease-out), background-color var(--dur-fast) var(--ease-out);
}
.switch input:checked + .switch-track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(13px); background: var(--on-accent); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

.swatch-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.swatch { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-2); cursor: pointer; }
input[type="color"] {
  width: 34px; height: 28px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 4px; }
.swatch-row .help { margin-top: 0; }

.gradient-panel {
  display: flex;
  flex-direction: column;   /* JS toggles this to display:flex */
  gap: 12px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--sunken);
}
#gradientAngleRow, #savedPosesRow { flex-direction: column; align-items: stretch; }
.radio-row { display: flex; gap: 16px; }
.radio-row label { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-2); cursor: pointer; }
input[type="radio"], input[type="checkbox"] { accent-color: var(--accent); cursor: pointer; }

.slider-row { display: flex; align-items: center; gap: 10px; }
input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--line-strong);
  border-radius: 2px;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px; height: 15px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  transition: transform var(--dur-press) var(--ease-out);
}
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.15); }
input[type="range"]::-moz-range-thumb {
  width: 15px; height: 15px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  cursor: pointer;
}
.slider-value { font-size: 12px; color: var(--text-2); min-width: 40px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Light dial ----------
   140x140 is fixed: main.js hardcodes DIAL_SIZE = 140 and positions the
   dot in raw pixels, so resizing this silently breaks the light mapping. */
.light-dial {
  position: relative;
  width: 140px;
  height: 140px;
  margin: 0 auto;
  background: var(--sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  touch-action: none;
  transition: opacity var(--dur-mid) var(--ease-out);
}
.light-dial.disabled { opacity: 0.4; pointer-events: none; }
.light-dial-figure {
  position: absolute;
  top: 50%; left: 50%;
  width: 16px; height: 16px;
  background: var(--text-3);
  border-radius: 3px;
  transform: translate(-50%, -50%);
}
.light-dial-dot {
  position: absolute;
  width: 15px; height: 15px;
  /* Tungsten, not oak: this dot stands for an actual light bulb, so it gets
     its own hue rather than borrowing the general accent colour. */
  background: var(--highlight);
  border: 2px solid var(--surface);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--highlight-glow);
  transform: translate(-50%, -50%);
  cursor: grab;
}
.light-dial-dot:active { cursor: grabbing; }

/* ---------- Legal links in the panel ---------- */
.inspector-legal {
  display: flex;
  gap: 14px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  font-size: 12px;
}
.inspector-legal a,
.inspector-legal button {
  color: var(--text-3);
  text-decoration: none;
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  cursor: pointer;
}
.inspector-legal a:hover,
.inspector-legal button:hover { color: var(--text); text-decoration: underline; }
.disclaimer { font-size: 11px; line-height: 1.5; color: var(--text-3); margin-top: 10px; }

textarea.text-input { resize: vertical; min-height: 100px; line-height: 1.5; font-family: var(--font); }

/* ---------- Export bar (pinned) ---------- */
.export-bar {
  flex-shrink: 0;
  padding: 14px 16px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.segmented {
  display: flex;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--sunken);
}
.segmented label { flex: 1; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; width: 0; height: 0; }
.segmented span {
  display: block;
  padding: 6px 0;
  text-align: center;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.segmented input:checked + span { background: var(--surface-2); color: var(--text); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (hover: hover) and (pointer: fine) {
  .segmented label:hover span { color: var(--text-2); }
}
.export-switch { font-size: 12.5px; color: var(--text-2); }
.export-actions { display: flex; gap: 8px; }
.export-actions .btn-primary { flex: 1; }

/* Turning transparency on switches the colour and gradient controls off,
   since there is no longer a background for them to change. */
input[type="color"]:disabled { opacity: 0.4; cursor: not-allowed; }
.switch input:disabled + .switch-track { opacity: 0.4; }
.radio-row input:disabled { cursor: not-allowed; }

/* ============================================================
   TOASTS — bottom-left, clear of the pinned Download button
   ============================================================ */
.toast-container {
  position: fixed;
  bottom: 18px;
  left: 18px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  z-index: 400;
  max-width: 330px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12.5px;
  box-shadow: var(--shadow-pop);
  animation: toast-in 240ms var(--ease-out);
}
.toast-icon {
  flex-shrink: 0;
  width: 18px; height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 11px;
}
.toast.success .toast-icon { background: var(--accent-soft); color: var(--accent); }
.toast.error .toast-icon { background: var(--danger-soft); color: var(--danger); }
.toast.info .toast-icon { background: var(--accent-soft); color: var(--accent); }
.toast.fade-out { animation: toast-out 170ms var(--ease-out) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes toast-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(5px) scale(0.98); } }

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(8, 9, 11, 0.62);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur-mid) var(--ease-out), visibility var(--dur-mid) var(--ease-out);
}
.modal-overlay.open { opacity: 1; visibility: visible; }
.modal {
  width: 100%;
  max-width: 400px;
  padding: 26px;
  background: var(--surface);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  transform: scale(0.97) translateY(8px);
  transition: transform var(--dur-mid) var(--ease-out);
}
.modal-overlay.open .modal { transform: none; }
.modal h2 { font-size: 19px; font-weight: 700; letter-spacing: -0.015em; }
.modal-sub { font-size: 13px; color: var(--text-2); margin: 6px 0 18px; }
.modal .field + .field { margin-top: 14px; }
.modal .btn-primary { margin-top: 16px; }
.form-error { color: var(--danger); font-size: 12.5px; margin-top: 10px; min-height: 1.2em; }

/* ============================================================
   COOKIE NOTICE — a card in the stage's corner, never on top of
   the Download button
   ============================================================ */
.cookie-notice {
  display: none;
  position: fixed;
  bottom: 18px;
  left: 18px;
  z-index: 300;
  max-width: 380px;
  align-items: center;
  gap: 14px;
  padding: 13px 15px;
  background: var(--surface);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
}
.cookie-notice p { font-size: 12.5px; line-height: 1.5; color: var(--text-2); }
.cookie-notice .btn-secondary { flex-shrink: 0; }

/* ============================================================
   LEGAL PAGES
   ============================================================ */
.doc-body { height: auto; min-height: 100%; display: flex; flex-direction: column; }
.doc {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 48px 24px 64px;
}
.doc-kicker {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  margin-bottom: 10px;
}
.doc h1 { font-size: 32px; font-weight: 700; letter-spacing: -0.025em; line-height: 1.2; }
.doc-updated { font-size: 12.5px; color: var(--text-3); margin-top: 10px; }
.doc-lead {
  font-size: 16px;
  line-height: 1.65;
  color: var(--text-2);
  margin: 28px 0;
  padding: 18px 20px;
  background: var(--surface);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.doc h2 { font-size: 19px; font-weight: 650; letter-spacing: -0.015em; margin: 36px 0 12px; }
.doc h3 { font-size: 15px; font-weight: 600; margin: 24px 0 8px; }
.doc p { margin-bottom: 14px; color: var(--text-2); }
.doc li { margin-bottom: 8px; color: var(--text-2); }
.doc ul { padding-left: 22px; margin-bottom: 16px; }
.doc strong { color: var(--text); font-weight: 600; }
.doc code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
}
.doc-todo {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 5px;
  background: var(--danger-soft);
  border: 1px dashed var(--danger);
  color: var(--danger);
  font-size: 12.5px;
  font-weight: 500;
}
.doc-table-wrap { overflow-x: auto; margin: 16px 0 24px; }
.doc-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 520px; }
.doc-table th, .doc-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  color: var(--text-2);
}
.doc-table th { color: var(--text); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.doc-nav {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin-top: 44px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  font-size: 13px;
}
.doc-foot {
  border-top: 1px solid var(--line);
  padding: 20px 24px;
  text-align: center;
}
.doc-foot p { font-size: 11.5px; color: var(--text-3); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
/* Short viewports (and heavy browser zoom) get normal page flow, so
   nothing is trapped in a squeezed fixed-height shell. */
@media (max-width: 1024px), (max-height: 620px) {
  .workspace {
    grid-template-columns: 1fr;
    height: auto;
    padding: 14px;
    gap: 14px;
  }
  .stage { container-type: normal; }
  .preview-panel { width: min(100%, 560px); }
  .inspector { overflow: visible; }
  .inspector-scroll { overflow: visible; }
  .export-bar { position: sticky; bottom: 0; z-index: 10; }
}

@media (max-width: 620px) {
  /* Wordmark + actions on the first row, the mode switch centred beneath
     them — all three cannot share one row at phone widths without either
     the wordmark or a control being pushed off the edge. */
  .topbar {
    height: auto;
    grid-template-columns: auto auto;
    grid-template-areas:
      'wordmark actions'
      'switch   switch';
    row-gap: 10px;
    justify-content: space-between;
    padding: 10px 12px;
  }
  .wordmark { grid-area: wordmark; font-size: 15px; }
  .topbar-actions { grid-area: actions; }
  .mode-switch { grid-area: switch; justify-self: center; }
  .mode-tab { padding: 7px 14px; font-size: 12.5px; }
  .coffee-text { display: none; }
  .workspace { padding: 10px; }
  .inspector-scroll { padding: 16px; }
  .preview-hint { font-size: 10px; gap: 8px; padding: 5px 10px; }
  .doc { padding: 32px 18px 48px; }
  .doc h1 { font-size: 26px; }
  .cookie-notice { left: 12px; right: 12px; bottom: 12px; max-width: none; }
  .toast-container { left: 12px; right: 12px; bottom: 12px; max-width: none; }
}

@media (max-width: 420px) {
  .input-row { flex-direction: column; align-items: stretch; }
  .input-row .btn-secondary, .input-row .btn-quiet { width: 100%; }
  .btn-row { flex-direction: column; }
  .btn-row > * { width: 100%; }
}

/* ============================================================
   REDUCED MOTION — keep what explains, drop what moves
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .loading-spinner span { animation: none; opacity: 0.8; }
  .toast { animation: fade-in 150ms ease both; }
  .toast.fade-out { animation: fade-out 130ms ease forwards; }
  .modal { transform: none; transition: none; }
  .skip-link { transition: none; }
  .btn-primary:active, .btn-secondary:active, .btn-quiet:active, .btn-ghost:active,
  .btn-danger:active, .icon-btn:active, .pose-btn:active, .style-btn:active,
  .dropzone:active { transform: none; }
  .switch-track::after { transition: background-color var(--dur-fast) linear; }
  input[type="range"]:active::-webkit-slider-thumb { transform: none; }
  @keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
  @keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }
}
