:root {
  --paper: #e3e7e1;
  --paper-raised: #eef1ec;
  --ink: #1c2226;
  --ink-soft: #4d575c;
  --rule: #b3bbb2;
  --sky-high: #93afc4;
  --sky-low: #dfe7ec;
  --signal: #f5b700;
  --wrong: #c9322b;
  --right: #17834a;

  --display: "Barlow Condensed", "Arial Narrow", sans-serif;
  --text: "Barlow", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--paper); color: var(--ink); font: 400 16px/1.5 var(--text); }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--signal); outline-offset: 2px; }
a { color: inherit; text-underline-offset: 3px; }

/* ---------- Masthead ---------- */
.masthead {
  grid-area: mast;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 12px; margin-bottom: 24px;
}
.masthead svg { width: 44px; height: 44px; flex: none; }
.wordmark { margin: 0; font: 700 52px/0.9 var(--display); letter-spacing: -0.01em; }
.tagline { margin: 0 0 0 6px; color: var(--ink-soft); font-size: 18px; }
.wordmark a { text-decoration: none; }
.mast-nav { margin-left: auto; display: flex; gap: 22px; font-weight: 500; }
.crumbs { grid-area: crumbs; margin: -10px 0 18px; color: var(--ink-soft); font-size: 15px; }

/* ---------- Setup screen ---------- */
.setup {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(320px, 1fr);
  grid-template-areas: "mast mast" "crumbs crumbs" "hangar brief";
  gap: 0 44px;
  max-width: 1440px; margin: 0 auto; padding: 28px 40px 48px;
}
.hangar { grid-area: hangar; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.viewer {
  position: relative; height: clamp(320px, 60vh, 600px);
  border-radius: 4px; overflow: hidden; cursor: grab; touch-action: none;
  background: linear-gradient(var(--sky-high), var(--sky-low));
}
.viewer:active { cursor: grabbing; }
.viewer canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.viewer-hint { position: absolute; left: 14px; bottom: 10px; margin: 0; font-size: 14px; color: #2b3b46; }

.sides { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin: 0; padding: 0; list-style: none; }
.sides img { display: block; width: 100%; aspect-ratio: 3 / 2; border-radius: 3px; background: linear-gradient(var(--sky-high), var(--sky-low)); }
.sides span { display: block; font-size: 14px; color: var(--ink-soft); margin-top: 3px; }

.briefing { grid-area: brief; }
.briefing h2, .results h2 { font: 600 28px/1.1 var(--display); margin: 0 0 10px; }
.briefing h2 + p { margin-top: 0; }
.briefing section + section { margin-top: 30px; padding-top: 22px; border-top: 1px solid var(--rule); }
.cue { color: var(--ink-soft); font-size: 15px; }

/* Keypad: keycaps laid out like WASD, each with what it does. */
.keypad { display: grid; grid-template-columns: repeat(3, 64px); gap: 8px 10px; margin: 16px 0; }
.key { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.key:nth-child(1) { grid-column: 2; grid-row: 1; }
.key:nth-child(2) { grid-column: 1; grid-row: 2; }
.key:nth-child(3) { grid-column: 2; grid-row: 2; }
.key:nth-child(4) { grid-column: 3; grid-row: 2; }
.cap {
  width: 52px; height: 50px; display: grid; place-items: center;
  font: 600 24px/1 var(--display);
  background: var(--paper-raised); border: 1.5px solid var(--ink); border-bottom-width: 5px; border-radius: 6px;
  transition: background .12s, border-color .12s, color .12s;
}
.key small { font-size: 13px; line-height: 1.1; color: var(--ink-soft); text-align: center; }

/* Form */
.field { display: block; margin: 0 0 18px; border: 0; padding: 0; }
.field > span, .field > legend { display: block; font-weight: 600; margin-bottom: 6px; padding: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
input[type="text"], select {
  width: 100%; padding: 9px 11px; font: inherit; color: var(--ink);
  background: var(--paper-raised); border: 1.5px solid var(--rule); border-radius: 4px;
}
input[type="text"]:focus, select:focus { border-color: var(--ink); outline: none; }
input[type="range"] { width: 100%; accent-color: var(--ink); }
output { font: 600 20px/1 var(--display); float: right; }
.hint { margin: 6px 0 0; font-size: 14px; color: var(--ink-soft); }
.error { color: var(--wrong); font-weight: 500; }

.segmented { display: flex; border: 1.5px solid var(--ink); border-radius: 5px; overflow: hidden; }
.segmented button {
  flex: 1; padding: 8px 4px; border: 0; background: transparent; color: var(--ink);
  font: 600 18px/1 var(--display); cursor: pointer;
}
.segmented button + button { border-left: 1.5px solid var(--ink); }
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }

.custom { margin: 0 0 18px; padding: 14px 16px; background: var(--paper-raised); border-radius: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips label { cursor: pointer; }
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips span { display: inline-block; padding: 5px 11px; border: 1.5px solid var(--rule); border-radius: 999px; font-size: 15px; }
.chips input:checked + span { border-color: var(--ink); background: var(--ink); color: var(--paper); }
.chips input:focus-visible + span { outline: 3px solid var(--signal); outline-offset: 1px; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 0 0 12px; cursor: pointer; }
.switch input {
  appearance: none; flex: none; width: 40px; height: 22px; margin: 0; border-radius: 11px;
  background: var(--rule); position: relative; cursor: pointer; transition: background .15s;
}
.switch input::before {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; transition: transform .15s;
}
.switch input:checked { background: var(--ink); }
.switch input:checked::before { transform: translateX(18px); }

.actions { display: flex; gap: 10px; margin-top: 22px; flex-wrap: wrap; }
.btn {
  padding: 12px 22px; border-radius: 5px; cursor: pointer;
  font: 600 20px/1 var(--display); border: 1.5px solid var(--ink);
}
.btn-primary { background: var(--signal); color: var(--ink); border-bottom-width: 4px; }
.btn-primary:active { transform: translateY(1px); border-bottom-width: 3px; }
.btn-quiet { background: transparent; color: var(--ink); }
.note { margin: 12px 0 0; font-weight: 500; }

/* ---------- Test screen ---------- */
.test { position: fixed; inset: 0; background: linear-gradient(var(--sky-high), var(--sky-low)); overflow: hidden; }
.test canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.test-bar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 2;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 22px;
  padding: 14px 24px; color: #22323d; font-size: 15px;
}
.test-bar strong { font: 600 20px/1 var(--display); }
.progress { display: flex; gap: 3px; margin: 0; padding: 0; list-style: none; }
.progress li { flex: 1; height: 7px; border-radius: 2px; background: rgba(28, 34, 38, .16); }
.progress li.now { background: rgba(28, 34, 38, .45); }
.progress li.done { background: var(--ink); }
.progress li.right { background: var(--right); }
.progress li.wrong { background: var(--wrong); }
.timer { position: absolute; top: 44px; left: 24px; right: 24px; height: 3px; z-index: 2; }
.timer div { height: 100%; width: 100%; background: #22323d; transform-origin: left; }

.guide { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.key-hint { margin: 8px 0 0; font-size: 14px; color: #22323d; }
.cap.held { background: var(--ink) !important; color: var(--paper); }

.crosshair { position: absolute; left: 50%; top: 50%; width: 30px; height: 30px; transform: translate(-50%, -50%); }
.crosshair::before, .crosshair::after { content: ""; position: absolute; background: #22323d; }
.crosshair::before { left: 14px; top: 0; width: 2px; height: 30px; }
.crosshair::after { top: 14px; left: 0; height: 2px; width: 30px; }

.test-keys { position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 2; text-align: center; }
.test-keys .keypad { margin: 0 auto; opacity: .85; }
.test-keys .cap { background: rgba(238, 241, 236, .85); }
.test-keys small { color: #22323d; }
.cap.hit-right { background: var(--right) !important; border-color: #0d5430; color: #fff; }
.cap.hit-wrong { background: var(--wrong) !important; border-color: #7d1712; color: #fff; }
.cap.expected { background: var(--signal) !important; }
.verdict { margin: 0 0 10px; min-height: 30px; font: 600 26px/1.1 var(--display); color: #1c2a33; }

/* ---------- Results screen ---------- */
.results { max-width: 1200px; margin: 0 auto; padding: 28px 40px 56px; }
.results-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(280px, 1fr); gap: 40px; }
.headline { display: flex; align-items: flex-end; gap: 40px; flex-wrap: wrap; margin-bottom: 26px; }
.headline div { display: flex; flex-direction: column; }
.headline b { font: 700 88px/0.85 var(--display); }
.headline .secondary b { font-size: 48px; }
.headline span { color: var(--ink-soft); margin-top: 6px; }
.session-meta { display: flex; flex-wrap: wrap; gap: 4px 18px; margin: -4px 0 18px; color: var(--ink-soft); }

/* ---------- Charts ---------- */
.chart-title { margin: 0 0 6px; font: 600 16px/1.3 var(--text); }
.chart { width: 100%; display: block; background: var(--paper-raised); border-radius: 4px; margin-bottom: 18px; overflow: visible; }
.chart .grid { stroke: var(--rule); stroke-width: 1; opacity: .6; }
.chart .axis { fill: var(--ink-soft); font: 12px var(--text); }
.chart .right { fill: var(--right); }
.chart .wrong { fill: var(--wrong); }
.chart .timeout { fill: var(--rule); }
.chart .median { stroke: var(--ink); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .line { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; }
.chart .dot { fill: var(--ink); stroke: var(--paper-raised); stroke-width: 2; }
.chart .cursor { stroke: var(--ink-soft); stroke-width: 1; }
.legend { display: flex; gap: 18px; flex-wrap: wrap; font-size: 14px; color: var(--ink-soft); margin: -8px 0 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.legend .key-right { background: var(--right); }
.legend .key-wrong { background: var(--wrong); }
.legend .key-timeout { background: var(--rule); }
.legend .key-median { height: 0; border-top: 2px dashed var(--ink); border-radius: 0; vertical-align: 3px; }
.tooltip {
  position: fixed; left: 0; top: 0; z-index: 10; pointer-events: none; max-width: 260px;
  padding: 8px 10px; border-radius: 4px; background: var(--ink); color: var(--paper);
  font-size: 14px; line-height: 1.4; box-shadow: 0 4px 14px rgba(28, 34, 38, .25);
}

/* ---------- Dashboard ---------- */
.dashboard { max-width: 1240px; margin: 0 auto; padding: 28px 40px 56px; }
.dash-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(300px, 1fr); gap: 0 48px; }
.dashboard h2 { font: 600 28px/1.1 var(--display); margin: 0 0 12px; }
.dashboard section + section { margin-top: 34px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
.section-head select { width: auto; }

.test-list { display: grid; gap: 16px; }
.test-card { display: grid; grid-template-columns: 220px 1fr; gap: 20px; padding: 16px; background: var(--paper-raised); border-radius: 6px; }
.test-card img { width: 100%; aspect-ratio: 8 / 5; object-fit: cover; border-radius: 4px; background: linear-gradient(var(--sky-high), var(--sky-low)); }
.test-card h3 { margin: 0 0 4px; font: 600 26px/1.1 var(--display); }
.test-card p { margin: 0 0 12px; }
.test-card .btn { display: inline-block; text-decoration: none; margin-top: 4px; }
.facts, .overview { display: flex; flex-wrap: wrap; gap: 10px 28px; margin: 0 0 12px; }
.facts dt, .overview dt { font-size: 14px; color: var(--ink-soft); }
.facts dd, .overview dd { margin: 0; font: 600 26px/1.1 var(--display); font-variant-numeric: tabular-nums; }

.sessions tbody tr { cursor: pointer; }
.sessions tbody tr:hover td { background: var(--paper-raised); }
.sessions td small { display: block; color: var(--ink-soft); font-size: 13px; }
.sessions td a { font-weight: 500; }
.file-btn { position: relative; display: inline-block; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-btn:focus-within { outline: 3px solid var(--signal); outline-offset: 2px; }
.btn.danger { color: var(--wrong); border-color: var(--wrong); }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; margin-bottom: 28px; }
th { text-align: left; font-weight: 600; border-bottom: 2px solid var(--ink); padding: 6px 8px 6px 0; }
td { border-bottom: 1px solid var(--rule); padding: 7px 8px 7px 0; }
td.num, th.num { text-align: right; }
.empty { color: var(--ink-soft); }

/* ---------- Small screens ---------- */
@media (max-width: 900px) {
  .setup { grid-template-columns: 1fr; grid-template-areas: "mast" "crumbs" "hangar" "brief"; padding: 18px 16px 40px; }
  .dashboard { padding: 18px 16px 40px; }
  .dash-grid { grid-template-columns: 1fr; }
  .dash-grid > div + div { margin-top: 34px; }
  .test-card { grid-template-columns: 1fr; }
  .viewer { min-height: 320px; }
  .sides { grid-template-columns: repeat(3, 1fr); }
  .briefing { margin-top: 28px; }
  .results { padding: 18px 16px 40px; }
  .results-grid { grid-template-columns: 1fr; }
  .wordmark { font-size: 42px; }
  .mast-nav { margin-left: 0; width: 100%; }
  .tagline { margin-left: 0; }
  .test-keys .cap { width: 64px; height: 60px; cursor: pointer; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
.btn:disabled { opacity: .6; cursor: progress; }
