:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #475569;
  --text-subtle: #64748b;
  --navy: #0b1f3a;
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-soft: #e0f2fe;
  --success: #059669;
  --success-soft: #d1fae5;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --purple: #7c3aed;
  --purple-soft: #ede9fe;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --radius: 14px;
  --radius-sm: 10px;
}

[data-theme="dark"] {
  --bg: #081220;
  --surface: #0f1d32;
  --surface-alt: #142540;
  --border: #1e3454;
  --text: #f1f5f9;
  --text-muted: #cbd5e1;
  --text-subtle: #94a3b8;
  --navy: #060e1a;
  --primary: #38bdf8;
  --primary-hover: #0ea5e9;
  --primary-soft: rgba(56, 189, 248, 0.14);
  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.14);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);
  --warning: #fbbf24;
  --warning-soft: rgba(251, 191, 36, 0.14);
  --purple: #a78bfa;
  --purple-soft: rgba(167, 139, 250, 0.14);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--primary);
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
}

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

.sidebar {
  width: 268px;
  flex-shrink: 0;
  background: var(--navy);
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 16px;
}

.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, #0ea5e9, #2563eb);
  display: grid;
  place-items: center;
  font-size: 22px;
  box-shadow: 0 6px 16px rgba(14, 165, 233, 0.35);
}

.brand-title {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 12px;
  color: #94a3b8;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: #cbd5e1;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.nav-item.active {
  background: rgba(56, 189, 248, 0.18);
  color: #ffffff;
  font-weight: 600;
}

.nav-icon {
  font-size: 17px;
  width: 22px;
  text-align: center;
}

.nav-badge {
  margin-left: auto;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 99px;
}

.nav-pill {
  margin-left: auto;
  background: linear-gradient(135deg, #0ea5e9, #8b5cf6);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 99px;
}

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

.tg-promo {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 12px;
}

.tg-promo-title {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 4px;
}

.tg-promo-text {
  font-size: 12px;
  color: #cbd5e1;
  margin-bottom: 10px;
  line-height: 1.4;
}

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.04);
  color: #e2e8f0;
  font-size: 13px;
  font-weight: 500;
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
}

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

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-mobile-brand {
  display: none;
  align-items: center;
  gap: 10px;
}

.brand-logo-sm {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, #0ea5e9, #2563eb);
  display: grid;
  place-items: center;
  font-size: 16px;
}

.topbar-sub {
  display: block;
  font-size: 11px;
  color: var(--text-subtle);
}

.topbar-stats {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.stat-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 99px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
}

.stat-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

.main-content {
  width: 100%;
  max-width: 1060px;
  margin: 0 auto;
  padding: 24px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.15s;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}
.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-ai {
  background: linear-gradient(135deg, #0284c7, #7c3aed);
  color: #fff;
}
.btn-ai:hover {
  filter: brightness(1.08);
}

.btn-tg {
  background: #229ed9;
  color: #fff;
  width: 100%;
}
.btn-tg:hover {
  background: #1b88be;
}

.btn-sm {
  padding: 7px 12px;
  font-size: 13px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  display: grid;
  place-items: center;
  font-size: 16px;
}

/* Cards & Grids */
.hero-banner {
  background: linear-gradient(135deg, #0b1f3a 0%, #123663 60%, #0369a1 100%);
  color: #fff;
  border-radius: 18px;
  padding: 26px 28px;
  margin-bottom: 24px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  box-shadow: var(--shadow-md);
}

.hero-banner h1 {
  margin: 0 0 8px;
  font-size: 24px;
  line-height: 1.25;
}

.hero-banner p {
  margin: 0;
  color: #cbd5e1;
  font-size: 14px;
  max-width: 620px;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.hero-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.hero-tag {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.14);
  color: #e0f2fe;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.modules-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.module-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.module-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
}

.module-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.module-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 9px;
  border-radius: 99px;
  background: var(--primary-soft);
  color: var(--primary);
}

.module-title {
  margin: 6px 0 4px;
  font-size: 18px;
  font-weight: 700;
}

.module-sub {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

.progress-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-subtle);
  margin-bottom: 5px;
}

.progress-bar {
  height: 8px;
  border-radius: 99px;
  background: var(--border);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--primary), var(--success));
  transition: width 0.3s ease;
}

.topic-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.topic-pill {
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 8px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.module-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: auto;
  padding-top: 4px;
}

/* Quick Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}

.metric-label {
  font-size: 12px;
  color: var(--text-subtle);
}

.metric-val {
  font-size: 22px;
  font-weight: 800;
  margin-top: 4px;
}

/* Quiz / Exam UI */
.quiz-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.quiz-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.pill-timer {
  background: var(--warning-soft);
  color: var(--warning);
  border-color: transparent;
  font-variant-numeric: tabular-nums;
}

.pill-timer.urgent {
  background: var(--danger-soft);
  color: var(--danger);
}

.pill-multi {
  background: var(--purple-soft);
  color: var(--purple);
  border-color: transparent;
}

.question-card {
  padding: 24px;
}

.question-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.question-text {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.45;
  margin: 0 0 18px;
}

.multi-hint {
  margin: -8px 0 16px;
  padding: 9px 13px;
  border-radius: 10px;
  background: var(--purple-soft);
  color: var(--purple);
  font-size: 13px;
  line-height: 1.4;
}

.diagram-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 18px;
  text-align: center;
  cursor: zoom-in;
  position: relative;
}

.diagram-box svg {
  max-width: 100%;
  height: auto;
  max-height: 220px;
}

.diagram-caption {
  font-size: 12px;
  color: var(--text-subtle);
  margin-top: 8px;
}

.options-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.option-btn {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  text-align: left;
  line-height: 1.45;
  transition: all 0.15s;
}

.option-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--surface-alt);
}

.option-btn.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.option-btn.correct {
  border-color: var(--success);
  background: var(--success-soft);
}

.option-btn.wrong {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.option-marker {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  margin-top: 1px;
}

.option-btn.multi .option-marker {
  border-radius: 6px;
}

.option-btn.selected .option-marker {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.option-btn.correct .option-marker {
  border-color: var(--success);
  background: var(--success);
  color: #fff;
}

.option-btn.wrong .option-marker {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}

.explanation-box {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border-left: 3px solid var(--primary);
  background: var(--surface-alt);
}

.explanation-box.is-correct {
  border-left-color: var(--success);
}

.explanation-box.is-wrong {
  border-left-color: var(--danger);
}

.explanation-title {
  font-weight: 700;
  font-size: 13.5px;
  margin-bottom: 5px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
}

.explanation-text {
  font-size: 13px;
  line-height: 1.4;
}

.ref-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--primary-soft);
  color: var(--primary);
}

.tip-box {
  margin-top: 7px;
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--warning-soft);
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.38;
}

.quiz-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.quiz-dots {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 14px;
}

.quiz-dots-scrollable {
  max-height: 200px;
  overflow-y: auto;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.quiz-nav-compact {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.quiz-nav-strip {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  gap: 5px;
  max-width: 100%;
}

.quiz-nav-strip::-webkit-scrollbar {
  display: none;
}

.quiz-nav-strip .q-dot {
  flex: 0 0 auto;
}

.quiz-nav-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.q-ellipsis {
  color: var(--text-subtle);
  font-size: 12px;
  padding: 0 2px;
  user-select: none;
}

.jump-input {
  width: 58px;
  padding: 5px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 12.5px;
  text-align: center;
}

.jump-input:focus {
  outline: none;
  border-color: var(--primary);
}

.topic-select {
  max-width: 280px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.topic-select:focus {
  outline: none;
  border-color: var(--primary);
}

.q-dot {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-subtle);
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.q-dot.current {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
  color: var(--primary);
}

.q-dot.ok {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.q-dot.bad {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.q-dot.answered {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* Topic filter bar */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.filter-chip {
  padding: 6px 12px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
}

.filter-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* Search & Conventions */
.search-box {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.input, .textarea, .select {
  width: 100%;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}

.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--primary);
}

.textarea {
  min-height: 110px;
  resize: vertical;
}

.convention-card {
  margin-bottom: 14px;
}

.convention-list {
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--text-muted);
  font-size: 14px;
}

.convention-list li {
  margin-bottom: 6px;
}

/* AI Helper */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  background: var(--surface-alt);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.preview-img {
  max-width: 100%;
  max-height: 240px;
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-top: 10px;
}

.ai-response {
  margin-top: 18px;
  padding: 20px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  line-height: 1.6;
}

.ai-response h3 {
  margin: 12px 0 6px;
  font-size: 16px;
}

.ai-response h3:first-child {
  margin-top: 0;
}

.ai-response ul {
  margin: 6px 0 12px;
  padding-left: 20px;
}

.ai-response code {
  background: var(--surface-alt);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 13px;
}

/* Results screen */
.result-banner {
  text-align: center;
  padding: 28px 20px;
  border-radius: 16px;
  margin-bottom: 20px;
}

.result-banner.passed {
  background: var(--success-soft);
  border: 1.5px solid var(--success);
}

.result-banner.failed {
  background: var(--danger-soft);
  border: 1.5px solid var(--danger);
}

.result-score {
  font-size: 42px;
  font-weight: 800;
  margin: 8px 0;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 18, 32, 0.72);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 100;
}

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

.modal-card {
  background: var(--surface);
  border-radius: 16px;
  max-width: 760px;
  width: 100%;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

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

.modal-body {
  padding: 20px;
  text-align: center;
}

.modal-body svg {
  width: 100%;
  max-height: 65vh;
}

/* Loading & Empty */
.loading-screen {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 0 auto 14px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

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

/* Bottom Nav (Mobile) */
.bottom-nav {
  display: none;
}

.mobile-only {
  display: none;
}

@media (max-width: 900px) {
  .sidebar {
    display: none;
  }
  .topbar-mobile-brand {
    display: flex;
  }
  .mobile-only {
    display: grid;
  }
  .topbar {
    padding: 10px 14px;
  }
  .stat-chip:nth-child(2) {
    display: none;
  }
  .main-content {
    padding: 16px 14px 88px;
  }
  .modules-grid {
    grid-template-columns: 1fr;
  }
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 62px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    z-index: 30;
  }
  .bottom-item {
    border: none;
    background: transparent;
    color: var(--text-subtle);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: 18px;
  }
  .bottom-item small {
    font-size: 11px;
    font-weight: 600;
  }
  .bottom-item.active {
    color: var(--primary);
  }
}

/* Compact top stats strip & quick drills (mobile-first) */
.stats-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.stat-mini {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 2px;
}

.stat-mini-btn {
  cursor: pointer;
  transition: border-color 0.15s;
}
.stat-mini-btn:hover {
  border-color: var(--primary);
}

.stat-mini-val {
  font-size: 16px;
  font-weight: 800;
  line-height: 1.15;
  color: var(--text);
}

.stat-mini-val small {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-subtle);
}

.stat-mini-lbl {
  font-size: 11px;
  color: var(--text-subtle);
  line-height: 1.1;
}

.saved-sessions-card {
  padding: 12px 14px;
  margin-bottom: 12px;
  border-color: var(--primary);
}

.saved-session-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
  border-radius: 10px;
  background: var(--surface-alt);
}

.saved-session-info {
  min-width: 0;
  flex: 1;
}

.saved-session-title {
  font-weight: 700;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.saved-session-meta {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

.saved-session-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.quick-drills-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 12px;
  scrollbar-width: none;
}

.quick-drills-strip::-webkit-scrollbar {
  display: none;
}

.quick-pill {
  flex: 0 0 auto;
  padding: 7px 12px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.quick-pill-primary {
  background: var(--primary-soft);
  border-color: transparent;
  color: var(--primary);
}

.quick-pill-ai {
  background: linear-gradient(135deg, #0284c7, #7c3aed);
  border-color: transparent;
  color: #fff;
}

.brand-logo-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
  display: block;
}

/* Telegram Mini App enhancements */
.tg-user-chip {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: transparent;
  font-weight: 700;
}

.bottom-icon-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.bottom-badge {
  position: absolute;
  top: -4px;
  right: -12px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 99px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.bottom-badge[hidden] {
  display: none;
}

html.tg-miniapp {
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

html.tg-miniapp .topbar {
  padding-top: calc(10px + var(--tg-safe-top, 0px));
}

html.tg-miniapp .bottom-nav {
  height: auto;
  padding-top: 6px;
  padding-bottom: max(10px, env(safe-area-inset-bottom), var(--tg-safe-bottom, 0px));
}

html.tg-miniapp .main-content {
  padding-bottom: calc(92px + max(10px, env(safe-area-inset-bottom), var(--tg-safe-bottom, 0px)));
}

@media (max-width: 600px) {
  .topbar-stats .stat-chip:not(.tg-user-chip) {
    display: none;
  }
  .filter-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: none;
  }
  .filter-bar::-webkit-scrollbar {
    display: none;
  }
  .filter-chip {
    flex: 0 0 auto;
    white-space: nowrap;
  }
  .hero-banner {
    padding: 18px 16px;
    border-radius: 14px;
  }
  .hero-banner h1 {
    font-size: 19px;
  }
  .question-card {
    padding: 16px;
  }
  .question-text {
    font-size: 16px;
  }
  .option-btn {
    padding: 12px 13px;
    font-size: 14px;
  }
  .topic-select {
    max-width: none;
    flex: 1 1 180px;
    min-width: 0;
  }
  .quiz-header .quiz-meta:last-child {
    width: 100%;
    flex-wrap: nowrap;
  }
  .quiz-nav-compact {
    padding: 8px 10px;
  }
}
