/* Light by default: midday glare in a parked car. Dark follows the phone. */
:root {
  color-scheme: light;
  --bg: oklch(0.966 0.012 80);
  --surface: oklch(0.992 0.005 80);
  --surface-2: oklch(0.935 0.014 78);
  --ink: oklch(0.21 0.014 60);
  --ink-2: oklch(0.38 0.016 60);
  --muted: oklch(0.47 0.014 65);
  --line: oklch(0.82 0.016 75);
  --line-strong: oklch(0.6 0.02 70);
  --accent: oklch(0.5 0.14 42);
  --accent-ink: oklch(0.985 0.006 80);
  --accent-tint: oklch(0.93 0.035 55);
  --accent-line: oklch(0.62 0.12 45);
  --pass: oklch(0.47 0.11 150);
  --pass-tint: oklch(0.93 0.04 150);
  --danger: oklch(0.5 0.17 28);
  --warn-bg: oklch(0.25 0.02 60);
  --warn-ink: oklch(0.96 0.03 85);
  --focus: oklch(0.5 0.14 42);

  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 24px; --s-6: 32px; --s-7: 48px; --s-8: 64px;
  --r: 10px; --r-sm: 6px;
  --t-sm: 0.875rem; --t-base: 1rem; --t-md: 1.125rem; --t-lg: 1.375rem; --t-xl: 1.75rem;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: oklch(0.2 0.01 65);
    --surface: oklch(0.245 0.012 65);
    --surface-2: oklch(0.28 0.012 65);
    --ink: oklch(0.94 0.012 80);
    --ink-2: oklch(0.85 0.012 80);
    --muted: oklch(0.75 0.012 75);
    --line: oklch(0.36 0.012 65);
    --line-strong: oklch(0.52 0.016 65);
    --accent: oklch(0.76 0.13 55);
    --accent-ink: oklch(0.2 0.02 50);
    --accent-tint: oklch(0.3 0.04 50);
    --accent-line: oklch(0.62 0.1 52);
    --pass: oklch(0.78 0.12 150);
    --pass-tint: oklch(0.3 0.04 150);
    --danger: oklch(0.72 0.15 28);
    --warn-bg: oklch(0.82 0.11 80);
    --warn-ink: oklch(0.2 0.02 60);
    --focus: oklch(0.8 0.12 60);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: 80px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Readex Pro", "Geeza Pro", "Segoe UI", Tahoma, system-ui, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.65;
  font-variant-numeric: lining-nums;
  overflow-wrap: anywhere;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.3; }
p { margin: 0; }
a { color: var(--accent); text-underline-offset: 3px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: var(--r-sm); }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.skip {
  position: absolute; inset-inline-start: var(--s-3); top: -100px; z-index: 30;
  background: var(--surface); padding: var(--s-2) var(--s-4); border-radius: var(--r-sm);
}
.skip:focus { top: var(--s-2); }

/* ---------- warning bar (always visible) ---------- */
.warning {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-2) var(--s-4);
  padding-top: max(var(--s-2), env(safe-area-inset-top));
  background: var(--warn-bg); color: var(--warn-ink);
  font-size: var(--t-sm); font-weight: 600; line-height: 1.45;
}
.warning .icon { flex: none; width: 20px; height: 20px; }

.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- page ---------- */
.page {
  max-width: 44rem; margin-inline: auto;
  padding: var(--s-5) var(--s-4) var(--s-8);
  display: flex; flex-direction: column; gap: var(--s-6);
}

.top h1 { font-size: var(--t-xl); font-weight: 700; letter-spacing: -0.01em; }
.subtitle { color: var(--ink-2); margin-top: var(--s-1); }
.honest {
  margin-top: var(--s-5);
  padding: var(--s-4);
  background: var(--surface-2);
  border-radius: var(--r);
}
.honest h2 { font-size: var(--t-base); font-weight: 700; margin-bottom: var(--s-1); }
.honest p { max-width: 65ch; }

/* ---------- where am I ---------- */
.progress {
  display: flex; flex-direction: column; gap: var(--s-3);
  padding: var(--s-4);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--r);
}
.progress-label { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--s-1) var(--s-3); }
.progress-label strong { font-size: var(--t-md); font-weight: 700; }
.tally { color: var(--muted); font-size: var(--t-sm); font-variant-numeric: tabular-nums; }

.stepper {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(6, 1fr); gap: var(--s-1);
}
.step {
  display: flex; align-items: center; justify-content: center;
  min-height: 44px;
  border-radius: var(--r-sm);
  border: 1.5px solid var(--line-strong);
  color: var(--ink-2);
  text-decoration: none;
  font-weight: 600; font-variant-numeric: tabular-nums;
  transition: background-color 150ms var(--ease), color 150ms var(--ease), border-color 150ms var(--ease);
}
.step.is-passed { background: var(--pass); border-color: var(--pass); color: var(--accent-ink); }
.step.is-current { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.step.is-locked { border-style: dashed; color: var(--muted); border-color: var(--line); }

.next-drill { display: flex; flex-direction: column; gap: 2px; font-size: var(--t-sm); }
.next-k { color: var(--muted); font-weight: 600; }
.next-drill a { color: var(--ink); text-decoration-color: var(--accent); padding-block: var(--s-1); }

/* ---------- car numbers ---------- */
.car {
  padding: var(--s-4);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--r);
  display: flex; flex-direction: column; gap: var(--s-3);
}
.car h2 { font-size: var(--t-lg); font-weight: 700; }
.specs { margin: 0; display: flex; flex-direction: column; }
.spec {
  display: grid; grid-template-columns: 8.5rem 1fr; gap: var(--s-1) var(--s-3);
  padding-block: var(--s-3);
  border-bottom: 1px solid var(--line);
}
.spec:last-child { border-bottom: 0; }
.spec dt { color: var(--muted); font-size: var(--t-sm); font-weight: 600; padding-top: 2px; }
.spec dd { margin: 0; }
.spec-mirror { grid-template-columns: 1fr; }
.spec-mirror dt { color: var(--ink); font-size: var(--t-base); }
.spec-mirror dd { display: flex; flex-direction: column; gap: var(--s-3); }

.width-field { display: flex; flex-direction: column; gap: var(--s-1); }
.width-field label { font-weight: 600; }
.input-unit { display: flex; align-items: center; gap: var(--s-2); }
.input-unit input {
  width: 8.5rem; min-height: 52px;
  padding: var(--s-2) var(--s-3);
  font-size: var(--t-lg); font-weight: 600; font-variant-numeric: tabular-nums;
  text-align: left;
  background: var(--bg); border: 2px solid var(--line-strong); border-radius: var(--r-sm);
}
.input-unit input:focus-visible { border-color: var(--accent); }
.input-unit input[aria-invalid="true"] { border-color: var(--danger); }
.unit { font-weight: 600; color: var(--ink-2); }
.field-msg { color: var(--danger); font-size: var(--t-sm); font-weight: 600; min-height: 0; }
.field-msg:empty { display: none; }

.derived { display: flex; flex-direction: column; gap: var(--s-2); }
.derived-title { font-weight: 700; font-size: var(--t-sm); }
.derived-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-2); }
.gate-cell {
  display: flex; flex-direction: column; gap: 2px;
  padding: var(--s-3);
  background: var(--accent-tint);
  border-radius: var(--r-sm);
}
.gate-label { font-size: var(--t-sm); font-weight: 600; }
.gate-value { font-size: var(--t-lg); font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.gate-how { font-size: var(--t-sm); color: var(--ink-2); }

.muted { color: var(--muted); }
.small { font-size: var(--t-sm); }

/* ---------- stages ---------- */
.stages { display: flex; flex-direction: column; gap: var(--s-3); }
.section-h { font-size: var(--t-lg); font-weight: 700; }
.stage-rules { display: flex; flex-direction: column; gap: var(--s-2); color: var(--ink-2); font-size: var(--t-sm); margin-bottom: var(--s-2); }

.stage {
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--r);
  transition: border-color 150ms var(--ease);
}
.stage.is-current { border-color: var(--accent); border-width: 2px; }
.stage.is-locked { background: transparent; border-style: dashed; }

.stage-toggle {
  width: 100%;
  display: flex; align-items: center; gap: var(--s-3);
  min-height: 64px;
  padding: var(--s-3) var(--s-4);
  background: none; border: 0; text-align: start;
  border-radius: var(--r);
}
.stage-toggle:disabled { cursor: not-allowed; }
.stage-num {
  flex: none;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  font-weight: 700; font-variant-numeric: tabular-nums;
}
.is-current .stage-num { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.is-passed .stage-num { background: var(--pass); border-color: var(--pass); color: var(--accent-ink); }
.is-locked .stage-num { border-style: dashed; color: var(--muted); }
.stage-titles { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.stage-title { font-size: var(--t-md); font-weight: 700; }
.stage-meta { font-size: var(--t-sm); color: var(--muted); font-weight: 400; }
.is-locked .stage-title { color: var(--ink-2); }
.stage-status { flex: none; display: flex; align-items: center; gap: var(--s-1); font-size: var(--t-sm); font-weight: 600; color: var(--accent); }
.is-passed .stage-status { color: var(--pass); }
.is-locked .stage-status { color: var(--muted); }
.stage-toggle > .icon-chevron { flex: none; color: var(--muted); transition: transform 200ms var(--ease); }
.stage.is-open .stage-toggle > .icon-chevron { transform: rotate(180deg); }
.is-locked .stage-toggle > .icon-chevron { display: none; }

.goal { padding: 0 var(--s-4) var(--s-3); padding-inline-start: calc(var(--s-4) + 40px + var(--s-3)); }
.lock-reason {
  margin: 0 var(--s-4) var(--s-4);
  margin-inline-start: calc(var(--s-4) + 40px + var(--s-3));
  font-size: var(--t-sm); color: var(--muted);
}
.is-locked .goal { color: var(--ink-2); }

.stage-body {
  padding: var(--s-2) var(--s-4) var(--s-5);
  display: flex; flex-direction: column; gap: var(--s-5);
  border-top: 1px solid var(--line);
}

.group h4, .read h4 {
  display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-2);
  font-size: var(--t-base); font-weight: 700;
  margin-bottom: var(--s-2);
}
.count { font-size: var(--t-sm); color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.group-drills { padding-top: var(--s-3); }
.group-crit, .group-pre {
  padding: var(--s-3);
  border-radius: var(--r);
  border: 1.5px solid var(--accent-line);
  background: var(--accent-tint);
}
.group-crit h4 { color: var(--ink); }
.group-crit h4 > span:first-child::before {
  content: "";
  display: inline-block; width: 10px; height: 10px; margin-inline-end: var(--s-2);
  background: var(--accent); transform: rotate(45deg); vertical-align: 1px;
}
.group-pre { background: var(--surface-2); border-color: var(--line-strong); margin-top: var(--s-3); }
.pre-hint { font-size: var(--t-sm); color: var(--ink-2); font-weight: 600; }

/* checkbox rows */
.checks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.checks > li + li { border-top: 1px solid var(--line); }
.group-crit .checks > li + li, .group-pre .checks > li + li { border-top-color: color-mix(in oklch, var(--accent-line) 35%, transparent); }
.check {
  display: flex; align-items: flex-start; gap: var(--s-3);
  min-height: 48px;
  padding: var(--s-3) var(--s-1);
  cursor: pointer;
  border-radius: var(--r-sm);
  transition: background-color 150ms var(--ease);
}
@media (hover: hover) { .check:hover { background: color-mix(in oklch, var(--ink) 5%, transparent); } }
.check.is-disabled { cursor: not-allowed; color: var(--muted); }
.check.is-disabled:hover { background: none; }
.cb {
  flex: none;
  width: 24px; height: 24px; margin: 2px 0 0;
  accent-color: var(--accent);
  cursor: inherit;
}
.group-crit .cb { accent-color: var(--pass); }
.check-text { flex: 1; min-width: 0; }
.check-text strong { font-weight: 700; }
.check.is-done .check-text { color: var(--ink-2); }
.gate-note {
  display: inline-block; margin-inline-start: var(--s-2);
  padding: 0 var(--s-2);
  border-radius: var(--r-sm);
  background: var(--surface); border: 1px solid var(--accent-line);
  font-size: var(--t-sm); font-weight: 600; white-space: nowrap;
}

.read p { color: var(--ink-2); max-width: 65ch; }
.bullets, .numbered { margin: 0; padding-inline-start: 1.25rem; display: flex; flex-direction: column; gap: var(--s-2); }
.bullets li, .numbered li { color: var(--ink-2); max-width: 65ch; }
.numbered li::marker { font-weight: 700; color: var(--accent); }

/* ---------- log ---------- */
.log { display: flex; flex-direction: column; gap: var(--s-4); }
.log-form {
  display: flex; flex-direction: column; gap: var(--s-4);
  padding: var(--s-4);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--r);
}
.field { display: flex; flex-direction: column; gap: var(--s-1); }
.field label { font-weight: 600; }
.field select, .field textarea {
  width: 100%; min-height: 48px;
  padding: var(--s-2) var(--s-3);
  background: var(--bg); border: 1.5px solid var(--line-strong); border-radius: var(--r-sm);
}
.field textarea { resize: vertical; line-height: 1.55; }
.field select:focus-visible, .field textarea:focus-visible { border-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: var(--s-2) var(--s-5);
  border-radius: var(--r-sm);
  border: 1.5px solid transparent;
  font-weight: 600;
  transition: background-color 150ms var(--ease), border-color 150ms var(--ease);
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:active { background: color-mix(in oklch, var(--accent) 85%, var(--ink)); }
.btn-quiet { background: transparent; border-color: var(--line-strong); color: var(--ink); }
@media (hover: hover) {
  .btn-primary:hover { background: color-mix(in oklch, var(--accent) 88%, var(--ink)); }
  .btn-quiet:hover { background: var(--surface-2); }
  .btn-danger:hover { background: color-mix(in oklch, var(--danger) 88%, var(--ink)); }
}
.btn-danger { background: var(--danger); color: var(--accent-ink); }
.log-form .btn-primary { align-self: stretch; }
.log-form .field-msg:not(:empty) { color: var(--ink-2); }

.empty { font-size: var(--t-sm); }
.log-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s-3); }
.log-item {
  padding: var(--s-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  display: flex; flex-direction: column; gap: var(--s-3);
}
.log-head { display: flex; justify-content: space-between; gap: var(--s-2); font-size: var(--t-sm); }
.log-head time { font-variant-numeric: tabular-nums; color: var(--muted); }
.log-stage { font-weight: 700; }
.log-body { margin: 0; display: flex; flex-direction: column; gap: var(--s-2); }
.log-body dt { font-size: var(--t-sm); color: var(--muted); font-weight: 600; }
.log-body dd { margin: 0; white-space: pre-wrap; }
.log-actions, .btn-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
.confirm-q { font-size: var(--t-sm); font-weight: 600; flex-basis: 100%; }

/* ---------- secondary sections ---------- */
.more-list { display: flex; flex-direction: column; border-top: 1.5px solid var(--line); }
.more { border-bottom: 1.5px solid var(--line); }
.more summary {
  list-style: none;
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  min-height: 56px; padding: var(--s-3) var(--s-1);
  font-size: var(--t-md); font-weight: 600;
  cursor: pointer;
}
.more summary::-webkit-details-marker { display: none; }
.more summary .icon { color: var(--muted); transition: transform 200ms var(--ease); }
.more[open] summary .icon { transform: rotate(180deg); }
.more-body { padding: 0 var(--s-1) var(--s-5); display: flex; flex-direction: column; gap: var(--s-3); }
.more-body h4 { font-size: var(--t-base); font-weight: 700; margin-top: var(--s-2); }
.caution { padding: var(--s-3); background: var(--surface-2); border-radius: var(--r-sm); font-weight: 600; }

.table-wrap { overflow-x: auto; }
.sched { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }
.sched caption { text-align: start; font-weight: 700; font-size: var(--t-base); padding-bottom: var(--s-2); }
.sched th, .sched td { padding: var(--s-2); text-align: start; vertical-align: top; border-bottom: 1px solid var(--line); }
.sched th { color: var(--muted); font-weight: 600; }
.sched td.t { white-space: nowrap; font-variant-numeric: tabular-nums; }
.sched td.n { text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.sched tr.rest td { color: var(--muted); background: var(--surface-2); }
.after-table { font-weight: 600; margin-bottom: var(--s-3); }

.links { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.links li + li { border-top: 1px solid var(--line); }
.links a { display: flex; align-items: center; min-height: 48px; padding-block: var(--s-2); }

/* ---------- reset ---------- */
.reset { padding-top: var(--s-4); }
.reset-area { display: flex; flex-direction: column; align-items: flex-start; gap: var(--s-3); }

/* ---------- wider screens ---------- */
@media (min-width: 640px) {
  .page { padding-inline: var(--s-6); gap: var(--s-7); }
  .top h1 { font-size: 2.25rem; }
  .next-drill { flex-direction: row; gap: var(--s-2); }
  .log-form .btn-primary { align-self: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
