/* Layout: specimen viewer. The zoomable canvas owns the screen; a spec-sheet
   panel holds the source, the inspector and the instrument controls. */
:root {
  --bg: #e9ecf0;
  --panel: #f7f8fa;
  --line: #d3d8df;
  --fg: #1a1f27;
  --muted: #5d6673;
  --accent: #2257c4;
  --accent-ink: #ffffff;
  --code-bg: #eef1f5;
  --warn: #9a5b00;
  --hud-bg: rgba(14, 18, 24, 0.62);
  --hud-fg: #f2f4f7;
  --hud-accent: #9cc0ff;
  --font-display: "Space Grotesk", "Inter", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1217; --panel: #161a21; --line: #2a303a; --fg: #e6e9ee; --muted: #9aa3b0;
    --accent: #7ea6ff; --accent-ink: #0b1020; --code-bg: #11151b; --warn: #f0b45a;
    --hud-bg: rgba(8, 10, 14, 0.66); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font: 14px/1.5 var(--font-body); }

.app { display: grid; grid-template-columns: minmax(0, 1fr) 420px; height: 100%; }
.stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: #000; }
#gl { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
#gl:active { cursor: grabbing; }
#gl:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.hud { position: absolute; background: var(--hud-bg); color: var(--hud-fg); border-radius: 6px; padding: 6px 10px;
  font: 12px var(--font-mono); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.hud.path { top: calc(12px + env(safe-area-inset-top, 0px)); left: max(12px, env(safe-area-inset-left, 0px));
  max-width: calc(100% - 24px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud.path b { font-weight: 500; color: var(--hud-accent); }
.dim { opacity: 0.65; }
.hud.scale { bottom: 12px; left: max(12px, env(safe-area-inset-left, 0px)); display: grid; gap: 4px; }
.bar { height: 6px; width: 100px; border: 1.5px solid var(--hud-fg); border-top: 0; }
.scale-row { display: flex; gap: 12px; justify-content: space-between; font-variant-numeric: tabular-nums; }
.hud.actions { bottom: 12px; right: 12px; display: flex; gap: 6px; padding: 6px; }
.hud button { font: 500 12px var(--font-body); color: var(--hud-fg); background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.22); border-radius: 4px; padding: 5px 10px; cursor: pointer; }
.hud button:hover { background: rgba(255, 255, 255, 0.2); }
.hud button[aria-pressed="true"] { background: #f2f4f7; color: #10141a; }
.hud button:focus-visible { outline: 2px solid var(--hud-accent); outline-offset: 1px; }
.marker { position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px; pointer-events: none;
  border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1.5px rgba(0, 0, 0, 0.6), inset 0 0 0 1.5px rgba(0, 0, 0, 0.6); }
.floor { position: absolute; top: calc(52px + env(safe-area-inset-top, 0px)); left: max(12px, env(safe-area-inset-left, 0px));
  max-width: 320px; background: #3a2600; color: #ffd796; font-size: 12px; padding: 6px 10px; border-radius: 6px; }
.nogl { position: absolute; inset: 0; display: grid; place-items: center; color: #f2f4f7; padding: 24px; text-align: center; }

.panel { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; min-width: 0;
  padding-block: 20px 28px; padding-left: max(20px, env(safe-area-inset-left, 0px)); padding-right: max(20px, env(safe-area-inset-right, 0px));
  display: flex; flex-direction: column; gap: 22px; }
h1 { font: 600 24px/1.1 var(--font-display); margin: 0; letter-spacing: -0.01em; }
h2 { font: 600 12px var(--font-body); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 0; }
.lede { margin: 6px 0 0; color: var(--muted); max-width: 62ch; text-wrap: pretty; }
.group { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.tight { gap: 4px; }
label { font-size: 13px; font-weight: 500; }
select, textarea, input[type="range"] { width: 100%; }
select { font: 14px var(--font-body); padding: 7px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--code-bg); color: var(--fg); }
:is(select, textarea, input, button):focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.ctl { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center; }
.ctl output { font: 12px var(--font-mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.ctl input { grid-column: 1 / -1; accent-color: var(--accent); }
.hint { font-size: 12px; color: var(--muted); margin: 0; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 6px; padding: 2px; margin: 0; gap: 2px; }
.seg label { flex: 1; text-align: center; padding: 5px 0; border-radius: 4px; cursor: pointer; font-weight: 500; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--accent); color: var(--accent-ink); }
.seg label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }

textarea { font: 12.5px/1.55 var(--font-mono); background: var(--code-bg); color: var(--fg); border: 1px solid var(--line); border-radius: 6px;
  padding: 10px 12px; min-height: 360px; resize: vertical; tab-size: 2; white-space: pre; overflow-x: auto; }
.btn { font: 600 13px var(--font-body); background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 6px; padding: 8px 14px; cursor: pointer; }
.btn.secondary { background: transparent; color: var(--accent); box-shadow: inset 0 0 0 1px var(--line); }
.link { font: 500 12px var(--font-body); background: none; border: 0; color: var(--accent); cursor: pointer; padding: 2px 6px; border-radius: 4px; }
.link:hover { text-decoration: underline; }
#status { font: 12px var(--font-mono); color: var(--muted); min-width: 0; flex: 1 1 200px; overflow-wrap: anywhere; }
#status.err { color: var(--warn); }
#status.err[data-line]:not([data-line=""]) { cursor: pointer; text-decoration: underline dotted; }
.share-url { font: 12px var(--font-mono); width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--code-bg); color: var(--fg); }

#inspector { display: flex; flex-direction: column; gap: 8px; }
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
.steps li { border-left: 2px solid var(--line); padding: 2px 0 2px 10px; }
.step-head { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.step-head b { font: 500 13px var(--font-mono); }
.step-desc { font-size: 12px; color: var(--muted); }
.chip { width: 10px; height: 10px; border-radius: 2px; flex: none; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2); }
.swatch-row { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.swatch { width: 22px; height: 22px; border-radius: 4px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25); }
.swatch-row code { font: 12px var(--font-mono); }

.ref { font-size: 13px; }
.ref p { margin: 8px 0 0; max-width: 62ch; }
.ref a { color: var(--accent); }
.ref code { font: 12px var(--font-mono); background: var(--code-bg); padding: 1px 4px; border-radius: 3px; }
.ref table { border-collapse: collapse; font-size: 12px; width: 100%; margin-top: 8px; }
.ref td { border-top: 1px solid var(--line); padding: 5px 6px 5px 0; vertical-align: top; }
.ref td:first-child { font-family: var(--font-mono); white-space: nowrap; }
details summary { cursor: pointer; font-weight: 600; }

@media (max-width: 860px) {
  html, body { height: auto; }
  .app { grid-template-columns: 1fr; height: auto; }
  .stage { height: 62svh; min-height: 320px; }
  .panel { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  textarea { min-height: 260px; }
}
