:root {
  --bg: #f3f2ee;
  --panel: #ffffff;
  --panel-2: #f7f6f2;
  --ink: #1d2023;
  --ink-2: #5b6168;
  --line: #dedbd2;
  --accent: #1e6b34;
  --accent-ink: #ffffff;
  --gold: #b88a2e;
  --warn: #9a5b00;
  --warn-bg: #fff4e0;
  --error: #b3261e;
  --pad: #c99a3e;
  --pad-ink: #1d1a12;
  --viewer: #17191d;
  /* 3D viewer chrome: the viewer stays dark in both themes */
  --viewer-bar: rgba(20,22,26,.8); --viewer-bar-solid: #1d2024; --viewer-ink: #e8e6e1; --viewer-ink-2: #b9bec4;
  --viewer-ctl: #23272c; --viewer-line: #7a8189; --viewer-sep: #3a4047; --viewer-on: #3f9d58; --viewer-on-ink: #0b1a10;
  --viewer-focus: #f2efe6; --viewer-tag: #9aa1a8; --viewer-tag-bg: rgba(20,22,26,.7); --viewer-empty: #c9cdd2; --viewer-drop: rgba(23,25,29,.6);
  --ctl-line: #80868c; /* control borders: >=3:1 against the panel; --line is for dividers only */
  --chip-on: #1e6b34;
  --cell-line: #868b91; --div-line: #b9b5aa;
  --cu-on: #d08a4a; --cu-edge: #9c5f24; --cu-tick: #1d1206;
  --mask-on: #2b6cb0; --mask-edge: #1f5590;
  --silk-on: #f6f6f0; --silk-line: #1d2023; --silk-tick: #1d2023;
  --radius: 8px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101214; --panel: #181b1e; --panel-2: #1f2327; --ink: #e8e6e1; --ink-2: #9aa1a8;
    --line: #2c3136; --accent: #3f9d58; --accent-ink: #0b1a10; --gold: #dcb46a;
    --warn: #f0b860; --warn-bg: #2a2214; --chip-on: #3f9d58; --error: #ff8a80; --pad: #dcb46a; --cell-line: #6f757c; --div-line: #4a5057; --mask-on: #3a7cc4; --mask-edge: #6aa0dc; --cu-edge: #e7a86c; --silk-line: #f6f6f0; --ctl-line: #757b82; --viewer-bar-solid: #1a1d21; --viewer-bar: rgba(16,18,21,.82); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101214; --panel: #181b1e; --panel-2: #1f2327; --ink: #e8e6e1; --ink-2: #9aa1a8;
  --line: #2c3136; --accent: #3f9d58; --accent-ink: #0b1a10; --gold: #dcb46a;
  --warn: #f0b860; --warn-bg: #2a2214; --chip-on: #3f9d58; --error: #ff8a80; --pad: #dcb46a; --cell-line: #6f757c; --div-line: #4a5057; --mask-on: #3a7cc4; --mask-edge: #6aa0dc; --cu-edge: #e7a86c; --silk-line: #f6f6f0; --ctl-line: #757b82; --viewer-bar-solid: #1a1d21; --viewer-bar: rgba(16,18,21,.82); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: grid; grid-template-rows: auto 1fr auto; min-height: 100vh; min-height: 100dvh;
}
/* touch-only and pointer-only copy */
.touch-only { display: none; }
@media (hover: none) and (pointer: coarse) {
  .touch-only { display: revert; }
  .pointer-only { display: none; }
}
h2 { display: flex; align-items: center; font-size: 13.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink); margin: 0 0 6px; font-weight: 700; }
h2 .sub { white-space: nowrap; text-transform: none; letter-spacing: 0; font-weight: 400; margin-left: 8px; color: var(--ink-2); font-size: 12px; }
h3 { font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); margin: 0 0 6px; font-weight: 650; }
.skip-link { position: absolute; left: 8px; top: -60px; z-index: 10; padding: 8px 12px; border-radius: 6px; background: var(--accent); color: var(--accent-ink); font-weight: 650; text-decoration: none; }
.skip-link:focus { top: 8px; outline: 2px solid var(--ink); outline-offset: 2px; }
#steps:focus, #viewer:focus { outline: none; }
fieldset.subgroup { border: 0; border-top: 1px dashed var(--line); margin: 14px 0 0; padding: 12px 0 0; min-width: 0; }
fieldset.subgroup > legend { padding: 0; float: left; width: 100%; }
fieldset.subgroup > legend + * { clear: both; }
.noscript { margin: 0; padding: 12px 16px; background: var(--warn-bg); color: var(--ink); border-bottom: 1px solid var(--line); }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
/* step badge: a round copper pad */
.step-num {
  display: inline-grid; place-items: center; flex: none; width: 20px; height: 20px; margin-right: 8px; border-radius: 50%;
  background: var(--pad); color: var(--pad-ink); font-family: var(--mono); font-size: 11.5px; font-weight: 700; letter-spacing: 0;
  box-shadow: 0 0 0 2px var(--panel), 0 0 0 3px var(--pad);
}
.num, output, input[type="number"] { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* top bar */
.topbar {
  display: flex; align-items: center; gap: 6px 18px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.tagline { margin: 0; color: var(--ink-2); font-size: 13.5px; }
.flow { margin-left: auto; }
.flow ol { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.flow li { display: flex; align-items: center; gap: 4px; }
.flow li + li::before { content: ""; width: 16px; height: 2px; border-radius: 1px; background: var(--pad); opacity: .7; }
.flow a { display: inline-flex; align-items: center; padding: 4px 9px 4px 4px; border-radius: 999px; color: var(--ink); text-decoration: none; font-size: 13px; font-weight: 550; }
.flow a .step-num { width: 18px; height: 18px; font-size: 10.5px; margin-right: 6px; box-shadow: none; }
.flow a:hover { background: var(--panel-2); }
.flow a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.logo { width: 20px; height: 20px; align-self: center; background: url("assets/favicon.svg") center / contain no-repeat; }
.about { border-bottom: 0; }
.about summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 6px; }
.about summary::-webkit-details-marker { display: none; }
.about summary::before { content: "▸"; color: var(--ink-2); font-size: 12px; }
.about details[open] summary::before { content: "▾"; }
.about summary h2 { margin: 0; }
.about summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.about p { margin: 10px 0 0; font-size: 13px; line-height: 1.5; color: var(--ink-2); max-width: 65ch; }
.about-links { margin: 10px 0 0; padding-left: 18px; font-size: 13px; display: grid; gap: 4px; }
.about-links a { color: var(--accent); }
.name { margin: 0; font-weight: 750; font-size: 17px; letter-spacing: .01em; }
.ver { color: var(--ink-2); font-family: var(--mono); font-size: 12px; }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hint { color: var(--ink-2); font-size: 12px; }

.btn {
  appearance: none; border: 1px solid var(--ctl-line); background: var(--panel-2); color: var(--ink);
  border-radius: 6px; padding: 7px 12px; font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--ink-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn.wide { display: block; width: 100%; padding: 10px 14px; font-size: 14.5px; font-weight: 650; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); border-color: var(--accent); }
.btn:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* layout */
.layout {
  display: grid; min-height: 0;
  grid-template-columns: minmax(340px, min(428px, 36vw)) 1fr;
  grid-template-rows: 1fr auto;
  grid-template-areas: "controls viewer" "controls strip";
}
.quick-open { display: none; }
/* keep keyboard focus clear of the sticky export dock */
.controls { scroll-padding-bottom: calc(var(--dock-h, 140px) + 8px); }
.controls { grid-area: controls; container: controls / inline-size; display: flex; flex-direction: column; overflow-y: auto; border-right: 1px solid var(--line); background: var(--panel); }
@media (prefers-reduced-motion: no-preference) { html, .controls { scroll-behavior: smooth; } }
.step { scroll-margin-top: 8px; }
.subgroup { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); }
#step-board { border-bottom: 0; }
.export-dock {
  position: sticky; bottom: 0; z-index: 1; margin-top: auto;
  padding: 12px 16px 14px; border-top: 1px solid var(--line); background: var(--panel);
  box-shadow: 0 -6px 14px -10px rgba(0,0,0,.35);
}
.export-dock a, .order-guide a { color: var(--accent); }
.export-spec { margin: 6px 0 0; font-size: 12px; color: var(--ink); }
.export-spec:empty { display: none; }
.order-guide { margin-top: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); font-size: 12.5px; }
.order-guide summary { cursor: pointer; padding: 8px 10px; font-weight: 650; }
.order-guide summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.order-guide ol { margin: 0; padding: 0 12px 4px 30px; display: grid; gap: 6px; }
.order-choices { margin: 6px 0 2px; padding-left: 16px; display: grid; gap: 3px; }
.order-choices b { font-weight: 650; }
.other-exports { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.viewer { grid-area: viewer; position: relative; min-height: 360px; background: var(--viewer); }
.strip { grid-area: strip; display: flex; gap: 12px; padding: 12px 16px; overflow-x: auto; border-top: 1px solid var(--line); background: var(--panel); }

.group { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.group-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.group-head h2 { margin: 0; }
.row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.row.check { flex-wrap: wrap; gap: 6px 16px; }
.row.buttons { flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.row.buttons.start { gap: 8px; margin: 0; }
#step-image .row.buttons.start { margin-bottom: 4px; }
.row input[type="range"] { flex: 1; }
.row output { min-width: 3.5em; text-align: right; color: var(--ink-2); }
.grid2, .grid3 { display: grid; gap: 8px 10px; }
.grid2 { grid-template-columns: 1fr 1fr; }
.grid3 { grid-template-columns: 1fr 1fr 1fr; margin: 6px 0; }
.grid2 label, .grid3 label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); }
input[type="number"], select {
  width: 100%; padding: 6px 8px; border: 1px solid var(--ctl-line); border-radius: 6px;
  background: var(--panel-2); color: var(--ink); font-size: 13px;
}
.group-head select { width: auto; }
.readout { margin: 10px 0 0; font-family: var(--mono); font-size: 12px; color: var(--ink-2); }

/* step 1 errors */
.error-box { margin: 0 0 10px; padding: 8px 10px; border-radius: 6px; border: 1px solid var(--error); color: var(--error); background: var(--panel-2); font-size: 12.5px; font-weight: 550; }

/* step 2: named looks */
.looks { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; margin: 4px 0 12px; }
.look { appearance: none; display: flex; flex-direction: column; gap: 6px; align-items: stretch; padding: 6px 6px 7px; border: 1px solid var(--ctl-line);
  border-radius: 8px; background: var(--panel-2); color: var(--ink); font: inherit; font-size: 12.5px; font-weight: 550; text-align: left; cursor: pointer; }
.look:hover { border-color: var(--ink-2); }
.look[aria-checked="true"] { border: 2px solid var(--accent); padding: 5px 5px 6px; background: var(--panel); }
.look:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.look-strip { display: flex; height: 22px; border-radius: 4px; overflow: hidden; box-shadow: inset 0 0 0 1px rgba(0,0,0,.2); }
.look-strip span { flex: 1; }
.look-name { padding: 0 2px; }
@media (pointer: coarse) { .look { min-height: 56px; } }

/* step 2: advanced layer editing */
.advanced { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.advanced > summary { cursor: pointer; padding: 8px 10px; font-size: 12.5px; font-weight: 650; color: var(--ink); }
.advanced > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.advanced[open] > summary { border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.advanced > :not(summary) { margin-left: 10px; margin-right: 10px; }
.advanced > .subgroup { margin-bottom: 10px; }
.preset-label { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink-2); }
.preset-label select { width: auto; }

/* tone table: a layer matrix, one compact row per brightness band */
.legend { margin: 0 0 8px; font-size: 12px; line-height: 1.4; color: var(--ink-2); }
.legend .key { color: var(--ink); font-weight: 600; white-space: nowrap; }
.legend .key::before { content: ""; display: inline-block; width: 9px; height: 9px; margin: 0 4px 0 1px; border-radius: 2px; vertical-align: 0; }
.legend .key.cu::before { background: var(--cu-on); }
.legend .key.mask::before { background: var(--mask-on); }
.legend .key.silk::before { background: var(--silk-on); box-shadow: inset 0 0 0 1.5px var(--silk-line); }
.matrix {
  --sw: 22px; --band: 52px; --cell: 32px; --div: 9px;
  --cols: var(--sw) minmax(0, 1fr) var(--band) repeat(3, var(--cell)) var(--div) repeat(3, var(--cell));
}
.tone-head, .tone {
  display: grid; grid-template-columns: var(--cols); column-gap: 3px; align-items: center;
}
.tone-head { grid-template-rows: auto auto; row-gap: 4px; padding-bottom: 4px; border-bottom: 1px solid var(--line);
  font-size: 10.5px; line-height: 1.1; color: var(--ink-2); }
.head-tone { grid-row: 2; align-self: end; padding-bottom: 6px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; font-size: 10px; }
.head-tone { grid-column: 1 / 4; }
.side-label { grid-row: 1; text-align: center; font-weight: 700; font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink);
  padding-bottom: 2px; border-bottom: 2px solid var(--pad); }
.side-label.s0 { grid-column: 4 / 7; }
.side-label.s1 { grid-column: 8 / 11; }
.col-label { grid-row: 2; align-self: stretch; justify-self: center; display: flex; align-items: center; justify-content: center;
  width: calc(var(--cell) + 4px); min-height: 28px; padding-bottom: 3px; text-align: center; color: var(--ink); font-weight: 550;
  border-bottom: 3px solid transparent; }
.col-label.cu { border-bottom-color: var(--cu-on); }
.col-label.mask { border-bottom-color: var(--mask-on); }
.col-label.silk { border-bottom-color: var(--silk-line); }
.s0.c0 { grid-column: 4; } .s0.c1 { grid-column: 5; } .s0.c2 { grid-column: 6; }
.s1.c0 { grid-column: 8; } .s1.c1 { grid-column: 9; } .s1.c2 { grid-column: 10; }
.tone-head .divider { grid-column: 7; grid-row: 1 / 3; }
.divider { align-self: stretch; justify-self: center; width: 1px; background: var(--div-line); }

.tones { list-style: none; margin: 0; padding: 0; }
.tone { grid-template-rows: auto auto; row-gap: 1px; padding: 2px 0; border-bottom: 1px solid var(--line); }
.tone > .divider { grid-column: 7; grid-row: 1 / 3; margin: -2px 0; }
.swatch { grid-column: 1; grid-row: 1 / 3; align-self: stretch; min-height: 30px; margin-right: 4px; border-radius: 4px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.2); }
.tone-name { grid-column: 2 / 4; grid-row: 1; min-width: 0; padding-left: 4px; font-size: 12.5px; font-weight: 550; line-height: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tone-name .k { display: inline-block; min-width: 1.1em; margin-right: 5px; color: var(--ink-2); font-weight: 600; font-family: var(--mono); font-size: 11.5px; }
.tone .th { grid-column: 2; grid-row: 2; min-width: 0; width: 100%; height: 15px; margin: 0; padding-left: 4px; }
.tone .th-end { font-size: 11px; color: var(--ink-2); line-height: 15px; padding-left: calc(4px + 1.1em + 5px); }
.band { grid-column: 3; grid-row: 2; padding-right: 6px; text-align: right; font-size: 11px; color: var(--ink-2); white-space: nowrap; line-height: 15px; }
.cell { grid-row: 1 / 3; position: relative; display: grid; place-items: center; width: var(--cell); height: 26px;
  border: 1.5px dashed var(--cell-line); border-radius: 5px; background: transparent; cursor: pointer; }
.cell input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.cell svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; visibility: hidden; pointer-events: none; }
.cell:hover { background: var(--panel-2); border-style: solid; }
.cell:has(input:checked) { border-style: solid; }
.cell:has(input:checked) svg { visibility: visible; }
.cell.cu:has(input:checked) { background: var(--cu-on); border-color: var(--cu-edge); color: var(--cu-tick); }
.cell.mask:has(input:checked) { background: var(--mask-on); border-color: var(--mask-edge); color: #fff; }
.cell.silk:has(input:checked) { background: var(--silk-on); border: 2px solid var(--silk-line); color: var(--silk-tick); }
.cell:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

/* narrow panel (phones, small laptops): the name and band share the first line, the slider and cells the second */
@container controls (max-width: 400px) {
  .tone-name { grid-column: 2 / 7; }
  .band { grid-column: 7 / 11; grid-row: 1; padding-right: 0; }
  .tone .th { grid-column: 2 / 4; }
  .cell { grid-row: 2; }
  .tone > .divider { grid-row: 2; margin: -2px 0 -4px; }
}
#step-tones .row.buttons { gap: 5px; }
#step-tones .row.buttons .btn.small { padding: 4px 7px; }
/* touch screens: 16px text (no zoom on focus) and finger-sized targets */
@media (pointer: coarse) {
  input[type="number"], select { font-size: 16px; min-height: 44px; }
  .btn, .btn.small { min-height: 44px; }
  .seg button { min-height: 42px; }
  .flow a { min-height: 40px; }
  .row.check label { min-height: 40px; display: inline-flex; align-items: center; gap: 6px; }
  .matrix { --cell: clamp(28px, 9.5cqw, 36px); }
  .cell { height: 40px; }
  /* narrow panel: name and band, then a full-width slider, then the cells */
  @container controls (max-width: 400px) {
    .tone { grid-template-rows: auto auto auto; row-gap: 4px; padding: 6px 0; }
    .swatch { grid-row: 1 / 4; }
    .tone .th { grid-column: 2 / -1; grid-row: 2; height: 32px; }
    .tone .th-end { line-height: 32px; }
    .cell, .tone > .divider { grid-row: 3; }
  }
}
/* short laptop screens: keep the tone matrix in view above the export dock */
@media (min-width: 720px) and (min-height: 501px) and (max-height: 800px) {
  .export-dock { padding: 10px 16px; }
  .other-exports { margin-top: 8px; }
}
.btn-sep { width: 1px; align-self: stretch; margin: 3px 2px; background: var(--line); }

/* empty note lists stay in the page (so the first note is announced) but take no space */
.warnings:empty { margin: 0; }
.warnings { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.warnings li { background: var(--warn-bg); color: var(--warn); border-radius: 6px; padding: 7px 10px; font-size: 12.5px; }
.warnings li.info { background: var(--panel-2); color: var(--ink-2); }

/* viewer */
.three { position: absolute; inset: 0; }
.three canvas { display: block; }
.three canvas:focus-visible { outline: 2px solid var(--viewer-focus); outline-offset: -4px; }
.view-bar {
  position: absolute; left: 12px; right: 12px; top: 12px; display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center;
  padding: 8px 10px; border-radius: 10px; background: var(--viewer-bar); color: var(--viewer-ink); backdrop-filter: blur(6px);
  font-size: 12.5px; width: fit-content; max-width: calc(100% - 24px);
}
.vb-title { align-self: stretch; display: flex; align-items: center; padding-right: 12px; border-right: 1px solid var(--viewer-sep);
  font-size: 10.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--viewer-ink-2); }
.vb-title::before { content: ""; width: 8px; height: 8px; margin-right: 7px; border-radius: 50%; background: var(--pad); }
.viewer { container: viewer / inline-size; }
/* the preview-only note sits under the board as a caption */
.vb-note { position: absolute; left: 14px; bottom: 12px; max-width: calc(100% - 100px); margin: 0; font-size: 11.5px; line-height: 1.3;
  color: var(--viewer-ink-2); background: var(--viewer-tag-bg); padding: 3px 8px; border-radius: 5px; }
@container viewer (max-width: 900px) { .vb-title { display: none; } }
.view-bar label { display: flex; align-items: center; gap: 6px; color: var(--viewer-ink-2); }
.view-bar select { width: auto; background: var(--viewer-ctl); color: var(--viewer-ink); border-color: var(--viewer-line); padding: 4px 6px; }
.view-bar .btn { background: var(--viewer-ctl); color: var(--viewer-ink); border-color: var(--viewer-line); }
.view-bar .btn:hover:not(:disabled) { border-color: var(--viewer-ink-2); }
.view-bar .btn.ghost { background: transparent; }
.view-bar .light input { width: 90px; }
.seg { display: inline-flex; border: 1px solid var(--viewer-line); border-radius: 6px; }
.seg button { appearance: none; border: 0; background: transparent; color: var(--viewer-ink-2); padding: 5px 10px; font: inherit; cursor: pointer; }
.seg button:first-child { border-radius: 5px 0 0 5px; }
.seg button:last-child { border-radius: 0 5px 5px 0; }
.seg button:hover { color: var(--viewer-ink); }
.seg button[aria-checked="true"] { background: var(--viewer-on); color: var(--viewer-on-ink); font-weight: 600; }
/* a light ring on the dark bar: every control, >=3:1 against the bar */
.view-bar :is(.btn, select, input, .seg button):focus-visible { outline: 2px solid var(--viewer-focus); outline-offset: 2px; }
.side-tag { position: absolute; right: 14px; bottom: 12px; font-family: var(--mono); font-size: 12px; color: var(--viewer-tag);
  background: var(--viewer-tag-bg); padding: 3px 8px; border-radius: 5px; }
.empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--viewer-empty); pointer-events: none; text-align: center; padding: 16px; }
.empty[hidden] { display: none; }
body.dragging .viewer::after { content: "Drop image"; position: absolute; inset: 10px; border: 2px dashed var(--viewer-on); border-radius: 12px;
  display: grid; place-items: center; color: var(--viewer-ink); font-size: 18px; background: var(--viewer-drop); }

/* strip */
.strip figure { margin: 0; display: flex; flex-direction: column; gap: 4px; flex: none; }
.strip canvas { height: 120px; width: auto; max-width: 220px; image-rendering: pixelated; background: #111; border-radius: 4px; border: 1px solid var(--line); }
.thumb { appearance: none; padding: 0; border: 0; background: none; cursor: zoom-in; border-radius: 5px; line-height: 0; }
.thumb:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.thumb:hover canvas { border-color: var(--ink-2); }
.layer-dialog { max-width: min(96vw, 1200px); padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--ink); }
.layer-dialog::backdrop { background: rgba(0,0,0,.6); }
.layer-dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.layer-dialog-head h2 { margin: 0; text-transform: none; letter-spacing: 0; font-size: 14px; }
.layer-dialog canvas { display: block; width: 100%; max-height: 78vh; object-fit: contain; image-rendering: pixelated; background: #111; border-radius: 6px; }
.strip figcaption { font-size: 11.5px; color: var(--ink-2); font-family: var(--mono); }
.layer-thumbs { display: flex; gap: 12px; }

/* status */
.statusbar { display: flex; justify-content: space-between; gap: 16px; border-top: 1px solid var(--line);
  padding: 6px max(16px, env(safe-area-inset-right, 0px)) max(6px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  background: var(--panel); font-size: 12px; color: var(--ink-2); }
#status { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats { font-family: var(--mono); white-space: nowrap; }
.gesture-hint { position: absolute; left: 14px; bottom: 12px; margin: 0; font-size: 12px; color: var(--viewer-tag);
  background: var(--viewer-tag-bg); padding: 3px 8px; border-radius: 5px; pointer-events: none; }
#status[data-kind="error"] { color: var(--error); font-weight: 600; }

/* single column: phones (portrait and landscape) and narrow windows; two panes from 720 px wide */
@media (max-width: 719px), (max-height: 500px) {
  /* the document scrolls; no inner scroll boxes */
  html, body { height: auto; }
  /* keep focused controls clear of the sticky status bar */
  html { scroll-padding-bottom: calc(var(--statusbar-h, 44px) + 8px); }
  body { display: block; min-height: 0; }
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto; grid-template-areas: "quick" "viewer" "controls" "strip"; }
  .quick-open { grid-area: quick; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
  #step-image .row.buttons.start { display: none; }
  .controls { overflow: visible; border-right: 0; border-top: 1px solid var(--line); }
  .export-dock { position: static; box-shadow: none; margin-top: 0; }
  .viewer { display: flex; flex-direction: column; min-height: 0; }
  .three { position: relative; height: 42vh; height: 42svh; min-height: 220px; }
  .stats { display: none; }
  .view-bar { position: static; width: auto; max-width: none; border-radius: 0; backdrop-filter: none; background: var(--viewer-bar-solid); padding: 10px 16px; }
  .vb-note, .gesture-hint { position: static; max-width: none; border-radius: 0; background: var(--viewer-bar-solid); padding: 0 16px 10px; }
  .side-tag { top: 12px; bottom: auto; }
  .flow { margin-left: 0; flex-basis: 100%; }
  .statusbar { position: sticky; bottom: 0; z-index: 2; }
  .strip { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); overflow: visible; border-top: 1px solid var(--line); }
  .layer-thumbs { display: contents; }
  .strip figure { min-width: 0; }
  .strip canvas { width: 100%; height: auto; max-width: none; aspect-ratio: 3 / 2; object-fit: contain; }
}
/* landscape phones: keep the board visible without filling the whole height */
@media (max-height: 500px) and (orientation: landscape) {
  .three { height: 62vh; height: 62svh; min-height: 180px; }
}
@media (max-width: 420px) {
  .tagline { flex-basis: 100%; }
}

/* ======================================================================
   PCB hints: a light touch of the board's own materials.
   - Surfaces are solder mask over the board: a faint green tint.
   - Things you pick show the surface finish (gold or silver), like an exposed pad.
   - Edges are hard 1px offsets (layer thickness), not soft shadows.
   - Corners are bevelled, bigger on one corner (pin 1 / board chamfer).
   - A copper trace runs down the steps; vias mark each step.
   ====================================================================== */
:root {
  --bg: #efede6; --panel: #fbfcfa; --panel-2: #f2f5f1;
  --edge-fr4: #d6cba6; --edge-mask: #c9d3c6; --edge-dark: rgba(0, 0, 0, .55);
  --finish: #c99a3e; --finish-ink: #1d1a12;
  --trace: #c08a52; --trace-off: rgba(192, 138, 82, .35);
  --bv: 7px; --bv-s: 3px; --bv-0: 1px;
}
:root[data-finish="hasl"] { --finish: #aab1b7; --finish-ink: #15181a; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1210; --panel: #151a17; --panel-2: #1b221e;
    --edge-fr4: #4a432e; --edge-mask: #0a0d0b;
    --finish: #dcb46a; --trace: #a8743f; --trace-off: rgba(168, 116, 63, .35);
  }
  :root:not([data-theme="light"])[data-finish="hasl"] { --finish: #c6ccd1; }
}
:root[data-theme="dark"] {
  --bg: #0e1210; --panel: #151a17; --panel-2: #1b221e;
  --edge-fr4: #4a432e; --edge-mask: #0a0d0b;
  --finish: #dcb46a; --trace: #a8743f; --trace-off: rgba(168, 116, 63, .35);
}
:root[data-theme="dark"][data-finish="hasl"] { --finish: #c6ccd1; }

/* ---- icons ---- */
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.i { width: 1.15em; height: 1.15em; flex: none; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: square; stroke-linejoin: miter; vertical-align: -0.22em; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn .i { width: 16px; height: 16px; }
.btn.small .i { width: 14px; height: 14px; }
.btn.wide { display: flex; }
.btn.icon-only { padding-left: 7px; padding-right: 7px; }
.step-i { width: 15px; height: 15px; margin-right: 7px; color: var(--ink-2); }
.advanced > summary .i, .order-guide summary .i { width: 15px; height: 15px; margin: 0 6px 0 2px; color: var(--ink-2); }
.seg button { display: inline-flex; align-items: center; gap: 6px; }
.seg button .i { width: 15px; height: 15px; }
.view-bar .light { gap: 6px; }
.view-bar .light .i { width: 16px; height: 16px; color: var(--viewer-ink-2); }
.status-line { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.status-line .i { width: 13px; height: 13px; }
.status-line:has(#status[data-kind="error"]) .i { color: var(--error); }
.error-box { display: flex; gap: 8px; align-items: flex-start; }
.error-box .i { width: 16px; height: 16px; margin-top: 1px; }
.warnings li { display: flex; gap: 8px; align-items: flex-start; }
.warnings li .i { width: 15px; height: 15px; margin-top: 1px; }

/* layer kinds are drawn, not written: pad, opening, ink */
.col-label { flex-direction: column; gap: 0; }
.col-label .i { width: 16px; height: 16px; }
.col-label .col-word { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.col-label.cu .i, .legend .key.cu .i { color: var(--cu-on); }
.col-label.mask .i, .legend .key.mask .i { color: var(--mask-on); }
.col-label.silk .i, .legend .key.silk .i { color: var(--ink); }
.legend .key::before { content: none; }
.legend .key { display: inline-flex; align-items: center; gap: 3px; }
.legend .key .i { width: 13px; height: 13px; }

/* board readout and export spec as small labelled facts */
.readout { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.readout span, .spec-chip { display: inline-flex; align-items: center; gap: 5px; }
.readout .i { width: 13px; height: 13px; color: var(--ink-2); }
.export-spec { display: flex; flex-wrap: wrap; gap: 5px; font-size: 12px; font-variant-numeric: tabular-nums; }
.spec-chip { padding: 2px 7px; border: 1px solid var(--line); background: var(--panel-2); border-radius: 3px; }
.spec-chip .i { width: 13px; height: 13px; color: var(--ink-2); }

/* layer thumbnails: a magnifier appears on hover/focus */
.thumb { position: relative; }
.thumb-zoom { position: absolute; top: 6px; right: 6px; width: 18px; height: 18px; padding: 2px; color: #f2efe6;
  background: rgba(16, 18, 21, .75); border-radius: 3px; opacity: 0; }
.thumb:hover .thumb-zoom, .thumb:focus-visible .thumb-zoom { opacity: 1; }

/* ---- mask surfaces and layer edges ---- */
.btn { box-shadow: 0 1px 0 var(--edge-fr4); }
.btn.primary { box-shadow: 0 1px 0 var(--edge-dark); }
.btn.ghost { box-shadow: none; }
input[type="number"], select { box-shadow: inset 0 1px 0 var(--edge-mask); } /* a mask opening: slightly recessed */
.look { box-shadow: 1px 1px 0 var(--edge-fr4); }
.look[aria-checked="true"] { border-color: var(--finish); box-shadow: 1px 1px 0 var(--cu-edge); }
.advanced, .order-guide { border-style: dashed; border-color: var(--ctl-line); box-shadow: none; }
.warnings li, .error-box { box-shadow: 1px 1px 0 var(--edge-fr4); }
.export-dock { box-shadow: 0 -1px 0 var(--edge-fr4); }
.strip canvas { box-shadow: 1px 1px 0 var(--edge-fr4); }
.view-bar { box-shadow: 1px 1px 0 var(--edge-dark); }
.layer-dialog { box-shadow: 2px 2px 0 var(--edge-fr4); }

/* exposed pads: step numbers and the chosen lighting show the surface finish */
.step-num { background: var(--finish); color: var(--finish-ink); box-shadow: 0 0 0 2px var(--panel), 0 0 0 3px var(--finish); }
.flow li + li::before { background: var(--trace); }
.seg button[aria-checked="true"] { background: var(--finish); color: var(--finish-ink); }

/* ---- bevelled corners (where supported; elsewhere the plain rounded corners stay) ---- */
@supports (corner-shape: bevel) {
  .btn, input[type="number"], select, .look, .seg, .advanced, .order-guide, .warnings li, .error-box,
  .spec-chip, .view-bar, .layer-dialog, .thumb, .strip canvas, .look-strip, .skip-link {
    corner-shape: bevel;
    border-radius: var(--bv) var(--bv-0) var(--bv-s) var(--bv-0);
  }
  .btn.small, .spec-chip, .look-strip, .thumb, .strip canvas { --bv: 5px; --bv-s: 2px; }
  .seg button:first-child { corner-shape: bevel; border-radius: calc(var(--bv) - 1px) 0 0 var(--bv-0); }
  .seg button:last-child { corner-shape: bevel; border-radius: 0 var(--bv-0) calc(var(--bv-s) - 1px) 0; }
  .cell { corner-shape: bevel; border-radius: 4px 1px 2px 1px; }
  .view-bar { --bv: 10px; --bv-s: 4px; }
  .export-dock .btn.wide { --bv: 9px; --bv-s: 4px; }
}

/* ---- a copper trace down the steps, with a via at each step; it lights up as steps are done ---- */
.step { position: relative; }
.step::before { content: ""; position: absolute; left: 6px; top: 26px; bottom: -26px; width: 2px; background: var(--trace-off); }
#step-board::before { content: none; }
.step::after { content: ""; position: absolute; left: 3px; top: 21px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--panel); box-shadow: inset 0 0 0 2px var(--trace-off); }
.step > h2 { position: relative; }
.step > h2::before { content: ""; position: absolute; left: -6px; top: 50%; width: 6px; height: 2px; margin-top: -1px; background: var(--trace-off); }
.step[data-done]::before, .step[data-done] > h2::before { background: var(--trace); }
.step[data-done]::after { box-shadow: inset 0 0 0 2px var(--finish); background: var(--finish); }

/* ---- net highlighting: one layer lit across the matrix and the thumbnails ---- */
.strip figure { transition: opacity .15s; }
.strip.net-active figure[data-layer]:not(.net-on) { opacity: .4; }
.strip figure.net-on canvas { box-shadow: 0 0 0 2px var(--finish); }
.col-label.net-on { background: var(--panel-2); }
.cell.net-on:not(:has(input:checked)) { border-color: var(--finish); border-style: solid; }
@media (prefers-reduced-motion: reduce) { .strip figure { transition: none; } }

.error-box[hidden] { display: none; }

/* ---- fewer words: labels live in icons and tooltips ---- */
.flow a { padding: 3px; }
.flow a .step-num { margin-right: 0; }
.export-spec { margin-top: 8px; }
.other-exports { margin-top: 8px; }
.order-link { display: inline-flex; align-items: center; gap: 5px; margin-left: auto; font-size: 12.5px; color: var(--accent); }
.order-link .i { width: 14px; height: 14px; }
.view-bar label .i { width: 15px; height: 15px; }
.view-bar label { gap: 5px; }
.seg button { padding: 5px 9px; }
.vb-note { display: inline-flex; align-items: center; gap: 5px; }
.vb-note .i { width: 13px; height: 13px; }
.empty p { display: inline-flex; align-items: center; gap: 8px; margin: 0; }
.empty .i { width: 18px; height: 18px; }
.strip figcaption { display: flex; align-items: center; gap: 5px; }
.strip figcaption .i { width: 13px; height: 13px; }
.cap-cu .i { color: var(--cu-on); }
.cap-mask .i { color: var(--mask-on); }
.cap-silk .i { color: var(--ink); }
@media (max-width: 719px), (max-height: 500px) {
  .flow { margin-left: auto; flex-basis: auto; }
}

/* ---- the viewport: a black window with bevelled corners, set into the white page ---- */
:root { --viewer: #050606; }
.layout { background: var(--panel); }
.viewer { margin: 12px 12px 0; overflow: hidden; border-radius: 10px; background: var(--viewer); box-shadow: 2px 2px 0 var(--edge-fr4); }
.view-bar { left: 14px; top: 14px; }
.strip { border-top: 0; }
@supports (corner-shape: bevel) {
  .viewer { corner-shape: bevel; border-radius: 22px 3px 12px 3px; }
}
@media (max-width: 719px), (max-height: 500px) {
  .viewer { margin: 10px 10px 0; }
  .controls { border-top: 0; margin-top: 10px; }
}
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.strip figure { position: relative; }
.vb-title { display: none; }

/* ---- sliders: a copper trace that runs up to a via (annular ring, drilled hole) ---- */
input[type="range"] {
  --tk: 3px; --th: 15px; --ring-w: 4px;
  --track: var(--trace-off); --fill-c: var(--trace); --ring: var(--finish); --hole: var(--panel); --via-edge: var(--edge-fr4);
  -webkit-appearance: none; appearance: none; height: 18px; margin: 0; padding: 0; background: transparent; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: var(--tk); border-radius: 0;
  background: linear-gradient(to right, var(--fill-c) var(--fill, 50%), var(--track) var(--fill, 50%));
}
input[type="range"]::-moz-range-track { height: var(--tk); background: var(--track); }
input[type="range"]::-moz-range-progress { height: var(--tk); background: var(--fill-c); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: var(--th); height: var(--th); margin-top: calc((var(--tk) - var(--th)) / 2);
  border: 0; border-radius: 50%; background: var(--hole); box-shadow: inset 0 0 0 var(--ring-w) var(--ring), 1px 1px 0 var(--via-edge);
}
input[type="range"]::-moz-range-thumb {
  width: var(--th); height: var(--th); border: 0; border-radius: 50%;
  background: var(--hole); box-shadow: inset 0 0 0 var(--ring-w) var(--ring), 1px 1px 0 var(--via-edge);
}
input[type="range"]:hover, input[type="range"]:active { --ring-w: calc(var(--th) / 2 - 2px); }
input[type="range"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
input[type="range"]:disabled { cursor: default; --ring: var(--ctl-line); --fill-c: var(--ctl-line); }
.tone .th { --tk: 2px; --th: 11px; --ring-w: 3px; height: 15px; }
.view-bar input[type="range"] { --track: var(--viewer-sep); --hole: var(--viewer-bar-solid); --via-edge: var(--edge-dark); }
.view-bar input[type="range"]:focus-visible { outline-color: var(--viewer-focus); }
@media (pointer: coarse) {
  input[type="range"] { --th: 22px; --ring-w: 6px; min-height: 32px; }
  .tone .th { --th: 20px; --ring-w: 5px; }
}
@media (prefers-reduced-motion: no-preference) {
  input[type="range"]::-webkit-slider-thumb { transition: box-shadow .12s; }
}

/* ---- checkboxes: an empty pad that gets plated (finish colour) when ticked ---- */
.row.check label { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; }
.row.check input[type="checkbox"] {
  -webkit-appearance: none; appearance: none; flex: none; width: 16px; height: 16px; margin: 0;
  border: 1.5px solid var(--ctl-line); border-radius: 3px; background: var(--panel-2);
  box-shadow: inset 1px 1px 0 var(--edge-mask); cursor: pointer;
}
.row.check input[type="checkbox"]:hover { border-color: var(--ink-2); }
.row.check input[type="checkbox"]:checked {
  border-color: var(--cu-edge); box-shadow: 1px 1px 0 var(--edge-fr4);
  background: var(--finish) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5' fill='none' stroke='%231d1a12' stroke-width='3.4' stroke-linecap='square'/%3E%3C/svg%3E") center / 12px no-repeat;
}
.row.check input[type="checkbox"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@supports (corner-shape: bevel) {
  .row.check input[type="checkbox"] { corner-shape: bevel; border-radius: 5px 1px 2px 1px; }
}
@media (pointer: coarse) {
  .row.check input[type="checkbox"] { width: 22px; height: 22px; }
  .row.check input[type="checkbox"]:checked { background-size: 16px; }
}
