/* Exam practice page. Colours are defined once as tokens; dark mode follows the system setting. */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --text: #16202b;
  --muted: #52606d;
  --border: #d5dde5;
  --accent: #0b5f8a;
  --accent-strong: #084a6c;
  --accent-soft: #e4f0f7;
  --focus: #1d7fc0;
  --hint-bg: #fff8e6;
  --hint-border: #d9a520;
  --mistake-bg: #fdeeee;
  --mistake-border: #c2464a;
  --code-bg: #f6f8fa;
  --code-label: #0b5f8a;
  --tok-c: #6a737d;
  --tok-s: #0a7a3e;
  --tok-n: #9a4c00;
  --tok-k: #7a2fb5;
  --dim-A: #0b5f8a;
  --dim-B: #7a2fb5;
  --dim-C: #9a4c00;
  --radius: 12px;
  --maxw: 920px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f151b;
    --surface: #161f28;
    --surface-2: #1b2631;
    --text: #e6edf3;
    --muted: #9fb0bf;
    --border: #2c3a47;
    --accent: #5cb3e6;
    --accent-strong: #8ccdf2;
    --accent-soft: #19344a;
    --focus: #7cc4f0;
    --hint-bg: #2c2410;
    --hint-border: #c99a2e;
    --mistake-bg: #311719;
    --mistake-border: #d9686c;
    --code-bg: #111a22;
    --code-label: #7cc4f0;
    --tok-c: #8b98a5;
    --tok-s: #7ed3a0;
    --tok-n: #f0b072;
    --tok-k: #c9a4f2;
    --dim-A: #5cb3e6;
    --dim-B: #c9a4f2;
    --dim-C: #f0b072;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
.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;
}

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, "Helvetica Neue", Arial, sans-serif;
}

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }

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

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.skip {
  position: absolute; left: -9999px; top: 0;
  background: var(--surface); color: var(--text); padding: 8px 12px; z-index: 10;
}
.skip:focus { left: 12px; top: 12px; }

/* header */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); padding: 28px 0 22px; }
.eyebrow { margin: 0 0 4px; color: var(--muted); font-size: 14px; letter-spacing: .02em; }
h1 { margin: 0; font-size: clamp(28px, 4.5vw, 38px); line-height: 1.15; letter-spacing: -.01em; }
.subtitle { margin: 6px 0 0; color: var(--muted); font-size: 18px; }

main { padding-top: 20px; padding-bottom: 0; }

/* controls */
.controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  align-items: end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 15px; min-width: 0; }
select {
  width: 100%;
  font: inherit; font-weight: 400; font-size: 16px;
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 10px;
}
.nav-buttons { display: flex; flex-wrap: wrap; gap: 8px; }

button, a.button {
  font: inherit; font-size: 15px; font-weight: 600;
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 14px; cursor: pointer;
}
/* a link that looks like a button (the formula sheet) */
a.button { display: inline-block; text-align: center; text-decoration: none; }
button:hover:not(:disabled) { border-color: var(--accent); }
a.button:hover { border-color: var(--accent); color: var(--text); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-strong); }
@media (prefers-color-scheme: dark) { button.primary { color: #0f151b; } }

.prelim {
  margin: 10px 0 0; font-size: 14px;
  background: var(--hint-bg); border-left: 4px solid var(--hint-border);
  padding: 8px 12px; border-radius: 6px;
}

/* cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin: 16px 0;
}
.question-card:focus { outline: none; }
h2 { margin: 2px 0 10px; font-size: 24px; line-height: 1.25; }
h3 { margin: 0 0 8px; font-size: 20px; }
h4 { margin: 0 0 4px; font-size: 16px; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; }
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 500; line-height: 1.3;
  border: 1px solid var(--border); border-radius: 999px;
  padding: 3px 10px; background: var(--surface-2);
}
.tag.dim b { font-weight: 800; }
.tag.pts-total { background: var(--accent-soft); border-color: var(--accent); font-weight: 600; }
.tag.pts-total b { font-weight: 800; }
.pts {
  display: inline-block; font-size: 13px; font-weight: 700; line-height: 1.3;
  color: var(--accent-strong); background: var(--accent-soft);
  border-radius: 999px; padding: 1px 8px; margin-right: 4px; white-space: nowrap;
}
.dim-A b { color: var(--dim-A); }
.dim-B b { color: var(--dim-B); }
.dim-C b { color: var(--dim-C); }
button.tag.lo { font-weight: 700; padding: 3px 10px; }
button.tag.lo[aria-expanded="true"] { background: var(--accent-soft); border-color: var(--accent); }
.lo-detail {
  font-size: 14px; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; margin: -4px 0 12px;
}

/* rich text */
.prose { overflow-wrap: break-word; }
.prose p { margin: 0 0 12px; }
.prose ul { margin: 0 0 12px; padding-left: 22px; }
.prose li { margin: 0 0 6px; }
.prose code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: .88em; background: var(--code-bg); border: 1px solid var(--border);
  border-radius: 5px; padding: 0 4px;
}
.prose pre code { border: 0; padding: 0; background: none; font-size: 14.5px; }
.part { display: grid; grid-template-columns: 2.1em minmax(0, 1fr); margin: 0 0 6px; }
.part-label { font-weight: 700; color: var(--accent); }
.part-body > :last-child { margin-bottom: 8px; }

mjx-container[display="true"] { overflow-x: auto; overflow-y: hidden; max-width: 100%; padding: 2px 0; }
mjx-container.mjx-wide { display: block; overflow-x: auto; overflow-y: hidden; max-width: 100%; margin: 4px 0; padding: 2px 0; }

/* notebook-style code cells */
.nb {
  display: grid; grid-template-columns: 44px minmax(0, 1fr);
  margin: 4px 0 14px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
  background: var(--code-bg);
}
.nb-label {
  padding: 10px 6px; text-align: right; font: 12px/1.6 ui-monospace, Menlo, Consolas, monospace;
  color: var(--code-label); border-right: 1px solid var(--border);
}
.nb-out .nb-label { color: var(--muted); }
.nb pre { margin: 0; padding: 10px 14px; overflow-x: auto; line-height: 1.5; }
.tok-c { color: var(--tok-c); font-style: italic; }
.tok-s { color: var(--tok-s); }
.tok-n { color: var(--tok-n); }
.tok-k { color: var(--tok-k); font-weight: 600; }

.reading {
  margin: 14px 0 0; padding-top: 12px; border-top: 1px solid var(--border);
  font-size: 14px; color: var(--muted);
}

/* hint and solution buttons, under the question */
.q-actions { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.buttons { display: flex; flex-wrap: wrap; gap: 8px; }

.hint {
  margin-top: 14px; background: var(--hint-bg); border-left: 4px solid var(--hint-border);
  border-radius: 6px; padding: 12px 16px;
}
.box-label { font-weight: 700; margin: 0 0 4px; }

/* Python notes: a box under the question, and a closed section in the practice exam */
.notes-box {
  margin-top: 14px; background: var(--accent-soft); border-left: 4px solid var(--accent);
  border-radius: 6px; padding: 12px 16px;
}
.notes-box .prose > :last-child, .pynotes .prose > :last-child { margin-bottom: 0; }
.notes-lead { margin: 0 0 8px; font-size: 14px; color: var(--muted); }
.pynotes {
  margin-top: 12px; border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; background: var(--surface-2);
}
.pynotes summary { font-weight: 700; cursor: pointer; }
.pynotes[open] summary { margin-bottom: 8px; }
.hint > :last-child, .mistake .prose > :last-child { margin-bottom: 0; }

.solution { border-top: 4px solid var(--accent); }
.mistake { border-radius: 6px; padding: 12px 16px; margin-top: 14px; }
.mistake { background: var(--mistake-bg); border-left: 4px solid var(--mistake-border); }

/* figures: drawn on a light surface, also in dark mode */
.qfig { margin: 6px 0 16px; }
.qfig-scroll { overflow-x: auto; }
.qfig figcaption { font-size: 13px; margin-top: 4px; text-align: right; }
.qfig img {
  display: block; width: auto; max-width: 100%; height: auto; margin: 0 auto;
  background: #fcfcfb; border: 1px solid var(--border); border-radius: 8px; padding: 6px;
}

/* practice exam */
.exam-head h2 { margin-bottom: 4px; }
.exam-head h2:focus { outline: none; }
.exam-info { margin: 0 0 12px; color: var(--muted); }
.exam-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.timer-box {
  display: inline-flex; align-items: baseline; gap: 6px; margin-right: 6px;
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; background: var(--surface-2);
}
.timer-label { font-size: 13px; color: var(--muted); }
.timer { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.timer.over { color: var(--mistake-border); }
.exam-note { margin: 12px 0 0; font-size: 14px; color: var(--muted); }
.exam-q h3 { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-size: 21px; margin-bottom: 12px; }
.exam-q h3 .tag { font-size: 13px; }
.exam-sol { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.exam-sol h4 { margin-bottom: 8px; }

/* legend */
.legend summary { font-weight: 700; cursor: pointer; }
.legend h4 { margin-top: 14px; }
.key { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 6px 0 0; font-size: 15px; }
.key dt { font-weight: 800; }
.key dd { margin: 0; color: var(--muted); }

/* notes at the end of the page (credit, disclaimer, privacy, references) */
.site-notes { padding-bottom: 30px; }
.site-notes .card { margin-top: 0; }
.notes details > :not(summary) { color: var(--muted); font-size: 14px; }
.notes details[open] > summary { margin-bottom: 12px; }
.notes p { margin: 0 0 10px; }
.notes p:last-child { margin-bottom: 0; }
.refs { margin: 0 0 10px; padding-left: 20px; }
.noscript { max-width: var(--maxw); margin: 20px auto; padding: 0 20px; }

/* small screens */
@media (max-width: 640px) {
  body { font-size: 16px; }
  .wrap { padding: 0 16px; }
  .controls { padding: 14px; }
  .part { grid-template-columns: 1.9em minmax(0, 1fr); }
  .card { padding: 18px 16px; }
  .nav-buttons button, .nav-buttons a.button { flex: 1 1 auto; }
  .nb { grid-template-columns: 1fr; }
  .nb-label { text-align: left; border-right: 0; border-bottom: 1px solid var(--border); padding: 4px 10px; }
  h2 { font-size: 21px; }
  .qfig img { max-width: none; width: 640px; }
}

/* printing: question, and the solution if it is open */
@media print {
  body { background: #fff; color: #000; font-size: 12pt; }
  .skip, .controls, .buttons, .legend, .prelim, .exam-bar, .exam-note, .pynotes, .notes-box { display: none !important; }
  .q-actions { border-top: 0; padding-top: 0; }
  .exam-q { break-inside: avoid-page; }
  .qfig figcaption { display: none; }
  .card { border: 0; padding: 0; margin: 0 0 16pt; }
  .site-header { border: 0; padding: 0 0 10pt; }
  .nb { break-inside: avoid; }
}
