/* ===== Colours (light mode, then dark mode) ===== */
:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5b6676;
  --border: #dde2e9;
  --accent: #1f5fbf;
  --accent-soft: #e6eefb;
  --good: #1e7a46;
  --good-soft: #e3f4ea;
  --bad: #b3261e;
  --bad-soft: #fbe9e7;
  --warn-soft: #fff6dc;
  --theme-a: #1f5fbf;
  --theme-b: #c2561a;
  --theme-c: #0f8077;
  --theme-d: #7b3fbf;
  --theme-e: #2e7d32;
  --radius: 10px;
  --max: 960px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1b2129;
    --text: #e6eaf0;
    --muted: #9aa5b4;
    --border: #2d3540;
    --accent: #7fb0ff;
    --accent-soft: #1d2b42;
    --good: #6fd39a;
    --good-soft: #17301f;
    --bad: #ff8a80;
    --bad-soft: #3a1c1a;
    --warn-soft: #3a3218;
    --theme-a: #7fb0ff;
    --theme-b: #ffa36c;
    --theme-c: #5fd3c6;
    --theme-d: #c39bff;
    --theme-e: #85d68a;
  }
}

/* ===== Basics ===== */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
main { max-width: var(--max); margin: 0 auto; padding: 24px 16px 48px; }
h1, h2, h3 { line-height: 1.25; }
h1 { font-size: 1.9rem; margin: 0.4em 0 0.5em; }
h2 { font-size: 1.35rem; margin-top: 1.8em; }
a { color: var(--accent); }
img, svg { max-width: 100%; height: auto; }
.lead { font-size: 1.1rem; color: var(--muted); }
.code { color: var(--muted); font-weight: 600; margin-right: 0.3em; }
mjx-container[display="true"] { overflow-x: auto; overflow-y: hidden; max-width: 100%; }
.key, .worked, .feedback, .markscheme { overflow-x: auto; }

/* ===== Keyboard and screen-reader helpers ===== */
/* A clear outline on whatever has keyboard focus (mouse clicks don't show it) */
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
/* Headings and feedback boxes the page moves focus to don't need an outline: they can't be clicked */
[tabindex="-1"]:focus { outline: none; }
.skip-link { position: absolute; left: 8px; top: -60px; z-index: 100; background: var(--accent); color: var(--surface); padding: 8px 14px; border-radius: 8px; font-weight: 600; text-decoration: none; }
.skip-link:focus { top: 8px; }
/* Read by screen readers but not shown on screen */
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } * { transition: none !important; animation: none !important; } }

/* ===== Header and menu ===== */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.site-header .inner { max-width: var(--max); margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.brand { font-weight: 700; text-decoration: none; color: var(--text); font-size: 1.1rem; }
.brand span { color: var(--accent); }
.menu-btn { display: none; background: none; border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 6px 12px; font: inherit; cursor: pointer; }
.site-nav ul { list-style: none; margin: 0; padding: 0; display: flex; gap: 4px; flex-wrap: wrap; }
.site-nav a { display: block; padding: 6px 10px; border-radius: 8px; text-decoration: none; color: var(--text); font-size: 0.95rem; }
.site-nav a:hover { background: var(--accent-soft); }
.site-nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
@media (max-width: 760px) {
  .menu-btn { display: block; }
  .site-nav { display: none; width: 100%; }
  .site-nav.open { display: block; }
  .site-nav ul { flex-direction: column; padding-bottom: 8px; }
  .site-nav a { padding: 10px; }
}

/* ===== Footer ===== */
.site-footer { border-top: 1px solid var(--border); color: var(--muted); font-size: 0.85rem; }
.site-footer .inner { max-width: var(--max); margin: 0 auto; padding: 16px; }

/* ===== Cards and grids ===== */
.card-grid { list-style: none; padding: 0; margin: 16px 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.card { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: var(--text); height: 100%; }
a.card:hover { border-color: var(--accent); }
.card h3 { margin: 0 0 4px; font-size: 1.05rem; }
.card p { margin: 0; color: var(--muted); font-size: 0.92rem; }
.card[data-theme] { border-left: 5px solid var(--theme-color, var(--accent)); }
[data-theme="A"] { --theme-color: var(--theme-a); }
[data-theme="B"] { --theme-color: var(--theme-b); }
[data-theme="C"] { --theme-color: var(--theme-c); }
[data-theme="D"] { --theme-color: var(--theme-d); }
[data-theme="E"] { --theme-color: var(--theme-e); }

/* ===== Small pieces ===== */
.tag { display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); vertical-align: middle; }
.tag.hl { background: var(--warn-soft); color: var(--text); }
.notice { background: var(--warn-soft); border-radius: var(--radius); padding: 12px 16px; margin: 16px 0; }
.box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px 16px; margin: 16px 0; }
.crumbs { font-size: 0.9rem; color: var(--muted); margin: 0; }
.button, button.primary { display: inline-block; background: var(--accent); color: var(--surface); border: 0; border-radius: 8px; padding: 10px 16px; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.button.secondary, button.secondary { background: var(--surface); color: var(--accent); border: 1px solid var(--accent); }
.topic-nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 40px; flex-wrap: wrap; }
.topic-nav a { flex: 1 1 200px; }
.topic-nav .next { text-align: right; }
.page-back { margin: 36px 0 0; padding-top: 18px; border-top: 1px solid var(--border); }

/* ===== Notes pages ===== */
.part-banner { margin: 40px 0 0; padding: 14px 18px; border-radius: var(--radius); background: var(--accent); color: var(--surface); font-size: 1.5rem; font-weight: 700; scroll-margin-top: 70px; }
.part-banner .code { color: inherit; opacity: 0.75; }
.part-banner p { margin: 4px 0 0; font-size: 1rem; font-weight: 400; opacity: 0.95; }
.part-banner + h2 { margin-top: 18px; }
/* HL-only part of a topic: orange banner plus an orange line down the whole HL section */
.part-banner.hl { background: var(--theme-b); }
.hl-zone { border-left: 4px solid var(--theme-b); padding-left: 12px; margin-top: 6px; }
.hl-zone > h2:first-child { margin-top: 12px; }
.hl-end { margin: 18px 0 0; padding: 8px 12px; border-radius: var(--radius); background: var(--warn-soft); font-size: 0.9rem; font-weight: 600; }
.toc { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 16px; }
.toc ol { margin: 6px 0; padding-left: 1.3em; }
.key { background: var(--accent-soft); border-radius: var(--radius); padding: 10px 16px; margin: 16px 0; }
.worked { background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--theme-b); border-radius: var(--radius); padding: 4px 16px 10px; margin: 18px 0; }
.worked h3 { font-size: 1rem; margin: 10px 0 4px; color: var(--theme-b); }
.table-wrap { overflow-x: auto; }
table.notes { border-collapse: collapse; margin: 12px 0; width: 100%; }
table.notes th, table.notes td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
table.notes th { background: var(--accent-soft); }
details.check { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 16px; margin: 10px 0; }
details.check summary { cursor: pointer; font-weight: 600; }
details.check[open] summary { margin-bottom: 6px; }

/* Diagrams drawn as inline SVG: colours follow light/dark mode */
figure.diagram { margin: 20px 0; text-align: center; color: var(--text); }
figure.diagram svg { width: 100%; max-width: 540px; height: auto; }
figure.diagram figcaption { font-size: 0.9rem; color: var(--muted); margin-top: 6px; }
.diagram-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px; }
.diagram-row figure.diagram { margin: 8px 0; }
figure.diagram svg.small { max-width: 280px; }
/* Photos from Wikimedia Commons and similar: the credit line sits under the caption */
figure.diagram img.photo { display: block; margin: 0 auto; width: 100%; max-width: 600px; height: auto; border-radius: 8px; }
figure.diagram .credit { display: block; font-size: 0.8rem; margin-top: 4px; }
.diagram text { fill: currentColor; font-size: 16px; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
@media (max-width: 600px) { .diagram text { font-size: 19px; } }
.key-1 { color: var(--accent); font-weight: 600; }
.key-2 { color: var(--theme-b); font-weight: 600; }
[id] { scroll-margin-top: 70px; }
.diagram .axis { stroke: currentColor; stroke-width: 1.5; fill: none; }
.diagram .grid { stroke: var(--border); stroke-width: 1; }
.diagram .l1 { stroke: var(--accent); stroke-width: 3; fill: none; }
.diagram .l2 { stroke: var(--theme-b); stroke-width: 3; fill: none; }
.diagram .l3 { stroke: currentColor; stroke-width: 2.5; fill: none; }
.diagram .thin { stroke-width: 2; }
.diagram .dash { stroke-dasharray: 7 5; }
.diagram .area { fill: var(--accent-soft); stroke: none; }
.diagram .f1 { fill: var(--accent); }
.diagram .f2 { fill: var(--theme-b); }
.diagram .f3 { fill: currentColor; }
.diagram .t1 { fill: var(--accent); font-weight: 600; }
.diagram .t2 { fill: var(--theme-b); font-weight: 600; }

/* ===== "Maths link" box on topic pages: where a physics idea uses DP Maths ===== */
.maths-link { background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--theme-c); border-radius: var(--radius); padding: 4px 16px 10px; margin: 18px 0; overflow-x: auto; }
.maths-link h3 { font-size: 1rem; margin: 10px 0 4px; color: var(--theme-c); }
.maths-link .tag { background: var(--surface); border: 1px solid var(--theme-c); color: var(--theme-c); margin-left: 4px; }
.maths-link p, .maths-link li { font-size: 0.95rem; }

/* ===== Joke of the day (home page) ===== */
.joke { background: var(--surface); border: 1px solid var(--border); border-top: 5px solid var(--theme-e); border-radius: var(--radius); padding: 4px 18px 16px; margin: 20px 0; }
.joke[hidden] { display: none; }
.joke h2 { margin: 12px 0 6px; font-size: 1.15rem; color: var(--theme-e); }
.joke-q { font-size: 1.1rem; font-weight: 600; margin: 6px 0 10px; }
.joke-a { font-size: 1.05rem; background: var(--good-soft); border-radius: 8px; padding: 8px 12px; margin: 0 0 12px; outline: none; }
.joke-buttons { display: flex; flex-wrap: wrap; gap: 10px; }
.joke-buttons button { padding: 10px 16px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; }
.joke-buttons button[hidden] { display: none; }

/* ===== About page ===== */
.about-dogs { margin: 12px 0 0; max-width: 320px; }
.about-dogs img { width: 100%; height: auto; border-radius: var(--radius); border: 1px solid var(--border); display: block; }
.about-dogs figcaption { font-size: 0.9rem; color: var(--muted); margin-top: 6px; }

/* ===== Knowledge and science (NoS + ToK) box at the start of topic pages ===== */
.tok { background: var(--surface); border: 1px solid var(--border); border-top: 5px solid var(--theme-d); border-radius: var(--radius); padding: 6px 18px 12px; margin: 20px 0; }
.tok > h2 { margin: 10px 0 4px; font-size: 1.25rem; }
.tok-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 28px; }
@media (max-width: 760px) { .tok-grid { grid-template-columns: 1fr; } }
.tok h3 { font-size: 1.02rem; margin: 12px 0 6px; color: var(--theme-d); }
.tok-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 8px; }
.tok-tags .tag { background: var(--surface); border: 1px solid var(--theme-d); color: var(--theme-d); }
.tok p, .tok li { font-size: 0.95rem; }
.tok-q { padding-left: 1.1em; margin: 6px 0; }
.tok-q li { margin-bottom: 8px; }
.tok-q strong { display: block; }
.tok-more { margin: 10px 0 0; font-weight: 600; }

/* ===== "Σ Equations" button and panel ===== */
.eq-fab { position: fixed; right: 16px; bottom: 16px; z-index: 20; background: var(--accent); color: var(--surface); border: 0; border-radius: 999px; padding: 10px 18px; font: inherit; font-weight: 700; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25); cursor: pointer; }
.eq-fab span { font-size: 1.15em; margin-right: 2px; }
body.has-eq main { padding-bottom: 96px; }
.eq-panel { position: fixed; z-index: 30; top: 0; right: 0; bottom: 0; width: min(390px, 100%); overflow-y: auto; background: var(--surface); border-left: 1px solid var(--border); box-shadow: -6px 0 24px rgba(0, 0, 0, 0.18); padding: 0 16px 16px; }
.eq-panel[hidden] { display: none; }
@media (max-width: 760px) {
  .eq-panel { top: auto; height: 62vh; width: 100%; border-left: 0; border-top: 1px solid var(--border); border-radius: 14px 14px 0 0; box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.2); }
}
.eq-head { position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; align-items: center; background: var(--surface); padding: 12px 0 8px; border-bottom: 1px solid var(--border); }
.eq-close { background: none; border: 0; color: var(--text); font-size: 1.8rem; line-height: 1; cursor: pointer; padding: 0 4px; }
.eq-pick { display: flex; flex-direction: column; gap: 4px; font-size: 0.82rem; font-weight: 600; color: var(--muted); margin: 10px 0 4px; }
.eq-item { border-bottom: 1px solid var(--border); padding: 4px 0; }
.eq-label { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.eq-item mjx-container[display="true"] { margin: 6px 0 !important; }
.eq-panel h4 { margin: 16px 0 2px; }
.eq-note { font-size: 0.88rem; color: var(--muted); }
.eq-foot { margin: 14px 0 0; font-weight: 600; }
#data-booklet:target .card { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ===== Question bank ===== */
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.filters label { display: flex; flex-direction: column; font-size: 0.82rem; font-weight: 600; color: var(--muted); gap: 4px; }
select, textarea, input { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px; width: 100%; }
.summary { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin: 16px 0; color: var(--muted); }
.question { background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--theme-color, var(--accent)); border-radius: var(--radius); padding: 16px; margin: 16px 0; }
.q-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 10px; }
.q-status { margin-left: auto; font-size: 0.8rem; font-weight: 700; }
.q-status.done { color: var(--good); }
.q-status.review { color: var(--bad); }
.q-status.started { color: var(--muted); }
.question figure { margin: 12px 0; text-align: center; }
.question figure img { background: #fff; border-radius: 8px; padding: 6px; width: 100%; max-width: 420px; }
.question table { border-collapse: collapse; margin: 10px 0; }
.question th, .question td { border: 1px solid var(--border); padding: 4px 10px; text-align: center; }
.options { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 8px; }
.option { width: 100%; display: flex; gap: 12px; align-items: center; text-align: left; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font: inherit; cursor: pointer; }
.option:hover:not(:disabled) { border-color: var(--accent); }
.option:disabled { cursor: default; }
.option .letter { font-weight: 700; min-width: 1.4em; }
.option.is-correct { background: var(--good-soft); border-color: var(--good); }
.option.is-wrong { background: var(--bad-soft); border-color: var(--bad); }
.feedback { border-radius: 8px; padding: 10px 12px; margin: 10px 0; }
.feedback.good { background: var(--good-soft); }
.feedback.bad { background: var(--bad-soft); }
.part { border-top: 1px dashed var(--border); padding-top: 12px; margin-top: 12px; }
.part-label { font-weight: 700; margin-right: 4px; }
.marks { color: var(--muted); font-weight: 600; white-space: nowrap; }
.part textarea { margin: 6px 0 8px; min-height: 70px; resize: vertical; }
.markscheme { background: var(--good-soft); border-radius: 8px; padding: 8px 14px; margin-top: 8px; }
.markscheme ul { margin: 6px 0; padding-left: 1.2em; }
.markscheme label { display: flex; align-items: center; gap: 8px; font-weight: 600; margin: 8px 0 4px; }
.markscheme select { width: auto; }
.num-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 6px 0 4px; }
.num-row input { width: 11em; max-width: 100%; }
.num-row .unit { font-weight: 600; }
.num-hint { font-size: 0.85rem; color: var(--muted); margin: 0 0 6px; }
.auto-mark { font-weight: 600; margin: 8px 0 4px; }
.q-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 16px 0 -4px; }
.q-nav button { padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; }
.q-nav button:disabled { opacity: 0.4; cursor: default; }
.q-count { color: var(--muted); font-weight: 600; text-align: center; }
.next-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 10px; margin: 14px 0 0; }
.next-row span { color: var(--muted); }
@media (max-width: 420px) { .q-nav button { padding: 8px 10px; } .q-count { font-size: 0.9rem; } }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; font: inherit; cursor: pointer; }

/* Embedded Google Slides (16:9, scales to the screen) */
/* Extra 30px leaves room for Google's control bar, so the slide itself fills the full width */
.embed-frame { position: relative; width: 100%; height: 0; padding-bottom: calc(56.25% + 30px); margin: 16px 0 8px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.embed-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.timeline-day { border-left: 5px solid var(--accent); padding: 2px 0 2px 14px; margin: 18px 0; }
.timeline-day h3 { margin: 4px 0; }
.due { display: inline-block; font-size: 0.8rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: var(--theme-b); color: var(--surface); margin-left: 4px; }

/* Stacked tables on narrow screens (class added by site.js when a table is too wide) */
table.notes.stacked, table.notes.stacked tbody, table.notes.stacked tr, table.notes.stacked th, table.notes.stacked td { display: block; width: 100%; }
table.notes.stacked { border: 0; }
table.notes.stacked .stack-head { display: none; }
table.notes.stacked tr { border: 1px solid var(--border); border-radius: var(--radius); margin: 0 0 10px; padding: 6px 12px; background: var(--surface); }
table.notes.stacked th, table.notes.stacked td { border: 0; padding: 3px 0; background: none; }
table.notes.stacked tr > :first-child { font-weight: 700; color: var(--accent); }
table.notes.stacked td[data-label]:not(:first-child)::before, table.notes.stacked th[data-label]:not(:first-child)::before { content: attr(data-label) ": "; font-weight: 600; color: var(--muted); }
