:root {
  --bg: #f7f5ff;
  --card: #ffffff;
  --text: #1f1d2b;
  --muted: #5f5b73;
  --border: #e2def0;
  --accent: #5b4bdb;
  --accent-soft: #ece9ff;
  --good: #1f8a4c;
  --good-soft: #e3f6ea;
  --bad: #c0392b;
  --bad-soft: #fdeaea;
  --math: #2f6fde;
  --english: #c2410c;
  --science: #15803d;
  --history: #9333ea;
  --unit1: #d97706;
  --health: #e11d48;
  --reading: #0d9488;
  --gifted: #7c3aed;
  --gifted-soft: #f3edff;
  --honors: #0e7490;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(40, 30, 90, 0.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15131f;
    --card: #1f1c2c;
    --text: #ecebf5;
    --muted: #a9a5c0;
    --border: #34304a;
    --accent: #9d91ff;
    --accent-soft: #2b2645;
    --good: #4ade80;
    --good-soft: #163324;
    --bad: #f87171;
    --bad-soft: #3a1c1c;
    --math: #6ea0ff;
    --english: #fb923c;
    --science: #4ade80;
    --history: #c084fc;
    --unit1: #fbbf24;
    --health: #fb7185;
    --reading: #2dd4bf;
    --gifted: #b69cff;
    --gifted-soft: #2a2140;
    --honors: #5ec8dc;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { font-size: 17px; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); }
main { flex: 1; width: 100%; max-width: 980px; margin: 0 auto; padding: 20px 16px 40px; outline: none; }
h1 { font-size: 1.9rem; margin: 0.2em 0 0.4em; line-height: 1.2; }
h2 { font-size: 1.35rem; margin: 1.2em 0 0.5em; }
h3 { font-size: 1.1rem; margin: 0 0 0.3em; }
.muted { color: var(--muted); }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5; flex-wrap: wrap;
}
.brand { font-weight: 800; font-size: 1.2rem; text-decoration: none; color: var(--text); display: flex; align-items: center; gap: 6px; }
.logo { font-size: 1.5rem; }
.topnav { display: flex; align-items: center; gap: 14px; }
.topnav a { text-decoration: none; font-weight: 600; }
.topnav { flex-wrap: wrap; justify-content: flex-end; }
.topnav .nav-games { background: var(--accent); color: #fff; padding: 6px 12px; border-radius: 999px; }
.topnav .nav-games:hover { filter: brightness(1.1); }

.footer { text-align: center; font-size: 0.85rem; color: var(--muted); padding: 18px 16px 28px; }

.chip, .btn {
  font: inherit; cursor: pointer; border-radius: 999px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); padding: 6px 14px; font-weight: 600;
}
.btn { border-radius: 10px; padding: 10px 18px; background: var(--accent); color: #fff; border-color: var(--accent); text-decoration: none; display: inline-block; }
.btn.secondary { background: var(--card); color: var(--text); border-color: var(--border); }
.btn:hover, .chip:hover { filter: brightness(1.05); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }

.crumbs { font-size: 0.9rem; margin-bottom: 4px; }
.crumbs a { text-decoration: none; }

.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
a.card { text-decoration: none; color: var(--text); display: block; transition: transform 0.1s; }
a.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card .big { font-size: 2.2rem; line-height: 1; }
.card p { margin: 0.4em 0 0; color: var(--muted); font-size: 0.95rem; }

.hero { text-align: center; padding: 10px 0 6px; }
.hero p { color: var(--muted); max-width: 620px; margin: 0 auto 10px; }
.grade-card { text-align: center; padding: 26px 16px; }
.grade-card .big { font-size: 3rem; font-weight: 800; color: var(--accent); }

.subject { border-top: 5px solid var(--sub, var(--accent)); }
.subject-math { --sub: var(--math); }
.subject-english { --sub: var(--english); }
.subject-science { --sub: var(--science); }
.subject-history { --sub: var(--history); }
.subject-ushistory { --sub: var(--history); }
.subject-unit1 { --sub: var(--unit1); }
.subject-health { --sub: var(--health); }
.focus { border: 2px solid var(--unit1); margin: 8px 0 18px; }
.focus h2 { margin: 0.2em 0 0.1em; }
.focus p { color: var(--muted); margin: 0; }
.focus .btn-row { margin-top: 12px; }
.focus-tag { font-size: 0.85rem; font-weight: 700; color: var(--unit1); text-transform: uppercase; letter-spacing: 0.03em; }
.tag {
  display: inline-block; font-size: 0.75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); margin-right: 4px;
}

.unit-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.unit-row {
  display: flex; align-items: center; gap: 12px; justify-content: space-between; flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px;
}
.unit-row .info { flex: 1 1 260px; min-width: 0; }
.unit-row .info a { font-weight: 700; text-decoration: none; color: var(--text); }
.unit-row .info a:hover { color: var(--accent); }
.unit-row .actions { display: flex; gap: 8px; align-items: center; }
.stars { letter-spacing: 1px; font-size: 1rem; white-space: nowrap; }

.learn ul { padding-left: 1.2em; }
.learn li { margin: 0.35em 0; }
.example {
  background: var(--accent-soft); border-radius: 10px; padding: 10px 14px; margin: 10px 0;
  white-space: pre-wrap; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.95rem;
}
.vocab { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.vcard {
  font: inherit; text-align: left; cursor: default; display: flex; flex-direction: column; gap: 4px;
  background: var(--card); color: var(--text); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px;
}
.vcard .term { font-weight: 800; font-size: 1.05rem; color: var(--accent); }
.vcard .def { font-size: 0.97rem; }
.vex { color: var(--muted); font-size: 0.92rem; }
.vocab.cards .vcard { cursor: pointer; border-style: dashed; min-height: 80px; justify-content: center; }
.vocab.cards .vcard .def, .vocab.cards .vcard .vex { display: none; }
.vocab.cards .vcard.open { border-style: solid; border-color: var(--accent); }
.vocab.cards .vcard.open .def, .vocab.cards .vcard.open .vex { display: block; }
.vocab-help .cards-only, .vocab-help.cards .list-only { display: none; }
.vocab-help.cards .cards-only { display: inline; }
.vocab-help .chip { margin-left: 6px; font-size: 0.9rem; }
.example + .example { margin-top: 10px; }

.resources { margin-top: 24px; }
.resources h3 { margin-bottom: 6px; }
.resources ul { margin: 0; padding-left: 1.1em; }
.resources li { margin: 6px 0; }
.track-badge {
  display: inline-block; font-size: 0.78rem; font-weight: 800; letter-spacing: 0.02em;
  padding: 3px 10px; border-radius: 999px; background: var(--gifted-soft); color: var(--gifted); border: 1px solid var(--gifted);
}
.track-advanced {
  margin-top: 28px; padding: 18px; border-radius: var(--radius);
  background: var(--gifted-soft); border: 2px dashed var(--gifted);
}
.track-advanced h2 { margin-top: 8px; }
.track-advanced .subject { border-top-color: var(--gifted); }
.subject-advanced { --sub: var(--gifted); }
.unit-list.advanced .unit-row { border-left: 4px solid var(--gifted); }
.verify { font-size: 0.72rem; font-weight: 700; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--unit1); color: var(--unit1); white-space: nowrap; }
.note { margin: 12px 0; }
.lanes { display: grid; gap: 10px; }
.lane { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.lane-name { font-weight: 800; margin-bottom: 6px; }
.lane-steps { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 4px; }
.step { background: var(--accent-soft); border-radius: 8px; padding: 3px 9px; font-size: 0.92rem; font-weight: 600; }
.arrow { color: var(--muted); }
.ms-grade { margin-top: 16px; }
.ms-grade details { margin-top: 10px; }
.ms-grade summary { cursor: pointer; font-weight: 600; color: var(--accent); }
table.tracks td.t-honors { color: var(--honors); font-weight: 600; }
table.tracks td.t-gifted { color: var(--gifted); font-weight: 600; }
.search { font: inherit; width: 100%; max-width: 420px; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--card); color: var(--text); margin: 6px 0 4px; }
.gloss-subject { margin-top: 10px; }
.gloss-subject h2 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.gloss-subject h2 .chip { font-size: 0.85rem; text-decoration: none; }
.gloss-unit h3 { margin: 14px 0 6px; font-size: 1rem; }
.gloss-unit h3 a { text-decoration: none; }
.glossary { margin: 0; display: grid; gap: 8px; }
.gloss-item { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; }
.gloss-item dt { font-weight: 800; }
.gloss-item dd { margin: 2px 0 0; }
.gloss-subject.advanced .gloss-item { border-left: 4px solid var(--gifted); }

.quiz { max-width: 720px; margin: 0 auto; }
.progressbar { height: 10px; background: var(--border); border-radius: 999px; overflow: hidden; margin: 8px 0 18px; }
.progressbar > div { height: 100%; background: var(--accent); transition: width 0.25s; }
.question { font-size: 1.25rem; font-weight: 650; margin: 0 0 14px; white-space: pre-wrap; }
.choices { display: grid; gap: 10px; }
.choice {
  font: inherit; text-align: left; cursor: pointer; padding: 12px 16px; border-radius: 12px;
  border: 2px solid var(--border); background: var(--card); color: var(--text); font-size: 1.05rem;
}
.choice:hover:not(:disabled) { border-color: var(--accent); }
.choice.correct { border-color: var(--good); background: var(--good-soft); }
.choice.wrong { border-color: var(--bad); background: var(--bad-soft); }
.choice:disabled { cursor: default; }
.feedback { margin-top: 14px; padding: 12px 14px; border-radius: 12px; }
.feedback.good { background: var(--good-soft); }
.feedback.bad { background: var(--bad-soft); }
.speak { font-size: 0.9rem; padding: 4px 10px; }
.score-big { font-size: 3rem; font-weight: 800; text-align: center; margin: 6px 0; }
.review-item { border-left: 4px solid var(--bad); padding: 6px 12px; margin: 10px 0; background: var(--card); border-radius: 0 10px 10px 0; }

.stat-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin: 12px 0 8px; }
.stat { text-align: center; }
.stat .num { font-size: 1.9rem; font-weight: 800; color: var(--accent); }

table.prog { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
table.prog th, table.prog td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }
.table-wrap { overflow-x: auto; }

.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,0.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20; }
.modal { background: var(--card); border-radius: var(--radius); padding: 20px; width: 100%; max-width: 420px; }
.modal input { font: inherit; width: 100%; padding: 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.profile-list { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 8px; }
.profile-list button { width: 100%; text-align: left; }

@media (max-width: 560px) {
  html { font-size: 16px; }
  h1 { font-size: 1.55rem; }
  .question { font-size: 1.12rem; }
}

/* ---------- Reading comprehension passages ---------- */
.subject-reading { --sub: var(--reading); }
.quiz.wide { max-width: 860px; }
.passage {
  background: var(--card); border: 1px solid var(--border); border-left: 5px solid var(--reading);
  border-radius: 12px; padding: 14px 18px; margin: 10px 0 16px;
  font-family: Georgia, "Times New Roman", serif; font-size: 1.06rem; line-height: 1.75;
}
.passage h3 { margin: 0 0 2px; font-family: system-ui, sans-serif; }
.passage h4 { margin: 14px 0 2px; font-family: system-ui, sans-serif; font-size: 1rem; color: var(--reading); }
.passage .byline { font-family: system-ui, sans-serif; font-size: 0.82rem; color: var(--muted); margin-bottom: 8px; }
.passage p { margin: 0 0 0.7em; }
.pnum {
  display: inline-block; min-width: 1.3em; margin-right: 6px; font: 700 0.72rem/1.6 system-ui, sans-serif;
  color: var(--reading); vertical-align: top; text-align: right;
}
.passage-poem .stanza { display: flex; gap: 8px; margin-bottom: 0.9em; }
.passage-poem .stanza p { white-space: pre-line; margin: 0; }
.passage-script .script-line { margin: 0 0 0.55em; }
.passage-script em { color: var(--muted); }
.passage-panel { margin: 10px 0 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--accent-soft); padding: 4px 12px 8px; }
.passage-panel summary { cursor: pointer; font-weight: 700; padding: 8px 0; }
.passage-panel .passage { max-height: 46vh; overflow-y: auto; margin-bottom: 4px; }
.passage-panel .speak { margin: 0 0 4px; }
@media (max-width: 560px) { .passage { font-size: 1rem; padding: 12px 14px; } .passage-panel .passage { max-height: 34vh; } }

/* ---------- Math worksheets ---------- */
.print-only { display: none; }
.worksheet { max-width: 900px; margin: 0 auto; }
.ws-head h1 { margin-bottom: 4px; }
.ws-inst { background: var(--accent-soft); border-radius: 10px; padding: 10px 14px; margin: 8px 0 14px; }
.ws-items { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 18px; }
.ws-item { background: var(--card); border: 2px solid var(--border); border-radius: 12px; padding: 10px 14px; break-inside: avoid; }
.ws-item.ok { border-color: var(--good); background: var(--good-soft); }
.ws-item.bad { border-color: var(--bad); background: var(--bad-soft); }
.ws-q { font-size: 1.3rem; font-weight: 650; }
.ws-n { color: var(--muted); font-weight: 700; margin-right: 4px; }
.eq { font-family: ui-monospace, Menlo, Consolas, "Courier New", monospace; }
.ws-ans { margin-top: 6px; }
.ws-ans label { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.15rem; display: flex; align-items: center; gap: 8px; }
.ws-ans input { font: inherit; width: 8em; max-width: 100%; padding: 6px 10px; border-radius: 8px; border: 2px solid var(--border); background: var(--bg); color: var(--text); }
.ws-fb { font-size: 0.93rem; margin-top: 4px; }
.ws-steps { margin-top: 4px; font-size: 0.93rem; }
.ws-steps summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.ws-steps pre { background: var(--accent-soft); border-radius: 8px; padding: 8px 12px; margin: 6px 0 0; white-space: pre-wrap; font-size: 0.95rem; }
.ws-key { display: none; margin-top: 6px; color: var(--good); }
.show-key .ws-key { display: block; }
.ws-card h3 { font-size: 1rem; }
.riddle { margin-top: 22px; background: var(--accent-soft); border-radius: var(--radius); padding: 12px 14px; }
.riddle-q { margin: 0 0 8px; font-size: 1.25rem; }
.code-bar { display: flex; flex-wrap: wrap; gap: 4px; }
.code-cell { width: 54px; border: 2px solid var(--text); background: var(--card); border-radius: 4px; text-align: center; }
.code-cell.space { background: linear-gradient(to top right, transparent calc(50% - 1px), var(--text) 50%, transparent calc(50% + 1px)), var(--card); }
.code-letter { height: 38px; font-size: 1.6rem; font-weight: 800; color: var(--accent); line-height: 38px; }
.code-num { border-top: 2px solid var(--text); font-weight: 700; padding: 2px 0; font-family: ui-monospace, Menlo, monospace; }
.code-cell.solved { border-color: var(--good); }
.riddle-help { font-size: 0.85rem; margin: 8px 0 0; }
.riddle-done { margin-top: 10px; font-size: 1.2rem; background: var(--good-soft); border-radius: 10px; padding: 10px 14px; }
@media (max-width: 640px) { .ws-items { grid-template-columns: 1fr; } .code-cell { width: 44px; } }
@media print {
  body { background: #fff; color: #000; display: block; min-height: 0; }
  .topbar, .footer, .no-print, .crumbs, .btn-row { display: none !important; }
  .print-only { display: block; }
  main { max-width: none; padding: 0; }
  .ws-item { border: 1px solid #999; background: #fff !important; min-height: 130px; padding: 8px 12px; }
  .ws-items.tight .ws-item { min-height: 105px; }
  .ws-work { min-height: 70px; background: linear-gradient(#bbb, #bbb) 50% 0 / 1px 100% no-repeat; }  /* T-chart line */
  .ws-q { font-size: 1.15rem; }
  .ws-inst { background: none; border: 1px solid #bbb; }
  .ws-head h1 { font-size: 1.3rem; }
  .ws-meta { margin: 6px 0 8px; font-size: 0.95rem; }
  .ws-key { color: #000; }
  .riddle { background: none; border: 1px solid #999; break-inside: avoid; }
  .code-cell { border-color: #000; }
  .code-letter { color: #000; }
}

/* ---------- Math roadmap ---------- */
.lead { font-size: 1.1rem; line-height: 1.65; }
.here-card ul { margin: 6px 0; padding-left: 1.2em; }
.mr-stage { margin-top: 26px; padding: 16px 18px 20px; border-radius: var(--radius); border: 1px solid var(--border); border-left: 8px solid var(--stage, var(--accent)); background: var(--card); }
.mr-stage .card { background: var(--bg); }
.mr-foundations { --stage: #2f6fde; }
.mr-middle { --stage: #0d9488; }
.mr-high { --stage: #9333ea; }
.mr-college { --stage: #c2410c; }
.mr-stage-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.mr-stage-head h2 { margin: 0; }
.topic-card .topic-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.topic-card.featured { border: 2px solid var(--accent); }
.feat-note { color: var(--accent) !important; font-weight: 700; }
.pathways th, .pathways td, .roadtable th, .roadtable td { vertical-align: top; }
.roadtable thead th { white-space: nowrap; }
.roadtable tbody th { text-align: left; min-width: 140px; }
.pathways td { min-width: 110px; }
.topic-head { display: flex; align-items: center; gap: 16px; margin-bottom: 6px; }
.topic-head h1 { margin: 0 0 4px; }
.topic-icon { font-size: 3rem; width: 78px; height: 78px; display: flex; align-items: center; justify-content: center; background: var(--accent-soft); border-radius: 20px; flex: none; }
.topic-tags { margin: 0 0 4px; }
.tag.here { background: var(--good-soft); color: var(--good); }
.callout { background: var(--accent-soft); border-left: 5px solid var(--accent); border-radius: 10px; padding: 12px 16px; margin: 14px 0; }
.learn-list, .use-list { padding-left: 1.2em; }
.learn-list li, .use-list li { margin: 4px 0; }
.try-list { display: grid; gap: 8px; }
.try { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 8px 14px; }
.try summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.try-ans { margin-top: 6px; padding: 8px 12px; background: var(--good-soft); border-radius: 8px; }
.connect { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.connect .chip { display: inline-block; margin: 3px 4px 3px 0; text-decoration: none; }
.connect .chip.current { background: var(--accent); color: #fff; border-color: var(--accent); }
.arrow-big { font-size: 1.6rem; color: var(--muted); }
.two-col { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); margin-top: 20px; }
.two-col ul { margin: 6px 0 0; padding-left: 1.2em; }
.onsite li { margin: 5px 0; }
@media (max-width: 560px) { .topic-icon { width: 60px; height: 60px; font-size: 2.2rem; } .arrow-big { transform: rotate(90deg); } }

/* ---------- Roadmap deep dives ---------- */
.mr-family { --stage: #d97706; background: var(--accent-soft); }
.deep { display: grid; gap: 14px; }
.deep-card h3 { margin: 0 0 6px; display: flex; align-items: center; gap: 8px; }
.deep-icon { display: inline-flex; width: 34px; height: 34px; align-items: center; justify-content: center; background: var(--accent-soft); border-radius: 10px; font-size: 1.15rem; flex: none; }
.deep-rules { margin: 6px 0 10px; padding-left: 1.2em; }
.deep-rules li { margin: 3px 0; }
.worked { background: var(--accent-soft); border-radius: 10px; padding: 10px 14px; margin: 10px 0; }
.worked-q { margin-bottom: 4px; }
.worked-steps { margin: 4px 0 6px; padding-left: 1.4em; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.95rem; }
.worked-steps li { margin: 3px 0; }
.worked-a { color: var(--good); }
.mistake { background: var(--bad-soft); border-radius: 10px; padding: 8px 14px; margin: 8px 0; }
.mistake .wrong { text-decoration: line-through; text-decoration-color: var(--bad); }
.mistake .to { color: var(--muted); margin: 0 4px; }
.mistake .right { color: var(--good); font-weight: 600; }
.deep-practice { font-size: 0.93rem; margin-top: 6px; }

/* ---------- Bonus quizzes ---------- */
.bonus { margin-top: 26px; padding: 14px 16px; border-radius: var(--radius); background: var(--accent-soft); border: 1px dashed var(--accent); }
.bonus h2 { margin-top: 0; }
.bonus-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.bonus-grid.inline { justify-content: flex-end; }
.bonus-chip { display: inline-flex; flex-direction: column; align-items: center; min-width: 54px; padding: 6px 8px; border-radius: 12px; background: var(--card); border: 1px solid var(--border); text-decoration: none; color: var(--text); line-height: 1.2; }
.bonus-chip b { font-size: 1.05rem; }
.bonus-chip .stars { font-size: 0.7rem; }
.bonus-chip:hover { border-color: var(--accent); }
.bonus-note { display: inline-block; margin-top: 4px; font-size: 0.85rem; font-weight: 600; text-decoration: none; }
