:root {
  --bg: #f6f4ef;
  --surface: #fffdf9;
  --sunk: #eeebe3;
  --ink: #1f2421;
  --muted: #646b66;
  --line: #ddd8cc;
  --accent: #2f6b55;
  --accent-ink: #ffffff;
  --accent-soft: #dfeae3;
  --good: #2f7a4a;
  --good-soft: #e1f0e5;
  --bad: #b2453a;
  --bad-soft: #f7e3df;
  --warn-soft: #f6edd6;
  --key: #6a4c93;
  --key-soft: #ece5f5;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(30, 30, 20, .06), 0 6px 20px rgba(30, 30, 20, .06);
  --font: ui-sans-serif, -apple-system, "Segoe UI", system-ui, Roboto, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151816;
    --surface: #1d211f;
    --sunk: #252a27;
    --ink: #e9ece9;
    --muted: #9aa39d;
    --line: #333a36;
    --accent: #6fbf9b;
    --accent-ink: #0f1a14;
    --accent-soft: #23362d;
    --good: #74c690;
    --good-soft: #1f3326;
    --bad: #ee8b7f;
    --bad-soft: #3a2422;
    --warn-soft: #352f1f;
    --key: #b9a0e0;
    --key-soft: #2c2638;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 var(--font); }
a { color: var(--accent); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.pad { padding: 24px; }

.top { display: flex; align-items: center; gap: 14px; padding: 14px max(20px, env(safe-area-inset-left)); border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.brand { font-family: var(--serif); font-weight: 700; font-size: 20px; color: var(--ink); text-decoration: none; }
#crumb { color: var(--muted); font-size: 14px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

main { max-width: 860px; margin: 0 auto; padding: 24px 20px 96px; }
main:focus { outline: none; }
h1 { font-family: var(--serif); font-size: clamp(26px, 4vw, 34px); line-height: 1.15; margin: 0 0 6px; }
h2 { font-family: var(--serif); font-size: 22px; margin: 32px 0 12px; }
h3 { font-size: 17px; margin: 22px 0 8px; }

/* home */
.packs { display: grid; gap: 12px; margin-top: 18px; }
.pack { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; align-items: center; padding: 16px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: inherit; box-shadow: var(--shadow); }
.pack:hover { border-color: var(--accent); }
.pack .t { font-weight: 650; font-size: 17px; }
.pack .c { color: var(--muted); font-size: 14px; }
.pack .when { grid-row: span 2; text-align: right; }
.pack .meter { grid-column: 1 / -1; }
.chip { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 13px; font-weight: 600; background: var(--sunk); color: var(--muted); white-space: nowrap; }
.chip.soon { background: var(--bad-soft); color: var(--bad); }
.chip.week { background: var(--warn-soft); color: var(--ink); }
.chip.key { background: var(--key-soft); color: var(--key); }
.chip.topic { background: var(--accent-soft); color: var(--accent); }
.meter { height: 6px; background: var(--sunk); border-radius: 99px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
details.past { margin-top: 28px; }
details.past summary { cursor: pointer; color: var(--muted); }

/* pack header + tabs */
.meta { color: var(--muted); margin-bottom: 18px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--sunk); border-radius: 12px; margin-bottom: 22px; }
.tabs a { flex: 1; text-align: center; padding: 9px 8px; border-radius: 9px; text-decoration: none; color: var(--muted); font-weight: 600; }
.tabs a[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
select, .btn { font: inherit; font-size: 14px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 650; }
.btn.big { font-size: 17px; padding: 13px 18px; border-radius: 12px; }
.spacer { flex: 1; }

/* flashcards */
.progress { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--muted); margin-bottom: 14px; }
.progress .meter { flex: 1; }
.stage { perspective: 1400px; }
.card { position: relative; min-height: 300px; cursor: pointer; transform-style: preserve-3d; transition: transform .45s cubic-bezier(.2, .7, .2, 1); }
.card.flipped { transform: rotateY(180deg); }
.face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); padding: 26px 28px 22px; display: flex; flex-direction: column; overflow: auto; }
.face.back { transform: rotateY(180deg); background: var(--surface); border-color: var(--accent); }
.face .labels { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.face .q { font-family: var(--serif); font-size: clamp(20px, 3.2vw, 26px); line-height: 1.35; white-space: pre-wrap; margin: auto 0; }
.face .q-small { color: var(--muted); font-size: 14px; white-space: pre-wrap; padding-bottom: 14px; margin-bottom: 16px; border-bottom: 1px dashed var(--line); }
.face .a { font-size: clamp(19px, 3vw, 24px); line-height: 1.4; white-space: pre-wrap; margin: auto 0; font-weight: 550; }
.face .hint { color: var(--muted); font-size: 13px; text-align: center; margin-top: 18px; }
.grade { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.grade .btn { padding: 14px; font-size: 16px; font-weight: 650; border-radius: 12px; }
.grade .again { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.grade .got { background: var(--good-soft); color: var(--good); border-color: transparent; }
.grade .btn:disabled { opacity: .35; cursor: default; }
kbd { font: 12px ui-monospace, monospace; padding: 1px 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; color: var(--muted); }
.keys { text-align: center; color: var(--muted); font-size: 13px; margin-top: 12px; }
.done { text-align: center; padding: 40px 20px; background: var(--surface); border-radius: 20px; border: 1px solid var(--line); }
.done .big-num { font-family: var(--serif); font-size: 52px; line-height: 1; }
.done .row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 22px; }

/* practice test */
.qs { display: grid; gap: 14px; }
.qbox { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.qbox.right { border-color: var(--good); }
.qbox.wrong { border-color: var(--bad); }
.qhead { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; font-size: 14px; color: var(--muted); }
.qtext { white-space: pre-wrap; margin-bottom: 12px; font-size: 17px; }
.choices { display: grid; gap: 8px; }
.choice { display: flex; gap: 12px; align-items: flex-start; text-align: left; width: 100%; padding: 11px 14px; border: 1px solid var(--line); border-radius: 11px; background: var(--bg); cursor: pointer; }
.choice .L { font-weight: 700; color: var(--muted); min-width: 1.2em; }
.choice[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.choice.is-right { border-color: var(--good); background: var(--good-soft); }
.choice.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.choice:disabled { cursor: default; color: var(--ink); }
textarea { width: 100%; min-height: 110px; font: inherit; padding: 12px; border-radius: 11px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); resize: vertical; }
.explain { margin-top: 12px; padding: 12px 14px; background: var(--sunk); border-radius: 10px; font-size: 15px; white-space: pre-wrap; }
.explain b { display: block; margin-bottom: 2px; }
.points label { display: flex; gap: 8px; align-items: flex-start; margin-top: 6px; cursor: pointer; }
.submitbar { position: sticky; bottom: 0; margin: 20px -20px 0; padding: 14px 20px calc(14px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); display: flex; gap: 10px; align-items: center; }
.score { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; }
.score .big-num { font-family: var(--serif); font-size: 44px; line-height: 1; }
table.topics { width: 100%; border-collapse: collapse; margin-top: 14px; font-size: 15px; }
table.topics td { padding: 8px 4px; border-top: 1px solid var(--line); vertical-align: middle; }
table.topics td.n { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.topics .meter { width: 100%; min-width: 60px; }

/* guide */
.topic { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; }
.topic > summary { cursor: pointer; padding: 15px 18px; font-weight: 650; font-size: 17px; list-style: none; display: flex; justify-content: space-between; gap: 10px; }
.topic > summary::-webkit-details-marker { display: none; }
.topic > summary::after { content: "+"; color: var(--muted); font-weight: 400; }
.topic[open] > summary::after { content: "−"; }
.topic .body { padding: 0 18px 16px; }
dl.terms { margin: 0; }
dl.terms dt { margin-top: 12px; }
dl.terms dt:first-child { margin-top: 0; }
dl.terms dt { font-weight: 650; }
dl.terms dd { margin: 0; color: var(--ink); }
ul.tidy { margin: 0; padding-left: 20px; }
ul.tidy li { margin: 4px 0; }
.mistakes { background: var(--warn-soft); border-radius: 10px; padding: 10px 14px; margin-top: 12px; }
.mistakes ul { margin: 4px 0 0; }
.sched label { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer; }
.sched input:checked + span { color: var(--muted); text-decoration: line-through; }

@media (max-width: 560px) {
  main { padding: 18px 14px 96px; }
  .face { padding: 20px; }
  .card { min-height: 340px; }
  .submitbar { margin: 20px -14px 0; padding-left: 14px; padding-right: 14px; }
}
@media (prefers-reduced-motion: reduce) { .card { transition: none; } }
