/* ============ Fonts ============ */
/* 7-segment LCD face for the timer (DSEG by keshikan, SIL OFL 1.1 - fonts/DSEG-LICENSE.txt) */
@font-face {
  font-family: "DSEG7 Classic";
  src: url("../fonts/DSEG7Classic-BoldItalic.woff2") format("woff2");
  font-weight: 700;
  font-style: italic;
  font-display: block;
}
@font-face {
  font-family: "DSEG7 Classic";
  src: url("../fonts/DSEG7Classic-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: block;
}

/* ============ Tokens ============ */
/* Colour tokens live in themes.css (one block per colour scheme). */
:root {
  --radius: 12px;
  --font: "Roboto", system-ui, -apple-system, "Segoe UI", sans-serif;
  /* LCD face for the timer readout only */
  --timer-font: "DSEG7 Classic", "Roboto", system-ui, sans-serif;
}

/* ============ Base ============ */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 var(--font);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 14px; }
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
kbd {
  font: 12px var(--font);
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface);
}
code { font: 500 12px var(--font); }
.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;
}
.muted { color: var(--muted); }
.small { font-size: 12px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ============ Top bar ============ */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
  transition: opacity 0.2s;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px;
  background:
    linear-gradient(var(--surface) 0 0) 33.3% 0 / 1.5px 100% no-repeat,
    linear-gradient(var(--surface) 0 0) 66.6% 0 / 1.5px 100% no-repeat,
    linear-gradient(var(--surface) 0 0) 0 33.3% / 100% 1.5px no-repeat,
    linear-gradient(var(--surface) 0 0) 0 66.6% / 100% 1.5px no-repeat,
    var(--ink);
}
.tabs { display: flex; gap: 4px; padding: 3px; background: var(--surface-2); border-radius: 10px; }
.tab {
  border: 0; background: transparent; padding: 6px 14px; border-radius: 8px;
  color: var(--ink-2); font-weight: 500;
}
.tab[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.top-controls { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.select-wrap select, .field select {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23898781' stroke-width='1.5'/%3E%3C/svg%3E") right 10px center no-repeat;
  padding: 7px 30px 7px 12px;
  border-radius: 8px;
  max-width: 200px;
}
.icon-btn {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--ink-2);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn.ghost { border-color: transparent; background: transparent; }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg .fill { fill: currentColor; stroke: none; }
.link-btn {
  border: 0; background: none; padding: 2px 4px; color: var(--accent); font-weight: 500; border-radius: 4px;
}
.link-btn:hover { text-decoration: underline; }

/* ============ Views ============ */
.view { flex: 1; min-height: 0; }
.view[hidden] { display: none !important; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head.wrap { flex-wrap: wrap; align-items: flex-start; }
.card-head p { margin: 2px 0 0; }

/* ============ Timer view ============ */
body.at-timer { height: 100vh; height: 100dvh; overflow: hidden; }
.timer-view {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  padding: 16px;
}
.sidebar { display: flex; flex-direction: column; gap: 16px; min-height: 0; transition: opacity 0.2s; }
.stats-card { padding-bottom: 10px; }
.stats-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.stats-table th { font-weight: 500; color: var(--muted); font-size: 12px; text-align: right; padding: 2px 6px 6px; }
.stats-table th:first-child, .stats-table td:first-child { text-align: left; }
.stats-table td { padding: 4px 6px; text-align: right; border-top: 1px solid var(--grid); }
.stats-table td:first-child { color: var(--ink-2); font-weight: 500; }
.stats-table td.clickable { cursor: pointer; border-radius: 4px; }
.stats-table td.clickable:hover { background: var(--surface-2); }

.solves-card { flex: 1; min-height: 0; display: flex; flex-direction: column; padding-bottom: 8px; }
.solves-scroll { overflow-y: auto; flex: 1; min-height: 120px; margin: 0 -8px; padding: 0 8px; }
.solves-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.solves-table th {
  position: sticky; top: 0; background: var(--surface);
  font-weight: 500; color: var(--muted); font-size: 12px; text-align: right; padding: 2px 6px 6px;
}
.solves-table th:first-child, .solves-table td:first-child { text-align: left; color: var(--muted); }
.solves-table td { padding: 5px 6px; text-align: right; border-top: 1px solid var(--grid); }
.solves-table tbody tr { cursor: pointer; }
.solves-table tbody tr:hover td { background: var(--surface-2); }
.solves-table td.time { font-weight: 600; }
.solves-table td.pb::after { content: " PB"; font-size: 10px; font-weight: 600; color: var(--muted); }
.more-btn { display: block; margin: 8px auto; }
.empty-note { color: var(--muted); text-align: center; padding: 24px 8px; margin: 0; }

.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--stage);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  overflow: hidden;
}
.scramble-bar { display: flex; align-items: center; gap: 8px; transition: opacity 0.2s; }
.scramble-text {
  flex: 1;
  text-align: center;
  font: 500 22px/1.45 var(--font);
  letter-spacing: 0.01em;
  word-spacing: 0.18em;
  white-space: pre-line;
  overflow-wrap: anywhere;
  user-select: text;
}
.scramble-text.long { font-size: 17px; }
.scramble-text.xlong { font-size: 14px; }
.scramble-tools { display: flex; justify-content: center; gap: 8px; margin-top: 4px; transition: opacity 0.2s; }
.scramble-tools .link-btn { color: var(--muted); font-size: 12px; }

.timer-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  min-height: 220px;
}
/*
 * Optional display housing around the readout: the Competition scheme draws an
 * oval board with a blue rim and a logo under the digits. Other schemes leave
 * these tokens empty, so the wrapper is invisible.
 */
.timer-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: var(--timer-size);
  min-width: var(--display-min-width);
  padding: var(--display-pad);
  border: var(--display-rim-width) solid transparent;
  border-radius: 50%;
  background:
    linear-gradient(var(--display-face), var(--display-face)) padding-box,
    var(--display-rim) border-box;
  box-shadow: var(--display-shadow);
}
.display-logo {
  display: var(--display-logo);
  width: 3.4em;
  height: auto;
  margin-top: 0.2em;
}
.display-logo .logo-text { font: italic 700 28px var(--font); fill: #ffffff; }
.display-logo .logo-speed { fill: #f2c230; }
.display-logo .logo-swoosh { fill: #e2252b; }

/*
 * The readout can also be drawn as a display panel with a bezel and two
 * indicator LEDs (SpeedStacks, Competition). Plain schemes leave those tokens
 * transparent/0.
 */
.timer {
  --led-l: var(--led-off-l);
  --led-r: var(--led-off-r);
  position: relative;
  font: var(--timer-style) 700 var(--timer-size)/1 var(--timer-font);
  min-width: var(--timer-min-width);
  text-align: var(--timer-align);
  color: var(--timer-ink);
  text-shadow: var(--timer-glow);
  padding: var(--timer-pad-y) var(--timer-pad-x);
  border: solid transparent;
  border-width: var(--timer-bezel-y) var(--timer-bezel-x);
  border-radius: var(--timer-radius);
  background:
    radial-gradient(circle, var(--led-l) 0 45%, transparent 52%) left var(--led-inset) center / var(--led-size) var(--led-size) no-repeat border-box,
    radial-gradient(circle, var(--led-r) 0 45%, transparent 52%) right var(--led-inset) center / var(--led-size) var(--led-size) no-repeat border-box,
    linear-gradient(var(--timer-bg), var(--timer-bg)) padding-box,
    linear-gradient(var(--timer-bezel), var(--timer-bezel)) border-box;
  transition: color 0.08s;
}
/* Unlit display segments: a faint "8" behind every digit (set via data-ghost). */
.timer::before {
  content: var(--timer-ghost-content);
  content: var(--timer-ghost-content) / "";
  position: absolute;
  left: var(--timer-pad-x);
  right: var(--timer-pad-x);
  top: var(--timer-pad-y);
  text-align: inherit;
  opacity: var(--timer-ghost);
  text-shadow: none;
  pointer-events: none;
}
/* Out of flow so it never shifts the digits off their unlit segments. */
.timer-pen {
  position: absolute;
  margin-left: 0.06em;
  font: 700 0.4em/1 var(--font);
  vertical-align: top;
}
.timer.holding { color: var(--hold); --led-l: var(--led-on-l); }
.timer.ready { color: var(--ready); --led-r: var(--led-on-r); }
.timer.inspect { color: var(--timer-dim); }
.timer.inspect-warn { color: var(--timer-warn); }
.timer.inspect-late { color: var(--timer-late); --led-l: var(--led-on-l); }
.timer-hint { color: var(--muted); min-height: 20px; text-align: center; }
.last-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; transition: opacity 0.2s; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
}
.chip:hover { background: var(--surface-2); color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.chip.danger:hover { color: var(--danger); }
.quick-avgs {
  display: flex; gap: 22px; color: var(--ink-2); font-size: 15px; font-variant-numeric: tabular-nums;
  transition: opacity 0.2s;
}
.quick-avgs b { color: var(--ink); font-weight: 600; }

.type-form { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.type-form input {
  font: italic 700 56px/1.2 var(--timer-font);
  width: min(420px, 80vw);
  text-align: center;
  border: 0;
  border-bottom: 2px solid var(--grid);
  background: transparent;
  outline: none;
  padding: 4px;
}
.type-form input:focus { border-bottom-color: var(--accent); }
.type-form .hint { color: var(--muted); font-size: 12px; margin: 0; text-align: center; }

.preview {
  position: absolute;
  right: 16px;
  bottom: 14px;
  width: 210px;
  transition: opacity 0.2s;
}
.preview svg { display: block; width: 100%; height: auto; }
.preview .facelet { stroke: rgba(0, 0, 0, 0.55); stroke-width: 0.6; }

/* Metronome */
.icon-btn[aria-pressed="true"] { background: var(--surface-2); color: var(--ink); }
.icon-btn.playing { color: var(--accent); }
#metro-btn { position: relative; }
#metro-btn.playing::after {
  content: "";
  position: absolute; top: 5px; right: 5px;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
}
#metro-btn.tick::after { transform: scale(1.6); }
.metronome {
  position: absolute;
  left: 16px;
  bottom: 14px;
  width: 270px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: opacity 0.2s;
  z-index: 2;
}
.metro-head { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.metro-title { font-weight: 600; color: var(--ink-2); }
.metro-rate { color: var(--muted); font-variant-numeric: tabular-nums; }
.metro-dots { display: flex; gap: 5px; margin-left: auto; }
.metro-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--surface-3); }
.metro-dot.accent { box-shadow: inset 0 0 0 1.5px var(--muted); }
.metro-dot.on { background: var(--ink-2); box-shadow: none; }
.metro-dot.on.accent { background: var(--accent); }
.metro-close { width: 24px; height: 24px; margin: -4px -6px -4px 0; }
.metro-close svg { width: 14px; height: 14px; }
.metro-main { display: flex; align-items: center; gap: 6px; }
.metro-play {
  flex: none;
  display: grid; place-items: center;
  width: 38px; height: 38px; margin-right: 4px;
  border: 0; border-radius: 50%;
  background: var(--primary); color: var(--on-primary);
}
.metro-play:hover { opacity: 0.88; }
.metro-play svg { width: 16px; height: 16px; fill: currentColor; }
.metro-play .i-stop, .metro-play[aria-pressed="true"] .i-play { display: none; }
.metro-play[aria-pressed="true"] .i-stop { display: block; }
.metro-step {
  flex: none;
  width: 28px; height: 28px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--ink-2);
  font-size: 16px; line-height: 1;
}
.metro-step:hover { background: var(--surface-2); color: var(--ink); }
.metro-bpm { display: flex; flex-direction: column; align-items: center; line-height: 1.05; }
.metro-bpm input {
  width: 50px;
  padding: 0;
  border: 0; border-radius: 4px;
  background: transparent;
  text-align: center;
  font: 600 20px/1.1 var(--font);
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
  appearance: textfield;
}
.metro-bpm input::-webkit-inner-spin-button,
.metro-bpm input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.metro-bpm input:focus { outline: none; background: var(--surface-2); }
.metro-unit { font-size: 10px; color: var(--muted); letter-spacing: 0.04em; }
.metro-tap { margin-left: auto; }
.metro-range { width: 100%; margin: 0; accent-color: var(--ink-2); }
.metro-more summary {
  font-size: 12px; color: var(--muted); cursor: pointer; width: max-content;
  list-style: none;
}
.metro-more summary::-webkit-details-marker { display: none; }
.metro-more summary::before { content: "▸ "; }
.metro-more[open] summary::before { content: "▾ "; }
.metro-options {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 10px;
  align-items: center;
  margin: 6px 0 4px;
  font-size: 12px;
  color: var(--ink-2);
}
.metro-options select {
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); padding: 3px 6px; font-size: 12px;
}
.metro-check { grid-column: 1 / -1; display: flex; align-items: center; gap: 6px; }

/* Focus mode while solving / inspecting */
body.solving .topbar,
body.solving .sidebar,
body.solving .scramble-bar,
body.solving .scramble-tools,
body.solving .preview,
body.solving .metronome,
body.solving .last-actions,
body.solving .quick-avgs { opacity: 0; pointer-events: none; }
body.solving .stage { border-color: transparent; }

/* ============ History view ============ */
.history-view {
  padding: 16px 20px 40px;
  max-width: 1240px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
#history-content { display: flex; flex-direction: column; gap: 16px; }
.filter-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.field select { color: var(--ink); font-size: 14px; }
.filter-summary { margin: 0 0 8px auto; font-size: 13px; }
.empty-state { text-align: center; padding: 48px 16px; }
.empty-state p { margin: 6px 0 0; }

.kpis { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 12px; }
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-value { font-size: 24px; font-weight: 600; margin-top: 2px; letter-spacing: -0.01em; }
.kpi-sub { font-size: 12px; color: var(--ink-2); margin-top: 2px; }

.chart { width: 100%; min-height: 120px; }
.chart-svg { display: block; overflow: visible; }
.chart-svg:focus { outline: none; }
.chart-svg:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
.chart-foot { margin: 6px 0 0; }

.legend { display: flex; flex-wrap: wrap; gap: 6px; }
.legend-item {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 999px; padding: 4px 10px 4px 8px;
  font-size: 12px; color: var(--ink-2);
}
.legend-item:hover { background: var(--surface-2); }
.legend-item[aria-pressed="false"] { color: var(--muted); }
.legend-item[aria-pressed="false"] .legend-key { opacity: 0.25; }
.legend-key { display: inline-block; width: 14px; height: 2px; border-radius: 2px; background: var(--key); }
.legend-key.dot { width: 8px; height: 8px; border-radius: 50%; }

/* SVG chart marks */
.gridline { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.baseline { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-empty { fill: var(--muted); font-size: 13px; }
.dot-single { fill: var(--single); stroke: var(--surface); stroke-width: 2; }
.dots.dense .dot-single { stroke-width: 0; opacity: 0.75; }
.dot-pb { fill: var(--ink); stroke: var(--surface); stroke-width: 1.5; opacity: 1 !important; }
.dot-clipped { fill: var(--muted); }
.dnf-mark { fill: var(--muted); font-size: 12px; font-weight: 600; }
.series-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.end-dot { stroke: var(--surface); stroke-width: 2; }
.end-label { fill: var(--ink); font-size: 11px; font-variant-numeric: tabular-nums; font-weight: 600; }
.end-name { fill: var(--muted); font-weight: 500; }
.crosshair { stroke: var(--ink-2); stroke-width: 1; shape-rendering: crispEdges; pointer-events: none; }
.hover-dot { stroke: var(--surface); stroke-width: 2; pointer-events: none; }
.hover-dot.single { fill: var(--single); }
.hover-marks { pointer-events: none; }
.overlay { fill: transparent; cursor: crosshair; }
.bars .bar { transition: opacity 0.1s; }
.bars.has-active .bar:not(.active) { opacity: 0.45; }
.bar-overflow { opacity: 0.6; }
.ref-line { stroke: var(--ink-2); stroke-width: 1; shape-rendering: crispEdges; }
.ref-label { fill: var(--ink); font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }
.ref-name { fill: var(--muted); font-weight: 500; }
.whisker { stroke: var(--ink-2); stroke-width: 1.5; }
.box { opacity: 0.35; }
.box-median { stroke: var(--ink); stroke-width: 2; }
.boxplot .overlay { cursor: default; }

/* Tables */
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.data-table th {
  text-align: left; font-weight: 500; color: var(--muted); font-size: 12px;
  padding: 6px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap;
}
.data-table td { padding: 6px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table .num { text-align: right; }
.data-table td.label { color: var(--ink-2); }
.data-table tbody tr.active td { background: var(--surface-2); }
.dist-table { margin-top: 12px; }
.dist-table .bar-col { width: 34%; min-width: 120px; }
.dist-bar { height: 8px; border-radius: 0 4px 4px 0; background: var(--s1); min-width: 1px; }
.dist-table td.zero { color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* Tooltip */
.tooltip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 8px 10px;
  font-size: 12px;
  min-width: 150px;
  font-variant-numeric: tabular-nums;
}
.tip-head { color: var(--muted); margin-bottom: 4px; white-space: nowrap; }
.tip-row { display: flex; align-items: center; gap: 8px; padding: 1px 0; white-space: nowrap; }
.tip-row strong { color: var(--ink); font-weight: 600; }
.tip-label { color: var(--ink-2); }
.tip-key { width: 12px; flex: none; }
.tip-key-line { height: 2px; border-radius: 2px; background: var(--key); }
.tip-key-dot { width: 8px; height: 8px; margin: 0 2px; border-radius: 50%; background: var(--key); }
.tip-key-bar { width: 10px; height: 10px; margin: 0 1px; border-radius: 2px; background: var(--key); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--primary); color: var(--on-primary);
  padding: 8px 16px; border-radius: 8px; font-size: 13px; z-index: 60;
  box-shadow: var(--shadow);
}

/* Modal */
.modal {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  box-shadow: var(--shadow);
}
.modal::backdrop { background: rgba(0, 0, 0, 0.35); }
.modal-inner { display: flex; flex-direction: column; max-height: calc(100dvh - 50px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px 20px; }
.modal-head h2 { font-size: 16px; }
.modal-body { padding: 6px 20px 20px; overflow-y: auto; }
.modal-body .big-time { font-size: 44px; font-weight: 600; letter-spacing: -0.02em; margin: 4px 0 8px; }
.modal-body .meta { color: var(--muted); font-size: 12px; margin-bottom: 12px; }
.modal-body .scr { font-size: 15px; line-height: 1.5; white-space: pre-line; background: var(--surface-2); padding: 10px 12px; border-radius: 8px; margin: 0 0 12px; overflow-wrap: anywhere; }
.modal-body textarea, .modal-body input[type="text"] {
  width: 100%; border: 1px solid var(--border); border-radius: 8px; background: var(--page);
  padding: 8px 10px; resize: vertical;
}
.modal-body .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 12px 0; }
.modal-body .row.end { justify-content: flex-end; }
.modal-body .preview-inline { width: 200px; margin: 0 0 12px; }
.modal-body .preview-inline svg { width: 100%; height: auto; display: block; }
.modal-body .preview-inline .facelet { stroke: rgba(0, 0, 0, 0.55); stroke-width: 0.6; }
.btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
  padding: 7px 14px; font-weight: 500;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.btn.primary:hover { opacity: 0.88; }
.btn.danger { color: var(--danger); }
.avg-list { font-variant-numeric: tabular-nums; line-height: 1.8; margin: 0 0 12px; padding-left: 26px; }
.avg-list .trimmed { color: var(--muted); }
.settings-grid { display: grid; grid-template-columns: 1fr auto; gap: 12px 16px; align-items: center; margin: 4px 0 16px; }
.settings-grid label { color: var(--ink-2); }
.settings-grid select { border: 1px solid var(--border); background: var(--surface); padding: 6px 10px; border-radius: 8px; }
.settings-section { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin: 18px 0 8px; }
.session-list { list-style: none; padding: 0; margin: 0 0 12px; }
.session-list li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--grid); }
.session-list li .grow { flex: 1; }
.session-list li.current .grow { font-weight: 600; }

/* Colour-scheme chooser: each card carries its own data-theme, so its
   contents render in that scheme's tokens. --ring comes from the page scheme. */
.scheme-grid {
  --ring: var(--ink);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin: 4px 0 8px;
}
.scheme-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--page);
  color: var(--ink);
  text-align: left;
}
.scheme-card:hover { box-shadow: 0 0 0 1px var(--ring); }
.scheme-card[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--ring); }
.scheme-window {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--stage);
}
/* Chooser previews: Competition's wide oval needs a smaller size to fit its card. */
.scheme-window { --timer-size: var(--preview-size); }
.scheme-keys { display: flex; gap: 6px; align-items: center; }
.scheme-keys span { width: 14px; height: 3px; border-radius: 2px; }
.scheme-keys .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--single); }
.scheme-name { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 500; padding: 0 2px; }
.scheme-name .check { visibility: hidden; font-weight: 700; }
.scheme-card[aria-pressed="true"] .check { visibility: visible; }
.scheme-auto { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; color: var(--ink-2); }

/* ============ Responsive ============ */
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 980px) {
  body.at-timer { height: auto; overflow: visible; }
  .timer-view { grid-template-columns: 1fr; }
  .stage { order: -1; min-height: 78vh; min-height: 78dvh; }
  .sidebar { display: grid; grid-template-columns: 1fr 1fr; }
  .solves-card { max-height: 420px; }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .topbar { padding: 8px 16px; gap: 8px 10px; }
  .brand > span:last-child { display: none; }
  .tabs { flex: 1; }
  .tab { flex: 1; padding: 6px 8px; }
  .top-controls { width: 100%; margin-left: 0; flex-wrap: nowrap; gap: 6px; }
  .select-wrap { flex: 1; min-width: 0; }
  .select-wrap select { width: 100%; max-width: none; }
  .icon-btn { flex: none; }
  .dist-table .bar-col, .dist-table td:last-child { display: none; }
  .dist-table th, .dist-table td { padding: 6px 6px; }
  .timer-view { padding: 12px 16px; gap: 12px; }
  .stage { padding: 14px 12px; }
  .scramble-text { font-size: 18px; }
  .preview { position: static; width: 170px; margin: 8px auto 0; }
  .metronome { position: static; width: 100%; max-width: 340px; margin: 8px auto 0; }
  .sidebar { grid-template-columns: 1fr; }
  .history-view { padding: 12px 16px 32px; }
  .filter-summary { margin-left: 0; width: 100%; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
