/* The TKT Course — interactive edition. System-wide styles. */
:root {
  --bg: #f6f4ef;
  --bg-alt: #efebe3;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --border: #e3ded2;
  --border-strong: #cfc7b6;
  --text: #26221a;
  --text-soft: #5d574a;
  --muted: #8f8877;
  --accent: #b3401f;        /* terracotta */
  --accent-soft: #f3dcd3;
  --accent-2: #946200;      /* ochre highlights */
  --green: #2e7d4f;
  --green-soft: #dff0e4;
  --amber: #a86e00;
  --amber-soft: #f7ecd4;
  --red: #b3401f;
  --red-soft: #f6ddd5;
  --blue: #1f5f8b;
  --blue-soft: #dcebf5;
  --sidebar-w: 320px;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(38, 32, 20, .05), 0 8px 24px rgba(38, 32, 20, .07);
  --font: 'Gelica', 'Avenir Next', 'Segoe UI', system-ui, -apple-system, 'PingFang SC', 'Noto Sans', sans-serif;
  --font-serif: 'Iowan Old Style', 'Palatino Linotype', 'Source Serif 4', Georgia, 'Songti SC', serif;
}
html[data-theme="dark"] {
  --bg: #191713;
  --bg-alt: #14120e;
  --surface: #211e18;
  --surface-2: #26221b;
  --border: #37322a;
  --border-strong: #4a4436;
  --text: #ece6d9;
  --text-soft: #b7ae9c;
  --muted: #8f8877;
  --accent: #e06a45;
  --accent-soft: #3a231b;
  --accent-2: #d9a441;
  --green: #58b380;
  --green-soft: #1d3328;
  --amber: #d9a441;
  --amber-soft: #33290f;
  --red: #e06a45;
  --red-soft: #3a231b;
  --blue: #6aa8d8;
  --blue-soft: #16303f;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16.5px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; }

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  scroll-behavior: smooth;
}
.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.content {
  width: min(860px, 100%); margin: 0 auto; padding: 40px 40px 120px;
}
@media (max-width: 1100px) {
  .sidebar { position: fixed; left: 0; z-index: 60; transform: translateX(-100%); transition: transform .25s ease; box-shadow: var(--shadow); }
  body.nav-open .sidebar { transform: none; }
  .content { padding: 24px 18px 110px; width: 100%; }
}
.nav-scrim { display: none; }
@media (max-width: 1100px) {
  body.nav-open .nav-scrim { display: block; position: fixed; inset: 0; background: rgba(15,12,5,.45); z-index: 55; }
}

/* ---------- sidebar ---------- */
.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 20px 18px 14px; border-bottom: 1px solid var(--border);
  text-decoration: none; color: var(--text);
}
.brand-badge {
  width: 42px; height: 42px; border-radius: 10px; flex: 0 0 auto;
  background: linear-gradient(135deg, var(--accent), #d97742);
  color: #fff; display: grid; place-items: center;
  font-weight: 800; font-size: 15px; letter-spacing: .5px;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.2);
}
.brand-name { font-size: 16px; font-weight: 800; line-height: 1.15; }
.brand-sub { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .12em; }

.side-progress { padding: 14px 18px 6px; }
.side-progress .meter { height: 6px; background: var(--bg-alt); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.side-progress .meter > span { display: block; height: 100%; background: var(--accent); border-radius: 4px; width: 0%; transition: width .4s; }
.side-progress .caption { font-size: 12px; color: var(--muted); font-weight: 600; display: flex; justify-content: space-between; }

.nav { padding: 8px 10px 30px; }
.nav-group { margin-top: 6px; }
.nav-group-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .14em;
  color: var(--muted); font-weight: 800; padding: 12px 10px 6px;
  display: flex; align-items: center; justify-content: space-between;
}
.nav-group-label .pct { font-variant-numeric: tabular-nums; }
.nav-link {
  display: flex; align-items: center; gap: 9px;
  padding: 7.5px 10px; border-radius: 9px; text-decoration: none;
  color: var(--text-soft); font-size: 13.5px; font-weight: 600;
  border: 1px solid transparent;
}
.nav-link .num {
  width: 26px; height: 22px; flex: 0 0 auto; border-radius: 6px;
  display: grid; place-items: center; font-size: 11.5px; font-weight: 800;
  background: var(--bg-alt); color: var(--text-soft);
  font-variant-numeric: tabular-nums;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.nav-link.active .num { background: var(--accent); color: #fff; }
html[data-theme="dark"] .nav-link.active { color: #f5c9b8; }
.nav-link .title-row { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-link .done-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); flex: 0 0 auto; opacity: 0; }
.nav-link .done-dot.on { opacity: 1; }
.nav-link .score-chip { font-size: 10.5px; font-weight: 800; color: var(--muted); background: var(--bg-alt); border-radius: 20px; padding: 2px 7px; }

/* ---------- topbar (mobile) ---------- */
.topbar { display: none; }
@media (max-width: 1100px) {
  .topbar {
    display: flex; align-items: center; gap: 10px;
    position: sticky; top: 0; z-index: 50;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
    padding: 10px 14px; width: 100%;
  }
  .topbar .icon-btn { display: inline-grid; }
}

/* ---------- icon buttons / chips ---------- */
.icon-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-soft);
  width: 38px; height: 38px; border-radius: 10px; cursor: pointer;
  display: none; place-items: center; font-size: 17px; flex: 0 0 auto;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }
.topbar-title { font-weight: 800; font-size: 15px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.toolbar { display: flex; gap: 8px; justify-content: flex-end; padding: 18px 40px 0; align-items: center; }
@media (max-width: 1100px) { .toolbar { display: none; } }
.tool-btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-soft);
  padding: 8px 13px; border-radius: 10px; cursor: pointer; font-size: 13px; font-weight: 600;
  font-family: var(--font);
}
.tool-btn:hover { color: var(--text); border-color: var(--border-strong); }
kbd.hint {
  font-family: var(--font); font-size: 11px; background: var(--bg-alt);
  border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px;
  padding: 1px 6px; color: var(--muted); font-weight: 700;
}

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-alt); color: var(--text-soft); border: 1px solid var(--border);
  font-size: 12px; font-weight: 700; padding: 3.5px 11px; border-radius: 999px;
}
.chip.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
html[data-theme="dark"] .chip.accent { color: #f5c9b8; }
.chip .k { font-family: var(--font-serif); font-style: italic; font-weight: 600; }

/* ---------- typography ---------- */
.content h1 {
  font-family: var(--font-serif); font-size: clamp(30px, 4.5vw, 42px);
  line-height: 1.12; margin: 10px 0 6px; letter-spacing: -.01em;
}
.content h2 {
  font-family: var(--font-serif); font-size: clamp(23px, 3vw, 29px);
  margin: 44px 0 10px; line-height: 1.2;
  display: flex; align-items: center; gap: 12px;
}
.content h2 .h-ico {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-size: 17px;
}
html[data-theme="dark"] .content h2 .h-ico { color: #f0b39a; }
.content h3 { font-size: 19px; margin: 30px 0 8px; font-weight: 800; }
.content h4 { font-size: 16px; margin: 22px 0 6px; font-weight: 800; color: var(--text-soft); }
.lead { font-size: 18.5px; color: var(--text-soft); font-family: var(--font-serif); line-height: 1.6; }
.content p { margin: 12px 0; }
.content ul, .content ol { padding-left: 24px; margin: 10px 0; }
.content li { margin: 5px 0; }
.content b, .content strong { font-weight: 800; }
.content em { font-style: italic; }
a { color: var(--accent); }
html[data-theme="dark"] a:not(.nav-link):not(.card) { color: #f0a583; }

.crumbs { display: flex; gap: 8px; align-items: center; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 12px; flex-wrap: wrap; }
.crumbs a { text-decoration: none; color: var(--muted); }
.crumbs a:hover { color: var(--text); }
.crumbs .sep { opacity: .5; }

.unit-meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 14px 0 4px; }

/* ---------- blocks ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 26px 28px;
  margin: 18px 0;
}
.callout {
  border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: 12px; background: var(--surface-2); padding: 16px 20px; margin: 20px 0;
}
.callout > .co-head {
  display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 13px;
  text-transform: uppercase; letter-spacing: .1em; color: var(--accent); margin-bottom: 4px;
}
.callout > .co-head .ico { font-size: 15px; }
.callout.tip { border-left-color: var(--green); }
.callout.tip > .co-head { color: var(--green); }
.callout.example { border-left-color: var(--blue); }
.callout.example > .co-head { color: var(--blue); }
.callout.reflection { background: var(--amber-soft); border-left-color: var(--amber); }
.callout.reflection > .co-head { color: var(--amber); }
.callout .co-title { font-weight: 800; margin-bottom: 2px; }
.callout ul, .callout ol { margin-bottom: 6px; }

.zig, .answer-strip {
  background: var(--bg-alt); border-radius: 10px; padding: 14px 18px; margin: 14px 0;
}
.zig { border-left: 4px solid var(--border-strong); }
.answer-strip { border: 1px dashed var(--border-strong); }

.term-list { display: grid; grid-template-columns: 1fr; gap: 10px; margin: 16px 0; }
.term-row { display: flex; gap: 16px; padding: 13px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.term-row .t { flex: 0 0 30%; font-weight: 800; }
.term-row .d { flex: 1; color: var(--text-soft); }
.term-row .t a { text-decoration: none; }
@media (max-width: 720px) { .term-row { flex-direction: column; gap: 4px; } .term-row .t { flex-basis: auto; } }

/* glossary tooltip */
dfn.gterm, .gterm {
  font-style: normal; cursor: help; border-bottom: 2px dotted var(--accent-2);
  text-decoration: none; color: inherit; position: relative;
}
.gterm-def { display: none; }
.gterm-pop {
  display: none;                 /* hidden until hovered, focused or clicked */
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px;
  box-shadow: var(--shadow); padding: 10px 14px; width: min(340px, 84vw); z-index: 40;
  font-size: 13.5px; line-height: 1.5; color: var(--text-soft); text-align: left;
}
.gterm-pop::after {
  content: ""; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  border: 7px solid transparent; border-top-color: var(--border-strong);
}
.gterm:hover .gterm-pop,
.gterm:focus .gterm-pop,
.gterm:focus-visible .gterm-pop,
.gterm.expanded .gterm-pop { display: block; }
.gterm:hover, .gterm:focus { color: var(--accent-2); }
.gterm.expanded { color: var(--accent-2); }
.gterm.expanded .gterm-pop { display: block; }
/* keep the click-open definition above neighbours */
.gterm.expanded { z-index: 30; }
/* terms inside tables would be clipped by the scroll container — never tooltip them */
.table-wrap .gterm-pop { display: none !important; }
.table-wrap .gterm { border-bottom: 0; cursor: text; }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; margin: 16px 0; background: var(--surface); }
table.tbl { border-collapse: collapse; width: 100%; font-size: 14.5px; }
.tbl th { background: var(--bg-alt); text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.tbl th, .tbl td { border-bottom: 1px solid var(--border); padding: 10px 14px; vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td:first-child { font-weight: 700; }

/* footer inside content */
.page-foot { margin-top: 56px; border-top: 1px solid var(--border); padding-top: 22px; display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.pager-link {
  display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: var(--text);
  border: 1px solid var(--border); background: var(--surface); border-radius: 12px;
  padding: 12px 18px; min-width: 220px; max-width: 46%;
}
.pager-link:hover { border-color: var(--accent); }
.pager-link small { color: var(--muted); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .1em; }
.pager-link .dir { font-weight: 800; font-size: 14.5px; }
.pager-link.next { margin-left: auto; text-align: right; }

.scan-note { margin-top: 28px; border-top: 1px dashed var(--border); padding-top: 14px; font-size: 13px; color: var(--muted); }
.scan-note a { word-break: break-word;
}

/* ---------- hero / dashboard ---------- */
.hero {
  background:
    radial-gradient(1100px 460px at 85% -10%, var(--accent-soft), transparent 60%),
    radial-gradient(700px 420px at -10% 110%, var(--blue-soft), transparent 55%),
    var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 58px 40px 50px; margin-top: 1px;
}
.hero-inner { width: min(920px, 100%); margin: 0 auto; }
.hero .eyebrow { font-size: 12px; letter-spacing: .22em; text-transform: uppercase; font-weight: 800; color: var(--accent); margin-bottom: 14px; }
.hero h1 { font-family: var(--font-serif); font-size: clamp(34px, 5.4vw, 54px); line-height: 1.06; margin: 0 0 14px; letter-spacing: -.015em; }
.hero p { font-size: 18px; color: var(--text-soft); max-width: 640px; font-family: var(--font-serif); }
.hero .actions { display: flex; gap: 12px; margin-top: 26px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; gap: 9px; text-decoration: none;
  background: var(--accent); color: #fff; font-weight: 800; font-size: 15px;
  padding: 13px 22px; border-radius: 12px; border: 1px solid transparent;
  box-shadow: 0 6px 18px rgba(179, 64, 31, .28); cursor: pointer; font-family: var(--font);
}
.btn:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border-strong); box-shadow: none; }
.btn.ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn.sm { padding: 9px 16px; font-size: 13.5px; border-radius: 10px; }

.grid-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); gap: 18px; margin: 22px 0; }
.mod-card {
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  background: var(--surface); text-decoration: none; color: var(--text);
  display: flex; flex-direction: column; transition: transform .15s ease, box-shadow .15s ease;
  box-shadow: var(--shadow);
}
.mod-card:hover { transform: translateY(-3px); }
.mod-card .mc-head { padding: 20px 20px 12px; border-left: 5px solid var(--accent); }
.mod-card.m2 .mc-head { border-left-color: var(--blue); }
.mod-card.m3 .mc-head { border-left-color: var(--green); }
.mod-card .mc-kicker { font-size: 11px; text-transform: uppercase; letter-spacing: .16em; font-weight: 800; color: var(--muted); }
.mod-card h3 { margin: 4px 0 4px; font-family: var(--font-serif); font-size: 21px; }
.mod-card .mc-sub { font-size: 13.5px; color: var(--text-soft); padding: 0 20px 12px; }
.mod-card .mc-meter { height: 5px; background: var(--bg-alt); margin: 0 20px 16px; border-radius: 4px; overflow: hidden; }
.mod-card .mc-meter span { display: block; height: 100%; background: var(--accent); width: 0%; }
.mod-card.m2 .mc-meter span { background: var(--blue); }
.mod-card.m3 .mc-meter span { background: var(--green); }
.mod-card .mc-foot { margin-top: auto; border-top: 1px solid var(--border); padding: 12px 20px; display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); font-weight: 700; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin: 14px 0 26px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; }
.stat .label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .1em; font-weight: 800; color: var(--muted); }
.stat .value { font-size: 26px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 12px; color: var(--text-soft); margin-top: 2px; }

/* ---------- quiz ---------- */
.quiz {
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  background: var(--surface); margin: 26px 0; box-shadow: var(--shadow);
}
.quiz .q-head {
  padding: 20px 24px; border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
}
.quiz .q-head .q-ico { width: 40px; height: 40px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 19px; flex: 0 0 auto; }
html[data-theme="dark"] .quiz .q-head .q-ico { color: #f0b39a; }
.quiz .q-head .q-title { font-weight: 800; font-size: 17px; }
.quiz .q-head .q-sub { font-size: 13px; color: var(--text-soft); }
.quiz .q-body { padding: 10px 24px 24px; }
.quiz .instructions { color: var(--text-soft); font-size: 15px; margin: 10px 0 4px; }
.quiz .materials { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 16px 20px; margin: 12px 0; }

.q-item { border-top: 1px dashed var(--border); padding: 18px 0 8px; margin-top: 14px; }
.q-item .q-num { font-weight: 800; color: var(--accent); margin-right: 8px; font-variant-numeric: tabular-nums; }
html[data-theme="dark"] .q-item .q-num { color: #f0a583; }
.q-item .q-stem { display: inline; }
.q-item .q-wrap { margin: 12px 0 6px; padding-left: 6px; }

.option-row { display: flex; gap: 12px; align-items: flex-start; padding: 8px 10px; border-radius: 10px; cursor: pointer; border: 1px solid transparent; }
.option-row:hover { background: var(--surface-2); border-color: var(--border); }
.option-row input { accent-color: var(--accent); margin-top: 4px; }
.option-row .o-letter { font-weight: 800; color: var(--text-soft); width: 18px; flex: 0 0 auto; font-variant-numeric: tabular-nums; }
.option-row .o-text { flex: 1; }
.option-row.picked { background: var(--accent-soft); border-color: transparent; }
.option-row.correct { background: var(--green-soft); border-color: var(--green); }
.option-row.wrong { background: var(--red-soft); border-color: var(--red); }
.q-item .feedback { display: none; margin: 10px 0 0; padding: 10px 14px; border-radius: 10px; font-size: 14px; }
.q-item.correct .feedback { display: block; background: var(--green-soft); color: var(--green); }
.q-item.wrong .feedback { display: block; background: var(--red-soft); color: var(--red); }
.feedback b { font-weight: 800; }

.match-q table, .order-q table { border-collapse: collapse; width: 100%; }
.match-q td, .order-q td { padding: 8px 8px; border-bottom: 1px dashed var(--border); vertical-align: middle; }
.match-q select, .order-q select, .gap-q input {
  font-family: var(--font); font-size: 14.5px; padding: 8px 10px; border-radius: 9px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); min-width: 150px;
}
.gap-q input { min-width: 220px; }
.options-pool { margin: 10px 0; padding: 12px 18px; background: var(--bg-alt); border-radius: 10px; font-size: 14.5px; }
.options-pool .opt { display: block; margin: 6px 0; }

.quiz .q-actions { display: flex; gap: 10px; justify-content: flex-end; padding: 16px 24px; border-top: 1px solid var(--border); background: var(--surface-2); flex-wrap: wrap; }
.quiz .result-band {
  display: none; margin: 0 24px 18px; padding: 16px 20px; border-radius: 12px;
  background: var(--green-soft); color: var(--green); font-weight: 800; font-size: 15px;
}
.quiz.done .result-band { display: block; }

/* accordion */
details.acc { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); margin: 12px 0; overflow: hidden; }
details.acc summary {
  cursor: pointer; padding: 13px 18px; font-weight: 800; font-size: 14.5px;
  display: flex; align-items: center; gap: 10px; list-style: none; user-select: none;
}
details.acc summary::-webkit-details-marker { display: none; }
details.acc summary::before { content: "▸"; color: var(--accent); font-size: 13px; transition: transform .15s; }
details.acc[open] summary::before { transform: rotate(90deg); }
details.acc .acc-body { padding: 4px 24px 18px; color: var(--text-soft); }
details.acc .acc-body table { margin: 8px 0; }

/* ---------- practice test (exam mode) ---------- */
.exam-top { position: sticky; top: 0; z-index: 30; margin: 0 -40px 26px; padding: 14px 40px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
@media (max-width: 1100px){ .exam-top { margin: 0 -18px 20px; padding: 12px 18px; } }
.exam-top .timer { font-weight: 800; font-variant-numeric: tabular-nums; font-size: 18px; background: var(--surface); border: 1px solid var(--border); padding: 6px 14px; border-radius: 10px; }
.exam-top .timer.low { color: var(--red); border-color: var(--red); }
.exam-top .filled { font-size: 13px; color: var(--text-soft); font-weight: 700; }
.exam-nav { margin-left: auto; display: grid; grid-template-columns: repeat(10, auto); gap: 5px; }
@media (max-width: 820px){ .exam-nav { display: flex; flex-wrap: wrap; } }
.exam-nav button {
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text-soft); font-size: 11.5px; font-weight: 800; cursor: pointer; font-variant-numeric: tabular-nums;
}
.exam-nav button.current { outline: 2px solid var(--accent); outline-offset: 1px; }
.exam-nav button.answered { background: var(--green-soft); color: var(--green); border-color: color-mix(in srgb, var(--green) 45%, transparent); }
.exam-item { display: none; }
.exam-item.current-item { display: block; }
.exam-item .stem .q-num { font-weight: 800; color: var(--accent); margin-right: 8px; }
.exam-controls { display: flex; gap: 12px; margin-top: 30px; flex-wrap: wrap; align-items: center; }
.exam-controls .spacer { flex: 1; }
.result-hero { text-align: center; padding: 34px 20px; }
.result-hero .big { font-size: 54px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--accent); }
.result-hero .small { color: var(--text-soft); font-weight: 700; }
.result-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-top: 22px; }
.review-item { border: 1px solid var(--border); border-radius: 12px; padding: 14px 18px; margin: 10px 0; background: var(--surface); }
.review-item .tags { display: flex; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.tag { font-size: 11px; font-weight: 800; padding: 3px 10px; border-radius: 999px; }
.tag.ok { background: var(--green-soft); color: var(--green); }
.tag.no { background: var(--red-soft); color: var(--red); }
.tag.qnum { background: var(--bg-alt); color: var(--muted); font-variant-numeric: tabular-nums; }
.review-item .your-answer { margin-top: 6px; font-size: 14px; }

/* ---------- flashcards ---------- */
.fc-deck { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; margin: 16px 0; }
.fc-tile { border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; text-align: center; background: var(--surface); }
.fc-tile .tt { font-weight: 800; font-size: 14px; }
.fc-tile .ts { font-size: 12px; color: var(--muted); font-weight: 700; margin-top: 4px; }
.fc-stage { perspective: 1400px; margin: 26px auto; max-width: 640px; }
.fc-card {
  position: relative; width: 100%; min-height: 300px; border-radius: 18px; transform-style: preserve-3d;
  transition: transform .5s cubic-bezier(.2, .8, .3, 1); cursor: pointer;
}
.fc-card.flipped { transform: rotateY(180deg); }
.fc-face {
  position: absolute; inset: 0; backface-visibility: hidden; border-radius: 18px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 34px; text-align: center; border: 1px solid var(--border-strong); box-shadow: var(--shadow);
}
.fc-face.front { background: linear-gradient(160deg, var(--surface), var(--surface-2)); }
.fc-face.back { background: linear-gradient(160deg, #fff, var(--accent-soft)); transform: rotateY(180deg); overflow-y: auto; justify-content: flex-start; padding-top: 26px; }
html[data-theme="dark"] .fc-face.back { background: linear-gradient(160deg, var(--surface), #33241d); }
.fc-face .term { font-family: var(--font-serif); font-size: 30px; font-weight: 800; line-height: 1.2; }
.fc-face .hint { color: var(--muted); font-size: 13px; margin-top: 14px; font-weight: 600; }
.fc-face .def { font-size: 16.5px; color: var(--text); line-height: 1.6; text-align: left; }
.fc-face .side-label { position: absolute; top: 14px; left: 18px; font-size: 11px; letter-spacing: .12em; font-weight: 800; color: var(--muted); text-transform: uppercase; }
.fc-controls { display: flex; gap: 10px; justify-content: center; margin: 8px 0 6px; flex-wrap: wrap; }
.fc-meta { text-align: center; color: var(--muted); font-size: 13px; font-weight: 700; }

/* ---------- glossary page ---------- */
.g-search-wrap { position: relative; margin: 14px 0 8px; }
.g-search-wrap input {
  width: 100%; font-size: 16px; padding: 13px 16px 13px 44px; border-radius: 12px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font-family: var(--font);
}
.g-search-wrap::before { content: "⌕"; position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 18px; }
.az-index { display: flex; flex-wrap: wrap; gap: 6px; margin: 16px 0; }
.az-index a {
  width: 30px; height: 30px; display: grid; place-items: center; font-weight: 800; font-size: 13px;
  border-radius: 8px; background: var(--surface); border: 1px solid var(--border);
  color: var(--text-soft); text-decoration: none;
}
.az-index a:hover { border-color: var(--accent); color: var(--accent); }
.az-index a.disabled { opacity: .3; pointer-events: none; }

/* ---------- search overlay ---------- */
.search-overlay { position: fixed; inset: 0; z-index: 100; display: none; background: rgba(20,16,9,.5); backdrop-filter: blur(3px); }
.search-overlay.open { display: block; }
.search-panel {
  width: min(680px, 92vw); margin: 9vh auto 0; background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 16px; box-shadow: var(--shadow);
  overflow: hidden; height: min(70vh, 640px); display: flex; flex-direction: column;
}
.search-panel .sp-top { display: flex; gap: 12px; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.search-panel input { flex: 1; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 18px; font-family: var(--font); }
.search-results { overflow-y: auto; padding: 8px; flex: 1; }
.search-hit { display: block; padding: 10px 12px; border-radius: 10px; text-decoration: none; color: var(--text); }
.search-hit:hover { background: var(--bg-alt); }
.search-hit .h-title { font-weight: 800; font-size: 14.5px; }
.search-hit .h-crumb { font-size: 11.5px; color: var(--muted); font-weight: 700; }
.search-hit .h-snippet { font-size: 13.5px; color: var(--text-soft); margin-top: 2px; }
.search-hit .h-snippet b { background: var(--amber-soft); color: var(--text); font-weight: 700; padding: 0 2px; border-radius: 3px; }
html[data-theme="dark"] .search-hit .h-snippet b { color: #ffd479; }
.sp-foot { padding: 10px 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); display: flex; gap: 14px; }

/* ---------- misc ---------- */
.done-banner { display: none; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: space-between; margin: 26px 0 0; border: 1px solid var(--green); background: var(--green-soft); color: var(--green); padding: 16px 20px; border-radius: 12px; font-weight: 800; }
.done-banner.show { display: flex; }
.done-banner .btn-undo { border: 0; background: transparent; color: var(--green); cursor: pointer; font-weight: 800; text-decoration: underline; font-family: var(--font); font-size: 14px; }
.banner-flash { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 11px 20px; border-radius: 999px; font-size: 14px; font-weight: 700; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 120; }
.banner-flash.show { opacity: 1; }

.unit-block { margin-bottom: 8px; }
hr.sep { border: 0; border-top: 1px dashed var(--border); margin: 30px 0; }
.small-note { font-size: 13px; color: var(--muted); }
.sketch { color: var(--muted); font-size: 13.5px; }
code { background: var(--bg-alt); padding: 2px 7px; border-radius: 6px; font-size: .9em; }

@media print {
  .sidebar, .toolbar, .topbar, .quiz .q-actions, .exam-nav, .scan-note, .pager-link { display: none !important; }
  .content { width: 100%; padding: 20px; }
  body { background: #fff; }
}

/* select-row scoring states */
.match-q select.correct, .order-q select.correct {
  border-color: var(--green); background: var(--green-soft); color: var(--green); font-weight: 800;
}
.match-q select.wrong, .order-q select.wrong {
  border-color: var(--red); background: var(--red-soft); color: var(--red); font-weight: 800;
}
.q-item.correct .feedback b { color: var(--green); }
.q-item.wrong .feedback b { color: var(--red); }
.exam-item.ok { border-color: var(--green); }
.exam-item.no { border-color: var(--red); }
.review-item.r-no { border-color: color-mix(in srgb, var(--red) 40%, transparent); }
.review-item.r-ok { border-color: color-mix(in srgb, var(--green) 40%, transparent); }

/* glossary A–Z letters with no entries */
.az-index .az-off {
  width: 30px; height: 30px; display: grid; place-items: center; font-weight: 800;
  font-size: 13px; border-radius: 8px; color: var(--muted); opacity: .35;
  border: 1px dashed var(--border);
}

/* ---------- toasts (top-center, above content) ---------- */
.toast-stack {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: 10px;
  align-items: center; pointer-events: none; width: min(720px, 94vw);
}
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border-strong); color: var(--text);
  padding: 11px 15px; border-radius: 12px; box-shadow: var(--shadow);
  font-size: 14px; font-weight: 700; line-height: 1.4;
  opacity: 0; transform: translateY(-12px) scale(.98); transition: opacity .2s ease, transform .2s ease;
}
.toast.in { opacity: 1; transform: none; }
.toast.out { opacity: 0; transform: translateY(-10px) scale(.98); }
.toast-ok { background: var(--green-soft); border-color: color-mix(in srgb, var(--green) 45%, transparent); color: var(--green); }
.toast-plain { color: var(--text-soft); }
.toast-ico { font-size: 15px; flex: 0 0 auto; }
.toast-msg { flex: 1; min-width: 0; }
.toast-action {
  flex: 0 0 auto; border: 0; background: transparent; color: inherit; cursor: pointer;
  font: inherit; font-weight: 800; text-decoration: underline; padding: 2px 4px; border-radius: 6px;
}
.toast-action:hover { background: rgba(0,0,0,.06); }
@media (max-width: 1100px) { .toast-stack { top: 62px; } }

/* mark-studied button state */
.tool-btn.is-done {
  background: var(--green-soft); color: var(--green);
  border-color: color-mix(in srgb, var(--green) 45%, transparent);
}
.tool-btn .mb-ico { font-weight: 800; }

/* mobile nav close button */
.nav-close {
  display: none; position: absolute; top: 14px; right: 12px;
  width: 34px; height: 34px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-soft);
  font-size: 18px; line-height: 1; align-items: center; justify-content: center;
}
@media (max-width: 1100px) {
  .nav-close { display: flex; }
  body.nav-open { overflow: hidden; }
}

/* ==========================================================================
   RESPONSIVE — phone / tablet / desktop
   Breakpoints: 1200 (small desktop), 1100 (drawer below), 900 (tablet), 640 (phone)
   ========================================================================== */

html { scroll-padding-top: 72px; }
body { overflow-x: hidden; }
.content p, .content li { max-width: 72ch; }
.content p { line-height: 1.68; }

/* --- small desktop ------------------------------------------------------- */
@media (max-width: 1200px) {
  :root { --sidebar-w: 280px; }
  .content { width: min(820px, 100%); padding: 34px 28px 110px; }
}

/* --- tablet / mobile: drawer navigation ---------------------------------- */
@media (max-width: 1100px) {
  .sidebar { width: min(86vw, 340px); flex-basis: auto; }
  .brand { padding: 18px 16px 12px; }
  .brand-badge { width: 38px; height: 38px; font-size: 13px; }
  .nav { padding-bottom: max(30px, env(safe-area-inset-bottom)); }
  .content {
    padding: 22px 22px calc(96px + env(safe-area-inset-bottom));
    width: 100%;
  }
  .toolbar { display: none; }
  .topbar { padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); }
  .topbar-title { font-size: 14.5px; }
}

/* --- tablet -------------------------------------------------------------- */
@media (max-width: 900px) {
  body { font-size: 16px; }
  .content { padding: 20px 18px calc(92px + env(safe-area-inset-bottom)); }
  .content h1 { font-size: clamp(26px, 6.2vw, 34px); }
  .content h2 { font-size: clamp(20px, 4.6vw, 25px); margin-top: 34px; }
  .content h3 { font-size: 17.5px; }
  .lead { font-size: 17px; }
  .hero { padding: 40px 20px 34px; }
  .hero h1 { font-size: clamp(30px, 7.4vw, 42px); }
  .hero p { font-size: 16.5px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-cards { grid-template-columns: 1fr; }
  .card { padding: 20px 18px; }
  .callout { padding: 14px 16px; }
  .quiz .q-head { padding: 16px 18px; }
  .quiz .q-body { padding: 8px 18px 18px; }
  .quiz .q-actions { padding: 14px 18px; }
  .quiz .result-band { margin: 0 18px 16px; }

  /* tables: comfortable horizontal scroll with a shadow hint */
  .table-wrap { -webkit-overflow-scrolling: touch; position: relative; }
  table.tbl { font-size: 14px; }
  .tbl th, .tbl td { padding: 9px 11px; }
  /* hint is added by JS only when the table actually overflows */

  /* exam mode */
  .exam-top { flex-wrap: wrap; gap: 8px; padding: 10px 16px; margin: 0 -18px 18px; }
  .exam-top .timer { font-size: 16px; padding: 5px 11px; }
  .exam-nav { order: 3; width: 100%; margin-left: 0; display: flex; flex-wrap: nowrap; overflow-x: auto; gap: 6px; padding-bottom: 4px; }
  .exam-nav button { width: 34px; height: 34px; flex: 0 0 auto; }
  .exam-item { padding: 16px 16px; }
  .exam-controls {
    position: sticky; bottom: 0; z-index: 25;
    background: color-mix(in srgb, var(--bg) 94%, transparent);
    backdrop-filter: blur(8px);
    margin: 0 -18px; padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
  }

  /* search panel: near full-screen */
  .search-panel { width: 94vw; height: min(78vh, 620px); margin-top: 6vh; }
  .sp-foot { display: none; }
}

/* --- phone --------------------------------------------------------------- */
@media (max-width: 640px) {
  body { font-size: 15.5px; }
  .content { padding: 16px 14px calc(88px + env(safe-area-inset-bottom)); }
  .content h1 { font-size: clamp(23px, 7vw, 29px); line-height: 1.18; }
  .content h2 { font-size: 19.5px; gap: 9px; margin-top: 30px; }
  .content h2 .h-ico { width: 30px; height: 30px; font-size: 15px; }
  .content h3 { font-size: 16.5px; }
  .content ul, .content ol { padding-left: 20px; }
  .hero { padding: 32px 16px 28px; }
  .hero h1 { font-size: clamp(26px, 9vw, 34px); }
  .hero .actions { gap: 9px; }
  .hero .actions .btn { flex: 1 1 100%; justify-content: center; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 13px 14px; }
  .stat .value { font-size: 22px; }
  .unit-meta .chip { font-size: 11px; }
  .crumbs { font-size: 12px; }

  .callout { padding: 13px 14px; border-radius: 10px; }
  .callout > .co-head { font-size: 11.5px; }
  .card { padding: 16px 14px; border-radius: 12px; }

  /* quiz: big tap targets */
  .quiz .q-head { padding: 14px; gap: 10px; }
  .quiz .q-head .q-ico { width: 34px; height: 34px; font-size: 16px; }
  .quiz .q-head .q-title { font-size: 15.5px; }
  .quiz .q-body { padding: 6px 14px 14px; }
  .quiz .q-actions { padding: 12px 14px; flex-direction: column-reverse; }
  .quiz .q-actions .btn { width: 100%; justify-content: center; }
  .option-row { padding: 11px 10px; min-height: 46px; align-items: center; }
  .option-row input[type="radio"] { width: 20px; height: 20px; margin-top: 0; }
  .q-item { padding: 14px 0 6px; }
  .match-q select, .order-q select, .gap-q input { min-width: 0; width: 100%; }
  .match-q table, .order-q table { font-size: 14px; }
  .match-q td, .order-q td { padding: 7px 6px; }
  .match-q td:last-child { width: 76px; }
  .options-pool { padding: 10px 12px; font-size: 14px; }

  /* flashcards */
  .fc-stage { margin: 14px auto; }
  .fc-card { min-height: 230px; }
  .fc-face { padding: 20px 16px; }
  .fc-face .term { font-size: 23px; }
  .fc-face .def { font-size: 15px; line-height: 1.55; }
  .fc-controls { gap: 8px; }
  .fc-controls .btn { flex: 1 1 auto; justify-content: center; }
  .deck-picker .tool-btn { flex: 1 1 44%; font-size: 12px; }

  /* glossary */
  .g-search-wrap { position: sticky; top: 58px; z-index: 20; background: var(--bg); padding: 6px 0; }
  .term-row { padding: 11px 12px; }
  .az-index a, .az-index .az-off { width: 27px; height: 27px; font-size: 12px; }

  /* exam */
  .exam-top { padding: 8px 12px; margin: 0 -14px 14px; }
  .exam-top .filled { font-size: 12px; }
  .exam-top .js-finish { width: 100%; margin-left: 0 !important; }
  .exam-controls { margin: 0 -14px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); }
  .exam-controls .btn { flex: 1 1 auto; justify-content: center; }
  .review-item { padding: 12px 14px; }
  .result-hero .big { font-size: 44px; }

  /* toast sits below the top bar, full width */
  .toast-stack { top: 58px; width: 94vw; }
  .toast { font-size: 13.5px; padding: 10px 13px; }

  /* footer */
  footer { padding: 16px !important; font-size: 11.5px !important; }
}

/* --- touch devices: comfortable hit areas, no iOS zoom on focus ---------- */
@media (pointer: coarse) {
  .nav-link { padding: 11px 10px; font-size: 14.5px; }
  .nav-link .num { width: 28px; height: 24px; }
  .tool-btn, .btn { min-height: 44px; }
  .btn.sm { min-height: 40px; }
  input[type="text"], input[type="search"], select, textarea { font-size: 16px !important; }
  .g-search-wrap input { padding-top: 14px; padding-bottom: 14px; }
  .js-fc-rate { min-height: 42px; }
  .az-index a, .az-index .az-off { width: 32px; height: 32px; }
  .exam-nav button { width: 38px; height: 38px; }
  .match-q select, .order-q select { min-height: 42px; }
}

/* --- landscape phones: keep content readable ---------------------------- */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .fc-card { min-height: 190px; }
  .hero { padding: 24px 18px 20px; }
}

/* --- reduced motion ------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
  html { scroll-behavior: auto; }
}

/* wide tables: visible affordance when horizontally scrollable */
.table-wrap { position: relative; }
.table-wrap.is-scrollable { box-shadow: inset -14px 0 14px -12px rgba(38, 32, 20, .28); }
html[data-theme="dark"] .table-wrap.is-scrollable { box-shadow: inset -14px 0 14px -12px rgba(0, 0, 0, .7); }
.table-wrap.is-scrollable::after {
  content: "→ scroll"; position: sticky; left: 100%; bottom: 6px;
  display: inline-block; float: right; margin: -22px 8px 6px 0;
  font-size: 10px; font-weight: 800; letter-spacing: .06em;
  color: var(--muted); background: var(--surface); border: 1px solid var(--border);
  padding: 1px 7px; border-radius: 6px; pointer-events: none;
}

/* glossary provenance badges */
.src-badge {
  display: inline-block; font-size: 9.5px; font-weight: 800; letter-spacing: .08em;
  text-transform: uppercase; padding: 1px 6px; border-radius: 5px; vertical-align: middle;
  border: 1px solid transparent;
}
.src-badge.official { background: var(--blue-soft); color: var(--blue); }
.src-badge.book { background: var(--amber-soft); color: var(--amber); }
