:root {
  --ground: #eef0ed;
  --surface: #ffffff;
  --surface-2: #e2e6e2;
  --ink: #151a18;
  --ink-2: #4a5552;
  --ink-3: #7c8783;
  --line: #d1d7d3;
  --accent: #0e7c86;
  --accent-ink: #ffffff;
  --accent-soft: rgba(14, 124, 134, 0.12);
  --good: #2b8a57;
  --good-soft: rgba(43, 138, 87, 0.14);
  --bad: #c2483d;
  --bad-soft: rgba(194, 72, 61, 0.13);
  --tip: #b9781a;
  --tip-soft: #fff3dc;
  --shadow: 0 18px 40px -22px rgba(21, 26, 24, 0.45), 0 2px 6px -2px rgba(21, 26, 24, 0.18);
  --radius: 18px;
  --display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", sans-serif;
  --body: "Atkinson Hyperlegible", "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", "SF Mono", Menlo, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ground: #101413; --surface: #182120; --surface-2: #212b29; --ink: #e8eeeb; --ink-2: #b3bfba; --ink-3: #7f8c87; --line: #2c3634;
    --accent-ink: #0b1d1f; --good: #58c48a; --good-soft: rgba(88,196,138,.16); --bad: #ef7a6f; --bad-soft: rgba(239,122,111,.16);
    --tip: #e4a84a; --tip-soft: #2a2214; --shadow: 0 18px 40px -22px rgba(0,0,0,.8), 0 2px 6px -2px rgba(0,0,0,.5);
  }
}
/* Subject accents. The app root carries data-subject while inside a deck or session. */
.app[data-subject="Science"]   { --accent: #0e7c86; --accent-soft: rgba(14,124,134,.12); }
.app[data-subject="French"]    { --accent: #223a8f; --accent-soft: rgba(34,58,143,.12); }
.app[data-subject="History"]   { --accent: #9a6b1c; --accent-soft: rgba(154,107,28,.14); }
.app[data-subject="Math"]      { --accent: #6d3b8f; --accent-soft: rgba(109,59,143,.12); }
.app[data-subject="English"]   { --accent: #2f6b3a; --accent-soft: rgba(47,107,58,.12); }
.app[data-subject="Spanish"]   { --accent: #b4472f; --accent-soft: rgba(180,71,47,.12); }
.app[data-subject="Geography"] { --accent: #1f6f8b; --accent-soft: rgba(31,111,139,.12); }
.app[data-subject="Other"]     { --accent: #4a5a6a; --accent-soft: rgba(74,90,106,.12); }
@media (prefers-color-scheme: dark) {
  .app[data-subject="Science"]   { --accent: #4fc1c9; }
  .app[data-subject="French"]    { --accent: #8fa6ec; }
  .app[data-subject="History"]   { --accent: #e0aa4e; }
  .app[data-subject="Math"]      { --accent: #b78fd6; }
  .app[data-subject="English"]   { --accent: #7cc48a; }
  .app[data-subject="Spanish"]   { --accent: #ef8f78; }
  .app[data-subject="Geography"] { --accent: #6fb8d6; }
  .app[data-subject="Other"]     { --accent: #9fb0c0; }
  .app                            { --accent: #4fc1c9; }
}
.subject-dot[data-subject="Science"]   { background: #0e7c86; }
.subject-dot[data-subject="French"]    { background: #223a8f; }
.subject-dot[data-subject="History"]   { background: #9a6b1c; }
.subject-dot[data-subject="Math"]      { background: #6d3b8f; }
.subject-dot[data-subject="English"]   { background: #2f6b3a; }
.subject-dot[data-subject="Spanish"]   { background: #b4472f; }
.subject-dot[data-subject="Geography"] { background: #1f6f8b; }
.subject-dot[data-subject="Other"]     { background: #4a5a6a; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--body); font-size: 17px; line-height: 1.5; color: var(--ink); background: var(--ground); min-height: 100vh; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: -0.01em; line-height: 1.1; margin: 0; text-wrap: balance; }
h1 { font-size: clamp(28px, 5vw, 38px); }
h2 { font-size: clamp(20px, 3.4vw, 26px); }
h3 { font-size: 17px; }
.eyebrow { font-family: var(--mono); font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); margin: 0 0 6px; }
.muted { color: var(--ink-2); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---- top bar ---- */
.topbar { position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; padding: 10px 16px; background: color-mix(in oklab, var(--ground) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); padding-top: max(10px, env(safe-area-inset-top)); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-family: var(--display); font-weight: 700; font-size: 18px; }
.brand-mark { position: relative; width: 26px; height: 22px; display: inline-block; }
.brand-mark i { position: absolute; width: 18px; height: 14px; border-radius: 4px; background: var(--accent); }
.brand-mark i:first-child { left: 0; bottom: 0; opacity: .55; }
.brand-mark i:last-child { right: 0; top: 0; }
.brand-name { display: none; }
@media (min-width: 560px) { .brand-name { display: inline; } }
.subjects { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.subjects::-webkit-scrollbar { display: none; }
.subjects a { flex: 0 0 auto; text-decoration: none; color: var(--ink-2); font-weight: 700; font-size: 14px; padding: 7px 12px; border-radius: 999px; border: 1px solid transparent; display: inline-flex; align-items: center; gap: 7px; }
.subjects a[aria-current="page"] { background: var(--surface); color: var(--ink); border-color: var(--line); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.subject-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.topbar-right { position: relative; display: flex; align-items: center; gap: 8px; }
.iconbtn { text-decoration: none; font-weight: 700; font-size: 14px; padding: 8px 12px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); white-space: nowrap; }
.chip { border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 700; font-size: 14px; padding: 7px 12px; border-radius: 999px; display: inline-flex; align-items: center; gap: 8px; }
.chip .avatar { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: inline-grid; place-items: center; font-family: var(--display); font-size: 12px; }
.menu { position: absolute; right: 0; top: calc(100% + 8px); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; display: grid; min-width: 160px; z-index: 30; }
.menu a, .menu button { text-align: left; text-decoration: none; color: var(--ink); background: none; border: 0; padding: 10px 12px; border-radius: 8px; font-weight: 700; font-size: 14px; }
.menu a:hover, .menu button:hover { background: var(--surface-2); }

/* ---- layout ---- */
.view { max-width: 820px; margin: 0 auto; padding: 24px 16px 96px; display: grid; gap: 22px; padding-bottom: max(96px, env(safe-area-inset-bottom)); }
.view.narrow { max-width: 720px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn { border: 0; border-radius: 14px; padding: 14px 18px; font-weight: 700; font-size: 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; transition: transform 120ms ease, filter 120ms ease; background: var(--surface-2); color: var(--ink); }
.btn:active { transform: scale(.98); }
.btn:hover { filter: brightness(1.05); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.good { background: var(--good); color: #fff; }
.btn.bad { background: var(--bad); color: #fff; }
.btn.big { padding: 18px 20px; font-size: 18px; flex-direction: column; gap: 3px; }
.btn.big small { font-weight: 400; font-size: 12px; opacity: .8; font-family: var(--mono); letter-spacing: .06em; }
.btn:disabled { opacity: .45; cursor: default; transform: none; filter: none; }
.pillbtn { border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); padding: 8px 13px; border-radius: 999px; font-size: 14px; font-weight: 700; }
.pillbtn:hover { border-color: var(--accent); color: var(--accent); }
.pillbtn.danger:hover { border-color: var(--bad); color: var(--bad); }
.pillbtn:disabled { opacity: .5; cursor: default; }

/* ---- login ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login { width: min(420px, 100%); background: var(--surface); border-radius: 22px; box-shadow: var(--shadow); padding: 30px 28px; display: grid; gap: 16px; border-top: 6px solid var(--accent); }
.login h1 { font-size: 30px; }
.field { display: grid; gap: 6px; }
.field label { font-size: 13px; font-weight: 700; color: var(--ink-2); letter-spacing: .02em; }
.field input, .field select, .field textarea { border: 1px solid var(--line); background: var(--ground); border-radius: 12px; padding: 12px 14px; font-size: 17px; width: 100%; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.field input.pin { font-family: var(--mono); letter-spacing: .3em; font-size: 22px; }
.form-error { color: var(--bad); font-size: 14px; min-height: 1.2em; }
.linkbtn { background: none; border: 0; color: var(--accent); font-weight: 700; padding: 0; text-decoration: underline; text-underline-offset: 3px; }

/* ---- home ---- */
.deck-list { display: grid; gap: 10px; }
.deck-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; transition: border-color 120ms ease, box-shadow 120ms ease; }
.deck-row:hover { border-color: var(--accent); }
.deck-row.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.deck-row .check { width: 22px; height: 22px; accent-color: var(--accent); }
.deck-row .title { font-family: var(--display); font-weight: 700; font-size: 18px; color: var(--ink); text-decoration: none; display: block; line-height: 1.15; }
.deck-row .sub { color: var(--ink-3); font-size: 13px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 3px; }
.deck-row .sub .subject-dot { width: 7px; height: 7px; }
.deck-row .stats { text-align: right; font-family: var(--mono); font-size: 12px; color: var(--ink-3); line-height: 1.5; white-space: nowrap; }
.deck-row .stats b { color: var(--ink); font-weight: 500; font-size: 15px; }
.meter { height: 5px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 8px; }
.meter i { display: block; height: 100%; background: var(--good); border-radius: 999px; }
.select-bar { position: fixed; left: 50%; transform: translateX(-50%); bottom: max(16px, env(safe-area-inset-bottom)); z-index: 25; background: var(--ink); color: var(--ground); border-radius: 999px; padding: 8px 8px 8px 18px; display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow); font-weight: 700; font-size: 15px; }
.select-bar .btn { padding: 10px 16px; font-size: 15px; border-radius: 999px; }
.select-bar .linkbtn { color: var(--ground); opacity: .8; }
.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: 16px; padding: 28px; text-align: center; color: var(--ink-2); display: grid; gap: 10px; justify-items: center; }
.recent { display: grid; gap: 8px; }
.recent-row { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; padding: 10px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; font-size: 14px; }
.recent-row .when { color: var(--ink-3); font-family: var(--mono); font-size: 12px; }
.pct { font-family: var(--mono); font-weight: 500; font-variant-numeric: tabular-nums; }
.pct.good { color: var(--good); } .pct.mid { color: var(--tip); } .pct.low { color: var(--bad); }

/* ---- deck detail ---- */
.statgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; display: flex; flex-direction: column; gap: 2px; }
.stat .n { font-family: var(--mono); font-size: 24px; font-weight: 500; line-height: 1; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); }
.stat.good .n { color: var(--good); } .stat.bad .n { color: var(--bad); }
.section { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.section > h3, .section > summary { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.section summary { cursor: pointer; list-style: none; font-family: var(--display); font-weight: 700; font-size: 17px; }
.section summary::-webkit-details-marker { display: none; }
.section summary::after { content: "+"; font-family: var(--mono); color: var(--ink-3); }
.section[open] > summary::after { content: "–"; }
.section[open] > summary { border-bottom: 1px solid var(--line); }
.section:not([open]) > summary { border-bottom: 0; }
.trow { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; padding: 10px 18px; border-bottom: 1px solid var(--line); font-size: 15px; }
.trow:last-child { border-bottom: 0; }
.trow .t { font-weight: 700; }
.trow .t em { font-weight: 400; color: var(--ink-3); font-style: normal; }
.trow .m { font-family: var(--mono); font-size: 12px; color: var(--ink-3); display: flex; gap: 10px; }
.trow.tricky .m { color: var(--bad); }
.trow.mastered .t::after { content: " ✓"; color: var(--good); }
.history { display: grid; }
.history .trow { grid-template-columns: 1fr auto auto; }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 44px; padding: 12px 18px 0; }
.bars i { flex: 1 1 0; max-width: 22px; border-radius: 3px 3px 0 0; background: var(--accent-soft); position: relative; min-height: 2px; }
.bars i b { position: absolute; left: 0; right: 0; bottom: 0; border-radius: 3px 3px 0 0; background: var(--accent); }
.inline-form { display: grid; gap: 10px; padding: 14px 18px; }
.inline-form .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---- study ---- */
.study-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.modes { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 999px; }
.modes button { border: 0; background: transparent; color: var(--ink-2); padding: 7px 14px; border-radius: 999px; font-size: 14px; font-weight: 700; }
.modes button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.bar { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--good); border-radius: 999px; transition: width 300ms ease; }
.card { position: relative; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px 28px 24px; min-height: 280px; display: flex; flex-direction: column; gap: 16px; border-top: 6px solid var(--accent); }
.card.is-missed-before { border-top-color: var(--bad); }
.card-meta { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-family: var(--mono); font-size: 12px; color: var(--ink-3); letter-spacing: .06em; text-transform: uppercase; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-family: var(--mono); font-size: 11px; letter-spacing: .06em; }
.pill.bad { background: var(--bad-soft); color: var(--bad); } .pill.tip { background: var(--tip-soft); color: var(--tip); } .pill.good { background: var(--good-soft); color: var(--good); } .pill.accent { background: var(--accent-soft); color: var(--accent); }
.prompt { font-family: var(--display); font-weight: 700; font-size: clamp(28px, 6vw, 44px); line-height: 1.08; letter-spacing: -0.015em; margin: 0; text-wrap: balance; }
.prompt.small { font-family: var(--body); font-weight: 400; font-size: clamp(19px, 3vw, 23px); line-height: 1.4; letter-spacing: 0; text-wrap: pretty; }
.prompt ul, .answer ul { margin: 8px 0 0; padding-left: 22px; }
.note { display: block; font-family: var(--body); font-size: 15px; color: var(--ink-3); font-style: italic; margin-top: 6px; letter-spacing: 0; }
.answer { border-top: 1px dashed var(--line); padding-top: 16px; font-size: clamp(18px, 2.6vw, 21px); line-height: 1.45; text-wrap: pretty; }
.answer.term { font-family: var(--display); font-weight: 700; font-size: clamp(28px, 6vw, 40px); line-height: 1.1; }
.answer .label { display: block; font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 6px; }
.tipbox { background: var(--tip-soft); border-left: 4px solid var(--tip); border-radius: 10px; padding: 14px 16px; font-size: 16px; line-height: 1.5; }
.tipbox strong { color: var(--tip); font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; display: block; margin-bottom: 4px; }
.tipbox.goofy { background: var(--accent-soft); border-left-color: var(--accent); }
.tipbox.goofy strong { color: var(--accent); }
.tiplinks { margin-top: 10px; }
.tiplinks button { border: 0; background: transparent; color: var(--tip); font-weight: 700; font-size: 14px; padding: 0; text-decoration: underline; text-underline-offset: 3px; }
.actions { display: grid; grid-template-columns: 1fr; gap: 10px; }
.actions.judge { grid-template-columns: 1fr 1fr; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; align-items: center; }
.kbd { font-family: var(--mono); font-size: 12px; color: var(--ink-3); text-align: center; margin: 0; }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 1px 6px; background: var(--surface); color: var(--ink-2); font-family: inherit; }
.done { text-align: center; padding: 10px 0 4px; display: grid; gap: 14px; justify-items: center; }
.done p { margin: 0; color: var(--ink-2); max-width: 46ch; }
.fade { animation: fade 220ms ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .fade { animation: none; } .bar i, .btn { transition: none; } }
@media (hover: none) and (pointer: coarse) { .kbd { display: none; } .btn.big small { display: none; } }
@media (max-width: 480px) { .card { padding: 22px 18px 20px; } .statgrid { gap: 6px; } .stat { padding: 8px 10px; } .stat .n { font-size: 20px; } .deck-row { grid-template-columns: auto 1fr; } .deck-row .stats { grid-column: 2; text-align: left; display: flex; gap: 12px; } .history .trow { grid-template-columns: 1fr auto; } }

/* ---- add worksheet ---- */
.steps { display: flex; gap: 6px; font-family: var(--mono); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.steps span[aria-current="step"] { color: var(--accent); }
.drop { border: 2px dashed var(--line); border-radius: 18px; padding: 34px 20px; text-align: center; background: var(--surface); display: grid; gap: 10px; justify-items: center; color: var(--ink-2); transition: border-color 120ms ease, background 120ms ease; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop input { display: none; }
textarea.big { min-height: 260px; font-family: var(--mono); font-size: 14px; line-height: 1.5; resize: vertical; }
.spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin .9s linear infinite; vertical-align: -3px; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }
.draft-cards { display: grid; }
.draft-card { display: grid; grid-template-columns: auto 1fr 1fr; gap: 10px; align-items: start; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.draft-card:last-child { border-bottom: 0; }
.draft-card input[type="checkbox"] { width: 20px; height: 20px; margin-top: 12px; accent-color: var(--accent); }
.draft-card input[type="text"] { border: 1px solid transparent; background: transparent; border-radius: 8px; padding: 8px 10px; font-size: 15px; width: 100%; }
.draft-card input[type="text"]:hover { border-color: var(--line); }
.draft-card input[type="text"]:focus { border-color: var(--accent); background: var(--ground); outline: none; }
.draft-card input.term { font-weight: 700; }
.section-toggle { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.section-toggle label { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; border: 1px solid var(--line); border-radius: 999px; padding: 5px 10px; }
@media (max-width: 560px) { .draft-card { grid-template-columns: auto 1fr; } .draft-card input.def { grid-column: 2; } }

/* ---- toast ---- */
.toast { position: fixed; left: 50%; bottom: max(80px, calc(env(safe-area-inset-bottom) + 64px)); transform: translateX(-50%); background: var(--ink); color: var(--ground); padding: 10px 16px; border-radius: 999px; font-weight: 700; font-size: 14px; box-shadow: var(--shadow); z-index: 40; max-width: 90vw; text-align: center; }
.toast.bad { background: var(--bad); color: #fff; }
