:root {
  --poppy: #0d9488;       /* teal accent (legacy var names from the DMV fork) */
  --poppy-dark: #0f766e;
  --navy: #1e3a5f;
  --ink: #22303f;
  --muted: #64748b;
  --bg: #fdf8f2;
  --card: #ffffff;
  --line: #eadfd2;
  --good: #16a34a;
  --good-bg: #ecfdf3;
  --bad: #dc2626;
  --bad-bg: #fef2f2;
  --gold: #f59e0b;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(30, 58, 95, .08), 0 4px 16px rgba(30, 58, 95, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --navy: #dbe7f5;
    --ink: #e7edf4;
    --muted: #94a3b8;
    --bg: #151a21;
    --card: #1e2530;
    --line: #2c3644;
    --good-bg: #10291b;
    --bad-bg: #2e1a1a;
    --shadow: 0 1px 3px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  min-height: 100dvh;
}
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; -webkit-tap-highlight-color: transparent; }
input { font: inherit; }

.app { max-width: 640px; margin: 0 auto; padding: 16px 16px 48px; }
.screen { display: none; animation: fadein .25s ease; }
.screen.active { display: block; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- header ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 8px 0 18px; }
.brand { font-weight: 800; font-size: 1.15rem; color: var(--navy); letter-spacing: -.02em; display: flex; align-items: center; gap: 8px; }
.brand .dot { color: var(--poppy); }
.who { display: flex; align-items: center; gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: .85rem; font-weight: 600; box-shadow: var(--shadow); }

/* ---------- generic ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
h1 { font-size: 1.5rem; letter-spacing: -.02em; color: var(--navy); }
h2 { font-size: 1.05rem; color: var(--navy); margin-bottom: 10px; }
.sub { color: var(--muted); font-size: .9rem; margin-top: 4px; }
.stack > * + * { margin-top: 14px; }

.btn {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 15px 18px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow);
  font-weight: 700; font-size: 1rem; text-align: left; color: var(--ink);
  transition: transform .08s ease;
}
.btn:active { transform: scale(.98); }
.btn .em { font-size: 1.5rem; }
.btn .desc { display: block; font-weight: 500; font-size: .8rem; color: var(--muted); margin-top: 2px; }
.btn.primary { background: linear-gradient(135deg, var(--poppy), var(--poppy-dark)); color: #fff; border: none; }
.btn.primary .desc { color: rgba(255,255,255,.85); }
.btn.navy { background: var(--navy); color: #fff; border: none; }
@media (prefers-color-scheme: dark) { .btn.navy { background: #31517a; } }
.btn.navy .desc { color: rgba(255,255,255,.75); }

/* ---------- profile ---------- */
.hero { text-align: center; padding: 28px 0 22px; }
.hero .big { font-size: 3rem; }
.users { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.user-chip { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 16px 8px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); font-weight: 700; }
.user-chip .em { font-size: 2rem; }
.newuser { display: flex; gap: 8px; }
.newuser input { flex: 1; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink); min-width: 0; }
.newuser button { padding: 12px 18px; border-radius: 12px; background: var(--poppy); color: #fff; font-weight: 700; flex-shrink: 0; }
.emoji-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.emoji-row button { font-size: 1.4rem; padding: 6px 9px; border-radius: 10px; border: 2px solid transparent; }
.emoji-row button.sel { border-color: var(--poppy); background: var(--bg); }

/* ---------- home ---------- */
.streaks { display: flex; gap: 10px; }
.streak-pill { flex: 1; text-align: center; padding: 12px 6px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.streak-pill .n { font-size: 1.35rem; font-weight: 800; color: var(--navy); }
.streak-pill .l { font-size: .72rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

.cats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (min-width: 480px) { .cats { grid-template-columns: repeat(3, 1fr); } }
.cat-tile { position: relative; display: flex; flex-direction: column; gap: 6px; padding: 13px 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); text-align: left; }
.cat-tile:active { transform: scale(.97); }
.cat-tile .em { font-size: 1.4rem; }
.cat-tile .nm { font-weight: 700; font-size: .82rem; line-height: 1.25; }
.cat-tile .meter { height: 6px; border-radius: 4px; background: var(--line); overflow: hidden; }
.cat-tile .meter > i { display: block; height: 100%; border-radius: 4px; background: var(--poppy); transition: width .4s ease; }
.cat-tile .pct { font-size: .72rem; color: var(--muted); font-weight: 600; }
.cat-tile.weak::after { content: "needs work"; position: absolute; top: 8px; right: 8px; font-size: .58rem; font-weight: 800; color: var(--bad); background: var(--bad-bg); padding: 2px 6px; border-radius: 999px; text-transform: uppercase; letter-spacing: .03em; }

/* ---------- auth ---------- */
.authgrid { display: flex; flex-direction: column; gap: 8px; }
.field { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink); width: 100%; }
.gobtn { padding: 12px 18px; border-radius: 12px; background: var(--poppy); color: #fff; font-weight: 700; }
.gobtn.wide { width: 100%; margin-top: 10px; }
.autherr { color: var(--bad); font-size: .85rem; font-weight: 600; margin-top: 8px; min-height: 1em; }
.greet { font-size: 1.05rem; font-weight: 700; color: var(--navy); padding: 2px 2px 0; }
.greet .sub2 { display: block; font-size: .78rem; font-weight: 500; color: var(--muted); margin-top: 2px; }

/* ---------- exam class switcher ---------- */
.seg { display: flex; gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 5px; box-shadow: var(--shadow); }
.seg button { flex: 1; padding: 10px 4px; border-radius: 10px; font-weight: 700; font-size: .85rem; color: var(--muted); }
.seg button.active { background: var(--poppy); color: #fff; }

/* ---------- quiz figure ---------- */
.q-fig { display: block; max-width: 100%; border: 1px solid var(--line); border-radius: 10px; margin: 0 auto 14px; background: #fff; }

/* ---------- quiz ---------- */
.quiz-top { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.quiz-top .counter { font-weight: 800; color: var(--navy); font-size: .9rem; white-space: nowrap; }
.bar { flex: 1; height: 8px; background: var(--line); border-radius: 5px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--poppy-dark), #2dd4bf); border-radius: 5px; transition: width .35s ease; }
.quit { color: var(--muted); font-size: 1.2rem; padding: 4px 8px; }

.q-cat { display: inline-block; font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--poppy-dark); background: var(--bg); border: 1px solid var(--line); padding: 3px 10px; border-radius: 999px; margin-bottom: 12px; }
.q-text { font-size: 1.12rem; font-weight: 700; line-height: 1.45; color: var(--navy); margin-bottom: 16px; }
.choices { display: flex; flex-direction: column; gap: 10px; }
.choice {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 14px 15px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--card); font-weight: 600; font-size: .97rem; text-align: left; line-height: 1.35;
  transition: border-color .15s, background .15s, transform .08s;
}
.choice:not(:disabled):active { transform: scale(.98); }
.choice .key { flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--bg); border: 1px solid var(--line); font-size: .8rem; font-weight: 800; color: var(--muted); }
.choice.correct { border-color: var(--good); background: var(--good-bg); }
.choice.correct .key { background: var(--good); border-color: var(--good); color: #fff; }
.choice.wrong { border-color: var(--bad); background: var(--bad-bg); animation: shake .3s ease; }
.choice.wrong .key { background: var(--bad); border-color: var(--bad); color: #fff; }
.choice.dim { opacity: .45; }
@keyframes shake { 0%,100% { transform: none; } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

.feedback { margin-top: 14px; border-radius: 14px; padding: 14px 15px; display: none; animation: fadein .25s ease; }
.feedback.show { display: block; }
.feedback.good { background: var(--good-bg); border: 1px solid var(--good); }
.feedback.bad { background: var(--bad-bg); border: 1px solid var(--bad); }
.feedback .verdict { font-weight: 800; margin-bottom: 6px; }
.feedback.good .verdict { color: var(--good); }
.feedback.bad .verdict { color: var(--bad); }
.feedback .expl { font-size: .93rem; line-height: 1.5; }
.feedback .ref { display: block; margin-top: 8px; font-size: .78rem; color: var(--muted); font-style: italic; }

.next-btn { margin-top: 14px; width: 100%; padding: 15px; border-radius: 14px; background: var(--navy); color: #fff; font-weight: 800; font-size: 1rem; display: none; }
.next-btn.show { display: block; animation: fadein .25s ease; }
@media (prefers-color-scheme: dark) { .next-btn { background: #31517a; } }

.exam-note { text-align: center; font-size: .78rem; color: var(--muted); margin-top: 12px; }

/* ---------- results ---------- */
.score-wrap { text-align: center; padding: 10px 0 4px; }
.ring { position: relative; width: 150px; height: 150px; margin: 0 auto 10px; }
.ring svg { transform: rotate(-90deg); }
.ring .track { stroke: var(--line); }
.ring .fill { stroke: var(--poppy); stroke-linecap: round; transition: stroke-dashoffset 1s ease; }
.ring .mid { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring .mid .p { font-size: 2rem; font-weight: 800; color: var(--navy); }
.ring .mid .s { font-size: .8rem; color: var(--muted); font-weight: 600; }
.verdict-line { font-size: 1.2rem; font-weight: 800; color: var(--navy); }
.verdict-line.pass { color: var(--good); }
.verdict-line.fail { color: var(--bad); }

.break-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.break-row:last-child { border-bottom: none; }
.break-row .em { font-size: 1.1rem; }
.break-row .nm { flex: 1; font-weight: 600; }
.break-row .sc { font-weight: 800; color: var(--navy); }

.missed { margin-top: 4px; }
.missed-item { padding: 12px 0; border-bottom: 1px solid var(--line); }
.missed-item:last-child { border-bottom: none; }
.missed-item .mq { font-weight: 700; font-size: .92rem; line-height: 1.4; margin-bottom: 6px; }
.missed-item .ma { font-size: .88rem; color: var(--good); font-weight: 700; margin-bottom: 4px; }
.missed-item .me { font-size: .85rem; color: var(--muted); line-height: 1.45; }

/* ---------- stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat-tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; text-align: center; }
.stat-tile .n { font-size: 1.5rem; font-weight: 800; color: var(--navy); }
.stat-tile .l { font-size: .72rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; margin-top: 2px; }

.cat-stat { padding: 11px 0; border-bottom: 1px solid var(--line); }
.cat-stat:last-child { border-bottom: none; }
.cat-stat .row1 { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.cat-stat .nm { flex: 1; font-weight: 700; font-size: .9rem; }
.cat-stat .tag { font-size: .68rem; font-weight: 800; padding: 3px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: .03em; }
.tag.ready { background: var(--good-bg); color: var(--good); }
.tag.close { background: #fef8e7; color: #b45309; }
.tag.work { background: var(--bad-bg); color: var(--bad); }
.tag.new { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
@media (prefers-color-scheme: dark) { .tag.close { background: #2e2410; } }
.cat-stat .meter { height: 8px; border-radius: 5px; background: var(--line); overflow: hidden; }
.cat-stat .meter > i { display: block; height: 100%; border-radius: 5px; transition: width .5s ease; }
.cat-stat .detail { font-size: .75rem; color: var(--muted); margin-top: 4px; }

.hist-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: .87rem; }
.hist-row:last-child { border-bottom: none; }
.hist-row .m { flex: 1; font-weight: 600; }
.hist-row .d { color: var(--muted); font-size: .76rem; }
.hist-row .s { font-weight: 800; color: var(--navy); }

.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-weight: 700; font-size: .9rem; padding: 6px 0; margin-bottom: 8px; }

/* ---------- admin score-over-time chart ---------- */
:root { --chart-bar: #0d9488; }  /* validated ≥3:1 on both light+dark surfaces */
.prog-user { padding: 14px 0 10px; border-bottom: 1px solid var(--line); }
.prog-user:last-child { border-bottom: none; }
.prog-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.prog-head .nm { font-weight: 800; color: var(--navy); }
.prog-head .sum, .prog-exam-head .sum { font-size: .78rem; color: var(--muted); }
.prog-exam { margin: 4px 0 14px 8px; }
.prog-exam:last-child { margin-bottom: 4px; }
.prog-exam-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.chart { position: relative; height: 96px; margin: 4px 0 2px; }
.chart .passline { position: absolute; left: 0; right: 0; bottom: 74%; border-top: 1px dashed var(--muted); opacity: .5; }
.chart .passlabel { position: absolute; right: 0; bottom: 74%; transform: translateY(-2px); font-size: .62rem; color: var(--muted); font-weight: 600; }
.chart .bars { position: absolute; inset: 0; display: flex; align-items: flex-end; gap: 2px; }
.cbar { position: relative; flex: 1; min-width: 3px; display: flex; align-items: flex-end; height: 100%; }
.cbar > i { display: block; width: 100%; background: var(--chart-bar); border-radius: 4px 4px 0 0; min-height: 2px; }
.cbar.empty > i { background: var(--line); height: 2px; border-radius: 0; }
.cbar .dlabel { position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); font-size: .66rem; font-weight: 700; color: var(--ink); white-space: nowrap; padding-bottom: 1px; }
.cbar[data-tip]:hover::after, .cbar[data-tip]:focus-visible::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 4px); left: 50%;
  transform: translateX(-50%); background: var(--navy); color: var(--bg);
  font-size: .7rem; font-weight: 600; padding: 4px 8px; border-radius: 8px;
  white-space: nowrap; z-index: 20; pointer-events: none;
}
@media (prefers-color-scheme: dark) {
  .cbar[data-tip]:hover::after, .cbar[data-tip]:focus-visible::after { background: #31517a; color: #e7edf4; }
}
.chart-x { display: flex; justify-content: space-between; font-size: .64rem; color: var(--muted); margin-bottom: 8px; }
.wk-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.wk-table th { text-align: left; font-size: .66rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 4px 6px 4px 0; font-weight: 700; }
.wk-table td { padding: 5px 6px 5px 0; border-top: 1px solid var(--line); }
.wk-table td.num, .wk-table th.num { text-align: right; }
.wk-table .pct { font-weight: 800; color: var(--navy); }

/* ---------- confetti ---------- */
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 50; }
.confetti i { position: absolute; top: -12px; width: 9px; height: 14px; border-radius: 2px; animation: drop linear forwards; }
@keyframes drop {
  to { transform: translateY(105vh) rotate(720deg); opacity: .7; }
}
