/* CubeSolve — cool plastic greys, slate ink, the six sticker colours used only to carry meaning */
:root {
  --paper: #e3e6e9;
  --panel: #f3f4f6;
  --panel-2: #eaedf0;
  --ink: #1b1f27;
  --ink-2: #5a626e;
  --line: #c6cbd2;
  --line-2: #d8dce1;

  --c-w: #f6f6f1; --c-y: #ffd31a; --c-g: #009e60; --c-b: #0a52be; --c-r: #c8102e; --c-o: #ff6a13;
  --stage-cross: #c8102e;
  --stage-f2l: #009e60;
  --stage-oll: #e2b400;
  --stage-pll: #0a52be;
  --stage-zbll: #ff6a13;
  --stage-other: #5a626e;
  --focus: #0a52be;
  --surface: #fff; --on-ink: #fff; --ink-hover: #2c3240; --frame: #1b1f27; --ink-fixed: #1b1f27; --disabled: #9aa1ab;
  --bad-fg: #9c1022; --bad-bg: #fbe9eb; --bad-line: #efc1c8; --good-fg: #0b6b3f;
  --hold-bg: #f6d9dd; --ready-bg: #d4efe2; --ready-fg: #00714a; --insp-fg: #a36200;
  --chart-a5: var(--c-b); --chart-a12: var(--c-r);
  --shadow: 0 30px 80px rgba(20, 25, 35, .35); --scrim: rgba(27, 31, 39, .45);
  color-scheme: light;

  --r-s: 5px; --r-m: 9px; --r-l: 14px;
  --font: 'Archivo', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
/* dark theme — set by js (data-theme) so "auto" follows the system */
:root[data-theme="dark"] {
  --paper: #12151a; --panel: #1b1f26; --panel-2: #232830; --ink: #e9ecf0; --ink-2: #9ba4b0; --line: #3a414c; --line-2: #2a303a;
  --surface: #262b34; --on-ink: #12151a; --ink-hover: #fff; --frame: #0a0c0f; --disabled: #4a515c; --focus: #7db4ff;
  --bad-fg: #ffb4be; --bad-bg: #3a1a20; --bad-line: #6b2a35; --good-fg: #5fd09b;
  --hold-bg: #3c1d23; --ready-bg: #17382b; --ready-fg: #5fd09b; --insp-fg: #f0b429;
  --chart-a5: #6ba6ff; --chart-a12: #ff7a8a;
  --shadow: 0 30px 80px rgba(0, 0, 0, .6); --scrim: rgba(0, 0, 0, .65);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--font); font-size: 15px; line-height: 1.5;
  font-variation-settings: 'wdth' 100;
}
h1, h2, h3 { margin: 0; line-height: 1.15; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
kbd { font: inherit; font-size: 12px; padding: 1px 6px; border-radius: 4px; border: 1px solid currentColor; opacity: .7; margin-left: 6px; }
[hidden] { display: none !important; }

/* ------------------------------------------------ top bar */
.topbar {
  display: flex; align-items: center; gap: 28px;
  padding: 14px clamp(14px, 3vw, 32px);
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); }
.brand-mark { display: grid; grid-template-columns: repeat(3, 8px); gap: 2px; padding: 3px; background: var(--frame); border-radius: 5px; }
.brand-mark i { width: 8px; height: 8px; border-radius: 2px; background: var(--c-y); }
.brand-mark i:nth-child(2) { background: var(--c-r); } .brand-mark i:nth-child(4) { background: var(--c-g); }
.brand-mark i:nth-child(6) { background: var(--c-b); } .brand-mark i:nth-child(8) { background: var(--c-o); }
.brand-mark i:nth-child(9) { background: var(--c-w); }
.brand-word { font-size: 22px; font-weight: 850; font-variation-settings: 'wdth' 125; letter-spacing: -0.01em; }
.tabs { display: flex; gap: 4px; }
.tabs button {
  border: 0; background: transparent; padding: 8px 14px; border-radius: var(--r-m);
  font-weight: 600; color: var(--ink-2); cursor: pointer;
}
.tabs button:hover { color: var(--ink); background: var(--panel-2); }
.tabs button[aria-selected="true"] { color: var(--ink); background: var(--panel); box-shadow: inset 0 -3px 0 var(--ink); }

main { padding: clamp(14px, 2.4vw, 28px) clamp(14px, 3vw, 32px) 48px; max-width: 1480px; margin: 0 auto; }
.panel { background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--r-l); }

/* ------------------------------------------------ buttons */
.btn {
  border: 1px solid var(--line); background: var(--panel); padding: 8px 14px; border-radius: var(--r-m);
  font-weight: 600; cursor: pointer; line-height: 1.2;
}
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.btn.primary:hover { background: var(--ink-hover); }
.btn.primary:disabled { background: var(--disabled); border-color: var(--disabled); cursor: not-allowed; }
.btn.big { padding: 12px 20px; font-size: 16px; }
.btn.wide { width: 100%; }
.ibtn {
  width: 40px; height: 40px; display: grid; place-items: center; border-radius: var(--r-m);
  border: 1px solid var(--line); background: var(--panel); cursor: pointer; padding: 0;
}
.ibtn svg { width: 18px; height: 18px; fill: currentColor; }
.ibtn:hover { border-color: var(--ink-2); }
.ibtn.play { width: 52px; height: 52px; background: var(--ink); color: var(--on-ink); border-color: var(--ink); border-radius: 50%; }
.ibtn.play svg { width: 22px; height: 22px; }
.ibtn .i-pause { display: none; }
.ibtn.playing .i-play { display: none; } .ibtn.playing .i-pause { display: block; }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; user-select: none; }
.toggle input { width: 16px; height: 16px; accent-color: var(--ink); }
select, input[type=text], input[type=search] {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: var(--r-m); padding: 8px 10px; min-width: 0;
}

.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--r-m); padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 7px 14px; border-radius: 7px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.seg button:hover { color: var(--ink); }
.seg button[aria-checked="true"], .seg button[aria-selected="true"] { background: var(--ink); color: var(--on-ink); }

/* ------------------------------------------------ scan */
.scan-layout { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(330px, 1fr); gap: 20px; align-items: start; }
.camera-panel { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.scan-instruction h1 { font-size: clamp(26px, 3.2vw, 38px); font-weight: 850; font-variation-settings: 'wdth' 122; letter-spacing: -0.015em; margin: 8px 0 6px; }
.scan-instruction p { margin: 0 0 12px; color: var(--ink-2); max-width: 62ch; }
.face-dots { display: flex; gap: 6px; }
.face-dots span { width: 26px; height: 6px; border-radius: 3px; background: var(--line); }
.face-dots span.done { background: var(--ink-2); }
.face-dots span.current { background: var(--ink); }
.orient { display: flex; flex-wrap: wrap; gap: 10px 22px; }
.orient-item { display: inline-flex; align-items: center; gap: 9px; font-weight: 600; }
.swatch { width: 22px; height: 22px; border-radius: 5px; border: 2px solid var(--ink); display: inline-block; background: var(--line); }

.camera-stage { position: relative; aspect-ratio: 4 / 3; background: #2a2f37; border-radius: var(--r-m); overflow: hidden; }
.camera-stage video, .camera-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.camera-empty {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  color: #e9ecef; text-align: center; padding: 24px;
  background: repeating-linear-gradient(0deg, transparent 0 calc(33.33% - 1px), rgba(255,255,255,.06) calc(33.33% - 1px) 33.33%),
              repeating-linear-gradient(90deg, transparent 0 calc(33.33% - 1px), rgba(255,255,255,.06) calc(33.33% - 1px) 33.33%), #2a2f37;
}
.camera-empty p { max-width: 40ch; margin: 0; }
.camera-empty .btn.primary { background: #fff; color: var(--ink-fixed); border-color: #fff; }
.camera-empty #camError { color: #ffb4a8; }
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.flash.go { animation: flash .35s ease-out; }
@keyframes flash { from { opacity: .7; } to { opacity: 0; } }
.camera-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; }

.net-panel { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.net-head h2 { font-size: 20px; font-weight: 800; font-variation-settings: 'wdth' 115; margin-bottom: 4px; }
.net-head p { margin: 0; }
.net {
  display: grid; grid-template-columns: repeat(4, 1fr); grid-template-areas: ". U . ." "L F R B" ". D . .";
  gap: 6px; max-width: 460px;
}
.face { display: flex; flex-direction: column; gap: 3px; }
.face-label {
  border: 0; background: none; padding: 0 2px; text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-2); cursor: pointer;
  border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.face-label:hover { color: var(--ink); text-decoration: underline; }
.face.current .face-label { color: var(--ink); }
.face-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; background: var(--frame); padding: 3px; border-radius: 7px; outline: 3px solid transparent; outline-offset: 2px; }
.face.current .face-grid { outline-color: var(--focus); }
.st { aspect-ratio: 1; border: 0; border-radius: 3px; padding: 0; cursor: pointer; background: #7a818b; position: relative; }
.st.empty { background: repeating-linear-gradient(45deg, #6b727c 0 3px, #757c86 3px 6px); }
.st.center::after { content: ''; position: absolute; inset: 34%; border-radius: 50%; background: rgba(0,0,0,.18); }
.st:hover { filter: brightness(1.08); box-shadow: inset 0 0 0 2px rgba(255,255,255,.7); }
.palette { display: flex; gap: 8px; flex-wrap: wrap; }
.pal { width: 38px; height: 38px; border-radius: 8px; border: 2px solid var(--line); cursor: pointer; padding: 0; }
.pal[aria-checked="true"] { border-color: var(--ink); box-shadow: 0 0 0 3px var(--panel), 0 0 0 5px var(--ink); }
.net-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.scramble-form label { font-weight: 600; font-size: 14px; display: block; margin-bottom: 6px; }
.scramble-form .row { display: flex; gap: 8px; }
.scramble-form input { flex: 1; }
.scramble-form p { margin: 6px 0 0; }
.validation { font-size: 14px; }
.validation:empty { display: none; }
.validation.bad { color: var(--bad-fg); background: var(--bad-bg); border: 1px solid var(--bad-line); padding: 10px 12px; border-radius: var(--r-m); }
.validation.good { color: var(--good-fg); }
.validation ul { margin: 4px 0 0 18px; padding: 0; }

/* ------------------------------------------------ solve */
.method-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px; margin-bottom: 8px; }
.method-opts { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; font-size: 14px; }
.method-opts label { display: inline-flex; align-items: center; gap: 8px; }
.method-desc { margin: 0 0 16px; color: var(--ink-2); max-width: 80ch; }
.solve-layout { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(320px, 1fr); gap: 20px; align-items: start; }
.stage-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.viewer-wrap { position: relative; overflow: hidden; }
.viewer { height: clamp(320px, 52vh, 560px); cursor: grab; }
.viewer canvas.dragging { cursor: grabbing; }
.viewer-hint { position: absolute; left: 16px; bottom: 10px; pointer-events: none; }

.now { display: flex; align-items: center; gap: 22px; padding: 14px 20px; min-height: 104px; }
.now-move {
  font-size: 66px; font-weight: 900; font-variation-settings: 'wdth' 125; line-height: 1; min-width: 2.4ch; text-align: center;
  letter-spacing: -0.02em; color: var(--ink);
}
.now-move.done { font-size: 34px; }
.now-info { min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.now-step { font-weight: 700; font-size: 16px; }
.now-step .stage-tag, .step-title .stage-tag { margin-right: 8px; }
.queue { display: flex; gap: 5px; flex-wrap: nowrap; overflow: hidden; mask-image: linear-gradient(90deg, #000 75%, transparent); }

.mv {
  display: inline-grid; place-items: center; min-width: 34px; height: 30px; padding: 0 7px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 700; font-variation-settings: 'wdth' 110; font-size: 15px; cursor: pointer;
  color: var(--ink);
}
.mv:hover { border-color: var(--ink); }
.mv.rot { background: var(--panel-2); color: var(--ink-2); font-style: italic; }
.mv.done { color: var(--ink-2); border-color: var(--line-2); background: transparent; }
.mv.next { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.queue .mv { cursor: default; }

.transport { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 16px 22px; padding: 12px 18px; }
.tbtns { display: flex; align-items: center; gap: 8px; }
.progress input { width: 100%; accent-color: var(--ink); }
.progress-label { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.speed { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--ink-2); }
.speed input { width: 110px; accent-color: var(--ink); }

.steps-col { padding: 6px 0 10px; max-height: calc(100vh - 150px); overflow: auto; position: sticky; top: 84px; }
.summary { padding: 14px 20px 12px; border-bottom: 1px solid var(--line-2); }
.summary .big { font-size: 34px; font-weight: 850; font-variation-settings: 'wdth' 118; line-height: 1; }
.summary .row { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.summary .stagebar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; margin-top: 12px; gap: 2px; }
.summary .stagebar span { display: block; }
.summary .legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: 13px; color: var(--ink-2); }
.summary .legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: 0; }
.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; }
.step { padding: 12px 20px 14px 20px; border-left: 4px solid transparent; position: relative; }
.step + .step { border-top: 1px solid var(--line-2); }
.step.active { background: var(--surface); border-left-color: var(--stage, var(--ink)); }
.step-head { display: flex; align-items: flex-start; gap: 10px; }
.step-num { counter-increment: step; font-size: 12px; color: var(--ink-2); min-width: 22px; padding-top: 3px; font-variant-numeric: tabular-nums; }
.step-num::before { content: counter(step); }
.step-title { font-weight: 700; flex: 1; min-width: 0; }
.step-count { font-size: 12px; color: var(--ink-2); white-space: nowrap; padding-top: 3px; }
.stage-tag { display: inline-block; font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 10px; color: #fff; background: var(--stage, var(--ink-2)); vertical-align: 1px; }
.stage-tag.light { color: var(--ink-fixed); }
.step-note { font-size: 13.5px; color: var(--ink-2); margin: 4px 0 8px 32px; max-width: 60ch; }
.step-body { display: flex; gap: 12px; align-items: flex-start; margin-left: 32px; }
.step-moves { display: flex; flex-wrap: wrap; gap: 5px; flex: 1; }
.step-thumb { flex: none; border-radius: 6px; cursor: pointer; background: none; border: 0; padding: 0; }
.step-thumb svg { display: block; }
.empty-state { padding: 40px 24px; text-align: center; color: var(--ink-2); }
.empty-state .btn { margin: 14px 4px 0; }

/* ------------------------------------------------ library */
.lib-head { display: flex; flex-direction: column; gap: 12px; margin-bottom: 10px; }
.lib-tools { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between; }
.lib-tools input[type=search] { width: min(320px, 100%); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 16px; padding: 4px 12px; font-size: 13.5px; font-weight: 600; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.lib-desc { color: var(--ink-2); margin: 4px 0 18px; max-width: 80ch; }
.lib-group { margin-bottom: 26px; }
.lib-group h3 { font-size: 17px; font-weight: 800; font-variation-settings: 'wdth' 112; margin: 0 0 10px; display: flex; align-items: baseline; gap: 10px; }
.lib-group h3 .muted { font-weight: 500; font-size: 13px; font-variation-settings: 'wdth' 100; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.card {
  display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: center; text-align: left;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--r-m); padding: 10px 12px; cursor: pointer;
}
.card:hover { border-color: var(--ink-2); background: var(--surface); }
.card svg { display: block; }
.card-name { font-weight: 800; font-variation-settings: 'wdth' 110; }
.card-nick { font-size: 12.5px; color: var(--ink-2); }
.card-alg { font-size: 13.5px; margin-top: 4px; line-height: 1.35; word-spacing: 1px; font-weight: 500; }
.card-alts { font-size: 12px; color: var(--ink-2); margin-top: 3px; }

/* ------------------------------------------------ dialog */
.alg-dialog { width: min(880px, calc(100vw - 24px)); border: 0; border-radius: var(--r-l); padding: 0; background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
.alg-dialog::backdrop { background: var(--scrim); }
.dlg-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 18px 20px 6px; }
.dlg-head h2 { font-size: 24px; font-weight: 850; font-variation-settings: 'wdth' 118; }
.dlg-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; padding: 8px 20px 20px; }
.dlg-viewer { height: 340px; background: var(--panel-2); border-radius: var(--r-m); }
.dlg-side { display: flex; flex-direction: column; gap: 14px; }
.dlg-moves { display: flex; flex-wrap: wrap; gap: 5px; }
.small-t .ibtn.play { width: 46px; height: 46px; }
.alt-list { display: flex; flex-direction: column; gap: 6px; }
.alt-list h4 { margin: 0; font-size: 13px; color: var(--ink-2); font-weight: 600; }
.alt { text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-s); padding: 6px 10px; cursor: pointer; font-size: 13.5px; }
.alt[aria-current="true"] { border-color: var(--ink); box-shadow: inset 3px 0 0 var(--ink); }

/* ------------------------------------------------ responsive */
@media (max-width: 980px) {
  .scan-layout, .solve-layout { grid-template-columns: 1fr; }
  .steps-col { position: static; max-height: none; }
  .transport { grid-template-columns: 1fr; justify-items: center; }
  .progress { width: 100%; }
}
@media (max-width: 640px) {
  .topbar { gap: 10px; padding: 10px 12px; }
  .brand { gap: 8px; }
  .brand-word { font-size: 17px; }
  .tabs button { padding: 7px 10px; }
  .viewer { height: 330px; }
  .seg button { padding: 6px 10px; font-size: 14px; }
  .now-move { font-size: 48px; }
  .dlg-body { grid-template-columns: 1fr; }
  .dlg-viewer { height: 260px; }
  .net { gap: 4px; }
}
@media (prefers-reduced-motion: reduce) {
  .flash.go { animation: none; }
}
@media (max-width: 400px) { .brand-word { display: none; } }

/* ------------------------------------------------ timer */
.row { display: flex; align-items: center; gap: 8px; } .row.between { justify-content: space-between; } .row.wrap { flex-wrap: wrap; }
.row.gap { gap: 8px; }
.timer-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.timer-main, .timer-side { display: grid; gap: 14px; min-width: 0; }
.scr-panel { padding: 14px 16px; display: grid; gap: 12px; }
.scr-row { display: flex; gap: 14px; align-items: flex-start; justify-content: space-between; }
.scr-text { font-size: clamp(17px, 2.4vw, 24px); font-weight: 650; letter-spacing: .02em; line-height: 1.45; word-spacing: .22em; font-variant-numeric: tabular-nums; }
.scr-btns { display: flex; gap: 6px; flex-shrink: 0; }
.scr-net { display: grid; grid-template-columns: repeat(12, 1fr); width: min(100%, 300px); gap: 1px; margin: 0 auto 0 0; }
.scr-net i { aspect-ratio: 1; border-radius: 2px; border: 1px solid rgba(0,0,0,.4); }
.scr-net i.gap { border-color: transparent; background: transparent !important; }
.timer-pad {
  min-height: clamp(220px, 38vh, 380px); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; text-align: center; user-select: none; -webkit-user-select: none; touch-action: manipulation; cursor: pointer;
  transition: background .12s, border-color .12s; border-width: 2px;
}
.tm-phase { color: var(--ink-2); font-size: 14px; font-weight: 600; min-height: 1.4em; }
.tm-display { font-size: clamp(64px, 14vw, 150px); font-weight: 800; font-variant-numeric: tabular-nums; font-variation-settings: 'wdth' 100; line-height: 1; letter-spacing: -0.02em; }
.tm-sub { min-height: 1.4em; font-weight: 600; color: var(--bad-fg); }
.timer-pad.holding { background: var(--hold-bg); border-color: var(--c-r); }
.timer-pad.ready { background: var(--ready-bg); border-color: var(--c-g); }
.timer-pad.ready .tm-display { color: var(--ready-fg); }
.timer-pad.insp .tm-display { color: var(--insp-fg); }
.timer-pad.running { background: var(--surface); border-color: var(--ink); }
body.timing .topbar, body.timing .scr-panel, body.timing .chart-panel, body.timing .timer-side, body.timing .last-panel { visibility: hidden; }
body.timing .timer-layout { grid-template-columns: 1fr; }
.last-panel { padding: 10px 14px; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; font-weight: 650; }
.last-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.btn.on { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.toast { padding: 9px 14px; border-radius: var(--r-m); background: var(--ink); color: var(--on-ink); font-weight: 600; display: flex; align-items: center; gap: 10px; }
.toast .btn { padding: 4px 10px; }
.chart-panel { padding: 12px 14px 8px; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.chart-head h3 { font-size: 15px; }
.legend { display: inline-flex; align-items: center; gap: 6px; }
.lg { display: inline-block; vertical-align: middle; }
.lg.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-2); }
.lg.a5 { width: 18px; height: 0; border-top: 3px solid var(--chart-a5); margin-left: 8px; }
.lg.a12 { width: 18px; height: 0; border-top: 3px dashed var(--chart-a12); margin-left: 8px; }
#tmChart { width: 100%; height: auto; display: block; }
.ch-grid { stroke: var(--line-2); stroke-width: 1; }
.ch-lab { fill: var(--ink-2); font-size: 11px; }
.ch-dot { fill: var(--ink-2); } .ch-dot:hover { fill: var(--ink); r: 4.5; }
.ch-a5 { fill: none; stroke: var(--chart-a5); stroke-width: 2.2; stroke-linejoin: round; }
.ch-a12 { fill: none; stroke: var(--chart-a12); stroke-width: 2.2; stroke-dasharray: 6 4; stroke-linejoin: round; }
.ch-dnf { fill: var(--chart-a12); font-size: 14px; font-weight: 700; }
.ch-empty { fill: var(--ink-2); font-size: 14px; }
.tm-card { padding: 12px 14px; display: grid; gap: 10px; }
.tm-card select { flex: 1; }
.stat-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.stat-table th, .stat-table td { padding: 5px 4px; text-align: right; border-bottom: 1px solid var(--line-2); font-size: 14px; }
.stat-table th:first-child { text-align: left; font-weight: 700; }
.stat-table thead th { color: var(--ink-2); font-size: 12px; font-weight: 600; }
.stat-table td { font-weight: 650; }
.summary-line { display: flex; gap: 14px; flex-wrap: wrap; }
.add-form { display: grid; gap: 6px; } .add-form input { flex: 1; }
.err { color: var(--bad-fg); margin: 0; min-height: 1.2em; }
.list-head, .solve-row { display: grid; grid-template-columns: 38px 1fr 64px 64px; gap: 4px; text-align: right; font-variant-numeric: tabular-nums; }
.list-head { font-size: 12px; font-weight: 600; color: var(--ink-2); padding: 0 6px; }
.list-head span:first-child, .list-head span:nth-child(2) { text-align: left; }
.solve-list { list-style: none; margin: 0; padding: 0; max-height: 300px; overflow: auto; }
.solve-row { width: 100%; border: 0; background: transparent; padding: 6px; border-radius: var(--r-s); cursor: pointer; font-size: 14px; text-align: right; }
.solve-row:hover { background: var(--panel-2); }
.solve-row .n { text-align: left; color: var(--ink-2); } .solve-row .t { text-align: left; font-weight: 700; } .solve-row .a { color: var(--ink-2); }
.solve-row.dnf .t { color: var(--bad-fg); } .solve-row em { font-style: normal; color: var(--ink-2); }
.settings summary { cursor: pointer; font-weight: 700; }
.settings[open] summary { margin-bottom: 4px; }
.field { display: grid; gap: 4px; font-size: 14px; }
.file-btn { cursor: pointer; display: inline-block; }
.tm-dialog { width: min(440px, 94vw); }
.tm-dbody { display: grid; gap: 12px; padding: 4px 18px 18px; }
.tm-dtime { font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; }
.tm-dscr { font-weight: 600; line-height: 1.5; word-spacing: .2em; background: var(--panel-2); padding: 10px; border-radius: var(--r-m); }
@media (max-width: 980px) { .timer-layout { grid-template-columns: 1fr; } .solve-list { max-height: 240px; } }
@media (max-width: 640px) { .scr-row { flex-direction: column; } .scr-net { width: 100%; } }


/* ------------------------------------------------ theme toggle */
.theme-btn { margin-left: auto; flex-shrink: 0; width: 38px; height: 38px; }
.theme-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; display: none; }
.theme-btn[data-pref="auto"] .i-auto, .theme-btn[data-pref="light"] .i-light, .theme-btn[data-pref="dark"] .i-dark { display: block; }

/* ------------------------------------------------ fitting: keep the controls on screen */
@media (min-width: 981px) {
  /* camera preview never taller than what is left under the header, so Capture stays visible */
  .camera-stage { width: min(100%, calc((100dvh - 370px) * 4 / 3)); min-width: min(100%, 320px); margin-inline: auto; }
  .viewer { height: clamp(260px, calc(100dvh - 440px), 580px); }
  .steps-col { max-height: calc(100dvh - 150px); }
}
@media (max-width: 980px) {
  .scan-layout, .solve-layout { grid-template-columns: minmax(0, 1fr); }
  .viewer { height: clamp(240px, 42dvh, 400px); }
  .transport { position: sticky; bottom: 8px; z-index: 6; box-shadow: 0 6px 24px rgba(0, 0, 0, .18); }
}
@media (max-width: 640px) {
  .viewer { height: clamp(230px, 38dvh, 340px); }
  main { overflow-x: clip; }
}
.timer-pad { min-height: clamp(200px, 36dvh, 380px); }
@media (min-width: 641px) {
  .scr-panel { grid-template-columns: minmax(0, 1fr) auto; align-items: start; }
  .scr-net { width: 200px; margin: 0; grid-column: 2; grid-row: 1 / span 1; }
  .scr-row { grid-column: 1; }
}
@media (max-height: 560px) and (min-width: 700px) { .timer-pad { min-height: 150px; } .tm-display { font-size: clamp(48px, 18vh, 100px); } }

.scr-row { flex-direction: column; gap: 10px; }
@media (min-width: 641px) { .scr-net { width: 190px; } }
