/* ---------- Design tokens ---------- */
:root {
  --bg: #fbf8f1;            /* warm cream: easier on the eyes than pure white */
  --surface: #ffffff;
  --ink: #1f2430;
  --ink-soft: #4a5263;
  --line: #e4ddcc;
  --maths: #2563a8;
  --maths-tint: #e7f0fa;
  --english: #b4462f;
  --english-tint: #fbebe6;
  --accent: var(--maths);
  --accent-tint: var(--maths-tint);
  --good: #2f7d4f;
  --good-tint: #e5f4ea;
  --remember: #fff4cc;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(31, 36, 48, .06), 0 4px 14px rgba(31, 36, 48, .06);
  --font: "Lexend", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body.english { --accent: var(--english); --accent-tint: var(--english-tint); }

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1.125rem;
  line-height: 1.65;
  letter-spacing: .01em;
}

img, video { max-width: 100%; display: block; }

a { color: var(--accent); }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }

/* ---------- Header / nav ---------- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.site-header .wrap {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; min-height: 64px; flex-wrap: wrap;
}
.brand {
  font-weight: 700; font-size: 1.15rem; color: var(--ink); text-decoration: none;
  display: flex; align-items: center; gap: 8px;
}
.brand .beta {
  font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em;
  background: var(--remember); color: #6b5300; padding: 2px 8px; border-radius: 99px;
}
.site-nav { display: flex; gap: 4px; }
.site-nav a {
  text-decoration: none; color: var(--ink-soft); font-weight: 500;
  padding: 8px 14px; border-radius: 99px;
}
.site-nav a:hover { background: var(--bg); color: var(--ink); }
.site-nav a[aria-current="page"] { background: var(--accent-tint); color: var(--accent); }
/* Student link (?student=1): no way to the rest of the site */
.student-view .site-nav, .student-view .site-footer a { display: none; }

/* ---------- Hero ---------- */
.hero { padding: 56px 0 32px; }
.hero h1 { font-size: clamp(2rem, 5vw, 3rem); line-height: 1.15; margin: 0 0 16px; }
.hero p.lead { font-size: 1.25rem; color: var(--ink-soft); max-width: 46ch; margin: 0; }
.page-hero { padding: 40px 0 16px; }
.page-hero h1 { font-size: clamp(1.8rem, 4vw, 2.5rem); margin: 0 0 8px; color: var(--accent); }
.page-hero p { margin: 0; color: var(--ink-soft); max-width: 60ch; }

h2 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 12px; }
h3 { font-size: 1.2rem; margin: 0 0 8px; }

section { padding: 24px 0; }

/* ---------- Cards (home) ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; box-shadow: var(--shadow);
}
.card p { margin: 0 0 12px; color: var(--ink-soft); }
.card p:last-child { margin-bottom: 0; }

.subject-card { display: flex; flex-direction: column; text-decoration: none; color: inherit; border-top: 6px solid var(--c); transition: transform .15s ease; }
.subject-card:hover { transform: translateY(-3px); }
.subject-card h2 { color: var(--c); }
.subject-card ul { margin: 0 0 16px; padding-left: 20px; color: var(--ink-soft); }
.subject-card .go { margin-top: auto; font-weight: 600; color: var(--c); }
.subject-card.maths { --c: var(--maths); }
.subject-card.english { --c: var(--english); }

.steps { counter-reset: step; list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.steps li { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.steps li::before {
  counter-increment: step; content: counter(step);
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent-tint); color: var(--accent); font-weight: 700; margin-bottom: 8px;
}
.steps strong { display: block; }
.steps span { color: var(--ink-soft); font-size: 1rem; }

.callout {
  background: var(--remember); border-radius: var(--radius); padding: 20px 24px;
  border: 1px solid #f0dd8f;
}
.callout h2 { font-size: 1.3rem; }
.callout ul { margin: 8px 0 0; padding-left: 20px; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; margin: 8px 0 16px; }
.btn {
  font: inherit; font-size: .95rem; font-weight: 500; cursor: pointer;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  padding: 8px 16px; border-radius: 99px; min-height: 44px;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Topic accordion ---------- */
.topics { display: grid; gap: 14px; padding-bottom: 48px; }

.topic {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.topic[open] { border-color: var(--accent); }

.topic > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 16px;
  padding: 16px 20px; min-height: 72px;
}
.topic > summary::-webkit-details-marker { display: none; }
.topic > summary:hover { background: var(--accent-tint); }

.topic .num {
  flex: none; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px;
  background: var(--accent-tint); color: var(--accent); font-weight: 700; font-size: 1.1rem;
}
.topic[open] .num { background: var(--accent); color: #fff; }

.topic .title { flex: 1; min-width: 0; }
.topic .title strong { display: block; font-size: 1.2rem; line-height: 1.3; }
.topic .title span { color: var(--ink-soft); font-size: .98rem; }

.topic .meta { flex: none; color: var(--ink-soft); font-size: .9rem; white-space: nowrap; }

.topic .chev {
  flex: none; width: 14px; height: 14px; border-right: 3px solid var(--ink-soft); border-bottom: 3px solid var(--ink-soft);
  transform: rotate(45deg); margin: 0 6px 6px 0; transition: transform .2s ease;
}
.topic[open] .chev { transform: rotate(225deg); margin: 6px 6px 0 0; }

.topic-body { padding: 4px 20px 24px; border-top: 1px solid var(--line); }

.topic-grid { display: grid; grid-template-columns: 1fr 1.25fr; gap: 24px; align-items: start; padding-top: 20px; }

.explain p { margin: 0 0 12px; }
.explain ul, .explain ol { margin: 0 0 12px; padding-left: 22px; }
.explain li { margin-bottom: 4px; }

.remember {
  background: var(--remember); border-left: 5px solid #e0b400; border-radius: 8px;
  padding: 12px 16px; margin-top: 12px; font-weight: 500;
}
.remember::before { content: "Remember: "; font-weight: 700; }

.video-box video {
  width: 100%; aspect-ratio: 16 / 9; background: #111; border-radius: 10px;
}
.video-box p { font-size: .9rem; color: var(--ink-soft); margin: 8px 0 0; }

.practice { margin-top: 28px; }
.practice h3 { display: flex; align-items: center; gap: 8px; }
.practice > ol { padding-left: 26px; margin: 0 0 16px; }
.practice > ol > li { margin-bottom: 10px; padding-left: 4px; }
.practice .hint { color: var(--ink-soft); font-size: .95rem; margin: 0 0 12px; }

.answers { border-radius: 10px; background: var(--good-tint); border: 1px solid #bfe0cb; }
.answers > summary {
  list-style: none; cursor: pointer; padding: 12px 16px; font-weight: 600; color: var(--good);
  display: flex; align-items: center; gap: 8px; min-height: 48px;
}
.answers > summary::-webkit-details-marker { display: none; }
.answers > summary::before { content: "👁"; }
.answers > summary .hide-label { display: none; }
.answers[open] > summary .show-label { display: none; }
.answers[open] > summary .hide-label { display: inline; }
.answers > ol { margin: 0; padding: 0 16px 16px 42px; }
.answers > ol > li { margin-bottom: 6px; }

.frac {
  display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle;
  line-height: 1.05; font-size: .95em; margin: 0 2px;
}
.frac > .top { border-bottom: 2px solid currentColor; padding: 0 3px; }
.frac > .bot { padding: 0 3px; }

/* Text only screen readers and read-aloud hear, e.g. "1 over 2" for a stacked fraction */
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.gap { display: inline-block; min-width: 4.5em; border-bottom: 2px solid var(--ink-soft); }
.u { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px; font-weight: 600; }

.extract {
  background: var(--bg); border-left: 5px solid var(--accent); padding: 10px 16px; border-radius: 6px;
  font-style: italic; margin: 8px 0 12px;
}

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--line); padding: 24px 0 40px; color: var(--ink-soft); font-size: .95rem; }

/* ---------- Small screens ---------- */
@media (max-width: 760px) {
  body { font-size: 1.05rem; }
  .topic-grid { grid-template-columns: 1fr; }
  .video-box { order: -1; }
  .topic > summary { gap: 12px; padding: 14px 14px; }
  .topic .meta { display: none; }
  .topic-body { padding: 4px 14px 20px; }
  .site-header .wrap { padding-top: 8px; padding-bottom: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

@media print {
  .site-header, .toolbar, video, .video-box { display: none !important; }
  .topic { break-inside: avoid; box-shadow: none; }
  .answers:not([open]) { display: none; }
}

/* School name in the header */
.brand .school {
  font-weight: 600; color: var(--ink-soft); padding-right: 10px; margin-right: 2px;
  border-right: 2px solid var(--line);
}
@media (max-width: 480px) {
  .brand { flex-wrap: wrap; row-gap: 0; }
  .brand .school { flex-basis: 100%; border: 0; padding: 0; font-size: .9rem; }
}

/* =====================================================================
   Pathways, support settings and printable worksheets
   ===================================================================== */

/* Each topic keeps its subject colour when Maths and English are mixed */
.is-maths { --accent: var(--maths); --accent-tint: var(--maths-tint); }
.is-english { --accent: var(--english); --accent-tint: var(--english-tint); }

.small { font-size: .9rem; color: var(--ink-soft); }
.loading { padding: 40px 0; color: var(--ink-soft); }
.notice { background: var(--remember); border-radius: 8px; padding: 8px 14px; margin-top: 16px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { color: #fff; filter: brightness(1.08); }
a.btn { display: inline-flex; align-items: center; text-decoration: none; }
.btn-icon { min-width: 44px; padding: 8px 0; justify-content: center; }
.btn:disabled { opacity: .35; cursor: default; }
.read-btn { margin: 4px 0 12px; }
.print-topic { margin: 12px 0 0; font-size: .95rem; }

/* Tick boxes with a bold label and a plain-English line underneath */
.tick { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; cursor: pointer; }
.tick:hover { background: var(--accent-tint); }
.tick input { width: 22px; height: 22px; margin: 3px 0 0; flex: none; accent-color: var(--accent); }
.tick strong { display: block; line-height: 1.3; }
.tick > span > span { display: block; font-size: .92rem; color: var(--ink-soft); line-height: 1.4; }

.speeds { border: 0; padding: 8px 12px 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.speeds legend { font-weight: 700; padding: 0; margin-bottom: 6px; }
.pill input { position: absolute; opacity: 0; }
.pill span { display: inline-block; padding: 6px 16px; border: 1px solid var(--line); border-radius: 99px; cursor: pointer; background: var(--surface); }
.pill input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.pill input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Student "Change how it looks" panel */
.pathway .toolbar { justify-content: space-between; align-items: flex-start; }
.settings { flex: 1 1 320px; max-width: 560px; }
.settings > summary {
  list-style: none; cursor: pointer; display: inline-flex; align-items: center; min-height: 44px;
  padding: 8px 16px; border: 1px solid var(--line); border-radius: 99px; background: var(--surface); font-weight: 500; font-size: .95rem;
}
.settings > summary::-webkit-details-marker { display: none; }
.settings > summary::before { content: "⚙"; margin-right: 8px; }
.settings[open] > summary { border-color: var(--accent); color: var(--accent); }
.settings-body { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 4px 14px; margin-top: 8px; }

/* Teacher builder */
.builder-grid { display: grid; grid-template-columns: 1.15fr 1fr; gap: 32px; align-items: start; padding-bottom: 48px; }
.builder-grid h2 { font-size: 1.25rem; margin: 20px 0 10px; }
.builder-grid > div > h2:first-child { margin-top: 0; }
.builder-side { position: sticky; top: 84px; }
.topic-pick { border: 1px solid var(--line); border-top: 6px solid var(--accent); border-radius: var(--radius); background: var(--surface); padding: 6px 4px 8px; margin: 0 0 16px; }
.topic-pick legend { font-weight: 700; font-size: 1.1rem; color: var(--accent); padding: 0 8px; }
.order { margin: 0; padding: 0; list-style: none; counter-reset: ord; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.order li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 8px 6px 12px; border-bottom: 1px solid var(--line); counter-increment: ord; }
.order li:last-child { border-bottom: 0; }
.order li > span:first-child::before { content: counter(ord) ". "; font-weight: 700; color: var(--accent); }
.order li.small::before, .order li.small > span::before { content: none; }
.order-btns { display: flex; gap: 4px; flex: none; }
.out-label { display: block; font-weight: 600; margin: 12px 0 4px; }
.out-row { display: flex; gap: 6px; }
.out-row input { flex: 1; min-width: 0; font: inherit; font-size: .9rem; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.qr-box { margin-top: 16px; }
.qr-box > summary { cursor: pointer; color: var(--accent); font-weight: 500; }
.qr-box svg { width: min(260px, 100%); height: auto; margin-top: 10px; background: #fff; }

@media (max-width: 860px) {
  .builder-grid { grid-template-columns: 1fr; }
  .builder-side { position: static; }
}

/* ---------- Support settings ---------- */
html.font-readable { font-size: 112.5%; }
html.font-readable body { background: #fdfbf5; line-height: 1.85; letter-spacing: .035em; word-spacing: .14em; }
html.font-readable .explain p, html.font-readable .practice li { max-width: 58ch; }
html.font-readable .topic, html.font-readable .settings-body { box-shadow: none; }

html.motion-reduce *, html.motion-reduce *::before, html.motion-reduce *::after {
  transition: none !important; animation: none !important; scroll-behavior: auto !important;
}
html.motion-reduce .subject-card:hover { transform: none; }

html.chunk-small .practice > ol > li:nth-child(n+4),
html.chunk-small .answers > ol > li:nth-child(n+4),
html.chunk-small .sheet-qs > li:nth-child(n+4),
html.chunk-small .sheet-ans > li:nth-child(n+4) { display: none; }

/* ---------- Printable worksheet ---------- */
.print-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 20px 0; }
.sheet { background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 32px 40px; margin-bottom: 48px; max-width: 820px; }
.sheet-head { display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: flex-end; border-bottom: 2px solid var(--ink); padding-bottom: 10px; margin-bottom: 8px; }
.sheet-brand { margin: 0; font-weight: 700; flex: 1 1 100%; }
.sheet-name { margin: 0; flex: 1; display: flex; gap: 8px; }
.sheet-name span { flex: 1; border-bottom: 1px solid var(--ink-soft); min-width: 6em; }

.sheet-topic { padding: 22px 0 8px; border-bottom: 1px dashed var(--line); }
.sheet-topic h2 { font-size: 1.45rem; margin: 0; color: var(--accent); display: flex; align-items: center; gap: 10px; }
.sheet-num {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: var(--accent); color: #fff; font-size: 1rem; font-weight: 700;
}
.sheet-sub { margin: 2px 0 10px; color: var(--ink-soft); }
.sheet-grid { display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: start; }
.sheet-qr { margin: 0; width: 132px; text-align: center; border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.sheet-qr svg { width: 110px; height: 110px; display: block; margin: 0 auto; }
.sheet-qr figcaption { font-size: .8rem; line-height: 1.3; margin-top: 6px; color: var(--ink-soft); }
.sheet-topic h3 { margin-top: 14px; }

/* Space to write under each question */
.sheet-qs { padding-left: 26px; }
.sheet-qs > li { margin-bottom: 6px; }
.sheet-qs > li::after {
  content: ""; display: block; height: 4.2em; margin-top: 2px;
  background: repeating-linear-gradient(to bottom, transparent 0, transparent calc(2.1em - 1px), #c9c2b2 calc(2.1em - 1px), #c9c2b2 2.1em);
}
.sheet-qs.lines-3 > li::after { height: 6.3em; }

.sheet-answers { padding-top: 24px; }
.sheet-answers > h2 { font-size: 1.6rem; }
.sheet-answers h3 { display: flex; align-items: center; gap: 10px; margin: 18px 0 6px; }
.sheet-answers h3 .sheet-num { width: 28px; height: 28px; font-size: .9rem; background: var(--ink-soft); }
.sheet-ans { margin: 0; padding-left: 26px; }

@media (max-width: 640px) {
  .sheet { padding: 20px 16px; }
  .sheet-grid { grid-template-columns: 1fr; }
}

@media print {
  @page { size: A4; margin: 14mm; }
  html, body { background: #fff !important; font-size: 11.5pt; }
  .site-footer, .print-bar, .notice, .read-btn, .print-topic, .settings { display: none !important; }
  .print-view .wrap { max-width: none; padding: 0; }
  .sheet { border: 0; padding: 0; margin: 0; max-width: none; }
  .sheet-topic { break-inside: auto; }
  .sheet-topic h2, .sheet-topic h3, .sheet-grid, .sheet-qs > li { break-inside: avoid; }
  .sheet-topic h2 { break-after: avoid; }
  .sheet-answers { break-before: page; }
  .sheet-num { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .remember { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  html.font-readable body { font-size: 13pt; }
}

/* ---------- Read aloud: the line being read, and the word being said ---------- */
.reading { background: var(--remember); border-radius: 6px; box-shadow: 0 0 0 6px var(--remember); }
.remember.reading { box-shadow: 0 0 0 3px #e0b400; }
::highlight(qe-word) { background-color: #1f2430; color: #fff; }
@media print { .reading { background: none; box-shadow: none; } }

/* ---------- Subject page: choose topics and support ---------- */
.setup { background: var(--surface); border: 1px solid var(--line); border-top: 6px solid var(--accent); border-radius: var(--radius); box-shadow: var(--shadow); margin: 8px 0 16px; }
.setup > summary {
  list-style: none; cursor: pointer; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 4px 16px; padding: 14px 20px; min-height: 60px;
}
.setup > summary::-webkit-details-marker { display: none; }
.setup-title { font-weight: 700; font-size: 1.15rem; color: var(--accent); }
.setup-title::before { content: "⚙"; margin-right: 10px; }
.setup:not([open]) .setup-title::after { content: " (change)"; font-weight: 500; font-size: .95rem; color: var(--ink-soft); }
.setup-body { border-top: 1px solid var(--line); padding: 0 20px 20px; }
.setup .builder-grid { padding: 20px 0 0; }
.setup h2 + .small { margin: -4px 0 10px; }
.setup .topic-pick { margin: 0; }
.pick-btns { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 12px 4px; }
.share > p.small { margin: 8px 0 0; }
.speeds .small { flex-basis: 100%; margin: -4px 0 2px; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(31, 36, 48, .35); margin-right: 6px; vertical-align: -2px; }
@media (max-width: 760px) { .setup > summary, .setup-body { padding-left: 14px; padding-right: 14px; } }

/* ---------- Background colour (support setting) ---------- */
html[data-bg="cream"]  { --bg: #f8efd4; --surface: #fdf8e8; }
html[data-bg="blue"]   { --bg: #d9e8f6; --surface: #eef5fc; }
html[data-bg="yellow"] { --bg: #f8f1b0; --surface: #fdfadb; }
html[data-bg="green"]  { --bg: #d8eed6; --surface: #eef8ed; }
html[data-bg="pink"]   { --bg: #f6dce6; --surface: #fcf0f4; }
html[data-bg="grey"]   { --bg: #e2e2e2; --surface: #f2f2f2; }
html[data-bg] body { background: var(--bg); }
@media print { html[data-bg] { --bg: #fff; --surface: #fff; } }

/* ---------- Home ---------- */
.why-list { margin: 0; padding-left: 20px; color: var(--ink-soft); }
.why-list li { margin-bottom: 6px; }
.speeds + .speeds { margin-top: 14px; }
