:root {
  color-scheme: dark;
  --bg: #10151b;
  --panel: #171e26;
  --edge: #242e39;
  --ink: #e9eef3;
  --dim: #8a97a5;
  --amber: #ffb454;
  --good: #58c98b;
  --bad: #f0647e;
  --mono: "Cascadia Mono", Consolas, "Courier New", monospace;
  --sans: "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

input, select, button, textarea { font: inherit; }

/* keep browser credential autofill on-theme instead of white */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--ink);
  -webkit-box-shadow: 0 0 0 1000px var(--panel) inset;
  box-shadow: 0 0 0 1000px var(--panel) inset;
  caret-color: var(--ink);
  transition: background-color 9999s ease-out;
}

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 28px;
  border-bottom: 1px solid var(--edge);
}

.brand {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 15px;
  letter-spacing: 0.25em;
  color: var(--ink);
}
.brand span { color: var(--amber); }
.brand:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

.navlink {
  background: none;
  border: none;
  color: var(--dim);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  padding: 6px 12px;
}
.navlink.active, .navlink:hover { color: var(--ink); }
.navlink:focus-visible, .chip:focus-visible, .card:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

.screen {
  flex: 1;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 32px 24px 40px;
  display: flex;
  flex-direction: column;
}
.hidden { display: none !important; }

.lede { color: var(--dim); font-size: 15px; margin-bottom: 24px; }
.footnote { color: var(--dim); font-size: 12.5px; margin-top: 28px; }
.footnote code { font-family: var(--mono); font-size: 11.5px; color: var(--ink); }

/* home: timer picker */
.timer-row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 26px;
}
.timer-label { color: var(--dim); font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 999px;
  color: var(--dim);
  font: inherit;
  font-size: 13.5px;
  padding: 7px 16px;
  cursor: pointer;
}
.chip.active { border-color: var(--amber); color: var(--amber); }

/* home layout with leaderboard sidebar */
.home-layout { flex: 1; display: flex; gap: 26px; min-height: 0; }
.home-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.home-side { width: 370px; flex-shrink: 0; display: flex; flex-direction: column; }
.leader-box {
  background: var(--panel);
  border: 1px solid var(--amber);
  border-radius: 12px;
  padding: 20px 22px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 480px;
}
.leader-box .subhead { font-size: 15px; }
.leader-sub { font-size: 13px; margin-bottom: 12px; }
.leader-list { flex: 1; }
.leader-select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--edge);
  border-radius: 8px;
  color: var(--ink);
  font: inherit;
  font-size: 14.5px;
  padding: 10px 12px;
  margin-bottom: 14px;
  cursor: pointer;
}
.leader-select:hover { border-color: var(--dim); }
.leader-select:focus-visible { outline: 2px solid var(--amber); outline-offset: 1px; }
.leader-box .subhead { margin: 0 0 2px; }
.leader-sub { color: var(--dim); font-size: 12px; margin-bottom: 8px; }
.leader-list { list-style: none; }
.leader-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--edge);
  font-size: 15px;
}
.leader-row:last-child { border-bottom: none; }
.leader-rank {
  font-family: var(--mono);
  color: var(--dim);
  width: 28px;
  height: 28px;
  font-size: 13px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.leader-rank.medal {
  border-radius: 50%;
  color: #10151b;
  font-weight: 700;
}
.leader-rank.r1 { background: #f5c542; }
.leader-rank.r2 { background: #c8ccd2; }
.leader-rank.r3 { background: #cd8a4f; }
.leader-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leader-score { font-family: var(--mono); font-size: 14px; flex-shrink: 0; }
.leader-row.me .leader-name { color: var(--amber); font-weight: 600; }
.leader-empty { color: var(--dim); font-size: 13.5px; padding: 8px 0; }
.offscreen { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
@media (max-width: 900px) {
  .home-layout { flex-direction: column; }
  .home-side { width: 100%; }
  .leader-box { position: static; }
}

/* profile switch */
.switch-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 4px 0 14px;
  font-size: 14.5px;
  cursor: pointer;
}
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch-track {
  position: absolute;
  inset: 0;
  background: var(--edge);
  border-radius: 999px;
  transition: background 120ms ease;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--dim);
  transition: transform 120ms ease, background 120ms ease;
}
.switch input:checked + .switch-track { background: rgba(255, 180, 84, 0.35); }
.switch input:checked + .switch-track::after { transform: translateX(18px); background: var(--amber); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--amber); outline-offset: 2px; }

.turnstile-slot { margin: 4px 0 10px; min-height: 0; }

/* home: section cards */
.cards {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  min-height: 0;
}
.card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 12px;
  color: var(--ink);
  text-align: left;
  padding: 26px 22px;
  min-height: 150px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  transition: border-color 120ms ease, transform 120ms ease;
}
.card:hover { border-color: var(--amber); transform: translateY(-1px); }
.card-key {
  position: absolute;
  top: 14px;
  right: 16px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--dim);
  border: 1px solid var(--edge);
  border-radius: 4px;
  padding: 2px 8px;
}
.card-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: rgba(255, 180, 84, 0.1);
  border: 1px solid rgba(255, 180, 84, 0.25);
  color: var(--amber);
  font-family: var(--mono);
  font-size: 26px;
  line-height: 1;
  margin-bottom: 4px;
}
.card-name { font-size: 23px; font-weight: 650; }
.card-sub { font-size: 13.5px; color: var(--dim); }
.card-mock { border-style: dashed; }
.card.disabled { opacity: 0.45; cursor: not-allowed; }

/* create-test button */
.btn-create {
  background: var(--amber);
  border: 1px solid var(--amber);
  border-radius: 999px;
  color: #10151b;
  font: inherit;
  font-size: 13.5px;
  font-weight: 650;
  padding: 8px 18px;
  cursor: pointer;
  margin-left: auto;
}
.btn-create:hover { filter: brightness(1.1); }
.btn-create:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* saved tests */
.saved-tests { margin-top: 24px; }
.test-list { display: flex; flex-wrap: wrap; gap: 10px; }
.test-row { display: flex; align-items: stretch; }
.test-run {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-right: none;
  border-radius: 10px 0 0 10px;
  color: var(--ink);
  font: inherit;
  text-align: left;
  padding: 10px 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.test-run:hover { border-color: var(--amber); }
.test-name { font-weight: 600; font-size: 15px; }
.test-meta { color: var(--dim); font-family: var(--mono); font-size: 12px; }
.test-del {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 0 10px 10px 0;
  color: var(--dim);
  font-size: 16px;
  padding: 0 12px;
  cursor: pointer;
}
.test-del:hover { color: var(--bad); border-color: var(--bad); }
.test-run:focus-visible, .test-del:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

/* test builder */
.builder-form { max-width: 560px; }
.field-row { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.field-row label { width: 150px; color: var(--dim); font-size: 14px; flex-shrink: 0; }
.field-row input {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 8px;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 15px;
  padding: 9px 12px;
  min-width: 0;
}
.field-row input:focus { outline: none; border-color: var(--amber); }
.count-grid {
  border: 1px solid var(--edge);
  border-radius: 10px;
  padding: 4px 16px;
  margin-bottom: 14px;
}
.count-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--edge);
}
.count-row:last-child { border-bottom: none; }
.count-row label { font-size: 14.5px; }
.count-note { color: var(--dim); font-size: 12px; }
.count-row input {
  width: 90px;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 8px;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 15px;
  text-align: center;
  padding: 7px 8px;
  flex-shrink: 0;
}
.count-row input:focus { outline: none; border-color: var(--amber); }
.builder-total { font-family: var(--mono); font-size: 15px; margin-bottom: 6px; }
.builder-msg { color: var(--bad); font-size: 13.5px; min-height: 18px; }

/* drill */
.timebar {
  height: 5px;
  width: 100%;
  background: var(--edge);
  border-radius: 3px;
  overflow: hidden;
}
.timebar-fill {
  height: 100%;
  width: 100%;
  background: var(--amber);
  transform-origin: left;
  transition: transform 100ms linear;
}
.timebar-fill.urgent { background: var(--bad); }

.drill-status {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 14px;
  color: var(--dim);
  font-size: 13.5px;
}
.drill-cat { text-transform: uppercase; letter-spacing: 0.12em; font-size: 12px; }
.drill-clock { font-family: var(--mono); font-size: 16px; color: var(--ink); }
.drill-clock.urgent { color: var(--bad); }

.drill-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 26px;
  padding-bottom: 40px;
}
.question {
  font-family: var(--mono);
  font-size: clamp(2.2rem, 7.5vw, 4.6rem);
  line-height: 1.25;
  text-align: center;
  max-width: 100%;
  overflow-wrap: anywhere;
}
.question.small { font-size: clamp(1.2rem, 3.4vw, 2rem); }
.answer-input {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 8px;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 28px;
  text-align: center;
  padding: 12px 18px;
  width: min(340px, 90%);
}
.answer-input:focus { outline: none; border-color: var(--amber); }
.hint { color: var(--dim); font-size: 13px; }

/* results and history */
.results-title { font-size: 26px; font-weight: 650; margin-bottom: 10px; }
.subhead {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--dim);
  margin: 26px 0 10px;
}
.scoreline {
  font-family: var(--mono);
  font-size: 16px;
  color: var(--dim);
  margin-bottom: 20px;
}
.scoreline b { color: var(--ink); font-weight: 600; }

.blotter-wrap { overflow-x: auto; border: 1px solid var(--edge); border-radius: 8px; }
.blotter { width: 100%; border-collapse: collapse; font-size: 14px; }
.blotter th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--dim);
  font-weight: 500;
  padding: 10px 14px;
  border-bottom: 1px solid var(--edge);
  white-space: nowrap;
}
.blotter td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--edge);
  font-family: var(--mono);
  font-size: 13.5px;
  white-space: nowrap;
}
.blotter td.q-text { white-space: normal; min-width: 180px; }
.blotter tr:last-child td { border-bottom: none; }
.blotter tr.row-wrong td { background: rgba(240, 100, 126, 0.07); }
.mark-good { color: var(--good); }
.mark-bad { color: var(--bad); }

.btn-row { display: flex; gap: 10px; margin-top: 24px; }
.btn {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 8px;
  color: var(--ink);
  font: inherit;
  font-size: 14.5px;
  padding: 10px 22px;
  cursor: pointer;
}
.btn:hover { border-color: var(--dim); }
a.btn { text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn-back { padding: 7px 16px; font-size: 13.5px; margin-right: 4px; }
.btn-primary { border-color: var(--amber); color: var(--amber); }
.btn-primary:hover { background: rgba(255, 180, 84, 0.08); }

/* account avatar */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  margin-left: 10px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--amber);
  color: var(--amber);
  font-family: var(--mono);
  font-size: 13px;
  text-decoration: none;
  vertical-align: middle;
  cursor: pointer;
}
.avatar:hover { background: rgba(255, 180, 84, 0.12); }
.avatar:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.avatar-here { cursor: default; }
.brand-link { text-decoration: none; display: inline-block; }
nav { display: flex; align-items: center; }
a.navlink { text-decoration: none; display: inline-block; }

/* dashboard */
.dash { max-width: 1080px; }
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}
.kpi {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 10px;
  padding: 14px 16px;
}
.kpi-value { font-family: var(--mono); font-size: 26px; }
.kpi-label { color: var(--dim); font-size: 12px; text-transform: uppercase; letter-spacing: 0.07em; margin-top: 4px; }

.filter-row { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.select {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 8px;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  padding: 7px 10px;
}
.select:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 12px;
}
.chart-card {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 10px;
  padding: 4px 16px 12px;
  margin-bottom: 12px;
}
.chart-card .subhead { margin: 12px 0 6px; }
.chart-mount svg { width: 100%; height: auto; display: block; }
.chart-empty { color: var(--dim); font-size: 13.5px; padding: 24px 0; }

/* daily activity heatmap */
.activity-mount { overflow-x: auto; padding: 8px 0 6px; }
.act0 { fill: #1b222b; }
.act1 { fill: rgba(255, 180, 84, 0.3); }
.act2 { fill: rgba(255, 180, 84, 0.55); }
.act3 { fill: rgba(255, 180, 84, 0.8); }
.act4 { fill: var(--amber); }
.act:hover { stroke: var(--ink); stroke-width: 1; }

.gridline { stroke: var(--edge); stroke-width: 1; }
.axis-text { fill: var(--dim); font-family: var(--mono); font-size: 11px; }
.value-text { fill: var(--ink); font-family: var(--mono); font-size: 12px; }
.series-line { fill: none; stroke: var(--amber); stroke-width: 2; stroke-linejoin: round; }
.series-dot { fill: var(--amber); }
.crosshair { stroke: var(--dim); stroke-width: 1; stroke-dasharray: 3 3; }

.hbars { padding: 8px 0 4px; }
.hbar-row { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.hbar-name { width: 110px; flex-shrink: 0; color: var(--dim); font-size: 13px; text-align: right; }
.hbar-track { flex: 1; height: 12px; background: var(--edge); border-radius: 0 4px 4px 0; }
.hbar-fill { height: 100%; background: var(--amber); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar-value { width: 90px; flex-shrink: 0; font-family: var(--mono); font-size: 12.5px; }

.tooltip {
  position: fixed;
  z-index: 10;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 6px;
  padding: 7px 10px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--dim);
  pointer-events: none;
  max-width: 260px;
}
.tooltip b { color: var(--ink); font-weight: 600; }

/* auth extras */
.or-row {
  color: var(--dim);
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 16px 0 12px;
}
.btn-google {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
}
.btn-google svg { flex-shrink: 0; }

/* footer */
.site-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 18px 24px 22px;
  border-top: 1px solid var(--edge);
  font-size: 13px;
}
.site-footer a { color: var(--dim); text-decoration: none; }
.site-footer a:hover { color: var(--ink); }
.site-footer span { color: var(--edge); }

/* legal page */
.legal { max-width: 760px; }
.legal section { margin-bottom: 26px; }
.legal p { color: var(--ink); font-size: 15px; line-height: 1.65; margin: 10px 0; }
.legal p b { font-weight: 650; }
.legal a { color: var(--amber); }

@media (prefers-reduced-motion: reduce) {
  .timebar-fill, .card { transition: none; }
}

@media (max-width: 560px) {
  .screen { padding: 20px 14px 32px; }
  .answer-input { font-size: 22px; }
}
