/* ===== Design tokens ===== */
:root {
  --bg: #0b0f14;
  --bg-elevated: #121821;
  --bg-elevated-2: #171f2b;
  --border: #232c3a;
  --border-soft: #1a212c;
  --text: #e7edf5;
  --text-dim: #9aa8bb;
  --text-faint: #5f6d80;
  --accent: #2dd4bf;
  --accent-dim: #1c9c8c;
  --accent-soft: rgba(45, 212, 191, 0.12);
  --accent-soft-2: rgba(45, 212, 191, 0.22);
  --danger: #f2836b;
  --danger-soft: rgba(242, 131, 107, 0.14);
  --good: #2dd4bf;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --radius: 12px;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

html[data-theme="light"] {
  --bg: #f5f7fa;
  --bg-elevated: #ffffff;
  --bg-elevated-2: #eef1f5;
  --border: #dde3ea;
  --border-soft: #e6eaef;
  --text: #172231;
  --text-dim: #56637a;
  --text-faint: #93a0b2;
  --accent: #0f9d8f;
  --accent-dim: #0c8577;
  --accent-soft: rgba(15, 157, 143, 0.1);
  --accent-soft-2: rgba(15, 157, 143, 0.18);
  --danger: #d65f42;
  --danger-soft: rgba(214, 95, 66, 0.1);
  --good: #0f9d8f;
  --shadow: 0 8px 24px rgba(20, 30, 45, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s ease, color 0.2s ease;
  min-height: 100vh;
}

a { color: var(--accent); }
a:hover { color: var(--accent-dim); }

code, pre, kbd {
  font-family: var(--font-mono);
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0, "calt" 0;
}

::selection { background: var(--accent-soft-2); }

/* ===== Topbar ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 14px;
  height: 60px;
  padding: 0 18px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  flex: none;
}
.icon-btn:hover { background: var(--bg-elevated-2); color: var(--text); }

.theme-fab {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 200;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.theme-fab:hover { background: var(--bg-elevated-2); }

/* ===== View switching ===== */
.view[hidden] { display: none !important; }

/* ===== Hero view ===== */
.hero-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.hero-inner {
  max-width: 560px;
  width: 100%;
  text-align: center;
}
.hero-mark {
  font-family: var(--font-mono);
  color: var(--accent);
  font-weight: 700;
  font-size: 30px;
  margin-bottom: 22px;
}
.hero-inner h1 {
  font-size: 34px;
  line-height: 1.25;
  letter-spacing: -0.01em;
  margin: 0 0 16px;
}
.hero-inner p {
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1.65;
  margin: 0 0 28px;
}
.hero-resume-stats[hidden] { display: none; }
.hero-resume-stats {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent-dim);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-mono);
  margin-bottom: 26px;
}
.hero-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}
.hero-btn {
  height: 50px;
  padding: 0 30px;
  border-radius: 12px;
  font-family: var(--font-sans);
  font-size: 15.5px;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid transparent;
}
.hero-btn-primary {
  background: var(--accent);
  color: var(--bg);
}
.hero-btn-primary:hover { filter: brightness(1.08); }
.hero-btn-secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--text-dim);
}
.hero-btn-secondary:hover { color: var(--text); border-color: var(--accent-dim); }

.hero-view .loading-state,
.hero-view .load-error { margin: 0 auto; }

.hero-privacy-note {
  margin: 22px 0 0 !important;
  color: var(--text-faint);
  font-size: 12.5px;
  text-align: center;
}
.hero-privacy-note svg {
  display: inline-block;
  vertical-align: -2px;
  margin-right: 6px;
  opacity: 0.8;
  flex: none;
}

/* ===== Back / Home nav ===== */
.back-btn[hidden] { display: none; }
.back-btn {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 150;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: 9px;
  color: var(--text-dim);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 9px 14px 9px 10px;
}
.back-btn:hover { color: var(--accent); border-color: var(--accent-dim); }

/* ===== Home view (topic picker) ===== */
.home-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.home-inner {
  max-width: 640px;
  width: 100%;
  text-align: center;
}
.home-inner h1 {
  font-size: 32px;
  line-height: 1.25;
  letter-spacing: -0.01em;
  margin: 0 0 16px;
}
.home-inner > p {
  color: var(--text-dim);
  font-size: 15.5px;
  line-height: 1.65;
  margin: 0 0 32px;
}
.topics-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}
.topics-list[hidden] { display: none; }

.topic-card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 18px 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-sans);
  text-align: left;
  cursor: pointer;
}
.topic-card:hover { border-color: var(--accent-dim); background: var(--bg-elevated-2); }
.topic-card-icon {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 15px;
}
.topic-card-name {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
}
.topic-card-chevron { flex: none; color: var(--text-faint); }
.topic-card:hover .topic-card-chevron { color: var(--accent); }

.topic-card-error {
  padding: 14px 16px;
  border: 1px solid var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: var(--radius);
  font-size: 13px;
}

.sidebar-toggle { display: none; }

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex: none;
  white-space: nowrap;
}
.brand-mark {
  font-family: var(--font-mono);
  color: var(--accent);
  font-weight: 600;
  font-size: 15px;
}
.brand-text {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}
.brand-accent { color: var(--accent); font-weight: 500; }
.brand-sub { color: var(--text-dim); font-weight: 500; }

.search-wrap {
  flex: 1;
  max-width: 460px;
  position: relative;
  display: flex;
  align-items: center;
  margin: 0 auto 0 20px;
}
.search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-faint);
  pointer-events: none;
}
#searchInput {
  width: 100%;
  height: 38px;
  padding: 0 34px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-elevated-2);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s ease;
  -webkit-appearance: none;
}
#searchInput:focus { border-color: var(--accent-dim); }
#searchInput::placeholder { color: var(--text-faint); }

.clear-search {
  position: absolute;
  right: 8px;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-faint);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.clear-search:hover { background: var(--bg); color: var(--text); }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated-2);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.pill-btn:hover { border-color: var(--accent-dim); color: var(--accent); }

/* ===== Layout ===== */
.layout {
  display: flex;
  align-items: flex-start;
  max-width: 1280px;
  margin: 0 auto;
}

.sidebar {
  position: sticky;
  top: 60px;
  height: calc(100vh - 60px);
  width: 250px;
  flex: none;
  overflow-y: auto;
  padding: 18px 10px 18px 18px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 16px;
}

.section-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  text-align: left;
  background: transparent;
  width: 100%;
}
.nav-item:hover { background: var(--bg-elevated-2); color: var(--text); }
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.nav-item .nav-count {
  margin-left: auto;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-faint);
  background: var(--bg-elevated-2);
  border-radius: 999px;
  padding: 1px 7px;
}
.nav-item.active .nav-count { color: var(--accent); background: var(--accent-soft-2); }

.nav-item.glossary-item {
  margin-top: 8px;
  padding-top: 9px;
  border-top: 1px dashed var(--border);
  border-radius: 0;
}

.sidebar-footer { flex: none; }

.progress-box {
  background: var(--bg-elevated-2);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 12px 13px;
}
.progress-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.progress-label span { color: var(--accent); font-weight: 700; font-family: var(--font-mono); }
.progress-track {
  height: 6px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.sidebar-scrim {
  display: none;
}

/* ===== Content ===== */
.content {
  flex: 1;
  min-width: 0;
  padding: 28px 28px 80px;
}

.section-block { margin-bottom: 42px; scroll-margin-top: 76px; }

.section-heading {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 0 0 4px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.section-heading h2 {
  font-size: 21px;
  margin: 0;
  letter-spacing: -0.01em;
}
.section-heading .section-index {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 600;
}
.section-heading .section-count {
  margin-left: auto;
  font-size: 12.5px;
  color: var(--text-faint);
  font-family: var(--font-mono);
}

.card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

/* ===== Question card ===== */
.q-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s ease;
}
.q-card:hover { border-color: var(--border); }
.q-card.marked-good { border-left: 3px solid var(--good); }
.q-card.marked-review { border-left: 3px solid var(--danger); }

.q-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 18px;
  cursor: pointer;
  user-select: none;
}
.q-header:hover { background: var(--bg-elevated-2); }

.q-marker {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--border);
}
.q-card.marked-good .q-marker { background: var(--good); }
.q-card.marked-review .q-marker { background: var(--danger); }

.q-title {
  flex: 1;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text);
}
.q-title code {
  background: var(--bg-elevated-2);
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 0.9em;
  color: var(--accent);
}

.q-chevron {
  flex: none;
  color: var(--text-faint);
  transition: transform 0.25s ease;
}
.q-card.open .q-chevron { transform: rotate(90deg); color: var(--accent); }

.q-body-wrap {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.28s ease;
}
.q-card.open .q-body-wrap { grid-template-rows: 1fr; }
.q-body-inner { overflow: hidden; }

.q-body {
  padding: 0 18px 18px 39px;
  color: var(--text-dim);
  font-size: 14px;
}
.q-body p { margin: 0 0 12px; }
.q-body p:last-child { margin-bottom: 0; }
.q-body ul, .q-body ol { margin: 0 0 12px; padding-left: 20px; }
.q-body li { margin-bottom: 6px; }
.q-body strong { color: var(--text); }
.q-body code {
  background: var(--bg-elevated-2);
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 0.88em;
  color: var(--accent);
  border: 1px solid var(--border-soft);
}
.q-body pre {
  margin: 4px 0 14px;
  border-radius: 9px;
  border: 1px solid var(--border);
  overflow-x: auto;
  font-size: 13px;
}
.q-body pre code {
  background: none;
  border: none;
  padding: 0;
  color: inherit;
}

.q-actions {
  display: flex;
  gap: 8px;
  padding-top: 4px;
}
.mark-btn {
  font-family: var(--font-sans);
  border-radius: 8px;
  width: 34px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--bg-elevated-2);
  color: var(--text-faint);
  cursor: pointer;
}
.mark-btn:hover { color: var(--text-dim); border-color: var(--text-faint); }
.mark-btn.mb-good.active { background: var(--accent-soft); border-color: var(--accent-dim); color: var(--accent); }
.mark-btn.mb-review.active { background: var(--danger); border-color: var(--danger); color: var(--bg); }

/* ===== Glossary ===== */
.glossary-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.glossary-table th, .glossary-table td {
  text-align: left;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13.5px;
}
.glossary-table th {
  color: var(--text-faint);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  background: var(--bg-elevated-2);
}
.glossary-table td:first-child {
  font-family: var(--font-mono);
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
  width: 140px;
}
.glossary-table tr:last-child td { border-bottom: none; }

.no-results {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-faint);
  font-size: 14px;
}
.no-results span { color: var(--text); font-weight: 600; }

.loading-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-faint);
  font-size: 14px;
}
.load-error {
  text-align: center;
  max-width: 480px;
  margin: 60px auto;
  padding: 20px 22px;
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  color: var(--danger);
  font-size: 13.5px;
  line-height: 1.6;
}

mark.hit {
  background: var(--accent-soft-2);
  color: var(--text);
  border-radius: 3px;
  padding: 0 1px;
}

/* ===== Assessment view (flashcards) — was .quiz-overlay ===== */
.assessment-view {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
.assessment-view[hidden] {
  display: none;
}

.quiz-topbar {
  display: flex;
  align-items: center;
  height: 58px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.quiz-title { font-weight: 700; font-size: 14.5px; }
.assessment-exit-btn {
  width: auto;
  gap: 6px;
  padding: 0 12px 0 8px;
}
.assessment-exit-label {
  font-size: 13px;
  font-weight: 600;
}
#assessmentHomeBtn { margin-left: auto; }
.quiz-progress {
  margin: 0 auto;
  font-family: var(--font-mono);
  color: var(--text-dim);
  font-size: 13px;
}

.quiz-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  perspective: 1600px;
  min-height: 0;
}

.quiz-card {
  width: 100%;
  max-width: 640px;
  height: 100%;
  max-height: 460px;
  cursor: pointer;
}

.quiz-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.4, 0.2, 0.2, 1);
}
.quiz-card.no-anim .quiz-card-inner { transition: none !important; }
.quiz-card.flipped .quiz-card-inner { transform: rotateY(180deg); }

.quiz-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  padding: 34px 34px 26px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}
.quiz-face-back { transform: rotateY(180deg); }

.quiz-section-tag {
  align-self: flex-start;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 18px;
  flex: none;
}

.quiz-question {
  font-size: 21px;
  font-weight: 600;
  line-height: 1.45;
  flex: 1;
  display: flex;
  align-items: center;
}
.quiz-question > span { display: inline; }
.quiz-question code {
  background: var(--bg-elevated-2);
  padding: 1px 7px;
  border-radius: 6px;
  color: var(--accent);
  font-size: 0.85em;
}

.quiz-flip-hint {
  flex: none;
  text-align: center;
  color: var(--text-faint);
  font-size: 12.5px;
  padding-top: 14px;
}

.quiz-answer {
  font-size: 14.5px;
  color: var(--text-dim);
  min-height: 0;
  max-width: 100%;
}
.quiz-answer p { margin: 0 0 12px; }
.quiz-answer strong { color: var(--text); }
.quiz-answer code {
  background: var(--bg-elevated-2);
  padding: 1px 6px;
  border-radius: 5px;
  color: var(--accent);
  font-size: 0.88em;
}
.quiz-answer pre {
  border-radius: 9px;
  border: 1px solid var(--border);
  font-size: 12.5px;
  margin: 4px 0 12px;
  overflow-x: auto;
  max-width: 100%;
  white-space: pre;
}
.quiz-answer pre code { background: none; padding: 0; color: inherit; }
.quiz-answer ul, .quiz-answer ol { padding-left: 18px; margin: 0 0 12px; }

.quiz-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 18px;
  flex: none;
  flex-wrap: wrap;
}

.quiz-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 42px;
  padding: 0 18px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated-2);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
.quiz-btn:hover { border-color: var(--accent-dim); }
.quiz-btn-ghost { color: var(--text-dim); }
.quiz-btn-review { border-color: var(--border); color: var(--text-faint); background: var(--bg-elevated-2); }
.quiz-btn-review:hover { color: var(--danger); }
.quiz-btn-review.active { color: var(--bg); background: var(--danger); border-color: var(--danger); }
.quiz-btn-confident { border-color: var(--border); color: var(--text-faint); background: var(--bg-elevated-2); }
.quiz-btn-confident:hover { color: var(--good); }
.quiz-btn-confident.active { color: var(--bg); background: var(--good); border-color: var(--good); }

.quiz-bottom-actions {
  display: flex;
  justify-content: center;
  gap: 22px;
  padding-bottom: 20px;
  flex: none;
}

/* ===== Exit confirmation modal ===== */
.confirm-modal-scrim {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.confirm-modal-scrim[hidden] { display: none; }

.confirm-modal {
  width: 100%;
  max-width: 380px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 24px 24px 20px;
}
.confirm-modal h3 {
  margin: 0 0 10px;
  font-size: 17px;
  letter-spacing: -0.01em;
}
.confirm-modal p {
  margin: 0 0 22px;
  color: var(--text-dim);
  font-size: 13.5px;
  line-height: 1.6;
}
.confirm-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.quiz-btn-confirm-exit {
  border-color: var(--danger);
  color: var(--bg);
  background: var(--danger);
}
.quiz-btn-confirm-exit:hover { filter: brightness(1.08); }
.resume-continue-btn { border-color: var(--accent); background: var(--accent); color: var(--bg); }
.resume-continue-btn:hover { filter: brightness(1.08); }
.text-btn {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 12.5px;
  font-family: var(--font-sans);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.text-btn:hover { color: var(--accent); }

/* ===== Responsive ===== */
@media (max-width: 860px) {
  .sidebar-toggle { display: inline-flex; }
  .brand-sub { display: none; }
  .search-wrap { margin-left: 8px; }

  .sidebar {
    position: fixed;
    top: 60px;
    left: 0;
    height: calc(100vh - 60px);
    width: 250px;
    z-index: 60;
    background: var(--bg-elevated);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-scrim {
    display: block;
    position: fixed;
    inset: 60px 0 0 0;
    background: rgba(0,0,0,0.45);
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  .sidebar-scrim.show { opacity: 1; pointer-events: auto; }

  .content { padding: 20px 16px 70px; }
  .q-body { padding-left: 18px; }
  .quiz-question { font-size: 18px; }
  .quiz-face { padding: 24px 20px 20px; }
  .quiz-controls { padding: 14px; }
  .quiz-btn { height: 44px; font-size: 13px; padding: 0 14px; }
}

@media (max-width: 640px) {
  .topbar { gap: 8px; padding: 0 10px; }
  .brand-text { display: none; }
  .search-wrap { margin-left: 4px; }
  #searchInput { font-size: 16px; padding: 0 32px; } /* 16px prevents iOS auto-zoom on focus */
  .pill-btn { padding: 0 11px; gap: 0; }
  .pill-btn .pill-label { display: none; }
  .topbar-actions { gap: 4px; }
}

@media (max-width: 480px) {
  .glossary-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .glossary-table td:first-child { width: 90px; }
  .section-heading h2 { font-size: 18px; }
  .section-heading .section-count { display: none; }
  .quiz-question { font-size: 16.5px; }
  .quiz-face { padding: 20px 16px 16px; }
  .quiz-controls { gap: 8px; }
  .quiz-btn { padding: 0 12px; font-size: 12.5px; }
  .quiz-bottom-actions { gap: 16px; }
}

@supports (padding: max(0px)) {
  .topbar { padding-left: max(18px, env(safe-area-inset-left)); padding-right: max(18px, env(safe-area-inset-right)); }
  .quiz-bottom-actions { padding-bottom: max(20px, env(safe-area-inset-bottom)); }
}
