/* Question bank — mobile-first study UX */
:root {
  --qb-ink: #1a1a1a;
  --qb-muted: #5c5c5c;
  --qb-paper: #faf9f7;
  --qb-card: #fff;
  --qb-border: #e5e2dc;
  --qb-accent: #1e3a5f;
  --qb-bright: #2563eb;
  --qb-ok: #059669;
  --qb-bad: #dc2626;
  --qb-warn: #d97706;
  --qb-touch: 48px;
  --qb-sticky-top: 3.5rem;
  --qb-safe-b: env(safe-area-inset-bottom, 0px);
  --qb-safe-t: env(safe-area-inset-top, 0px);
}

html:has(body.qb-page) {
  scroll-padding-top: calc(var(--qb-sticky-top) + 10rem);
}

* { box-sizing: border-box; }

body.qb-page {
  font-family: "Palatino Linotype", Palatino, Georgia, serif;
  background: var(--qb-paper);
  color: var(--qb-ink);
  line-height: 1.6;
  margin: 0;
  min-height: 100vh;
  padding-bottom: calc(1rem + var(--qb-safe-b));
  overflow-x: hidden;
}

/* Site nav: flush with sticky controls below */
body.qb-page .site-nav {
  margin: 0;
  padding: 0.55rem 1rem;
  top: var(--qb-safe-t);
  z-index: 130;
  box-shadow: none;
}

/* ── Unified sticky controls (mobile) ── */
.qb-sticky-controls {
  position: sticky;
  top: var(--qb-sticky-top);
  z-index: 110;
  background: var(--qb-paper);
  border-bottom: 1px solid var(--qb-border);
  margin: 0 -1rem;
  padding: 0 1rem 0.5rem;
  box-shadow: none;
}

@media (max-width: 899px) {
  .qb-sticky-controls {
    margin-top: -1px;
    padding-top: 1px;
    padding-bottom: 0.35rem;
  }

  .qb-sticky-controls.is-collapsed {
    padding-bottom: 0.35rem;
  }

  .qb-sticky-controls.is-collapsed .qb-filter-panel {
    display: none;
  }

  .qb-sticky-controls:not(.is-collapsed) .qb-filter-chevron {
    transform: rotate(180deg);
  }
}

/* Collapsible filter toggle — mobile only */
.qb-filter-toggle {
  display: none;
}

@media (max-width: 899px) {
  .qb-filter-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    min-height: var(--qb-touch);
    margin: 0.35rem 0 0.15rem;
    padding: 0.55rem 0.65rem;
    border: 1px solid var(--qb-border);
    border-radius: 10px;
    background: #fff;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .qb-filter-toggle-title {
    flex-shrink: 0;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--qb-muted);
  }

  .qb-filter-toggle-summary {
    flex: 1;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--qb-ink);
    line-height: 1.35;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .qb-filter-chevron {
    flex-shrink: 0;
    font-size: 0.85rem;
    color: var(--qb-muted);
    transition: transform 0.2s ease;
  }

  .qb-filter-panel {
    padding-top: 0.35rem;
  }
}

@media (min-width: 900px) {
  .qb-filter-panel {
    display: block !important;
  }
}

@media (min-width: 900px) {
  .qb-sticky-controls {
    position: static;
    margin: 0;
    margin-top: 0;
    padding: 0 0 0.75rem;
    border-bottom: none;
  }
}
.qb-shell {
  max-width: 52rem;
  margin: 0 auto;
  padding: 0 0 2rem;
}

.qb-main {
  padding: 0 1rem 2rem;
}

@media (min-width: 900px) {
  .qb-shell {
    max-width: 72rem;
    display: grid;
    grid-template-columns: 15.5rem 1fr;
    gap: 0;
    align-items: start;
  }
  .qb-main { padding: 1.25rem 1.75rem 3rem; max-width: none; }
  .qb-sidebar-panel { display: block !important; }
  .qb-filter-fab { display: none !important; }
  .qb-sheet-backdrop { display: none !important; }
}

/* ── Hero (compact on mobile) ── */
.qb-hero {
  padding: 1rem 1rem 0.75rem;
  background: linear-gradient(180deg, #eff6ff 0%, var(--qb-paper) 100%);
  border-bottom: 1px solid var(--qb-border);
}

@media (min-width: 900px) {
  .qb-hero {
    grid-column: 1 / -1;
    padding: 1.25rem 1.75rem;
    border-bottom: 1px solid var(--qb-border);
    background: linear-gradient(135deg, #eff6ff 0%, #ecfdf5 100%);
    border-radius: 0;
  }
}

.qb-hero h1 {
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 0.25rem;
}

@media (min-width: 600px) {
  .qb-hero h1 { font-size: 1.65rem; }
}

.qb-hero-tagline {
  margin: 0;
  color: var(--qb-muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

@media (min-width: 600px) {
  .qb-hero-tagline { font-size: 0.92rem; }
}

/* Tappable stat chips → switch study mode */
.qb-mode-chips {
  display: flex;
  gap: 0.45rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 0.5rem 0 0.35rem;
  margin: 0;
  scroll-snap-type: x proximity;
}

.qb-mode-chips::-webkit-scrollbar { display: none; }

.qb-mode-chip {
  flex: 0 0 auto;
  scroll-snap-align: start;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.55rem 0.85rem;
  min-height: var(--qb-touch);
  border: 1px solid var(--qb-border);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.qb-mode-chip:active { transform: scale(0.98); }

.qb-mode-chip .count {
  font-family: 'IBM Plex Mono', Consolas, monospace;
  font-size: 0.68rem;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  background: #f1f5f9;
  color: #475569;
}

.qb-mode-chip.is-active {
  background: var(--qb-accent);
  border-color: var(--qb-accent);
  color: #fff;
}

.qb-mode-chip.is-active .count {
  background: rgba(255,255,255,0.2);
  color: #fff;
}

.qb-mode-chip--wrong.is-active {
  background: #fef2f2;
  border-color: #fca5a5;
  color: var(--qb-bad);
}

.qb-mode-chip--wrong.is-active .count {
  background: #fee2e2;
  color: var(--qb-bad);
}

.qb-mode-chip--saved.is-active {
  background: #fffbeb;
  border-color: #fcd34d;
  color: #92400e;
}

/* ── Layout ── */

/* Filter dock — static inside sticky wrapper (not nested sticky) */
.qb-filter-dock {
  position: static;
  z-index: auto;
  background: transparent;
  backdrop-filter: none;
  border-bottom: none;
  padding: 0 0 0.25rem;
  box-shadow: none;
}

@media (min-width: 900px) {
  .qb-filter-dock {
    padding: 0 0 1rem;
    grid-column: 2;
  }
}

.qb-filter-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--qb-muted);
  font-weight: 600;
  margin: 0 0 0.4rem;
}

/* Segmented control — question format */
.qb-segment {
  display: flex;
  padding: 3px;
  background: #e8e6e1;
  border-radius: 10px;
  gap: 2px;
}

.qb-segment-btn {
  flex: 1;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  min-height: 40px;
  padding: 0.4rem 0.35rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--qb-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
}

@media (min-width: 600px) {
  .qb-segment-btn { font-size: 0.82rem; min-height: 42px; }
}

.qb-segment-btn.is-active {
  background: #fff;
  color: var(--qb-accent);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.qb-filter-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.65rem;
}

.qb-active-summary {
  flex: 1;
  font-size: 0.78rem;
  color: var(--qb-muted);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.qb-active-summary strong {
  color: var(--qb-ink);
  font-weight: 600;
}

.qb-filter-fab,
.qb-topic-btn {
  flex-shrink: 0;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  min-height: var(--qb-touch);
  padding: 0 1rem;
  border: 1px solid var(--qb-border);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  -webkit-tap-highlight-color: transparent;
}

.qb-filter-fab.has-filters,
.qb-topic-btn.has-filters {
  border-color: var(--qb-bright);
  background: #eff6ff;
  color: #1d4ed8;
}

.qb-result-count {
  font-family: 'IBM Plex Mono', Consolas, monospace;
  font-size: 0.72rem;
  color: var(--qb-muted);
  margin: 0.35rem 0 0;
}

@media (max-width: 899px) {
  .qb-result-count { display: none; }
}

#qb-questions {
  margin-top: 0.75rem;
  scroll-margin-top: calc(var(--qb-sticky-top) + 9rem);
}

.qb-card {
  scroll-margin-top: calc(var(--qb-sticky-top) + 9rem);
}

/* ── Desktop sidebar ── */
.qb-sidebar-panel {
  display: none;
  padding: 1rem 0.85rem 2rem;
  border-right: 1px solid var(--qb-border);
  position: sticky;
  top: calc(var(--qb-sticky-top) + 0.5rem);
  max-height: calc(100vh - var(--qb-sticky-top) - 1rem);
  overflow-y: auto;
}

.qb-sidebar-panel h2 {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--qb-muted);
  margin: 1rem 0 0.45rem;
  font-weight: 600;
}

.qb-sidebar-panel h2:first-child { margin-top: 0; }

#qb-concept-nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.qb-concept-btn {
  font-family: inherit;
  font-size: 0.8rem;
  text-align: left;
  padding: 0.5rem 0.6rem;
  min-height: 40px;
  border: none;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  color: var(--qb-ink);
  line-height: 1.35;
}

.qb-concept-btn em {
  font-style: normal;
  font-family: 'IBM Plex Mono', Consolas, monospace;
  font-size: 0.65rem;
  color: var(--qb-muted);
  margin-left: 0.2rem;
}

.qb-concept-btn:hover { background: #f5f4f1; }
.qb-concept-btn.active { background: #eff6ff; color: var(--qb-bright); font-weight: 600; }

#qb-lesson-stars {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.qb-lesson-chip {
  font-family: inherit;
  font-size: 0.76rem;
  text-align: left;
  padding: 0.45rem 0.55rem;
  min-height: 40px;
  border: 1px solid var(--qb-border);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.qb-lesson-chip.is-starred {
  border-color: #fcd34d;
  background: #fffbeb;
}

.qb-lesson-count {
  margin-left: auto;
  font-family: 'IBM Plex Mono', Consolas, monospace;
  font-size: 0.62rem;
  color: var(--qb-muted);
}

.qb-toggle-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.8rem;
  margin-top: 0.85rem;
  color: var(--qb-muted);
  cursor: pointer;
}

.qb-toggle-row input {
  margin-top: 0.2rem;
  accent-color: var(--qb-accent);
  width: 1.1rem;
  height: 1.1rem;
}

.qb-clear-btn {
  font-family: inherit;
  font-size: 0.76rem;
  margin-top: 0.65rem;
  padding: 0.5rem 0.65rem;
  min-height: var(--qb-touch);
  border: 1px solid #fecaca;
  background: #fef2f2;
  color: var(--qb-bad);
  border-radius: 8px;
  cursor: pointer;
  width: 100%;
}

/* ── Bottom sheet (mobile topics) ── */
.qb-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 26, 0.45);
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s, visibility 0.25s;
}

.qb-sheet-backdrop.is-open {
  opacity: 1;
  visibility: visible;
}

.qb-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 210;
  background: #fff;
  border-radius: 16px 16px 0 0;
  max-height: min(85vh, 640px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  box-shadow: 0 -8px 32px rgba(0,0,0,0.12);
}

.qb-sheet-backdrop.is-open .qb-sheet {
  transform: translateY(0);
}

.qb-sheet-handle {
  width: 2.5rem;
  height: 4px;
  background: #d1d5db;
  border-radius: 2px;
  margin: 0.65rem auto 0;
  flex-shrink: 0;
}

.qb-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.15rem 0.5rem;
  border-bottom: 1px solid var(--qb-border);
  flex-shrink: 0;
}

.qb-sheet-head h2 {
  font-size: 1.05rem;
  margin: 0;
  font-weight: 600;
}

.qb-sheet-close {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  min-width: var(--qb-touch);
  min-height: var(--qb-touch);
  border: none;
  background: #f3f4f6;
  border-radius: 50%;
  cursor: pointer;
  color: var(--qb-muted);
}

.qb-sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0.85rem 1.15rem 0.5rem;
}

.qb-sheet-section { margin-bottom: 1.25rem; }

.qb-sheet-section--last {
  margin-bottom: 0.5rem;
}

.qb-sheet-foot {
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  z-index: 2;
  padding: 0.75rem 1.15rem calc(0.75rem + var(--qb-safe-b));
  border-top: 1px solid var(--qb-border);
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(8px);
  box-shadow: 0 -6px 16px rgba(30, 58, 95, 0.08);
}

.qb-sheet-section h3 {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--qb-muted);
  margin: 0 0 0.5rem;
}

.qb-chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.qb-topic-chip {
  font-family: inherit;
  font-size: 0.78rem;
  padding: 0.5rem 0.75rem;
  min-height: 40px;
  border: 1px solid var(--qb-border);
  border-radius: 999px;
  background: #fff;
  cursor: pointer;
}

.qb-topic-chip.active {
  background: var(--qb-accent);
  border-color: var(--qb-accent);
  color: #fff;
}

.qb-topic-chip em {
  font-style: normal;
  font-family: 'IBM Plex Mono', Consolas, monospace;
  font-size: 0.65rem;
  opacity: 0.85;
  margin-left: 0.15rem;
}

.qb-sheet-actions {
  display: flex;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  border: none;
}

.qb-sheet-reset {
  flex: 1;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  min-height: var(--qb-touch);
  border: 1px solid var(--qb-border);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
}

.qb-sheet-apply {
  flex: 2;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  min-height: var(--qb-touch);
  border: none;
  border-radius: 10px;
  background: var(--qb-accent);
  color: #fff;
  cursor: pointer;
}

/* ── Questions ── */

.qb-group-title {
  font-size: 1.05rem;
  margin: 1.75rem 0 0.65rem;
  padding-bottom: 0.35rem;
  border-bottom: 2px solid var(--qb-accent);
  color: var(--qb-accent);
}

.qb-group-title:first-child { margin-top: 0.25rem; }

.qb-card {
  background: var(--qb-card);
  border: 1px solid var(--qb-border);
  border-radius: 12px;
  padding: 1rem 1rem 1.1rem;
  margin-bottom: 0.75rem;
  box-shadow: 0 1px 3px rgba(30, 58, 95, 0.05);
}

.qb-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
}

.qb-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: center;
  flex: 1;
  min-width: 0;
}

.qb-badge {
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.18rem 0.4rem;
  border-radius: 4px;
  background: #f1f5f9;
  color: #475569;
}

.qb-badge.midterm { background: #dbeafe; color: #1d4ed8; }
.qb-badge.optional { background: #fef3c7; color: #92400e; }
.qb-badge.type { background: #f3f4f6; color: #374151; }

.qb-lesson-link {
  font-size: 0.72rem;
  color: var(--qb-bright);
  text-decoration: none;
}

.qb-save-btn {
  font-family: inherit;
  font-size: 0.72rem;
  padding: 0.45rem 0.6rem;
  min-height: 36px;
  min-width: 36px;
  border: 1px solid var(--qb-border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  flex-shrink: 0;
}

.qb-save-btn.is-saved {
  background: #fffbeb;
  border-color: #fcd34d;
  color: #92400e;
}

.qb-question {
  font-size: 0.98rem;
  font-weight: 600;
  margin: 0 0 0.85rem;
  line-height: 1.5;
}

.qb-options {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.qb-options.tf {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.qb-opt {
  font-family: inherit;
  font-size: 0.92rem;
  text-align: left;
  padding: 0.85rem 1rem;
  min-height: var(--qb-touch);
  border: 1.5px solid var(--qb-border);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
  -webkit-tap-highlight-color: transparent;
  line-height: 1.35;
}

.qb-opt:active:not(:disabled) { background: #f8fafc; }
.qb-opt:disabled { cursor: default; opacity: 1; }
.qb-opt.correct { background: #d1fae5; border-color: #6ee7b7; }
.qb-opt.wrong { background: #fee2e2; border-color: #fca5a5; }

.qb-feedback { margin-top: 0.65rem; font-size: 0.88rem; }
.qb-result.ok { color: var(--qb-ok); font-weight: 600; }
.qb-result.bad { color: var(--qb-bad); font-weight: 600; }
.qb-result.neutral { color: var(--qb-warn); }

.qb-wrong-note {
  font-size: 0.76rem;
  color: var(--qb-bad);
  margin: 0.5rem 0 0;
  font-style: italic;
}

.qb-explain, .qb-essay-reveal {
  margin-top: 0.65rem;
  font-size: 0.85rem;
  color: var(--qb-muted);
}

.qb-explain summary, .qb-essay-reveal summary {
  cursor: pointer;
  color: var(--qb-bright);
  font-weight: 600;
  min-height: var(--qb-touch);
  display: flex;
  align-items: center;
}

.qb-essay-answer {
  white-space: pre-wrap;
  font-family: 'IBM Plex Mono', Consolas, monospace;
  font-size: 0.72rem;
  background: #f8fafc;
  border: 1px solid var(--qb-border);
  border-radius: 8px;
  padding: 0.75rem;
  margin-top: 0.5rem;
  overflow-x: auto;
  max-width: 100%;
}

.qb-note {
  font-size: 0.8rem;
  color: var(--qb-warn);
  margin: 0.5rem 0 0;
  padding: 0.5rem 0.65rem;
  background: #fffbeb;
  border-radius: 6px;
}

.qb-empty {
  text-align: center;
  color: var(--qb-muted);
  padding: 2.5rem 1rem;
  font-size: 0.95rem;
}

.qb-empty-icon {
  font-size: 2rem;
  display: block;
  margin-bottom: 0.5rem;
  opacity: 0.5;
}

.qb-empty-action {
  display: inline-block;
  margin-top: 1rem;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.65rem 1.1rem;
  min-height: var(--qb-touch);
  border: none;
  border-radius: 10px;
  background: var(--qb-accent);
  color: #fff;
  cursor: pointer;
}

.qb-footer {
  margin-top: 2rem;
  padding: 1rem 1rem 0;
  border-top: 1px solid var(--qb-border);
  font-size: 0.82rem;
  color: var(--qb-muted);
}

.qb-footer a { color: var(--qb-bright); }

@media print {
  .no-print, .qb-filter-dock, .qb-sidebar-panel, .qb-sheet-backdrop, .qb-save-btn { display: none !important; }
}
