/* Interview cram reader — print-poster edition. Hard borders, flat color, big type. */

@import url("https://fonts.googleapis.com/css2?family=Archivo:wght@500;600;700;800;900&family=IBM+Plex+Mono:wght@400;500;600&display=swap");

:root {
  --reader-font: 112.5%;

  --paper: #f4f3ee;
  --paper-dim: #e9e7df;
  --ink: #101010;
  --ink-muted: #4a4a46;
  --ink-faint: #8a8a84;

  --blue: #2b2bee;
  --blue-deep: #1e1ec4;
  --yellow: #ffd400;
  --orange: #ff4d00;
  --green: #0a7d4f;
  --violet: #6d28d9;

  --bg-page: var(--paper);
  --bg-card: #ffffff;
  --text: var(--ink);
  --text-secondary: var(--ink-muted);
  --border: var(--ink);
  --border-soft: #d6d4cc;
  --sidebar-bg: var(--ink);
  --sidebar-text: var(--paper);
  --sidebar-muted: #9a9a94;
  --sidebar-hover: #2a2a2a;
  --accent: var(--blue);
  --accent-bright: var(--blue-deep);

  --font-ui: "Archivo", system-ui, sans-serif;
  --font-read: "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --sidebar-w: 20rem;
  --content-max: 46rem;
  --radius: 0;
  --shadow-hard: 6px 6px 0 0 var(--ink);
  --shadow-hard-sm: 3px 3px 0 0 var(--ink);
  --mobile-header-h: 3.5rem;
}

html[data-theme="dark"] {
  --paper: #141414;
  --paper-dim: #1c1c1c;
  --bg-page: #141414;
  --bg-card: #1d1d1d;
  --text: #f2f1ec;
  --text-secondary: #c2c1ba;
  --ink-faint: #8a8a84;
  --border: #f2f1ec;
  --border-soft: #3a3a36;
  --sidebar-bg: #0a0a0a;
  --shadow-hard: 6px 6px 0 0 rgb(242 241 236 / 35%);
  --shadow-hard-sm: 3px 3px 0 0 rgb(242 241 236 / 35%);
  --blue: #6e6eff;
  --blue-deep: #8a8aff;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  font-size: var(--reader-font);
}

body {
  margin: 0;
  font-family: var(--font-ui);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg-page);
}

::selection {
  background: var(--yellow);
  color: #101010;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.skip-link {
  position: absolute;
  top: -3rem;
  left: 1rem;
  padding: 0.6rem 1rem;
  background: var(--blue);
  color: #fff;
  border: 2px solid var(--ink);
  z-index: 200;
  text-decoration: none;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.8rem;
}

.skip-link:focus {
  top: 1rem;
}

/* —— Reading progress bar (injected by JS) —— */
.read-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 4px;
  width: 0;
  background: var(--blue);
  z-index: 300;
  transition: width 0.1s linear;
}

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* —— Sidebar: the black stacks —— */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 1rem 0 2rem;
  border-right: 2px solid var(--ink);
}

.sidebar-brand {
  padding: 0 1.1rem 1rem;
  border-bottom: 1px solid rgb(255 255 255 / 14%);
  margin-bottom: 0.75rem;
}

.brand-link {
  color: #fff;
  font-weight: 800;
  font-size: 1rem;
  text-decoration: none;
  line-height: 1.3;
  display: block;
  text-transform: uppercase;
  letter-spacing: -0.01em;
}

.brand-link:hover {
  color: var(--yellow);
}

.brand-sub {
  margin: 0.45rem 0 0;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--sidebar-muted);
  line-height: 1.5;
}

.search-wrap {
  display: block;
  padding: 0 1rem 0.75rem;
}

.search-wrap input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 2px solid rgb(255 255 255 / 25%);
  border-radius: 0;
  background: rgb(255 255 255 / 6%);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.search-wrap input::placeholder {
  color: var(--sidebar-muted);
}

.search-wrap input:focus {
  outline: none;
  border-color: var(--yellow);
}

.toc {
  padding: 0 0.4rem;
  font-size: 0.9rem;
}

.toc-part summary {
  cursor: pointer;
  padding: 0.5rem 0.6rem;
  font-weight: 800;
  color: #fff;
  list-style: none;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.toc-part summary::before {
  content: "▸ ";
  color: var(--yellow);
}

.toc-part[open] summary::before {
  content: "▾ ";
}

.toc-part summary::-webkit-details-marker {
  display: none;
}

.toc ul {
  list-style: none;
  margin: 0;
  padding: 0 0 0.5rem 0.35rem;
}

.toc a {
  display: block;
  padding: 0.4rem 0.6rem;
  color: var(--sidebar-muted);
  text-decoration: none;
  border-left: 3px solid transparent;
  line-height: 1.4;
  font-size: 0.86rem;
}

.toc a:hover {
  color: #fff;
  border-left-color: var(--yellow);
  background: var(--sidebar-hover);
}

.toc a[aria-current="page"] {
  background: var(--yellow);
  color: #101010;
  font-weight: 700;
  border-left-color: var(--yellow);
}

.toc li.hidden,
.toc-part.hidden {
  display: none;
}

.toc-appendix {
  margin-top: 0.75rem;
  padding: 0.75rem 1rem 0;
  border-top: 1px solid rgb(255 255 255 / 14%);
}

.toc-appendix a {
  color: var(--yellow);
  font-weight: 800;
  text-decoration: none;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.toc-appendix a:hover {
  text-decoration: underline;
}

/* —— Reader toolbar: control strip —— */
.reader-toolbar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  padding: 0;
  background: var(--bg-page);
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.toolbar-toggle {
  display: none;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 44px;
  padding: 0.55rem 1rem;
  border: none;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-page);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
}

.toolbar-toggle-label {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.7rem;
  color: var(--text-secondary);
}

.toolbar-chevron {
  font-size: 1rem;
  line-height: 1;
  transition: transform 0.2s ease;
}

body.toolbar-collapsed .toolbar-chevron {
  transform: rotate(-90deg);
}

.reader-toolbar-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
}

body.toolbar-collapsed .reader-toolbar-controls {
  display: none;
}

.reader-toolbar .toolbar-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-secondary);
  margin-right: 0.25rem;
}

.reader-toolbar button,
.reader-toolbar a.btn-jump {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.45rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: 0;
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  box-shadow: var(--shadow-hard-sm);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.reader-toolbar button:hover,
.reader-toolbar a.btn-jump:hover {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 0 var(--ink);
}

html[data-theme="dark"] .reader-toolbar button:hover,
html[data-theme="dark"] .reader-toolbar a.btn-jump:hover {
  box-shadow: 4px 4px 0 0 rgb(242 241 236 / 35%);
}

.reader-toolbar button:active,
.reader-toolbar a.btn-jump:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 0 var(--ink);
}

.reader-toolbar button.is-active {
  background: var(--blue);
  border-color: var(--border);
  color: #fff;
}

.reader-toolbar a.btn-jump {
  background: var(--orange);
  color: #fff;
}

.toolbar-spacer {
  flex: 1;
}

/* —— Main content area —— */
.main {
  padding: 0 0 4rem;
  min-width: 0;
}

.main-inner {
  max-width: calc(var(--content-max) + 3rem);
  margin: 0 auto;
  padding: 2rem clamp(1rem, 3vw, 2rem) 3rem;
}

.reading-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: 0;
  box-shadow: var(--shadow-hard);
  padding: clamp(1.5rem, 4vw, 2.75rem);
}

/* —— Home —— */
.home-hero h1 {
  font-family: var(--font-ui);
  font-size: clamp(1.9rem, 4.5vw, 2.6rem);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: -0.02em;
  margin: 0 0 0.5rem;
  line-height: 1.05;
}

.home-hero .lead {
  font-family: var(--font-read);
  font-size: 1.15rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.home-hero .eyebrow {
  display: inline-block;
  font-family: var(--font-mono);
  font-weight: 600;
  color: #fff;
  background: var(--blue);
  border: 2px solid var(--border);
  padding: 0.25rem 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.68rem;
  margin-bottom: 0.85rem;
}

.cram-banner {
  background: var(--yellow);
  color: #101010;
  padding: 1rem 1.25rem;
  border: 2px solid var(--ink);
  box-shadow: var(--shadow-hard-sm);
  margin-bottom: 1.5rem;
  font-size: 1rem;
  line-height: 1.5;
}

.cram-banner strong {
  display: block;
  font-size: 1.05rem;
  margin-bottom: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.stats {
  display: flex;
  gap: 0;
  margin: 1.5rem 0;
  border: 2px solid var(--border);
  width: fit-content;
}

.stat {
  padding: 0.75rem 1.5rem;
  text-align: center;
}

.stat + .stat {
  border-left: 2px solid var(--border);
}

.stat-n {
  display: block;
  font-size: 2rem;
  font-weight: 900;
  color: var(--blue);
  font-family: var(--font-ui);
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.stat-l {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-secondary);
}

.home-hint {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.part-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: 0;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-hard-sm);
}

.part-card h2 {
  font-size: 1.1rem;
  margin: 0 0 0.5rem;
  text-transform: uppercase;
  letter-spacing: -0.01em;
}

.part-card a {
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}

.part-card h2 a:hover {
  color: var(--blue);
}

.part-card .part-intro {
  font-family: var(--font-read);
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.6;
}

.part-card .chapter-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
}

.part-card .chapter-list li {
  padding: 0.3rem 0;
  border-top: 1px solid var(--border-soft);
  font-size: 0.9rem;
}

.part-card .chapter-list a {
  color: var(--blue);
  font-weight: 600;
}

.part-card .chapter-list a:hover {
  text-decoration: underline;
}

.part-card .more {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* —— Chapter header —— */
.chapter-header {
  margin-bottom: 1.75rem;
  padding-bottom: 1.25rem;
  border-bottom: 4px solid var(--ink);
}

.chapter-meta {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--blue);
  margin: 0 0 0.6rem;
}

.chapter-header h1 {
  font-family: var(--font-ui);
  font-size: clamp(1.7rem, 3.8vw, 2.3rem);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1.08;
  color: var(--text);
}

.chapter-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.chapter-nav a {
  flex: 1;
  min-width: 140px;
  padding: 0.65rem 1rem;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: 0;
  color: var(--text);
  font-weight: 700;
  font-size: 0.85rem;
  text-decoration: none;
  line-height: 1.35;
  box-shadow: var(--shadow-hard-sm);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.chapter-nav a:hover {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 0 var(--ink);
  color: var(--blue);
}

html[data-theme="dark"] .chapter-nav a:hover {
  box-shadow: 4px 4px 0 0 rgb(242 241 236 / 35%);
}

.nav-next {
  text-align: right;
}

/* —— Prose (large, high contrast) —— */
.prose {
  font-family: var(--font-read);
  font-size: 1.125rem;
  line-height: 1.85;
  color: var(--text);
}

.prose p {
  margin: 0 0 1.15rem;
}

.prose strong {
  font-weight: 700;
  color: var(--text);
}

.prose em {
  color: var(--text-secondary);
}

.prose code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--paper-dim);
  color: var(--text);
  padding: 0.15em 0.4em;
  border: 1px solid var(--border-soft);
}

html[data-theme="dark"] .prose code {
  background: #262626;
  color: #f2f1ec;
}

.prose pre {
  background: #101010;
  color: #f4f3ee;
  padding: 1.15rem 1.25rem;
  border: 2px solid var(--ink);
  box-shadow: var(--shadow-hard-sm);
  border-radius: 0;
  overflow-x: auto;
  font-size: 0.92rem;
  line-height: 1.55;
  margin: 1.25rem 0;
}

html[data-theme="dark"] .prose pre {
  background: #0a0a0a;
  border-color: var(--border-soft);
}

.prose pre code {
  background: none;
  border: none;
  padding: 0;
  color: inherit;
  font-family: var(--font-mono);
}

/* —— Layer sections: filing-card system —— */
.chapter-body .layer {
  margin: 1.75rem 0;
  padding: 1.25rem 1.35rem;
  border: 2px solid var(--ink);
  border-radius: 0;
  background: var(--bg-card);
  position: relative;
}

.chapter-body .layer-heading {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  margin: -1.25rem 0 1rem -1.35rem;
  padding: 0.4rem 0.85rem;
  border-right: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  color: #101010;
}

/* Hook — yellow tab */
.chapter-body .layer-hook .layer-heading {
  background: var(--yellow);
}

/* Intuition — violet tab */
.chapter-body .layer-intuition .layer-heading {
  background: #ddd6fe;
}

/* Mechanism — plain paper tab */
.chapter-body .layer-mechanism .layer-heading {
  background: var(--paper-dim);
}

/* Worked example — blue tab */
.chapter-body .layer-example .layer-heading {
  background: #c7d2fe;
}

/* Interview — the loud one */
.chapter-body .layer-interview {
  border-width: 3px;
  box-shadow: var(--shadow-hard);
}

.chapter-body .layer-interview .layer-heading {
  background: var(--orange);
  color: #fff;
  font-weight: 600;
}

/* Practice — green tab */
.chapter-body .layer-practice .layer-heading {
  background: #a7f3d0;
}

/* Connections — quiet */
.chapter-body .layer-connections {
  border-style: dashed;
  border-color: var(--ink-faint);
  background: transparent;
}

.chapter-body .layer-connections .layer-heading {
  background: transparent;
  border-color: var(--ink-faint);
  border-style: dashed;
  color: var(--text-secondary);
}

.chapter-body .layer-default .layer-heading {
  background: var(--paper-dim);
}

html[data-theme="dark"] .chapter-body .layer-intuition .layer-heading {
  background: #4c1d95;
  color: #f2f1ec;
}

html[data-theme="dark"] .chapter-body .layer-example .layer-heading {
  background: #1e1e8f;
  color: #f2f1ec;
}

html[data-theme="dark"] .chapter-body .layer-practice .layer-heading {
  background: #065f46;
  color: #f2f1ec;
}

html[data-theme="dark"] .chapter-body .layer-mechanism .layer-heading,
html[data-theme="dark"] .chapter-body .layer-default .layer-heading {
  color: #f2f1ec;
}

html[data-theme="dark"] .chapter-body .layer-hook .layer-heading {
  color: #101010;
}

/* Hide raw h4 when wrapped in layer */
.chapter-body .layer > h4:first-child {
  display: none;
}

/* Cram mode: only essentials */
body.cram-mode .chapter-body .layer:not(.layer-hook):not(.layer-interview):not(.layer-practice) {
  display: none;
}

body.cram-mode .chapter-header {
  border-bottom-color: var(--orange);
}

.cite-marker {
  font-family: var(--font-mono);
  font-size: 0.65em;
  color: var(--text-secondary);
}

.mermaid {
  margin: 1.25rem 0;
  text-align: center;
}

/* Section jump pills (in-chapter) */
.section-jump {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1.5rem;
}

.section-jump a {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.35rem 0.65rem;
  border-radius: 0;
  text-decoration: none;
  background: var(--bg-card);
  border: 2px solid var(--border);
  color: var(--text);
}

.section-jump a:hover {
  background: var(--yellow);
  color: #101010;
}

.section-jump a.jump-interview {
  border-color: var(--ink);
  color: #fff;
  background: var(--orange);
}

.section-jump a.jump-interview:hover {
  background: var(--ink);
}

.layout-home #btn-jump-interview,
.layout-appendix #btn-jump-interview {
  display: none;
}

.reader-toolbar .appendix-only[hidden] {
  display: none;
}

.layout-appendix .reader-toolbar .appendix-only {
  display: inline-block;
}

/* —— Appendix drill cards —— */
.appendix .chapter-body > h1 {
  display: none;
}

.appendix-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1.25rem;
  padding: 0.75rem 1rem;
  background: var(--yellow);
  border: 2px solid var(--ink);
  box-shadow: var(--shadow-hard-sm);
  font-size: 0.9rem;
  color: #101010;
}

html[data-theme="dark"] .appendix-controls {
  box-shadow: var(--shadow-hard-sm);
}

.appendix-count {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #101010;
  white-space: nowrap;
}

.appendix-controls label {
  font-weight: 800;
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  color: #101010;
}

.appendix-controls input {
  flex: 1;
  min-width: 12rem;
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--ink);
  border-radius: 0;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  background: #fff;
  color: #101010;
}

.appendix-controls input:focus {
  outline: 3px solid var(--blue);
  outline-offset: -1px;
}

.appendix-card {
  margin: 0 0 1rem;
  border: 2px solid var(--ink);
  border-radius: 0;
  background: var(--bg-card);
  overflow: hidden;
  box-shadow: var(--shadow-hard-sm);
}

.appendix-card.is-hidden {
  display: none;
}

.appendix-card details {
  margin: 0;
}

.appendix-card summary {
  cursor: pointer;
  list-style: none;
  padding: 1rem 1.15rem;
  font-family: var(--font-ui);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg-card);
}

.appendix-card summary:hover {
  background: var(--paper-dim);
}

.appendix-card summary::-webkit-details-marker {
  display: none;
}

.appendix-card summary::before {
  content: "▸ ";
  color: var(--blue);
  font-weight: 800;
}

.appendix-card details[open] summary::before {
  content: "▾ ";
}

.appendix-card details[open] summary {
  border-bottom: 2px solid var(--ink);
  background: var(--paper-dim);
}

.appendix-card .q-badge {
  display: inline-block;
  min-width: 2.5rem;
  margin-right: 0.5rem;
  padding: 0.15rem 0.45rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  text-align: center;
  color: #fff;
  background: var(--blue);
  border: 1px solid var(--ink);
  border-radius: 0;
  vertical-align: middle;
}

.appendix-answer {
  padding: 1rem 1.15rem 1.15rem;
  font-family: var(--font-read);
  font-size: 1.05rem;
  line-height: 1.75;
}

.appendix-answer em {
  font-style: normal;
  font-weight: 600;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--green);
  display: block;
  margin-bottom: 0.5rem;
}

body.appendix-hide-answers .appendix-card details {
  pointer-events: auto;
}

body.appendix-hide-answers .appendix-card details:not([open]) .appendix-answer {
  display: none;
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .mobile-header {
    display: flex;
  }

  .main {
    padding-top: calc(var(--mobile-header-h) + env(safe-area-inset-top, 0px));
  }

  .reader-toolbar {
    margin-top: 0;
    top: calc(var(--mobile-header-h) + env(safe-area-inset-top, 0px));
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 90;
    background: rgb(0 0 0 / 50%);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  .sidebar-backdrop.is-visible {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar-backdrop[hidden] {
    display: none;
  }

  .sidebar-backdrop.is-visible[hidden] {
    display: block;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
    width: min(20rem, 88vw);
    max-width: 88vw;
    height: 100%;
    height: 100dvh;
    max-height: none;
    transform: translateX(-105%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 24px rgb(0 0 0 / 35%);
    padding-top: max(1rem, env(safe-area-inset-top));
    padding-bottom: max(2rem, env(safe-area-inset-bottom));
    -webkit-overflow-scrolling: touch;
  }

  body.sidebar-open {
    overflow: hidden;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-brand {
    position: relative;
    padding-right: 1rem;
  }

  .sidebar-top {
    display: flex;
  }

  .sidebar-close {
    display: flex;
  }

  .toc a {
    padding: 0.65rem 0.75rem;
    font-size: 0.95rem;
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .toc-part summary {
    padding: 0.65rem 0.75rem;
    min-height: 44px;
  }

  .reader-toolbar {
    position: sticky;
    z-index: 60;
  }

  .toolbar-toggle {
    display: flex;
  }

  .reader-toolbar-controls {
    padding: 0.5rem 0.65rem;
    gap: 0.35rem;
  }

  .reader-toolbar .toolbar-label {
    display: none;
  }

  .reader-toolbar button,
  .reader-toolbar a.btn-jump {
    min-height: 44px;
    min-width: 44px;
    padding: 0.5rem 0.65rem;
    font-size: 0.72rem;
  }

  .toolbar-spacer {
    display: none;
  }

  .main-inner {
    padding: 0.75rem 0.65rem 2rem;
    padding-bottom: max(2rem, env(safe-area-inset-bottom));
  }

  .reading-card {
    padding: 1.15rem 1rem;
    box-shadow: none;
    border-left: none;
    border-right: none;
  }

  .prose {
    font-size: 1.0625rem;
    line-height: 1.8;
  }

  .chapter-header h1 {
    font-size: 1.5rem;
  }

  .chapter-nav {
    flex-direction: column;
  }

  .chapter-nav a {
    min-width: 0;
    width: 100%;
    text-align: left;
    min-height: 48px;
    display: flex;
    align-items: center;
  }

  .nav-next {
    text-align: left;
  }

  .section-jump {
    gap: 0.35rem;
  }

  .section-jump a {
    font-size: 0.62rem;
    padding: 0.45rem 0.6rem;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
  }

  .chapter-body .layer {
    padding: 1rem;
    margin: 1.25rem 0;
  }

  .chapter-body .layer-heading {
    margin: -1rem 0 0.85rem -1rem;
  }

  .appendix-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .appendix-controls input {
    min-width: 0;
    width: 100%;
    min-height: 44px;
    font-size: 16px;
  }

  .appendix-count {
    text-align: center;
  }

  .appendix-card summary {
    padding: 0.85rem 0.9rem;
    font-size: 0.95rem;
    min-height: 48px;
  }

  .appendix-card .q-badge {
    display: block;
    width: fit-content;
    margin-bottom: 0.35rem;
  }

  .stats {
    width: 100%;
  }

  .stat {
    flex: 1;
    padding: 0.6rem 0.5rem;
  }

  .home-hero h1 {
    font-size: 1.55rem;
  }

  .cram-banner {
    font-size: 0.95rem;
  }

  .layout-appendix .reader-toolbar .appendix-only {
    flex: 1 1 auto;
    min-width: calc(50% - 0.25rem);
  }
}

/* —— Mobile header + hamburger —— */
.mobile-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 80;
  align-items: center;
  gap: 0.65rem;
  min-height: var(--mobile-header-h);
  padding: 0 0.75rem;
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  border-bottom: 2px solid var(--yellow);
}

.mobile-header-text {
  flex: 1;
  min-width: 0;
  line-height: 1.25;
}

.mobile-header-book {
  display: block;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.01em;
  color: #fff;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mobile-header-book:hover {
  color: var(--yellow);
}

.mobile-header-page {
  margin: 0.15rem 0 0;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--sidebar-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mobile-header-page:empty {
  display: none;
}

.hamburger-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid rgb(255 255 255 / 25%);
  border-radius: 0;
  background: transparent;
  cursor: pointer;
}

.hamburger-btn:hover {
  border-color: var(--yellow);
}

.hamburger-icon {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 22px;
  height: 16px;
}

.hamburger-line {
  display: block;
  width: 22px;
  height: 2px;
  background: #fff;
  transition: transform 0.2s ease, opacity 0.2s ease;
  transform-origin: center;
}

body.sidebar-open .hamburger-line:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

body.sidebar-open .hamburger-line:nth-child(2) {
  opacity: 0;
}

body.sidebar-open .hamburger-line:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.sidebar-backdrop {
  display: none;
}

.sidebar-top {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid rgb(255 255 255 / 14%);
  background: rgb(0 0 0 / 25%);
}

.sidebar-top-title {
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--yellow);
}

.sidebar-close {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid rgb(255 255 255 / 25%);
  border-radius: 0;
  background: transparent;
  color: #fff;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

.sidebar-close-icon {
  display: block;
  margin-top: -2px;
}

.sidebar-close:hover {
  border-color: var(--yellow);
  color: var(--yellow);
}

.sidebar-close:focus-visible {
  outline: 2px solid var(--yellow);
  outline-offset: 2px;
}

@media (max-width: 480px) {
  .reader-toolbar-controls {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
  }

  body.toolbar-collapsed .reader-toolbar-controls {
    display: none;
  }

  .reader-toolbar-controls a.btn-jump,
  .reader-toolbar-controls .appendix-only {
    grid-column: 1 / -1;
  }

  .layout-appendix .reader-toolbar-controls {
    grid-template-columns: repeat(2, 1fr);
  }

  .prose pre {
    font-size: 0.85rem;
    padding: 0.85rem;
    margin-left: -0.25rem;
    margin-right: -0.25rem;
  }
}

@media (min-width: 901px) {
  .mobile-header,
  .sidebar-top,
  .sidebar-close,
  .sidebar-backdrop,
  .toolbar-toggle {
    display: none !important;
  }

  .reader-toolbar-controls {
    display: flex !important;
  }
}
