:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f0f5f7;
  --ink: #17202a;
  --muted: #52616d;
  --line: #dbe3e7;
  --navy: #153b4d;
  --teal: #087f7b;
  --teal-dark: #086865;
  --teal-soft: #dff4f1;
  --blue: #3366a6;
  --blue-soft: #e8f1fb;
  --green: #277a54;
  --green-soft: #e5f5ec;
  --orange: #a85610;
  --orange-soft: #fff0dc;
  --purple: #7551a6;
  --purple-soft: #f0eafb;
  --red: #a83b3b;
  --red-soft: #fdeaea;
  --hero-bg: #153b4d;
  --hero-ink: #ffffff;
  --hero-muted: #d8e5e8;
  --hero-accent: #9fe2dc;
  --on-teal: #ffffff;
  --shadow: 0 12px 35px rgba(21, 59, 77, 0.08);
  --radius: 18px;
  --sidebar: 245px;
  --rail: 270px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #10181c;
  --surface: #172227;
  --surface-soft: #1d2d33;
  --ink: #eef5f5;
  --muted: #a7b7bd;
  --line: #2d4148;
  --navy: #d6eff1;
  --teal: #62d2ca;
  --teal-dark: #83e3dc;
  --teal-soft: #163c3b;
  --blue: #82b1e8;
  --blue-soft: #1b344e;
  --green: #81d5aa;
  --green-soft: #193a2b;
  --orange: #f0a45d;
  --orange-soft: #492f18;
  --purple: #c3a3ec;
  --purple-soft: #342746;
  --red: #f08d8d;
  --red-soft: #482426;
  --hero-bg: #123b44;
  --hero-ink: #ffffff;
  --hero-muted: #d8e5e8;
  --hero-accent: #9fe2dc;
  --on-teal: #062b2a;
  --shadow: 0 12px 35px rgba(0, 0, 0, 0.22);
}

* { box-sizing: border-box; }

html {
  overflow-x: clip;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--sticky-h, 72px) + 16px);
}

body {
  overflow-x: clip;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.65;
}

button, input { font: inherit; }
button { cursor: pointer; }
a { color: var(--teal-dark); }

.sr-only,
.skip-link:not(:focus) {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 12px;
  left: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--navy);
  color: var(--surface);
}

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 10px 28px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--navy);
  text-decoration: none;
  line-height: 1.12;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 13px;
  background: var(--navy);
  color: var(--surface);
  font-family: Georgia, serif;
  font-size: 25px;
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 16px; letter-spacing: 0.01em; }
.brand small { margin-top: 4px; color: var(--muted); font-size: 11px; letter-spacing: 0.05em; text-transform: uppercase; }

.header-actions { display: flex; align-items: center; gap: 10px; }

.chapter-picker {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.chapter-picker select {
  max-width: 215px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 12px;
}

.chapter-picker:focus-within {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--teal) 18%, transparent);
}

.chapter-picker option {
  background: #ffffff;
  color: #17202a;
}

.chapter-picker option:checked {
  background: #b9e3e4;
  color: #153b4d;
}

.search {
  display: flex;
  width: min(30vw, 290px);
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
}

.search:focus-within {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--teal) 18%, transparent);
}

.search svg {
  width: 18px;
  fill: none;
  stroke: var(--muted);
  stroke-linecap: round;
  stroke-width: 2;
}

.search input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.search input::placeholder {
  color: var(--muted);
  opacity: 1;
}

input[type="radio"],
input[type="checkbox"] {
  accent-color: var(--teal-dark);
}

.icon-button, .button {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
}

.icon-button {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  font-size: 19px;
}

.button { padding: 9px 14px; font-weight: 700; }
.button-primary { border-color: var(--teal); background: var(--teal); color: var(--on-teal); }
.button-primary:hover { background: var(--teal-dark); }

.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 900px) var(--rail);
  justify-content: center;
  gap: 28px;
  padding: 30px 28px 80px;
}

.sidebar, .study-rail {
  position: sticky;
  top: calc(var(--sticky-h, 72px) + 24px);
  min-width: 0;
  max-width: 100%;
  height: fit-content;
}

.progress-card, .rail-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.progress-card { padding: 16px; }
.progress-heading { display: flex; justify-content: space-between; font-size: 13px; }
.progress-card small { color: var(--muted); font-size: 11px; }
.progress-track { height: 7px; margin: 10px 0 6px; overflow: hidden; border-radius: 99px; background: var(--line); }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--teal); transition: width 250ms ease; }

#chapter-nav { margin: 22px 0; }
#chapter-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 3px 0;
  padding: 8px 9px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
  text-decoration: none;
}

#chapter-nav a::before {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border: 2px solid var(--line);
  border-radius: 50%;
  content: "";
}

#chapter-nav a.active { background: var(--teal-soft); color: var(--teal-dark); font-weight: 700; }
#chapter-nav a.complete::before { border-color: var(--teal); background: var(--teal); }

.sidebar-note {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}
.sidebar-note strong, .sidebar-note span { display: block; }
.status-dot { width: 8px; height: 8px; margin-top: 4px; border-radius: 50%; background: var(--orange); }

main { min-width: 0; }

.hero {
  position: relative;
  overflow: hidden;
  padding: 50px;
  border-radius: 28px;
  background: var(--hero-bg);
  color: var(--hero-ink);
  box-shadow: var(--shadow);
}

.hero::after {
  position: absolute;
  right: -80px;
  bottom: -110px;
  width: 300px;
  height: 300px;
  border: 65px solid rgba(255,255,255,0.06);
  border-radius: 50%;
  content: "";
}

.hero .eyebrow { color: var(--hero-accent); }
.hero h1 { max-width: 650px; margin: 8px 0 16px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(36px, 5vw, 61px); font-weight: 500; line-height: 1.04; letter-spacing: -0.03em; }
.hero p { max-width: 650px; margin: 0; color: var(--hero-muted); font-size: 17px; }
.hero-meta { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 30px; }
.hero-meta span { padding: 6px 10px; border: 1px solid rgba(255,255,255,0.18); border-radius: 99px; background: rgba(255,255,255,0.07); font-size: 12px; }

.learning-path {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 18px;
}

.path-item { padding: 17px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.path-item strong, .path-item span { display: block; }
.path-item strong { color: var(--teal-dark); font-family: Georgia, serif; font-size: 25px; }
.path-item span { color: var(--muted); font-size: 12px; line-height: 1.4; }

.chapter-section {
  margin-top: 24px;
  padding: 36px 40px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: 0 8px 25px rgba(21, 59, 77, 0.04);
}

.section-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 25px; }
.section-number { display: block; margin-bottom: 8px; color: var(--teal-dark); font-size: 11px; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; }
.section-header h2 { margin: 0; color: var(--navy); font-family: Georgia, "Times New Roman", serif; font-size: 32px; font-weight: 500; line-height: 1.15; }
.section-header p { max-width: 650px; margin: 8px 0 0; color: var(--muted); }

.complete-button {
  flex: 0 0 auto;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
}
.complete-button.is-complete { border-color: var(--teal); background: var(--teal-soft); color: var(--teal-dark); }

h3 { margin: 28px 0 12px; color: var(--navy); font-size: 19px; line-height: 1.3; }
h4 { margin: 20px 0 8px; }
p { margin: 10px 0; }
ul, ol { padding-left: 22px; }
li + li { margin-top: 5px; }

.eyebrow { color: var(--teal-dark); font-size: 10px; font-weight: 900; letter-spacing: 0.13em; text-transform: uppercase; }
.lead { color: var(--navy); font-family: Georgia, serif; font-size: 20px; line-height: 1.55; }
.muted { color: var(--muted); }
.micro-note { color: var(--muted); font-size: 12px; }

.tag {
  display: inline-block;
  margin-right: 4px;
  padding: 3px 7px;
  border-radius: 99px;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.tag.core { background: var(--blue-soft); color: var(--blue); }
.tag.clinical { background: var(--green-soft); color: var(--green); }
.tag.exam { background: var(--purple-soft); color: var(--purple); }
.tag.advanced { background: var(--orange-soft); color: var(--orange); }
.tag.safety { background: var(--red-soft); color: var(--red); }

.card-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin: 18px 0; }
.card { padding: 20px; border: 1px solid var(--line); border-radius: 15px; background: var(--bg); }
.card h3, .card h4 { margin-top: 0; }
.card p:last-child { margin-bottom: 0; }

.callout { margin: 20px 0; padding: 18px 20px; border-left: 4px solid var(--blue); border-radius: 0 13px 13px 0; background: var(--blue-soft); }
.callout strong:first-child { color: var(--blue); }
.callout.clinical { border-color: var(--green); background: var(--green-soft); }
.callout.clinical strong:first-child { color: var(--green); }
.callout.exam { border-color: var(--purple); background: var(--purple-soft); }
.callout.exam strong:first-child { color: var(--purple); }
.callout.warning { border-color: var(--orange); background: var(--orange-soft); }
.callout.warning strong:first-child { color: var(--orange); }
.callout.danger { border-color: var(--red); background: var(--red-soft); }
.callout.danger strong:first-child { color: var(--red); }

.flow { display: flex; align-items: stretch; gap: 8px; margin: 20px 0; }
.flow-step { position: relative; min-width: 0; flex: 1; padding: 15px; overflow-wrap: anywhere; border: 1px solid var(--line); border-radius: 13px; background: var(--bg); text-align: center; }
.flow-step:not(:last-child)::after { position: absolute; z-index: 2; top: 50%; right: -10px; color: var(--teal); content: "→"; font-weight: 900; transform: translateY(-50%); }
.flow-step strong, .flow-step span { display: block; }
.flow-step strong { color: var(--navy); }
.flow-step span { color: var(--muted); font-size: 11px; }

.gram-visual { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 24px 0; }
.cell-result { padding: 22px; border: 1px solid var(--line); border-radius: 16px; text-align: center; }
.cell-result.positive { background: var(--purple-soft); }
.cell-result.negative { background: var(--red-soft); }
.bacteria { display: flex; min-height: 72px; align-items: center; justify-content: center; gap: 8px; }
.bacillus { display: inline-block; width: 45px; height: 16px; border: 3px solid currentColor; border-radius: 99px; transform: rotate(18deg); }
.bacillus:nth-child(2) { transform: rotate(-18deg); }
.positive .bacteria { color: #6d42a0; }
.negative .bacteria { color: #d0526f; }
.cell-result strong { display: block; margin-top: 10px; }
.cell-result small { color: var(--muted); }

.smear-gallery { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin: 18px 0; }
.smear-card { margin: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); }
.smear-card svg { display: block; width: 100%; height: auto; border-bottom: 1px solid var(--line); }
.smear-card figcaption { display: block; padding: 13px 15px; }
.smear-card figcaption strong, .smear-card figcaption span { display: block; }
.smear-card figcaption strong { color: var(--navy); }
.smear-card figcaption span { margin-top: 4px; color: var(--muted); font-size: 11px; line-height: 1.45; }

.cell-blueprint,
.envelope-compare figure,
.flagella-grid figure {
  margin: 18px 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface-soft);
}

.cell-blueprint svg { display: block; width: 100%; height: auto; }

.envelope-compare {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.envelope-compare figure { margin: 0; background: var(--surface); }
.envelope-compare svg { display: block; width: 100%; height: auto; border-bottom: 1px solid var(--line); }
.envelope-compare figcaption,
.flagella-grid figcaption { display: block; padding: 13px 15px; }
.envelope-compare figcaption strong,
.envelope-compare figcaption span,
.flagella-grid figcaption strong,
.flagella-grid figcaption span { display: block; }
.envelope-compare figcaption span,
.flagella-grid figcaption span { margin-top: 4px; color: var(--muted); font-size: 11px; }

.flagella-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 18px 0; }
.flagella-grid figure { margin: 0; background: var(--surface); }
.flagella-cell {
  position: relative;
  height: 120px;
  border-bottom: 1px solid var(--line);
  background: var(--teal-soft);
}
.flagella-cell::before {
  position: absolute;
  top: 42px;
  left: calc(50% - 34px);
  width: 68px;
  height: 32px;
  border: 4px solid var(--navy);
  border-radius: 50%;
  background: var(--surface);
  content: "";
}
.flagella-cell span { position: absolute; display: block; width: 46px; height: 25px; border-top: 3px solid var(--teal-dark); border-radius: 50%; }
.flagella-cell.mono span { top: 47px; right: 8px; }
.flagella-cell.lopho span:nth-child(1) { top: 35px; right: 7px; transform: rotate(-18deg); }
.flagella-cell.lopho span:nth-child(2) { top: 48px; right: 4px; }
.flagella-cell.lopho span:nth-child(3) { top: 61px; right: 7px; transform: rotate(18deg); }
.flagella-cell.amphi span:nth-child(1) { top: 46px; right: 7px; }
.flagella-cell.amphi span:nth-child(2) { top: 46px; left: 7px; transform: scaleX(-1); }
.flagella-cell.peri span:nth-child(1) { top: 20px; left: 45px; transform: rotate(-75deg); }
.flagella-cell.peri span:nth-child(2) { top: 48px; right: 5px; }
.flagella-cell.peri span:nth-child(3) { bottom: 15px; left: 45px; transform: rotate(75deg); }
.flagella-cell.peri span:nth-child(4) { top: 48px; left: 5px; transform: scaleX(-1); }

.spore-visual {
  position: relative;
  display: grid;
  min-height: 390px;
  place-items: center;
  margin: 20px 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface-soft);
}
.spore-layer {
  position: absolute;
  display: grid;
  place-items: center;
  border-radius: 50%;
  text-align: center;
}
.spore-layer strong, .spore-layer span { display: block; }
.spore-layer span { max-width: 180px; color: var(--muted); font-size: 10px; line-height: 1.35; }
.spore-layer:not(.core-spore) > strong { display: none; }
.spore-layer:not(.core-spore) > span { display: none; }
.spore-layer.coat { z-index: 0; width: 360px; height: 330px; border: 18px solid #674b2d; background: #eee0c9; }
.spore-layer.cortex { z-index: 1; width: 290px; height: 260px; border: 16px solid #d7a34d; background: #f8e6bd; }
.spore-layer.inner-membrane { z-index: 2; width: 220px; height: 190px; border: 12px solid var(--teal-dark); background: var(--teal-soft); }
.spore-layer.core-spore { z-index: 3; width: 150px; height: 125px; padding: 15px; border: 8px solid var(--navy); background: var(--surface); }

.typing-ladder {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: end;
  gap: 8px;
  margin: 20px 0;
}
.typing-ladder div {
  display: flex;
  min-height: 90px;
  flex-direction: column;
  justify-content: flex-end;
  padding: 14px 11px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
}
.typing-ladder div:nth-child(2) { min-height: 110px; background: var(--blue-soft); }
.typing-ladder div:nth-child(3) { min-height: 130px; background: var(--teal-soft); }
.typing-ladder div:nth-child(4) { min-height: 150px; background: var(--purple-soft); }
.typing-ladder div:nth-child(5) { min-height: 170px; background: var(--orange-soft); }
.typing-ladder strong, .typing-ladder span { display: block; }
.typing-ladder strong { color: var(--navy); font-size: 12px; }
.typing-ladder span { margin-top: 5px; color: var(--muted); font-size: 10px; line-height: 1.35; }

.genome-compare {
  margin: 20px 0;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface-soft);
}
.genome-row {
  display: grid;
  grid-template-columns: 90px repeat(8, 1fr);
  gap: 5px;
  align-items: center;
  margin: 8px 0;
}
.genome-row strong { color: var(--navy); font-size: 11px; }
.genome-row span { height: 24px; border-radius: 5px; background: var(--teal); }
.genome-row.reference span { background: var(--line); }
.genome-row .variant { background: var(--red); }
.genome-row.distant span:not(.variant) { background: var(--blue); }

.table-wrap { width: 100%; max-width: 100%; margin: 18px 0; overflow-x: auto; contain: inline-size; border: 1px solid var(--line); border-radius: 14px; }
table { width: 100%; border-collapse: collapse; background: var(--surface); font-size: 13px; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--surface-soft); color: var(--navy); font-size: 11px; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: 0; }

.decision-tree { margin: 20px 0; padding: 24px; border-radius: 16px; background: var(--surface-soft); text-align: center; }
.decision-root { display: inline-block; padding: 10px 16px; border-radius: 10px; background: var(--navy); color: var(--surface); font-weight: 800; }
.decision-branches { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 25px; }
.branch { position: relative; padding: 15px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.branch::before { position: absolute; top: -25px; left: 50%; width: 1px; height: 24px; background: var(--line); content: ""; }
.branch strong { display: block; color: var(--teal-dark); }
.branch span { color: var(--muted); font-size: 11px; }

.case {
  overflow: hidden;
  margin: 20px 0;
  border: 1px solid var(--line);
  border-radius: 16px;
}
.case-header { display: flex; justify-content: space-between; gap: 15px; padding: 14px 18px; background: var(--green-soft); }
.case-header strong { color: var(--green); }
.case-body { padding: 20px; }
.case-question { margin-top: 15px; padding: 12px 14px; border-radius: 10px; background: var(--bg); font-weight: 700; }
details { margin-top: 10px; border: 1px solid var(--line); border-radius: 10px; }
summary { padding: 11px 14px; color: var(--teal-dark); font-weight: 800; cursor: pointer; }
details > div { padding: 0 14px 14px; }

.growth-curve { width: 100%; max-height: 340px; margin: 15px 0; }
.growth-curve text { fill: var(--muted); font-family: Inter, "Segoe UI", sans-serif; font-size: 12px; }
.growth-curve .axis { stroke: var(--muted); stroke-width: 1.5; }
.growth-curve .curve { fill: none; stroke: var(--teal); stroke-linecap: round; stroke-width: 5; }
.growth-curve .guide { stroke: var(--line); stroke-dasharray: 5; }

.flashcard-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.flashcard { min-height: 155px; padding: 0; border: 0; border-radius: 15px; background: transparent; perspective: 1000px; text-align: left; }
.flashcard-inner { position: relative; display: block; width: 100%; height: 100%; min-height: 155px; transition: transform 400ms; transform-style: preserve-3d; }
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard-face { position: absolute; display: flex; width: 100%; height: 100%; min-height: 155px; flex-direction: column; justify-content: space-between; padding: 20px; border: 1px solid var(--line); border-radius: 15px; background: var(--bg); backface-visibility: hidden; }
.flashcard-back { background: var(--teal-soft); transform: rotateY(180deg); }
.flashcard-face small { color: var(--muted); }

.quiz-question { margin: 18px 0; padding: 20px; border: 1px solid var(--line); border-radius: 15px; }
.quiz-question fieldset { margin: 0; padding: 0; border: 0; }
.quiz-question legend { margin-bottom: 12px; color: var(--navy); font-weight: 800; }
.quiz-option { display: block; margin: 7px 0; padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px; cursor: pointer; }
.quiz-option:has(input:checked) { border-color: var(--teal); background: var(--teal-soft); }
.quiz-feedback { margin-top: 10px; padding: 10px; border-radius: 8px; background: var(--surface-soft); }

.reference-list { padding-left: 20px; }
.reference-list li { margin-bottom: 12px; }
.reference-list a { overflow-wrap: anywhere; }

.rail-card { margin-bottom: 16px; padding: 20px; }
.rail-card h2 { margin: 4px 0 8px; color: var(--navy); font-family: Georgia, serif; font-size: 22px; font-weight: 500; }
.rail-card p { color: var(--muted); font-size: 12px; }
.mode-list { margin-top: 15px; }
.mode-item { display: flex; align-items: center; gap: 10px; margin-top: 8px; padding: 9px; border-radius: 9px; background: var(--bg); font-size: 11px; }
.mode-icon { display: grid; width: 27px; height: 27px; place-items: center; border-radius: 8px; background: var(--teal-soft); color: var(--teal-dark); font-weight: 900; }
.pearl-card { display: flex; align-items: flex-start; gap: 12px; background: var(--purple-soft); }
.pearl-icon { color: var(--purple); font-size: 22px; }
.pearl-card p { margin: 5px 0 0; color: var(--ink); }

.search-panel {
  position: fixed;
  z-index: 30;
  inset: var(--sticky-h, 72px) 0 0;
  padding: 30px;
  background: rgba(12, 25, 30, 0.48);
  backdrop-filter: blur(5px);
}
.search-panel-inner { width: min(760px, 100%); max-height: 75vh; margin: auto; overflow: auto; border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
.search-panel-header { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); background: var(--surface); }
.search-result { display: block; padding: 16px 20px; border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.search-result:hover { background: var(--bg); }
.search-result strong, .search-result span { display: block; }
.search-result span { color: var(--muted); font-size: 12px; }

.empty-state { padding: 40px; color: var(--muted); text-align: center; }
.search-hidden { display: none !important; }
.print-footer { display: none; }

@media (max-width: 1220px) {
  .app-layout { grid-template-columns: var(--sidebar) minmax(0, 900px); }
  .study-rail { display: none; }
}

@media (max-width: 850px) {
  .app-header { padding: 10px 16px; }
  .brand small { display: none; }
  .search { width: 190px; }
  .chapter-picker span { display: none; }
  .chapter-picker select { width: 52px; }
  #print-button { font-size: 0; }
  #print-button span { font-size: 18px; }
  .app-layout { display: block; padding: 18px 14px 50px; }
  .sidebar { position: static; margin-bottom: 18px; }
  #chapter-nav { display: flex; width: 100%; max-width: 100%; overflow-x: auto; contain: inline-size; gap: 5px; margin: 12px 0; padding-bottom: 5px; }
  #chapter-nav a { flex: 0 0 auto; border: 1px solid var(--line); background: var(--surface); }
  .sidebar-note { display: none; }
  .hero { padding: 35px 25px; }
  .learning-path { grid-template-columns: repeat(2, 1fr); }
  .chapter-section { padding: 28px 23px; }
}

@media (max-width: 560px) {
  .brand span:last-child { display: none; }
  .header-actions { min-width: 0; flex: 1; justify-content: flex-end; gap: 6px; }
  .search { width: auto; min-width: 0; flex: 1; }
  .chapter-picker { padding: 8px 6px; }
  .chapter-picker select { width: 44px; }
  #theme-toggle { display: none; }
  .icon-button { width: 37px; height: 37px; }
  .hero h1 { font-size: 38px; }
  .hero-meta span { overflow-wrap: anywhere; }
  .section-header { display: block; }
  .section-header h2 { overflow-wrap: anywhere; }
  .complete-button { margin-top: 14px; }
  .card-grid, .flashcard-grid, .gram-visual, .decision-branches { grid-template-columns: 1fr; }
  .smear-gallery { grid-template-columns: 1fr; }
  .envelope-compare { grid-template-columns: 1fr; }
  .flagella-grid { grid-template-columns: repeat(2, 1fr); }
  .spore-visual { min-height: 340px; transform: scale(.9); margin: -5px; }
  .typing-ladder { grid-template-columns: 1fr; align-items: stretch; }
  .typing-ladder div,
  .typing-ladder div:nth-child(n) { min-height: 0; }
  .genome-row { grid-template-columns: 70px repeat(8, 1fr); gap: 3px; }
  .flow { flex-direction: column; }
  .flow-step:not(:last-child)::after { top: auto; right: 50%; bottom: -15px; transform: rotate(90deg); }
}

@media print {
  @page { size: A4; margin: 15mm 14mm 17mm; }
  :root {
    color-scheme: light;
    --bg: #fff;
    --surface: #fff;
    --surface-soft: #f3f6f6;
    --ink: #17202a;
    --muted: #56636d;
    --line: #cfd9dd;
    --navy: #153b4d;
    --teal: #087f7b;
    --teal-dark: #086865;
    --teal-soft: #e4f4f2;
    --blue: #3366a6;
    --blue-soft: #e8f1fb;
    --green: #277a54;
    --green-soft: #e5f5ec;
    --orange: #a85610;
    --orange-soft: #fff0dc;
    --purple: #7551a6;
    --purple-soft: #f0eafb;
    --red: #a83b3b;
    --red-soft: #fdeaea;
  }
  body { background: #fff; font-size: 10.2pt; }
  .app-header, .sidebar, .study-rail, .complete-button, .search-panel, .skip-link, .button, .icon-button { display: none !important; }
  .app-layout { display: block; padding: 0; }
  main { width: 100%; }
  .cover { min-height: 250mm; background: var(--navy); break-after: page; }
  .hero { min-height: 150mm; padding: 24mm 20mm 10mm; border-radius: 0; box-shadow: none; }
  .hero h1 { font-size: 35pt; }
  .learning-path { margin: 0; padding: 0 20mm 15mm; background: var(--navy); }
  .path-item { padding: 10px; border-color: rgba(255,255,255,0.22); background: rgba(255,255,255,0.08); }
  .path-item strong { color: #9fe2dc; }
  .path-item span { color: #d8e5e8; }
  .chapter-section { margin: 0; padding: 8mm 0 4mm; border: 0; border-radius: 0; box-shadow: none; break-before: page; }
  .continuous-print .chapter-section { break-before: auto; }
  .continuous-print .section-header { break-after: avoid; }
  .section-header h2 { font-size: 22pt; }
  .card, .callout, .flow, .gram-visual, .smear-card, .cell-blueprint, .envelope-compare, .flagella-grid, .spore-visual, .typing-ladder, .genome-compare, .table-wrap, .case, .decision-tree, .quiz-question, details { break-inside: avoid; }
  .flashcard-grid { display: block; }
  .flashcard { display: block; min-height: 0; margin: 4mm 0; }
  .flashcard-inner { min-height: 0; transform: none !important; }
  .flashcard-face { position: static; display: block; min-height: 0; margin: 2mm 0; backface-visibility: visible; }
  .flashcard-back { transform: none; }
  .flashcard-face strong, .flashcard-face span { display: block; }
  .flashcard-back span { margin-top: 2mm; }
  .flashcard-face small { display: none; }
  details > div { display: block; }
  summary { list-style: none; }
  a { color: var(--ink); text-decoration: none; }
  .print-footer { position: fixed; right: 0; bottom: -10mm; left: 0; display: flex; justify-content: space-between; color: var(--muted); font-size: 8pt; }
}

/* ===================================================================== *
 * MedPulse IQ Books shell (medpulse.js): navigation, Listen, Dr. Amy.   *
 * ===================================================================== */

.mp-topbar {
  position: relative;
  z-index: 21;
  display: flex;
  min-height: 46px;
  align-items: center;
  gap: 18px;
  padding: 6px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  font-size: 13px;
}
.mp-logo { display: inline-flex; flex: 0 0 auto; align-items: center; gap: 8px; color: var(--ink); font-weight: 800; text-decoration: none; }
.mp-logo svg { width: 26px; height: 26px; fill: none; stroke: var(--teal-dark); stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
.mp-logo b { color: var(--teal-dark); }
.mp-crumbs { display: flex; min-width: 0; flex: 1; align-items: center; margin: 0; padding: 0; color: var(--muted); list-style: none; white-space: nowrap; }
.mp-crumbs li { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.mp-crumbs li + li { margin-top: 0; }
.mp-crumbs li + li::before { padding: 0 8px; color: var(--muted); content: "/"; }
.mp-crumbs a { color: var(--muted); text-decoration: none; }
.mp-crumbs a:hover { color: var(--teal-dark); text-decoration: underline; }
.mp-crumbs [aria-current] { color: var(--ink); font-weight: 700; }
.mp-top-links { display: flex; flex: 0 0 auto; align-items: center; gap: 14px; }
.mp-top-links a { color: var(--muted); font-weight: 700; text-decoration: none; }
.mp-top-links a:hover { color: var(--teal-dark); }
.mp-top-links .mp-dashboard { padding: 6px 13px; border-radius: 99px; background: var(--teal); color: var(--on-teal); }
.mp-top-links .mp-dashboard:hover { background: var(--teal-dark); color: var(--on-teal); }

.contents-button { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.chapter-step { color: var(--ink); font-size: 24px; line-height: 1; text-decoration: none; }
.chapter-step:hover { border-color: var(--teal); color: var(--teal-dark); }
.chapter-step.is-disabled { opacity: 0.35; }

/* Hero actions sit on the dark hero in both themes, so they use hero tokens only. */
.hero-actions { position: relative; z-index: 1; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 22px; }
.mode-toggle { display: inline-flex; padding: 4px; border: 1px solid rgba(255,255,255,0.28); border-radius: 99px; background: rgba(255,255,255,0.08); }
.mode-toggle button { padding: 7px 14px; border: 0; border-radius: 99px; background: transparent; color: var(--hero-muted); font-size: 13px; font-weight: 700; }
.mode-toggle button.is-active { background: var(--hero-accent); color: #0b3540; }
.hero-button { display: inline-flex; align-items: center; gap: 7px; padding: 8px 15px; border: 1px solid rgba(255,255,255,0.32); border-radius: 99px; background: rgba(255,255,255,0.08); color: var(--hero-ink); font-size: 13px; font-weight: 700; text-decoration: none; }
.hero-button:hover { background: rgba(255,255,255,0.16); }
.hero-button-solid { border-color: #ffffff; background: #ffffff; color: #153b4d; }
.hero-button-solid:hover { background: #e3f4f2; }
.hero-select { padding: 7px 10px; border: 1px solid rgba(255,255,255,0.32); border-radius: 99px; background: rgba(255,255,255,0.08); color: var(--hero-ink); font: inherit; font-size: 12px; }
.hero-select option, .listen-controls select option, .tutor-focus select option { background: #ffffff; color: #17202a; }
.hero-actions :focus-visible { outline: 3px solid var(--hero-accent); outline-offset: 2px; }

.amy-invite {
  display: flex;
  align-items: flex-start;
  gap: 22px;
  margin-top: 18px;
  padding: 24px;
  border: 1px solid color-mix(in srgb, var(--teal) 35%, var(--line));
  border-radius: 22px;
  background: linear-gradient(135deg, var(--teal-soft), var(--surface) 70%);
  box-shadow: var(--shadow);
}
.amy-mic { display: grid; flex: 0 0 auto; width: 72px; height: 72px; place-items: center; border: 0; border-radius: 50%; background: var(--teal); box-shadow: 0 0 0 8px color-mix(in srgb, var(--teal) 18%, transparent); color: var(--on-teal); font-size: 30px; }
.amy-mic:hover { background: var(--teal-dark); }
.amy-copy { min-width: 0; }
.amy-name { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0; color: var(--ink); font-size: 19px; }
.amy-badge { padding: 3px 9px; border-radius: 99px; background: var(--teal-soft); color: var(--teal-dark); font-size: 10px; font-weight: 900; letter-spacing: 0.08em; text-transform: uppercase; }
.amy-tagline { margin: 6px 0 2px; color: var(--ink); font-size: 16px; font-weight: 700; }
.amy-blurb { margin: 0; color: var(--muted); font-size: 13px; }
.amy-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; }
.amy-label { color: var(--muted); font-size: 12px; }
.persona-toggle { display: inline-flex; overflow: hidden; border: 1px solid var(--line); border-radius: 99px; background: var(--surface); }
.persona-toggle button { padding: 5px 12px; border: 0; background: transparent; color: var(--muted); font-size: 12px; font-weight: 700; }
.persona-toggle button.is-active { background: var(--teal); color: var(--on-teal); }
.amy-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.amy-actions .button { border-radius: 99px; }

.inline-anchor { display: none; align-items: flex-start; gap: 12px; margin-top: 16px; padding: 16px 18px; border: 1px solid var(--line); border-radius: 16px; background: var(--purple-soft); }
.inline-anchor > span { color: var(--purple); font-size: 20px; }
.inline-anchor p { margin: 4px 0 0; color: var(--ink); }

.connected-strip, .finish-connected { margin-top: 18px; }
.connected-strip { padding: 20px 22px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); }
.connected-head p { margin: 4px 0 12px; color: var(--muted); font-size: 13px; }
.connect-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.connect-chip { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); color: var(--ink); text-decoration: none; transition: border-color 150ms, transform 150ms; }
.connect-chip:hover { border-color: var(--teal); transform: translateY(-1px); }
.connect-chip > span:first-child { font-size: 20px; }
.connect-chip small, .connect-chip strong { display: block; }
.connect-chip small { color: var(--muted); font-size: 11px; line-height: 1.35; }
.connect-chip strong { margin-top: 2px; font-size: 13px; line-height: 1.35; }

.section-actions { display: flex; flex: 0 0 auto; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px; }
.section-tool { display: inline-flex; align-items: center; gap: 4px; padding: 7px 11px; border: 1px solid var(--line); border-radius: 99px; background: var(--surface); color: var(--ink); font-size: 11px; font-weight: 700; }
.section-tool:hover { border-color: var(--teal); color: var(--teal-dark); }
.chapter-section.is-speaking { border-color: var(--teal); box-shadow: 0 0 0 3px color-mix(in srgb, var(--teal) 22%, transparent), var(--shadow); }

.quiz-question.is-correct { border-color: var(--green); }
.quiz-question.is-incorrect { border-color: var(--orange); }
.quiz-question.is-unanswered { border-style: dashed; border-color: var(--blue); }
.quiz-score.is-scored { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-top: 16px; padding: 14px 16px; border: 1px solid var(--teal); border-radius: 14px; background: var(--teal-soft); color: var(--ink); }
.quiz-score.is-scored strong { color: var(--teal-dark); font-size: 16px; }
.quiz-score.is-scored span { flex: 1 1 260px; }
.quiz-reset { padding: 6px 12px; border: 1px solid var(--teal); border-radius: 99px; background: var(--surface); color: var(--teal-dark); font-weight: 700; }
.quiz-submit { margin-top: 8px; padding: 9px 18px; border: 1px solid var(--teal); border-radius: 99px; background: var(--teal); color: var(--on-teal); font-weight: 800; }
.ask-amy { display: inline-flex; align-items: center; gap: 6px; margin-top: 10px; padding: 6px 12px; border: 1px solid var(--teal); border-radius: 99px; background: var(--surface); color: var(--teal-dark); font-size: 12px; font-weight: 700; }
.ask-amy:hover { background: var(--teal-soft); }
.quiz-feedback .ask-amy { display: flex; width: fit-content; }

.chapter-finish { margin-top: 24px; padding: 32px 36px; border: 1px solid color-mix(in srgb, var(--teal) 40%, var(--line)); border-radius: 22px; background: linear-gradient(160deg, var(--teal-soft), var(--surface) 60%); }
.chapter-finish h2 { margin: 6px 0 8px; color: var(--ink); font-family: Georgia, "Times New Roman", serif; font-size: 28px; font-weight: 500; line-height: 1.2; }
.finish-progress { color: var(--teal-dark); font-weight: 800; }
.finish-kind { color: var(--muted); }
.finish-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.finish-actions .button { border-radius: 99px; text-decoration: none; }
.finish-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 22px; }
.finish-nav-card { padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); text-decoration: none; }
.finish-nav-card:hover { border-color: var(--teal); }
.finish-nav-card.is-next { text-align: right; }
.finish-nav-card small, .finish-nav-card strong { display: block; }
.finish-nav-card small { color: var(--muted); font-size: 12px; }

.next-card a { display: block; margin-top: 8px; color: var(--ink); text-decoration: none; }
.next-card a small { display: block; color: var(--muted); font-size: 11px; }
.next-card a strong { display: block; color: var(--teal-dark); }

/* Drawers */
.drawer-shell[hidden] { display: none; }
.drawer-backdrop { position: fixed; z-index: 58; inset: 0; background: rgba(8, 18, 22, 0.5); backdrop-filter: blur(3px); }
.contents-drawer, .tutor-drawer { position: fixed; z-index: 60; top: 0; bottom: 0; display: flex; flex-direction: column; background: var(--surface); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3); color: var(--ink); }
.contents-drawer { left: 0; width: min(430px, 92vw); padding: 20px; border-right: 1px solid var(--line); }
.drawer-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.drawer-header h2 { margin: 4px 0 0; color: var(--ink); font-family: Georgia, "Times New Roman", serif; font-size: 24px; font-weight: 500; }
.drawer-header p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.contents-search { flex: 0 0 auto; width: 100%; margin: 14px 0 10px; }
.toc-list { flex: 1; margin: 0; padding: 0 4px 0 0; overflow-y: auto; list-style: none; }
.toc-list li + li { margin-top: 6px; }
.toc-item { display: flex; gap: 12px; padding: 10px 12px; border: 1px solid transparent; border-radius: 12px; color: var(--ink); text-decoration: none; }
.toc-item:hover { border-color: var(--line); background: var(--bg); }
.toc-item.is-current { border-color: var(--teal); background: var(--teal-soft); }
.toc-num { flex: 0 0 auto; width: 30px; color: var(--teal-dark); font-family: Georgia, serif; font-size: 18px; font-weight: 700; }
.toc-body { min-width: 0; flex: 1; }
.toc-body strong, .toc-body small { display: block; }
.toc-body strong { font-size: 13px; line-height: 1.35; }
.toc-body small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.toc-bar { display: block; height: 4px; margin-top: 6px; overflow: hidden; border-radius: 99px; background: var(--line); }
.toc-bar i { display: block; height: 100%; border-radius: inherit; background: var(--teal); }
.drawer-footer { padding-top: 14px; border-top: 1px solid var(--line); }
.book-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.book-links a { padding: 6px 11px; border: 1px solid var(--line); border-radius: 99px; color: var(--ink); font-size: 12px; font-weight: 700; text-decoration: none; }
.book-links a:hover { border-color: var(--teal); color: var(--teal-dark); }
body.drawer-open { overflow: hidden; }

.tutor-drawer { right: 0; width: min(440px, 100vw); gap: 10px; padding: 18px; border-left: 1px solid var(--line); }
.tutor-backdrop { display: none; }
.tutor-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.tutor-identity { display: flex; min-width: 0; align-items: center; gap: 10px; }
.tutor-avatar { display: grid; flex: 0 0 auto; width: 44px; height: 44px; place-items: center; border-radius: 50%; background: var(--teal-soft); font-size: 24px; }
.tutor-identity h2 { margin: 0; color: var(--ink); font-size: 17px; }
.tutor-identity small { display: block; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.tutor-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.tutor-focus { display: inline-flex; min-width: 0; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; font-weight: 700; }
.tutor-focus select { max-width: 190px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 99px; background: var(--bg); color: var(--ink); font: inherit; font-size: 12px; }
.tutor-modes { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.tutor-mode-button { padding: 7px 13px; border: 1px solid var(--teal); border-radius: 99px; background: var(--teal-soft); color: var(--teal-dark); font-size: 12px; font-weight: 800; }
.tutor-link { padding: 0; border: 0; background: transparent; color: var(--teal-dark); font-size: 12px; font-weight: 800; }
.tutor-messages { display: flex; min-height: 0; flex: 1; flex-direction: column; gap: 10px; overflow-y: auto; padding: 4px 2px; }
.tutor-messages[hidden] { display: none; }
.msg > div { max-width: 88%; padding: 10px 13px; border-radius: 16px; font-size: 13.5px; line-height: 1.55; overflow-wrap: anywhere; }
.msg-user { display: flex; justify-content: flex-end; }
.msg-user > div { background: var(--teal); color: var(--on-teal); white-space: pre-wrap; }
.msg-ai > div { border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
.msg-ai p { margin: 0 0 6px; }
.msg-ai p:last-child { margin-bottom: 0; }
.msg-ai ul, .msg-ai ol { margin: 4px 0 6px; padding-left: 18px; }
.msg-ai code { padding: 1px 4px; border-radius: 4px; background: var(--surface-soft); }
.msg-action { display: inline-block; margin-top: 6px; color: var(--teal-dark); font-weight: 800; }
.tutor-suggestions { display: flex; flex-wrap: wrap; gap: 8px; }
.tutor-suggestions[hidden] { display: none; }
.tutor-suggestions .chip { padding: 7px 12px; border: 1px solid var(--line); border-radius: 99px; background: var(--bg); color: var(--ink); font-size: 12px; }
.tutor-suggestions .chip:hover { border-color: var(--teal); color: var(--teal-dark); }
.tutor-status { min-height: 1em; margin: 0; color: var(--teal-dark); font-size: 13px; font-weight: 700; text-align: center; }
.tutor-error { margin: 0; color: var(--orange); font-size: 12px; text-align: center; }
.tutor-error:empty, .tutor-status:empty { display: none; }
.tutor-mic-row { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.tutor-mic-row small { color: var(--muted); font-size: 11px; }
.tutor-mic { display: grid; width: 60px; height: 60px; place-items: center; border: 0; border-radius: 50%; background: var(--teal); box-shadow: 0 8px 20px color-mix(in srgb, var(--teal) 35%, transparent); color: var(--on-teal); font-size: 24px; }
.tutor-mic:disabled { opacity: 0.45; cursor: not-allowed; }
.tutor-mic.is-listening { background: #c62828; color: #ffffff; animation: mp-pulse 1.2s ease-in-out infinite; }
.tutor-form { display: flex; gap: 8px; }
.tutor-form input { min-width: 0; flex: 1; padding: 10px 14px; border: 1px solid var(--line); border-radius: 99px; outline: 0; background: var(--bg); color: var(--ink); font: inherit; font-size: 14px; }
.tutor-form input::placeholder { color: var(--muted); opacity: 1; }
.tutor-form input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px color-mix(in srgb, var(--teal) 18%, transparent); }
.tutor-form .button { border-radius: 99px; }
.tutor-form .button:disabled { opacity: 0.55; }
.tutor-footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px; color: var(--muted); font-size: 11px; }
.tutor-footer label { display: inline-flex; align-items: center; gap: 5px; color: var(--ink); }

.amy-fab { position: fixed; z-index: 45; right: 22px; bottom: 22px; display: inline-flex; align-items: center; gap: 8px; padding: 12px 18px 12px 14px; border: 0; border-radius: 99px; background: var(--teal); box-shadow: 0 12px 30px rgba(8, 60, 58, 0.35); color: var(--on-teal); font-size: 14px; font-weight: 700; }
.amy-fab > span:first-child { font-size: 20px; }
.amy-fab:hover { background: var(--teal-dark); }
body.tutor-open .amy-fab { display: none; }
body.is-listening .amy-fab { bottom: 100px; }
body.is-listening { padding-bottom: 90px; }

.listen-bar { position: fixed; z-index: 40; left: 50%; bottom: 18px; display: flex; width: min(720px, calc(100vw - 24px)); align-items: center; gap: 14px; padding: 10px 14px; border-radius: 18px; background: var(--hero-bg); box-shadow: 0 16px 40px rgba(0, 0, 0, 0.32); color: var(--hero-ink); transform: translateX(-50%); }
.listen-bar[hidden] { display: none; }
.listen-wave { display: inline-flex; flex: 0 0 auto; align-items: flex-end; gap: 3px; height: 22px; }
.listen-wave i { width: 4px; height: 8px; border-radius: 2px; background: var(--hero-accent); animation: mp-wave 900ms ease-in-out infinite; }
.listen-wave i:nth-child(2) { animation-delay: 150ms; }
.listen-wave i:nth-child(3) { animation-delay: 300ms; }
.listen-wave i:nth-child(4) { animation-delay: 450ms; }
.listen-bar.is-paused .listen-wave i { animation-play-state: paused; }
.listen-now { min-width: 0; flex: 1; }
.listen-now small, .listen-now strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.listen-now small { color: var(--hero-muted); font-size: 11px; }
.listen-now strong { font-size: 14px; }
.listen-controls { display: flex; flex: 0 0 auto; align-items: center; gap: 6px; }
.listen-controls button { display: grid; width: 36px; height: 36px; place-items: center; border: 1px solid rgba(255,255,255,0.28); border-radius: 50%; background: rgba(255,255,255,0.08); color: var(--hero-ink); font-size: 14px; }
.listen-controls .listen-main { width: 42px; height: 42px; border-color: #ffffff; background: #ffffff; color: #153b4d; font-size: 16px; }
.listen-controls select { padding: 6px 8px; border: 1px solid rgba(255,255,255,0.28); border-radius: 99px; background: rgba(255,255,255,0.08); color: var(--hero-ink); font: inherit; font-size: 12px; }
.listen-bar :focus-visible { outline: 3px solid var(--hero-accent); outline-offset: 2px; }

.mp-toast { position: fixed; z-index: 70; top: calc(var(--sticky-h, 72px) + 12px); left: 50%; display: flex; width: max-content; max-width: calc(100vw - 24px); align-items: center; gap: 12px; padding: 12px 14px 12px 18px; border-radius: 14px; background: var(--hero-bg); box-shadow: 0 16px 40px rgba(0, 0, 0, 0.3); color: var(--hero-ink); font-size: 14px; opacity: 0; pointer-events: none; transform: translate(-50%, -12px); transition: opacity 200ms, transform 200ms; }
.mp-toast.is-visible { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
.mp-toast a { color: var(--hero-accent); font-weight: 800; white-space: nowrap; }
.mp-toast button { border: 0; background: transparent; color: var(--hero-muted); font-size: 18px; }

@keyframes mp-wave { 0%, 100% { height: 6px; } 50% { height: 20px; } }
@keyframes mp-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(198, 40, 40, 0.45); } 50% { box-shadow: 0 0 0 12px rgba(198, 40, 40, 0); } }

@media (prefers-reduced-motion: reduce) {
  .listen-wave i, .tutor-mic.is-listening { animation: none; }
  .connect-chip, .mp-toast { transition: none; }
}

@media (max-width: 1220px) {
  .inline-anchor { display: flex; }
}

@media (max-width: 900px) {
  .tutor-drawer { top: auto; width: 100vw; height: auto; max-height: min(88vh, 720px); border-left: 0; border-radius: 22px 22px 0 0; }
  .tutor-drawer:has(.msg) { height: min(88vh, 720px); }
  .tutor-backdrop { display: block; }
}

@media (max-width: 850px) {
  .mp-topbar { gap: 12px; padding: 6px 16px; }
  .chapter-picker { display: none; }
  .connect-grid { grid-template-columns: 1fr; }
  .chapter-finish { padding: 26px 22px; }
  .section-header { display: block; }
  .section-actions { justify-content: flex-start; margin-top: 14px; }
  .complete-button { margin-top: 0; }
}

@media (max-width: 560px) {
  .mp-hide-sm, .mp-top-links a:not(.mp-dashboard), .mp-crumbs li:first-child { display: none; }
  .mp-crumbs li:nth-child(2)::before { display: none; }
  .mp-logo span { display: none; }
  #theme-toggle { display: grid; }
  #print-button { display: none; }
  .contents-button span { display: none; }
  .contents-button { padding: 9px 11px; }
  .hero-actions { gap: 8px; }
  .mode-toggle { width: 100%; }
  .mode-toggle button { flex: 1; }
  .amy-invite { flex-direction: column; gap: 14px; padding: 20px; }
  .amy-mic { width: 60px; height: 60px; font-size: 26px; }
  .finish-nav { grid-template-columns: 1fr; }
  .finish-nav-card.is-next { text-align: left; }
  .amy-fab { right: 14px; bottom: 14px; padding: 12px; }
  .amy-fab > span:last-child { display: none; }
  .listen-bar { gap: 8px; padding: 8px 10px; }
  .listen-wave { display: none; }
  .listen-controls select { display: none; }
  .mp-toast { top: calc(var(--sticky-h, 72px) + 8px); }
}

@media (max-width: 400px) {
  .app-header .brand { display: none; }
}

@media print {
  .mp-noprint, .mp-topbar, .amy-fab, .listen-bar, .drawer-shell, .mp-toast, .inline-anchor { display: none !important; }
}

/* Access: locked previews, Gold gate, print branding */
.hero-preview { border-color: var(--hero-accent); }
.access-note { margin: 12px 0 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--ink); font-size: 12px; }
.access-note a { color: var(--teal-dark); font-weight: 800; }
.access-note.is-gold { border-color: var(--teal); background: var(--teal-soft); }
.toc-lock { color: var(--teal-dark); font-weight: 800; }
.toc-item.is-locked .toc-num { opacity: 0.7; }

#unlock-chapter { border-color: color-mix(in srgb, var(--teal) 45%, var(--line)); background: linear-gradient(160deg, var(--teal-soft), var(--surface) 55%); }
#unlock-chapter .complete-button, #unlock-chapter .section-tool { display: none; }
.lock-card { color: var(--ink); }
.lock-badge { display: inline-block; padding: 5px 12px; border-radius: 99px; background: var(--teal); color: var(--on-teal); font-size: 12px; font-weight: 800; }
.lock-message { margin: 14px 0; font-size: 16px; line-height: 1.6; }
.lock-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0; }
.lock-actions .button { border-radius: 99px; text-decoration: none; }
.lock-ladder { color: var(--muted); font-size: 13px; }
.lock-list { columns: 2; column-gap: 28px; color: var(--ink); }
.lock-list li { break-inside: avoid; }

.gate-shell .drawer-backdrop { z-index: 64; }
.gate-card { position: fixed; z-index: 66; top: 50%; left: 50%; width: min(480px, calc(100vw - 28px)); max-height: calc(100vh - 40px); overflow-y: auto; padding: 28px; border: 1px solid var(--line); border-radius: 22px; background: var(--surface); box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35); color: var(--ink); transform: translate(-50%, -50%); }
.gate-icon { display: grid; width: 52px; height: 52px; place-items: center; border-radius: 50%; background: var(--teal-soft); color: var(--teal-dark); font-size: 24px; font-weight: 800; }
.gate-card h2 { margin: 14px 0 8px; color: var(--ink); font-family: Georgia, "Times New Roman", serif; font-size: 24px; font-weight: 500; line-height: 1.25; }
.gate-card p { color: var(--muted); }
.gate-perks { margin: 14px 0; padding: 0; list-style: none; }
.gate-perks li { margin: 6px 0; padding: 8px 12px; border-radius: 10px; background: var(--bg); color: var(--ink); font-size: 13px; }
.gate-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.gate-actions .button { border-radius: 99px; text-decoration: none; }
.gate-note { margin-bottom: 0; font-size: 12px; }

.voice-tip { flex-basis: 100%; margin: 4px 0 0; padding: 8px 10px; border-radius: 10px; background: var(--blue-soft); color: var(--ink); font-size: 11px; }

.print-brand, .print-locked-note { display: none; }

@media (max-width: 560px) {
  .lock-list { columns: 1; }
  .gate-card { padding: 22px; }
}

@media print {
  .print-brand { position: fixed; top: -9mm; right: 0; left: 0; display: block; color: #086865; font-size: 8pt; font-weight: 700; text-align: center; }
  .print-footer span:first-child { color: #086865; font-weight: 700; }
  .print-locked body > *:not(.print-locked-note) { display: none !important; }
  .print-locked .print-locked-note { display: block; padding: 60mm 20mm; color: #153b4d; font-size: 14pt; text-align: center; }
  #unlock-chapter { display: none !important; }
}

/* Pinned header: MedPulse row + book toolbar stay visible while scrolling */
.mp-sticky { position: sticky; z-index: 25; top: 0; box-shadow: 0 6px 18px rgba(12, 25, 30, 0.06); }
.mp-sticky .app-header { position: relative; top: auto; }
.mp-sticky .mp-topbar { background: var(--surface); }
.sidebar, .study-rail { max-height: calc(100vh - var(--sticky-h, 72px) - 40px); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; padding-bottom: 12px; }

@media (max-width: 850px) {
  .sidebar { max-height: none; overflow: visible; }
}

@media (max-width: 560px) {
  .mp-topbar { min-height: 40px; padding: 4px 12px; }
  .mp-top-links .mp-dashboard { padding: 5px 12px; font-size: 12px; }
  .mp-sticky .app-header { min-height: 56px; padding: 7px 12px; }
  .mp-sticky .icon-button, .mp-sticky .contents-button { height: 38px; }
}

@media print {
  .mp-sticky { position: static; box-shadow: none; }
}

/* Comfortable tap targets in the pinned header (WCAG 2.5.8: at least 24px) */
.mp-crumbs a, .mp-crumbs [aria-current] { display: inline-block; padding: 6px 2px; }
.mp-top-links a:not(.mp-dashboard) { display: inline-block; padding: 7px 4px; }
.chapter-picker { padding-top: 2px; padding-bottom: 2px; }
.chapter-picker select { padding: 9px 0; }

/* Responsive header polish */
#print-button { white-space: nowrap; }
.mp-crumbs li { flex: 0 1 auto; }

@media (max-width: 1360px) and (min-width: 851px) {
  .brand small { display: none; }
  .search { width: min(22vw, 220px); }
}

@media (max-width: 1100px) and (min-width: 851px) {
  .chapter-picker span { display: none; }
  .chapter-picker select { max-width: 150px; }
  #print-button { font-size: 0; padding: 9px 12px; }
  #print-button span { font-size: 18px; }
  .search { width: 185px; }
}

@media (max-width: 560px) {
  /* Logo + subject + Home + All IQ Books + Dashboard: the chapter is already in the hero and the Chapters drawer. */
  .mp-crumbs li:first-child, .mp-crumbs li:last-child { display: none; }
  .mp-crumbs li:nth-child(2)::before { display: none; }
  .mp-top-links a:not(.mp-dashboard):not(.mp-hide-sm) { display: inline-block; }
  .mp-topbar { gap: 10px; }
  .mp-top-links { gap: 10px; }
}

@media (max-width: 400px) {
  .mp-topbar { gap: 8px; padding: 4px 10px; font-size: 12px; }
  .mp-top-links { gap: 6px; }
  .mp-top-links .mp-dashboard { padding: 5px 10px; font-size: 12px; }
  .mp-logo svg { width: 24px; height: 24px; }
}
