/* =========================================================
   Claude Certified Architect Study Hub — Design System
   5 Curated Themes: warm, nordic, sepia, midnight, emerald
   ========================================================= */

:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-serif: 'Newsreader', Georgia, 'Times New Roman', serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --body-font: var(--font-sans);
  --base-size: 16px;
  --content-max: 900px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.07);

  /* spacing scale */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;

  --topbar-h: 56px;
  --tabbar-h: 60px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --tap: 44px;
}

/* Theme 1: Warm Paper (Default) */
html[data-theme="warm"] {
  --bg: #FAF8F5;
  --surface: #FFFFFF;
  --surface-alt: #F3EFE8;
  --surface-hover: #EFEAE1;
  --border: #E5DFD5;
  --border-strong: #CFC6B8;
  --text: #1F1E1C;
  --text-muted: #656058;
  --accent: #C8643C;
  --accent-hover: #B2532E;
  --accent-soft: #FBECE6;
  --accent-text: #963F1E;
  --code-bg: #F4F0E8;
  --code-border: #E2DACD;
  --correct-bg: #EDF7F1;
  --correct-border: #3A9663;
  --correct-text: #1E5E3B;
  --wrong-bg: #FDF0EE;
  --wrong-border: #D9534F;
  --wrong-text: #8F2B28;
  --takeaway-bg: #FFF8E6;
  --takeaway-border: #D99B26;
  --takeaway-text: #744D06;
  --info-bg: #EEF5FB;
  --info-border: #3B82B6;
  --info-text: #1E4E75;
  --warn-bg: #FEF5E7;
  --warn-border: #D97706;
  --warn-text: #7C3E05;
}

/* Theme 2: Nordic Frost */
html[data-theme="nordic"] {
  --bg: #F3F6FA;
  --surface: #FFFFFF;
  --surface-alt: #EBF0F7;
  --surface-hover: #E1E8F2;
  --border: #DCE3EE;
  --border-strong: #BEC9DA;
  --text: #131B2E;
  --text-muted: #52607A;
  --accent: #2563EB;
  --accent-hover: #1D4ED8;
  --accent-soft: #E8F0FE;
  --accent-text: #1E40AF;
  --code-bg: #F0F4FA;
  --code-border: #D6DFEC;
  --correct-bg: #ECFDF5;
  --correct-border: #10B981;
  --correct-text: #065F46;
  --wrong-bg: #FEF2F2;
  --wrong-border: #EF4444;
  --wrong-text: #991B1B;
  --takeaway-bg: #EFF6FF;
  --takeaway-border: #3B82F6;
  --takeaway-text: #1E3A8A;
  --info-bg: #F0FDFA;
  --info-border: #0D9488;
  --info-text: #115E59;
  --warn-bg: #FFFBEB;
  --warn-border: #F59E0B;
  --warn-text: #92400E;
}

/* Theme 3: Sepia Reader */
html[data-theme="sepia"] {
  --bg: #F4ECD8;
  --surface: #FBF6EA;
  --surface-alt: #ECE1C8;
  --surface-hover: #E3D6B8;
  --border: #DDD0B4;
  --border-strong: #C3B28F;
  --text: #382C25;
  --text-muted: #6E5D52;
  --accent: #9C4A1A;
  --accent-hover: #7E3912;
  --accent-soft: #F3DFD0;
  --accent-text: #7A350E;
  --code-bg: #EFE5CE;
  --code-border: #D8C9AA;
  --correct-bg: #E8F2E6;
  --correct-border: #3E7B48;
  --correct-text: #214D29;
  --wrong-bg: #F9E5E2;
  --wrong-border: #B94A3E;
  --wrong-text: #75271F;
  --takeaway-bg: #F8ECC8;
  --takeaway-border: #B78428;
  --takeaway-text: #5F420B;
  --info-bg: #E7EEF0;
  --info-border: #4A7A8C;
  --info-text: #274854;
  --warn-bg: #F9E8CD;
  --warn-border: #C47A1E;
  --warn-text: #6E4109;
}

/* Theme 4: Midnight Slate */
html[data-theme="midnight"] {
  --bg: #0B1120;
  --surface: #151E32;
  --surface-alt: #1E293B;
  --surface-hover: #27354D;
  --border: #28354D;
  --border-strong: #3E5070;
  --text: #E2E8F0;
  --text-muted: #94A3B8;
  --accent: #38BDF8;
  --accent-hover: #0EA5E9;
  --accent-soft: rgba(56, 189, 248, 0.14);
  --accent-text: #7DD3FC;
  --code-bg: #0D1526;
  --code-border: #28354D;
  --correct-bg: rgba(16, 185, 129, 0.14);
  --correct-border: #10B981;
  --correct-text: #6EE7B7;
  --wrong-bg: rgba(239, 68, 68, 0.14);
  --wrong-border: #EF4444;
  --wrong-text: #FCA5A5;
  --takeaway-bg: rgba(245, 158, 11, 0.13);
  --takeaway-border: #F59E0B;
  --takeaway-text: #FCD34D;
  --info-bg: rgba(56, 189, 248, 0.12);
  --info-border: #38BDF8;
  --info-text: #BAE6FD;
  --warn-bg: rgba(251, 146, 60, 0.14);
  --warn-border: #FB923C;
  --warn-text: #FDBA74;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.4);
}

/* Theme 5: Emerald Forest */
html[data-theme="emerald"] {
  --bg: #0A1410;
  --surface: #11201A;
  --surface-alt: #182C24;
  --surface-hover: #213B30;
  --border: #234034;
  --border-strong: #345C4B;
  --text: #E2EFE9;
  --text-muted: #90B0A1;
  --accent: #34D399;
  --accent-hover: #10B981;
  --accent-soft: rgba(52, 211, 153, 0.14);
  --accent-text: #6EE7B7;
  --code-bg: #09120E;
  --code-border: #234034;
  --correct-bg: rgba(52, 211, 153, 0.14);
  --correct-border: #34D399;
  --correct-text: #A7F3D0;
  --wrong-bg: rgba(248, 113, 113, 0.14);
  --wrong-border: #F87171;
  --wrong-text: #FECACA;
  --takeaway-bg: rgba(251, 191, 36, 0.12);
  --takeaway-border: #FBBF24;
  --takeaway-text: #FDE68A;
  --info-bg: rgba(45, 212, 191, 0.12);
  --info-border: #2DD4BF;
  --info-text: #99F6E4;
  --warn-bg: rgba(251, 146, 60, 0.14);
  --warn-border: #FB923C;
  --warn-text: #FED7AA;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.4);
}

/* Font & Size Settings */
html[data-font="serif"] { --body-font: var(--font-serif); }
html[data-size="sm"] { --base-size: 14px; }
html[data-size="md"] { --base-size: 16px; }
html[data-size="lg"] { --base-size: 18px; }
html[data-size="xl"] { --base-size: 20px; }
html[data-width="wide"] { --content-max: 1220px; }

/* Base Reset */
*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body-font);
  font-size: var(--base-size);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
html { color-scheme: light; }
html[data-theme="midnight"], html[data-theme="emerald"] { color-scheme: dark; }
body { overflow-wrap: break-word; }
img, svg, video { max-width: 100%; height: auto; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font-family: var(--font-sans); font-size: 0.9rem; }
code, pre { font-family: var(--font-mono); }

.hidden { display: none !important; }
.mobile-only { display: none; }

/* Layout Shell */
.app-shell {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar {
  width: 272px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  z-index: 60;
  font-family: var(--font-sans);
}

.sidebar-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--text);
  text-decoration: none !important;
}
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 0.95rem; letter-spacing: -0.01em; }
.brand-text small { font-size: 0.74rem; color: var(--text-muted); }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
}

.nav-group { margin-bottom: 16px; }
.nav-group-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 4px 10px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  text-decoration: none !important;
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--surface-alt); }
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 600;
}

.nav-icon {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  background: var(--surface-alt);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.nav-item.active .nav-icon {
  background: var(--accent);
  color: #fff;
}

.nav-count, .nav-badge {
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 99px;
  background: var(--surface-alt);
  color: var(--text-muted);
}
.nav-badge { background: var(--accent-soft); color: var(--accent-text); }

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-alt);
}
.progress-mini-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  margin-bottom: 6px;
}
.progress-bar-track {
  height: 7px;
  border-radius: 99px;
  background: var(--border);
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.3s ease;
}
.sidebar-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

/* Main Column & Topbar */
.main-column {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 24px;
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-family: var(--font-sans);
}

.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-title {
  margin: 0;
  font-weight: 600;
  font-size: 0.98rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.control-pill {
  display: inline-flex;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}
.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.8rem;
  transition: all 0.15s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

/* Theme Picker Dots */
.theme-picker {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.theme-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s;
}
.theme-dot:hover { transform: scale(1.15); }
.theme-dot { padding: 0; }
.theme-dot.active { border-color: var(--text); transform: scale(1.15); }
.theme-dot[data-theme-pick="warm"] { background: linear-gradient(135deg, #FAF8F5 50%, #C8643C 50%); }
.theme-dot[data-theme-pick="nordic"] { background: linear-gradient(135deg, #F3F6FA 50%, #2563EB 50%); }
.theme-dot[data-theme-pick="sepia"] { background: linear-gradient(135deg, #F4ECD8 50%, #9C4A1A 50%); }
.theme-dot[data-theme-pick="midnight"] { background: linear-gradient(135deg, #0B1120 50%, #38BDF8 50%); }
.theme-dot[data-theme-pick="emerald"] { background: linear-gradient(135deg, #0A1410 50%, #34D399 50%); }

/* App Main Container */
.app-main {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 28px 24px 72px;
  outline: none;
  transition: max-width 0.2s ease;
}

/* Buttons */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font-weight: 500;
  cursor: pointer;
}
.btn-secondary:hover { background: var(--surface-alt); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  cursor: pointer;
}
.btn-ghost:hover { background: var(--surface-alt); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
.btn-xs { padding: 3px 8px; font-size: 0.75rem; flex: 1; text-align: center; }

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-alt); }

/* Cards & Typography */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}

.hero-banner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 5px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 24px 28px;
  margin-bottom: 22px;
  box-shadow: var(--shadow-sm);
}
.hero-banner h1 { margin: 0 0 8px; font-size: 1.55rem; letter-spacing: -0.02em; font-family: var(--font-sans); }
.hero-banner p { margin: 0; color: var(--text-muted); }

/* Dashboard Grids */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
}
.kpi-label { font-size: 0.78rem; color: var(--text-muted); font-family: var(--font-sans); font-weight: 500; }
.kpi-value { font-size: 1.55rem; font-weight: 700; margin-top: 4px; font-family: var(--font-sans); }
.kpi-sub { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }

.bank-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.bank-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.12s, box-shadow 0.15s;
  text-decoration: none !important;
  color: var(--text);
}
.bank-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.bank-card-top { display: flex; justify-content: space-between; align-items: center; }
.bank-card h3 { margin: 0; font-size: 1.02rem; font-family: var(--font-sans); }
.bank-card p { margin: 0; font-size: 0.85rem; color: var(--text-muted); }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: 0.74rem;
  font-weight: 600;
  font-family: var(--font-sans);
  background: var(--surface-alt);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.badge-accent { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.badge-easy { background: var(--correct-bg); color: var(--correct-text); border-color: transparent; }
.badge-intermediate { background: var(--info-bg); color: var(--info-text); border-color: transparent; }
.badge-advanced { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }
.badge-expert { background: var(--wrong-bg); color: var(--wrong-text); border-color: transparent; }
.badge-multi { background: var(--takeaway-bg); color: var(--takeaway-text); border-color: var(--takeaway-border); }

/* Filter Bar */
.filter-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  font-family: var(--font-sans);
}
.filter-bar input[type="search"],
.filter-bar input[type="number"],
.filter-bar select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 0.86rem;
}
.filter-bar input[type="search"] { flex: 1; min-width: 190px; }

.toolbar-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
  font-family: var(--font-sans);
  font-size: 0.86rem;
  color: var(--text-muted);
}

/* Question Card */
.q-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.q-card.is-current { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

.q-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.q-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.q-id {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--accent-text);
  background: var(--accent-soft);
  padding: 2px 9px;
  border-radius: 6px;
}
.q-actions { display: flex; gap: 6px; align-items: center; }

.bookmark-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.82rem;
}
.bookmark-btn.active {
  background: var(--takeaway-bg);
  border-color: var(--takeaway-border);
  color: var(--takeaway-text);
  font-weight: 600;
}

.q-stem { margin-bottom: 16px; }
.q-stem p:first-child { margin-top: 0; }
.q-stem p:last-child { margin-bottom: 0; }

/* Answer Options */
.options-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-bottom: 16px;
}

.option-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.14s, background 0.14s;
  font-family: var(--body-font);
  font-size: 0.96rem;
  line-height: 1.55;
}
.option-item:hover { border-color: var(--border-strong); background: var(--surface-alt); }
.option-item.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.option-item.correct {
  border-color: var(--correct-border);
  background: var(--correct-bg);
  color: var(--correct-text);
}
.option-item.wrong {
  border-color: var(--wrong-border);
  background: var(--wrong-bg);
  color: var(--wrong-text);
}
.option-item.dimmed { opacity: 0.72; }

.option-letter {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 0.82rem;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  margin-top: 1px;
}
.option-item.selected .option-letter {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.option-item.correct .option-letter {
  background: var(--correct-border);
  border-color: var(--correct-border);
  color: #fff;
}
.option-item.wrong .option-letter {
  background: var(--wrong-border);
  border-color: var(--wrong-border);
  color: #fff;
}
.option-body { flex: 1; min-width: 0; }
.option-body p { margin: 0; }

.q-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  font-family: var(--font-sans);
}
.result-pill {
  font-weight: 600;
  font-size: 0.86rem;
  padding: 4px 11px;
  border-radius: 99px;
}
.result-pill.correct { background: var(--correct-bg); color: var(--correct-text); }
.result-pill.wrong { background: var(--wrong-bg); color: var(--wrong-text); }

/* Structured Explanation Panel */
.explanation-panel {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px dashed var(--border-strong);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.exp-block {
  border-radius: var(--radius-md);
  padding: 13px 16px;
  background: var(--surface-alt);
  border-left: 4px solid var(--border-strong);
}
.exp-block h4 {
  margin: 0 0 6px;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-family: var(--font-sans);
}
.exp-block p:first-of-type { margin-top: 0; }
.exp-block p:last-child, .exp-block ul:last-child { margin-bottom: 0; }

.exp-correct { background: var(--correct-bg); border-left-color: var(--correct-border); }
.exp-correct h4 { color: var(--correct-text); }

.exp-root { background: var(--wrong-bg); border-left-color: var(--wrong-border); }
.exp-root h4 { color: var(--wrong-text); }

.exp-solution { background: var(--correct-bg); border-left-color: var(--correct-border); }
.exp-solution h4 { color: var(--correct-text); }

.exp-takeaway { background: var(--takeaway-bg); border-left-color: var(--takeaway-border); }
.exp-takeaway h4 { color: var(--takeaway-text); }

.exp-tech { background: var(--info-bg); border-left-color: var(--info-border); }
.exp-tech h4 { color: var(--info-text); }

.exp-status { background: var(--warn-bg); border-left-color: var(--warn-border); }
.exp-status h4 { color: var(--warn-text); }

.distractor-list { display: flex; flex-direction: column; gap: 8px; }
.distractor-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 0.93rem;
}
.distractor-key {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.78rem;
  padding: 1px 7px;
  border-radius: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  margin-top: 2px;
  flex-shrink: 0;
}

/* Scenario & Comparison Context Cards */
.context-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}
.context-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.context-card h2 { margin: 0; font-size: 1.18rem; font-family: var(--font-sans); }

/* Markdown Rendering */
.md-content h1, .md-content h2, .md-content h3, .md-content h4 {
  font-family: var(--font-sans);
  letter-spacing: -0.01em;
  margin-top: 1.4em;
  margin-bottom: 0.55em;
}
.md-content h1 { font-size: 1.5rem; }
.md-content h2 { font-size: 1.24rem; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.md-content h3 { font-size: 1.06rem; }
.md-content p { margin: 0.65em 0; }
.md-content ul, .md-content ol { padding-left: 1.4em; margin: 0.5em 0; }
.md-content li { margin: 0.3em 0; }
.md-content blockquote {
  margin: 0.9em 0;
  padding: 10px 16px;
  border-left: 4px solid var(--accent);
  background: var(--surface-alt);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.md-content blockquote p { margin: 0.3em 0; }
.md-content hr { border: none; border-top: 1px solid var(--border); margin: 1.4em 0; }
.md-content :not(pre) > code {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.87em;
}

.code-block-wrap {
  position: relative;
  margin: 12px 0;
  border: 1px solid var(--code-border);
  border-radius: var(--radius-md);
  background: var(--code-bg);
  overflow: hidden;
}
.code-block-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 12px;
  border-bottom: 1px solid var(--code-border);
  font-family: var(--font-sans);
  font-size: 0.74rem;
  color: var(--text-muted);
}
.code-copy-btn {
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 0.72rem;
  cursor: pointer;
}
.code-copy-btn:hover { color: var(--text); }
.code-block-wrap pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  font-size: 0.84rem;
  line-height: 1.5;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  margin: 12px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
th, td {
  padding: 10px 13px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th {
  background: var(--surface-alt);
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.84rem;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-alt); }

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 24px;
  flex-wrap: wrap;
  font-family: var(--font-sans);
}

/* Domain Bars */
.domain-bar-row { margin-bottom: 12px; font-family: var(--font-sans); }
.domain-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 4px;
}
.domain-bar-track {
  height: 10px;
  border-radius: 99px;
  background: var(--surface-alt);
  overflow: hidden;
}
.domain-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
}

/* Research Reader */
.research-layout {
  display: grid;
  grid-template-columns: 1fr 240px;
  gap: 22px;
  align-items: start;
}
.research-toc {
  position: sticky;
  top: 76px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  font-family: var(--font-sans);
  font-size: 0.81rem;
}
.research-toc h4 { margin: 0 0 10px; font-size: 0.78rem; text-transform: uppercase; color: var(--text-muted); }
.toc-link {
  display: block;
  padding: 4px 0;
  color: var(--text-muted);
  cursor: pointer;
}
.toc-link:hover { color: var(--accent-text); }
.toc-link.lvl-3 { padding-left: 12px; font-size: 0.77rem; }

.tab-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 18px;
}
.tab-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
}
.tab-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.kbd {
  display: inline-block;
  padding: 2px 7px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  background: var(--surface-alt);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
}

.loading-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}


/* =========================================================
   Shared utilities & accessibility
   ========================================================= */
.skip-link {
  position: fixed;
  left: 12px;
  top: -60px;
  z-index: 200;
  background: var(--accent);
  color: #fff;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
}
.skip-link:focus { top: 12px; text-decoration: none; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
.option-item:focus-visible, .bank-card:focus-visible, .palette-tile:focus-visible { outline-offset: 1px; }
:focus:not(:focus-visible) { outline: none; }

body.scroll-locked { overflow: hidden; }

.muted { color: var(--text-muted); }
.small { font-size: 0.84rem; }
.desktop-only { display: initial; }
.mobile-only-inline, .sheet-only { display: none; }
.hide-touch { }
.scroll-strip { }

.btn-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none !important;
  text-align: center;
  line-height: 1.3;
}
a.btn-primary { color: #fff; }
a.btn-secondary { color: var(--text); }
.btn-danger { background: var(--wrong-border); }
.btn-danger:hover { background: var(--wrong-border); filter: brightness(0.92); }
.btn-danger-outline { color: var(--wrong-text); border-color: var(--wrong-border); }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-top: var(--sp-4); }
.btn-primary, .btn-secondary, .btn-ghost { font-family: var(--font-sans); font-size: 0.92rem; }

.section-title { margin: 6px 0 4px; font-size: 1.12rem; font-family: var(--font-sans); letter-spacing: -0.01em; }
.section-heading { margin: 0 0 var(--sp-3); font-size: 1.12rem; font-family: var(--font-sans); }
.page-head { margin-bottom: var(--sp-4); }
.page-head h1 { margin: 0 0 4px; font-size: 1.35rem; font-family: var(--font-sans); letter-spacing: -0.01em; }
.page-head p { margin: 0; font-size: 0.92rem; }

.brand-mark.topbar-mark { display: none; width: 32px; height: 32px; font-size: 0.8rem; border-radius: 8px; text-decoration: none; }
.display-btn {
  display: none;
  align-items: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 0 12px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.86rem;
  cursor: pointer;
}
.display-btn [aria-hidden] { font-size: 1.05rem; font-family: var(--font-serif); }

.theme-dot { display: inline-block; flex-shrink: 0; }
i.theme-dot { cursor: inherit; pointer-events: none; }

.count-badge {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 99px;
  background: var(--accent);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  margin-left: 4px;
}
.count-badge[hidden] { display: none; }

/* =========================================================
   Sheets (bottom sheet on mobile, centered dialog on desktop)
   ========================================================= */
.sheet-root { position: fixed; inset: 0; z-index: 100; display: none; font-family: var(--font-sans); }
.sheet-root.open { display: block; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.5); animation: fade-in 0.2s ease-out; }
.sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: calc(100dvh - 32px - var(--safe-t));
  display: flex;
  flex-direction: column;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.25);
  padding-bottom: var(--safe-b);
  animation: sheet-up 0.26s cubic-bezier(0.2, 0.8, 0.2, 1);
  transition: transform 0.2s;
}
.sheet-grab { height: 20px; display: grid; place-items: center; touch-action: none; }
.sheet-grab::before { content: ''; width: 40px; height: 4px; border-radius: 4px; background: var(--border-strong); }
.sheet-header { display: flex; align-items: center; justify-content: space-between; padding: 0 14px 6px 18px; touch-action: none; }
.sheet-header h3 { margin: 0; font-size: 1.05rem; }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; padding: 6px 18px 20px; -webkit-overflow-scrolling: touch; }
.sheet-actions { margin-top: var(--sp-4); display: grid; }
.sheet-actions .btn-primary { min-height: 48px; }
.confirm-message p { margin: 0 0 8px; }
.confirm-warn { color: var(--warn-text); }
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2); margin-top: var(--sp-4); }
.confirm-actions button { min-height: 48px; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes pop-in { from { opacity: 0; transform: scale(0.97); } to { opacity: 1; transform: none; } }

@media (min-width: 821px) {
  .sheet-panel {
    inset: 0;
    margin: auto;
    height: fit-content;
    width: min(520px, calc(100vw - 32px));
    max-height: calc(100dvh - 48px);
    border-radius: var(--radius-lg);
    border-bottom: 1px solid var(--border);
    animation: pop-in 0.18s ease-out;
    padding-bottom: 0;
  }
  .sheet-grab { display: none; }
  .sheet-header { padding-top: 14px; }
  .nav-sheet .sheet-panel { width: min(720px, calc(100vw - 32px)); }
  .confirm-sheet .sheet-panel { width: min(440px, calc(100vw - 32px)); }
}

/* Display sheet */
.setting-row { padding: var(--sp-3) 0; border-bottom: 1px solid var(--border); }
.setting-row:last-child { border-bottom: none; }
.setting-label { font-size: 0.76rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: var(--sp-2); }
.setting-hint { font-size: 0.82rem; color: var(--text-muted); margin: var(--sp-2) 0 0; }
.wide-pill { display: flex; width: 100%; }
.wide-pill .seg-btn { flex: 1; min-height: 44px; font-size: 0.92rem; }
.size-readout { opacity: 1; color: var(--text); cursor: default; flex: 1.4 !important; }
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: var(--sp-2); }
.theme-chip {
  display: flex; align-items: center; gap: 8px;
  min-height: 46px; padding: 0 12px;
  background: var(--surface-alt); color: var(--text);
  border: 2px solid var(--border); border-radius: 10px;
  font-weight: 500; cursor: pointer;
}
.theme-chip.active { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.theme-chip .theme-dot { width: 22px; height: 22px; border: 1px solid var(--border-strong); transform: none !important; }
.data-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-2); }
.data-actions > * { min-height: 46px; display: inline-flex; align-items: center; justify-content: center; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px);
  transform: translate(-50%, 20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 99px;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 150;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 821px) { .toast { bottom: 24px; } }

/* =========================================================
   Bottom tab bar (mobile only)
   ========================================================= */
.tabbar { display: none; }
.tab-item {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--tabbar-h);
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.7rem;
  font-weight: 600;
  text-decoration: none !important;
  cursor: pointer;
  padding: 6px 2px;
}
.tab-item.active { color: var(--accent-text); }
.tab-item.active .tab-ico { background: var(--accent-soft); }
.tab-ico { position: relative; width: 48px; height: 28px; border-radius: 14px; display: grid; place-items: center; font-size: 1.1rem; line-height: 1; transition: background 0.15s; }
.tab-badge {
  position: absolute; top: -2px; right: 2px;
  min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 99px; background: var(--accent); color: #fff;
  font-size: 0.64rem; font-weight: 700; display: grid; place-items: center; line-height: 1;
}
.tab-badge[hidden] { display: none; }

/* =========================================================
   Filters, toolbar, pagination
   ========================================================= */
.filter-selects, .filter-actions { display: contents; }
.filter-toggle { display: none; }
.filter-bar select { max-width: 100%; }
.filter-selects select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 0.86rem;
}
.full-select, .jump-group input {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
}
.full-select { width: 100%; max-width: 100%; }
.jump-group { display: flex; gap: 4px; align-items: center; }
.jump-group input { width: 90px; }

/* Question card extras */
.feedback-banner {
  display: flex; align-items: center; gap: 12px;
  margin-top: var(--sp-4);
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1.5px solid;
  font-family: var(--font-sans);
  scroll-margin-top: calc(var(--topbar-h) + 12px);
}
.feedback-banner.correct { background: var(--correct-bg); border-color: var(--correct-border); color: var(--correct-text); }
.feedback-banner.wrong { background: var(--wrong-bg); border-color: var(--wrong-border); color: var(--wrong-text); }
.feedback-icon { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; flex-shrink: 0; }
.feedback-banner.correct .feedback-icon { background: var(--correct-border); }
.feedback-banner.wrong .feedback-icon { background: var(--wrong-border); }
.feedback-sub { font-size: 0.86rem; opacity: 0.9; }
.q-controls { gap: var(--sp-2); justify-content: flex-start; }
.q-card, .context-card { scroll-margin-top: calc(var(--topbar-h) + 8px); }
.q-stem pre, .exp-block pre, .context-card pre { max-width: 100%; }
.md-content, .q-stem, .option-body, .exp-block, .distractor-item { overflow-wrap: break-word; }
.md-content > :first-child { margin-top: 0; }
.table-wrap th, .table-wrap td { overflow-wrap: normal; }
.badge-flag { background: var(--warn-bg); color: var(--warn-text); border-color: var(--warn-border); }
.select-hint { margin: -6px 0 10px; font-size: 0.84rem; color: var(--text-muted); font-family: var(--font-sans); }

/* Dashboard */
.continue-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); gap: var(--sp-3); margin-bottom: var(--sp-4); }
.continue-card {
  display: flex; flex-direction: column; gap: 4px;
  padding: 16px 18px; border-radius: var(--radius-md);
  background: var(--accent-soft); border: 1px solid var(--accent);
  color: var(--text); text-decoration: none !important; font-family: var(--font-sans);
}
.continue-card.continue-mock { background: var(--warn-bg); border-color: var(--warn-border); }
.continue-kicker { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; color: var(--accent-text); }
.continue-mock .continue-kicker { color: var(--warn-text); }
.continue-card strong { font-size: 1.05rem; }
.continue-sub { font-size: 0.84rem; color: var(--text-muted); }
.continue-cta { margin-top: 6px; font-weight: 600; color: var(--accent-text); font-size: 0.9rem; }
.quick-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-3); margin-bottom: var(--sp-4); }
.quick-action {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 72px; padding: 10px 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  color: var(--text); font-family: var(--font-sans); font-weight: 600; font-size: 0.84rem;
  text-decoration: none !important; text-align: center;
}
.quick-action span { font-size: 1.3rem; line-height: 1; }
.kpi-of { font-size: 0.9rem; color: var(--text-muted); font-weight: 400; }
.weights-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); gap: 26px; margin-top: 14px; }
.bank-grid { grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); }
.kpi-grid { grid-template-columns: repeat(auto-fit, minmax(min(175px, 100%), 1fr)); }
.domain-bar-fill.below { background: var(--warn-border); }

/* Mock lobby */
.mock-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--sp-3); flex-wrap: wrap; }
.mock-card-head > div { flex: 1 1 260px; min-width: 0; }
.mock-card p { margin: 4px 0 0; }
.mock-history { margin-top: var(--sp-3); font-size: 0.84rem; }
.mock-history ul { margin: 4px 0 0; padding-left: 18px; }
.resume-card { border-left: 5px solid var(--warn-border); background: var(--warn-bg); }
.resume-card p { margin: 4px 0 0; }

/* =========================================================
   Mock exam runner
   ========================================================= */
.mock-hud {
  position: sticky;
  top: var(--topbar-h);
  z-index: 25;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px 0;
  margin-bottom: var(--sp-4);
  box-shadow: var(--shadow-md);
  font-family: var(--font-sans);
  overflow: hidden;
}
.mock-hud-main { display: flex; align-items: center; gap: var(--sp-3); padding-bottom: 10px; }
.mock-hud-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; flex: 1; font-size: 0.9rem; }
.mock-hud-text .muted { font-size: 0.78rem; font-weight: 400; }
.mock-hud-actions { display: flex; gap: 6px; align-items: center; }
.mock-hud-actions button { min-height: 40px; }
.mock-timer {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 700;
  padding: 4px 11px;
  border-radius: 6px;
  background: var(--surface-alt);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.mock-timer.warning { background: var(--wrong-bg); color: var(--wrong-text); }
.mock-progress-track { height: 4px; margin: 0 -14px; background: var(--surface-alt); }
.mock-progress-fill { height: 100%; background: var(--accent); transition: width 0.25s; }

.mock-palette {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 6px;
  margin-bottom: var(--sp-3);
}
.palette-tile {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  position: relative;
}
.palette-tile.answered { background: var(--accent-soft); color: var(--accent-text); border-color: var(--accent); }
.palette-tile.current { outline: 2px solid var(--text); outline-offset: 1px; }
.palette-tile.flagged::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn-border);
}
.palette-inline { padding: 14px 16px; }
.palette-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 0.78rem; color: var(--text-muted); font-family: var(--font-sans); margin-bottom: var(--sp-3); }
.palette-legend span { display: inline-flex; align-items: center; gap: 6px; }
.lg { width: 14px; height: 14px; border-radius: 4px; border: 1px solid var(--border-strong); display: inline-block; position: relative; }
.lg-answered { background: var(--accent-soft); border-color: var(--accent); }
.lg-unanswered { background: var(--surface); }
.lg-flagged::after { content: ''; position: absolute; top: 1px; right: 1px; width: 6px; height: 6px; border-radius: 50%; background: var(--warn-border); }
.lg-current { outline: 2px solid var(--text); outline-offset: 0; }
.nav-summary { font-size: 0.9rem; margin-bottom: var(--sp-3); }
.palette-inline .palette-legend { margin: 0; }

.scenario-card { padding: 14px 18px; }
.scenario-card summary { cursor: pointer; font-weight: 600; font-family: var(--font-sans); min-height: 28px; }
.scenario-body { margin-top: 10px; }
.paused-card { text-align: center; padding: 40px 20px; }

.mock-actionbar {
  position: sticky;
  bottom: 0;
  z-index: 25;
  display: flex;
  justify-content: space-between;
  gap: var(--sp-2);
  padding: 10px 12px;
  margin-top: var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}
.mock-actionbar button { min-height: 46px; font-weight: 600; }
.flag-btn.active { background: var(--takeaway-bg); border-color: var(--takeaway-border); color: var(--takeaway-text); }

/* Score report */
.score-hero.pass { border-left-color: var(--correct-border); }
.score-hero.fail { border-left-color: var(--warn-border); }
.score-kicker { font-size: 0.84rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px !important; }
.score-main { display: flex; align-items: center; gap: var(--sp-4); margin-bottom: var(--sp-2); }
.score-big { font-family: var(--font-sans); font-size: 3rem; font-weight: 700; line-height: 1; letter-spacing: -0.03em; color: var(--text); }
.score-verdict { font-weight: 700; font-family: var(--font-sans); color: var(--text); }
.score-hero .small { margin-top: 6px; }
.review-toolbar { align-items: flex-start; }
.filter-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill-btn {
  min-height: 40px; padding: 0 14px;
  background: var(--surface); color: var(--text-muted);
  border: 1px solid var(--border-strong); border-radius: 99px;
  font-family: var(--font-sans); font-weight: 500; cursor: pointer;
}
.pill-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.q-header .result-pill { align-self: flex-start; }

.toc-open-btn { display: none; }
.toc-sheet-list .toc-link { padding: 12px 4px; font-size: 0.95rem; border-bottom: 1px solid var(--border); }
.toc-sheet-list .toc-link.lvl-3 { padding-left: 18px; font-size: 0.9rem; }
.doc-filter { padding: 10px 14px; }

/* Desktop hover affordances only where hover exists */
@media (hover: none) {
  .option-item:hover { border-color: var(--border); background: var(--bg); }
  .option-item.selected:hover { border-color: var(--accent); background: var(--accent-soft); }
  .option-item.correct:hover { border-color: var(--correct-border); background: var(--correct-bg); }
  .option-item.wrong:hover { border-color: var(--wrong-border); background: var(--wrong-bg); }
  .bank-card:hover { transform: none; box-shadow: none; border-color: var(--border); }
  .nav-item:hover, .btn-ghost:hover, .btn-secondary:hover, .seg-btn:hover, tbody tr:hover { background: inherit; }
  .btn-primary:hover { background: var(--accent); }
  .theme-dot:hover { transform: none; }
  a:hover { text-decoration: none; }
  .hide-touch { display: none !important; }
}
@media (hover: none) and (pointer: coarse) { .hide-touch { display: none !important; } }
.btn-ghost:active, .btn-secondary:active, .tab-item:active, .bank-card:active, .quick-action:active, .continue-card:active { background: var(--surface-hover); }
.btn-primary:active { background: var(--accent-hover); }
.option-item:active { border-color: var(--accent); }

/* =========================================================
   Responsive
   ========================================================= */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 55;
}

@media (max-width: 960px) {
  .research-layout { grid-template-columns: 1fr; }
  .research-toc { display: none; }
  .toc-open-btn { display: inline-flex; align-items: center; min-height: var(--tap); }
  .scroll-strip { flex-wrap: nowrap; overflow-x: auto; margin-inline: -14px; padding: 0 14px 4px; scrollbar-width: none; }
  .scroll-strip::-webkit-scrollbar { display: none; }
  .scroll-strip .tab-btn { white-space: nowrap; flex-shrink: 0; }
}

@media (max-width: 820px) {
  :root { --topbar-h: 52px; }
  html { scroll-padding-top: calc(var(--topbar-h) + 8px); }
  .mobile-only { display: grid; }
  .desktop-only { display: none !important; }
  .mobile-only-inline { display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
  .sheet-only { display: inline-flex; }

  /* Drawer */
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(86vw, 330px);
    transform: translateX(-105%);
    visibility: hidden;
    transition: transform 0.24s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 0.24s;
    box-shadow: var(--shadow-md);
    padding-bottom: var(--safe-b);
    padding-left: var(--safe-l);
  }
  .sidebar.open { transform: none; visibility: visible; transition-delay: 0s; }
  .sidebar-backdrop.open { display: block; animation: fade-in 0.2s; }
  .sidebar-nav { overscroll-behavior: contain; }
  .nav-item { min-height: var(--tap); padding: 8px 12px; font-size: 0.95rem; }
  .sidebar-actions .btn-xs { min-height: var(--tap); display: inline-flex; align-items: center; justify-content: center; font-size: 0.85rem; }

  /* Compact app header */
  .topbar {
    padding: calc(6px + var(--safe-t)) calc(14px + var(--safe-r)) 6px calc(14px + var(--safe-l));
    min-height: calc(var(--topbar-h) + var(--safe-t));
  }
  .brand-mark.topbar-mark { display: grid; }
  .topbar-title { font-size: 1.02rem; }
  .desktop-controls { display: none; }
  .display-btn { display: inline-flex; }

  /* Bottom tab bar */
  .tabbar {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 50;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 0 var(--safe-r) var(--safe-b) var(--safe-l);
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.06);
  }
  body.in-exam .tabbar, body.in-exam .topbar { display: none; }

  /* Content */
  .app-main {
    padding: 14px calc(14px + var(--safe-r)) calc(var(--tabbar-h) + var(--safe-b) + 28px) calc(14px + var(--safe-l));
  }
  body.in-exam .app-main { padding-top: calc(10px + var(--safe-t)); padding-bottom: calc(96px + var(--safe-b)); }
  .card, .q-card, .context-card, .hero-banner { padding: 16px; border-radius: 12px; margin-bottom: var(--sp-3); }
  .hero-banner { padding: 16px; }
  .hero-banner h1 { font-size: 1.28rem; }
  .context-card h2 { font-size: 1.08rem; }

  /* Inputs: >=16px prevents iOS zoom-on-focus; >=44px tap height */
  input, select, textarea, .filter-bar input[type="search"], .filter-bar input[type="number"], .filter-bar select,
  .filter-selects select, .full-select, .jump-group input { font-size: 16px; min-height: var(--tap); }
  .btn-primary, .btn-secondary, .btn-ghost, .btn-sm, .bookmark-btn, .tab-btn, .seg-btn, .code-copy-btn {
    min-height: var(--tap);
    padding-top: 6px;
    padding-bottom: 6px;
  }
  .btn-sm { padding-left: 14px; padding-right: 14px; font-size: 0.86rem; }
  .code-copy-btn { padding: 0 12px; font-size: 0.8rem; }
  .icon-btn { width: var(--tap); height: var(--tap); }
  .bookmark-btn { padding-left: 12px; padding-right: 12px; }
  .bookmark-btn .bm-text { display: none; }
  .bookmark-btn { min-width: var(--tap); font-size: 1.1rem; }
  .pagination .btn-sm { min-width: 96px; }

  /* Reading typography */
  .q-stem { font-size: 1.02rem; line-height: 1.68; }
  .md-content { line-height: 1.7; }
  .md-content h1 { font-size: 1.35rem; }
  .md-content h2 { font-size: 1.16rem; }
  .q-header { margin-bottom: var(--sp-3); padding-bottom: 10px; }
  .q-header .q-actions { margin-left: auto; }

  /* Answer options: big full-width rows */
  .options-list { gap: 10px; margin-bottom: var(--sp-3); }
  .option-item { min-height: 56px; padding: 12px 14px; align-items: center; font-size: 1rem; border-radius: 12px; }
  .option-letter { width: 32px; height: 32px; font-size: 0.92rem; border-radius: 8px; margin-top: 0; }

  /* Sticky Check / Next, reachable by thumb */
  .q-controls.is-sticky {
    position: sticky;
    bottom: calc(var(--tabbar-h) + var(--safe-b));
    z-index: 15;
    margin: 0 -16px;
    padding: 10px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -6px 14px rgba(0, 0, 0, 0.06);
    display: flex;
    flex-wrap: nowrap;
  }
  .q-controls.is-sticky .btn-primary { flex: 1; min-height: 48px; }
  .q-controls .btn-secondary { width: 100%; min-height: 48px; }

  /* Filters collapse into a sheet */
  .filter-bar { flex-wrap: nowrap; padding: 10px; gap: var(--sp-2); }
  .filter-bar input[type="search"] { min-width: 0; }
  .filter-toggle { display: inline-flex; align-items: center; flex-shrink: 0; }
  .filter-bar > .filter-selects { display: none; }
  .sheet-body .filter-selects { display: flex; flex-direction: column; gap: var(--sp-3); }
  .filter-selects select { width: 100%; }
  .filter-actions { display: grid; grid-template-columns: 1fr; gap: var(--sp-2); margin-top: var(--sp-2); }
  .filter-actions .btn-primary, .filter-actions .btn-ghost { min-height: 48px; }
  .doc-filter { flex-wrap: wrap; }
  .toolbar-row { gap: var(--sp-2); font-size: 0.82rem; }
  .jump-group { margin-left: auto; }
  .jump-group input { width: 96px; }

  /* Dashboard */
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: var(--sp-2); }
  .kpi-card { padding: 12px 14px; }
  .kpi-value { font-size: 1.35rem; }
  .bank-grid { grid-template-columns: 1fr; gap: var(--sp-2); }
  .bank-card { padding: 14px 16px; min-height: var(--tap); }
  .quick-actions { gap: var(--sp-2); }

  /* Tabs (bookmarks) */
  .tab-strip:not(.scroll-strip) .tab-btn { flex: 1; text-align: center; padding-left: 8px; padding-right: 8px; }
  .tab-btn { display: inline-flex; align-items: center; justify-content: center; }

  /* Mock */
  .mock-hud { top: var(--safe-t); margin-top: 0; padding: 8px 12px 0; }
  body:not(.in-exam) .mock-hud { top: var(--topbar-h); }
  .mock-hud-main { gap: 8px; padding-bottom: 8px; }
  .mock-timer { font-size: 1.05rem; padding: 4px 8px; }
  .mock-progress-track { margin: 0 -12px; }
  .mock-hud-actions button { padding-left: 12px; padding-right: 12px; font-size: 0.85rem; }
  .palette-inline { display: none; }
  .mock-actionbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    margin: 0;
    border-radius: 14px 14px 0 0;
    border-width: 1px 0 0;
    padding: 10px calc(12px + var(--safe-r)) calc(10px + var(--safe-b)) calc(12px + var(--safe-l));
    display: grid;
    grid-template-columns: 1fr 1fr auto 1.3fr;
    z-index: 45;
  }
  .mock-actionbar button { min-height: 48px; padding-left: 10px; padding-right: 10px; }
  .score-big { font-size: 2.6rem; }
  .data-actions { grid-template-columns: 1fr 1fr 1fr; }
  .setting-width { display: none; }
  .toast { bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); }
  .q-card .q-header .result-pill { font-size: 0.8rem; }
  .research-layout .card { padding: 14px; }
  table { font-size: 0.86rem; }
  th, td { padding: 8px 10px; }
}

@media (max-width: 400px) {
  .quick-action { font-size: 0.78rem; min-height: 68px; }
  .mock-hud-actions .btn-ghost { padding-left: 8px; padding-right: 8px; }
  .q-id { font-size: 0.84rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* pwa.js injects an inline-styled toast (update / install prompt); keep it above the tab bar and unwrapped */
body > div[role="status"]:not(.toast) { width: max-content; max-width: calc(100vw - 32px); }
@media (max-width: 820px) {
  body > div[role="status"]:not(.toast) { bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px) !important; }
  body.in-exam > div[role="status"]:not(.toast) { bottom: calc(84px + var(--safe-b)) !important; }
}

.q-card[data-qid] .q-header { flex-wrap: nowrap; }
.q-card[data-qid] .q-header > div:first-child { flex: 1; min-width: 0; }
.q-card[data-qid] .q-actions { flex-shrink: 0; }
.page-head h1 { line-height: 1.25; }
.sheet-only { justify-content: center; align-items: center; }
@media (min-width: 821px) { .mobile-only { display: none !important; } }
@media (max-width: 820px) {
  .hero-banner h1 { font-size: 1.15rem; margin-bottom: 4px; line-height: 1.3; }
  .hero-banner p { font-size: 0.9rem; line-height: 1.55; }
}

@media (max-width: 820px) {
  .table-wrap th, .table-wrap td { min-width: 120px; }
  .table-wrap th:first-child, .table-wrap td:first-child { min-width: 96px; }
}
