:root {
  --paper: #f3efe6;
  --paper-2: #ebe5d8;
  --card: #fbf9f4;
  --ink: #17140f;
  --ink-2: #4a443a;
  --ink-3: #70685a;
  --line: #d9d1c1;
  --line-2: #bdb29c;
  --gutter: #e6dfd1;
  --track: #e9e2d4;
  --sel: #ffffff;
  --sel-line: #b5aa94;
  --check-a: #ffffff;
  --check-b: #ece8e0;
  --red: #d9482b;
  --blue: #2f56c8;
  --gold: #e8b53d;
  --green: #37866b;
  --focus: #2f56c8;
  --radius: 14px;
  --serif: "Newsreader", Georgia, serif;
  --sans: "Geist", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, "Cascadia Mono", monospace;
  --pad: 28px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #13110d;
    --paper-2: #1d1a15;
    --card: #1a1813;
    --ink: #f1ece2;
    --ink-2: #c9c1b2;
    --ink-3: #9d9483;
    --line: #322d25;
    --line-2: #4f4839;
    --gutter: #0f0d0a;
    --track: #0f0d0a;
    --sel: #4a443a;
    --sel-line: #7a7161;
    --check-a: #2a2620;
    --check-b: #221f1a;
    --focus: #8aa6ff;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 400 15px/1.55 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: inherit; }
button { font: inherit; color: inherit; }
img { max-width: 100%; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 8px; }
kbd { font: 500 11.5px/1 var(--mono); padding: 3px 5px; border-radius: 5px; border: 1px solid var(--line-2); border-bottom-width: 2px; background: var(--card); color: var(--ink-2); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.wrap { max-width: 1180px; margin: 0 auto; padding-left: var(--pad); padding-right: var(--pad); }

/* ------------------------------------------------------------------ header */
.top { padding-top: 22px; padding-bottom: 22px; display: flex; align-items: center; justify-content: space-between; }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font: 500 19px/1 var(--serif); letter-spacing: .2px; }
.mark { width: 28px; height: 28px; }
.mark-bg { fill: var(--ink); }
.links { display: flex; gap: 26px; }
.links a { text-decoration: none; color: var(--ink-2); font-size: 14px; padding: 4px 0; }
.links a:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 1px; }

/* ------------------------------------------------------------------ intro / file heading */
.intro { padding: 28px 0 26px; }
.intro h1 { font: 400 clamp(34px, 4.6vw, 56px)/1.05 var(--serif); letter-spacing: -1px; margin: 0 0 12px; text-wrap: balance; }
.intro p { margin: 0; font-size: 17px; color: var(--ink-2); max-width: 560px; }
.file-head { padding: 16px 0 18px; }
.fh-title { font: 400 32px/1.1 var(--serif); letter-spacing: -.5px; margin: 0 0 4px; }
.fh-title:focus { outline: none; }
.fh-title { scroll-margin-top: 16px; }
.fh-title:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; }
.fh-preset::before { content: "·"; margin: 0 8px; color: var(--line-2); }
.fh-preset { white-space: nowrap; }
.fh-name { margin: 0; font-size: 14px; color: var(--ink-3); overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 720px; }

/* ------------------------------------------------------------------ bench */
.bench { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 12px; }
.toolbar { display: flex; align-items: center; gap: 8px 12px; padding: 0 0 12px; flex-wrap: wrap; }
.views, .zoom, .seg { display: inline-flex; align-items: center; padding: 3px; border-radius: 11px; background: var(--track); border: 1px solid var(--line); }
.views button, .seg button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; font-size: 14px; color: var(--ink-2); cursor: pointer; }
.seg button { padding: 7px 13px; }
.views button:hover, .seg button:hover { color: var(--ink); }
.views button[aria-selected="true"], .seg button[aria-checked="true"] {
  background: var(--sel); color: var(--ink); font-weight: 500; box-shadow: 0 0 0 1px var(--sel-line), 0 1px 2px rgba(23, 20, 15, .12);
}
.zoom { margin-left: auto; }
.zoom button { border: 0; background: none; height: 30px; border-radius: 8px; cursor: pointer; color: var(--ink); }
.zoom button:disabled { opacity: .35; cursor: default; }
.zoom .icon { width: 32px; display: grid; place-items: center; }
.zoom .icon svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.zoom-pct { min-width: 48px; text-align: center; font: 500 12.5px/1 var(--mono); color: var(--ink-2); }
.zoom-fit { padding: 0 12px; margin-left: 2px; font-size: 13.5px; border-left: 1px solid var(--line) !important; border-radius: 0 8px 8px 0 !important; }
.zoom button:not(:disabled):hover { background: var(--sel); }
.status { margin: 0; display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-2); }
.status-time { font: 500 12.5px/1 var(--mono); color: var(--ink-3); }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 0 color-mix(in srgb, var(--red) 50%, transparent); animation: pulse 1.6s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

.notice-actions { display: flex; gap: 6px; flex: none; }
.status-m { flex: none; min-height: 34px; }
.status-h { margin-top: 10px; }
.notice-h { margin-top: 12px; max-width: 720px; }
.notice-h .btn { height: 44px; }
.notice { display: flex; align-items: center; gap: 10px 12px; justify-content: space-between; flex-wrap: wrap; margin: 6px 0 0; padding: 10px 12px 10px 14px; border-radius: 10px; border: 1px solid var(--line); border-left: 3px solid var(--red); background: var(--paper); }
.notice p { margin: 0; font-size: 14px; color: var(--ink-2); }
.notice strong { color: var(--ink); font-weight: 500; }

.stage { position: relative; border-radius: var(--radius); overflow: hidden; height: 300px; background: var(--gutter); transition: height .25s ease; }
.stage[data-mode="empty"] { background: var(--paper-2); height: auto; min-height: 300px; display: flex; }
.stage[data-mode="empty"] .drop { position: relative; inset: auto; flex: 1; }

/* empty state */
.drop {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  border: 1.5px dashed var(--line-2); border-radius: var(--radius); text-align: center; padding: 20px;
  transition: background-color .15s, border-color .15s;
}
.stage.is-over .drop { background: color-mix(in srgb, var(--paper-2) 55%, var(--card)); border-style: solid; border-color: var(--ink); }
.drop.is-msg .drop-art { display: none; }
.drop-buttons { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.drop-buttons .btn { min-height: 44px; flex-shrink: 0; }
.drop-art { width: 96px; margin-bottom: 2px; transition: transform .2s; }
.drop-art path { stroke: var(--ink); stroke-width: 2.4; stroke-linejoin: round; }
.drop-art path:nth-child(1) { fill: var(--red); }
.drop-art path:nth-child(2) { fill: var(--blue); }
.drop-art path:nth-child(3) { fill: var(--gold); }
.drop-art path:nth-child(4) { fill: var(--green); }
.stage.is-over .drop-art { transform: translateY(-3px) rotate(-1.5deg); }
.drop-title { margin: 0; font: 400 22px/1.2 var(--serif); }
.drop-msg { margin: -6px 0 2px; max-width: 360px; color: var(--ink-2); font-size: 14px; }
.drop-helper { margin: 0; color: var(--ink-2); font-size: 14px; }
.drop-sub { margin: -6px 0 0; color: var(--ink-2); font-size: 13px; }
@media (pointer: coarse) { .drop-helper { display: none; } .drop-sub { margin-top: 0; } }

/* viewer */
.viewer { position: absolute; inset: 0; }
.canvas { position: absolute; inset: 0; overflow: hidden; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.canvas.zoomed { touch-action: none; }
.canvas.zoomed .pan { cursor: grab; }
.canvas.dragging .pan { cursor: grabbing; }
.pan {
  position: absolute; left: 0; top: 0;
  background-color: var(--check-a);
  background-image: linear-gradient(45deg, var(--check-b) 25%, transparent 25%, transparent 75%, var(--check-b) 75%),
                    linear-gradient(45deg, var(--check-b) 25%, transparent 25%, transparent 75%, var(--check-b) 75%);
  background-size: 16px 16px; background-position: 0 0, 8px 8px;
  box-shadow: 0 0 0 1px rgba(23, 20, 15, .1);
  transform-origin: 0 0; will-change: transform;
}
.canvas { contain: strict; }
/* the layers are rasterised once per committed zoom level; panning, zoom gestures and the Compare split only move
   composited layers (transforms), so nothing is repainted while you drag */
.clip { position: absolute; inset: 0; overflow: hidden; will-change: transform; }
.layer { position: absolute; left: 0; top: 0; width: 100%; height: 100%; display: block; will-change: transform; }
.layer.lines { background: #fff; }

/* compare: everything is placed over the visible image rectangle (--l, --t, --w, --h set by JS) */
.split { position: absolute; inset: 0; pointer-events: none; }
.split-line { position: absolute; top: var(--t, 0); height: var(--h, 100%); width: 2px; margin-left: -1px; left: var(--x, 50%); background: #fff; box-shadow: 0 0 0 1px rgba(15, 12, 8, .55); }
.split-knob { pointer-events: auto; position: absolute; top: var(--ky, 50%); left: var(--kx, 50%); width: 44px; height: 44px; margin: -22px 0 0 -22px; display: grid; place-items: center; cursor: ew-resize; touch-action: none; border-radius: 50%; }
.knob-face { transform: translateX(var(--fo, 0px)); width: 34px; height: 34px; border-radius: 50%; background: #fff; border: 1px solid rgba(15, 12, 8, .35); box-shadow: 0 3px 12px rgba(15, 12, 8, .3); display: grid; place-items: center; }
.split-knob.edge-l .ch-l, .split-knob.edge-r .ch-r { display: none; }
.split-knob.edge-l .knob-face svg { transform: translateX(-3px); }
.split-knob.edge-r .knob-face svg { transform: translateX(3px); }
.knob-face svg { width: 18px; height: 18px; fill: none; stroke: #17140f; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.split-knob:focus-visible { outline: none; }
.split-knob:focus-visible .knob-face { outline: none; box-shadow: inset 0 0 0 3px var(--focus), 0 3px 12px rgba(15, 12, 8, .3); }
.tag { position: absolute; top: calc(var(--t, 0px) + var(--h, 0px) - 32px); font: 500 10.5px/1 var(--mono); letter-spacing: .6px; text-transform: uppercase; padding: 6px 7px; border-radius: 6px; background: rgba(23, 20, 15, .74); color: #fff; }
.tag-l { left: calc(var(--l, 0px) + 8px); }
.tag-r { left: calc(var(--l, 0px) + var(--w, 0px) - 8px); transform: translateX(-100%); }

/* controls under the canvas */
.controls { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px 24px; padding: 14px 2px 0; margin-top: 12px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.detail { display: flex; flex-direction: column; gap: 6px; }
.detail-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.label { font: 500 11.5px/1 var(--mono); letter-spacing: .7px; text-transform: uppercase; color: var(--ink-3); }
.hint-row { display: flex; align-items: center; gap: 12px; min-height: 34px; }
.detail-hint { margin: 0; color: var(--ink-3); font-size: 13.5px; flex: 1; min-width: 0; }
.retrace { flex: none; }
/* one fixed slot for "Re-trace as Detailed" or "Tracing as Balanced · 120 s": the Detail group never changes width */
.slot { flex: none; width: 236px; display: flex; justify-content: flex-start; align-items: center; min-height: 34px; }
.status-time { min-width: 4.5ch; }
@media (max-width: 1120px) and (min-width: 821px) {   /* export and Detail no longer fit side by side: stack from the outset */
  .controls { flex-direction: column; align-items: stretch; }
  .detail-row, .hint-row { justify-content: flex-start; }
  .detail { align-self: flex-start; max-width: 100%; }
  .detail-hint { flex: 0 1 auto; }
}
.retrace[disabled] { visibility: hidden; }
.meta { margin: 14px 2px 2px; display: flex; flex-wrap: wrap; gap: 6px 28px; }
.meta div { display: flex; flex-direction: column; }
.meta dt { font: 500 11px/1.3 var(--mono); letter-spacing: .6px; text-transform: uppercase; color: var(--ink-3); }
.meta dd { margin: 0; font: 500 13.5px/1.4 var(--mono); color: var(--ink); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 10px;
  font-weight: 500; font-size: 14.5px; text-decoration: none; cursor: pointer; border: 1px solid transparent; white-space: nowrap;
  transition: background-color .15s, border-color .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.small { height: 34px; padding: 0 12px; font-size: 13.5px; }
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.primary:hover { background: color-mix(in srgb, var(--ink) 86%, var(--paper)); }
.btn.ghost { background: transparent; border-color: var(--line-2); }
.btn.ghost:hover { background: var(--paper-2); }
.btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ------------------------------------------------------------------ how / notes / footer */
.how { padding: 60px 0 8px; }
.how h2 { font: 400 30px/1.15 var(--serif); letter-spacing: -.4px; margin: 0 0 22px; }
.specimen { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.specimen figure { margin: 0; }
.frame { border-radius: 10px; overflow: hidden; border: 1px solid var(--line); aspect-ratio: 3 / 2; background: var(--card); }
.frame img { width: 100%; height: 100%; display: block; object-fit: cover; }
.frame.lines { background: #fff; }
.specimen figcaption { margin-top: 10px; display: flex; flex-direction: column; gap: 3px; }
.cap-k { font: 500 11.5px/1.3 var(--mono); letter-spacing: .6px; text-transform: uppercase; color: var(--ink-3); }
.cap-t { font-size: 14.5px; color: var(--ink-2); max-width: 340px; }
.closeup { display: none; }
.cu-frame { position: relative; aspect-ratio: 1; overflow: hidden; border-radius: 8px; border: 1px solid var(--line); background: var(--card); }
.cu-frame.lines { background: #fff; }
.cu-frame img { position: absolute; width: 300%; height: 200%; max-width: none; left: -148.75%; top: -20%; }
.cu span { display: block; margin-top: 6px; font: 500 10.5px/1.3 var(--mono); letter-spacing: .5px; text-transform: uppercase; color: var(--ink-3); }
.cu-note { grid-column: 1 / -1; margin: 4px 0 0; color: var(--ink-2); font-size: 14.5px; }

.notes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; padding: 44px 0 64px; border-top: 1px solid var(--line); margin-top: 56px; }
.notes h2 { font: 400 20px/1.2 var(--serif); margin: 0 0 8px; }
.notes p { margin: 0; color: var(--ink-2); }

.foot { display: flex; justify-content: space-between; gap: 4px 16px; color: var(--ink-3); font-size: 13px; padding-top: 22px; padding-bottom: 36px;
        background: linear-gradient(var(--line), var(--line)) no-repeat var(--pad) 0 / calc(100% - 2 * var(--pad)) 1px; }
.foot > span:first-child { font: 500 15px/1.2 var(--serif); color: var(--ink-2); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 10; }

/* ------------------------------------------------------------------ small screens */
@media (max-width: 820px) {
  :root { --pad: 16px; }
  .top { padding-top: 16px; padding-bottom: 16px; }
  .links a { white-space: nowrap; }
  .links { gap: 16px; }
  .links a { font-size: 13.5px; }
  .intro { padding: 12px 0 18px; }
  .intro p { font-size: 16px; }
  .file-head { padding: 8px 0 14px; }
  .fh-title { font-size: 26px; }
  .fh-preset { display: block; }
  .fh-preset::before { content: none; }
  .bench { padding: 8px; border-radius: 16px; }
  .toolbar { padding-bottom: 8px; }
  .views { width: 100%; justify-content: space-between; }
  .views button { flex: 1; padding: 9px 4px; font-size: 13.5px; min-height: 44px; }
  .seg button { min-height: 44px; }
  .actions .btn { height: 44px; }
  .zoom { margin-left: 0; }
  .zoom button { height: 44px; }
  .zoom .icon { width: 44px; }
  .zoom-fit { padding: 0 14px; }

  .stage { height: 240px; }
  .stage[data-mode="empty"] { min-height: 240px; }
  .controls { flex-direction: column; align-items: stretch; }
  .actions .btn { flex: 1 1 auto; }
  .actions .btn.primary { flex-basis: 100%; }
  .meta { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
  .specimen { gap: 8px; }
  .cap-t { display: none; }
  .specimen figure { display: flex; flex-direction: column-reverse; gap: 6px; }
  .specimen figcaption { margin-top: 0; }
  .cu span { display: none; }
  .hide-m { display: none; }
  .hint-row { flex-wrap: wrap; }
  .detail-hint { flex-basis: 100%; }
  .retrace[disabled] { display: none; }
  .slot { width: auto; min-height: 0; flex-basis: 100%; }
  .retrace, .status-m { height: 44px; min-height: 44px; }
  .cap-k { font-size: 10px; letter-spacing: .3px; }
  .closeup { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
  .notes { grid-template-columns: 1fr; }
  .how { padding-top: 44px; }
  .foot { flex-direction: column; }
}
@media (max-height: 640px) and (min-width: 821px) {   /* short desktop windows: tighter header so export stays on screen */
  .top { padding-top: 12px; padding-bottom: 10px; }
  .file-head { padding: 4px 0 10px; }
  .fh-title { font-size: 26px; }
  .intro { padding: 12px 0 16px; }
  .toolbar { padding-bottom: 8px; }
}
@media (max-width: 380px) {
  .top { flex-wrap: wrap; row-gap: 10px; }
  .links { width: 100%; gap: 20px; }
  .hide-m { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .pulse { animation: none; }
  * { transition: none !important; }
}
