/* ==========================================================================
   OS MID-SEM MASTER — shared stylesheet
   Offline. No frameworks, no external fonts, no CDN.
   ========================================================================== */

/* ---------- 1. Tokens ---------- */
:root {
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --surface-2: #F1F5F9;
  --ink: #0F172A;
  --ink-soft: #475569;
  --ink-faint: #64748B;
  --line: #E2E8F0;
  --line-strong: #CBD5E1;

  --blue: #2563EB;
  --blue-soft: #EFF6FF;
  --red: #DC2626;
  --red-soft: #FEF2F2;
  --orange: #D97706;
  --orange-soft: #FFFBEB;
  --green: #16A34A;
  --green-soft: #F0FDF4;
  --slate: #334155;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px -12px rgba(15, 23, 42, .12);
  --sidebar-w: 264px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

html[data-theme="dark"] {
  --bg: #0B1120;
  --surface: #111827;
  --surface-2: #1A2333;
  --ink: #E5EAF3;
  --ink-soft: #A9B4C6;
  --ink-faint: #8C99AD;
  --line: #243044;
  --line-strong: #33425C;

  --blue: #60A5FA;
  --blue-soft: #14243D;
  --red: #F87171;
  --red-soft: #2A1618;
  --orange: #FBBF24;
  --orange-soft: #2A2110;
  --green: #4ADE80;
  --green-soft: #12261A;
  --slate: #CBD5E1;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px -14px rgba(0, 0, 0, .7);
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5rem; font-weight: 700; letter-spacing: -.015em; }
h1 { font-size: clamp(1.7rem, 1.2rem + 2vw, 2.35rem); }
h2 { font-size: clamp(1.35rem, 1.1rem + 1vw, 1.7rem); margin-top: 2.6rem; }
h3 { font-size: 1.14rem; margin-top: 1.8rem; }
h4 { font-size: 1rem; margin-top: 1.4rem; color: var(--ink-soft); }

p { margin: 0 0 .9rem; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
strong { font-weight: 650; }
ul, ol { margin: 0 0 1rem; padding-left: 1.3rem; }
li { margin: .22rem 0; }
li > ul, li > ol { margin: .2rem 0; }
hr { border: 0; border-top: 1px solid var(--line); margin: 2rem 0; }
code, kbd { font-family: var(--mono); font-size: .88em; }
code {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: .08em .38em;
  word-break: break-word;
}
abbr { text-decoration: none; border-bottom: 1px dotted var(--line-strong); cursor: help; }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 200;
  background: var(--blue); color: #fff; padding: .6rem 1rem; border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; border-radius: 4px; }

/* ---------- 3. App shell ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--line);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 1.4rem 1rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  z-index: 60;
}

.brand { display: flex; align-items: center; gap: .65rem; padding: 0 .35rem; }
.brand-mark {
  width: 38px; height: 38px; flex: 0 0 38px;
  border-radius: 10px;
  background: var(--blue);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 800; font-size: .82rem; letter-spacing: -.04em;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text b { font-size: .95rem; letter-spacing: -.02em; }
.brand-text span { font-size: .72rem; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .09em; }

.nav-label {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .12em;
  color: var(--ink-faint); padding: 0 .55rem; margin-bottom: -.35rem;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem .6rem;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  font-size: .92rem; font-weight: 500;
  border: 1px solid transparent;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav a[aria-current="page"] {
  background: var(--blue-soft); color: var(--blue);
  border-color: color-mix(in srgb, var(--blue) 25%, transparent);
  font-weight: 650;
}
.nav .ico { width: 18px; text-align: center; font-size: .95rem; flex: 0 0 18px; }

.side-block { border-top: 1px solid var(--line); padding-top: .9rem; }
.side-actions { display: flex; flex-direction: column; gap: .45rem; }

.progress-wrap { font-size: .8rem; color: var(--ink-soft); }
.progress-head { display: flex; justify-content: space-between; margin-bottom: .35rem; font-weight: 600; }
.progress-bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--line); }
.progress-bar > i {
  display: block; height: 100%; width: 0%;
  background: var(--green); transition: width .35s ease;
}
.progress-note { font-size: .72rem; color: var(--ink-faint); margin-top: .35rem; }

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: .6rem;
  padding: .65rem clamp(1rem, 3vw, 2.2rem);
}
.topbar .crumb { font-size: .84rem; color: var(--ink-faint); font-weight: 500; margin-right: auto; }
.topbar .crumb b { color: var(--ink); }

.hamburger {
  display: none; align-items: center; gap: .45rem;
  background: var(--surface); border: 1px solid var(--line-strong);
  color: var(--ink); border-radius: var(--radius-sm);
  padding: .42rem .7rem; font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer;
}
.scrim {
  display: none; position: fixed; inset: 0; background: rgba(15, 23, 42, .48);
  z-index: 55; border: 0; padding: 0;
}

.content { padding: clamp(1.1rem, 3vw, 2.4rem); max-width: 1180px; width: 100%; }

.page-head { margin-bottom: 1.6rem; }
.eyebrow {
  display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: .13em;
  text-transform: uppercase; color: var(--blue); margin-bottom: .5rem;
}
.lede { font-size: 1.03rem; color: var(--ink-soft); max-width: 74ch; }

/* ---------- 4. Toolbar ---------- */
.toolbar {
  display: flex; flex-wrap: wrap; gap: .5rem; align-items: center;
  padding: .8rem 0 1rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 1.4rem;
}
.toolbar .spacer { margin-left: auto; }
.search {
  display: flex; align-items: center; gap: .4rem;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); padding: .18rem .55rem;
  min-width: 210px; flex: 0 1 260px;
}
.search:focus-within { border-color: var(--blue); }
.search input {
  border: 0; background: transparent; color: var(--ink);
  font: inherit; font-size: .88rem; padding: .38rem .1rem; width: 100%;
}
.search input:focus { outline: none; }

/* ---------- 5. Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: .42rem .8rem; font: inherit; font-size: .84rem; font-weight: 600;
  cursor: pointer; transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--ink-faint); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: #1D4ED8; border-color: #1D4ED8; color: #fff; }
.btn-sm { padding: .3rem .6rem; font-size: .78rem; }

.filters { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
.chip {
  background: var(--surface); border: 1px solid var(--line-strong); color: var(--ink-soft);
  border-radius: 99px; padding: .28rem .75rem; font: inherit; font-size: .78rem; font-weight: 600;
  cursor: pointer;
}
.chip:hover { border-color: var(--ink-faint); color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.chip.chip-recent[aria-pressed="true"] { background: var(--green); border-color: var(--green); color: #fff; }

/* ---------- 6. Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
  box-shadow: var(--shadow);
  margin: 0 0 1.1rem;
}
.card-flat { box-shadow: none; }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.1rem; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: .15rem;
}
.stat b { font-size: 1.85rem; letter-spacing: -.03em; line-height: 1.1; }
.stat span { font-size: .78rem; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .08em; font-weight: 600; }
.stat small { font-size: .8rem; color: var(--ink-soft); }
.stat.stat-blue b { color: var(--blue); }
.stat.stat-green b { color: var(--green); }
.stat.stat-orange b { color: var(--orange); }
.stat.stat-red b { color: var(--red); }

.link-card {
  display: block; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.05rem 1.15rem; box-shadow: var(--shadow);
  color: inherit; transition: border-color .15s, transform .12s;
}
.link-card:hover { border-color: var(--blue); transform: translateY(-2px); text-decoration: none; }
.link-card h3 { margin: 0 0 .25rem; font-size: 1.02rem; color: var(--ink); }
.link-card p { margin: 0; font-size: .87rem; color: var(--ink-soft); }
.link-card .tag-row { margin-top: .6rem; display: flex; flex-wrap: wrap; gap: .3rem; }

/* ---------- 7. Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: .28rem;
  font-size: .69rem; font-weight: 700; letter-spacing: .055em; text-transform: uppercase;
  padding: .17rem .5rem; border-radius: 99px;
  border: 1px solid transparent; white-space: nowrap;
}
.badge-recent { background: var(--green-soft); color: var(--green); border-color: color-mix(in srgb, var(--green) 35%, transparent); }
.badge-gap { background: var(--blue-soft); color: var(--blue); border-color: color-mix(in srgb, var(--blue) 35%, transparent); }
.badge-variant { background: var(--orange-soft); color: var(--orange); border-color: color-mix(in srgb, var(--orange) 40%, transparent); }
.badge-syllabus { background: var(--surface-2); color: var(--ink-faint); border-color: var(--line-strong); }
.badge-year { background: var(--surface-2); color: var(--ink-soft); border-color: var(--line-strong); letter-spacing: .02em; }
.badge-marks { background: var(--surface-2); color: var(--ink-soft); border-color: var(--line-strong); }

.p-vh { background: var(--red-soft); color: var(--red); border-color: color-mix(in srgb, var(--red) 35%, transparent); }
.p-h  { background: var(--orange-soft); color: var(--orange); border-color: color-mix(in srgb, var(--orange) 40%, transparent); }
.p-m  { background: var(--blue-soft); color: var(--blue); border-color: color-mix(in srgb, var(--blue) 30%, transparent); }
.p-s  { background: var(--surface-2); color: var(--ink-faint); border-color: var(--line-strong); }

.tag-row { display: flex; flex-wrap: wrap; gap: .32rem; align-items: center; }

/* ---------- 8. Question cards ---------- */
.q-card {
  background: var(--surface); border: 1px solid var(--line);
  border-left: 4px solid var(--line-strong);
  border-radius: var(--radius); box-shadow: var(--shadow);
  margin: 0 0 1rem; overflow: hidden;
}
.q-card[data-priority="very-high"] { border-left-color: var(--red); }
.q-card[data-priority="high"] { border-left-color: var(--orange); }
.q-card[data-priority="medium"] { border-left-color: var(--blue); }
.q-card[data-priority="safety"] { border-left-color: var(--line-strong); }
.q-card.is-hidden { display: none; }

.q-head { padding: .95rem 1.15rem .35rem; }
.q-head .q-tag { font-size: .7rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-faint); }
.q-text { margin: .35rem 0 .6rem; font-size: 1.02rem; font-weight: 650; line-height: 1.45; }
.q-text::before { content: "Q. "; color: var(--blue); font-weight: 800; }
.q-meta { display: flex; flex-wrap: wrap; gap: .32rem; padding-bottom: .55rem; }

.q-body { padding: 0 1.15rem 1.05rem; }

details.answer {
  border-top: 1px dashed var(--line);
  margin-top: .2rem;
}
details.answer > summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: center; gap: .45rem;
  padding: .62rem 0 .3rem;
  font-size: .84rem; font-weight: 700; color: var(--blue);
  user-select: none;
}
details.answer > summary::-webkit-details-marker { display: none; }
details.answer > summary::before {
  content: "▸"; font-size: .85rem; transition: transform .18s ease; display: inline-block;
}
details.answer[open] > summary::before { transform: rotate(90deg); }
details.answer > summary:hover { text-decoration: underline; }
.answer-inner {
  padding: .2rem 0 .3rem;
  border-top: 1px solid var(--line);
  margin-top: .15rem;
}
.answer-inner > *:last-child { margin-bottom: 0; }

.ans-label {
  font-size: .7rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-faint); margin: 1rem 0 .4rem;
}
.ans-label:first-child { margin-top: .6rem; }

.asked-in {
  font-size: .82rem; color: var(--ink-soft);
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: .5rem .7rem; margin: .55rem 0 0;
}
.asked-in b { color: var(--ink); }

/* ---------- 9. Notes / callouts ---------- */
.note, .verify, .tip, .warn, .exam-tip {
  border-radius: var(--radius-sm); padding: .75rem .9rem; margin: .9rem 0;
  font-size: .92rem; border: 1px solid; border-left-width: 4px;
}
.note { background: var(--blue-soft); border-color: color-mix(in srgb, var(--blue) 28%, transparent); border-left-color: var(--blue); }
.verify { background: var(--orange-soft); border-color: color-mix(in srgb, var(--orange) 32%, transparent); border-left-color: var(--orange); }
.tip, .exam-tip { background: var(--green-soft); border-color: color-mix(in srgb, var(--green) 28%, transparent); border-left-color: var(--green); }
.warn { background: var(--red-soft); border-color: color-mix(in srgb, var(--red) 28%, transparent); border-left-color: var(--red); }
.note b, .verify b, .tip b, .warn b, .exam-tip b { display: block; margin-bottom: .18rem; font-size: .78rem; letter-spacing: .07em; text-transform: uppercase; }

.muted { color: var(--ink-faint); font-size: .88rem; }
.small { font-size: .85rem; }
.mark-unclear { background: var(--orange-soft); color: var(--orange); border-radius: 4px; padding: 0 .25em; font-weight: 600; }

/* ---------- 10. Tables ---------- */
.table-wrap { overflow-x: auto; margin: .9rem 0; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
caption { caption-side: top; text-align: left; font-size: .8rem; font-weight: 700; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .08em; padding: .6rem .75rem; background: var(--surface-2); border-bottom: 1px solid var(--line); }
th, td { padding: .55rem .72rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { background: var(--surface-2); font-weight: 700; color: var(--ink); white-space: nowrap; border-bottom: 1px solid var(--line-strong); }
tbody tr:last-child td { border-bottom: 0; }
tbody th { font-weight: 650; color: var(--ink); background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
table.center td, table.center th { text-align: center; }
table.compact th, table.compact td { padding: .35rem .55rem; font-size: .84rem; }
td.good { color: var(--green); font-weight: 700; }
td.bad { color: var(--red); font-weight: 700; }
tr.total td, tr.total th { background: var(--surface-2); font-weight: 800; }

/* coverage matrix row helpers */
.cov-yes { color: var(--green); font-weight: 800; }
.cov-old { color: var(--orange); font-weight: 800; }
.cov-no { color: var(--ink-faint); font-weight: 700; }

/* ---------- 11. Gantt charts ---------- */
.gantt { margin: .9rem 0 1.1rem; }
.gantt-track { display: flex; width: 100%; border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; background: var(--surface); }
.gantt-cell {
  flex: 0 0 auto; text-align: center; font-size: .8rem; font-weight: 700;
  padding: .5rem .2rem; color: #fff; border-right: 1px solid rgba(255, 255, 255, .55);
  min-width: 26px; white-space: nowrap;
}
.gantt-cell:last-child { border-right: 0; }
.gantt-cell.g-idle { background: var(--ink-faint); }
.gantt-cell.g-a, .gantt-cell.g-p1 { background: #2563EB; }
.gantt-cell.g-b, .gantt-cell.g-p2 { background: #DC2626; }
.gantt-cell.g-c, .gantt-cell.g-p3 { background: #D97706; }
.gantt-cell.g-d, .gantt-cell.g-p4 { background: #16A34A; }
.gantt-cell.g-e, .gantt-cell.g-p5 { background: #7C3AED; }
.gantt-cell.g-f, .gantt-cell.g-p6 { background: #0891B2; }
html[data-theme="dark"] .gantt-cell.g-a, html[data-theme="dark"] .gantt-cell.g-p1 { background: #1D4ED8; }
html[data-theme="dark"] .gantt-cell.g-p5 { background: #6D28D9; }

.gantt-scale { display: flex; width: 100%; font-family: var(--mono); font-size: .74rem; color: var(--ink-faint); margin-top: 2px; }
.gantt-scale span { flex: 0 0 auto; text-align: left; position: relative; }
.gantt-scale span i { position: absolute; left: 0; top: -6px; height: 6px; width: 1px; background: var(--line-strong); }
.gantt-legend { display: flex; flex-wrap: wrap; gap: .55rem; font-size: .78rem; color: var(--ink-soft); margin-top: .45rem; }
.gantt-legend em { font-style: normal; display: inline-flex; align-items: center; gap: .3rem; }
.gantt-legend em::before { content: ""; width: 11px; height: 11px; border-radius: 3px; background: var(--sw, var(--line-strong)); display: inline-block; }

/* ---------- 12. Frame tables (page replacement) ---------- */
.frame-grid { display: grid; gap: 2px; grid-auto-flow: column; overflow-x: auto; padding-bottom: .35rem; margin: .9rem 0; }
.frame-col { display: flex; flex-direction: column; gap: 2px; min-width: 44px; }
.frame-col > div {
  border: 1px solid var(--line); background: var(--surface);
  min-height: 30px; display: grid; place-items: center;
  font-family: var(--mono); font-size: .82rem; font-weight: 600;
}
.frame-col .fc-ref { background: var(--surface-2); font-weight: 800; }
.frame-col .fc-hd { font-size: .68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); background: var(--surface-2); }
.frame-col .fc-fault { background: var(--red-soft); color: var(--red); font-weight: 800; }
.frame-col .fc-hit { background: var(--green-soft); color: var(--green); font-weight: 800; }
.frame-col .fc-load { background: color-mix(in srgb, var(--blue) 12%, var(--surface)); border-color: var(--blue); color: var(--blue); font-weight: 800; }
.frame-col .fc-empty { color: var(--line-strong); }

/* ---------- 13. Memory / block diagrams ---------- */
.memrow { display: flex; align-items: stretch; gap: .8rem; flex-wrap: wrap; margin: .8rem 0; }
.memcol { flex: 1 1 150px; min-width: 130px; }
.memcol h5 { margin: 0 0 .35rem; font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-faint); font-weight: 800; }
.membits { border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; }
.membits div { padding: .42rem .5rem; font-family: var(--mono); font-size: .8rem; text-align: center; border-bottom: 1px solid var(--line); background: var(--surface); }
.membits div:last-child { border-bottom: 0; }
.membits .hl { background: var(--blue-soft); color: var(--blue); font-weight: 700; }
.membits .hl2 { background: var(--orange-soft); color: var(--orange); font-weight: 700; }
.arrow-down { text-align: center; color: var(--ink-faint); font-size: 1.15rem; line-height: 1.4; }

/* ---------- 14. Code / pseudocode ---------- */
pre {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: .85rem .95rem;
  overflow-x: auto; margin: .85rem 0; line-height: 1.55;
}
pre code { background: none; border: 0; padding: 0; font-size: .84rem; color: var(--ink); }

/* ---------- 15. Diagrams ---------- */
figure.diagram { margin: 1.1rem 0 1.5rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1rem 1.1rem; box-shadow: var(--shadow); }
figure.diagram figcaption { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-faint); margin-bottom: .7rem; }
figure.diagram figcaption .dnum { color: var(--blue); }
.svg-holder { width: 100%; }
svg { max-width: 100%; height: auto; display: block; margin-inline: auto; }

/* SVG theme hooks — every diagram stays readable in grayscale */
.svg-holder svg text { font-family: inherit; }
.s-box { fill: var(--surface); stroke: var(--line-strong); stroke-width: 1.6; }
.s-box-strong { fill: var(--surface); stroke: var(--ink); stroke-width: 2; }
.s-blue { fill: var(--blue-soft); stroke: var(--blue); stroke-width: 1.8; }
.s-green { fill: var(--green-soft); stroke: var(--green); stroke-width: 1.8; }
.s-red { fill: var(--red-soft); stroke: var(--red); stroke-width: 1.8; }
.s-orange { fill: var(--orange-soft); stroke: var(--orange); stroke-width: 1.8; }
.s-shade { fill: var(--surface-2); stroke: var(--line-strong); stroke-width: 1.4; }
.s-dark { fill: var(--ink); stroke: var(--ink); }
.s-line { stroke: var(--ink-soft); stroke-width: 1.8; fill: none; }
.s-line-thin { stroke: var(--line-strong); stroke-width: 1.2; fill: none; }
.s-dash { stroke: var(--ink-faint); stroke-width: 1.6; fill: none; stroke-dasharray: 5 4; }
.t { fill: var(--ink); font-size: 13px; font-weight: 600; }
.t-sm { fill: var(--ink-soft); font-size: 11.5px; font-weight: 500; }
.t-xs { fill: var(--ink-faint); font-size: 10.5px; font-weight: 600; }
.t-strong { fill: var(--ink); font-size: 13.5px; font-weight: 800; }
.t-inv { fill: #fff; font-size: 12.5px; font-weight: 700; }
.t-lbl { fill: var(--ink-soft); font-size: 11.5px; font-weight: 700; }
.marker-arrow { fill: var(--ink-soft); }

.howto {
  border: 1px dashed var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface-2); padding: .7rem .85rem; margin-top: .85rem;
}
.howto h5 { margin: 0 0 .35rem; font-size: .72rem; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; color: var(--blue); }
.howto ol { margin: 0; padding-left: 1.15rem; font-size: .88rem; color: var(--ink-soft); }
.howto li { margin: .12rem 0; }

/* ---------- 16. Checklist ---------- */
.checklist { display: grid; gap: .4rem; margin: .8rem 0 1.2rem; }
.check {
  display: flex; align-items: flex-start; gap: .6rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: .55rem .75rem; cursor: pointer;
  font-size: .92rem; transition: border-color .15s, background .15s;
}
.check:hover { border-color: var(--blue); }
.check input { margin: .22rem 0 0; width: 16px; height: 16px; accent-color: var(--green); flex: 0 0 16px; cursor: pointer; }
.check input:checked + span { color: var(--ink-faint); text-decoration: line-through; text-decoration-color: var(--line-strong); }
.check:has(input:checked) { background: var(--green-soft); border-color: color-mix(in srgb, var(--green) 32%, transparent); }
.check .p { margin-left: auto; }

.check-group { margin-bottom: 1.3rem; }
.check-group > h4 { margin: 0 0 .5rem; color: var(--ink); font-size: .95rem; }

/* ---------- 17. Section headers ---------- */
.sec {
  display: flex; align-items: baseline; gap: .7rem; flex-wrap: wrap;
  margin: 2.8rem 0 1rem; padding-bottom: .55rem; border-bottom: 2px solid var(--line);
}
.sec h2 { margin: 0; }
.sec .sec-badge {
  font-size: .7rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase;
  color: #fff; background: var(--blue); border-radius: 5px; padding: .16rem .5rem;
}
.sec.sec-ii .sec-badge { background: var(--orange); }
h2, h3 { scroll-margin-top: 5rem; }

/* ---------- 18. Back to top / footer ---------- */
.to-top {
  position: fixed; right: 18px; bottom: 18px; z-index: 70;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--ink); color: var(--bg); border: 0; cursor: pointer;
  font-size: 1.1rem; line-height: 1; display: none; place-items: center;
  box-shadow: var(--shadow);
}
.to-top.show { display: grid; }
.to-top:hover { background: var(--blue); color: #fff; }

.foot {
  border-top: 1px solid var(--line); margin-top: 3rem; padding: 1.2rem 0 0;
  font-size: .82rem; color: var(--ink-faint);
}

/* ---------- 19. Search highlight ---------- */
mark { background: #FEF08A; color: #0F172A; border-radius: 2px; padding: 0 .12em; }
html[data-theme="dark"] mark { background: #CA8A04; color: #0B1120; }
.search-miss { opacity: .22; }

/* ---------- 20. Responsive ---------- */
@media (max-width: 1000px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; height: 100vh;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .scrim { display: block; }
  .hamburger { display: inline-flex; }
  .app { flex-direction: row; }
}

@media (max-width: 640px) {
  body { font-size: 15.5px; }
  .content { padding: 1rem .95rem 2rem; }
  .toolbar { gap: .4rem; }
  .search { flex: 1 1 100%; }
  .toolbar .spacer { display: none; }
  .q-head { padding: .85rem .9rem .25rem; }
  .q-body { padding: 0 .9rem .9rem; }
  .card { padding: .95rem .95rem; }
  .grid { gap: .75rem; }
  .gantt-cell { font-size: .72rem; min-width: 20px; }
}

@media (max-width: 420px) {
  .topbar { flex-wrap: wrap; }
  .topbar .crumb { flex: 1 1 100%; order: -1; }
}

/* ---------- 21. Print ---------- */
@media print {
  :root, html[data-theme="dark"] {
    --bg: #fff; --surface: #fff; --surface-2: #F1F5F9;
    --ink: #000; --ink-soft: #1F2937; --ink-faint: #374151;
    --line: #B7C0CC; --line-strong: #6B7280;
    --blue: #1D4ED8; --green: #15803D; --orange: #B45309; --red: #B91C1C;
    --blue-soft: #fff; --green-soft: #fff; --orange-soft: #fff; --red-soft: #fff;
    --shadow: none;
  }
  html, body { background: #fff !important; }
  .sidebar, .topbar, .toolbar, .to-top, .scrim, .hamburger, .no-print, .side-actions { display: none !important; }
  .app { display: block; }
  .content { max-width: none; padding: 0; }
  details.answer { border-top: 1px solid #B7C0CC; }
  details.answer > summary { display: none !important; }
  details.answer > .answer-inner { display: block !important; border-top: 0; }
  .q-card, .card, figure.diagram, .stat, table, pre { box-shadow: none !important; break-inside: avoid; page-break-inside: avoid; }
  .q-card { border: 1px solid #B7C0CC; }
  .q-card.is-hidden { display: block !important; }
  h2, h3 { break-after: avoid; page-break-after: avoid; }
  table { font-size: 8.5pt; }
  .table-wrap { overflow: visible; border-color: #B7C0CC; }
  .gantt-cell { color: #000 !important; background: #E5E7EB !important; border: 1px solid #6B7280; }
  a[href^="http"]::after { content: ""; }
  .foot { font-size: 8pt; }
  @page { margin: 14mm; }
}

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