/* ============ Theme tokens ============ */
:root {
  --brand: #0E5247;
  --brand-2: #0b3f37;
  --accent: #a08a5e;
  --accent-soft: #efe7d6;
  --gold: #a08a5e;
  --lime: #B6F24A;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(15,40,55,.06), 0 1px 3px rgba(15,40,55,.05);
  --shadow-md: 0 6px 22px rgba(15,55,75,.10);
  --shadow-lg: 0 22px 60px rgba(10,40,60,.22);
  --maxw: 1180px;
  --ease: cubic-bezier(.22,.61,.36,1);
}
html[data-theme="light"] {
  --bg: #FBF9F2;
  --bg-2: #F3EFE4;
  --paper: #ffffff;
  --ink: #14322C;
  --ink-soft: #3f5751;
  --muted: #5b6b66;
  --line: #e7e1d3;
  --line-2: #ddd6c4;
  --soft: #EAF5EF;
  --ring-track: #e6edf4;
  --kbd-bg: #f0f4f8;
  --glass: rgba(255,255,255,.82);
}
html[data-theme="dark"] {
  --brand: #5fc9b3;
  --brand-2: #49b89f;
  --accent: #c9b487;
  --accent-soft: #2e2a1d;
  --gold: #c9b487;
  --lime: #B6F24A;
  --bg: #0b1613;
  --bg-2: #0f1d19;
  --paper: #122019;
  --ink: #e9efe9;
  --ink-soft: #b2c2bb;
  --muted: #84978f;
  --line: #20312b;
  --line-2: #2a3f37;
  --soft: #14302a;
  --ring-track: #223344;
  --kbd-bg: #1b2a38;
  --glass: rgba(16,26,36,.82);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow-md: 0 8px 26px rgba(0,0,0,.45);
  --shadow-lg: 0 24px 64px rgba(0,0,0,.6);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: "Hanken Grotesk", "Hind Siliguri", Inter, system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1100px 500px at 78% -8%, color-mix(in srgb, var(--brand) 12%, transparent), transparent 60%),
    var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
.bn, [lang="bn"] { font-family: "Hind Siliguri", "Tiro Bangla", "Noto Serif Bengali", serif; }
h1, h2, h3, .serif { font-family: "Newsreader", Fraunces, Georgia, serif; }
a { color: var(--brand); }
kbd {
  font: 600 11px Inter, sans-serif;
  background: var(--kbd-bg);
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 5px;
  color: var(--ink-soft);
}

/* ============ App bar ============ */
.appbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 16px;
  padding: 11px 22px;
  background: var(--glass);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; color: var(--ink); margin-right: auto; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(140deg, var(--brand), var(--brand-2));
  color: #fff; font: 800 19px Fraunces, serif; box-shadow: var(--shadow-sm);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 15px; letter-spacing: -.01em; }
.brand-text small { color: var(--muted); font-size: 11.5px; }
.appbar-actions { display: flex; align-items: center; gap: 9px; }

.cmdk {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px 7px 11px; border: 1px solid var(--line-2);
  background: var(--paper); color: var(--muted);
  border-radius: 9px; cursor: pointer; font: inherit; font-size: 13px;
}
.cmdk:hover { border-color: var(--brand); color: var(--ink); }
.cmdk kbd { margin-left: 4px; }

.icon-btn {
  position: relative;
  width: 38px; height: 38px; display: grid; place-items: center;
  border: 1px solid var(--line-2); background: var(--paper); color: var(--ink-soft);
  border-radius: 9px; cursor: pointer;
}
.icon-btn:hover { border-color: var(--brand); color: var(--brand); }
.badge-count {
  position: absolute; top: -6px; right: -6px; min-width: 17px; height: 17px;
  padding: 0 4px; border-radius: 9px; background: var(--accent); color: #fff;
  font: 700 10px Inter, sans-serif; display: grid; place-items: center;
}
.ico-moon { display: none; }
html[data-theme="dark"] .ico-sun { display: none; }
html[data-theme="dark"] .ico-moon { display: block; }

.lang { display: flex; gap: 2px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px; padding: 2px; }
.lang button { border: 0; background: transparent; color: var(--muted); padding: 5px 9px; border-radius: 7px; cursor: pointer; font: 600 12px Inter, sans-serif; }
.lang button.active { background: var(--paper); color: var(--brand); box-shadow: var(--shadow-sm); }

/* ============ Hero ============ */
main { max-width: var(--maxw); margin: 0 auto; padding: 22px; }
.hero { padding: 40px 6px 14px; }
.eyebrow { margin: 0 0 14px; font: 700 12px Inter, sans-serif; letter-spacing: .12em; text-transform: uppercase; color: var(--brand-2); }
.hero h1 { margin: 0; font-size: clamp(30px, 5vw, 52px); line-height: 1.04; letter-spacing: -.02em; font-weight: 600; }
.hero h1 span { color: var(--brand); font-style: italic; }
.lede { max-width: 640px; margin: 16px 0 24px; font-size: 17px; color: var(--ink-soft); }
.hero-search { margin-bottom: 26px; }
.hero-search-btn {
  display: flex; align-items: center; gap: 11px; width: min(540px, 100%);
  padding: 14px 16px; border: 1px solid var(--line-2); background: var(--paper);
  border-radius: 12px; cursor: text; color: var(--muted); font: inherit; font-size: 15px;
  box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s;
}
.hero-search-btn:hover { border-color: var(--brand); box-shadow: var(--shadow-md); }
.hero-search-btn span { margin-right: auto; text-align: left; }

.stats { display: flex; flex-wrap: wrap; gap: 12px; }
.stat { display: flex; flex-direction: column; padding: 14px 18px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-sm); min-width: 120px; box-shadow: var(--shadow-sm); }
.stat b { font: 700 26px Fraunces, serif; color: var(--brand); line-height: 1; }
.stat span { font-size: 12.5px; color: var(--muted); margin-top: 5px; }
.stat.progress-stat b { color: var(--accent); }

/* ============ Semester tabs ============ */
#semtabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 30px 0 6px; }
.semtab { border: 1px solid var(--line-2); background: var(--paper); color: var(--ink-soft); padding: 8px 14px; border-radius: 999px; cursor: pointer; font: 600 13px Inter, sans-serif; }
.semtab:hover { border-color: var(--brand); color: var(--brand); }
.semtab.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ============ Subject grids ============ */
.sem-section { margin: 26px 0 8px; }
.sem-section > h2 { font-size: 19px; color: var(--ink); margin: 0 0 4px; font-weight: 600; }
.sem-section > .sub { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }

.card {
  position: relative; display: flex; flex-direction: column;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 16px 14px; cursor: pointer; box-shadow: var(--shadow-sm);
  transition: transform .16s var(--ease), box-shadow .16s var(--ease), border-color .16s;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--line-2); }
.card-top { display: flex; align-items: flex-start; gap: 10px; }
.card .code { font: 800 13px Inter, sans-serif; letter-spacing: .04em; color: var(--brand); background: var(--soft); padding: 3px 8px; border-radius: 6px; }
.card-star { margin-left: auto; background: none; border: 0; cursor: pointer; color: var(--line-2); padding: 0; line-height: 0; }
.card-star:hover { color: var(--accent); }
.card-star.on { color: var(--accent); }
.card .title { font-size: 15px; font-weight: 600; margin: 11px 0 3px; line-height: 1.3; }
.card .title-bn { font-size: 13px; color: var(--muted); min-height: 17px; }
.card-foot { display: flex; align-items: center; gap: 10px; margin-top: 13px; padding-top: 12px; border-top: 1px solid var(--line); }
.badge { font: 700 10.5px Inter, sans-serif; padding: 3px 9px; border-radius: 999px; background: var(--soft); color: var(--brand-2); }
.badge.Minor { background: #fdf1e0; color: #b56a16; }
.badge.Elective { background: #ece6f5; color: #6a4ca0; }
.badge.SEC { background: #e4f4ea; color: #1b7a3a; }
.badge.MDC { background: #fde2e7; color: #b23a64; }
.badge.CRM { background: #e2eefd; color: #2b5fa8; }
html[data-theme="dark"] .badge { background: #14303c; color: var(--brand); }
html[data-theme="dark"] .badge.Minor { background: #3a2c14; color: #e0a458; }
html[data-theme="dark"] .badge.Elective { background: #2c2440; color: #b79fe0; }
html[data-theme="dark"] .badge.SEC { background: #163524; color: #6fc48c; }
html[data-theme="dark"] .badge.MDC { background: #3a1b27; color: #e58aa6; }
html[data-theme="dark"] .badge.CRM { background: #16283f; color: #8fb6e8; }
.card-pdf { margin-left: auto; font-size: 12.5px; color: var(--muted); text-decoration: none; }
.card-pdf:hover { color: var(--brand); }
.card-ppt { margin-left: 12px; color: var(--brand); }
.card-ppt:hover { color: var(--accent); }

/* progress ring */
.ring { --p: 0; width: 34px; height: 34px; flex: none; }
.ring svg { transform: rotate(-90deg); }
.ring .track { stroke: var(--ring-track); }
.ring .bar { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .5s var(--ease); }
.ring .pct { font: 700 9px Inter, sans-serif; fill: var(--ink-soft); }
.card-foot .ring { margin-left: auto; }

/* ============ Reader ============ */
#reader { padding-top: 6px; }
.crumbs { font-size: 13px; color: var(--muted); margin: 6px 0 12px; }
.crumbs a { text-decoration: none; }
.crumbs b { color: var(--ink); }
.reader-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; position: sticky; top: 60px; z-index: 20; background: var(--bg); padding: 8px 0; }
.tb { border: 1px solid var(--line-2); background: var(--paper); color: var(--ink-soft); border-radius: 9px; padding: 8px 12px; cursor: pointer; font: 600 13px Inter, sans-serif; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.tb:hover { border-color: var(--brand); color: var(--brand); }
.tb-accent { background: var(--brand); border-color: var(--brand); color: #fff; }
.tb-accent:hover { color: #fff; filter: brightness(1.05); }
.tb-pdf { margin-left: auto; background: var(--accent); border-color: var(--accent); color: #fff; }
.tb-pdf:hover { color: #fff; filter: brightness(1.05); }
.tb-ppt { background: var(--brand); border-color: var(--brand); color: #fff; }
.tb-ppt:hover { color: #fff; filter: brightness(1.08); }

.reader-body { display: grid; grid-template-columns: 248px 1fr; gap: 26px; align-items: start; margin-top: 8px; }
.reader-body > * { min-width: 0; }
#toc { position: sticky; top: 110px; max-height: calc(100vh - 130px); overflow: auto; padding: 12px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); font-size: 13px; }
.toc-title { font: 700 12px Inter, sans-serif; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 4px 6px 8px; }
#toc a { display: block; color: var(--ink-soft); text-decoration: none; padding: 5px 8px; border-radius: 7px; line-height: 1.35; border-left: 2px solid transparent; }
#toc a.h3 { padding-left: 16px; font-size: 12.5px; color: var(--muted); }
#toc a:hover { background: var(--soft); color: var(--brand); }
#toc a.active { color: var(--brand); border-left-color: var(--brand); background: var(--soft); }

#content { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 30px 36px; box-shadow: var(--shadow-sm); min-width: 0; overflow-wrap: break-word; }
#content > h1:first-child { margin-top: 0; }
#content h1, #content h2 { color: var(--ink); font-weight: 600; letter-spacing: -.01em; }
#content h2 { font-size: 22px; margin-top: 34px; padding-bottom: 8px; border-bottom: 2px solid var(--line); }
#content h3 { font-size: 16.5px; margin-top: 26px; color: var(--brand-2); scroll-margin-top: 120px; }
#content p, #content li { color: var(--ink-soft); }
#content strong { color: var(--ink); }
#content .table-scroll { overflow-x: auto; max-width: 100%; margin: 12px 0 18px; }
#content table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
#content th, #content td { border: 1px solid var(--line); padding: 8px 9px; vertical-align: top; text-align: left; }
#content th { background: var(--soft); color: var(--ink); }
#content blockquote { border-left: 4px solid var(--brand); background: var(--soft); margin: 14px 0; padding: 10px 16px; border-radius: 0 10px 10px 0; }
#content code { background: var(--bg-2); padding: 1px 5px; border-radius: 5px; font-size: 13px; overflow-wrap: anywhere; word-break: break-word; }
#content pre { overflow-x: auto; max-width: 100%; }
#content figure { margin: 16px 0; text-align: center; }
#content img { max-width: 520px; width: 100%; display: block; margin: 14px auto; border: 1px solid var(--line); border-radius: 10px; }
#content figcaption { font-style: italic; font-size: 13px; color: var(--muted); margin-top: 6px; }
#content i, #content em { font-style: italic; }
#content .katex-display { overflow-x: auto; overflow-y: hidden; max-width: 100%; padding: 6px 2px; margin: 14px 0; }
#content .katex { font-size: 1.04em; }
/* keep KaTeX a11y MathML clipped so it never contributes layout width (mobile overflow guard) */
#content .katex-mathml { position: absolute !important; clip: rect(1px,1px,1px,1px) !important; width: 1px !important; height: 1px !important; overflow: hidden !important; padding: 0 !important; border: 0 !important; }

/* question row: checkbox + bookmark + heading */
.q-row { position: relative; display: flex; align-items: flex-start; gap: 10px; margin-top: 26px; padding-right: 92px; scroll-margin-top: 120px; }
.q-row .q-check { flex: none; margin-top: 2px; width: 20px; height: 20px; border: 1.5px solid var(--line-2); border-radius: 6px; background: var(--paper); cursor: pointer; display: grid; place-items: center; color: transparent; }
.q-row .q-check.done { background: var(--brand); border-color: var(--brand); color: #fff; }
.q-row .q-star { flex: none; margin-top: 1px; background: none; border: 0; cursor: pointer; color: var(--line-2); }
.q-row .q-star.on { color: var(--accent); }
.q-row h3 { margin: 0; flex: 1; }
.q-row.done h3 { color: var(--muted); }

.ans-toggle { display: inline-flex; align-items: center; gap: 6px; margin: 8px 0 8px 30px; background: color-mix(in srgb, var(--brand) 10%, var(--paper)); color: var(--brand); border: 1px solid color-mix(in srgb, var(--brand) 28%, var(--line)); border-radius: 8px; padding: 5px 12px; cursor: pointer; font: 600 12.5px Inter, sans-serif; }
.ans-toggle:hover { background: color-mix(in srgb, var(--brand) 16%, var(--paper)); }
.answer { display: none; border-left: 3px solid var(--brand); background: var(--soft); border-radius: 0 10px 10px 0; padding: 4px 18px; margin: 0 0 12px 30px; }
.answer.open { display: block; }

/* ============ Command palette ============ */
.palette { position: fixed; inset: 0; z-index: 80; background: rgba(10,25,35,.42); backdrop-filter: blur(3px); display: flex; align-items: flex-start; justify-content: center; padding-top: 12vh; }
.palette.hidden { display: none; }
.palette-box { width: min(640px, 92vw); background: var(--paper); border: 1px solid var(--line-2); border-radius: 16px; box-shadow: var(--shadow-lg); overflow: hidden; animation: pop .14s var(--ease); }
@keyframes pop { from { transform: translateY(-8px) scale(.985); opacity: .4; } }
.palette-input { display: flex; align-items: center; gap: 11px; padding: 16px 18px; border-bottom: 1px solid var(--line); color: var(--muted); }
.palette-input input { flex: 1; border: 0; background: none; font: 500 17px Inter, "Noto Serif Bengali", sans-serif; color: var(--ink); outline: none; }
.palette-results { max-height: 52vh; overflow: auto; padding: 8px; }
.p-group { font: 700 11px Inter, sans-serif; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); padding: 10px 12px 5px; }
.p-item { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 10px; cursor: pointer; }
.p-item .p-code { font: 700 11px Inter, sans-serif; color: var(--brand); background: var(--soft); padding: 2px 7px; border-radius: 5px; flex: none; }
.p-item .p-text { flex: 1; min-width: 0; font-size: 14px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-item .p-sub { font-size: 12px; color: var(--muted); flex: none; }
.p-item.sel, .p-item:hover { background: var(--soft); }
.p-item.sel { outline: 2px solid color-mix(in srgb, var(--brand) 40%, transparent); }
.p-empty { padding: 26px; text-align: center; color: var(--muted); font-size: 14px; }
.palette-foot { display: flex; gap: 16px; align-items: center; padding: 9px 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.palette-foot #paletteStatus { margin-left: auto; }

/* ============ Flashcards ============ */
.flash { position: fixed; inset: 0; z-index: 90; background: var(--bg); display: flex; flex-direction: column; }
.flash.hidden { display: none; }
.flash-top { display: flex; align-items: center; gap: 16px; padding: 16px 22px; border-bottom: 1px solid var(--line); }
.flash-top #flashTitle { font: 600 16px Fraunces, serif; }
.flash-progress { flex: 1; height: 7px; background: var(--ring-track); border-radius: 999px; overflow: hidden; }
.flash-progress #flashBar { height: 100%; width: 0; background: linear-gradient(90deg, var(--brand), var(--accent)); transition: width .3s var(--ease); }
.flash-stage { flex: 1; display: grid; place-items: center; padding: 24px; perspective: 1600px; }
.flash-card { width: min(680px, 94vw); height: min(60vh, 460px); position: relative; transform-style: preserve-3d; transition: transform .5s var(--ease); cursor: pointer; }
.flash-card.flipped { transform: rotateY(180deg); }
.flash-face { position: absolute; inset: 0; backface-visibility: hidden; background: var(--paper); border: 1px solid var(--line-2); border-radius: 20px; box-shadow: var(--shadow-md); padding: 30px 34px; overflow: auto; }
.flash-back { transform: rotateY(180deg); }
.flash-tag { font: 700 11px Inter, sans-serif; letter-spacing: .1em; text-transform: uppercase; color: var(--brand); margin-bottom: 14px; }
.flash-back .flash-tag { color: var(--accent); }
#flashQ { font: 600 21px Fraunces, "Noto Serif Bengali", serif; color: var(--ink); }
#flashA { font-size: 14.5px; color: var(--ink-soft); line-height: 1.55; }
#flashA table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
#flashA th, #flashA td { border: 1px solid var(--line); padding: 5px 7px; }
.flash-hint { position: absolute; bottom: 18px; left: 0; right: 0; text-align: center; color: var(--muted); font-size: 12.5px; }
.flash-controls { display: flex; gap: 12px; align-items: center; justify-content: center; padding: 18px; border-top: 1px solid var(--line); }
.flash-yes { background: #e4f4ea; border-color: #b8e0c6; color: #1b7a3a; }
.flash-no { background: #fdeaea; border-color: #f3cccc; color: #b23a3a; }
html[data-theme="dark"] .flash-yes { background: #163524; border-color: #2a5a3c; color: #6fc48c; }
html[data-theme="dark"] .flash-no { background: #3a1c1c; border-color: #5a2c2c; color: #e58a8a; }
.flash-count { color: var(--muted); font-size: 13px; margin-left: 8px; }

/* ============ Bookmarks view ============ */
.view-title { font-size: 24px; font-weight: 600; margin: 14px 0 18px; }
.bm-item { display: flex; align-items: center; gap: 12px; padding: 14px 16px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 10px; cursor: pointer; box-shadow: var(--shadow-sm); }
.bm-item:hover { border-color: var(--brand); }
.bm-item .p-code { font: 700 11px Inter, sans-serif; color: var(--brand); background: var(--soft); padding: 3px 8px; border-radius: 5px; }
.bm-item .bm-q { flex: 1; font-size: 14.5px; color: var(--ink); }
.bm-remove { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 18px; }
.bm-remove:hover { color: var(--accent); }
.empty-state { text-align: center; color: var(--muted); padding: 50px 20px; }

/* ============ Footer ============ */
footer { max-width: var(--maxw); margin: 30px auto 0; padding: 22px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12.5px; display: flex; flex-wrap: wrap; gap: 8px; }
footer .dot { opacity: .5; }
footer code { background: var(--bg-2); padding: 1px 5px; border-radius: 4px; }

/* ============ Responsive ============ */
@media (max-width: 860px) {
  body { overflow-x: hidden; }
  .appbar { flex-wrap: wrap; row-gap: 8px; padding: 10px 14px; }
  .reader-body { grid-template-columns: 1fr; }
  #toc { position: static; max-height: 40vh; order: -1; }
  .brand-text small { display: none; }
  .cmdk span { display: none; }
  .reader-toolbar { top: 0; }
}
@media (max-width: 560px) {
  main { padding: 16px; }
  #content { padding: 20px 18px; }
  .lang button { padding: 5px 7px; }
  .stat { flex: 1; min-width: 0; }
}

/* ============ Print ============ */
@media print {
  .appbar, #semtabs, #toc, .reader-toolbar, footer, .palette, .flash, .hero { display: none !important; }
  .reader-body { grid-template-columns: 1fr; }
  .answer { display: block !important; }
  .ans-toggle, .q-check, .q-star { display: none !important; }
  #content { border: 0; box-shadow: none; padding: 0; }
}

/* ============================================================
   Readability layer (2026-07-30)
   Long-form study reading: measure, rhythm, scanning hierarchy.
   Measured before: 100 chars/line, line-height 1.55, h3 16.5px vs body 16px.
   ============================================================ */

/* 1. Reading measure. Prose is capped; tables, figures and math stay full width. */
#content p,
#content li,
#content blockquote {
  max-width: 66ch;   /* ~74 average characters; the ch unit is the width of "0" */
}

/* 2. Reading rhythm and size. */
#content {
  font-size: 16.75px;
  line-height: 1.72;
}
#content p { margin: 0 0 1.05em; }
#content ul, #content ol { margin: 0 0 1.15em; padding-left: 1.35em; }
#content li { margin-bottom: .42em; }
#content li::marker { color: var(--accent); }

/* 3. Scanning hierarchy. 68 question headings per paper need to be findable. */
#content h2 {
  font-size: 25px;
  line-height: 1.25;
  margin-top: 2.4em;
  letter-spacing: -.015em;
  text-wrap: balance;
}
#content h3 {
  font-size: 20px;
  line-height: 1.32;
  font-weight: 600;
  margin-top: 2em;
  margin-bottom: .55em;
  padding-left: .7em;
  border-left: 3px solid var(--accent);
  text-wrap: pretty;
}
#content h4 { font-size: 17px; margin-top: 1.5em; margin-bottom: .4em; color: var(--ink); }

/* 4. Answer blocks: give the model answer a calm, distinct field. */
#content p > strong:first-child { color: var(--brand-2); }

/* 5. Tables. 34 per paper, previously 13.5px. */
#content table { font-size: 14.5px; line-height: 1.5; }
#content th, #content td { padding: 10px 12px; }
#content thead th,
#content tr:first-child th {
  background: var(--soft);
  font-weight: 600;
}
#content tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--bg-2) 45%, transparent); }
#content .table-scroll { border: 1px solid var(--line); border-radius: var(--radius-sm); }
#content .table-scroll table { margin: 0; }
#content .table-scroll th:first-child,
#content .table-scroll td:first-child { padding-left: 14px; }

/* 6. Long tokens (chemical names, URLs) must not blow out the measure. */
#content { hyphens: auto; -webkit-hyphens: auto; }
#content code, #content .katex { hyphens: none; -webkit-hyphens: none; }
#content code {
  overflow-wrap: anywhere;
  word-break: break-word;
  max-width: 100%;
  display: inline;
  white-space: pre-wrap;
}

/* 7. Quote / teacher-note blocks. */
#content blockquote {
  padding: 12px 18px;
  font-size: 15.5px;
  line-height: 1.65;
  color: var(--ink-soft);
}
#content blockquote p:last-child { margin-bottom: 0; }

/* 8. Contents sidebar: easier to hit and scan. */
#toc { font-size: 13.5px; line-height: 1.4; }
#toc a { padding: 6px 9px; }
#toc a.h3 { font-size: 13px; }

/* 9. Reader column: a touch more breathing room on large screens. */
@media (min-width: 1100px) {
  #content { padding: 38px 44px; }
}

/* 10. Mobile: keep the measure honest, drop the ornament. */
@media (max-width: 720px) {
  #content { font-size: 16.25px; line-height: 1.65; padding: 20px 18px; }
  #content h2 { font-size: 21px; margin-top: 1.9em; }
  #content h3 { font-size: 18px; padding-left: .55em; }
  #content table { font-size: 13.75px; }
  #content th, #content td { padding: 8px 9px; }
}

/* 11. Respect reduced-motion. */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ============================================================
   Reading surface, readability pass 2026-07-30
   These files run 20k to 114k words. Optimised for sustained
   on-screen study reading: measure, rhythm, scannable Q&A,
   legible dense tables. Uses existing tokens, works in both themes.
   ============================================================ */

/* 1. MEASURE. Cap prose to a comfortable line length while letting
      tables, figures and pre blocks use the full column. */
#content { --measure: 74ch; font-size: 17px; line-height: 1.72; padding: 34px 40px; }
#content > p,
#content > ul,
#content > ol,
#content > blockquote { max-width: var(--measure); }
#content li { margin: 3px 0; }
#content > p { margin: 0 0 1.05em; }
#content ul, #content ol { padding-left: 1.35em; }

/* 2. HEADING RHYTHM. More space above than below, so a heading
      binds to the text it introduces. */
#content h2 { font-size: 25px; line-height: 1.25; margin: 2.2em 0 .75em; }
#content h3 { font-size: 19px; line-height: 1.35; margin: 1.9em 0 .55em; }
#content h4 { font-size: 16px; margin: 1.5em 0 .4em; color: var(--ink); }

/* 3. QUESTION BLOCKS. Every "### Q..." is an exam question. Give it a
      card so students can scan for questions instead of reading walls. */
#content h3[id^="q"],
#content h3 { scroll-margin-top: 120px; }
#content h3:not(.plain) {
  background: var(--soft);
  border-left: 3px solid var(--brand);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 12px 16px;
  color: var(--ink);
  font-weight: 600;
}

/* 4. ANSWER EMPHASIS. "**Answer:**" opens the model answer. */
#content p > strong:first-child { color: var(--brand-2); }

/* 5. DENSE TABLES. These papers are table heavy. Bigger type,
      zebra striping, sticky header inside the scroll box. */
#content table { font-size: 14.5px; line-height: 1.5; }
#content th, #content td { padding: 9px 12px; }
#content thead th { position: sticky; top: 0; z-index: 1; }
#content tbody tr:nth-child(even) { background: color-mix(in srgb, var(--bg-2) 55%, transparent); }
#content tbody tr:hover { background: color-mix(in srgb, var(--soft) 70%, transparent); }
#content .table-scroll { border: 1px solid var(--line); border-radius: var(--radius-sm); }
#content .table-scroll table { border: 0; }
#content .table-scroll th, #content .table-scroll td { border-left: 0; border-right: 0; }

/* 6. BENGALI. Bengali glyphs need more leading than Latin. */
#content [lang="bn"], #content .bn { line-height: 1.9; }

/* 7. FOCUS AND SELECTION. Keyboard users and copy-to-notes. */
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }
::selection { background: color-mix(in srgb, var(--brand) 26%, transparent); }

/* 8. LONG-DOC NAVIGATION. Wider sticky contents on large screens. */
@media (min-width: 1100px) {
  .reader-body { grid-template-columns: 272px 1fr; }
  #toc { font-size: 13.5px; }
}

/* 9. SMALL SCREENS. Most students read on a phone. */
@media (max-width: 720px) {
  #content { padding: 20px 16px; font-size: 16.5px; line-height: 1.68; }
  #content h2 { font-size: 21px; }
  #content h3 { font-size: 17.5px; padding: 10px 12px; }
  #content table { font-size: 13.5px; }
  main { padding: 14px; }
}

/* 10. PRINT. Students print these for revision. */
@media print {
  .appbar, .reader-toolbar, #toc, footer, .palette, .flash { display: none !important; }
  #content { border: 0; box-shadow: none; padding: 0; font-size: 11.5pt; line-height: 1.5; }
  #content > p, #content > ul, #content > ol { max-width: none; }
  #content h2, #content h3 { break-after: avoid; }
  #content table, #content tr, #content h3 { break-inside: avoid; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 9pt; color: #555; }
}

/* 11. Respect reduced motion. */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ============================================================
   Long-document navigation, 2026-07-31
   One subject is ~200 screens of scrolling. Students need to know
   where they are, get back to the top, and reach a specific question.
   ============================================================ */

/* Reading progress, hairline across the very top */
.read-progress {
  position: fixed; inset: 0 0 auto 0; height: 3px; z-index: 60;
  background: transparent; opacity: 0; pointer-events: none;
  transition: opacity .2s var(--ease);
}
.read-progress.on { opacity: 1; }
.read-progress i {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--brand), var(--accent));
}

/* Back to top */
.back-to-top {
  position: fixed; right: 20px; bottom: 22px; z-index: 55;
  width: 42px; height: 42px; display: grid; place-items: center;
  border: 1px solid var(--line-2); border-radius: 50%;
  background: var(--paper); color: var(--brand);
  box-shadow: var(--shadow-md); cursor: pointer;
  opacity: 0; transform: translateY(8px); pointer-events: none;
  transition: opacity .18s var(--ease), transform .18s var(--ease);
}
.back-to-top.on { opacity: 1; transform: none; pointer-events: auto; }
.back-to-top:hover { border-color: var(--brand); color: var(--brand-2); }

/* Question links nested in the contents, collapsed by default */
.toc-toggle {
  display: block; width: 100%; text-align: left;
  margin: 2px 0 4px; padding: 3px 8px;
  background: none; border: 0; cursor: pointer;
  color: var(--muted); font: 600 11px Inter, sans-serif;
  letter-spacing: .06em; text-transform: uppercase;
}
.toc-toggle::before { content: "+ "; font-weight: 700; }
.toc-toggle.open::before { content: "- "; }
.toc-toggle:hover { color: var(--brand); }
.toc-qs { display: none; margin: 0 0 6px; border-left: 1px solid var(--line); padding-left: 6px; }
.toc-qs.open { display: block; }
#toc a.q {
  font-size: 12px; color: var(--muted); padding: 4px 8px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
#toc a.q:hover { color: var(--brand); background: var(--soft); }
#toc a.active { color: var(--brand); border-left-color: var(--brand); background: var(--soft); }

@media print { .read-progress, .back-to-top { display: none !important; } }
@media (max-width: 720px) { .back-to-top { right: 12px; bottom: 14px; } }

/* ============================================================
   Exam-group filter, 2026-08-03
   VU answers by group: any five of Group A (2 marks), any four of
   Group B (5), any one of Group C (10). Let students drill one at a time.
   ============================================================ */
.group-filter {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin: 4px 0 16px; padding: 10px 12px;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.gfilter {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 13px; border: 1px solid var(--line-2);
  background: var(--bg-2); color: var(--ink-soft);
  border-radius: 999px; cursor: pointer;
  font: 600 12.5px Inter, sans-serif;
  transition: background .15s var(--ease), color .15s var(--ease), border-color .15s var(--ease);
}
.gfilter:hover { border-color: var(--brand); color: var(--brand); }
.gfilter.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.gcount {
  min-width: 20px; padding: 1px 6px; border-radius: 999px;
  background: color-mix(in srgb, var(--ink) 10%, transparent);
  font-size: 11px; font-weight: 700; text-align: center;
}
.gfilter.active .gcount { background: rgba(255,255,255,.24); color: #fff; }
.q-row.g-hidden, .answer.g-hidden { display: none !important; }

/* marks badge on each question, so the group is visible while reading */
.q-row[data-marks]::after {
  content: attr(data-marks) " marks";
  position: absolute; top: 10px; right: 12px;
  font: 700 10.5px Inter, sans-serif; letter-spacing: .03em;
  padding: 2px 8px; border-radius: 999px;
  background: var(--soft); color: var(--brand-2);
}
.q-row[data-group="C"]::after { background: var(--accent-soft); color: var(--accent); }
@media (max-width: 720px) {
  /* badge is hidden on phones, so reclaim the space reserved for it */
  .q-row[data-marks]::after { display: none; }
  .q-row { padding-right: 0; }
  .group-filter { padding: 8px; gap: 6px; }
  .gfilter { padding: 6px 10px; font-size: 12px; }
}
@media print { .group-filter { display: none !important; } .q-row.g-hidden, .answer.g-hidden { display: block !important; } }

/* ============================================================
   MOBILE READING LAYER (2026-08-03)
   Audited on a real 375px viewport. Answer paragraphs measured
   204px wide = 26 characters per line, because main padding,
   #content padding, the q-row flex indent, the .answer left
   margin, its padding and a blockquote's padding all stacked:
   171px of a 375px screen was chrome. Comfortable prose runs
   45-75 characters; the mobile floor is about 40. After this
   layer the same paragraph measures 298px = 38 characters.
   Tap targets are also raised to the 44px WCAG 2.5.5 size.
   ============================================================ */
@media (max-width: 560px) {

  /* 1. Reclaim outer padding. */
  main { padding: 8px; }
  #content { padding: 16px 10px; }

  /* 2. The answer block is the reading surface. Drop the decorative
        30px left margin and halve the padding. The brand left border
        stays, so the visual tie to its question survives. */
  .answer {
    margin-left: 0;
    padding: 10px 10px;
    border-radius: 0 8px 8px 0;
  }

  /* 3. Scoring-focus callouts sit in a blockquote whose 18px side
        padding cost another 36px inside an already narrow column.
        Keep the left rule, drop the right padding. */
  .answer blockquote, #content blockquote {
    padding: 8px 0 8px 12px;
    margin-left: 0;
    margin-right: 0;
  }

  /* 4. Lists default to a 40px indent, a tenth of the screen per level. */
  .answer ul, .answer ol,
  #content ul, #content ol { padding-left: 20px; }
  .answer li, #content li { margin-bottom: 6px; }

  /* 5. Tighten the question row without losing its controls. */
  .q-row { gap: 8px; }
  .q-row h3 { padding-left: 10px; padding-right: 10px; }

  /* 6. Tap targets. 115 controls measured under 44px tall; the
        language toggle was 26px. Height is what fingers miss. */
  .lang button,
  .tb, .icon-btn, .cmdk, .gfilter, .ans-toggle { min-height: 44px; }
  .lang button { padding: 0 12px; }
  .tb { padding: 0 14px; display: inline-flex; align-items: center; }
  .icon-btn { min-width: 44px; }
  .back-to-top { min-height: 44px; min-width: 44px; }
  .toc-toggle { min-height: 44px; }
  #toc a, .toc-qs a { display: flex; align-items: center; min-height: 44px; }
  .appbar nav a, footer a { display: inline-block; padding: 12px 4px; }

  /* 7. The tick and star are 20px by design; enlarging them would
        bloat every question row. Expand the hit area instead with a
        centred 44px pseudo-element, leaving the visuals untouched. */
  .q-row .q-check, .q-row .q-star { position: relative; }
  .q-row .q-check::after, .q-row .q-star::after {
    content: "";
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 44px; height: 44px;
  }

  /* 8. Tables already scroll inside .table-scroll; let that box use
        the full reclaimed width rather than sitting inside the pad. */
  .table-scroll { margin-left: -10px; margin-right: -10px; padding: 0 10px; }
}

/* ============================================================
   PEDAGOGY CALLOUTS (2026-08-08)
   The corpus opens each long answer with a concept line, carries a
   scoring-focus line, and sprinkles why-notes. styleCallouts() in
   app.js tags them; these styles make the answer's anatomy visible:
   idea first, exam guidance second, reasoning asides inline.
   ============================================================ */
.concept-box {
  background: var(--soft);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 0 10px 10px 0;
  padding: 12px 14px;
  margin: 14px 0;
  position: relative;
}
.concept-box > strong:first-child { color: var(--accent); }
.concept-box::before {
  content: "\1F4A1";                     /* light bulb */
  position: absolute;
  top: -10px;
  left: -13px;
  font-size: 13px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 50%;
  width: 22px; height: 22px;
  display: grid; place-items: center;
}
.scoring-chip {
  font-size: 13.5px;
  color: var(--muted);
  background: var(--paper);
  border: 1px dashed var(--line-2);
  border-radius: 8px;
  padding: 7px 11px;
  margin: 10px 0;
}
.scoring-chip > strong:first-child { color: var(--brand); font-weight: 600; }
.why-note {
  border-left: 3px solid var(--line-2);
  padding-left: 12px;
  color: var(--ink);
  margin: 10px 0;
}
.why-note > em:first-child { color: var(--brand); font-style: normal; font-weight: 600; }
@media (max-width: 560px) {
  .concept-box { padding: 10px 10px; margin-left: 0; }
  .concept-box::before { left: -9px; }
}
@media print {
  .concept-box { border: 1px solid #999; border-left: 4px solid #555; }
}

/* Revision mode: hide everything inside an answer except the concept box,
   so a paper becomes a flip-through deck of its core ideas. */
body.concept-mode .answer > *:not(.concept-box) { display: none; }
body.concept-mode .answer { padding-top: 2px; padding-bottom: 2px; }
body.concept-mode .answer:not(:has(.concept-box))::after {
  content: "No concept summary for this question.";
  display: block; color: var(--muted); font-size: 13px; padding: 6px 0;
}
