:root {
  --ink: #172523;
  --muted: #526461;
  --brand: #173f3a;
  --brand-soft: #dcebe7;
  --paper: #fffdf8;
  --surface: #ffffff;
  --line: #d7dfdc;
  --accent: #f0c96b;
  --danger: #9f3030;
  --font-scale: 1;
  --shadow: 0 10px 30px rgba(23, 63, 58, .08);
}

* { box-sizing: border-box; }
html { background: var(--paper); font-size: calc(16px * var(--font-scale)); }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.6;
  min-height: 100vh;
}
button { font: inherit; }
button:focus-visible, a:focus-visible { outline: 3px solid #146c62; outline-offset: 3px; }
.skip-link { position: fixed; left: 1rem; top: -5rem; z-index: 20; background: #fff; padding: .75rem; color: var(--ink); }
.skip-link:focus { top: 1rem; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem; min-height: 64px;
  padding: .45rem max(.75rem, env(safe-area-inset-right)) .45rem max(.75rem, env(safe-area-inset-left));
  background: rgba(255,253,248,.96); border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: .45rem; flex: 0 1 auto; min-width: 0; min-height: 44px; padding: .25rem; border: 0; background: none; color: var(--brand); font-weight: 800; font-size: 1.18rem; cursor: pointer; }
.brand img { display: block; flex: 0 0 auto; width: 36px; height: 36px; }
.brand span { overflow: hidden; white-space: nowrap; }
.text-size { display: flex; gap: .2rem; }
.text-size button { min-width: 42px; min-height: 44px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 10px; }
.text-size button.active { background: var(--brand); color: #fff; border-color: var(--brand); }

@media (max-width: 340px) {
  .topbar { gap: .25rem; padding-inline: max(.4rem, env(safe-area-inset-left)); }
  .brand { gap: .3rem; padding-inline: .15rem; font-size: 1.08rem; }
  .brand img { width: 32px; height: 32px; }
  .text-size { gap: .1rem; }
  .text-size button { min-width: 40px; padding-inline: .35rem; }
}

main { width: min(100% - 2rem, 680px); margin: 0 auto; padding: 2rem 0 calc(7rem + env(safe-area-inset-bottom)); }
.eyebrow { margin: 0 0 .35rem; color: var(--brand); font-weight: 800; letter-spacing: .05em; text-transform: uppercase; font-size: .8rem; }
h1 { margin: 0 0 1.2rem; font-size: clamp(1.65rem, 7vw, 2.35rem); line-height: 1.22; letter-spacing: -.025em; }
h2 { margin: 0 0 .6rem; font-size: 1.12rem; line-height: 1.35; }
p { max-width: 58ch; }
.lead { color: var(--muted); margin: -.5rem 0 1.5rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 1.35rem; box-shadow: var(--shadow); }
.hero { background: var(--brand); color: #fff; border: 0; }
.hero .eyebrow, .hero .muted { color: #d8ebe6; }
.hero h1 { max-width: 12ch; }
.session-meta { display: flex; gap: 1rem; flex-wrap: wrap; margin: 1.5rem 0; }
.session-meta strong { display: block; font-size: 1.35rem; }
.session-meta span { color: #d8ebe6; font-size: .9rem; }
.progress-track { height: 10px; overflow: hidden; border-radius: 99px; background: rgba(255,255,255,.2); margin: 1rem 0 .4rem; }
.progress-track > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.progress-label { display: flex; justify-content: space-between; font-size: .9rem; }

.primary, .secondary, .choice { border: 0; border-radius: 13px; min-height: 52px; padding: .8rem 1rem; cursor: pointer; font-weight: 750; }
.primary { width: 100%; background: var(--accent); color: #292011; }
.secondary { width: 100%; background: var(--brand-soft); color: var(--brand); }
.choice { background: #fff; border: 2px solid var(--line); color: var(--ink); }
.choice.bad { border-color: #d9a1a1; color: #752222; }
.choice.mid { border-color: #d9ba69; }
.choice.good { border-color: #78a99f; color: #154c43; }
.button-row { display: grid; gap: .65rem; margin-top: 1.3rem; }
.question-number { color: var(--muted); font-size: .88rem; font-weight: 700; }
.answer { border-left: 4px solid var(--accent); padding-left: 1rem; margin: 1.4rem 0; }
.answer strong { display: block; margin-bottom: .25rem; }
.explanation { color: var(--muted); }
.memory { margin: 1.2rem 0; padding: 1rem; border-radius: 14px; background: #fff6d9; }
.memory strong { display: block; }
.lesson-image { width: 100%; margin: 1.25rem auto; text-align: center; overflow: hidden; }
.lesson-image img { display: block; width: 100%; max-width: 520px; height: auto; margin: 0 auto; border-radius: 14px; }
.status-pill { display: inline-flex; align-items: center; min-height: 32px; padding: .25rem .65rem; border-radius: 99px; background: var(--brand-soft); color: var(--brand); font-weight: 750; font-size: .82rem; }
.study-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .8rem; }

.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; margin-bottom: 1.5rem; }
.stat { min-height: 115px; background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 1rem; }
.stat strong { display: block; color: var(--brand); font-size: 1.5rem; line-height: 1.3; }
.stat span { color: var(--muted); font-size: .87rem; }
.section-list { display: grid; gap: .7rem; }
.scope-list { display: flex; flex-direction: column; gap: .7rem; width: 100%; max-width: 620px; margin: 0 auto; }
.scope-card { display: flex; flex-direction: column; align-items: stretch; justify-content: center; gap: .12rem; width: 100%; min-width: 0; min-height: 68px; margin: 0; padding: .85rem 1rem; text-align: left; white-space: normal; overflow: hidden; border: 2px solid var(--line); border-radius: 14px; background: #fff; color: var(--ink); cursor: pointer; }
.scope-card > span { display: block; min-width: 0; max-width: 100%; overflow-wrap: break-word; word-break: normal; hyphens: auto; }
.scope-card__title { color: var(--ink); font-size: 1.02rem; line-height: 1.35; font-weight: 750; }
.scope-card__subtitle { color: var(--ink); font-size: .93rem; line-height: 1.4; font-weight: 600; }
.scope-card__meta { color: var(--muted); font-size: .84rem; line-height: 1.4; font-weight: 500; }
.scope-card.featured { border-color: #78a99f; background: var(--brand-soft); }
.section-row { padding: .9rem 0; border-bottom: 1px solid var(--line); }
.section-row > div:first-child { display: flex; justify-content: space-between; gap: .8rem; }
.mini-track { height: 7px; margin-top: .5rem; background: #e7ecea; border-radius: 9px; overflow: hidden; }
.mini-track span { display: block; height: 100%; background: var(--brand); }
.hard-list { padding-left: 1.25rem; }
.hard-list li { margin-bottom: .55rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.exercise-options { display: grid; gap: .7rem; border: 0; padding: 0; margin: 1.2rem 0; }
.exercise-progress { box-sizing: border-box; width: 100%; min-width: 0; margin: 0 0 1rem; padding: .8rem .9rem .9rem; border: 1px solid var(--line); border-radius: 14px; background: #fff; box-shadow: 0 4px 16px rgba(23, 63, 58, .05); }
.session-goal { display: grid; grid-template-columns: 1fr auto; gap: .1rem .75rem; margin: -.15rem 0 .75rem; padding: 0 0 .7rem; border-bottom: 1px solid var(--line); }
.session-goal strong { color: var(--brand); }
.session-goal span { font-weight: 800; white-space: nowrap; }
.session-goal small { grid-column: 1 / -1; color: var(--muted); }
.exercise-progress__label { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .6rem; font-size: .9rem; }
.exercise-progress__label > strong { color: var(--muted); font-size: .78rem; letter-spacing: .06em; text-transform: uppercase; }
.exercise-progress__label > span { padding: .22rem .55rem; border-radius: 99px; background: var(--brand-soft); color: var(--brand); font-weight: 800; white-space: nowrap; }
.exercise-progress progress { display: block; appearance: none; -webkit-appearance: none; inline-size: 100%; width: 100%; max-width: none; height: 12px; overflow: hidden; border: 0; border-radius: 99px; background: #dcebe7; accent-color: var(--brand); }
.exercise-progress progress::-webkit-progress-bar { border-radius: 99px; background: #dcebe7; }
.exercise-progress progress::-webkit-progress-value { border-radius: 99px; background: var(--brand); }
.exercise-progress progress::-moz-progress-bar { border-radius: 99px; background: var(--brand); }
.streak-badge { display: inline-flex; max-width: 100%; margin: .65rem 0 0; padding: .28rem .65rem; border-radius: 99px; background: #fff3cf; color: #674b00; font-size: .84rem; font-weight: 800; line-height: 1.35; overflow-wrap: anywhere; }
.recovery-notice { display: flex; align-items: flex-start; gap: .65rem; margin: 1rem 0; padding: .85rem; border: 1px solid #b9ded1; border-radius: 14px; background: #eef8f4; color: var(--ink); }
.recovery-notice > span { flex: 0 0 auto; font-size: 1.25rem; line-height: 1.4; }
.recovery-notice h2 { margin: 0 0 .2rem; color: var(--brand); font-size: 1rem; }
.recovery-notice p { margin: 0; font-size: .92rem; }
.recovery-notice small { display: block; margin-top: .3rem; color: var(--muted); line-height: 1.45; }
.session-complete { margin: 1rem 0; padding: .75rem .9rem; border: 1px solid #e2c36f; border-radius: 14px; background: #fff6d9; color: #674b00; font-weight: 800; text-align: center; }
.confetti { position: fixed; z-index: 30; inset: 0; overflow: hidden; pointer-events: none; contain: strict; }
.confetti-piece { position: absolute; top: -18px; left: var(--confetti-x); width: 8px; height: 13px; border-radius: 2px; background: var(--confetti-color); opacity: 0; animation: confetti-fall 1.25s cubic-bezier(.2,.65,.35,1) var(--confetti-delay) forwards; will-change: transform, opacity; }
.confetti-piece:nth-child(3n) { width: 9px; height: 9px; border-radius: 50%; }
.confetti--recovery .confetti-piece { width: 7px; height: 10px; animation-duration: .78s; }
@keyframes confetti-fall {
  0% { opacity: 0; transform: translate3d(0, 0, 0) rotate(0); }
  12% { opacity: 1; }
  100% { opacity: 0; transform: translate3d(var(--confetti-drift), 105vh, 0) rotate(var(--confetti-turn)); }
}
.option { display: flex; align-items: center; gap: .8rem; min-height: 54px; padding: .75rem; border: 2px solid var(--line); border-radius: 13px; cursor: pointer; }
.option:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.option input, .exam-checklist input { width: 22px; height: 22px; flex: 0 0 auto; accent-color: var(--brand); }
.choice-help { margin: 0 0 .25rem; color: var(--muted); font-size: .88rem; }
.matching { display: grid; gap: 1rem; margin: 1.2rem 0; }
.matching label { display: grid; gap: .4rem; }
.matching select { width: 100%; min-height: 50px; padding: .65rem; border: 2px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink); font: inherit; }
.feedback { margin: 1.2rem 0; padding: 1rem; border-radius: 14px; border-left: 5px solid; }
.feedback strong { display: block; margin-bottom: .25rem; }
.feedback span { display: block; }
.feedback.correct { background: #e3f1ed; border-color: #34766a; }
.feedback.incorrect { background: #fff0ec; border-color: #a34b3e; }
.form-error { min-height: 1.6em; color: var(--danger); font-weight: 700; }
.exam-checklist { display: grid; gap: .7rem; margin: 1.2rem 0; padding: 0; border: 0; }
.exam-checklist legend { font-weight: 800; margin-bottom: .7rem; }
.exam-checklist label { display: flex; gap: .8rem; align-items: flex-start; padding: .65rem 0; }
.empty { text-align: center; padding: 2rem 1rem; }
.muted { color: var(--muted); }

.bottom-nav {
  position: fixed; z-index: 9; bottom: 0; left: 0; right: 0;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: .4rem max(.35rem, env(safe-area-inset-right)) max(.4rem, env(safe-area-inset-bottom)) max(.35rem, env(safe-area-inset-left));
  background: #fff; border-top: 1px solid var(--line);
}
.bottom-nav button { min-width: 0; min-height: 58px; padding: .35rem .15rem; border: 0; background: transparent; color: var(--muted); font-size: clamp(.68rem, 3vw, .76rem); line-height: 1.2; font-weight: 700; border-radius: 10px; }
.bottom-nav button span { display: block; font-size: 1.25rem; line-height: 1.1; }
.bottom-nav button.active { color: var(--brand); background: var(--brand-soft); }

@media (min-width: 600px) {
  main { padding-top: 3rem; }
  .button-row.three { grid-template-columns: repeat(3, 1fr); }
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
  .bottom-nav { width: min(620px, calc(100% - 2rem)); left: 50%; right: auto; transform: translateX(-50%); bottom: 1rem; border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; } .confetti { display: none !important; } }
.concept-list { display: grid; gap: .65rem; margin: 1rem 0; }
.concept-list div { padding: .75rem .85rem; border: 1px solid var(--border); border-radius: .75rem; background: var(--surface-soft); }
.concept-list dt { font-weight: 700; }
.concept-list dd { margin: .2rem 0 0; line-height: 1.55; }
