/* ===== Design tokens ===== */
:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f0ede6;
  --text: #1d2433;
  --muted: #485062;
  --border: #ddd8cc;
  --brand: #012169;      /* Union blue */
  --brand-ink: #ffffff;
  --accent: #c8102e;     /* Union red */
  --ok: #1b7f4b;
  --ok-bg: #e5f4ec;
  --bad: #b3261e;
  --bad-bg: #fbe9e7;
  --warn-bg: #fff5d6;
  --focus: #2f6fed;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 24, 40, .06), 0 4px 16px rgba(20, 24, 40, .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11151d; --surface: #1a202b; --surface-2: #222a37; --text: #e8ebf1; --muted: #a2abbb;
    --border: #2f3847; --brand: #8fb0ff; --brand-ink: #0c1222; --accent: #ff6b7d;
    --ok: #5fd39a; --ok-bg: #173226; --bad: #ff8a80; --bad-bg: #3a1e1e; --warn-bg: #3a3218; --focus: #8fb0ff;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11151d; --surface: #1a202b; --surface-2: #222a37; --text: #e8ebf1; --muted: #a2abbb;
  --border: #2f3847; --brand: #8fb0ff; --brand-ink: #0c1222; --accent: #ff6b7d;
  --ok: #5fd39a; --ok-bg: #173226; --bad: #ff8a80; --bad-bg: #3a1e1e; --warn-bg: #3a3218; --focus: #8fb0ff;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
  color-scheme: dark;
}

/* ===== Base ===== */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.6 var(--font); }
a { color: var(--brand); }
img { max-width: 100%; height: auto; }
h1, h2, h3, h4 { line-height: 1.25; margin: 1.4em 0 .5em; }
h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); margin-top: .6em; }
h2 { font-size: 1.4rem; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--surface); padding: 8px 12px; z-index: 100; }
.skip-link:focus { left: 8px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.hidden { display: none !important; }

/* ===== Header ===== */
.site-header { background: var(--brand); color: var(--brand-ink); position: sticky; top: 0; z-index: 20; box-shadow: var(--shadow); }
:root[data-theme="dark"] .site-header { background: var(--surface); color: var(--text); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .site-header { background: var(--surface); color: var(--text); } }
.header-inner { display: flex; align-items: center; justify-content: space-between; min-height: 60px; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-weight: 700; }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 8px; background: var(--accent); color: #fff; font-size: .9rem; letter-spacing: .5px; }
.brand-sub { display: block; font-weight: 400; font-size: .75rem; opacity: .8; }
.site-nav { display: flex; align-items: center; gap: 4px; }
.site-nav a { color: inherit; text-decoration: none; padding: 8px 12px; border-radius: 8px; font-size: .95rem; }
.site-nav a:hover, .site-nav a.active { background: rgba(255,255,255,.15); }
.theme-toggle, .nav-toggle { background: transparent; border: 1px solid rgba(255,255,255,.35); color: inherit; border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 1rem; }
.nav-toggle { display: none; }
@media (max-width: 760px) {
  .nav-toggle { display: block; }
  .site-nav { display: none; position: absolute; left: 0; right: 0; top: 60px; flex-direction: column; align-items: stretch; background: inherit; padding: 8px 16px 16px; background: var(--brand); }
  :root[data-theme="dark"] .site-nav { background: var(--surface); }
  .site-nav.open { display: flex; }
  .theme-toggle { align-self: flex-start; margin-top: 6px; }
}

/* ===== Footer ===== */
.site-footer { margin-top: 64px; padding: 24px 0 40px; border-top: 1px solid var(--border); color: var(--muted); font-size: .85rem; }

/* ===== Cards & grids ===== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.hero { padding: 28px 0 8px; }
.hero p { max-width: 70ch; font-size: 1.05rem; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 16px 0; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat b { display: block; font-size: 1.6rem; line-height: 1.1; }
.stat span { color: var(--muted); font-size: .85rem; }

.chapter-card { display: flex; flex-direction: column; gap: 10px; }
.chapter-card h3 { margin: 0; font-size: 1.1rem; }
.chapter-card .icon { font-size: 1.6rem; }
.chapter-card .actions { margin-top: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.progress.ok > span { background: var(--ok); }

/* ===== Buttons ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 10px 16px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; min-height: 44px; }
.btn:hover { border-color: var(--brand); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { color: var(--bad); }
.btn-sm { padding: 6px 12px; min-height: 36px; font-size: .9rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }

/* ===== Reader ===== */
.reader { display: grid; grid-template-columns: 260px 1fr; gap: 28px; align-items: start; margin-top: 20px; }
.toc { position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow: auto; padding: 16px; }
.toc h3 { margin: 0 0 8px; font-size: .95rem; }
.toc ol { list-style: none; padding: 0; margin: 0 0 12px; }
.toc li a { display: block; padding: 6px 8px; border-radius: 8px; text-decoration: none; color: var(--text); font-size: .92rem; }
.toc li a:hover { background: var(--surface-2); }
.toc li a.active { background: var(--brand); color: var(--brand-ink); }
.toc .read-mark { float: right; color: var(--ok); }
.chapter-select { width: 100%; padding: 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; margin-bottom: 12px; }
.article { padding: 24px 28px; }
.article h2.section-title { margin-top: 0; }
.article p, .article li { max-width: 72ch; }
.article h4 { font-size: 1.08rem; color: var(--brand); margin-top: 1.6em; }
.article h4.check-heading { color: var(--text); background: var(--warn-bg); padding: 10px 14px; border-radius: 10px 10px 0 0; margin-bottom: 0; }
.article h4.check-heading + ul { background: var(--warn-bg); margin-top: 0; padding: 4px 14px 12px 34px; border-radius: 0 0 10px 10px; }
.table-wrap { overflow-x: auto; margin: 12px 0; }
table { border-collapse: collapse; width: 100%; font-size: .95rem; }
th, td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; vertical-align: top; }
th { background: var(--surface-2); }
.note-figure { margin: 20px 0; max-width: 560px; }
.note-figure img { border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); display: block; max-height: 420px; width: auto; }
.note-figure figcaption { font-size: .85rem; color: var(--muted); margin-top: 6px; }
.note-figure .credit { display: block; font-size: .78rem; margin-top: 2px; }
.note-figure .credit a { color: var(--muted); }
.note-figure.wide { max-width: 760px; }
table.credits img { width: 72px; height: 54px; object-fit: cover; border-radius: 6px; display: block; }
table.credits td { font-size: .88rem; }
.note-figure.failed img { display: none; }
.note-figure.failed figcaption::before { content: "🖼 Image could not load – "; }
.section-nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 32px; flex-wrap: wrap; }
@media (max-width: 860px) {
  .reader { grid-template-columns: 1fr; }
  .toc { position: static; max-height: none; }
  .article { padding: 18px 16px; }
}

/* ===== Quiz setup ===== */
fieldset { border: 0; padding: 0; margin: 0 0 18px; }
legend { font-weight: 700; margin-bottom: 8px; }
.choice-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.choice { position: relative; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice label { display: block; height: 100%; border: 2px solid var(--border); background: var(--surface); border-radius: 10px; padding: 12px 14px; cursor: pointer; }
.choice label b { display: block; }
.choice label span { color: var(--muted); font-size: .88rem; }
.choice input:checked + label { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 8%, var(--surface)); }
.choice input:focus-visible + label { outline: 3px solid var(--focus); outline-offset: 2px; }
.choice input:disabled + label { opacity: .5; cursor: not-allowed; }

/* ===== Quiz runner ===== */
.quiz-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin: 20px 0 10px; }
.quiz-meta { color: var(--muted); font-size: .92rem; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; padding: 4px 10px; border-radius: 8px; background: var(--surface-2); }
.timer.low { background: var(--bad-bg); color: var(--bad); }
.question-card { padding: 24px; }
.q-type { display: inline-block; font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); margin-bottom: 6px; }
.q-text { font-size: 1.2rem; font-weight: 600; margin: 0 0 16px; }
.options { display: grid; gap: 10px; }
.option { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border: 2px solid var(--border); border-radius: 10px; cursor: pointer; background: var(--surface); text-align: left; font: inherit; color: var(--text); width: 100%; min-height: 48px; }
.option:hover:not([disabled]) { border-color: var(--brand); }
.option .key { flex: none; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 6px; background: var(--surface-2); font-weight: 700; font-size: .85rem; }
.option.selected { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 8%, var(--surface)); }
.option.selected .key { background: var(--brand); color: var(--brand-ink); }
.option.correct { border-color: var(--ok); background: var(--ok-bg); }
.option.correct .key { background: var(--ok); color: #fff; }
.option.wrong { border-color: var(--bad); background: var(--bad-bg); }
.option.wrong .key { background: var(--bad); color: #fff; }
.option[disabled] { cursor: default; }
.feedback { margin-top: 16px; padding: 12px 14px; border-radius: 10px; }
.feedback.ok { background: var(--ok-bg); }
.feedback.bad { background: var(--bad-bg); }
.feedback b { display: block; margin-bottom: 4px; }
.dots { display: flex; flex-wrap: wrap; gap: 4px; margin: 12px 0; }
.dots button { width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); font-size: .7rem; cursor: pointer; color: var(--muted); padding: 0; }
.dots button.answered { background: var(--surface-2); color: var(--text); }
.dots button.current { outline: 2px solid var(--brand); }
.dots button.ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.dots button.bad { background: var(--bad); color: #fff; border-color: var(--bad); }

/* ===== Results ===== */
.result-hero { text-align: center; padding: 28px 20px; }
.result-hero .score { font-size: 3rem; font-weight: 800; line-height: 1; }
.badge { display: inline-block; padding: 4px 12px; border-radius: 99px; font-weight: 700; font-size: .9rem; }
.badge.pass { background: var(--ok-bg); color: var(--ok); }
.badge.fail { background: var(--bad-bg); color: var(--bad); }
.review-item { border-left: 4px solid var(--border); padding: 10px 14px; margin: 10px 0; background: var(--surface); border-radius: 0 10px 10px 0; }
.review-item.ok { border-color: var(--ok); }
.review-item.bad { border-color: var(--bad); }
.review-item p { margin: 4px 0; }
.review-item .ans-ok { color: var(--ok); font-weight: 600; }
.review-item .ans-bad { color: var(--bad); font-weight: 600; text-decoration: line-through; }

.notice { background: var(--warn-bg); border-radius: 10px; padding: 12px 14px; margin: 12px 0; }
.list-plain { padding-left: 1.2em; }
.list-plain li { margin: 4px 0; }
table.stats td:not(:first-child), table.stats th:not(:first-child) { text-align: right; }

/* =====================================================================
   BOOK DESIGN
   ===================================================================== */
:root {
  --paper: #fbf6ea;
  --paper-edge: #e9dfc8;
  --ink: #2a2418;
  --ink-muted: #6b604c;
  --gold: #b8892f;
  --serif-display: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --serif-text: "Source Serif 4", Georgia, "Times New Roman", serif;
  --glass: rgba(255, 255, 255, .86);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --paper: #221e17; --paper-edge: #3a3226; --ink: #ece4d2; --ink-muted: #b3a78f; --gold: #d9ac55; --glass: rgba(22, 26, 34, .84); }
}
:root[data-theme="dark"] { --paper: #221e17; --paper-edge: #3a3226; --ink: #ece4d2; --ink-muted: #b3a78f; --gold: #d9ac55; --glass: rgba(22, 26, 34, .84); }

/* Fixed page background picture (set per page by the app) */
#page-bg { position: fixed; inset: 0; z-index: -2; background: var(--bg) center / cover no-repeat; transition: background-image .4s ease; }
body.has-bg #page-bg::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(10, 14, 24, .55), rgba(10, 14, 24, .72)); }
body.has-bg { background: #0d1118; }
.bg-credit { position: fixed; right: 8px; bottom: 6px; z-index: 5; max-width: min(560px, calc(100vw - 16px)); font-size: .7rem; line-height: 1.3;
  color: rgba(255, 255, 255, .78); background: rgba(0, 0, 0, .45); padding: 4px 8px; border-radius: 6px; }
.bg-credit:empty { display: none; }
.bg-credit a { color: #fff; }
main { padding-bottom: 48px; }

/* Glass panels and headings that sit on a background picture */
.glass { background: var(--glass); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); border: 1px solid rgba(255, 255, 255, .25);
  border-radius: var(--radius); padding: 22px 24px; box-shadow: var(--shadow); margin-top: 24px; }
.glass h1 { margin-top: 0; font-family: var(--serif-display); font-size: clamp(2rem, 5vw, 2.8rem); }
.glass p { margin-bottom: 0; }
.eyebrow { text-transform: uppercase; letter-spacing: .18em; font-size: .78rem; color: var(--accent); font-weight: 700; }
body.has-bg h2.on-bg { color: #fff; text-shadow: 0 2px 8px rgba(0, 0, 0, .6); font-family: var(--serif-display); font-size: 1.8rem; }
.chip { background: var(--surface); padding: 6px 12px; border-radius: 99px; border: 1px solid var(--border); }
.hero.glass { padding: 32px; }
.hero h1 { font-size: clamp(2.2rem, 6vw, 3.4rem); }

/* Page-turn animation */
@keyframes turnIn { from { opacity: 0; transform: perspective(1400px) rotateY(-14deg) translateX(24px); } to { opacity: 1; transform: none; } }
.turn-in { animation: turnIn .55s cubic-bezier(.2, .7, .2, 1) both; transform-origin: left center; }
@media (prefers-reduced-motion: reduce) { .turn-in { animation: none; } }

/* Chapter cards on the home page look like book covers */
.book-card { background: var(--surface); border: 1px solid var(--border); border-radius: 6px 14px 14px 6px; overflow: hidden; display: flex; flex-direction: column;
  box-shadow: -6px 0 0 -2px rgba(0, 0, 0, .25) inset, var(--shadow); }
.book-card-cover { position: relative; display: flex; flex-direction: column; justify-content: flex-end; min-height: 190px; padding: 16px 18px;
  background: #223 center / cover no-repeat; color: #fff; text-decoration: none; }
.book-card-cover::before { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0, 0, 0, .05) 20%, rgba(0, 0, 0, .78)); }
.book-card-cover::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 10px; background: linear-gradient(90deg, rgba(0, 0, 0, .45), transparent); }
.book-card-cover > span { position: relative; }
.book-card-num { font-size: .75rem; letter-spacing: .2em; text-transform: uppercase; color: #f3d38a; }
.book-card-title { font-family: var(--serif-display); font-size: 1.55rem; font-weight: 700; line-height: 1.1; }
.book-card-body { padding: 14px 18px 18px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.book-card-body .actions { margin-top: auto; display: flex; gap: 8px; }

/* Full-page covers for chapters and sub-chapters */
.cover { position: relative; margin: 20px auto 0; min-height: calc(100vh - 110px); border-radius: 6px 18px 18px 6px; overflow: hidden;
  background: #1b2233 center / cover no-repeat; color: #fff; display: flex; align-items: flex-end;
  box-shadow: -14px 0 0 -6px rgba(0, 0, 0, .35) inset, 0 20px 50px rgba(0, 0, 0, .35); }
.cover-shade { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(5, 8, 15, .15) 0%, rgba(5, 8, 15, .35) 45%, rgba(5, 8, 15, .88) 100%); }
.cover::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 22px; z-index: 1; background: linear-gradient(90deg, rgba(0, 0, 0, .55), rgba(0, 0, 0, 0)); }
.cover-inner { position: relative; z-index: 2; padding: clamp(24px, 6vw, 64px); max-width: 860px; }
.cover-crumbs { display: flex; gap: 18px; margin-bottom: 18vh; font-size: .9rem; }
.cover-crumbs a { color: rgba(255, 255, 255, .85); text-decoration: none; }
.cover-crumbs a:hover { text-decoration: underline; }
.cover-eyebrow { text-transform: uppercase; letter-spacing: .28em; font-size: .85rem; color: #f3d38a; font-weight: 600; }
.cover-rule { width: 90px; height: 2px; background: #f3d38a; margin: 14px 0 10px; }
.cover-title { font-family: var(--serif-display); font-weight: 700; font-size: clamp(2.6rem, 8vw, 5rem); line-height: 1; margin: 0 0 14px; text-shadow: 0 3px 18px rgba(0, 0, 0, .5); }
.cover-blurb { font-family: var(--serif-text); font-size: 1.15rem; max-width: 60ch; color: rgba(255, 255, 255, .92); }
.cover-actions { margin-top: 22px; }
.btn-ghost { background: rgba(255, 255, 255, .12); color: #fff; border-color: rgba(255, 255, 255, .45); }
.btn-ghost:hover { background: rgba(255, 255, 255, .22); border-color: #fff; }
.cover .btn-primary { background: #f3d38a; border-color: #f3d38a; color: #1d1608; }
.cover-credit { position: absolute; right: 10px; bottom: 8px; z-index: 2; font-size: .7rem; color: rgba(255, 255, 255, .75); max-width: 70%; text-align: right; }
.cover-credit a { color: #fff; }

/* Paper pages */
.book { max-width: 920px; margin: 20px auto 0; }
.paper { position: relative; background: var(--paper); color: var(--ink); border-radius: 4px 14px 14px 4px;
  padding: clamp(22px, 5vw, 56px) clamp(18px, 6vw, 72px) 60px;
  box-shadow: inset 18px 0 22px -16px rgba(0, 0, 0, .35), 0 1px 0 var(--paper-edge), 0 3px 0 -1px var(--paper), 0 4px 0 -1px var(--paper-edge), 0 18px 40px rgba(0, 0, 0, .18);
  background-image: radial-gradient(circle at 20% 10%, rgba(255, 255, 255, .35), transparent 50%), linear-gradient(90deg, rgba(0, 0, 0, .05), transparent 6%); }
.paper a { color: inherit; }
.paper-crumbs { display: flex; justify-content: space-between; gap: 12px; font-size: .88rem; color: var(--ink-muted); margin-bottom: 18px; }
.paper-crumbs a { color: var(--ink-muted); }
.paper-kicker { text-transform: uppercase; letter-spacing: .18em; font-size: .75rem; color: var(--gold); font-weight: 700; }
.paper-heading { font-family: var(--serif-display); font-size: clamp(2rem, 5vw, 2.8rem); margin: .2em 0 .3em; color: var(--ink); }
.paper-sub { font-family: var(--serif-text); font-style: italic; color: var(--ink-muted); margin-top: 0; }
.prose { font-family: var(--serif-text); font-size: 1.08rem; line-height: 1.75; }
.prose p:first-of-type::first-letter { float: left; font-family: var(--serif-display); font-size: 3.4em; line-height: .8; padding: 6px 8px 0 0; color: var(--gold); font-weight: 700; }
.prose h4 { font-family: var(--serif-display); font-size: 1.45rem; color: var(--ink); margin-top: 1.8em; border-bottom: 1px solid var(--paper-edge); padding-bottom: 4px; }
.prose h4.check-heading { font-family: var(--font); font-size: 1rem; border: 0; }
.prose table th { background: rgba(0, 0, 0, .05); }
.prose th, .prose td { border-color: var(--paper-edge); }
.prose .note-figure { max-width: 100%; margin: 26px auto; text-align: center; }
.prose .note-figure img { margin: 0 auto; max-height: 460px; box-shadow: 0 6px 18px rgba(0, 0, 0, .18); border: 6px solid #fff; border-radius: 2px; }
.prose .note-figure figcaption { font-family: var(--serif-text); font-style: italic; color: var(--ink-muted); }
.prose .note-figure .credit { font-style: normal; font-family: var(--font); }
.prose .note-figure .credit a, .prose .note-figure figcaption { color: var(--ink-muted); }
.page-nav { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--paper-edge); }
.paper .btn { background: transparent; color: var(--ink); border-color: var(--paper-edge); }
.paper .btn-primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.folio { position: absolute; left: 0; right: 0; bottom: 18px; text-align: center; font-family: var(--serif-text); font-style: italic; font-size: .85rem; color: var(--ink-muted); }

/* Contents page */
.toc-list { list-style: none; padding: 0; margin: 24px 0 0; }
.toc-row { display: flex; align-items: center; gap: 14px; padding: 12px 6px; text-decoration: none; border-bottom: 1px dashed var(--paper-edge); font-family: var(--serif-text); font-size: 1.12rem; }
.toc-row:hover { background: rgba(0, 0, 0, .04); }
.toc-thumb { flex: none; width: 64px; height: 44px; border-radius: 3px; background: var(--paper-edge) center / cover no-repeat; box-shadow: 0 2px 6px rgba(0, 0, 0, .2); }
.toc-num { flex: none; font-family: var(--serif-display); font-weight: 700; font-size: 1.3rem; color: var(--gold); min-width: 2.4em; }
.toc-title { flex: none; max-width: 60%; }
.toc-dots { flex: 1; border-bottom: 2px dotted var(--paper-edge); transform: translateY(-4px); min-width: 20px; }
.toc-meta { flex: none; font-size: .85rem; color: var(--ink-muted); }
.toc-meta .read-mark { float: none; color: var(--ok); }
@media (max-width: 600px) {
  .toc-thumb { display: none; }
  .toc-title { max-width: none; flex: 1; }
  .toc-dots { display: none; }
  .cover-crumbs { margin-bottom: 10vh; }
  .cover-credit { max-width: 92%; }
}
.glass + .card, .glass + .stat-row, .glass + .table-wrap { margin-top: 16px; }
@media (max-width: 600px) { .cover-inner { padding-bottom: 90px; } .cover-credit { left: 10px; text-align: left; } }

/* =====================================================================
   HOME PAGE (modern layout)
   ===================================================================== */
main.wide { max-width: 1400px; }
@keyframes rise { from { opacity: 0; transform: translateY(18px) scale(.98); } to { opacity: 1; transform: none; } }
.rise { animation: rise .6s cubic-bezier(.2, .7, .2, 1) both; animation-delay: calc(var(--i, 0) * 70ms); }
@keyframes kenburns { from { transform: scale(1.02); } to { transform: scale(1.12) translate(-1%, -1%); } }
body.has-bg #page-bg { animation: kenburns 40s ease-in-out infinite alternate; }

.home-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(320px, 1fr); gap: 20px; margin-top: 24px; }
.home-grid .glass { margin-top: 0; }
.home-hero { padding: clamp(24px, 4vw, 44px); display: flex; flex-direction: column; justify-content: center; }
.home-hero h1 { font-family: var(--serif-display); font-size: clamp(2.4rem, 5.5vw, 4.2rem); line-height: 1.02; margin: .15em 0 .3em; }
.accent-word { background: linear-gradient(90deg, var(--accent), var(--gold)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.lead { font-size: 1.12rem; max-width: 56ch; }
.btn-lg { padding: 13px 22px; font-size: 1.02rem; }
.exam-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 22px; }
.exam-chips span { padding: 6px 12px; border-radius: 99px; border: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 70%, transparent); font-size: .88rem; }
.exam-chips b { color: var(--accent); }

.home-progress { display: flex; flex-direction: column; gap: 14px; padding: 22px 24px; }
.hp-head { display: flex; justify-content: space-between; align-items: baseline; }
.hp-head h2 { margin: 0; font-family: var(--serif-display); font-size: 1.6rem; }
.hp-body { display: grid; grid-template-columns: 140px 1fr; gap: 18px; align-items: center; }
.ring { position: relative; width: 140px; height: 140px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--surface-2); stroke-width: 11; }
.ring-fill { fill: none; stroke: url(#none) var(--ok); stroke: var(--ok); stroke-width: 11; stroke-linecap: round; transition: stroke-dashoffset 1.3s cubic-bezier(.2, .7, .2, 1); }
.ring-label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; line-height: 1; }
.ring-label b { font-size: 2.2rem; }
.ring-label span { font-size: .78rem; color: var(--muted); margin-top: 4px; }
.hp-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0; }
.hp-stats div { background: color-mix(in srgb, var(--surface) 75%, transparent); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; }
.hp-stats dt { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.hp-stats dd { margin: 2px 0 0; font-size: .95rem; }
.hp-stats dd b { font-size: 1.35rem; }
.hp-last { font-size: .88rem; color: var(--muted); border-top: 1px solid var(--border); padding-top: 12px; }

.action-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-top: 20px; }
.action-tile { margin-top: 0; display: flex; align-items: center; gap: 14px; padding: 16px 18px; text-decoration: none; color: var(--text);
  transition: transform .25s ease, box-shadow .25s ease, border-color .25s ease; }
a.action-tile:hover { transform: translateY(-4px); box-shadow: 0 14px 30px rgba(0, 0, 0, .3); border-color: var(--accent); }
.action-tile.disabled { opacity: .6; }
.tile-icon { flex: none; display: grid; place-items: center; width: 46px; height: 46px; border-radius: 12px; font-size: 1.4rem; background: color-mix(in srgb, var(--accent) 16%, transparent); }
.tile-text { display: flex; flex-direction: column; min-width: 0; }
.tile-text span { font-size: .85rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.tile-arrow { margin-left: auto; font-size: 1.2rem; transition: transform .25s ease; }
a.action-tile:hover .tile-arrow { transform: translateX(4px); }

.shelf-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 34px; }
.shelf-head h2 { margin: 0; }
.on-bg-muted { color: var(--muted); font-size: .9rem; }
body.has-bg .on-bg-muted { color: rgba(255, 255, 255, .8); text-shadow: 0 1px 4px rgba(0, 0, 0, .6); }
.shelf { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 18px; margin-top: 14px; }
.shelf .book-card { transition: transform .35s cubic-bezier(.2, .7, .2, 1), box-shadow .35s ease; will-change: transform; }
.shelf .book-card:hover { box-shadow: -6px 0 0 -2px rgba(0, 0, 0, .25) inset, 0 24px 44px rgba(0, 0, 0, .45); }
.shelf .book-card-cover { aspect-ratio: 3 / 4; min-height: 0; padding: 18px; gap: 4px; }
.shelf .book-card-cover::before { background: linear-gradient(180deg, rgba(0, 0, 0, .1) 25%, rgba(0, 0, 0, .85)); transition: opacity .3s; }
.book-card-cover { background-size: cover; transition: background-size .6s ease; }
.book-card-icon { position: absolute !important; top: 14px; right: 14px; font-size: 1.4rem; background: rgba(0, 0, 0, .35); border-radius: 10px; padding: 4px 8px; }
.book-card-meta { font-size: .8rem; color: rgba(255, 255, 255, .82); }
.book-card-bar { display: block; height: 5px; border-radius: 99px; background: rgba(255, 255, 255, .25); overflow: hidden; margin-top: 8px; }
.book-card-bar > span { display: block; height: 100%; background: #f3d38a; border-radius: 99px; }
.book-card-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px 14px; }

@media (max-width: 1200px) {
  .shelf { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .action-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .home-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .shelf { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 72%; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 8px; }
  .shelf .book-card { scroll-snap-align: start; }
  .action-tiles { grid-template-columns: 1fr; }
  .hp-body { grid-template-columns: 1fr; justify-items: center; }
  .hp-stats { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .rise, body.has-bg #page-bg { animation: none; }
  .ring-fill { transition: none; }
}
.site-header .wrap { max-width: 1400px; }
.hp-chapters { display: flex; flex-direction: column; gap: 8px; margin-top: auto; }
.hp-ch { display: grid; grid-template-columns: 150px 1fr 42px; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-size: .88rem; padding: 4px 6px; border-radius: 8px; }
.hp-ch:hover { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
.hp-ch-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hp-ch-bar { position: relative; height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.hp-ch-bar > span { position: absolute; left: 0; top: 0; bottom: 0; width: var(--w); border-radius: 99px; animation: grow 1.2s cubic-bezier(.2, .7, .2, 1) both .3s; }
.hp-ch-bar .seen { background: color-mix(in srgb, var(--brand) 55%, transparent); }
.hp-ch-bar .mastered { background: var(--ok); }
.hp-ch-pct { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
@keyframes grow { from { width: 0; } }
.ring { width: 150px; height: 150px; }
.hp-body { grid-template-columns: 150px 1fr; }
.glass { background: var(--glass); }
.action-tile.glass { backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
@media (prefers-reduced-motion: reduce) { .hp-ch-bar > span { animation: none; } }
.home-grid > *, .action-tiles > *, .shelf > * { min-width: 0; }
@media (max-width: 900px) { .home-grid { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 640px) { .hp-ch { grid-template-columns: 120px 1fr 38px; } .exam-chips span { font-size: .8rem; } }
.hp-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } .hp-body > * { min-width: 0; } .hp-stats dt { overflow-wrap: anywhere; }
@media (max-width: 640px) { .hp-body { grid-template-columns: minmax(0, 1fr); justify-items: center; } .hp-stats { width: 100%; } }

/* =====================================================================
   ACCOUNT / PROGRESS CODES
   ===================================================================== */
.account-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-top: 16px; }
.account-card h2 { margin-top: 0; font-family: var(--serif-display); font-size: 1.7rem; }
.glass + .account-card, .notice + .account-grid { margin-top: 16px; }
.field-label { display: block; font-weight: 600; font-size: .9rem; margin: 12px 0 6px; }
.code-input { width: 100%; font: 600 1.35rem/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .12em; text-transform: uppercase;
  padding: 12px 14px; border-radius: 10px; border: 2px solid var(--border); background: var(--surface); color: var(--text); margin-bottom: 8px; }
.code-input:focus { border-color: var(--brand); outline: none; }
.form-error { color: var(--bad); min-height: 1.2em; margin: 4px 0 10px; font-size: .9rem; }
.code-display { font: 700 clamp(1.4rem, 5vw, 2.2rem)/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .14em; text-align: center;
  padding: 18px; border-radius: 12px; border: 2px dashed var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); user-select: all; overflow-wrap: anywhere; }
.code-display.small-code { font-size: 1.2rem; text-align: left; padding: 10px 14px; }
.new-code { max-width: 720px; }
.check { display: flex; gap: 10px; align-items: center; font-weight: 600; margin-top: 14px; }
.sync-line { display: flex; align-items: center; gap: 8px; }
.sync-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.sync-dot.synced { background: var(--ok); }
.sync-dot.saving { background: #f0b429; animation: pulse 1s ease-in-out infinite; }
.sync-dot.offline, .sync-dot.expired, .sync-dot.error { background: var(--bad); }
@keyframes pulse { 50% { opacity: .35; } }
.account-pill { display: inline-flex; align-items: center; gap: 7px; border: 1px solid rgba(255, 255, 255, .35); }
.expiry-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 14px; padding: 10px 14px;
  border-radius: 10px; background: var(--warn-bg); color: var(--text); box-shadow: var(--shadow); animation: rise .4s ease both; }
#banner:empty { display: none; }
@media (max-width: 760px) { .account-grid { grid-template-columns: 1fr; } }

/* =====================================================================
   BOOK-STYLE HEADER (leather cover, gold tooling, ribbon bookmarks)
   ===================================================================== */
.site-header, :root[data-theme="dark"] .site-header {
  color: #f4e4bc;
  background:
    radial-gradient(120% 140% at 50% -40%, rgba(255, 255, 255, .10), transparent 60%),
    repeating-linear-gradient(115deg, rgba(255, 255, 255, .025) 0 2px, transparent 2px 6px),
    linear-gradient(180deg, #5a1d1d 0%, #431414 55%, #341010 100%);
  border-bottom: 1px solid #1d0707;
  box-shadow: 0 1px 0 #c9a24a inset, 0 -1px 0 #c9a24a inset, 0 6px 18px rgba(0, 0, 0, .35);
  animation: coverIn .7s cubic-bezier(.2, .7, .2, 1) both;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .site-header { color: #f4e4bc; background:
    radial-gradient(120% 140% at 50% -40%, rgba(255, 255, 255, .10), transparent 60%),
    repeating-linear-gradient(115deg, rgba(255, 255, 255, .025) 0 2px, transparent 2px 6px),
    linear-gradient(180deg, #5a1d1d 0%, #431414 55%, #341010 100%); } }
/* gold tooled border running along the cover */
.site-header::before, .site-header::after { content: ""; position: absolute; left: 0; right: 0; height: 0; border-top: 1px dashed rgba(201, 162, 74, .55); pointer-events: none; }
.site-header::before { top: 5px; }
.site-header::after { bottom: 5px; }
@keyframes coverIn { from { transform: translateY(-100%); } to { transform: none; } }
.header-inner { min-height: 66px; position: relative; }

.brand { gap: 12px; }
.brand-text { font-family: var(--serif-display); font-size: 1.35rem; letter-spacing: .02em; color: #f7e7bd;
  text-shadow: 0 1px 0 rgba(0, 0, 0, .6), 0 0 1px #c9a24a; }
.brand-sub { font-family: var(--font); font-size: .66rem; letter-spacing: .28em; text-transform: uppercase; color: #c9a24a; opacity: 1; }
.brand-book svg { display: block; overflow: visible; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .5)); }
.bb-cover { fill: #c9a24a; }
.bb-page-left, .bb-page-right, .bb-flip { fill: #fbf3dc; }
.bb-flip { transform-origin: 32px 26px; animation: pageFlip 6s ease-in-out infinite; }
.bb-lines { stroke: #b9a27a; stroke-width: 1.4; stroke-linecap: round; fill: none; }
@keyframes pageFlip {
  0%, 70% { transform: scaleX(1); opacity: 1; }
  80% { transform: scaleX(0); opacity: .9; }
  90% { transform: scaleX(-1); opacity: 1; }
  100% { transform: scaleX(-1); opacity: 0; }
}
.brand:hover .bb-flip { animation-duration: 1.4s; }

.site-nav { gap: 2px; }
.site-nav > a { position: relative; color: #f1dfb2; font-family: var(--serif-text); font-size: .98rem; letter-spacing: .02em; padding: 10px 14px; border-radius: 6px; transition: color .2s, background .2s; }
.site-nav > a:hover, .site-nav > a.active { background: rgba(255, 255, 255, .07); color: #fff6dc; }
/* ribbon bookmark hanging from the active / hovered item */
.site-nav > a::after { content: ""; position: absolute; left: 50%; top: calc(100% + 1px); width: 16px; height: 0; transform: translateX(-50%);
  background: linear-gradient(90deg, #a11d2b, #d1293b 50%, #a11d2b); clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 72%, 0 100%);
  box-shadow: 0 2px 4px rgba(0, 0, 0, .35); transition: height .35s cubic-bezier(.2, .8, .2, 1.3); z-index: 3; }
.site-nav > a:hover::after { height: 16px; }
.site-nav > a.active::after { height: 26px; background: linear-gradient(90deg, #a8862e, #e7c56b 50%, #a8862e); }
.site-nav > a.account-pill { border: 1px solid rgba(201, 162, 74, .7); background: rgba(0, 0, 0, .18); font-family: var(--font); font-size: .9rem; margin-left: 6px; }
.site-nav > a.account-pill.signedOut, .site-nav > a.account-pill.expired { background: linear-gradient(180deg, #e7c56b, #c9a24a); color: #2a1407; border-color: #e7c56b; font-weight: 700; }
.site-nav > a.account-pill.signedOut .sync-dot, .site-nav > a.account-pill.expired .sync-dot { background: #7a1020; }
.theme-toggle, .nav-toggle { border-color: rgba(201, 162, 74, .6); color: #f1dfb2; }
@media (max-width: 760px) {
  .site-nav, :root[data-theme="dark"] .site-nav { background: linear-gradient(180deg, #431414, #2c0d0d); border-bottom: 2px solid #c9a24a; top: 66px; }
  .site-nav > a::after { display: none; }
  .site-nav > a.active { box-shadow: inset 4px 0 0 #e7c56b; }
}
@media (prefers-reduced-motion: reduce) { .site-header, .bb-flip { animation: none; } }

/* ---------- footer with About + Credits ---------- */
.book-footer { margin-top: 40px; padding: 18px 0 44px; border: 0; color: var(--muted); }
body.has-bg .book-footer { color: rgba(255, 255, 255, .8); }
.footer-inner { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.footer-ornament { color: var(--gold); font-size: 1.4rem; }
.footer-links { display: flex; gap: 22px; flex-wrap: wrap; justify-content: center; font-family: var(--serif-text); }
.footer-links a { color: inherit; text-decoration: none; border-bottom: 1px solid transparent; }
.footer-links a:hover { border-color: currentColor; }
body.has-bg .footer-links a { color: #fff; text-shadow: 0 1px 4px rgba(0, 0, 0, .7); }

/* ---------- new-code screen ---------- */
.big-code { font-size: clamp(2.6rem, 12vw, 4.2rem); letter-spacing: .32em; padding: 22px 10px 22px calc(10px + .32em); margin: 10px 0 14px; }
.code-warning { background: var(--bad-bg); border-radius: 10px; padding: 12px 14px; }
.save-steps { list-style: none; padding: 0; margin: 16px 0; display: grid; gap: 10px; counter-reset: step; }
.save-steps li { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.save-icon { font-size: 1.6rem; flex: none; }
.link-btn { background: none; border: 0; padding: 0; color: var(--brand); font: inherit; font-weight: 600; text-decoration: underline; cursor: pointer; }
.confirm-box { border-top: 1px solid var(--border); margin-top: 18px; padding-top: 16px; }
.confirm-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.code-input.short { width: 9.5em; letter-spacing: .3em; text-align: center; margin: 0; }

/* ---------- welcome dialog for new devices ---------- */
.welcome-dialog { border: 0; padding: 30px 28px 24px; max-width: min(480px, calc(100vw - 32px)); border-radius: 6px 16px 16px 6px; color: var(--ink);
  background: var(--paper); box-shadow: inset 14px 0 18px -14px rgba(0, 0, 0, .4), 0 30px 80px rgba(0, 0, 0, .45); text-align: center; }
.welcome-dialog[open] { animation: turnIn .55s cubic-bezier(.2, .7, .2, 1) both; }
.welcome-dialog::backdrop { background: rgba(12, 8, 6, .62); backdrop-filter: blur(3px); }
.welcome-dialog h2 { font-family: var(--serif-display); font-size: 2rem; margin: 10px 0 8px; }
.welcome-points { text-align: left; margin: 12px auto 14px; padding-left: 1.2em; max-width: 34ch; }
.welcome-points li { margin: 4px 0; }
.welcome-actions { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.welcome-actions .link-btn { color: var(--ink-muted); margin-top: 2px; }
.welcome-book { position: relative; width: 74px; height: 50px; margin: 0 auto; }
.welcome-book span { position: absolute; top: 0; width: 37px; height: 50px; background: #fffaf0; border: 2px solid var(--gold); }
.welcome-book span:first-child { left: 0; border-radius: 6px 0 0 6px; }
.welcome-book span:last-child { right: 0; border-radius: 0 6px 6px 0; transform-origin: left center; animation: bookOpen 2.4s ease-in-out infinite alternate; }
@keyframes bookOpen { from { transform: perspective(200px) rotateY(-70deg); } to { transform: perspective(200px) rotateY(0); } }
.site-nav > a.account-pill::after { display: none; }

/* =====================================================================
   LANDING PAGE
   ===================================================================== */
body { overflow-x: clip; }
.leather {
  color: #f4e4bc;
  background:
    radial-gradient(90% 120% at 15% 0%, rgba(255, 255, 255, .10), transparent 55%),
    radial-gradient(70% 90% at 100% 100%, rgba(0, 0, 0, .35), transparent 60%),
    repeating-linear-gradient(115deg, rgba(255, 255, 255, .022) 0 2px, transparent 2px 6px),
    linear-gradient(160deg, #6a2222 0%, #4a1616 45%, #2c0c0c 100%);
}
.landing { margin-top: 0; }
.landing > .leather, .landing > .lp-facts { width: 100vw; margin-left: calc(50% - 50vw); }
.lp-btn-gold { background: linear-gradient(180deg, #f1d488, #c9a24a); color: #2a1407; border-color: #e7c56b; box-shadow: 0 6px 18px rgba(0, 0, 0, .3); }
.lp-btn-gold:hover { filter: brightness(1.06); border-color: #fff0c2; }
.lp-btn-ghost { background: rgba(255, 255, 255, .06); color: #f7e7bd; border-color: rgba(231, 197, 107, .6); }
.lp-btn-ghost:hover { background: rgba(255, 255, 255, .14); border-color: #e7c56b; }
.lp-small { font-size: .85rem; color: rgba(244, 228, 188, .75); margin-top: 14px; }
.lp-small a { color: #f1d488; }
.lp-error { color: #ffb4a8; }

/* hero */
.lp-hero { position: relative; overflow: hidden; padding: clamp(40px, 7vw, 90px) 16px clamp(70px, 9vw, 110px);
  box-shadow: inset 0 1px 0 #c9a24a, inset 0 -1px 0 #c9a24a; }
.lp-hero::before { content: ""; position: absolute; inset: 14px; border: 1px solid rgba(201, 162, 74, .45); border-radius: 4px; pointer-events: none;
  box-shadow: inset 0 0 0 5px rgba(201, 162, 74, .08), inset 0 0 0 6px rgba(201, 162, 74, .3); }
.lp-hero-inner { position: relative; max-width: 1280px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr); gap: clamp(24px, 5vw, 70px); align-items: center; }
.lp-kicker { text-transform: uppercase; letter-spacing: .3em; font-size: .78rem; color: #e7c56b; display: flex; gap: 12px; align-items: center; }
.lp-kicker span { font-size: .7rem; }
.lp-title { font-family: var(--serif-display); font-weight: 700; font-size: clamp(2.7rem, 6.4vw, 5.2rem); line-height: .98; margin: 16px 0 18px; color: #fbf0d2;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .45), 0 0 1px #c9a24a; animation: rise .8s cubic-bezier(.2, .7, .2, 1) both .1s; }
.lp-title em { font-style: italic; background: linear-gradient(180deg, #f6dc94, #c9a24a 70%); -webkit-background-clip: text; background-clip: text; color: transparent; }
.lp-lead { font-family: var(--serif-text); font-size: clamp(1.05rem, 1.6vw, 1.25rem); max-width: 54ch; color: rgba(251, 240, 210, .9); animation: rise .8s ease both .25s; }
.lp-hero .btn-row { animation: rise .8s ease both .4s; }
.lp-scroll { position: absolute; left: 50%; bottom: 26px; transform: translateX(-50%); color: #e7c56b; text-decoration: none; font-size: .9rem; letter-spacing: .1em;
  animation: bob 2.2s ease-in-out infinite; }
@keyframes bob { 50% { transform: translate(-50%, 6px); } }

/* 3D book whose cover swings open to show the contents page */
.lp-book { position: relative; width: min(340px, 78vw); aspect-ratio: 3 / 4; margin: 0 auto; perspective: 1800px; }
.lp-book-pages, .lp-book-cover { position: absolute; inset: 0; border-radius: 4px 12px 12px 4px; }
.lp-book-pages { background: var(--paper); color: var(--ink); padding: 34px 30px; box-shadow: inset 16px 0 20px -14px rgba(0, 0, 0, .35), 6px 6px 0 -2px #e9dfc8, 10px 10px 0 -4px #d9cdb0, 0 30px 60px rgba(0, 0, 0, .5);
  font-family: var(--serif-text); display: flex; flex-direction: column; gap: 10px; }
:root[data-theme="dark"] .lp-book-pages { background: #fbf6ea; color: #2a2418; }
.lp-page-title { font-family: var(--serif-display); font-size: 1.9rem; font-weight: 700; border-bottom: 1px solid #e0d3b3; padding-bottom: 6px; margin-bottom: 4px; }
.lp-page-row { display: flex; gap: 12px; font-size: 1.02rem; border-bottom: 1px dotted #d9cdb0; padding-bottom: 6px; }
.lp-page-row span:first-child { color: #b8892f; font-family: var(--serif-display); font-weight: 700; min-width: 2em; }
.lp-page-foot { margin-top: auto; font-style: italic; font-size: .85rem; color: #6b604c; text-align: center; }
.lp-book-cover { transform-origin: left center; transform-style: preserve-3d; backface-visibility: hidden;
  background: radial-gradient(90% 70% at 30% 20%, rgba(255, 255, 255, .12), transparent 60%), repeating-linear-gradient(115deg, rgba(255, 255, 255, .03) 0 2px, transparent 2px 6px), linear-gradient(160deg, #7a2828, #4a1616 60%, #2e0d0d);
  box-shadow: inset 10px 0 14px -6px rgba(0, 0, 0, .55), inset -2px 0 0 rgba(255, 255, 255, .06), 0 30px 60px rgba(0, 0, 0, .5);
  padding: 22px; animation: coverOpen 5.5s cubic-bezier(.45, .05, .25, 1) 1s infinite alternate; }
.lp-cover-frame { height: 100%; border: 2px solid #c9a24a; outline: 1px solid rgba(201, 162, 74, .5); outline-offset: 5px; border-radius: 3px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 12px; }
.lp-cover-crest { color: #e7c56b; font-size: 2.2rem; }
.lp-cover-title { font-family: var(--serif-display); font-weight: 700; font-size: clamp(1.7rem, 4vw, 2.3rem); line-height: 1.05; color: #f6dc94; text-shadow: 0 1px 0 rgba(0, 0, 0, .6); }
.lp-cover-rule { width: 60%; height: 1px; background: linear-gradient(90deg, transparent, #c9a24a, transparent); }
.lp-cover-sub { text-transform: uppercase; letter-spacing: .3em; font-size: .72rem; color: #e7c56b; }
.lp-book-shadow { position: absolute; left: 6%; right: -4%; bottom: -26px; height: 26px; background: radial-gradient(closest-side, rgba(0, 0, 0, .45), transparent); filter: blur(4px); }
@keyframes coverOpen { 0%, 25% { transform: rotateY(0); } 75%, 100% { transform: rotateY(-160deg); } }

/* facts strip */
.lp-facts { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); background: var(--paper); color: var(--ink); border-bottom: 1px solid var(--paper-edge);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .08); padding: 0 max(16px, calc(50vw - 640px)); }
.lp-facts div { padding: 26px 12px; text-align: center; border-right: 1px dashed var(--paper-edge); }
.lp-facts div:last-child { border-right: 0; }
.lp-facts b { display: block; font-family: var(--serif-display); font-size: clamp(1.7rem, 3vw, 2.4rem); color: #8a1f1f; line-height: 1; }
:root[data-theme="dark"] .lp-facts b { color: var(--gold); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .lp-facts b { color: var(--gold); } }
.lp-facts span { font-size: .85rem; color: var(--ink-muted); }

/* generic sections */
.lp-section { padding: clamp(50px, 7vw, 90px) 0 0; }
.lp-section-head { text-align: center; margin-bottom: 30px; }
.lp-section-head h2 { font-family: var(--serif-display); font-size: clamp(2rem, 4.4vw, 3rem); margin: 6px 0 0; }
.lp-features { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.lp-feature { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 24px; box-shadow: var(--shadow); transition: transform .3s ease, box-shadow .3s ease; }
.lp-feature:hover { transform: translateY(-5px); box-shadow: 0 18px 36px rgba(0, 0, 0, .14); }
.lp-feature-icon { display: grid; place-items: center; width: 54px; height: 54px; border-radius: 14px; font-size: 1.6rem;
  background: linear-gradient(160deg, #6a2222, #3a1010); box-shadow: inset 0 0 0 1px #c9a24a; margin-bottom: 14px; }
.lp-feature h3 { margin: 0 0 6px; font-family: var(--serif-display); font-size: 1.5rem; }
.lp-feature p { margin: 0; color: var(--muted); }

.lp-steps { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; position: relative; }
.lp-steps::before { content: ""; position: absolute; top: 34px; left: 16%; right: 16%; border-top: 2px dashed var(--gold); opacity: .5; }
.lp-steps li { position: relative; text-align: center; padding: 0 12px; }
.lp-medal { display: grid; place-items: center; width: 68px; height: 68px; margin: 0 auto 14px; border-radius: 50%; font-family: var(--serif-display); font-weight: 700; font-size: 1.5rem;
  color: #2a1407; background: radial-gradient(circle at 35% 30%, #fff0c2, #e7c56b 40%, #a8862e); box-shadow: 0 0 0 4px var(--bg), 0 0 0 5px #c9a24a, 0 8px 18px rgba(0, 0, 0, .25); position: relative; }
.lp-steps h3 { font-family: var(--serif-display); font-size: 1.5rem; margin: 0 0 6px; }
.lp-steps p { color: var(--muted); margin: 0 auto; max-width: 34ch; }

.lp-shelf { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; }
.lp-spine { position: relative; display: flex; flex-direction: column; justify-content: flex-end; aspect-ratio: 2 / 3; border-radius: 4px 12px 12px 4px; overflow: hidden; text-decoration: none; color: #fff;
  box-shadow: inset 12px 0 14px -8px rgba(0, 0, 0, .6), 0 14px 30px rgba(0, 0, 0, .25); transition: transform .35s cubic-bezier(.2, .7, .2, 1), box-shadow .35s; }
.lp-spine:hover { transform: translateY(-10px) rotate(-1deg); box-shadow: inset 12px 0 14px -8px rgba(0, 0, 0, .6), 0 26px 44px rgba(0, 0, 0, .35); }
.lp-spine-img { position: absolute; inset: 0; background: #3a1010 center / cover no-repeat; transition: transform .6s ease; }
.lp-spine:hover .lp-spine-img { transform: scale(1.07); }
.lp-spine::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0, 0, 0, 0) 30%, rgba(30, 6, 6, .92)); }
.lp-spine-text { position: relative; z-index: 1; padding: 16px; display: flex; flex-direction: column; gap: 3px; }
.lp-spine-text small { color: #e7c56b; letter-spacing: .2em; text-transform: uppercase; font-size: .68rem; }
.lp-spine-text b { font-family: var(--serif-display); font-size: 1.35rem; line-height: 1.1; }
.lp-spine-text em { font-style: normal; font-size: .78rem; color: rgba(255, 255, 255, .8); }
.lp-note { text-align: center; color: var(--muted); font-size: .9rem; margin-top: 14px; }

.lp-faq { max-width: 820px; margin: 0 auto; display: grid; gap: 10px; }
.lp-faq details { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 0 18px; box-shadow: var(--shadow); }
.lp-faq summary { cursor: pointer; list-style: none; padding: 16px 30px 16px 0; font-weight: 600; position: relative; font-size: 1.05rem; }
.lp-faq summary::-webkit-details-marker { display: none; }
.lp-faq summary::after { content: "+"; position: absolute; right: 0; top: 50%; transform: translateY(-50%); font-size: 1.4rem; color: var(--gold); transition: transform .25s; }
.lp-faq details[open] summary::after { transform: translateY(-50%) rotate(45deg); }
.lp-faq details p { margin: 0 0 16px; color: var(--muted); }

.lp-cta { margin-top: clamp(50px, 7vw, 90px); padding: clamp(46px, 6vw, 80px) 16px; text-align: center; box-shadow: inset 0 1px 0 #c9a24a, inset 0 -1px 0 #c9a24a; }
.lp-cta-inner { max-width: 760px; margin: 0 auto; }
.lp-cta h2 { font-family: var(--serif-display); font-size: clamp(2.2rem, 5vw, 3.4rem); margin: 6px 0 10px; color: #fbf0d2; }
.lp-cta p { color: rgba(251, 240, 210, .88); font-size: 1.1rem; }
.lp-cta .btn-row { justify-content: center; }
main:has(.landing) + .book-footer { margin-top: 0; }

/* scroll reveal */
.landing .reveal { opacity: 0; transform: translateY(26px); transition: opacity .7s ease, transform .7s cubic-bezier(.2, .7, .2, 1); transition-delay: calc(var(--i, 0) * 90ms); }
.landing .reveal.in { opacity: 1; transform: none; }

@media (max-width: 1000px) {
  .lp-hero-inner { grid-template-columns: 1fr; text-align: center; }
  .lp-kicker { justify-content: center; }
  .lp-lead { margin-left: auto; margin-right: auto; }
  .lp-hero .btn-row { justify-content: center; }
  .lp-features { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lp-shelf { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .lp-facts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .lp-facts div:nth-child(3) { border-right: 0; }
}
@media (max-width: 640px) {
  .lp-features, .lp-steps { grid-template-columns: 1fr; }
  .lp-steps::before { display: none; }
  .lp-shelf { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 62%; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 10px; }
  .lp-spine { scroll-snap-align: start; }
  .lp-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lp-facts div { border-right: 0; border-bottom: 1px dashed var(--paper-edge); }
  .lp-hero::before { inset: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .lp-book-cover { animation: none; transform: rotateY(-160deg); }
  .lp-title, .lp-lead, .lp-hero .btn-row, .lp-scroll { animation: none; }
  .landing .reveal { opacity: 1; transform: none; transition: none; }
}
.lp-title em { background: none; color: #f1d488; -webkit-text-fill-color: #f1d488; }
@media (max-width: 640px) { .lp-kicker { letter-spacing: .16em; font-size: .7rem; } .lp-kicker span { display: none; } }

/* =====================================================================
   READING SETTINGS (Aa panel): themes, size, typeface, spacing, width
   ===================================================================== */
.prose { font-size: calc(1.08rem * var(--read-scale, 1)); }
.prose h4 { font-size: 1.35em; }
.paper { filter: brightness(var(--read-brightness, 1)); transition: background-color .3s, color .3s; }
/* themes (Calm = the default book look, following light/dark mode) */
html[data-reading-theme="original"] .paper { --paper: #ffffff; --ink: #1c1c1e; --ink-muted: #6e6e73; --paper-edge: #e3e3e8; --gold: #a8741a; background-image: none; }
html[data-reading-theme="quiet"] .paper { --paper: #4a4a4c; --ink: #d6d6db; --ink-muted: #a7a7ac; --paper-edge: #5f5f63; --gold: #e0b45e; background-image: none; }
html[data-reading-theme="paper"] .paper { --paper: #ececee; --ink: #1d1d1f; --ink-muted: #5f5f64; --paper-edge: #d4d4d9; --gold: #8f6a20; background-image: none; }
html[data-reading-theme="bold"] .paper { --paper: #ffffff; --ink: #000000; --ink-muted: #3a3a3c; --paper-edge: #dcdce0; --gold: #8a5a00; background-image: none; }
html[data-reading-theme="focus"] .paper { --paper: #fffbf2; --ink: #1d1b16; --ink-muted: #5f5a4e; --paper-edge: #ece4d1; --gold: #9a7224; background-image: none; }
html[data-reading-theme="quiet"] .prose .note-figure img { border-color: #5f5f63; }
/* typeface */
html[data-reading-font="sans"] .prose { font-family: var(--font); }
html[data-reading-font="easy"] .prose { font-family: "Atkinson Hyperlegible", Verdana, Tahoma, sans-serif; letter-spacing: .01em; }
html[data-reading-font="serif"] .prose { font-family: var(--serif-text); }
html[data-reading-bold] .prose { font-weight: 600; }
html[data-reading-bold] .prose b, html[data-reading-bold] .prose strong { font-weight: 800; }
/* spacing, alignment, width */
html[data-reading-spacing="compact"] .prose { line-height: 1.5; }
html[data-reading-spacing="relaxed"] .prose { line-height: 2.05; }
html[data-reading-justify] .prose p, html[data-reading-justify] .prose li { text-align: justify; hyphens: auto; -webkit-hyphens: auto; }
html[data-reading-width="wide"] .book { max-width: 1240px; }
html[data-reading-width="wide"] .prose p, html[data-reading-width="wide"] .prose li { max-width: none; }
/* high contrast */
html[data-reading-contrast] .paper { --ink: #000; --ink-muted: #1a1a1a; }
html[data-reading-contrast][data-reading-theme="quiet"] .paper, html[data-reading-contrast][data-theme="dark"][data-reading-theme="calm"] .paper { --ink: #fff; --ink-muted: #f0f0f0; }
@media (prefers-color-scheme: dark) { html[data-reading-contrast]:not([data-theme="light"])[data-reading-theme="calm"] .paper { --ink: #fff; --ink-muted: #f0f0f0; } }

/* floating Aa button */
.aa-btn { position: fixed; right: 18px; bottom: 22px; z-index: 30; width: 58px; height: 58px; border-radius: 50%; cursor: pointer;
  font-family: var(--serif-display); font-weight: 700; font-size: 1.45rem; color: #f6dc94;
  background: radial-gradient(circle at 35% 30%, #7a2828, #431414 70%); border: 2px solid #c9a24a;
  box-shadow: 0 0 0 4px rgba(201, 162, 74, .18), 0 10px 24px rgba(0, 0, 0, .35); transition: transform .2s ease; animation: rise .5s ease both .3s; }
.aa-btn:hover { transform: scale(1.06); }
body:has(.aa-btn) .bg-credit { right: 86px; }

/* settings panel */
.reader-settings { position: fixed; right: 16px; bottom: 92px; z-index: 40; width: min(390px, calc(100vw - 24px)); max-height: calc(100vh - 120px); overflow: auto;
  padding: 18px 18px 20px; border-radius: 30px; color: #1c1a16; background: rgba(226, 219, 203, .97); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(0, 0, 0, .08); box-shadow: 0 24px 60px rgba(0, 0, 0, .35); animation: rsIn .28s cubic-bezier(.2, .8, .2, 1) both; font-family: var(--font); }
@keyframes rsIn { from { opacity: 0; transform: translateY(14px) scale(.97); } to { opacity: 1; transform: none; } }
.rs-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.rs-head h2 { margin: 0; font-size: 1.25rem; font-weight: 700; }
.rs-close { width: 44px; height: 44px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, .1); background: #f3eee2; font-size: 1.1rem; cursor: pointer; color: inherit; }
.rs-row { display: grid; grid-template-columns: 1.4fr 1fr; gap: 10px; }
.rs-pill { display: flex; border-radius: 999px; background: rgba(0, 0, 0, .07); overflow: hidden; }
.rs-pill button { flex: 1; height: 50px; border: 0; background: transparent; cursor: pointer; color: inherit; font-weight: 700; display: grid; place-items: center; }
.rs-pill button + button { border-left: 1px solid rgba(0, 0, 0, .12); }
.rs-pill button:hover:not([disabled]) { background: rgba(0, 0, 0, .06); }
.rs-pill button[disabled] { opacity: .35; cursor: default; }
.rs-toggles button { border-left: 0 !important; }
.rs-toggles button[aria-pressed="true"] { background: rgba(0, 0, 0, .14); }
.rs-bright { display: flex; align-items: center; gap: 10px; margin: 18px 4px; font-size: 1rem; }
.rs-big-sun { font-size: 1.35rem; }
.rs-bright input { flex: 1; accent-color: #1c1a16; height: 6px; }
.rs-themes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.rs-theme { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: 92px; border-radius: 20px; border: 2px solid transparent; cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .08); transition: transform .15s; }
.rs-theme:hover { transform: translateY(-2px); }
.rs-theme.selected { border-color: #1c1a16; box-shadow: 0 0 0 2px rgba(28, 26, 22, .15); }
.rs-aa { font-size: 1.8rem; line-height: 1; }
.rs-name { font-size: .9rem; }
.rs-theme-original { background: #fff; color: #1c1c1e; font-family: var(--font); }
.rs-theme-quiet { background: #4a4a4c; color: #c7c7cc; font-family: var(--serif-text); }
.rs-theme-paper { background: #ececee; color: #1d1d1f; font-family: var(--serif-text); }
.rs-theme-bold { background: #fff; color: #000; font-family: var(--font); font-weight: 800; }
.rs-theme-calm { background: #efe3cd; color: #3b2f22; font-family: var(--serif-text); }
.rs-theme-focus { background: #fffbf2; color: #1d1b16; font-family: var(--font); }
.rs-custom-btn { width: 100%; margin-top: 14px; height: 52px; border-radius: 999px; border: 0; background: rgba(0, 0, 0, .07); font: 700 1.05rem var(--font); color: inherit; cursor: pointer; }
.rs-custom-btn:hover { background: rgba(0, 0, 0, .11); }
.rs-custom { margin-top: 14px; display: grid; gap: 12px; }
.rs-field > span { display: block; font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; opacity: .75; }
.rs-seg { display: flex; flex-wrap: wrap; gap: 6px; }
.rs-seg button { flex: 1; min-width: 70px; padding: 9px 8px; border-radius: 12px; border: 1px solid rgba(0, 0, 0, .12); background: #f3eee2; color: inherit; cursor: pointer; font: 600 .88rem var(--font); }
.rs-seg button[aria-pressed="true"] { background: #1c1a16; color: #f3eee2; border-color: #1c1a16; }
.rs-seg button[data-font="easy"] { font-family: "Atkinson Hyperlegible", Verdana, sans-serif; }
.rs-seg button[data-font="serif"] { font-family: var(--serif-text); }
.rs-switch { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.rs-switch input { width: 20px; height: 20px; accent-color: #1c1a16; }
.rs-reset { justify-self: start; background: none; border: 0; text-decoration: underline; color: inherit; cursor: pointer; font: inherit; opacity: .8; padding: 0; }
@media (max-width: 600px) {
  .reader-settings { left: 8px; right: 8px; bottom: 8px; width: auto; border-radius: 28px; max-height: 80vh; }
  .aa-btn { right: 14px; bottom: 16px; width: 54px; height: 54px; }
}
@media (prefers-reduced-motion: reduce) { .reader-settings, .aa-btn { animation: none; } }

/* =====================================================================
   QUIZ NAVIGATION + ANSWERED GRID
   ===================================================================== */
.check-row { margin-top: 16px; }
.quiz-nav { display: flex; justify-content: space-between; align-items: center; gap: 24px; margin-top: 20px; }
.quiz-nav .btn { min-width: 140px; min-height: 50px; }
.quiz-prev[disabled] { visibility: hidden; }
.quiz-sub { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
@media (max-width: 480px) { .quiz-nav .btn { min-width: 0; flex: 1; } .quiz-nav { gap: 16px; } }

.dots-wrap { margin: 16px 0 6px; padding: 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); }
.dots { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 8px; margin: 0; }
.dots button { position: relative; width: auto; height: 44px; border-radius: 10px; font-size: .95rem; font-weight: 700; padding: 0; cursor: pointer; transition: transform .15s; }
.dots button:hover { transform: translateY(-2px); }
.dots button i { position: absolute; top: 2px; right: 5px; font-size: .62rem; font-style: normal; line-height: 1; }
/* not answered: dashed outline, hollow */
.dots button.todo { background: transparent; color: var(--muted); border: 2px dashed color-mix(in srgb, var(--muted) 70%, transparent); }
/* answered (exam): solid filled */
.dots button.answered { background: var(--brand); color: var(--brand-ink); border: 2px solid var(--brand); }
.dots button.ok { background: var(--ok); color: #fff; border: 2px solid var(--ok); }
.dots button.bad { background: var(--bad); color: #fff; border: 2px solid var(--bad); }
.dots button.current { outline: 3px solid #d4a63a; outline-offset: 2px; }
.dots-legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 12px; font-size: .88rem; color: var(--muted); }
.dots-legend .lg { display: inline-flex; align-items: center; gap: 6px; }
.dots-legend .lg::before { content: ""; width: 14px; height: 14px; border-radius: 4px; }
.dots-legend .answered::before { background: var(--brand); }
.dots-legend .ok::before { background: var(--ok); }
.dots-legend .bad::before { background: var(--bad); }
.dots-legend .todo::before { border: 2px dashed var(--muted); }

/* =====================================================================
   BACKGROUND CREDIT: a line at the very bottom of the page (not floating)
   ===================================================================== */
.bg-credit, body:has(.aa-btn) .bg-credit { position: static; max-width: 1100px; margin: 0 auto; padding: 0 16px 24px; background: none; border-radius: 0;
  text-align: center; font-size: .72rem; color: var(--muted); }
body.has-bg .bg-credit { color: rgba(255, 255, 255, .72); }
body.has-bg .bg-credit a { color: #fff; }
.bg-credit a { color: inherit; }

/* =====================================================================
   SHARE RESULT
   ===================================================================== */
.btn-share { background: linear-gradient(180deg, #f1d488, #c9a24a); color: #2a1407; border-color: #e7c56b; }
.btn-share:hover { filter: brightness(1.05); border-color: #fff0c2; }
.share-dialog { position: relative; border: 0; padding: 22px; width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 24px); overflow: auto; border-radius: 18px;
  background: var(--surface); color: var(--text); box-shadow: 0 30px 80px rgba(0, 0, 0, .45); }
.share-dialog[open] { animation: rsIn .3s cubic-bezier(.2, .8, .2, 1) both; }
.share-dialog::backdrop { background: rgba(12, 8, 6, .65); backdrop-filter: blur(3px); }
.share-dialog h2 { margin: 0 0 12px; font-family: var(--serif-display); font-size: 1.8rem; }
.share-preview-img { display: block; width: 100%; border-radius: 10px; box-shadow: 0 10px 26px rgba(0, 0, 0, .3); }
.share-loading { padding: 80px 0; text-align: center; color: var(--muted); }
.share-text { font-size: .9rem; color: var(--muted); background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin: 14px 0; }
.share-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.share-actions [data-share] { grid-column: 1 / -1; }
.share-close { position: absolute; top: 14px; right: 14px; width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer; font-size: 1rem; }
body.has-bg .quiz-meta { color: rgba(255, 255, 255, .88); text-shadow: 0 1px 4px rgba(0, 0, 0, .6); }
body.has-bg main > p.small.muted { color: rgba(255, 255, 255, .78); text-shadow: 0 1px 4px rgba(0, 0, 0, .6); }

/* =====================================================================
   QUIZ SET-UP (compact dropdowns)
   ===================================================================== */
.quiz-setup { margin-top: 16px; }
.qs-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 20px; }
.qs-field { display: flex; flex-direction: column; gap: 6px; }
.qs-label { font-weight: 700; font-size: .95rem; }
.qs-select { appearance: none; -webkit-appearance: none; width: 100%; min-height: 52px; padding: 12px 44px 12px 14px; border-radius: 12px;
  border: 2px solid var(--border); background-color: var(--surface); color: var(--text); font: 600 1rem var(--font); cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 22px) 52%, calc(100% - 16px) 52%; background-size: 6px 6px; background-repeat: no-repeat; transition: border-color .2s; }
.qs-select:hover, .qs-select:focus { border-color: var(--brand); outline: none; }
.qs-select:focus-visible { box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 35%, transparent); }
.qs-help { color: var(--muted); font-size: .85rem; min-height: 1.2em; }
.qs-start { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }
.qs-summary { margin: 0; color: var(--muted); }
.qs-summary b { color: var(--text); }
@media (max-width: 640px) {
  .qs-grid { grid-template-columns: 1fr; gap: 14px; }
  .qs-start { flex-direction: column; align-items: stretch; text-align: center; }
  .qs-start .btn { width: 100%; }
  .quiz-setup { padding: 18px 16px; }
}
@media (max-width: 640px) {
  .qs-title { padding: 16px 18px; }
  .qs-title h1 { font-size: 1.9rem; margin-bottom: 4px; }
  .qs-title p { font-size: .92rem; }
  .qs-grid { gap: 10px; }
  .qs-help { font-size: .8rem; }
  .qs-start { position: sticky; bottom: 0; z-index: 5; margin: 16px -16px -18px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: var(--surface); border-radius: 0 0 var(--radius) var(--radius); box-shadow: 0 -8px 20px rgba(0, 0, 0, .12); gap: 8px; }
  .qs-summary { font-size: .9rem; }
}
.share-toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); z-index: 60; max-width: min(460px, calc(100vw - 32px));
  padding: 12px 16px; border-radius: 12px; background: #1c1a16; color: #fbf0d2; box-shadow: 0 12px 30px rgba(0, 0, 0, .35); font-size: .92rem; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; }
.share-toast.show { opacity: 1; transform: translate(-50%, 0); }

/* =====================================================================
   MODERN MOBILE LAYER: bottom tab bar, decluttered phone layouts, motion
   ===================================================================== */
:root { --ease-out: cubic-bezier(.22, 1, .36, 1); --ease-spring: cubic-bezier(.34, 1.56, .64, 1); --tabbar-h: 0px; }

/* header: nav pushed right, round theme toggle at the end */
.site-nav { margin-left: auto; }
.theme-toggle { flex: none; display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border-radius: 50%; transition: transform .45s var(--ease-spring), background-color .2s; }
.theme-toggle:hover { background: rgba(255, 255, 255, .08); }
.theme-toggle:active { transform: rotate(180deg) scale(.9); }

/* shared tap feedback */
.btn, .option, .action-tile, .book-card-cover, .lp-spine, .toc-row, .hp-ch, .dots button, .tabbar a { -webkit-tap-highlight-color: transparent; }
.btn { transition: transform .18s var(--ease-out), filter .2s, background-color .2s, border-color .2s, box-shadow .2s; }
.btn:active:not([disabled]) { transform: scale(.96); }
.option { transition: border-color .2s, background-color .25s, transform .18s var(--ease-out); }
.option:active:not([disabled]) { transform: scale(.985); }
.action-tile:active, .lp-spine:active { transform: scale(.97); }

/* quiz motion: slide between questions, react when an answer is checked */
@keyframes qNext { from { opacity: 0; transform: translateX(32px); } }
@keyframes qPrev { from { opacity: 0; transform: translateX(-32px); } }
@keyframes pop { 40% { transform: scale(1.035); } }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
@keyframes feedIn { from { opacity: 0; transform: translateY(-6px); } }
.question-card.q-next { animation: qNext .4s var(--ease-out) both; }
.question-card.q-prev { animation: qPrev .4s var(--ease-out) both; }
.question-card:not(.q-next):not(.q-prev) .option.correct { animation: pop .5s var(--ease-spring); }
.question-card:not(.q-next):not(.q-prev) .option.wrong { animation: shake .4s ease; }
.question-card:not(.q-next):not(.q-prev) .feedback { animation: feedIn .4s var(--ease-out) both; }

/* page changes: header and tab bar stay put, content cross-fades */
.site-header { view-transition-name: site-header; }
.tabbar { view-transition-name: tabbar; }
::view-transition-old(root) { animation: vtOut .18s ease both; }
::view-transition-new(root) { animation: vtIn .32s var(--ease-out) both; }
@keyframes vtOut { to { opacity: 0; } }
@keyframes vtIn { from { opacity: 0; } }

/* ---------- bottom tab bar ---------- */
.tabbar { display: none; }
@media (max-width: 760px) {
  :root { --tabbar-h: calc(62px + env(safe-area-inset-bottom)); }
  body { padding-bottom: var(--tabbar-h); }
  body.in-quiz { padding-bottom: 0; }

  .site-nav { display: none !important; }
  .header-inner { min-height: 56px; }
  .site-header::before { top: 4px; }
  .site-header::after { bottom: 4px; }
  .brand-book svg { width: 38px; height: 28px; }
  .brand-text { font-size: 1.18rem; line-height: 1.15; }
  .brand-sub { font-size: .56rem; letter-spacing: .24em; }
  .theme-toggle { margin: 0; width: 38px; height: 38px; }

  .tabbar { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
    height: var(--tabbar-h); padding: 6px 6px env(safe-area-inset-bottom);
    background: rgba(40, 11, 11, .9); backdrop-filter: saturate(160%) blur(18px); -webkit-backdrop-filter: saturate(160%) blur(18px);
    border-top: 1px solid rgba(201, 162, 74, .45); box-shadow: 0 -10px 30px rgba(0, 0, 0, .22); transition: transform .4s var(--ease-out); }
  .tabbar a { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: rgba(241, 223, 178, .68); text-decoration: none; font-size: .68rem; font-weight: 600; letter-spacing: .02em; transition: color .2s; }
  .tabbar a::before { content: ""; position: absolute; top: 3px; left: 50%; width: 54px; height: 30px; margin-left: -27px; border-radius: 99px;
    background: rgba(231, 197, 107, .2); opacity: 0; transform: scaleX(.4); transition: transform .4s var(--ease-spring), opacity .2s; }
  .tabbar svg { position: relative; width: 24px; height: 24px; margin-top: 2px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
    transition: transform .35s var(--ease-spring); }
  .tabbar span { position: relative; }
  .tabbar a.active { color: #f6dc94; }
  .tabbar a.active::before { opacity: 1; transform: none; }
  .tabbar a:active svg { transform: scale(.85); }
  .tabbar .sync-dot { position: absolute; top: 5px; left: calc(50% + 7px); width: 9px; height: 9px; box-shadow: 0 0 0 2px #2c0c0c; display: none; }
  .tabbar .sync-dot.synced, .tabbar .sync-dot.saving, .tabbar .sync-dot.offline, .tabbar .sync-dot.expired, .tabbar .sync-dot.error { display: block; }
  body.in-quiz .tabbar { transform: translateY(110%); }

  /* floating things sit above the tab bar */
  .aa-btn { bottom: calc(var(--tabbar-h) + 14px); }
  .reader-settings { bottom: calc(var(--tabbar-h) + 8px); max-height: calc(100svh - var(--tabbar-h) - 80px); }
  .share-toast { bottom: calc(var(--tabbar-h) + 14px); }

  /* lighter page furniture */
  .turn-in { animation-name: rise; animation-duration: .5s; }
  .glass { padding: 18px; margin-top: 14px; }
  .glass h1 { font-size: 1.9rem; margin-bottom: .2em; }
  .book-footer { margin-top: 28px; padding: 10px 0 18px; }
  .footer-ornament { display: none; }
  .footer-links { gap: 6px 18px; font-size: .88rem; }
  .footer-links a[href="#/account"] { display: none; }
  .bg-credit, body:has(.aa-btn) .bg-credit { padding-bottom: 14px; font-size: .66rem; }
}

@media (max-width: 640px) {
  .wrap { padding: 0 14px; }

  /* ---------- home ---------- */
  .home-grid { gap: 12px; margin-top: 14px; }
  .home-hero { padding: 22px 20px; }
  .home-hero h1 { font-size: 2.35rem; }
  .lead { font-size: 1rem; }
  .home-hero .btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .home-hero .btn-lg { padding: 12px 8px; font-size: .95rem; }
  .exam-chips { flex-wrap: nowrap; overflow-x: auto; margin: 16px -20px 0; padding: 0 20px 2px; scrollbar-width: none; }
  .exam-chips::-webkit-scrollbar { display: none; }
  .exam-chips span { flex: none; }
  .home-progress { padding: 18px; gap: 12px; }
  .hp-head h2 { font-size: 1.45rem; }
  .hp-body { grid-template-columns: 100px minmax(0, 1fr); justify-items: stretch; gap: 14px; }
  .ring { width: 100px; height: 100px; }
  .ring-label b { font-size: 1.6rem; }
  .ring-label span { font-size: .66rem; }
  .hp-stats { gap: 6px; }
  .hp-stats div { padding: 6px 9px; border-radius: 9px; }
  .hp-stats dt { font-size: .6rem; letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .hp-stats dd { font-size: .78rem; }
  .hp-stats dd b { font-size: 1.1rem; }
  .hp-ch { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 34px; padding: 3px 4px; }
  .hp-last { font-size: .82rem; }
  .action-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
  .action-tile { flex-direction: column; align-items: flex-start; gap: 10px; padding: 14px; }
  .tile-arrow { display: none; }
  .tile-icon { width: 38px; height: 38px; font-size: 1.15rem; border-radius: 11px; }
  .tile-text b { font-size: .95rem; line-height: 1.25; }
  .tile-text span { font-size: .76rem; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .shelf-head { margin-top: 26px; }
  .shelf { grid-auto-columns: 78%; gap: 12px; margin: 12px -14px 0; padding: 0 14px 8px; scroll-padding: 0 14px; scrollbar-width: none; }
  .shelf::-webkit-scrollbar { display: none; }

  /* ---------- quiz set-up ---------- */
  .qs-title { padding: 14px 18px; }
  .qs-title h1 { font-size: 1.75rem; margin: 0; }
  .qs-title p { display: none; }
  .qs-help { display: none; }
  .qs-label { font-size: .85rem; }
  .qs-select { min-height: 48px; }
  .qs-start { bottom: var(--tabbar-h); }

  /* ---------- quiz runner ---------- */
  .quiz-top { margin: 12px 0 8px; }
  .quiz-meta { font-size: .8rem; }
  .question-card { padding: 18px 16px; }
  .q-text { font-size: 1.1rem; line-height: 1.45; }
  .option { padding: 11px 12px; }
  .quiz-nav { margin-top: 16px; }
  .quiz-nav .btn { min-height: 48px; }
  .dots-wrap { padding: 12px; margin-top: 12px; }
  .dots { grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); gap: 6px; }
  .dots button { height: 36px; font-size: .82rem; border-radius: 9px; }
  .dots-legend { font-size: .8rem; margin-top: 10px; }

  /* ---------- results ---------- */
  .result-hero { padding: 24px 16px; }
  .result-hero .score { font-size: 2.6rem; }
  .result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .result-actions .btn { font-size: .9rem; padding: 10px 8px; }
  .result-actions .btn-share, .result-actions #retry-wrong { grid-column: 1 / -1; }
  .review-item { padding: 10px 12px; }

  /* ---------- progress tables become cards ---------- */
  .card.table-wrap { padding: 4px 16px; }
  table.stack thead { display: none; }
  table.stack, table.stack tbody { display: block; }
  table.stack tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 10px; padding: 14px 0; border-bottom: 1px solid var(--border); }
  table.stack tr:last-child { border-bottom: 0; }
  table.stack td, table.stack th { border: 0; padding: 0; background: none; text-align: left !important; font-weight: 600; }
  table.stack [data-label]::before { content: attr(data-label); display: block; font-size: .66rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
  table.stack tr > :first-child { grid-column: 1 / -1; font-size: 1.02rem; font-weight: 700; }
  table.stack tr > :first-child::before { display: none; }
  table.stack .empty { display: none; }
  table.stack td:last-child:not(.empty):not([data-label]) { grid-column: 1 / -1; }
  table.stack td:last-child .btn { width: 100%; }
  table.stack tr.total { background: color-mix(in srgb, var(--surface-2) 60%, transparent); margin: 0 -16px; padding: 14px 16px; }

  /* ---------- reader ---------- */
  .cover { margin-top: 10px; min-height: calc(100svh - 56px - var(--tabbar-h) - 20px); border-radius: 4px 16px 16px 4px; }
  .cover::before { width: 14px; }
  .cover-inner { padding: 22px 20px 70px; }
  .cover-crumbs { font-size: .82rem; gap: 14px; }
  .cover-eyebrow { font-size: .72rem; letter-spacing: .22em; }
  .cover-title { font-size: 2.6rem; }
  .cover-blurb { font-size: 1rem; }
  .cover-actions .btn { flex: 1 1 auto; }
  .cover-credit { font-size: .6rem; opacity: .75; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .book { margin-top: 10px; }
  .paper { padding: 22px 18px 56px; }
  .paper-heading { font-size: 1.9rem; }
  .page-nav { flex-direction: column-reverse; align-items: stretch; margin-top: 30px; }
  .toc-row { padding: 12px 2px; font-size: 1.02rem; }

  /* ---------- landing ---------- */
  .lp-hero { padding: 36px 16px 56px; }
  .lp-title { font-size: 2.6rem; margin: 12px 0 14px; }
  .lp-lead { font-size: 1rem; }
  .lp-hero .btn-row { flex-direction: column; align-items: stretch; }
  .lp-book { width: min(230px, 62vw); margin-top: 8px; }
  .lp-book-pages { padding: 22px 20px; gap: 6px; }
  .lp-page-title { font-size: 1.4rem; }
  .lp-page-row { font-size: .85rem; }
  .lp-scroll { display: none; }
  .lp-facts div { padding: 16px 8px; }
  .lp-section { padding-top: 48px; }
  .lp-section-head { margin-bottom: 20px; }
  /* features: a swipeable row instead of six stacked cards */
  .lp-features { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 78%; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory;
    margin: 0 -16px; padding: 4px 16px 14px; scroll-padding: 0 16px; scrollbar-width: none; }
  .lp-features::-webkit-scrollbar { display: none; }
  .lp-feature { scroll-snap-align: start; padding: 18px; }
  .lp-feature:hover { transform: none; }
  .lp-feature-icon { width: 46px; height: 46px; font-size: 1.3rem; margin-bottom: 12px; }
  .lp-feature h3 { font-size: 1.3rem; }
  .lp-feature p { font-size: .9rem; }
  /* steps: medal beside the text */
  .lp-steps { gap: 18px; }
  .lp-steps li { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 2px 16px; text-align: left; padding: 0; }
  .lp-medal { grid-row: span 2; width: 52px; height: 52px; font-size: 1.15rem; margin: 0; }
  .lp-steps h3 { font-size: 1.3rem; margin: 2px 0 2px; }
  .lp-steps p { margin: 0; font-size: .92rem; }
  .lp-faq summary { font-size: .98rem; padding: 14px 28px 14px 0; }
}

@media (hover: none) { .kbd-hint { display: none; } }

@media (prefers-reduced-motion: reduce) {
  .question-card.q-next, .question-card.q-prev, .option.correct, .option.wrong, .feedback { animation: none !important; }
  .btn:active, .action-tile:active, .lp-spine:active, .option:active { transform: none; }
  .tabbar, .tabbar a::before, .tabbar svg, .theme-toggle { transition: none; }
}

/* =====================================================================
   EVIDENCE QUOTES, PASS ESTIMATE, REAL-TEST OUTCOME
   ===================================================================== */
.evidence { margin: 10px 0 0; padding: 8px 12px; border-left: 3px solid var(--gold); background: color-mix(in srgb, var(--gold) 9%, transparent);
  border-radius: 0 8px 8px 0; font-family: var(--serif-text); font-size: .95rem; font-style: italic; }
.evidence-label { display: block; font: 700 .7rem var(--font); font-style: normal; text-transform: uppercase; letter-spacing: .12em; color: color-mix(in srgb, var(--gold) 35%, var(--text)); margin-bottom: 2px; }
.insight-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 16px 0; }
.insight h2 { margin: 0 0 4px; font-family: var(--serif-display); font-size: 1.5rem; }
.insight-big { font-size: 2.6rem; font-weight: 800; line-height: 1.1; margin: 4px 0 8px; }
.range-bar { position: relative; height: 12px; border-radius: 99px; background: var(--surface-2); margin: 10px 0 6px; }
.range-fill { position: absolute; top: 0; bottom: 0; border-radius: 99px; background: color-mix(in srgb, var(--brand) 35%, transparent); }
.range-dot { position: absolute; top: 50%; width: 16px; height: 16px; border-radius: 50%; background: var(--brand); border: 2px solid var(--surface); transform: translate(-50%, -50%); }
.range-mark { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--accent); }
.how { margin-top: 12px; font-size: .9rem; }
.how summary { cursor: pointer; font-weight: 600; color: var(--brand); }
.how p { color: var(--muted); margin: 8px 0 0; }
.outcome-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin: 12px 0; }
.outcome-form label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; font-weight: 600; }
.outcome-form input, .outcome-form select { min-height: 40px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; }
.hp-pass { display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 2px 10px; padding: 10px 12px; border-radius: 10px; text-decoration: none; color: var(--text);
  background: color-mix(in srgb, var(--surface) 75%, transparent); border: 1px solid var(--border); font-size: .88rem; }
.hp-pass b { font-size: 1.5rem; grid-row: span 2; align-self: center; }
.hp-pass small { color: var(--muted); }
.hp-pass.muted { display: block; }
@media (max-width: 760px) { .insight-grid { grid-template-columns: 1fr; } }

body.has-bg main > .muted, body.has-bg main > p.muted { color: rgba(255, 255, 255, .85); text-shadow: 0 1px 4px rgba(0, 0, 0, .6); }
