/* ---------- design tokens ---------- */
:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #eeeeee;
  --text: #17171c;
  --text-dim: #5d5d6b;
  --line: #dededf;
  --brand: #ffd34d;
  --brand-ink: #2b2000;
  --ok: #1b8b3a;
  --ok-bg: #d4f3dc;
  --bad: #c62828;
  --bad-bg: #fadcdc;
  --pink: #9d174d;
  --pink-bg: #ffe3f3;
  --link: #1a56db;
  --shadow: 0 1px 3px rgba(16, 16, 30, .12), 0 6px 18px rgba(16, 16, 30, .10);
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1e1e24;
    --surface: #27272e;
    --surface-2: #313139;
    --text: #f2f2f5;
    --text-dim: #a2a2b0;
    --line: #3d3d47;
    --brand: #ffd666;
    --brand-ink: #2b2000;
    --ok: #5ed37e;
    --ok-bg: #17351f;
    --bad: #ff8a80;
    --bad-bg: #3a1a1a;
    --pink: #f9a8d4;
    --pink-bg: #4a1942;
    --link: #8ab4f8;
    --shadow: 0 1px 3px rgba(0, 0, 0, .45), 0 6px 18px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

img { max-width: 100%; }

/* Links only ever appear inside hand-written Handbook/Guide prose (auto-linkified
   NSW Gov domains/phone numbers) - a single site-wide style covers all of them. */
a {
  color: var(--link);
  text-decoration-color: currentColor;
  text-underline-offset: 2px;
}
a:hover { text-decoration-thickness: 2px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  will-change: transform;         /* own compositor layer: avoids stale-paint
                                     glitches when several sticky bars stack */
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--brand);
  color: var(--brand-ink);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .12);
}
.topbar__title {
  flex: 1;
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -.01em;
}
.topbar__back,
.topbar__fav {
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 1.35rem;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.topbar__back {
  display: grid;
  place-items: center;
}
.topbar__back:hover,
.topbar__fav:hover { background: rgba(0, 0, 0, .1); }
.topbar__fav[aria-pressed="true"] { color: #b3261e; }

/* Same leftward triangle as .hbpage__tri, scaled down for the topbar. */
.topbar__tri {
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-right: 9px solid var(--brand-ink);
  transform: translateX(-1px);
}

.progressbar {
  position: sticky;
  top: 48px;
  z-index: 9;
  will-change: transform;
  height: 4px;
  background: var(--surface-2);
}
.progressbar__fill {
  height: 100%;
  width: 0;
  background: var(--ok);
  transition: width .25s ease;
}

/* ---------- layout ---------- */
main {
  max-width: 720px;
  margin: 0 auto;
  padding: 18px 14px 40px;
  --content-max: 720px;
}
/* The handbook's sidebar + content layout needs more room than the quiz's single column. */
main.app--wide { max-width: 1100px; --content-max: 1100px; }
.section-title {
  margin: 28px 0 10px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

/* ---------- home ---------- */
.hero { margin-bottom: 20px; }
.hero__eyebrow {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}
.hero__title {
  margin: 6px 0 8px;
  font-size: 1.7rem;
  line-height: 1.2;
  letter-spacing: -.02em;
}
.hero__sub { margin: 0; color: var(--text-dim); }

.stats {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.stat { display: flex; align-items: center; gap: 14px; }
.stat__meta { display: flex; flex-direction: column; }
.stat__meta span { color: var(--text-dim); font-size: .88rem; }
.stat__nums {
  display: flex;
  gap: 18px;
  margin-left: auto;
}
.stat__nums div { display: flex; flex-direction: column; align-items: center; }
.stat__nums strong { font-size: 1.2rem; }
.stat__nums span { font-size: .75rem; color: var(--text-dim); }

.ring {
  --pct: 0;
  position: relative;
  width: 62px;
  height: 62px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: .85rem;
  font-weight: 700;
  background:
    conic-gradient(var(--ok) calc(var(--pct) * 1%), var(--surface-2) 0);
}
.ring::before {
  content: "";
  position: absolute;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--surface);
}
.ring span { position: relative; }
.ring--big { width: 108px; height: 108px; font-size: 1.4rem; }
.ring--big::before { width: 84px; height: 84px; }

/* Section/topic rings show completion, not accuracy: how much of the whole section
   has been attempted, split into how much was right vs. wrong — not just accuracy
   among what's been attempted. Two conic-gradient stops instead of one. */
.ring--split {
  --pct-right: 0;
  --pct-wrong: 0;
  background:
    conic-gradient(
      var(--ok) 0 calc(var(--pct-right) * 1%),
      var(--bad) calc(var(--pct-right) * 1%) calc((var(--pct-right) + var(--pct-wrong)) * 1%),
      var(--surface-2) calc((var(--pct-right) + var(--pct-wrong)) * 1%) 0
    );
}

/* ---------- cards ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  padding: 14px;
  text-align: left;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .12s ease, border-color .12s ease;
}
.card:hover { background: var(--surface-2); }
.card:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.card--primary {
  background: var(--brand);
  color: var(--brand-ink);
}
.card--primary:hover { background: var(--brand); }
/* The topic page's lone "practice all" button isn't part of a multi-item
   grid like the home screen's cards — it should still read as a full-width
   banner CTA rather than shrink to a single grid-cell's width. */
#section-practice-all {
  grid-column: 1 / -1;
  flex-direction: row;
  align-items: center;
  gap: 14px;
}
.card__icon { font-size: 1.5rem; line-height: 1; }
.card__body { display: flex; flex-direction: column; gap: 2px; }
.card__body small { opacity: .75; font-size: .84rem; }
.card__body small.card__stats { display: inline-flex; gap: 6px; opacity: 1; }
.card__stat {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  font-weight: 700;
  font-size: .74rem;
}
.card__stat--q { background: var(--surface-2); color: var(--text-dim); }
.card__stat--right { background: var(--ok-bg); color: var(--ok); }
.card__stat--wrong { background: var(--bad-bg); color: var(--bad); }
.card__ring {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 40px;
  height: 40px;
  font-size: .62rem;
}
.card__ring::before { width: 28px; height: 28px; }

@media (max-width: 480px) {
  .cards { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
}

.home-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 28px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.switch { display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--text-dim); cursor: pointer; }
.linkbtn {
  border: 0;
  background: none;
  color: var(--bad);
  font: inherit;
  font-size: .9rem;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
}

/* ---------- home tabs ---------- */
/* A sibling of <main> (like .topbar), not a child of it, so its background
   spans the full viewport width. .hometabs__inner has the same max-width +
   margin:auto centering as main, so the tab row/description align with
   main's column; .app--wide switches it the same way main's own class does
   for the handbook tab. */
.hometabs {
  position: sticky;
  top: 45px;                     /* below the sticky topbar */
  z-index: 8;
  will-change: transform;
  background: var(--bg);
}
.hometabs__inner {
  display: flex;
  flex-direction: column;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 14px 18px;           /* was margin-bottom: as a margin this sat
                                     outside the sticky box, so it engaged
                                     sticky positioning later than the very
                                     next sticky element (hbnav), producing a
                                     gap that visibly grew/shrank mid-scroll */
}
.hometabs.app--wide .hometabs__inner { max-width: 1100px; }
.hometabs__row {
  display: flex;
  gap: 4px;
}
.hometabs__btn {
  flex: 1;
  padding: 10px 8px 12px;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  font: inherit;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text-dim);
  cursor: pointer;
}
.hometabs__btn:hover { color: var(--text); }
.hometabs__btn.is-active { color: var(--text); border-bottom-color: var(--brand); }

/* ---------- handbook (sidebar + one topic per page) ---------- */
.hbwrap {
  display: flex;
  align-items: flex-start;
  gap: 28px;
}

.hbnav-toggle {
  display: none;                 /* shown only at narrow widths, see media query below */
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 12px;
  background: var(--brand);
  border: 1px solid var(--brand);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font: inherit;
  font-weight: 700;
  color: var(--brand-ink);
  cursor: pointer;
}
.hbnav-toggle__chevron { transition: transform .15s ease; color: var(--brand-ink); }
.hbnav-toggle[aria-expanded="true"] .hbnav-toggle__chevron { transform: rotate(180deg); }

/* Icon-only floating buttons for moving to the previous/next subsection,
   pinned to the bottom corners so they stay reachable regardless of
   how long the current subsection's content is. */
.hbpage {
  position: fixed;
  bottom: 20px;
  z-index: 15;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 1px solid var(--brand);
  border-radius: 50%;
  background: var(--brand);
  color: var(--brand-ink);
  box-shadow: var(--shadow);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}
.hbpage:hover { background: var(--brand); filter: brightness(.95); }
.hbpage--prev { left: 20px; }
.hbpage--next { right: 20px; }
.hbpage__tri {
  width: 0;
  height: 0;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
}
/* A triangle's visual centroid sits 1/3 of its width from the base, not at
   its bounding-box center -- so centering the box (via place-items) still
   looks off-balance. Nudging by border-width/6 pulls the centroid itself
   onto the button's actual center. */
.hbpage--prev .hbpage__tri { border-right: 12px solid var(--brand-ink); transform: translateX(-2px); }
.hbpage--next .hbpage__tri { border-left: 12px solid var(--brand-ink); transform: translateX(2px); }
@media (max-width: 760px) {
  .hbpage { bottom: 14px; width: 44px; height: 44px; }
  .hbpage--prev { left: 14px; }
  .hbpage--next { right: 14px; }
}

.hbnav {
  flex: 0 0 250px;
  min-width: 0;
  background: var(--bg);
  position: sticky;
  top: 139px;                    /* below the sticky topbar + hometabs (incl. the handbook description) */
  z-index: 6;
  will-change: transform;
  max-height: calc(100vh - 157px);
  overflow-y: auto;
  padding-right: 4px;
}
.hbnav__group { margin-bottom: 6px; }
.hbnav__chapter {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: 0 0 4px;
  padding: 6px 4px;
  border: 0;
  border-radius: 8px;
  background: none;
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  text-align: left;
  color: var(--text);
  cursor: pointer;
}
.hbnav__chapter:hover { background: var(--surface-2); }
.hbnav__chapter-icon {
  flex: none;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--surface-2);
  font-size: 1rem; font-weight: 700; line-height: 1;
  color: var(--text-dim);
}
.hbnav__chapter[aria-expanded="true"] .hbnav__chapter-icon { background: var(--brand); color: var(--brand-ink); }
.hbnav__chapter--leaf.is-active { background: var(--brand); color: var(--brand-ink); }
.hbnav__chapter--leaf.is-active .hbnav__chapter-icon { background: var(--brand-ink); color: var(--brand); }
.hbnav__chapter-label { flex: 1; }
.hbnav__chapter-chevron { flex: none; font-size: .7rem; transition: transform .15s ease; }
.hbnav__chapter[aria-expanded="true"] .hbnav__chapter-chevron { transform: rotate(180deg); }
.hbnav__list {
  list-style: none; margin: 2px 0 10px; padding: 0; display: grid; gap: 2px;
  margin-left: 9px; padding-left: 12px; border-left: 2px solid var(--line);
}
.hbnav__link {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  font: inherit;
  font-size: .88rem;
  color: var(--text);
  cursor: pointer;
}
.hbnav__link:hover { background: var(--surface-2); }
.hbnav__link.is-active { background: var(--brand); color: var(--brand-ink); font-weight: 600; }

.hbcontent { flex: 1; min-width: 0; padding-bottom: 76px; }  /* keeps the fixed prev/next buttons from covering the tail of the content */
.hbcontent .hero__title { font-size: 1.3rem; }
.hbcontent__chapter-label {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text-dim);
}
.hbcontent__bullets {
  margin: 18px 0 0;
  padding-left: 22px;
  display: grid;
  gap: 10px;
  font-size: .95rem;
  line-height: 1.5;
}

.hbfigure {
  position: relative;
  margin: 18px 0;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}
.hbfigure img { max-width: 100%; border-radius: 6px; cursor: zoom-in; }
.hbfigure figcaption { margin-top: 8px; font-size: .98rem; color: var(--text-dim); text-align: left; }
.hbfigure__num {
  position: absolute;
  top: 6px;
  left: 6px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: .72rem;
  font-weight: 700;
  color: #fff;
  background: rgba(0, 0, 0, .58);
  z-index: 1;
}

/* ---------- image lightbox (click a figure to enlarge it, with a gallery
   prev/next through every figure on the current page) ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.lightbox__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .7);
}
.lightbox__panel {
  position: relative;
  max-width: min(720px, 92vw);
  max-height: 92vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.lightbox__close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}
.lightbox__img { max-width: 100%; max-height: 70vh; border-radius: 8px; }
.lightbox__caption { margin: 14px 0 0; font-size: 1rem; color: var(--text); text-align: left; }
.lightbox__detail {
  margin: 10px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: .95rem;
  line-height: 1.5;
  color: var(--text-dim);
  text-align: left;
}
.lightbox__detail-item { margin: 0; }
.lightbox__detail-item + .lightbox__detail-item { margin-top: 8px; }
.lightbox__nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.lightbox__nav:hover { border-color: var(--text-dim); }
.lightbox__nav--prev { left: 8px; }
.lightbox__nav--next { right: 8px; }
.lightbox__tri { width: 0; height: 0; border-top: 7px solid transparent; border-bottom: 7px solid transparent; }
.lightbox__nav--prev .lightbox__tri { border-right: 10px solid var(--text); transform: translateX(-1px); }
.lightbox__nav--next .lightbox__tri { border-left: 10px solid var(--text); transform: translateX(1px); }
@media (max-width: 480px) {
  .lightbox__nav { width: 38px; height: 38px; }
}

/* 2+ figures on a page lay out as a responsive grid instead of one long column. */
.hbfigures {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 14px;
  margin: 18px 0;
}
/* An explicit figuresGrid.cols count (data-cols) is a hard column count above
   the mobile breakpoint, so a section's chosen grid shape (e.g. 3x3, 2x1) is
   never silently overshot/undershot by auto-fit at in-between widths; below
   the breakpoint it falls back to a responsive auto-fit so narrow screens
   still reflow instead of overflowing. */
.hbfigures[data-cols="1"] { grid-template-columns: repeat(1, 1fr); }
.hbfigures[data-cols="2"] { grid-template-columns: repeat(2, 1fr); }
.hbfigures[data-cols="3"] { grid-template-columns: repeat(3, 1fr); }
.hbfigures[data-cols="4"] { grid-template-columns: repeat(4, 1fr); }
.hbfigures[data-cols="5"] { grid-template-columns: repeat(5, 1fr); }
@media (max-width: 480px) {
  /* Every figures grid becomes a single column on phone width, regardless of
     its desktop data-cols or a per-section data-mobile-cols override. */
  .hbfigures,
  .hbfigures[data-cols],
  .hbfigures[data-mobile-cols] {
    grid-template-columns: 1fr;
  }
}
.hbfigures .hbfigure { margin: 0; display: flex; flex-direction: column; --hb-fig-scale: 1; }
.hbfigures .hbfigure img { max-height: calc(var(--hb-img-h, 220px) * var(--hb-fig-scale, 1)); width: auto; max-width: 100%; margin: 0 auto; object-fit: contain; }
.hbfigures .hbfigure figcaption { margin-top: auto; padding-top: 8px; }
/* grid-column-end only (not the "grid-column: span 2" shorthand, which sets
   grid-column-START): a newRow figure sets grid-column-start inline, and a
   shorthand here would silently clobber that with its own implicit start. */
.hbfigures .hbfigure--wide { grid-column-end: span 2; }
.hbfigures .hbfigure--wide img { max-width: 100%; width: 100%; }
.hbfigures--square .hbfigure img,
.hbfigures .hbfigure--square img {
  aspect-ratio: 1 / 1; width: 100%; height: auto; max-height: none; object-fit: contain;
}

.hbtable-wrap {
  margin: 18px 0;
  max-width: 100%;           /* without this, the table's auto-layout min-
                                content width can bubble up through this
                                overflow:auto wrapper and inflate .hbcontent
                                itself, overflowing the page horizontally */
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.hbtable { width: 100%; border-collapse: collapse; font-size: .88rem; }
.hbtable th, .hbtable td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  white-space: normal;
}
.hbtable th {
  text-align: left;
  font-size: .98rem;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--text);
  background: var(--surface-2);
}
.hbtable td { text-align: left; }
.hbtable tr:last-child td { border-bottom: 0; }
/* Not scoped to .hbtable - the same highlight pill is also used inside
   figure captions and bullets, not just table cells. */
mark {
  display: inline-block;
  white-space: nowrap;
  background: var(--brand);
  color: var(--brand-ink);
  padding: 1px 6px;
  border-radius: 999px;
  font: inherit;
}
mark.pink { background: var(--pink-bg); color: var(--pink); }

.hbtable-title {
  display: inline-block;
  margin: 22px 0 8px;
  padding: 3px 10px;
  border-radius: 6px;
  background: var(--brand);
  color: var(--brand-ink);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: .01em;
}
/* A subsection under one of a page's few big .hbgroup-title parts - muted
   light-gray instead of brand yellow, so only the main parts read as "highlighted". */
.hbtable-title--sub { background: var(--surface-2); color: var(--text); }

/* Marks one of a page's few main parts, each of which can group several of
   its own smaller-titled tables - a bit bigger than a sub-table's .hbtable-title
   (1.05rem) but not as large as the page's own .hero__title (1.3rem). */
.hbgroup-title {
  display: block;
  margin: 34px 0 14px;
  padding: 8px 16px;
  border-radius: var(--radius);
  background: var(--brand);
  color: var(--brand-ink);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -.02em;
}
.hbgroup-title:first-child { margin-top: 0; }

.hbabbr {
  margin: 26px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: .8rem;
  line-height: 1.6;
  color: var(--text-dim);
}
.hbabbr strong { color: var(--text); }

@media (max-width: 760px) {
  .hbwrap {
    flex-direction: column;
    align-items: stretch;    /* .hbwrap's own align-items:flex-start is for
                                the desktop row layout (hugs sidebar/content
                                to their natural size); in column mode that
                                same flex-start let hbcontent's width hug its
                                widest child (e.g. a table) instead of being
                                capped to the column's width, overflowing
                                the page horizontally */
  }
  .hbnav-toggle {
    display: flex;
    position: fixed;
    top: calc(6px + env(safe-area-inset-top, 0px));  /* sits on the yellow
                                                         topbar itself, not
                                                         the tab row below it */
    right: 12px;
    z-index: 20;
    width: auto;
    gap: 6px;
    margin-bottom: 0;
    padding: 8px 6px;
    background: transparent;
    border-color: transparent;
    box-shadow: none;
    color: var(--brand-ink);
  }
  .hbnav {
    display: none;
    position: fixed;
    top: calc(104px + env(safe-area-inset-top, 0px));
    left: 12px;
    right: 12px;
    flex: none;
    width: auto;
    max-height: 65vh;
    overflow-y: auto;
    z-index: 20;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 12px 14px;
    margin-bottom: 16px;
  }
  .hbnav.is-open { display: block; }
}

@media (max-width: 480px) {
  /* "span"/"rowSpan" set grid-column-end/grid-row-end as inline styles,
     which no external stylesheet rule can override -- so a figure that
     spans e.g. 4 columns on desktop kept forcing that many *implicit*
     tracks under the narrow auto-fit grid below, overflowing the page
     horizontally. !important is required here to win over inline styles. */
  .hbfigures .hbfigure {
    grid-column-end: span 1 !important;
    grid-row-end: span 1 !important;
  }
}

/* ---------- section (per-topic question grid) ---------- */
.qgrid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
}
.qcard {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 8px;
  text-align: left;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.qcard:hover { border-color: var(--brand); }
.qcard__thumb {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  margin-bottom: 8px;
}
.qcard__thumb img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.qcard__num {
  position: absolute;
  top: 6px;
  left: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: .68rem;
  font-weight: 700;
  color: #fff;
  background: rgba(0, 0, 0, .58);
}
.qcard__status {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: .66rem;
  font-weight: 700;
  background: var(--surface);
  color: var(--text-dim);
  box-shadow: var(--shadow);
}
.qcard__status--right { background: var(--ok-bg); color: var(--ok); }
.qcard__status--wrong { background: var(--bad-bg); color: var(--bad); }
.qcard__title {
  font-size: .82rem;
  line-height: 1.28;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

@media (max-width: 480px) {
  .qgrid { grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 10px; }
}

/* ---------- quiz ---------- */
.counter { margin: 0 0 10px; font-size: .85rem; font-weight: 600; color: var(--text-dim); }
.qimage {
  position: relative;
  margin: 0 0 16px;
  padding: 10px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}
.qimage img {
  max-height: 42vh;
  width: auto;
  border-radius: 8px;
  display: inline-block;
}
/* Prev/next controls anchored to the image itself rather than the bottom of
   the page - white circular buttons, not the yellow brand accent. */
.qimgnav {
  position: absolute;
  bottom: 8px;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.qimgnav:hover:not(:disabled) { border-color: var(--text-dim); }
.qimgnav:disabled { opacity: .4; cursor: not-allowed; }
.qimgnav--prev { left: 8px; }
.qimgnav--next { right: 8px; }
.qimgnav__tri { width: 0; height: 0; border-top: 6px solid transparent; border-bottom: 6px solid transparent; }
.qimgnav--prev .qimgnav__tri { border-right: 9px solid var(--text); transform: translateX(-1px); }
.qimgnav--next .qimgnav__tri { border-left: 9px solid var(--text); transform: translateX(1px); }
.qtext {
  margin: 0 0 16px;
  font-size: 1.22rem;
  line-height: 1.35;
  letter-spacing: -.01em;
}

.options { display: grid; gap: 10px; }
.option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  padding: 13px 15px;
  text-align: left;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 2px solid transparent;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.option:hover:not(:disabled) { border-color: var(--brand); }
.option__key {
  flex: none;
  width: 22px;
  font-weight: 700;
  color: var(--text-dim);
}
.option[aria-pressed="true"] { border-color: var(--text-dim); }
.option.is-correct { background: var(--ok-bg); border-color: var(--ok); }
.option.is-wrong { background: var(--bad-bg); border-color: var(--bad); }
.option.is-correct .option__key { color: var(--ok); }
.option.is-wrong .option__key { color: var(--bad); }
.option:disabled { cursor: default; }

.feedback {
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--surface-2);
  border-radius: var(--radius);
}
.feedback.is-ok { background: color-mix(in srgb, var(--ok-bg) 70%, var(--surface)); }
.feedback.is-bad { background: color-mix(in srgb, var(--bad-bg) 70%, var(--surface)); }
.feedback__head { margin: 0 0 6px; font-weight: 700; }
.feedback__head.is-ok { color: var(--ok); }
.feedback__head.is-bad { color: var(--bad); }
.feedback__body { margin: 0; color: var(--text); }

.btn {
  flex: 1;
  padding: 13px 16px;
  font: inherit;
  font-weight: 600;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--text-dim); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn--primary { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.btn--ghost { background: transparent; box-shadow: none; }

.hint { margin: 18px 0 0; font-size: .8rem; color: var(--text-dim); text-align: center; }
kbd {
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface);
  font: inherit;
  font-size: .78rem;
}
@media (hover: none) { .hint { display: none; } }

/* ---------- result ---------- */
.result {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 26px 18px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}
.result h2 { margin: 8px 0 0; font-size: 1.5rem; }
.result p { margin: 0; color: var(--text-dim); }
.result.is-pass h2 { color: var(--ok); }
.result.is-fail h2 { color: var(--bad); }
.result-actions { display: grid; gap: 10px; margin-top: 16px; }

.review { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.review__item {
  padding: 14px 16px;
  background: var(--surface);
  border-left: 4px solid var(--ok);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.review__item.is-wrong { border-left-color: var(--bad); }
.review__q { margin: 0 0 8px; font-weight: 600; }
.review__row { margin: 2px 0; font-size: .92rem; color: var(--text-dim); }
.review__row b { color: var(--text); font-weight: 600; }
.review__why { margin: 8px 0 0; font-size: .92rem; }
.review__img { max-height: 140px; border-radius: 8px; margin-bottom: 10px; }

/* ---------- footer ---------- */
.sitefoot {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 14px 40px;
  color: var(--text-dim);
  font-size: .8rem;
}

[hidden] { display: none !important; }
