@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Playfair+Display:ital,wght@0,400;0,500;0,600;1,400;1,500&display=swap");

:root {
  --bg: #fafafa;
  --bg-elev: #ffffff;
  --bg-elev-2: #f5f5f7;
  --fg: #1d1d1f;
  --fg-muted: #6e6e73;
  --fg-faint: #86868b;
  --border: rgba(0,0,0,0.08);
  --accent: #c41e3a;
  --accent-hover: #a8182f;
  --accent-fg: #ffffff;
  --accent-soft: rgba(196,30,58,0.10);
  --accent-soft-2: rgba(196,30,58,0.18);
  --good: #2f7a4d;
  --good-soft: #e6f1ea;
  --bad: #a83a2f;
  --bad-soft: #f5e1dd;
  --warn: #a6700d;
  --warn-soft: #fbf0d8;
  --glow: rgba(196,30,58,0.12);
  --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.04);
  --shadow-hover: 0 4px 12px rgba(0,0,0,0.08), 0 16px 32px rgba(0,0,0,0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --serif: "Playfair Display", Georgia, serif;
  --mono: "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

[data-theme="dark"] {
  --bg: #000000;
  --bg-elev: #1c1c1e;
  --bg-elev-2: #2c2c2e;
  --fg: #f5f5f7;
  --fg-muted: #a1a1a6;
  --fg-faint: #6e6e73;
  --border: rgba(255,255,255,0.10);
  --accent: #ff375f;
  --accent-hover: #ff5c7c;
  --accent-fg: #ffffff;
  --accent-soft: rgba(255,55,95,0.15);
  --accent-soft-2: rgba(255,55,95,0.25);
  --good: #5dcb7e;
  --good-soft: rgba(93,203,126,0.16);
  --bad: #e07060;
  --bad-soft: rgba(224,112,96,0.18);
  --warn: #f0b34a;
  --warn-soft: rgba(240,179,74,0.16);
  --glow: rgba(255,55,95,0.15);
  --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 4px 12px rgba(0,0,0,0.2);
  --shadow-hover: 0 4px 12px rgba(0,0,0,0.4), 0 16px 32px rgba(0,0,0,0.3);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.55;
  font-size: 16px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  position: relative;
}
body::before {
  content: "";
  position: fixed;
  inset: -35vh 0 auto 0;
  height: 65vh;
  background: radial-gradient(ellipse at center top, var(--glow) 0%, transparent 62%);
  pointer-events: none;
  z-index: -1;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  max-width: 980px;
  margin: 0 auto;
  padding: 24px 24px 64px;
}
.container.wide {
  max-width: 1180px;
}

/* ============ Top bar ============ */
.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px 18px;
  padding: 0 0 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.topbar h1 {
  font-size: 16px;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  letter-spacing: -0.2px;
  justify-self: start;
  min-width: 0;
  white-space: nowrap;
}

.topbar .maple {
  width: 22px;
  height: 22px;
  color: var(--accent);
}

.topbar nav {
  grid-column: 1 / -1;
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elev-2);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.45);
  overflow: visible;
}

.topbar nav a {
  color: var(--fg-muted);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  flex: 0 0 auto;
}
.topbar nav a:hover {
  background: var(--bg-elev);
  border-color: var(--border);
  color: var(--fg);
  text-decoration: none;
}
.topbar nav a.current {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent-soft-2);
  font-weight: 600;
}

.iconbtn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-muted);
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all .12s ease;
  padding: 0;
}
.iconbtn:hover { color: var(--fg); border-color: var(--fg-muted); }
.iconbtn svg { width: 16px; height: 16px; }
.topbar nav .iconbtn:first-of-type { margin-left: auto; }

.menu-toggle {
  display: none;
  width: 42px;
  height: 38px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 5px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
}
.menu-toggle span {
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  transition: transform .16s ease, opacity .16s ease;
}
.menu-toggle:hover {
  border-color: var(--fg-muted);
  background: var(--bg-elev);
}
.topbar.nav-open .menu-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.topbar.nav-open .menu-toggle span:nth-child(2) { opacity: 0; }
.topbar.nav-open .menu-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ============ Landing — hero ============ */
.hero {
  background:
    radial-gradient(circle at 100% 0%, rgba(255,255,255,0.16) 0%, transparent 50%),
    linear-gradient(135deg, #c41e3a 0%, #9e1730 58%, #6f1023 100%);
  color: #fff;
  padding: clamp(30px, 5vw, 54px);
  border-radius: 8px;
  margin-bottom: 28px;
  box-shadow: var(--shadow-hover);
  position: relative;
  overflow: hidden;
}
.hero-eyebrow {
  display: block;
  width: max-content;
  max-width: 100%;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  background: rgba(255,255,255,0.18);
  padding: 4px 10px;
  border-radius: 999px;
  margin: 0 auto 12px;
  text-align: center;
}
.hero h2 {
  margin: 0 auto 10px;
  font-family: var(--serif);
  font-size: clamp(34px, 6vw, 58px);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.05;
  max-width: 760px;
  text-align: center;
}
.hero p {
  margin: 0 auto;
  opacity: .94;
  font-size: 15.5px;
  line-height: 1.55;
  max-width: 620px;
  text-align: center;
}
.hero p em { font-style: normal; font-weight: 600; }
.hero .leaf {
  position: absolute;
  right: -30px;
  top: -25px;
  width: 200px;
  opacity: .10;
  pointer-events: none;
  transform: rotate(15deg);
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-top: 26px;
}
.hero-stat {
  background: rgba(255,255,255,0.13);
  padding: 14px 16px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
  backdrop-filter: blur(8px);
}
.hero-stat .v {
  font-size: 24px;
  font-weight: 700;
  display: block;
  line-height: 1.1;
  letter-spacing: -0.5px;
}
.hero-stat .l {
  font-size: 11px;
  opacity: .85;
  text-transform: uppercase;
  letter-spacing: .8px;
  margin-top: 4px;
  font-weight: 550;
}
.hero-stat.community-stat .l {
  line-height: 1.3;
}

@media (max-width: 640px) {
  .hero { padding: 26px 22px; }
  .hero h2 { font-size: 26px; }
  .hero-stats { grid-template-columns: repeat(2, 1fr); }
  .hero-stat.community-stat { grid-column: 1 / -1; }
}

/* ============ Tabs (landing) ============ */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-elev);
  padding: 5px;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 22px;
  position: relative;
}
.tabs button {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--fg-muted);
  font-size: 14.5px;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  transition: color .15s ease, background .15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.tabs button:hover { color: var(--fg); }
.tabs button.active {
  background: var(--bg-elev-2);
  color: var(--fg);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.tabs button .tab-icon { font-size: 16px; }
.tabs button .tab-count {
  font-size: 11px;
  font-weight: 700;
  background: var(--bg-elev-2);
  color: var(--fg-muted);
  padding: 2px 7px;
  border-radius: 999px;
  margin-left: 2px;
}
.tabs button.active .tab-count {
  background: var(--accent-soft);
  color: var(--accent);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fade .15s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* ============ Section heading ============ */
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 28px 0 14px;
  gap: 8px;
  flex-wrap: wrap;
}
.section-head h3 { margin: 0; font-size: 18px; font-weight: 650; }
.section-head .hint { color: var(--fg-muted); font-size: 13px; }

/* ============ Test grid ============ */
.tests-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(225px, 1fr));
  gap: 14px;
}

.test-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 18px 16px;
  text-decoration: none;
  color: inherit;
  display: block;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
  position: relative;
  overflow: hidden;
}
.test-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent);
  opacity: 0;
  transition: opacity .15s ease;
}
.test-card:hover {
  text-decoration: none;
  border-color: var(--fg-muted);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.07), 0 2px 6px rgba(0,0,0,0.04);
}
.test-card:hover::before { opacity: 1; }
[data-theme="dark"] .test-card:hover { box-shadow: 0 8px 24px rgba(0,0,0,0.4); }

.test-card .top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.test-card .title {
  font-weight: 650;
  font-size: 16px;
  letter-spacing: -0.1px;
}
.test-card .qcount {
  font-size: 11px;
  color: var(--fg-faint);
  text-transform: uppercase;
  letter-spacing: .6px;
  font-weight: 600;
  background: var(--bg-elev-2);
  padding: 3px 8px;
  border-radius: 6px;
}
.test-card .desc {
  color: var(--fg-muted);
  font-size: 13px;
  margin-bottom: 14px;
  min-height: 36px;
}
.test-card .progress {
  height: 6px;
  background: var(--bg-elev-2);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 10px;
}
.test-card .progress > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #d97f72);
  border-radius: 3px;
  transition: width .4s cubic-bezier(.22,.61,.36,1);
}
.test-card[data-pass="yes"] .progress > span {
  background: linear-gradient(90deg, var(--good), #5dcb7e);
}
.test-card .meta {
  font-size: 12.5px;
  color: var(--fg-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.test-card .meta .score { font-weight: 650; color: var(--fg); }
.test-card .meta .score.good { color: var(--good); }
.test-card .meta .score.bad { color: var(--bad); }

.test-card.mock {
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--accent) 4%, transparent), transparent 46%),
    var(--bg-elev);
  border-color: var(--border);
  color: inherit;
  box-shadow: var(--shadow);
}
.test-card.mock .qcount {
  background: var(--accent-soft);
  color: var(--accent);
}
.test-card.mock .desc { color: var(--fg-muted); }
.test-card.mock .meta { color: var(--fg-muted); }
.test-card.mock .meta .score { color: var(--fg); }
.test-card.mock .meta .score.good { color: var(--good); }
.test-card.mock .progress { background: var(--bg-elev-2); }
.test-card.mock .progress > span { background: linear-gradient(90deg, var(--accent), #d97f72); }
.test-card.mock::before { background: var(--accent); }
.test-card.mock:hover { box-shadow: var(--shadow-hover); }

/* ============ Landing — portfolio (study hub) ============ */
.portfolio {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 8px;
}
.portfolio-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 26px 24px;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  transition: transform .35s cubic-bezier(.2,.8,.2,1), box-shadow .35s cubic-bezier(.2,.8,.2,1), border-color .25s ease;
  display: flex;
  position: relative;
  overflow: hidden;
  min-height: 230px;
}
.portfolio-card::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--glow), transparent 60%);
  opacity: 0;
  transition: opacity .35s ease;
  pointer-events: none;
}
.portfolio-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
  border-color: var(--accent-soft-2);
  text-decoration: none;
}
.portfolio-card:hover::after { opacity: 1; }
.portfolio-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.portfolio-card .pc-inner {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.portfolio-card .pc-icon {
  width: 52px;
  height: 52px;
  background: var(--accent-soft);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  transition: background .25s ease, transform .35s ease;
}
.portfolio-card:hover .pc-icon {
  background: var(--accent);
  transform: scale(1.04) rotate(-3deg);
}
.portfolio-card .pc-icon svg {
  width: 26px;
  height: 26px;
  color: var(--accent);
  transition: color .25s ease;
}
.portfolio-card:hover .pc-icon svg { color: var(--accent-fg); }

.portfolio-card .pc-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 8px;
}

.portfolio-card .pc-title {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 500;
  line-height: 1.2;
  margin: 0 0 10px;
  letter-spacing: -0.02em;
  color: var(--fg);
}

.portfolio-card .pc-desc {
  font-size: 14px;
  color: var(--fg-muted);
  line-height: 1.55;
  margin: 0 0 18px;
  flex: 1;
}

.portfolio-card .pc-cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  transition: gap .25s ease;
}
.portfolio-card:hover .pc-cta { gap: 10px; }
.portfolio-card .pc-cta svg {
  width: 16px;
  height: 16px;
  transition: transform .25s ease;
}
.portfolio-card:hover .pc-cta svg { transform: translateX(3px); }

@media (prefers-reduced-motion: reduce) {
  .portfolio-card,
  .portfolio-card::after,
  .portfolio-card .pc-icon,
  .portfolio-card .pc-icon svg,
  .portfolio-card .pc-cta,
  .portfolio-card .pc-cta svg {
    transition: none;
    transform: none;
  }
}

@media (max-width: 820px) {
  .portfolio { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .portfolio-card { min-height: 200px; padding: 22px 20px; border-radius: 16px; }
  .portfolio-card .pc-title { font-size: 20px; }
}
@media (max-width: 520px) {
  .portfolio { grid-template-columns: 1fr; gap: 10px; }
  .portfolio-card { min-height: 0; padding: 20px 18px; border-radius: 14px; }
  .portfolio-card .pc-icon { width: 44px; height: 44px; border-radius: 12px; margin-bottom: 14px; }
  .portfolio-card .pc-icon svg { width: 22px; height: 22px; }
  .portfolio-card .pc-title { font-size: 18px; margin-bottom: 8px; }
  .portfolio-card .pc-desc { font-size: 13.5px; margin-bottom: 14px; }
  .portfolio-card .pc-label { font-size: 10.5px; }
}

/* ============ Test page — header ============ */
.test-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  flex-wrap: wrap;
  gap: 12px;
}
.test-head h2 { margin: 0; font-size: 22px; font-weight: 650; }
.test-head .sub { color: var(--fg-muted); font-size: 14px; margin-top: 2px; }

.modes {
  display: inline-flex;
  background: var(--bg-elev-2);
  border-radius: 8px;
  padding: 3px;
  border: 1px solid var(--border);
}
.modes button {
  background: transparent;
  border: none;
  color: var(--fg-muted);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 550;
  border-radius: 6px;
  cursor: pointer;
  transition: all .12s ease;
  font-family: inherit;
}
.modes button.active {
  background: var(--bg-elev);
  color: var(--fg);
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

/* ============ Progress dots ============ */
.qnav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 18px;
  padding: 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.qnav button {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--fg-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all .1s ease;
}
.qnav button:hover { color: var(--fg); border-color: var(--fg-muted); }
.qnav button.active { background: var(--accent); color: white; border-color: var(--accent); }
.qnav button.correct { background: var(--good-soft); color: var(--good); border-color: var(--good); }
.qnav button.wrong { background: var(--bad-soft); color: var(--bad); border-color: var(--bad); }

/* ============ Loading skeleton (test page first paint) ============ */
@keyframes skel-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}
.skel-dot,
.skel-line,
.skel-option,
.skel-badge {
  background: var(--bg-elev-2);
  border-radius: 6px;
  animation: skel-pulse 1.4s ease-in-out infinite;
}
.skel-dot {
  display: inline-block;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  margin: 0;
}
.skel-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.skel-badges { display: flex; gap: 8px; margin-bottom: 4px; }
.skel-badge { height: 22px; width: 56px; border-radius: 999px; }
.skel-badge.wide { width: 90px; }
.skel-line { height: 18px; border-radius: 4px; }
.skel-line.w90 { width: 92%; }
.skel-line.w70 { width: 72%; }
.skel-line.w50 { width: 48%; }
.skel-options { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.skel-option { height: 56px; border-radius: 12px; }

.error-card .err-title { font-weight: 700; color: var(--bad); margin: 0 0 6px; font-size: 16px; }
.error-card .err-detail { color: var(--fg-muted); font-size: 13.5px; margin: 0 0 14px; font-family: var(--mono); word-break: break-word; }

@media (prefers-reduced-motion: reduce) {
  .skel-dot, .skel-line, .skel-option, .skel-badge { animation: none; }
}

/* ============ Question card ============ */
.qcard {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 30px;
  margin-bottom: 18px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 8px 24px rgba(0,0,0,0.04);
}
[data-theme="dark"] .qcard { box-shadow: 0 8px 24px rgba(0,0,0,0.25); }

.qmeta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 12px;
  flex-wrap: wrap;
}
.qmeta .badges { display: flex; gap: 8px; flex-wrap: wrap; }
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .3px;
}
.badge.qid { background: var(--bg-elev-2); color: var(--fg-muted); border: 1px solid var(--border); }
.badge.topic { background: var(--accent-soft); color: var(--accent); }
[data-theme="dark"] .badge.topic { background: rgba(255,82,71,.15); }

.bookmark-btn {
  background: transparent;
  border: none;
  color: var(--fg-faint);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}
.bookmark-btn:hover { color: var(--accent); }
.bookmark-btn.on { color: var(--accent); }
.bookmark-btn svg { width: 18px; height: 18px; vertical-align: middle; }

.qstem {
  font-size: 18px;
  font-weight: 600;
  margin: 6px 0 18px;
  line-height: 1.5;
}

.options { display: flex; flex-direction: column; gap: 8px; }

.option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev-2);
  cursor: pointer;
  transition: all .1s ease;
  font-size: 15px;
  text-align: left;
  font-family: inherit;
  color: inherit;
  width: 100%;
}
.option:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-soft);
}
[data-theme="dark"] .option:hover:not(:disabled) {
  background: var(--bg-elev);
}
.option:disabled { cursor: default; }

.option .letter {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--bg-elev);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  border: 1px solid var(--border);
  flex-shrink: 0;
  color: var(--fg-muted);
}

.option .text { flex: 1; padding-top: 2px; }

.option .mark {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity .15s ease;
}
.option .mark svg { width: 22px; height: 22px; }

.option.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.option.selected .letter { background: var(--accent); color: white; border-color: var(--accent); }

.option.correct {
  border-color: var(--good);
  background: var(--good-soft);
}
.option.correct .letter { background: var(--good); color: white; border-color: var(--good); }
.option.correct .mark { opacity: 1; color: var(--good); }

.option.wrong {
  border-color: var(--bad);
  background: var(--bad-soft);
}
.option.wrong .letter { background: var(--bad); color: white; border-color: var(--bad); }
.option.wrong .mark { opacity: 1; color: var(--bad); }

/* ============ Explanation / reference ============ */
.explain {
  margin-top: 20px;
  padding: 0;
  border-radius: 12px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  display: none;
  overflow: hidden;
}
.explain.show { display: block; }

.explain .answer-line {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 14px 18px;
  background: var(--good-soft);
  border-bottom: 1px solid var(--border);
}
.explain .answer-tag {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--good);
  background: var(--bg-elev);
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--good);
  flex-shrink: 0;
}
.explain .answer-text {
  font-size: 15.5px;
  font-weight: 600;
  color: var(--fg);
  line-height: 1.4;
}
.explain .answer-text strong {
  color: var(--good);
  font-weight: 700;
  margin-right: 2px;
}

.explain .explanation-note {
  padding: 14px 18px 0;
  color: var(--fg);
  font-size: 14.5px;
  line-height: 1.55;
}

.explain .snippet {
  font-size: 14.5px;
  color: var(--fg-muted);
  line-height: 1.6;
  padding: 16px 18px 14px;
  position: relative;
  font-style: italic;
}
.explain .snippet::before {
  content: '"';
  position: absolute;
  left: 6px;
  top: 6px;
  font-size: 38px;
  color: var(--fg-faint);
  font-family: Georgia, serif;
  line-height: 1;
  opacity: .35;
}

.explain .source-line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
  font-size: 13px;
  flex-wrap: wrap;
}
.explain .source-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--fg-faint);
}
.explain .source-cite {
  color: var(--fg);
  font-weight: 600;
}
.explain .pdf-link {
  margin-left: auto;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}
.explain .pdf-link:hover { text-decoration: underline; }
.explain .answer-rate {
  padding: 0 18px 14px;
  background: var(--bg-elev);
  color: var(--fg-muted);
  font-size: 13px;
  line-height: 1.45;
}
.explain .answer-rate.ready {
  color: var(--good);
  font-weight: 600;
}

/* ============ Footer actions ============ */
.qactions {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-top: 22px;
  gap: 12px;
}
.qactions .left {
  grid-column: 2;
  display: flex;
  justify-content: center;
  gap: 10px;
}
.qactions .right {
  grid-column: 3;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.btn {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
  font-family: inherit;
  transition: all .1s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover:not(:disabled) { border-color: var(--fg-muted); background: var(--bg-elev); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn.primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--fg-muted);
}
.btn.ghost:hover { color: var(--fg); background: var(--bg-elev-2); }

.btn.pager {
  min-width: 112px;
  justify-content: center;
  background: transparent;
  border-color: var(--border);
  color: var(--fg);
  box-shadow: none;
}
.btn.pager:hover:not(:disabled) {
  background: transparent;
  border-color: var(--accent);
  color: var(--accent);
}

/* ============ Quiz mode results ============ */
.results-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  box-shadow: var(--shadow);
}
.results-card .score-big {
  font-size: 56px;
  font-weight: 700;
  line-height: 1;
  margin: 8px 0 6px;
}
.results-card .score-big.pass { color: var(--good); }
.results-card .score-big.fail { color: var(--bad); }
.results-card .verdict {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 6px;
}
.results-card .breakdown {
  color: var(--fg-muted);
  font-size: 14px;
  margin-bottom: 22px;
}
.results-card .actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ============ Save banner ============ */
.save-banner {
  position: fixed;
  bottom: 18px;
  right: 18px;
  background: var(--fg);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: all .25s ease;
  z-index: 100;
}
.save-banner.show {
  opacity: 1;
  transform: translateY(0);
}

/* ============ Empty / status ============ */
.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--fg-muted);
}
.empty .big { font-size: 40px; margin-bottom: 8px; }

/* ============ Settings drawer ============ */
.drawer {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
.drawer.open { display: flex; }
.drawer .panel {
  background: var(--bg-elev);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 22px 24px;
  width: 100%;
  max-width: 440px;
}
.drawer .panel h3 { margin: 0 0 4px; }
.drawer .panel p { color: var(--fg-muted); font-size: 14px; margin: 6px 0 16px; }
.drawer .panel .row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ============ Page head (Notes / Facts) ============ */
.page-head {
  margin-bottom: 20px;
}
.page-head h2 {
  margin: 0 0 6px;
  font-size: 28px;
  letter-spacing: -0.3px;
  font-weight: 750;
}
.page-head p {
  margin: 0;
  color: var(--fg-muted);
  font-size: 14.5px;
  max-width: 640px;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 18px;
}
.info-grid > div,
.info-grid > a {
  display: block;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 15px 16px;
  color: inherit;
  box-shadow: var(--shadow);
}
.info-grid > a:hover {
  border-color: var(--accent-soft-2);
  text-decoration: none;
}
.info-grid strong {
  display: block;
  font-size: 0.86rem;
  margin-bottom: 0.35rem;
}
.info-grid span {
  display: block;
  color: var(--fg-muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.study-map {
  margin-top: 28px;
}

/* ============ Filter bar (search + chips) ============ */
.filter-bar {
  margin-bottom: 18px;
}
.filter-bar input[type="search"] {
  width: 100%;
  padding: 11px 14px;
  font-size: 14.5px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--fg);
  font-family: inherit;
  margin-bottom: 10px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.filter-bar input[type="search"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--fg-muted);
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 550;
  cursor: pointer;
  font-family: inherit;
  transition: all .12s ease;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.chip:hover { color: var(--fg); border-color: var(--fg-muted); }
.chip.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}
.chip .chip-count {
  font-size: 10.5px;
  background: var(--bg-elev-2);
  padding: 1px 6px;
  border-radius: 999px;
  font-weight: 700;
}
.chip.active .chip-count {
  background: white;
  color: var(--accent);
}

/* Highlight */
mark {
  background: #fff3a8;
  color: inherit;
  border-radius: 3px;
  padding: 0 2px;
}
[data-theme="dark"] mark {
  background: rgba(245, 200, 80, 0.32);
  color: #fff;
}

/* ============ Timeline (Dates) — CSS Grid layout ============ */
.timeline {
  list-style: none;
  padding: 0;
  margin: 0;
}
.timeline-row {
  display: grid;
  grid-template-columns: 140px 28px 1fr;
  align-items: stretch;
  gap: 0;
  position: relative;
}
/* Vertical line down the middle column */
.timeline-row::before {
  content: '';
  position: absolute;
  left: 153px;             /* 140 (year col) + 13 (half of 28-col, minus 1px line width) */
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}
.timeline-row:first-child::before { top: 18px; }
.timeline-row:last-child::before { bottom: calc(100% - 28px); }

.timeline-row .t-year {
  padding: 16px 14px 16px 0;
  text-align: right;
  font-weight: 700;
  font-size: 14px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.3px;
  line-height: 1.35;
}
.timeline-row .t-dot-col {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 22px;
}
.timeline-row .t-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--bg);
  box-shadow: 0 0 0 2px var(--border);
}
.timeline-row .t-body {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  margin: 10px 0;
  margin-left: 14px;
  transition: border-color .15s ease, transform .15s ease;
}
.timeline-row .t-body:hover {
  border-color: var(--fg-muted);
  transform: translateX(2px);
}
.timeline-row .t-event {
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--fg);
}
.timeline-row .t-source {
  display: inline-block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--fg-muted);
  font-weight: 550;
}
.timeline-row .t-source:hover { color: var(--accent); }

@media (max-width: 640px) {
  .timeline-row {
    grid-template-columns: 90px 24px 1fr;
  }
  .timeline-row::before { left: 101px; }
  .timeline-row .t-year { font-size: 12.5px; padding-right: 10px; }
  .timeline-row .t-body { margin-left: 10px; padding: 10px 12px; }
}

/* ============ Person cards ============ */
.people-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}
.person-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease;
  position: relative;
  overflow: hidden;
}
.person-card::after {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 3px;
  background: var(--accent);
  opacity: 0;
  transition: opacity .15s ease;
}
.person-card:hover {
  border-color: var(--fg-muted);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.06);
}
.person-card:hover::after { opacity: 1; }

.person-card header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.p-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.3px;
  flex-shrink: 0;
}
.p-id { flex: 1; min-width: 0; }
.p-id h4 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.2px;
  line-height: 1.3;
  color: var(--fg);
}
.p-role {
  font-size: 13px;
  color: var(--fg-muted);
  margin-top: 2px;
  font-weight: 550;
}
.p-era {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  background: var(--bg-elev-2);
  color: var(--fg-muted);
  padding: 4px 10px;
  border-radius: 999px;
  flex-shrink: 0;
  align-self: flex-start;
}
.p-did {
  font-size: 14px;
  line-height: 1.6;
  color: var(--fg);
  margin: 0;
}
.p-source {
  font-size: 12.5px;
  color: var(--fg-muted);
  font-weight: 600;
  margin-top: auto;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}
.p-source:hover { color: var(--accent); }

/* ============ Facts ============ */
.facts-head .facts-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--fg-muted);
}
.facts-head .facts-stats span {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 999px;
}
.facts-head .facts-stats strong {
  color: var(--fg);
  font-weight: 700;
}

/* Reference tables section */
.ref-section {
  margin: 4px 0 24px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px 16px;
}
.ref-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}
.ref-tab {
  background: transparent;
  border: 1px solid transparent;
  padding: 7px 12px;
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-muted);
  cursor: pointer;
  transition: all .15s ease;
}
.ref-tab:hover { color: var(--fg); background: var(--bg); }
.ref-tab.active {
  color: var(--fg);
  background: var(--bg);
  border-color: var(--border);
  box-shadow: inset 0 -2px 0 var(--accent);
}
.ref-panel { animation: fadein .2s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }
.ref-group { margin-bottom: 18px; }
.ref-group:last-child { margin-bottom: 0; }
.ref-group-title {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--fg-faint);
}
.ref-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.ref-table th {
  text-align: left;
  font-weight: 600;
  color: var(--fg-muted);
  border-bottom: 1px solid var(--border);
  padding: 7px 10px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.ref-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.ref-table tr:last-child td { border-bottom: 0; }
.ref-table a { color: var(--fg-muted); font-weight: 600; }
.ref-table a:hover { color: var(--accent); }
.prov-abbr {
  display: inline-block;
  min-width: 28px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  margin-right: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  text-align: center;
  color: var(--fg-muted);
  letter-spacing: .5px;
}
@media (max-width: 720px) {
  .hide-mobile { display: none; }
}

/* Three branches widget */
.branch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.branch-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 14px 12px;
  border-left: 3px solid var(--accent);
}
.branch-card .branch-name {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--accent);
  margin-bottom: 4px;
}
.branch-card p { margin: 4px 0 8px; font-size: 14px; line-height: 1.5; color: var(--fg); }
.branch-card small { color: var(--fg-muted); font-size: 12.5px; line-height: 1.5; }
.branch-foot { margin: 12px 0 0; font-size: 12px; color: var(--fg-muted); }
.branch-foot a { color: var(--fg-muted); font-weight: 600; }
.branch-foot a:hover { color: var(--accent); }

/* Group headers (when "All" view groups by category) */
.facts-group {
  margin: 26px 0 12px;
  font-size: 14px;
  font-weight: 700;
  color: var(--fg);
  display: flex;
  align-items: center;
  gap: 10px;
}
.facts-group::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.facts-group:first-child { margin-top: 4px; }
.facts-group-icon { font-size: 18px; line-height: 1; }
.facts-group-count {
  font-size: 11px;
  font-weight: 600;
  color: var(--fg-muted);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
}

.facts-sub {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.facts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.facts-grid:has(.facts-group) {
  display: block;
}

/* The card itself */
.fact-card {
  --card-accent: var(--accent);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease;
  position: relative;
  overflow: hidden;
}
.fact-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--card-accent);
  opacity: .8;
}
.fact-card:hover {
  border-color: var(--fg-muted);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(0,0,0,0.06);
}
.fact-card:hover::before { opacity: 1; }
.fact-eyebrow {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--fg-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  line-height: 1.4;
}
.fact-eyebrow .fact-icon {
  font-size: 14px;
  line-height: 1;
  filter: saturate(.95);
}
.fact-answer {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--fg);
  letter-spacing: -.005em;
}
.fact-ctx {
  font-size: 13px;
  line-height: 1.55;
  color: var(--fg-muted);
}
.fact-card .fact-source {
  font-size: 11.5px;
  color: var(--fg-faint);
  font-weight: 600;
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  letter-spacing: .2px;
}
.fact-card .fact-source:hover { color: var(--card-accent); }

/* ============ Summary page (Discover Canada distilled) ============ */
.summary-controls {
  display: flex;
  gap: 12px;
  align-items: center;
  margin: 8px 0 18px;
  flex-wrap: wrap;
}
.summary-controls .search-wrap {
  position: relative;
  flex: 1 1 280px;
  min-width: 240px;
}
.summary-controls .search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--fg-faint);
  pointer-events: none;
}
.summary-controls input[type="search"] {
  width: 100%;
  padding: 11px 40px 11px 40px;
  font-size: 14.5px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--fg);
  font-family: inherit;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.summary-controls input[type="search"]::-webkit-search-decoration,
.summary-controls input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }
.summary-controls input[type="search"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.summary-controls .search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border: 0;
  background: transparent;
  color: var(--fg-faint);
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease, color .15s ease, background .15s ease;
  padding: 0;
}
.summary-controls .search-clear svg { width: 14px; height: 14px; }
.summary-controls .search-clear:hover { color: var(--fg); background: var(--bg-elev-2); }
.summary-controls .search-wrap[data-has-value="true"] .search-clear {
  opacity: 1;
  pointer-events: auto;
}
.summary-controls .bulk-actions { display: flex; gap: 6px; flex-shrink: 0; }
.summary-controls .btn-tiny {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--fg-muted);
  font-size: 12.5px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  transition: all .15s ease;
}
.summary-controls .btn-tiny:hover { color: var(--fg); border-color: var(--fg-muted); background: var(--bg-elev-2); }

.search-status {
  margin: -6px 0 14px;
  font-size: 13px;
  color: var(--fg-muted);
  font-weight: 600;
}
.search-status .no-results {
  padding: 14px 16px;
  background: var(--bg-elev);
  border: 1px dashed var(--border);
  border-radius: 10px;
  color: var(--fg-muted);
  text-align: center;
}
.search-status .no-results strong { color: var(--fg); }

.summary-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 32px;
  align-items: start;
}
.summary-toc {
  position: sticky;
  top: 16px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 12px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}
.summary-toc h3 {
  margin: 0 0 8px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--fg-faint);
}
.summary-toc ol {
  list-style: none;
  padding: 0;
  margin: 0 0 10px;
  counter-reset: chap;
}
.summary-toc li { counter-increment: chap; }
.summary-toc li a {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--fg-muted);
  font-size: 13px;
  font-weight: 550;
  text-decoration: none;
  margin-bottom: 1px;
  border-left: 2px solid transparent;
}
.summary-toc li a:hover {
  background: var(--bg-elev-2);
  color: var(--fg);
}
.summary-toc li a.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-left-color: var(--accent);
}
.summary-toc .toc-icon { font-size: 14px; line-height: 1; }
.summary-toc .toc-title { line-height: 1.25; }
.summary-toc .toc-pages {
  font-size: 11px;
  color: var(--fg-faint);
  font-variant-numeric: tabular-nums;
}
.summary-toc li a.active .toc-pages { color: var(--accent); }
.summary-toc .toc-meta {
  padding: 10px;
  border-top: 1px solid var(--border);
  margin-top: 6px;
  font-size: 12.5px;
  font-weight: 600;
}

.summary-main {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

/* Chapter accordion */
.chapter {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  scroll-margin-top: 24px;
  overflow: hidden;
  transition: border-color .15s ease, box-shadow .2s ease;
}
.chapter:hover { border-color: var(--accent-soft-2); }
.chapter.is-open { box-shadow: 0 1px 3px rgba(0,0,0,0.03); }

.chapter-header {
  display: grid;
  grid-template-columns: auto auto 1fr auto auto;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 16px 20px;
  background: transparent;
  border: 0;
  text-align: left;
  cursor: pointer;
  color: inherit;
  font-family: inherit;
  font-size: 1rem;
  transition: background .15s ease;
}
.chapter-header:hover { background: var(--bg-elev-2); }
.chapter-header:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: 14px;
}

.chapter-header .ch-num {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--fg-faint);
  letter-spacing: 0.5px;
  font-variant-numeric: tabular-nums;
  min-width: 18px;
  text-align: center;
}

.chapter-header .ch-icon {
  font-size: 22px;
  line-height: 1;
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: var(--accent-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chapter-header .ch-titles { min-width: 0; }
.chapter-header h3 {
  margin: 0 0 2px;
  font-size: 16.5px;
  font-weight: 700;
  letter-spacing: -0.2px;
  color: var(--fg);
}
.chapter-header .ch-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--fg-muted);
  font-size: 12.5px;
  flex-wrap: wrap;
}
.chapter-header .ch-meta a {
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
}
.chapter-header .ch-meta a:hover { text-decoration: underline; }
.chapter-header .ch-meta-sep { color: var(--fg-faint); }

.chapter-header .ch-count {
  font-size: 11px;
  font-weight: 700;
  color: var(--fg-faint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--bg-elev-2);
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.chapter-header .ch-chevron {
  width: 18px;
  height: 18px;
  color: var(--fg-faint);
  transition: transform .25s cubic-bezier(.4,0,.2,1);
}
.chapter.is-open .ch-chevron { transform: rotate(180deg); color: var(--accent); }

.chapter-body {
  padding: 4px 22px 22px;
  display: none;
}
.chapter.is-open .chapter-body { display: block; }

.chapter-body .bullets {
  list-style: none;
  padding: 16px 0 0;
  margin: 0;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.chapter-body .bullets li {
  position: relative;
  padding-left: 22px;
  font-size: 15px;
  line-height: 1.65;
  color: var(--fg);
}
.chapter-body .bullets li::before {
  content: '';
  position: absolute;
  left: 4px;
  top: 0.72em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: .55;
}
.chapter-body .bullets strong { font-weight: 700; color: var(--fg); }
.chapter-body .bullets em { font-style: italic; color: var(--fg-muted); }
.chapter-body .bullets mark {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  padding: 1px 3px;
  border-radius: 3px;
}

.ch-table-wrap {
  margin-top: 16px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.ch-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.ch-table thead th {
  background: var(--bg-elev-2);
  color: var(--fg-muted);
  font-weight: 700;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.ch-table tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--fg);
}
.ch-table tbody tr:last-child td { border-bottom: none; }
.ch-table tbody tr:hover td { background: var(--bg-elev-2); }
.ch-table tbody td:first-child {
  font-weight: 700;
  color: var(--accent);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

@media (max-width: 900px) {
  .summary-layout { grid-template-columns: 1fr; gap: 0; }
  .summary-toc { display: none; }
}

/* keyboard hint */
.kbd {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 6px;
  color: var(--fg);
  font-weight: 600;
}

.kbd-help {
  text-align: center;
  font-size: 13px;
  color: var(--fg-muted);
  margin-top: 36px;
  padding: 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.kbd-help strong {
  color: var(--fg);
  margin-right: 8px;
}

.legal-line {
  text-align: center;
  color: var(--fg-faint);
  font-size: 12px;
  margin-top: 24px;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.5;
}
.legal-line em { font-style: italic; color: var(--fg-muted); }
.legal-line a { color: var(--fg-muted); text-decoration: underline; text-underline-offset: 2px; }

.app-footer {
  margin: 34px auto 0;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: block;
  color: var(--fg-muted);
  text-align: center;
  max-width: 620px;
}
.app-footer strong {
  display: block;
  color: var(--fg);
  font-size: 0.84rem;
  margin-bottom: 0.25rem;
}
.app-footer span {
  display: block;
  font-size: 0.78rem;
  line-height: 1.45;
}
.app-footer nav {
  display: none;
}
.app-footer a {
  color: var(--fg-muted);
  font-size: 0.82rem;
  font-weight: 600;
}
.app-footer a:hover {
  color: var(--accent);
}

/* ============================================================
   MOBILE — small phones (≤640px)
   ============================================================ */
@media (max-width: 640px) {
  .container, .container.wide {
    padding: 16px 14px 60px;
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 12px 0 14px;
    gap: 10px 12px;
    align-items: center;
    position: relative;
    padding-right: 0;
  }
  .topbar h1 {
    font-size: 15px;
    grid-column: 1 / -1;
    justify-self: start;
    min-width: 0;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .topbar h1 .maple { width: 18px; height: 18px; }
  .menu-toggle {
    display: inline-flex;
    justify-self: end;
  }
  .topbar nav {
    display: flex;
    grid-column: 1 / -1;
    width: 100%;
    overflow: visible;
    scrollbar-width: auto;
    margin: 0;
    padding: 8px;
    flex-direction: column;
    align-items: stretch;
    flex-wrap: nowrap;
    gap: 5px;
    background: var(--bg-elev);
    box-shadow: var(--shadow);
  }
  .topbar.nav-ready nav { display: none; }
  .topbar.nav-ready.nav-open nav { display: flex; }
  .topbar nav::-webkit-scrollbar { display: initial; }
  .topbar nav a {
    width: 100%;
    flex-shrink: 1;
    font-size: 13px;
    padding: 10px 12px;
  }
  .topbar nav .iconbtn {
    position: static;
    width: 100%;
    height: 40px;
    justify-content: flex-start;
    gap: 10px;
    padding: 0 12px;
    margin-left: 0;
    color: var(--fg-muted);
  }
  .topbar nav .iconbtn:first-of-type { margin-left: 0; }
  .topbar nav .iconbtn::after {
    content: attr(data-label);
    font-size: 13px;
    font-weight: 600;
  }
  .topbar:not(:has(.iconbtn + .iconbtn)) { padding-right: 0; }

  .info-grid {
    grid-template-columns: 1fr;
  }

  .app-footer {
    margin-top: 28px;
  }

  /* Hero */
  .hero {
    padding: 24px 20px 22px;
    border-radius: 14px;
    margin-bottom: 18px;
  }
  .hero h2 { font-size: 22px; }
  .hero p { font-size: 14px; }
  .hero-stats { gap: 8px; margin-top: 18px; }
  .hero-stat { padding: 10px 12px; }
  .hero-stat .v { font-size: 20px; }
  .hero-stat .l { font-size: 10px; }

  /* Tabs (Practice / Mock) */
  .tabs button { font-size: 13px; padding: 9px 10px; gap: 5px; }
  .tabs button .tab-count { font-size: 10px; padding: 1px 6px; }

  /* Test card grid */
  .tests-grid { gap: 10px; }
  .test-card { padding: 14px 14px 12px; border-radius: 12px; }
  .test-card .title { font-size: 15px; }
  .test-card .desc { font-size: 12.5px; min-height: 0; margin-bottom: 10px; }

  /* Section heading */
  .section-head h3 { font-size: 16px; }
  .section-head .hint { font-size: 12px; }

  /* Page head (notes/facts/summary) */
  .page-head h2 { font-size: 22px; }
  .page-head p { font-size: 13.5px; }

  /* Question card */
  .qcard {
    padding: 18px 18px 20px;
    border-radius: 12px;
  }
  .qstem { font-size: 16.5px; margin: 6px 0 14px; }
  .option { padding: 11px 12px; font-size: 14px; gap: 10px; min-height: 44px; }
  .option .letter { width: 24px; height: 24px; font-size: 12px; }

  /* Test header — modes toggle aligns below the title */
  .test-head { gap: 8px; }
  .test-head h2 { font-size: 18px; }
  .test-head .sub { font-size: 13px; }

  /* Question nav (the 1-20 dots) */
  .qnav { padding: 8px; gap: 3px; }
  .qnav button {
    width: 30px; height: 30px;
    font-size: 12px;
    /* min-height for tap target */
  }

  /* Action buttons full-width feel */
  .qactions { grid-template-columns: 1fr; gap: 10px; }
  .qactions .left, .qactions .right { grid-column: 1; width: 100%; }
  .qactions .left { justify-content: center; }
  .qactions .right { justify-content: center; }
  .btn.pager { flex: 1; max-width: 150px; }
  .btn { padding: 10px 14px; font-size: 13.5px; min-height: 40px; }

  /* Explanation */
  .explain .answer-line { padding: 12px 14px; flex-wrap: wrap; gap: 8px; }
  .explain .answer-text { font-size: 15px; }
  .explain .snippet { padding: 14px 14px 12px; font-size: 14px; }
  .explain .source-line { padding: 10px 14px 12px; font-size: 12.5px; }
  .explain .pdf-link { margin-left: 0; flex-basis: 100%; }

  /* Results card */
  .results-card { padding: 22px 18px; }
  .results-card .score-big { font-size: 44px; }

  /* Filter bar */
  .filter-bar input[type="search"] { font-size: 16px; padding: 10px 12px; } /* 16px prevents iOS zoom */
  .chip { font-size: 12px; padding: 5px 10px; }

  /* Person & fact cards */
  .person-card { padding: 14px 16px; border-radius: 12px; }
  .p-id h4 { font-size: 15px; }
  .p-did { font-size: 13.5px; }

  .fact-card { padding: 14px 14px 12px; }
  .fact-card p { font-size: 13.5px; }

  /* Summary chapter accordion — mobile */
  .chapter { border-radius: 12px; }
  .chapter-header {
    grid-template-columns: auto 1fr auto;
    gap: 12px;
    padding: 14px 14px;
  }
  .chapter-header .ch-num { display: none; }
  .chapter-header .ch-count { display: none; }
  .chapter-header .ch-icon { font-size: 20px; width: 36px; height: 36px; border-radius: 10px; }
  .chapter-header h3 { font-size: 15.5px; }
  .chapter-header .ch-meta { font-size: 12px; gap: 6px; }
  .chapter-body { padding: 0 14px 16px; }
  .chapter-body .bullets { padding-top: 14px; gap: 11px; }
  .chapter-body .bullets li { font-size: 14.5px; padding-left: 18px; line-height: 1.6; }
  .ch-table { font-size: 12.5px; }
  .ch-table thead th { padding: 8px 10px; font-size: 11px; }
  .ch-table tbody td { padding: 8px 10px; }

  /* Summary controls — mobile */
  .summary-controls { margin: 6px 0 14px; gap: 10px; }
  .summary-controls input[type="search"] { font-size: 16px; padding: 12px 40px; } /* 16px prevents iOS zoom */
  .summary-controls .bulk-actions { flex: 1; }
  .summary-controls .btn-tiny { flex: 1; padding: 9px 10px; }

  /* Drawer panel */
  .drawer { padding: 16px; align-items: flex-end; }
  .drawer .panel {
    border-radius: 14px 14px 0 0;
    padding: 18px 20px;
  }

  /* Save banner — float full-width on phones */
  .save-banner {
    left: 18px;
    right: 18px;
    bottom: 16px;
    text-align: center;
  }

  /* Keyboard hint card is desktop-only */
  .kbd-help { display: none; }
}

/* ============================================================
   TABLET (641–900px) — minor tweaks
   ============================================================ */
@media (min-width: 641px) and (max-width: 900px) {
  .qcard { padding: 22px 24px; }
  .test-head h2 { font-size: 20px; }
  .topbar nav { gap: 3px; padding: 7px; }
  .topbar nav a { font-size: 12px; padding: 7px 8px; }
}

/* iOS notch / Android safe areas */
@supports (padding: max(0px)) {
  .container, .container.wide {
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
  }
  @media (max-width: 640px) {
    .container, .container.wide {
      padding-left: max(14px, env(safe-area-inset-left));
      padding-right: max(14px, env(safe-area-inset-right));
    }
  }
}
