/* DMV Cram — see DESIGN.md. Paper (light) / Night drive (dark). */

:root {
  --bg: oklch(0.965 0.012 90);
  --surface: oklch(0.995 0.006 95);
  --ink: oklch(0.26 0.022 55);
  --muted: oklch(0.47 0.018 55);
  --line: oklch(0.885 0.014 85);
  --line-soft: oklch(0.92 0.012 85);
  --accent: oklch(0.63 0.185 42);
  --accent-ink: oklch(0.99 0.01 90);
  --accent-soft: oklch(0.93 0.045 55);
  --accent-deep: oklch(0.5 0.16 40);
  --good: oklch(0.55 0.14 152);
  --good-bg: oklch(0.94 0.05 152);
  --bad: oklch(0.53 0.19 27);
  --bad-bg: oklch(0.945 0.045 27);
  --warn: oklch(0.72 0.13 88);
  --shadow: 0 1px 2px oklch(0.26 0.022 55 / 0.06), 0 4px 16px oklch(0.26 0.022 55 / 0.05);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: oklch(0.185 0.012 55);
    --surface: oklch(0.235 0.015 55);
    --ink: oklch(0.93 0.012 85);
    --muted: oklch(0.67 0.015 70);
    --line: oklch(0.325 0.014 55);
    --line-soft: oklch(0.28 0.013 55);
    --accent: oklch(0.72 0.165 48);
    --accent-ink: oklch(0.15 0.02 55);
    --accent-soft: oklch(0.3 0.05 48);
    --accent-deep: oklch(0.78 0.15 50);
    --good: oklch(0.72 0.13 152);
    --good-bg: oklch(0.27 0.045 152);
    --bad: oklch(0.7 0.16 27);
    --bad-bg: oklch(0.28 0.05 27);
    --warn: oklch(0.78 0.13 88);
    --shadow: 0 1px 2px oklch(0 0 0 / 0.25), 0 4px 16px oklch(0 0 0 / 0.2);
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- shared chrome ---------- */

.screen {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 0 20px calc(96px + env(safe-area-inset-bottom));
  animation: screen-in 0.22s var(--ease);
}
.screen.no-bar { padding-bottom: calc(28px + env(safe-area-inset-bottom)); }

@keyframes screen-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 0 14px;
  min-height: 56px;
}
.topbar .tb-title { font-size: 16px; font-weight: 650; flex: 1; text-align: center; }
.topbar .tb-side { width: 44px; display: flex; }
.topbar .tb-side.right { justify-content: flex-end; }

.iconbtn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 50%;
  color: var(--muted);
  transition: background 0.15s var(--ease), transform 0.15s var(--ease);
}
.iconbtn:active { background: var(--line-soft); transform: scale(0.94); }
.iconbtn svg { width: 22px; height: 22px; }

.progress-track {
  height: 4px; border-radius: 2px;
  background: var(--line-soft);
  overflow: hidden;
  flex: 1;
}
.progress-fill {
  height: 100%; border-radius: 2px;
  background: var(--accent);
  width: 100%;
  transform-origin: left;
  transition: transform 0.3s var(--ease);
}

.bottombar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  gap: 12px;
  justify-content: center;
  padding: 14px 20px calc(14px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line-soft);
  z-index: 10;
}
.bottombar .inner { display: flex; gap: 12px; width: 100%; max-width: 480px; }

.btn {
  flex: 1;
  min-height: 54px;
  padding: 14px 22px;
  border-radius: 16px;
  font-size: 17px;
  font-weight: 650;
  background: var(--accent);
  color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform 0.15s var(--ease), filter 0.15s var(--ease), opacity 0.15s;
}
.btn:active { transform: scale(0.97); filter: brightness(0.94); }
.btn[disabled] { opacity: 0.4; pointer-events: none; }
.btn.quiet { background: var(--surface); color: var(--ink); border: 1.5px solid var(--line); }
.btn.good { background: var(--good); color: var(--accent-ink); }
.btn.bad-quiet { background: var(--bad-bg); color: var(--bad); }

.label {
  font-size: 13px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

/* ---------- home ---------- */

.home-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(18px + env(safe-area-inset-top)) 0 6px;
}
.wordmark { font-size: 17px; font-weight: 800; letter-spacing: 0.01em; }
.wordmark .ca { color: var(--accent); }

.readiness {
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 26px 0 10px;
}
.ring-wrap { position: relative; width: 124px; height: 124px; flex-shrink: 0; }
.ring-wrap svg { transform: rotate(-90deg); }
.ring-bg { stroke: var(--line-soft); }
.ring-val { stroke: var(--accent); transition: stroke-dashoffset 0.9s var(--ease); }
.ring-center {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  text-align: center;
}
.ring-center .big { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.ring-center .of { font-size: 12.5px; color: var(--muted); font-weight: 600; margin-top: 3px; }
.verdict { flex: 1; }
.verdict h2 { font-size: 21px; font-weight: 750; line-height: 1.25; letter-spacing: -0.01em; }
.verdict p { color: var(--muted); font-size: 14.5px; margin-top: 6px; line-height: 1.4; }

.section { margin-top: 34px; }
.section > .label { display: block; margin-bottom: 12px; }
.section-note { font-size: 13.5px; color: var(--muted); margin-top: 10px; }

/* plan checklist */
.plan-list { display: flex; flex-direction: column; }
.plan-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 2px;
  width: 100%;
  text-align: left;
  border-bottom: 1px solid var(--line-soft);
  transition: opacity 0.2s;
}
.plan-row:last-child { border-bottom: none; }
.plan-row .step-dot {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--line);
  display: grid; place-items: center;
  flex-shrink: 0;
  font-size: 13px; font-weight: 700; color: var(--muted);
}
.plan-row.current .step-dot { border-color: var(--accent); color: var(--accent); }
.plan-row.done .step-dot { background: var(--good); border-color: var(--good); color: var(--accent-ink); }
.plan-row .plan-body { flex: 1; min-width: 0; display: block; }
.plan-row .plan-title { font-weight: 650; font-size: 16.5px; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.plan-row .plan-time { font-size: 12.5px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.plan-row .plan-sub { font-size: 13.5px; color: var(--muted); margin-top: 2px; display: block; }
.plan-row.done .plan-title { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; }
.plan-row.done .plan-sub { text-decoration: none; }
.plan-row .chev { color: var(--muted); flex-shrink: 0; }
.plan-row.current .plan-title { color: var(--accent-deep); }
.plan-row:active { opacity: 0.6; }

/* mode rows */
.mode-list { display: flex; flex-direction: column; gap: 10px; }
.mode-row {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: 18px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  transition: transform 0.15s var(--ease);
}
.mode-row:active { transform: scale(0.98); }
.mode-row .mode-ic {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--accent-soft);
  color: var(--accent-deep);
  flex-shrink: 0;
}
.mode-row .mode-ic svg { width: 22px; height: 22px; }
.mode-row .mode-body { flex: 1; min-width: 0; display: block; }
.mode-row .mode-title { font-weight: 650; font-size: 16.5px; display: block; }
.mode-row .mode-sub { font-size: 13.5px; color: var(--muted); margin-top: 1px; display: block; }
.mode-row .mode-side { text-align: right; flex-shrink: 0; }
.mode-row .mode-stat { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.mode-row .badge {
  display: inline-block;
  min-width: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bad-bg);
  color: var(--bad);
  font-size: 13px; font-weight: 700;
  text-align: center;
}

/* mini mastery bar */
.mini-bar { height: 4px; border-radius: 2px; background: var(--line-soft); margin-top: 8px; overflow: hidden; }
.mini-bar i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }

/* ---------- onboarding ---------- */

.onb { justify-content: center; gap: 10px; min-height: 100dvh; padding-bottom: 40px; }
.onb .sign-hero { margin: 0 auto 26px; width: 132px; }
.onb h1 { font-size: 28px; font-weight: 800; text-align: center; letter-spacing: -0.015em; line-height: 1.2; }
.onb .lede { text-align: center; color: var(--muted); margin: 12px 0 34px; font-size: 16px; }
.choice-big {
  display: flex; align-items: center; gap: 14px;
  width: 100%;
  border: 2px solid var(--line);
  background: var(--surface);
  border-radius: 18px;
  padding: 18px;
  margin-bottom: 12px;
  text-align: left;
  transition: border-color 0.15s, transform 0.15s var(--ease);
}
.choice-big:active { transform: scale(0.98); border-color: var(--accent); }
.choice-big .cb-title { font-size: 18px; font-weight: 700; }
.choice-big .cb-sub { font-size: 14px; color: var(--muted); margin-top: 2px; }

/* ---------- quiz ---------- */

.quiz-meta {
  display: flex; align-items: center; gap: 10px;
  padding: 2px 0 14px;
  font-size: 13.5px; font-weight: 650; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.streak-chip {
  margin-left: auto;
  color: var(--accent-deep);
  font-weight: 700;
  animation: chip-in 0.25s var(--ease);
}
@keyframes chip-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

.qcard { flex: 1; display: flex; flex-direction: column; }
.qtext {
  font-size: 20px;
  font-weight: 650;
  line-height: 1.35;
  letter-spacing: -0.005em;
  margin: 10px 0 24px;
  min-height: 3.6em;
}
.q-anim { animation: q-in 0.24s var(--ease); }
@keyframes q-in { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.answers { display: flex; flex-direction: column; gap: 12px; }
.ans {
  width: 100%;
  text-align: left;
  border: 2px solid var(--line);
  background: var(--surface);
  border-radius: 16px;
  padding: 15px 16px;
  font-size: 16.5px;
  line-height: 1.4;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  transition: border-color 0.12s, background 0.12s, transform 0.12s var(--ease), opacity 0.2s;
}
.ans .ans-key {
  font-size: 13px; font-weight: 700; color: var(--muted);
  border: 1.5px solid var(--line);
  border-radius: 8px;
  width: 24px; height: 24px;
  display: grid; place-items: center;
  flex-shrink: 0;
  margin-top: 1px;
}
.ans:active { transform: scale(0.985); }
.ans.correct {
  border-color: var(--good);
  background: var(--good-bg);
}
.ans.correct .ans-key { border-color: var(--good); color: var(--good); background: none; }
.ans.wrong {
  border-color: var(--bad);
  background: var(--bad-bg);
  animation: shake 0.3s var(--ease);
}
.ans.wrong .ans-key { border-color: var(--bad); color: var(--bad); }
.ans.dim { opacity: 0.45; }
.ans[disabled] { pointer-events: none; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  60% { transform: translateX(3px); }
}

.explain {
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  font-size: 15px;
  line-height: 1.5;
  color: var(--muted);
  animation: chip-in 0.22s var(--ease);
}
.explain b { color: var(--ink); font-weight: 700; }
.explain .verdict-line { font-weight: 750; font-size: 14px; display: block; margin-bottom: 4px; }
.explain .verdict-line.ok { color: var(--good); }
.explain .verdict-line.no { color: var(--bad); }

/* miss pips (mock) */
.pips { display: flex; gap: 5px; align-items: center; }
.pips i {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--line);
  transition: background 0.2s;
}
.pips i.burnt { background: var(--bad); }
.pips .pips-label { font-size: 12px; margin-left: 4px; }

/* ---------- results ---------- */

.result-hero { text-align: center; padding: 34px 0 8px; }
.result-hero .score-big {
  font-size: 52px; font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1;
}
.result-hero .score-big small { font-size: 24px; color: var(--muted); font-weight: 700; }
.result-hero .pass-line { font-size: 19px; font-weight: 750; margin-top: 12px; }
.result-hero .pass-line.ok { color: var(--good); }
.result-hero .pass-line.no { color: var(--bad); }
.result-hero .sub { color: var(--muted); font-size: 14.5px; margin-top: 6px; }

.topic-delta { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.td-row {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 0;
  font-size: 15px;
}
.td-row .td-name { flex: 1; font-weight: 600; }
.td-row .td-frac { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 14px; font-weight: 650; }
.td-row .td-bar { width: 110px; height: 5px; border-radius: 3px; background: var(--line-soft); overflow: hidden; flex-shrink: 0; }
.td-row .td-bar i { display: block; height: 100%; border-radius: 3px; background: var(--good); }
.td-row.weak .td-bar i { background: var(--bad); }

.missed-list { display: flex; flex-direction: column; gap: 10px; }
.missed-item {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  padding: 13px 15px;
  font-size: 14.5px;
}
.missed-item .mq { font-weight: 650; margin-bottom: 5px; }
.missed-item .ma { color: var(--good); font-weight: 600; }

/* ---------- flashcards ---------- */

.flash-stage { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 10px 0; }
.flashcard {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: 22px;
  box-shadow: var(--shadow);
  min-height: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 30px 26px;
  width: 100%;
  gap: 14px;
  transition: transform 0.15s var(--ease);
}
.flashcard:active { transform: scale(0.985); }
.flashcard .fc-topic { font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--accent-deep); }
.flashcard .fc-front { font-size: 21px; font-weight: 700; line-height: 1.35; letter-spacing: -0.01em; }
.flashcard .fc-back {
  font-size: 19px; font-weight: 650; line-height: 1.4;
  color: var(--accent-deep);
  animation: chip-in 0.2s var(--ease);
}
.flashcard .fc-hint { font-size: 13.5px; color: var(--muted); }
.flash-count { text-align: center; font-size: 13.5px; color: var(--muted); font-weight: 650; padding-top: 12px; font-variant-numeric: tabular-nums; }

/* ---------- signs ---------- */

.sign-stage {
  display: flex;
  justify-content: center;
  padding: 8px 0 26px;
}
.sign-stage svg { width: 168px; height: auto; filter: drop-shadow(0 3px 8px oklch(0.26 0.022 55 / 0.18)); }

/* ---------- cheat sheet ---------- */

.cheat-group { margin-top: 26px; }
.cheat-group h3 { font-size: 16px; font-weight: 750; margin-bottom: 4px; letter-spacing: -0.005em; }
.cheat-row {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: 15px;
}
.cheat-row:last-child { border-bottom: none; }
.cheat-row .ck { flex: 1; color: var(--muted); line-height: 1.35; }
.cheat-row .cv {
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  text-align: right;
  max-width: 46%;
  flex-shrink: 0;
  transition: filter 0.15s, background 0.15s;
  border-radius: 6px;
}
.cheat-row .cv.hidden-val { filter: blur(7px); cursor: pointer; }
.quizme {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 650;
  color: var(--accent-deep);
  padding: 8px 0;
}
.quizme .switch {
  width: 40px; height: 24px; border-radius: 12px;
  background: var(--line);
  position: relative;
  transition: background 0.18s;
}
.quizme .switch::after {
  content: "";
  position: absolute;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--surface);
  top: 2px; left: 2px;
  transition: transform 0.18s var(--ease);
  box-shadow: 0 1px 3px oklch(0 0 0 / 0.2);
}
.quizme.on .switch { background: var(--accent); }
.quizme.on .switch::after { transform: translateX(16px); }

/* ---------- topic picker ---------- */

.topic-list { display: flex; flex-direction: column; }
.topic-row {
  display: flex; align-items: center; gap: 14px;
  width: 100%; text-align: left;
  padding: 14px 2px;
  border-bottom: 1px solid var(--line-soft);
}
.topic-row:active { opacity: 0.6; }
.topic-row .t-body { flex: 1; }
.topic-row .t-name { font-weight: 650; font-size: 16px; }
.topic-row .t-stat { font-size: 13px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }

/* ---------- settings ---------- */

.settings-panel { border-top: 1px solid var(--line-soft); margin-top: 8px; padding-top: 8px; }
.set-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 2px;
  font-size: 15.5px;
  border-bottom: 1px solid var(--line-soft);
}
.set-row:last-child { border-bottom: none; }
.set-row .set-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.seg {
  display: flex;
  background: var(--line-soft);
  border-radius: 12px;
  padding: 3px;
  gap: 2px;
}
.seg button {
  padding: 7px 13px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 650;
  color: var(--muted);
}
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px oklch(0 0 0 / 0.12); }
.danger-link { color: var(--bad); font-weight: 650; font-size: 15px; padding: 12px 2px; }

.foot-note { font-size: 12.5px; color: var(--muted); line-height: 1.5; margin-top: 30px; padding-bottom: 10px; }
.foot-note a { color: var(--accent-deep); }

/* toast */
.toast {
  position: fixed;
  left: 50%; bottom: calc(104px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  font-size: 14px; font-weight: 600;
  padding: 10px 18px;
  border-radius: 999px;
  z-index: 40;
  animation: toast-in 0.25s var(--ease);
  max-width: 86vw;
  text-align: center;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
.toast.out { opacity: 0; transition: opacity 0.3s; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
