/* Tokens: design-soul base (neutral, customer surface) */
@font-face { font-family: "Anton"; src: url(/fonts/anton.woff2) format("woff2"); font-display: swap; }
@font-face { font-family: "Geist"; font-weight: 600; src: url(/fonts/geist-600.woff2) format("woff2"); font-display: swap; }
@font-face { font-family: "Inter"; font-weight: 400; src: url(/fonts/inter-400.woff2) format("woff2"); font-display: swap; }
@font-face { font-family: "Inter"; font-weight: 500; src: url(/fonts/inter-500.woff2) format("woff2"); font-display: swap; }
@font-face { font-family: "Inter"; font-weight: 600; src: url(/fonts/inter-600.woff2) format("woff2"); font-display: swap; }

:root {
  --font-display: "Geist", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-12: 48px; --s-16: 64px;
  --r-md: 8px; --r-lg: 12px; --r-xl: 16px;
  --t-fast: 100ms;
  --text-sm: 14px; --text-base: 16px; --text-md: 18px; --text-lg: 22px; --text-xl: 28px; --text-2xl: 36px;
  --control-h: 48px;
  --bg: #F7F7F8; --surface: #FFFFFF; --surface-2: #F2F2F4; --line: #E6E6EA;
  --ink: #18181B; --ink-2: #52525B; --ink-3: #A1A1AA;
  --brand-action: #18181B; --brand-hover: #000000; --on-brand: #FFFFFF;
  --bad: #C0362C;
  --focus: 0 0 0 3px color-mix(in srgb, var(--brand-action) 35%, transparent);
  --shadow-lg: 0 16px 48px rgb(0 0 0 / .14), 0 2px 6px rgb(0 0 0 / .06);
  --scrim: rgb(0 0 0 / .4);
  --stage: #0B0B0C;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F0F11; --surface: #18181B; --surface-2: #222226; --line: #2E2E33;
    --ink: #F4F4F5; --ink-2: #A1A1AA; --ink-3: #71717A;
    --brand-action: #F4F4F5; --brand-hover: #FFFFFF; --on-brand: #0F0F11;
    --bad: #F87171; --shadow-lg: 0 16px 48px rgb(0 0 0 / .55); --scrim: rgb(0 0 0 / .6);
    --stage: #000;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 var(--text-base)/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased; min-height: 100dvh;
}
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.offscreen { position: fixed; left: 0; top: 0; width: 2px; height: 2px; opacity: 0; pointer-events: none; }

h1, h2 { font-family: var(--font-display); font-weight: 600; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: var(--text-2xl); line-height: 1.12; text-wrap: balance; }
h1.small { font-size: var(--text-lg); line-height: 1.25; }
h2 { font-size: var(--text-md); }
p { margin: 0; }
.lede { color: var(--ink-2); max-width: 44ch; }
.hint { color: var(--ink-2); font-size: var(--text-sm); }
.err { color: var(--bad); font-size: var(--text-sm); }

/* Top bar */
.bar {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-4);
  max-width: 1040px; margin: 0 auto; padding: var(--s-3) var(--s-4);
  padding-top: max(var(--s-3), env(safe-area-inset-top));
}
.mark { font: 600 var(--text-md)/1 var(--font-display); color: var(--ink); text-decoration: none; padding: var(--s-3) 0; }
.tabs { display: flex; gap: var(--s-5); }
.tabs button {
  appearance: none; background: none; border: 0; padding: var(--s-3) 0; min-height: 44px; cursor: pointer;
  font: 500 var(--text-sm)/1 var(--font-body); color: var(--ink-2);
  border-bottom: 2px solid transparent; transition: color var(--t-fast);
}
.tabs button[aria-current="page"] { color: var(--ink); border-bottom-color: var(--ink); }
.tabs .num:not(:empty) { color: var(--ink-3); margin-left: 2px; }

main { max-width: 1040px; margin: 0 auto; padding: var(--s-4) var(--s-4) calc(var(--s-12) + env(safe-area-inset-bottom)); }

/* Buttons */
.btn {
  appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  height: var(--control-h); padding: 0 var(--s-5); border-radius: var(--r-md); cursor: pointer;
  border: 1px solid var(--brand-action); background: var(--brand-action); color: var(--on-brand);
  font: 600 var(--text-base)/1 var(--font-body); transition: background var(--t-fast), opacity var(--t-fast);
}
.btn:hover { background: var(--brand-hover); }
.btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--bad); flex: 0 0 var(--control-h); padding: 0; }
.btn:disabled { opacity: .55; cursor: default; }
.link {
  appearance: none; background: none; border: 0; cursor: pointer; min-height: 44px;
  font: 500 var(--text-sm)/1 var(--font-body); color: var(--ink-2); text-decoration: underline; text-underline-offset: 3px;
}
.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:is(button, input, a):focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-md); }

/* Start */
.start { display: grid; gap: var(--s-4); justify-items: start; padding-top: var(--s-8); }
.start .btn { margin-top: var(--s-2); min-width: 220px; }
.start #recent { width: 100%; margin-top: var(--s-12); display: grid; gap: var(--s-3); }
@media (hover: none) { #drop-hint { display: none; } }
body.dragging { outline: 2px dashed var(--ink-3); outline-offset: -12px; }

/* Editor and result */
.edit { display: grid; gap: var(--s-5); }
.stage {
  background: var(--stage); border-radius: var(--r-lg); overflow: hidden;
  display: grid; place-items: center; min-height: 200px;
}
.stage canvas, .stage img { display: block; max-width: 100%; max-height: 52dvh; width: auto; height: auto; }
.controls { display: grid; gap: var(--s-4); align-content: start; }
.field { display: grid; gap: var(--s-2); font-size: var(--text-sm); color: var(--ink-2); font-weight: 500; }
.field b { color: var(--ink); font-weight: 600; }
.field input[type="text"] {
  height: var(--control-h); padding: 0 var(--s-3); border-radius: var(--r-md);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: 400 var(--text-base)/1 var(--font-body); width: 100%;
}
.field input[type="text"]::placeholder { color: var(--ink-3); }
.field input[type="text"]:focus { outline: none; border-color: var(--ink); box-shadow: var(--focus); }
input[type="range"] { width: 100%; height: 32px; accent-color: var(--ink); margin: 0; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); overflow: hidden; }
.seg button {
  appearance: none; border: 0; background: none; height: 44px; cursor: pointer; color: var(--ink-2);
  font: 500 var(--text-sm)/1 var(--font-body); font-variant-numeric: tabular-nums; border-left: 1px solid var(--line);
}
.seg button:first-child { border-left: 0; }
.seg button[aria-checked="true"] { background: var(--ink); color: var(--bg); font-weight: 600; }
.progress { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--ink); }
.controls .link { justify-self: center; }

@media (min-width: 880px) {
  .edit { grid-template-columns: minmax(0, 1fr) 360px; gap: var(--s-8); align-items: start; }
  .stage canvas, .stage img { max-height: 70dvh; }
  .start { padding-top: var(--s-16); }
  h1 { font-size: 44px; }
  h1.small { font-size: var(--text-lg); }
}

/* Shelf */
.shelf-head { display: grid; gap: var(--s-1); margin-bottom: var(--s-4); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--s-2); }
.grid button {
  appearance: none; border: 0; padding: 0; cursor: pointer; background: var(--stage);
  border-radius: var(--r-md); overflow: hidden; aspect-ratio: 1; display: block;
}
.grid img { width: 100%; height: 100%; object-fit: contain; display: block; }
.empty { display: grid; gap: var(--s-4); justify-items: start; padding: var(--s-8) 0; color: var(--ink-2); }

/* Sheet */
dialog {
  border: 0; padding: var(--s-4); background: var(--surface); color: var(--ink);
  border-radius: var(--r-xl); box-shadow: var(--shadow-lg); width: min(440px, calc(100vw - 32px));
}
dialog[open] { display: grid; gap: var(--s-3); }
dialog::backdrop { background: var(--scrim); }
dialog .stage img { max-height: 56dvh; }
dialog .close {
  appearance: none; border: 0; background: none; color: var(--ink-2); cursor: pointer;
  width: 44px; height: 44px; display: grid; place-items: center; justify-self: end; margin: -8px -8px -8px 0;
}
.row { display: flex; gap: var(--s-2); }
.row .btn { flex: 1; padding: 0 var(--s-3); }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--s-6) + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: var(--s-3) var(--s-4); border-radius: var(--r-md);
  font-size: var(--text-sm); max-width: calc(100vw - 32px); z-index: 10;
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
