/* ------------------------------------------------------------------ tokens */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --text: #16202a;
  --muted: #5b6875;
  --border: #d8dee5;
  --accent: #7a1f2b;
  --accent-strong: #5e1621;
  --on-accent: #ffffff;
  --accent-soft: #f6e4e6;
  --focus: #1d4ed8;
  --e: #15803d;
  --m: #b45309;
  --a: #b91c1c;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 6px 20px rgba(15, 23, 42, 0.06);
  --paper: #ffffff;
  --paper-text: #111111;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1418;
    --surface: #182027;
    --surface-2: #212b34;
    --text: #e6ebf0;
    --muted: #9aa8b5;
    --border: #2d3944;
    --accent: #e0838f;
    --accent-strong: #f0b0b8;
    --on-accent: #2b080d;
    --accent-soft: #3d1a1f;
    --focus: #7aa2ff;
    --e: #4ade80;
    --m: #fbbf24;
    --a: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.35);
    --paper: #1b242c;
    --paper-text: #e9eef2;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1418;
  --surface: #182027;
  --surface-2: #212b34;
  --text: #e6ebf0;
  --muted: #9aa8b5;
  --border: #2d3944;
  --accent: #e0838f;
  --accent-strong: #f0b0b8;
  --on-accent: #2b080d;
  --accent-soft: #3d1a1f;
  --focus: #7aa2ff;
  --e: #4ade80;
  --m: #fbbf24;
  --a: #f87171;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.35);
  --paper: #1b242c;
  --paper-text: #e9eef2;
  color-scheme: dark;
}

/* ------------------------------------------------------------------- base */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: 6px; z-index: 50; }
.skip:focus { left: 8px; }
h1, h2, h3, p { margin: 0; }

/* ----------------------------------------------------------------- header */
.app-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { color: var(--accent); display: grid; }
.brand h1 { font-size: 17px; line-height: 1.2; font-weight: 650; letter-spacing: -0.01em; }
.tag { font-size: 12.5px; color: var(--muted); }
.header-tools { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.icon-btn:hover { border-color: var(--accent); }
.fb-btn { width: auto; display: flex; gap: 6px; padding: 0 12px; font-size: 13px; color: inherit; text-decoration: none; }
.fb-btn[hidden] { display: none; }
.i-sun { display: none; }
:root[data-theme="dark"] .i-sun { display: block; }
:root[data-theme="dark"] .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .i-sun { display: block; }
  :root:not([data-theme="light"]) .i-moon { display: none; }
}

/* segmented control */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 2px; gap: 2px; flex-wrap: wrap; max-width: 100%; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 6px; color: var(--muted); font-weight: 550; min-height: 32px; }
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.seg.wide button { padding: 6px 10px; }
.opt > .seg { justify-self: start; }

/* ----------------------------------------------------------------- layout */
.layout { display: grid; grid-template-columns: minmax(280px, 340px) minmax(0, 1fr); gap: 20px; padding: 20px; max-width: 1500px; margin: 0 auto; align-items: start; }
.sidebar {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; position: sticky; top: 68px; max-height: calc(100vh - 88px); display: flex; flex-direction: column; min-height: 0;
}
.side-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.side-head h2 { font-size: 15px; font-weight: 650; }
.count { font-size: 12.5px; color: var(--accent-strong); font-weight: 600; }
.search { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.side-actions { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 8px 0 6px; }
.link-btn { background: none; border: 0; padding: 2px 0; color: var(--accent-strong); font-size: 12.5px; text-decoration: underline; text-underline-offset: 2px; }
.tree { overflow: auto; margin: 0 -6px; padding: 0 6px; flex: 1; min-height: 0; }

/* tree */
.tree details { margin: 0; }
.tree summary { list-style: none; display: flex; align-items: center; gap: 6px; padding: 5px 4px; border-radius: 6px; cursor: pointer; user-select: none; }
.tree summary::-webkit-details-marker { display: none; }
.tree summary:hover { background: var(--surface-2); }
.tree summary::before {
  content: ""; width: 7px; height: 7px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg); transition: transform 0.12s; margin: 0 4px 0 2px; flex-shrink: 0;
}
.tree details[open] > summary::before { transform: rotate(45deg); }
.tree .form-sum { font-weight: 650; font-size: 14px; }
.tree .form-body { margin-left: 8px; border-left: 1px solid var(--border); padding-left: 6px; }
.tree .ch-sum { font-size: 13.5px; }
.tree .ch-sum .no { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 1.6em; }
.tree .topics { margin: 0 0 4px 22px; display: grid; gap: 1px; }
.tree label.row { display: flex; align-items: flex-start; gap: 7px; padding: 3px 4px; border-radius: 6px; font-size: 13px; cursor: pointer; line-height: 1.35; }
.tree label.row:hover { background: var(--surface-2); }
.tree input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; margin: 2px 0 0; flex-shrink: 0; }
.tree .tid { color: var(--muted); font-variant-numeric: tabular-nums; flex-shrink: 0; }
.badge { font-size: 10.5px; padding: 0 6px; border-radius: 99px; border: 1px solid var(--border); color: var(--muted); white-space: nowrap; margin-left: 4px; }
.tree .empty { color: var(--muted); font-size: 13px; padding: 8px 4px; }
.tree .hide { display: none; }
.sum-label { display: flex; align-items: center; gap: 7px; flex: 1; min-width: 0; }

/* ---------------------------------------------------------------- options */
.main { min-width: 0; display: grid; gap: 16px; }
.options { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 14px 24px; align-items: start; }
.opt { display: grid; gap: 6px; align-content: start; min-width: 0; }
.options { container-type: inline-size; }
@container (min-width: 1000px) { .opt.qlang { padding-left: 24px; } } /* only when it shares a row with Difficulty */
/* wide screens: narrower first column moves Difficulty left; Difficulty (400px) fits BM labels on one row, Question language stays put */
@media (min-width: 1460px) {
  .options { grid-template-columns: 300px 400px minmax(270px, 1fr); }
  .opt.qlang { padding-left: 0; }
}
.opt label, .lbl { font-size: 12.5px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.count-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#count { width: 74px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chips button { padding: 4px 9px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface-2); font-size: 13px; min-height: 30px; }
.chips button:hover, .chips button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent-strong); }
.chips button[aria-pressed="true"] { background: var(--accent-soft); }
.hint { font-size: 12.5px; color: var(--muted); }
.more { grid-column: 1 / -1; }
.more-grid { display: flex; flex-wrap: wrap; gap: 10px 24px; align-items: center; }
.check { display: inline-flex; gap: 9px; align-items: center; font-size: 14px; cursor: pointer; }
/* switch-style toggles: the native checkbox restyled, so app.js still reads/writes .checked */
.check input[role="switch"] { appearance: none; -webkit-appearance: none; position: relative; flex-shrink: 0; width: 38px; height: 22px; margin: 0; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--muted); cursor: pointer; transition: background-color 0.15s, border-color 0.15s; }
.check input[role="switch"]::before { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--muted); transition: transform 0.15s; }
.check input[role="switch"]:checked { background: var(--accent); border-color: var(--accent); }
.check input[role="switch"]:checked::before { transform: translateX(16px); background: var(--on-accent); }
.check:hover input[role="switch"]:not(:checked) { border-color: var(--accent); }
.check input[role="switch"]:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .check input[role="switch"], .check input[role="switch"]::before { transition: none; } }
.check.off { opacity: 0.45; pointer-events: none; }
.more .check, .more .seed { font-size: 14px; font-weight: 550; color: var(--text); text-transform: none; letter-spacing: normal; }
.seed { display: inline-flex; gap: 8px; align-items: center; font-size: 14px; flex: 1 1 260px; min-width: 0; }
.seed input { flex: 1; min-width: 0; padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.seed input[aria-invalid="true"] { border-color: var(--a); outline: 1px solid var(--a); }
.seed-wrap { position: relative; display: flex; flex: 1 1 260px; min-width: 0; }
.seed-wrap .seed { flex: 1; }
.seed-pop { position: absolute; z-index: 20; top: calc(100% + 8px); right: 0; width: min(420px, 100%); padding: 12px 36px 12px 14px; border: 1px solid var(--a); border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-size: 13px; font-weight: 400; line-height: 1.45; }
.seed-pop[hidden] { display: none; }
.seed-pop::before { content: ""; position: absolute; top: -6px; right: 40px; width: 10px; height: 10px; background: var(--surface); border-left: 1px solid var(--a); border-top: 1px solid var(--a); transform: rotate(45deg); }
.seed-pop strong { display: block; color: var(--a); font-size: 14px; margin-bottom: 4px; }
.seed-pop p { margin: 0 0 6px; }
.seed-pop ul { margin: 0; padding-left: 18px; }
.seed-pop li { margin: 2px 0; }
.seed-pop code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
.seed-pop-x { position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; border: 0; border-radius: 6px; background: none; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; }
.seed-pop-x:hover { background: var(--surface-2); color: var(--text); }
@media print { .seed-pop { display: none !important; } }
/* "what's new" notice for returning visitors (see NEWS in app.js) */
.news { position: fixed; z-index: 50; right: 16px; bottom: 16px; width: min(420px, calc(100vw - 32px)); background: var(--surface); color: var(--text); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: var(--radius); box-shadow: var(--shadow), 0 12px 32px rgba(15, 23, 42, 0.18); padding: 14px 40px 14px 16px; font-size: 14px; line-height: 1.45; animation: news-in 0.25s ease-out; }
.news.out { opacity: 0; transform: translateY(8px); transition: opacity 0.3s, transform 0.3s; }
.news h2 { margin: 0 0 6px; font-size: 15px; color: var(--accent-strong); }
.news ul { margin: 0; padding-left: 18px; }
.news li { margin: 3px 0; }
.news a { color: var(--accent-strong); font-weight: 600; }
.news-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--accent); opacity: 0.5; transform-origin: left; border-radius: 0 0 0 var(--radius); }
@keyframes news-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes news-time { to { transform: scaleX(0); } }
@media (max-width: 600px) { .news { left: 16px; right: 16px; width: auto; } }
@media (prefers-reduced-motion: reduce) { .news, .news.out { animation: none; transition: none; } }
@media print { .news { display: none !important; } }
.actions { grid-column: 1 / -1; display: flex; gap: 10px; flex-wrap: wrap; }
.options > .hint { grid-column: 1 / -1; margin-top: -6px; }
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); font-weight: 600; min-height: 40px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
:root[data-theme="dark"] .btn.primary:hover { color: var(--on-accent); }

/* ------------------------------------------------------------------ sheet */
/* the worksheet's serif is bundled, not left to the system: Android has no Times New Roman and set the sheet in its
   much wider Noto Serif, so a paper printed from a phone broke its lines and pages differently from the same paper
   printed from a computer. Tinos has Times New Roman's metrics, so the sheet keeps its look and length everywhere. */
@font-face { font-family: "Tinos"; font-style: normal; font-weight: 400; font-display: swap; src: url(../vendor/fonts/tinos-400-latin.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Tinos"; font-style: normal; font-weight: 400; font-display: swap; src: url(../vendor/fonts/tinos-400-greek.woff2) format("woff2"); unicode-range: U+0370-0377, U+037A-037F, U+0384-038A, U+038C, U+038E-03A1, U+03A3-03FF; }
@font-face { font-family: "Tinos"; font-style: normal; font-weight: 700; font-display: swap; src: url(../vendor/fonts/tinos-700-latin.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Tinos"; font-style: normal; font-weight: 700; font-display: swap; src: url(../vendor/fonts/tinos-700-greek.woff2) format("woff2"); unicode-range: U+0370-0377, U+037A-037F, U+0384-038A, U+038C, U+038E-03A1, U+03A3-03FF; }
@font-face { font-family: "Tinos"; font-style: italic; font-weight: 400; font-display: swap; src: url(../vendor/fonts/tinos-400-italic-latin.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Tinos"; font-style: italic; font-weight: 400; font-display: swap; src: url(../vendor/fonts/tinos-400-italic-greek.woff2) format("woff2"); unicode-range: U+0370-0377, U+037A-037F, U+0384-038A, U+038C, U+038E-03A1, U+03A3-03FF; }
@font-face { font-family: "Tinos"; font-style: italic; font-weight: 700; font-display: swap; src: url(../vendor/fonts/tinos-700-italic-latin.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Tinos"; font-style: italic; font-weight: 700; font-display: swap; src: url(../vendor/fonts/tinos-700-italic-greek.woff2) format("woff2"); unicode-range: U+0370-0377, U+037A-037F, U+0384-038A, U+038C, U+038E-03A1, U+03A3-03FF; }
.sheet { background: var(--paper); color: var(--paper-text); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px 34px 34px; font-family: "Tinos", "Times New Roman", Georgia, serif; font-size: 16px; line-height: 1.45; min-height: 240px; overflow-wrap: anywhere; }
.sheet .empty { text-align: center; padding: 48px 12px; color: var(--muted); font-family: system-ui, sans-serif; }
.sheet .empty h3 { font-size: 18px; color: var(--text); margin-bottom: 4px; }
.sheet-head { border-bottom: 2px solid currentColor; padding-bottom: 8px; margin-bottom: 14px; }
.sheet-head h2 { font-size: 1.3em; line-height: 1.25; }
.sheet-head .sub { font-size: 0.92em; opacity: 0.75; margin-top: 2px; }
.sheet .code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.72em; opacity: 0.7; }
.sheet-head .code { margin-top: 2px; }
.idline { display: flex; gap: 22px; margin-top: 12px; font-size: 0.95em; }
.idline span { display: flex; gap: 6px; align-items: flex-end; }
.idline span::after { content: ""; flex: 1; border-bottom: 1px solid currentColor; height: 1em; }
.idline .nm { flex: 3; } .idline .cl { flex: 1.3; } .idline .dt { flex: 1.3; }

ol.questions { list-style: none; margin: 0; padding: 0; }
.q { display: grid; grid-template-columns: 2.1em minmax(0, 1fr) auto; }
/* the faint "Answer" pill at the right of each question (screen only): hover shows the answer, a click / tap pins it */
.peek { position: relative; align-self: start; margin-left: 8px; }
/* normal format: the pill sits in the question's top-right corner, so the working space below runs the full width */
.fmt-normal .q { grid-template-columns: 2.1em minmax(0, 1fr); position: relative; }
.fmt-normal .peek { position: absolute; top: 0; right: 0; }
.fmt-normal .q .qt-text { padding-right: 76px; }
.peek-btn { font: 600 11px/1.6 system-ui, sans-serif; letter-spacing: 0.02em; color: inherit; background: none; border: 1px solid currentColor; border-radius: 99px; padding: 0 8px; opacity: 0.22; cursor: pointer; transition: opacity 0.12s; -webkit-tap-highlight-color: transparent; }
.peek-btn:focus-visible { opacity: 1; outline: 2px solid var(--focus); outline-offset: 2px; }
.peek.open .peek-btn { opacity: 0.85; }
.peek-pop { display: none; position: absolute; z-index: 30; top: 100%; right: 0; width: max-content; max-width: min(380px, 78vw); margin-top: 6px; padding: 8px 12px; background: var(--paper); color: var(--paper-text); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow), 0 10px 28px rgba(15, 23, 42, 0.16); font-size: 0.95em; line-height: 1.45; text-align: left; }
/* an invisible bridge over the gap, so the pointer can travel from the pill into the popover */
.peek-pop::before { content: ""; position: absolute; left: 0; right: 0; top: -8px; height: 8px; }
.peek.open .peek-pop { display: block; }
@media (hover: hover) {
  .peek:hover .peek-btn { opacity: 0.85; }
  .peek:hover .peek-pop { display: block; }
}
.peek-pop .fig-wrap { text-align: left; }
.peek-pop .fig { max-width: 100%; height: auto; }
@media (prefers-reduced-motion: reduce) { .peek-btn { transition: none; } }
/* printing: keep a question's text and figure together, but let its working space run on to the next page rather
   than push the whole question over and leave half a page empty; the space never starts a page on its own */
.q .qt-text, .q .fig-wrap { break-inside: avoid; page-break-inside: avoid; }
/* (only when a figure or working space follows: on a question's last child, break-after: avoid also forbids the
   break after the whole question, which leaves no place to start the second column in the two-column format) */
.q .qt-text:has(+ .fig-wrap, + .space) { break-after: avoid; }
.q .space { break-before: avoid; page-break-before: avoid; }
.q:last-child .space { break-inside: avoid; page-break-inside: avoid; } /* else its tail can fill a page of its own before the answers */
.fmt-compact .q { break-inside: avoid; page-break-inside: avoid; }
.q .qn { font-weight: 700; padding-top: 0; }
.q .qb { min-width: 0; }
.q .qt-text { display: block; }
.dtag { display: inline-block; font: 600 0.62em/1.5 system-ui, sans-serif; letter-spacing: 0.03em; padding: 0 6px; border-radius: 99px; border: 1px solid currentColor; vertical-align: 0.15em; margin-right: 6px; text-transform: uppercase; }
.dtag.e { color: var(--e); } .dtag.m { color: var(--m); } .dtag.a { color: var(--a); }
.hide-labels .dtag { display: none; }
.q .space { border-radius: 6px; }
.fmt-normal .q { margin-bottom: 10px; }
.fmt-normal .q .space { border: 1px dashed color-mix(in srgb, currentColor 22%, transparent); margin-top: 6px; }
.fmt-compact .q { margin-bottom: 0; padding: 3px 0 4px; }
.fmt-compact .q + .q { border-top: 1px solid color-mix(in srgb, currentColor 10%, transparent); }
.fmt-compact.cols-2 ol.questions { column-count: 2; column-gap: 9mm; column-rule: 1px solid color-mix(in srgb, currentColor 15%, transparent); }
/* in the columns a table too wide for its column is zoomed down to fit (app.js measures it); diagrams shrink by
   themselves */
.fmt-compact.cols-2 table.qt, ol.ans-list table.qt { zoom: var(--fit-screen, 1); }
.fig-wrap { margin: 6px 0 2px; text-align: center; }
.fig-wrap .fig { max-width: 100%; height: auto; color: var(--paper-text); --bg: var(--paper); }
/* a block, not an inline image: an inline SVG leaves a line's descender gap under itself, and at the foot of a
   printed page those few pixels can push an empty page into the PDF */
.fig-wrap .fig { display: block; margin: 0 auto; }
.fig-wrap.left .fig, ol.ans-list .fig-wrap .fig { margin-left: 0; }
.fig-wrap.inline-2 .fig { margin: 0; }
.sheet svg.fig { color: var(--paper-text); --bg: var(--paper); } /* also figures inside answer text: label halos in the paper colour */
.fig-wrap.left { text-align: left; }
.fig-wrap.inline-2 { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }

ol.parts { list-style: none; margin: 4px 0 0; padding: 0; counter-reset: p; }
ol.parts > li { counter-increment: p; position: relative; padding-left: 2em; margin: 2px 0; }
ol.parts > li::before { content: "(" counter(p, lower-alpha) ")"; position: absolute; left: 0; }
ol.aparts { list-style: none; margin: 0; padding: 0; counter-reset: p; }
ol.aparts > li { counter-increment: p; position: relative; padding-left: 1.8em; }
ol.aparts > li::before { content: "(" counter(p, lower-alpha) ")"; position: absolute; left: 0; }

table.qt { border-collapse: collapse; margin: 6px auto; font-size: 0.95em; }
/* words in a table cell wrap between words, never inside one ("Intege|r" in a narrow column) */
table.qt { overflow-wrap: normal; }
/* the narrow two-column format: tighter cells, so more tables fit a column (wider ones span both, see app.js) */
.fmt-compact.cols-2 table.qt th, .fmt-compact.cols-2 table.qt td { padding: 2px 5px; }
table.qt th, table.qt td { border: 1px solid currentColor; padding: 2px 9px; text-align: center; min-width: 2em; }
table.qt.plain th, table.qt.plain td { border: 0; }
table.qt.left td, table.qt.left th { text-align: left; }
/* one maths size for questions, answers and working (KaTeX's own 1.21em is tuned for sans-serif body text) */
.sheet .katex { font-size: 1.05em; }
/* a matrix in running text: keep clear of the lines above and below */
.sheet .katex-base:has(.mtable) { margin: 0.25em 0; }
.blank { display: inline-block; min-width: 3em; border-bottom: 1px solid currentColor; height: 1em; vertical-align: baseline; }
.box { display: inline-block; min-width: 1.6em; height: 1.4em; border: 1px solid currentColor; vertical-align: middle; }

/* answers */
.answers { margin-top: 26px; border-top: 2px solid currentColor; padding-top: 12px; }
.ans-toggle { display: inline-flex; align-items: center; gap: 8px; background: var(--accent-soft); color: var(--accent-strong); border: 1px solid var(--accent); border-radius: 8px; padding: 8px 14px; font: 650 14px system-ui, sans-serif; min-height: 38px; }
.ans-toggle .chev { width: 8px; height: 8px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform 0.12s; }
.ans-toggle[aria-expanded="true"] .chev { transform: rotate(45deg); }
.ans-print-title { display: none; }
.brand-pill { display: none; }
.ans-body { margin-top: 14px; }
.answers.is-collapsed .ans-body { display: none; }
.answers.is-collapsed { border-top-style: dashed; }
ol.ans-list { list-style: none; margin: 0; padding: 0; column-width: 300px; column-gap: 9mm; }
ol.ans-list > li { display: grid; grid-template-columns: 2.1em minmax(0, 1fr); break-inside: avoid; padding: 3px 0; border-bottom: 1px dotted color-mix(in srgb, currentColor 22%, transparent); }
ol.ans-list .an { font-weight: 700; }
ol.ans-list .fig-wrap { text-align: left; }
.ans-final { font-weight: 400; }
.ans-work { font-size: 0.88em; opacity: 0.8; margin-top: 1px; }
/* one block per working step, with a hanging indent so a long formula wraps under itself */
.ans-work .step { padding-left: 1.2em; text-indent: -1.2em; line-height: 1.55; }
.ans-work .step + .step { margin-top: 2px; }
.ans-work li { line-height: 1.55; }

/* ------------------------------------------------------------- site guide */
/* js/tour.js: a full-screen dialog; .tour-hole is a window onto the control a step is about (its huge shadow dims the
   rest of the page) and .tour-card is placed beside it. The first and last steps have no control: the card is
   centred and the whole page dimmed. */
.tour { position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: transparent; color: var(--text); overflow: hidden; }
.tour::backdrop { background: transparent; }
.tour-hole { position: fixed; border-radius: 10px; box-shadow: 0 0 0 3px var(--accent), 0 0 0 200vmax rgba(8, 18, 24, 0.62); transition: top 0.25s, left 0.25s, width 0.25s, height 0.25s; pointer-events: none; }
.tour.is-centred { background: rgba(8, 18, 24, 0.62); }
.tour.is-centred .tour-hole { display: none; }
.tour-card { position: fixed; width: min(380px, calc(100vw - 24px)); max-height: calc(100% - 24px); overflow: auto; overscroll-behavior: contain; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 24px 64px rgba(0, 0, 0, 0.4); transition: top 0.25s, left 0.25s; }
.tour.is-centred .tour-card { top: 50% !important; left: 50% !important; transform: translate(-50%, -50%); width: min(460px, calc(100vw - 24px)); }
/* the band: squared paper on the accent colour */
.tour-band { position: relative; padding: 18px 56px 16px 20px; color: #fff; background-color: #7a1f2b; background-image: linear-gradient(rgba(255, 255, 255, 0.09) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, 0.09) 1px, transparent 1px); background-size: 16px 16px; border-radius: calc(var(--radius) - 1px) calc(var(--radius) - 1px) 0 0; }
.tour-step { margin: 0 0 4px; font-size: 12px; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; color: rgba(255, 255, 255, 0.82); }
.tour-band h2 { font-size: 22px; line-height: 1.2; font-weight: 700; letter-spacing: -0.01em; }
.tour-band h2:focus { outline: none; }
.tour-x { position: absolute; top: 10px; right: 10px; width: 36px; height: 36px; display: grid; place-items: center; padding: 0; border: 1.5px solid rgba(255, 255, 255, 0.55); border-radius: 50%; background: rgba(0, 0, 0, 0.18); color: #fff; font-size: 20px; line-height: 1; }
.tour-x:hover { border-color: #fff; }
.tour-x:focus-visible { outline-color: #fff; }
.tour-x.is-hint { animation: tour-x-hint 0.6s ease-in-out 3; }
@keyframes tour-x-hint { 50% { background: #fff; color: #7a1f2b; border-color: #fff; box-shadow: 0 0 0 5px rgba(255, 255, 255, 0.45); } }
.tour-body { display: grid; gap: 14px; padding: 16px 20px 4px; }
.tour-body p { font-size: 15px; line-height: 1.55; }
.tour-body .tour-hl { display: block; margin-top: 8px; padding: 6px 10px; border-radius: 6px; color: inherit; }
/* the sister sites, in their logos' colours (the header's Drills and Visual buttons) */
.tour-hl-drills { background: #e3e7fb; box-shadow: inset 3px 0 0 #3848a8; }
.tour-hl-visual { background: #dcf1f6; box-shadow: inset 3px 0 0 #0e7490; }
:root[data-theme="dark"] .tour-hl-drills { background: #262f63; box-shadow: inset 3px 0 0 #8c9bf0; }
:root[data-theme="dark"] .tour-hl-visual { background: #12424f; box-shadow: inset 3px 0 0 #4cc3dd; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tour-hl-drills { background: #262f63; box-shadow: inset 3px 0 0 #8c9bf0; }
  :root:not([data-theme="light"]) .tour-hl-visual { background: #12424f; box-shadow: inset 3px 0 0 #4cc3dd; }
}
@media (forced-colors: active) { .tour-body .tour-hl { color: MarkText; background: Mark; } }
.tour-lang { justify-self: start; }
.tour-lang[hidden], .tour-end[hidden] { display: none; }
.tour-end { justify-self: center; display: grid; place-items: center; width: 56px; height: 56px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-strong); font-size: 28px; font-weight: 700; }
.tour-dots { display: flex; flex-wrap: wrap; gap: 2px; margin: 0; padding: 0; list-style: none; }
.tour-dot { display: grid; place-items: center; width: 22px; height: 22px; padding: 0; border: 0; background: none; }
.tour-dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--border); transition: width 0.2s, background-color 0.2s; }
.tour-dot:hover::before { background: var(--muted); }
.tour-dot[aria-current="step"]::before { width: 18px; border-radius: 4px; background: var(--accent); }
.tour-actions { display: grid; gap: 6px; padding: 14px 20px 16px; }
.tour-main { display: flex; gap: 8px; }
.tour-main .btn { justify-content: center; }
.tour-main .primary { flex: 1; }
.tour-prev:disabled { opacity: 0.45; cursor: default; }
.tour-skip { justify-self: center; font-size: 13.5px; font-weight: 600; }
@media (prefers-reduced-motion: reduce) { .tour-hole, .tour-card, .tour-dot::before { transition: none; } .tour-x.is-hint { animation-timing-function: steps(1, end); } }
@media (forced-colors: active) { .tour-x.is-hint { animation: none; outline: 4px solid Highlight; outline-offset: 2px; } }
@media print { .tour { display: none !important; } }

/* ------------------------------------------------------------- responsive */
/* screen only: a printed page is narrower than 900px, and a phone may report its own width when printing, so these
   would otherwise reach the printout (on a phone, the Name / Class / Date line stacked into three) */
@media screen and (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 12px 16px; }
  .sidebar { position: static; max-height: 460px; }
  .app-header { padding: 8px 16px; position: static; }
  .tag { display: none; }
  .sheet { padding: 18px 16px 22px; }
}
@media screen and (max-width: 760px) {
  /* three header links: icons only, so the title keeps its room */
  .fb-btn span { display: none; }
  .fb-btn { padding: 0; width: 36px; justify-content: center; }
  /* the buttons move under the title when both don't fit on one row (on a phone they used to squeeze the title) */
  .app-header { flex-wrap: wrap; row-gap: 8px; }
  .brand { flex: 1 1 240px; }
}
@media screen and (max-width: 520px) {
  .options { grid-template-columns: 1fr; }
  .seg button { padding: 6px 10px; }
  .brand h1 { font-size: 15px; }
  .idline { flex-direction: column; gap: 8px; }
}
@media screen and (max-width: 420px) {
  .brand { gap: 8px; }
  .header-tools { gap: 5px; }
  .header-tools .seg button { padding: 6px 8px; }
}

/* ------------------------------------------------------------------ print */
@page { size: A4; margin: 13mm 14mm 15mm; @bottom-center { content: counter(page); font: 9pt "Tinos", "Times New Roman", serif; color: #444; } }
@media print {
  :root, :root[data-theme="dark"] {
    --bg: #fff; --surface: #fff; --text: #000; --paper: #fff; --paper-text: #000; --border: #999; --e: #000; --m: #000; --a: #000; --accent-soft: #fff; --accent-strong: #000; --muted: #444;
    color-scheme: light;
  }
  html, body { background: #fff !important; color: #000 !important; font-size: 11.5pt; }
  .skip, .app-header, .sidebar, .options, .ans-toggle, .peek { display: none !important; }
  .layout { display: block; padding: 0; max-width: none; }
  .main { display: block; }
  .sheet { border: 0; box-shadow: none; border-radius: 0; padding: 0; font-size: 11.5pt; line-height: 1.4; min-height: 0; overflow: visible; }
  .sheet-head { padding-bottom: 5px; margin-bottom: 9px; }
  .fmt-normal .q .space { border: 0; }
  .fmt-normal .q .qt-text { padding-right: 0; }
  .fmt-compact { font-size: 11pt; }
  .answers { break-before: page; page-break-before: always; margin-top: 0; border-top: 0; padding-top: 0; }
  .answers.is-collapsed .ans-body, .ans-body { display: block !important; }
  /* nothing may hang below the last question or answer: invisible overhang (a padding, KaTeX's line struts) at the
     foot of the last page otherwise adds an empty page to the PDF */
  ol.questions > .q:last-child { padding-bottom: 0; margin-bottom: 0; }
  .answers { overflow: clip; }
  .ans-print-title { display: block; font-size: 1.3em; font-weight: 700; border-bottom: 2px solid #000; padding-bottom: 5px; margin-bottom: 8px; }
  .ans-print-title small { font-weight: 400; font-size: 0.65em; margin-left: 8px; opacity: 0.8; }
  .ans-print-title small.code { display: block; margin-left: 0; font-size: 0.5em; }
  /* the site's name in a small pill under the paper code, in both headers */
  .code-row { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; margin-top: 2px; }
  .code-row .code { margin-top: 0; }
  .brand-pill { display: inline-block; flex: none; font: 600 9pt/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; letter-spacing: 0.02em; color: #fff !important; background: #000; text-decoration: none; border: 0.75pt solid #000; border-radius: 999px; padding: 2.5px 10px; }
  .ans-body { margin-top: 0; }
  ol.ans-list { column-count: 2; column-width: auto; font-size: 10.5pt; }
  .fmt-compact.cols-2 table.qt, ol.ans-list table.qt { zoom: var(--fit-print, 1); }
  .dtag { border-color: #000; }
  .fig-wrap .fig { color: #000; }
  /* no figure taller than about two thirds of the page body (a few graphs are drawn far too tall; see the plan) */
  .fig-wrap .fig { max-height: 175mm; width: auto; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
