:root {
  --bg: #f5f2ea;
  --card: #ffffff;
  --ink: #1d2623;
  --muted: #5f6c67;
  --line: #e4ded2;
  --good: #1c7a4b;
  --good-soft: #e1f3e9;
  --bad: #b13b2b;
  --bad-soft: #fbe7e3;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 8px 24px rgba(31,59,51,.08);
  --radius: 18px;
  --hdr: 56px;
  --dock: 64px;
  --t: 160;                                   /* topic hue, set per topic */
  --head: ui-rounded, "SF Pro Rounded", "Segoe UI Variable Display", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111614; --card: #1b2220; --ink: #e9efec; --muted: #9eaba6; --line: #2b3532;
    --good: #72d6a3; --good-soft: #17301f; --bad: #f29484; --bad-soft: #3a211d;
    --shadow: 0 0 0 1px #26302d;
  }
}
/* Topic colours are derived where --t is SET (root for a topic page, the card on home): a custom
   property that references another is resolved on the element declaring it, so defining these
   on :root alone would freeze every card at the default hue. */
:root, [style*="--t:"] { --tc: hsl(var(--t) 55% 38%); --tc-soft: hsl(var(--t) 60% 95%); --tc-ink: #fff; }
@media (prefers-color-scheme: dark) {
  :root, [style*="--t:"] { --tc: hsl(var(--t) 55% 62%); --tc-soft: hsl(var(--t) 30% 17%); --tc-ink: #0f1513; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2, .brand { font-family: var(--head); }
h1 { font-size: 1.45rem; line-height: 1.2; margin: 0; font-weight: 800; letter-spacing: -.2px; }
h2 { font-size: 1.08rem; margin: 0 0 6px; line-height: 1.3; font-weight: 700; }
a { color: var(--tc); }
:focus-visible { outline: 3px solid var(--tc); outline-offset: 2px; border-radius: 6px; }
svg.i { width: 22px; height: 22px; flex: none; }
.wrap { max-width: 720px; margin: 0 auto; padding: 0 max(16px, env(safe-area-inset-left)) 0 max(16px, env(safe-area-inset-right)); }
main { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
body.in-topic main { padding-bottom: calc(var(--dock) + 24px + env(safe-area-inset-bottom)); }

/* ---------- home ---------- */
.hero {
  position: relative; height: min(68svh, 560px); min-height: 380px; overflow: hidden;
  background: #2a3a35 url(img/hero.webp) center 22% / cover no-repeat; color: #fff;
}
.hero::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,.05) 35%, rgba(10,24,20,.55) 62%, rgba(10,24,20,.92) 100%);
}
.hero .inner {
  position: absolute; inset: auto 0 0 0; z-index: 1;
  padding: 0 max(20px, env(safe-area-inset-left)) 26px max(20px, env(safe-area-inset-right));
  max-width: 720px; margin: 0 auto;
}
.hero .kicker { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1px; background: rgba(255,255,255,.18); backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px); padding: 5px 12px; border-radius: 999px; }
.hero h1 { font-size: clamp(2.1rem, 9vw, 3rem); line-height: 1.02; margin: 12px 0 8px; text-shadow: 0 2px 18px rgba(0,0,0,.35); }
.hero p { margin: 0; font-size: 1.02rem; opacity: .92; }
.stats { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.stats span { background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.25); border-radius: 12px;
  padding: 6px 10px; font-size: .85rem; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.stats b { font-size: 1.05rem; margin-right: 3px; }
.section-title { font-family: var(--head); font-weight: 800; font-size: 1.15rem; margin: 22px 0 12px; }
.topics { display: grid; gap: 14px; }
@media (min-width: 640px) { .topics { grid-template-columns: 1fr 1fr; } }
a.topic {
  display: block; color: inherit; text-decoration: none; background: var(--card); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow); transition: transform .15s ease;
}
a.topic:active { transform: scale(.985); }
.topic .pic { position: relative; aspect-ratio: 2 / 1; background: var(--tc-soft) center / cover no-repeat; }
.topic .pic::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, transparent 50%, rgba(0,0,0,.35)); }
.badge {
  position: absolute; left: 14px; bottom: -22px; z-index: 1; width: 48px; height: 48px; border-radius: 14px;
  display: grid; place-items: center; background: var(--tc); color: var(--tc-ink);
  box-shadow: 0 6px 16px hsl(var(--t) 50% 30% / .35); border: 3px solid var(--card);
}
.topic .num { position: absolute; right: 12px; top: 12px; z-index: 1; background: rgba(0,0,0,.45); color: #fff;
  font-size: .75rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; backdrop-filter: blur(4px); }
.topic .body { padding: 30px 16px 16px; }
.topic .blurb { color: var(--muted); font-size: .94rem; }
.counts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.counts span { display: inline-flex; align-items: center; gap: 5px; font-size: .8rem; font-weight: 600;
  color: var(--tc); background: var(--tc-soft); padding: 4px 9px; border-radius: 999px; }
.counts svg.i { width: 15px; height: 15px; }
footer.note { color: var(--muted); font-size: .8rem; text-align: center; margin: 28px 0 8px; }

/* ---------- topic header + banner ---------- */
.appbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  height: calc(var(--hdr) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 3px solid var(--tc);
}
.backbtn {
  display: inline-flex; align-items: center; gap: 2px; height: 44px; padding: 0 16px 0 8px; border-radius: 999px;
  background: var(--tc); color: var(--tc-ink); text-decoration: none; font-weight: 800; font-size: .95rem; flex: none;
  box-shadow: 0 3px 10px hsl(var(--t) 50% 30% / .25);
}
.backbtn svg.i { width: 22px; height: 22px; stroke-width: 2.6; }
.backbtn:active { transform: scale(.96); }
.minibrand { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; min-width: 0; text-decoration: none; color: var(--ink);
  font-family: var(--head); font-weight: 800; font-size: .95rem; }
.minibrand span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { width: 34px; height: 34px; border-radius: 50%; flex: none; background: #2a3a35 url(img/hero.webp) 52% 14% / 260% auto no-repeat;
  box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--tc); }
.banner { position: relative; height: 150px; background: var(--tc) center 40% / cover no-repeat; color: #fff; }
.banner .crumb { font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .8px; opacity: .85; }
.banner.small { height: 96px; }
.banner::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, hsl(var(--t) 60% 18% / .9), hsl(var(--t) 60% 25% / .35)); }
.banner .wrap { position: relative; z-index: 1; height: 100%; display: flex; align-items: flex-end; gap: 12px; padding-bottom: 14px; }
.banner .badge { position: static; border-color: rgba(255,255,255,.35); width: 44px; height: 44px; }
.banner h1 { font-size: 1.25rem; text-shadow: 0 1px 10px rgba(0,0,0,.4); }
.banner.small h1 { font-size: 1.05rem; }
.banner .sub { font-size: .82rem; opacity: .9; }

/* ---------- bottom dock ---------- */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.dock[hidden], body.kb .dock { display: none; }
.dock a { min-height: var(--dock); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; text-decoration: none; color: var(--muted); font-size: .72rem; font-weight: 600; }
.dock a.on { color: var(--tc); }
.dock a.on svg { background: var(--tc-soft); border-radius: 999px; padding: 3px 14px; width: 52px; height: 30px; }
.dock a svg { width: 24px; height: 24px; padding: 3px 0; box-sizing: content-box; height: 24px; }

/* ---------- summary ---------- */
.chipbar {
  position: sticky; top: calc(var(--hdr) + env(safe-area-inset-top)); z-index: 5; display: flex; align-items: center; gap: 4px;
  padding: 8px 8px; margin: 0 -16px 8px;
  background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.chev { flex: none; width: 36px; height: 44px; display: grid; place-items: center; border: 0; border-radius: 12px;
  background: var(--tc-soft); color: var(--tc); cursor: pointer; transition: opacity .2s; }
.chev:disabled { opacity: .3; cursor: default; }
.chips {
  flex: 1; min-width: 0; display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 0 2px;
  scroll-snap-type: x proximity; cursor: grab; touch-action: pan-x pan-y;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 16px, #000 calc(100% - 16px), transparent);
          mask-image: linear-gradient(90deg, transparent, #000 16px, #000 calc(100% - 16px), transparent);
}
.chipbar.at-start .chips { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 16px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 16px), transparent); }
.chipbar.at-end .chips { -webkit-mask-image: linear-gradient(90deg, transparent, #000 16px); mask-image: linear-gradient(90deg, transparent, #000 16px); }
.chipbar.at-start.at-end .chips { -webkit-mask-image: none; mask-image: none; }
.chips::-webkit-scrollbar { display: none; }
.chips a { flex: none; min-width: 44px; height: 44px; padding: 0 6px; border-radius: 22px; display: grid; place-items: center;
  text-decoration: none; color: var(--ink); background: var(--card); border: 1px solid var(--line); font-weight: 700;
  font-size: .9rem; scroll-snap-align: start; transition: background .2s, color .2s; }
.chips a.on { background: var(--tc); color: var(--tc-ink); border-color: var(--tc); }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin: 0 0 12px; }
.slide { scroll-margin-top: calc(var(--hdr) + env(safe-area-inset-top) + 72px); transition: box-shadow .4s; }
.slide .pill { display: inline-block; font-size: .74rem; font-weight: 800; letter-spacing: .5px; text-transform: uppercase;
  color: var(--tc); background: var(--tc-soft); padding: 3px 10px; border-radius: 999px; margin-bottom: 8px; }
.slide ul { margin: 4px 0 0; padding-left: 0; list-style: none; }
.slide li { position: relative; padding-left: 20px; margin: 6px 0; }
.slide li::before { content: ""; position: absolute; left: 4px; top: .62em; width: 7px; height: 7px; border-radius: 50%; background: var(--tc); }
.slide.flash { box-shadow: 0 0 0 3px var(--tc), var(--shadow); }
details { border-top: 1px solid var(--line); margin-top: 12px; }
details + details { margin-top: 0; }
summary { min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 8px; cursor: pointer;
  color: var(--tc); font-weight: 700; font-size: .92rem; list-style: none; }
summary::-webkit-details-marker { display: none; }
summary::after { content: ""; width: 9px; height: 9px; border-right: 2.5px solid currentColor; border-bottom: 2.5px solid currentColor;
  transform: rotate(45deg) translate(-2px, -2px); transition: transform .2s; }
details[open] summary::after { transform: rotate(225deg); }
.full { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .95rem; background: var(--tc-soft); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 10px; }
.full .label { display: block; font-size: .72rem; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 2px; }
.slideimg { width: 100%; height: auto; border-radius: 12px; margin-bottom: 10px; border: 1px solid var(--line); display: block; }

/* ---------- practice shared ---------- */
.prog-row { display: flex; align-items: center; gap: 10px; margin: 16px 0 12px; font-size: .88rem; color: var(--muted); font-weight: 600; }
.prog { flex: 1; height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.prog i { display: block; height: 100%; border-radius: inherit; background: var(--tc); transition: width .3s ease; }
.btn {
  appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 48px;
  border: 0; background: var(--tc); color: var(--tc-ink); border-radius: 14px; padding: 0 18px;
  font: inherit; font-weight: 700; cursor: pointer; transition: transform .1s;
}
.btn:active { transform: scale(.97); }
.btn.ghost { background: var(--card); color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line); }
.btn:disabled { opacity: .45; }
.btn svg.i { width: 20px; height: 20px; }
.nav-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.tools { display: flex; justify-content: flex-end; margin-bottom: 4px; }
.tools .btn { min-height: 40px; padding: 0 12px; font-size: .88rem; }
.readmore { display: inline-flex; align-items: center; min-height: 44px; font-weight: 700; font-size: .92rem; text-decoration: none; }
.empty { color: var(--muted); }

/* ---------- flashcards ---------- */
.flip { perspective: 1200px; touch-action: pan-y; user-select: none; -webkit-user-select: none; cursor: pointer; }
.flip-inner { display: grid; transition: transform .5s cubic-bezier(.2,.7,.2,1); transform-style: preserve-3d; }
.flip.flipped .flip-inner { transform: rotateY(180deg); }
.face {
  grid-area: 1 / 1; min-height: 260px; display: flex; flex-direction: column; justify-content: center; text-align: center;
  padding: 22px 20px; border-radius: 22px; background: var(--card); box-shadow: var(--shadow);
  backface-visibility: hidden; -webkit-backface-visibility: hidden; font-size: 1.15rem; line-height: 1.4;
}
.face.front { border-top: 6px solid var(--tc); }
.face.back { transform: rotateY(180deg); background: var(--tc); color: var(--tc-ink); }
.face .side { font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 1px; opacity: .65; margin-bottom: 12px; }
.face.front .q { font-family: var(--head); font-weight: 700; font-size: 1.25rem; }
.face.back .readmore { color: inherit; justify-content: center; text-decoration: underline; text-underline-offset: 3px; }
.hint { text-align: center; color: var(--muted); font-size: .82rem; margin-top: 10px; }
.swipe-out-l { animation: outL .18s ease-in forwards; }
.swipe-out-r { animation: outR .18s ease-in forwards; }
@keyframes outL { to { transform: translateX(-40px); opacity: 0; } }
@keyframes outR { to { transform: translateX(40px); opacity: 0; } }
.slide-in { animation: inUp .25s ease-out; }
@keyframes inUp { from { transform: translateY(8px); opacity: 0; } }

/* ---------- fill in the blank ---------- */
.blank-card { position: relative; }
.blank-q { font-size: 1.12rem; line-height: 1.55; font-family: var(--head); font-weight: 600; }
.blank-q .gap { display: inline-block; min-width: 4.5em; border-bottom: 3px solid var(--tc); margin: 0 2px; }
.score { display: inline-flex; align-items: center; gap: 6px; font-weight: 800; color: var(--tc); background: var(--tc-soft);
  padding: 4px 10px; border-radius: 999px; font-size: .85rem; }
input.answer {
  width: 100%; font: inherit; font-size: 17px; padding: 13px 14px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--bg); color: var(--ink); margin: 14px 0 10px; transition: border-color .15s;
}
input.answer:focus { outline: none; border-color: var(--tc); }
.blank-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.result { border-radius: 14px; padding: 12px 14px; margin-top: 12px; animation: pop .35s ease-out; }
.result.good { background: var(--good-soft); color: var(--good); }
.result.bad { background: var(--bad-soft); color: var(--bad); }
.result .verdict { font-weight: 800; font-size: 1.05rem; }
.result strong { color: var(--ink); }
.shake { animation: shake .4s ease-in-out; }
@keyframes shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }
@keyframes pop { 0% { transform: scale(.94); opacity: 0; } 60% { transform: scale(1.03); opacity: 1; } 100% { transform: scale(1); } }
.burst { position: absolute; left: 50%; top: 40%; width: 0; height: 0; pointer-events: none; z-index: 3; }
.burst i { position: absolute; width: 8px; height: 12px; border-radius: 2px; background: var(--c);
  animation: fly .9s cubic-bezier(.15,.7,.3,1) forwards; }
@keyframes fly { to { transform: rotate(var(--a)) translateY(var(--d)) rotate(var(--r)); opacity: 0; } }


/* ---------- slide cards: thumbnail + full-screen viewer ---------- */
.slide-top { display: flex; gap: 14px; align-items: flex-start; }
.slide-head { min-width: 0; flex: 1; }
.thumb {
  position: relative; flex: none; width: 120px; aspect-ratio: 16 / 9; padding: 0; border: 0; border-radius: 10px; overflow: hidden;
  cursor: zoom-in; background: var(--tc-soft); box-shadow: 0 0 0 1px var(--line), 0 4px 12px rgba(0,0,0,.08);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s; }
.thumb:active img { transform: scale(1.04); }
.thumb .zoom { position: absolute; right: 5px; bottom: 5px; width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: rgba(0,0,0,.6); color: #fff; backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.thumb .zoom svg.i { width: 16px; height: 16px; stroke-width: 2.4; }
@media (max-width: 360px) { .thumb { width: 96px; } }
body.noscroll { overflow: hidden; }
body.noscroll .dock { display: none; }
.viewer { position: fixed; inset: 0; z-index: 50; background: #0b0f0e; color: #fff; display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); animation: fadeIn .2s ease-out; }
@keyframes fadeIn { from { transform: scale(.98); } }
.vbar, .vnav { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; }
.vbar span { font-weight: 700; font-size: .95rem; opacity: .85; }
.vstage { flex: 1; display: grid; place-items: center; padding: 8px; min-height: 0; touch-action: pinch-zoom pan-y; }
.vstage img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; background: #fff; }
.vbtn { width: 48px; height: 48px; border-radius: 50%; border: 0; display: grid; place-items: center; background: rgba(255,255,255,.14); color: #fff; cursor: pointer; }
.vbtn:disabled { opacity: .3; }
.vtitle { flex: 1; text-align: center; font-size: .9rem; opacity: .85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- multiple-choice test ---------- */
.btn.small { min-height: 40px; padding: 0 12px; font-size: .88rem; }
.prog-row .btn.small { min-height: 36px; }
.nav-row.single { grid-template-columns: 1fr; }
.test-intro { text-align: center; padding: 26px 20px; }
.test-intro > svg.i { width: 44px; height: 44px; color: var(--tc); background: var(--tc-soft); padding: 12px; box-sizing: content-box; border-radius: 18px; }
.test-intro h2 { margin-top: 12px; font-size: 1.3rem; }
.test-intro p, .result-card p { color: var(--muted); }
.test-start { display: grid; gap: 10px; margin-top: 16px; }
.mcq { position: relative; }
.mcq-q { font-family: var(--head); font-weight: 700; font-size: 1.12rem; line-height: 1.4; margin-bottom: 14px; }
.mcq-q.small { font-size: 1rem; margin-bottom: 6px; }
.opts { display: grid; gap: 10px; }
.opt {
  position: relative; display: flex; align-items: center; gap: 12px; width: 100%; min-height: 54px; padding: 10px 14px; text-align: left;
  font: inherit; font-size: 1rem; color: var(--ink); background: var(--bg); border: 2px solid var(--line); border-radius: 14px; cursor: pointer;
  transition: border-color .15s, background .15s, transform .1s;
}
.opt:active { transform: scale(.985); }
.opt .key { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: .85rem;
  background: var(--tc-soft); color: var(--tc); }
.opt.correct { border-color: var(--good); background: var(--good-soft); }
.opt.correct .key { background: var(--good); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong .key { background: var(--bad); color: #fff; }
.opt:disabled { cursor: default; }
.opt:disabled:not(.correct):not(.wrong) { opacity: .55; }
.result-card { position: relative; text-align: center; padding: 26px 20px; }
.ring { --p: 0; width: 128px; height: 128px; margin: 0 auto 10px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--tc) calc(var(--p) * 1%), var(--line) 0); }
.ring span { width: 104px; height: 104px; border-radius: 50%; display: grid; place-items: center; background: var(--card);
  font-family: var(--head); font-weight: 800; font-size: 1.7rem; color: var(--tc); }
.missed { padding: 14px 16px; }
a.btn { text-decoration: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .burst { display: none; }
}
