:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-subtle: #f1f5f9;
  --surface-hover: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --primary: #0d9488;
  --primary-hover: #0f766e;
  --primary-soft: #f0fdfa;
  --primary-ring: rgba(13, 148, 136, 0.18);

  --accent: #2563eb;
  --accent-soft: #eff6ff;

  --success: #059669;
  --success-soft: #ecfdf5;
  --success-border: #a7f3d0;

  --danger: #e11d48;
  --danger-soft: #fff1f2;
  --danger-border: #fecdd3;

  --warn: #d97706;
  --warn-soft: #fffbeb;
  --warn-border: #fde68a;

  --code-bg: #111827;
  --code-header: #1f2937;
  --code-text: #e5e7eb;
  --code-highlight: rgba(251, 191, 36, 0.16);
  --code-highlight-border: #f59e0b;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 6px 24px -4px rgba(15, 23, 42, 0.06), 0 2px 6px rgba(15, 23, 42, 0.03);
  --radius: 14px;
  --radius-sm: 10px;
}

[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111827;
  --surface-subtle: #1e293b;
  --surface-hover: #1a2436;
  --border: #1f2937;
  --border-strong: #334155;
  --text: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;

  --primary: #14b8a6;
  --primary-hover: #2dd4bf;
  --primary-soft: rgba(20, 184, 166, 0.14);
  --primary-ring: rgba(20, 184, 166, 0.28);

  --accent: #60a5fa;
  --accent-soft: rgba(96, 165, 250, 0.14);

  --success: #34d399;
  --success-soft: rgba(16, 185, 129, 0.14);
  --success-border: rgba(52, 211, 153, 0.35);

  --danger: #fb7185;
  --danger-soft: rgba(244, 63, 94, 0.14);
  --danger-border: rgba(251, 113, 133, 0.35);

  --warn: #fbbf24;
  --warn-soft: rgba(245, 158, 11, 0.14);
  --warn-border: rgba(251, 191, 36, 0.35);

  --code-bg: #060a14;
  --code-header: #0f172a;
  --code-text: #e2e8f0;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 10px 30px -6px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select {
  font-family: inherit;
  color: inherit;
}

.hidden {
  display: none !important;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, #0d9488, #0284c7);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(13, 148, 136, 0.24);
}

.brand-text h1 {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.brand-text p {
  font-size: 12px;
  color: var(--text-muted);
  margin: 1px 0 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mode-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface-subtle);
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.mode-pill {
  border: none;
  background: transparent;
  padding: 6px 13px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.16s ease;
  white-space: nowrap;
}

.mode-pill:hover {
  color: var(--text);
}

.mode-pill.active {
  background: var(--surface);
  color: var(--primary);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.pill-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  line-height: 1.4;
}

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

.pill-badge.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

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

.action-btn, .icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.action-btn {
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 500;
}

.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
}

.action-btn:hover, .icon-btn:hover {
  border-color: var(--border-strong);
  color: var(--text);
  background: var(--surface-hover);
}

.mobile-menu-btn {
  display: none;
}

/* Workspace Grid */
.workspace {
  max-width: 1360px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

/* Sidebar */
.sidebar {
  position: sticky;
  top: 76px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
  padding-right: 2px;
}

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

.progress-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.progress-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.progress-val {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
}

.progress-bar-track {
  height: 7px;
  background: var(--surface-subtle);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 14px;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #0d9488, #38bdf8);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.progress-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  text-align: center;
}

.metric {
  background: var(--surface-subtle);
  border-radius: 9px;
  padding: 7px 4px;
}

.metric-num {
  display: block;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.metric-num.danger-text {
  color: var(--danger);
}

.metric-lbl {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

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

.section-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 2px 8px 8px;
  letter-spacing: 0.03em;
}

.chapter-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chapter-item {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 10px;
  padding: 9px 10px;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: all 0.14s ease;
}

.chapter-item:hover {
  background: var(--surface-subtle);
}

.chapter-item.active {
  background: var(--primary-soft);
  border-color: color-mix(in srgb, var(--primary) 30%, transparent);
}

.chapter-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.chapter-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chapter-item.active .chapter-name {
  color: var(--primary);
}

.chapter-stat {
  font-size: 11.5px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.chapter-mini-bar {
  height: 3px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}

.chapter-mini-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 99px;
  transition: width 0.25s ease;
}

.sidebar-footer {
  padding: 2px 6px;
}

.home-back-link {
  font-size: 12.5px;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
}

.home-back-link:hover {
  color: var(--primary);
}

.sidebar-backdrop {
  display: none;
}

/* Main Stage */
.main-stage {
  min-width: 0;
}

.filter-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow-sm);
}

.type-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.type-tab {
  border: 1px solid transparent;
  background: var(--surface-subtle);
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.type-tab:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.type-tab.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.tab-cnt {
  font-size: 11.5px;
  opacity: 0.82;
  background: rgba(15, 23, 42, 0.08);
  padding: 0 6px;
  border-radius: 999px;
}

.type-tab.active .tab-cnt {
  background: rgba(255, 255, 255, 0.22);
  opacity: 1;
}

.filter-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 0 10px;
  height: 34px;
  width: 220px;
  color: var(--text-muted);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
  background: var(--surface);
}

.search-box input {
  border: none;
  background: transparent;
  outline: none;
  width: 100%;
  font-size: 13px;
  color: var(--text);
}

.toggle-chip, .chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 34px;
  padding: 0 11px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 12.5px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
}

.toggle-chip:hover, .chip-btn:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.chip-btn.active {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: color-mix(in srgb, var(--primary) 35%, transparent);
}

.context-banner {
  background: var(--warn-soft);
  border: 1px solid var(--warn-border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13.5px;
}

/* Question Card */
.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px 28px;
  box-shadow: var(--shadow-md);
  min-height: 360px;
}

.q-meta-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.q-badges {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-type-choice { background: #eff6ff; color: #1d4ed8; }
.badge-type-judge { background: #f0fdf4; color: #15803d; }
.badge-type-short { background: #fef3c7; color: #b45309; }
.badge-type-code { background: #f3e8ff; color: #7e22ce; }

[data-theme="dark"] .badge-type-choice { background: rgba(59, 130, 246, 0.18); color: #93c5fd; }
[data-theme="dark"] .badge-type-judge { background: rgba(34, 197, 94, 0.18); color: #86efac; }
[data-theme="dark"] .badge-type-short { background: rgba(245, 158, 11, 0.18); color: #fcd34d; }
[data-theme="dark"] .badge-type-code { background: rgba(168, 85, 247, 0.18); color: #d8b4fe; }

.badge-chapter {
  background: var(--surface-subtle);
  color: var(--text-secondary);
  font-weight: 500;
}

.badge-num {
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 500;
}

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

.mini-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  padding: 5px 11px;
  border-radius: 8px;
  font-size: 12.5px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s;
}

.mini-btn:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.mini-btn.fav-active {
  background: var(--warn-soft);
  border-color: var(--warn-border);
  color: var(--warn);
  font-weight: 600;
}

.mini-btn.danger:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.q-stem {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.7;
  color: var(--text);
  margin: 0 0 20px;
  white-space: pre-wrap;
  word-break: break-word;
}

.q-subprompt {
  font-size: 14.5px;
  color: var(--text-secondary);
  background: var(--surface-subtle);
  border-left: 3px solid var(--primary);
  padding: 12px 15px;
  border-radius: 0 10px 10px 0;
  margin: -6px 0 18px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Images */
.media-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 14px 0 20px;
}

.diagram-figure {
  margin: 0;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  max-width: 100%;
  cursor: zoom-in;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.diagram-figure:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.diagram-figure img {
  display: block;
  max-width: 100%;
  max-height: 340px;
  width: auto;
  height: auto;
  border-radius: 8px;
  background: #fff;
}

.diagram-caption {
  font-size: 11.5px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 6px;
}

/* MCQ Options */
.options-list {
  display: flex;
  flex-direction: column;
  gap: 11px;
}

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

.option-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--primary-soft);
  transform: translateY(-1px);
}

.option-btn:disabled {
  cursor: default;
}

.opt-key {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--surface-subtle);
  color: var(--text-secondary);
  font-weight: 700;
  font-size: 13.5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
  transition: all 0.16s ease;
}

.option-btn:hover:not(:disabled) .opt-key {
  background: var(--primary);
  color: #fff;
}

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

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

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

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

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

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

.opt-text {
  flex: 1;
  word-break: break-word;
}

.opt-status {
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
}

.option-btn.correct .opt-status { color: var(--success); }
.option-btn.wrong .opt-status { color: var(--danger); }

/* Judge Buttons */
.judge-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.judge-btn {
  border: 1.5px solid var(--border);
  background: var(--surface);
  border-radius: 14px;
  padding: 20px 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 16.5px;
  font-weight: 600;
  transition: all 0.16s ease;
}

.judge-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--primary-soft);
  transform: translateY(-1px);
}

.judge-btn:disabled {
  cursor: default;
}

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

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

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

/* Explanation Box */
.explanation-box {
  margin-top: 22px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  overflow: hidden;
  animation: fadeSlide 0.2s ease;
}

@keyframes fadeSlide {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.verdict-bar {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  font-weight: 600;
  font-size: 14.5px;
}

.verdict-bar.ok {
  background: var(--success-soft);
  color: var(--success);
  border-bottom: 1px solid var(--success-border);
}

.verdict-bar.err {
  background: var(--danger-soft);
  color: var(--danger);
  border-bottom: 1px solid var(--danger-border);
}

.verdict-bar.info {
  background: var(--primary-soft);
  color: var(--primary);
  border-bottom: 1px solid color-mix(in srgb, var(--primary) 25%, transparent);
}

.verdict-actions {
  display: flex;
  gap: 8px;
}

.exp-body {
  padding: 16px 18px;
  font-size: 14.5px;
  line-height: 1.78;
  color: var(--text);
}

.exp-title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.exp-para {
  margin: 0 0 8px;
  word-break: break-word;
}

.exp-para:last-child {
  margin-bottom: 0;
}

.exp-opt-tag {
  display: inline-block;
  font-weight: 700;
  color: var(--primary);
  margin-right: 4px;
}

/* Subjective / Coding Scratchpad & Reveal */
.scratchpad-wrap {
  margin-bottom: 16px;
}

.scratchpad-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.scratchpad-input {
  width: 100%;
  min-height: 92px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-subtle);
  font-size: 14px;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

.scratchpad-input.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  min-height: 110px;
}

.scratchpad-input:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.reveal-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-primary {
  border: none;
  background: var(--primary);
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, transform 0.12s;
}

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

.btn-outline {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  padding: 9px 15px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-outline.danger {
  color: var(--danger);
  border-color: var(--danger-border);
}

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

.self-eval-bar {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px dashed var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.self-eval-label {
  font-size: 13px;
  color: var(--text-muted);
}

.eval-btns {
  display: flex;
  gap: 8px;
}

.eval-btn {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  padding: 7px 14px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.eval-btn.master.active, .eval-btn.master:hover {
  background: var(--success-soft);
  border-color: var(--success);
  color: var(--success);
}

.eval-btn.review.active, .eval-btn.review:hover {
  background: var(--warn-soft);
  border-color: var(--warn);
  color: var(--warn);
}

/* Code Block */
.code-block-wrap {
  margin: 12px 0;
  border-radius: 11px;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: var(--code-bg);
}

.code-block-header {
  background: var(--code-header);
  color: #94a3b8;
  padding: 7px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
}

.copy-code-btn {
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: transparent;
  color: #e2e8f0;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 11.5px;
  cursor: pointer;
  transition: all 0.15s;
}

.copy-code-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.code-pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.65;
  color: var(--code-text);
  tab-size: 4;
}

.code-line {
  display: block;
  min-height: 1.65em;
  padding: 0 6px;
  border-radius: 4px;
}

.code-line.key-line {
  background: var(--code-highlight);
  border-left: 3px solid var(--code-highlight-border);
  padding-left: 8px;
}

/* Embedded Table */
.rich-table-wrap {
  overflow-x: auto;
  margin: 12px 0;
}

.rich-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  background: var(--surface);
  border-radius: 8px;
  overflow: hidden;
}

.rich-table th, .rich-table td {
  border: 1px solid var(--border);
  padding: 8px 11px;
  text-align: left;
  vertical-align: top;
}

.rich-table th {
  background: var(--surface-subtle);
  font-weight: 600;
}

/* Bottom Nav */
.bottom-nav {
  margin-top: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.nav-btn {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 11px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.nav-btn:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
}

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

.nav-btn.primary:hover:not(:disabled) {
  background: var(--primary-hover);
  color: #fff;
}

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

.nav-center {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
}

.nav-counter {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-secondary);
}

.auto-next-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  color: var(--text-muted);
  cursor: pointer;
}

.shortcut-hint {
  margin-top: 12px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}

.shortcut-hint code {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 54px 20px;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 38px;
  margin-bottom: 10px;
}

.empty-state h3 {
  margin: 0 0 6px;
  color: var(--text);
  font-size: 17px;
}

.empty-state p {
  margin: 0 0 18px;
  font-size: 14px;
}

/* Sheet Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  z-index: 60;
}

.sheet-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(410px, 92vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 70;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 32px rgba(15, 23, 42, 0.16);
}

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

.drawer-header h3 {
  margin: 0;
  font-size: 16px;
}

.drawer-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.sheet-legend {
  padding: 10px 20px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.sheet-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--surface-subtle);
  border: 1px solid var(--border-strong);
  display: inline-block;
}

.dot.ok { background: var(--success); border-color: var(--success); }
.dot.err { background: var(--danger); border-color: var(--danger); }
.dot.fav { background: var(--warn); border-color: var(--warn); }

.sheet-grid {
  padding: 16px 20px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 8px;
}

.sheet-cell {
  height: 38px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  position: relative;
  transition: all 0.12s;
}

.sheet-cell:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.sheet-cell.current {
  box-shadow: 0 0 0 2.5px var(--primary);
  border-color: var(--primary);
}

.sheet-cell.ok {
  background: var(--success-soft);
  border-color: var(--success-border);
  color: var(--success);
}

.sheet-cell.err {
  background: var(--danger-soft);
  border-color: var(--danger-border);
  color: var(--danger);
}

.sheet-cell.fav::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--warn);
}

/* Mock Exam */
.exam-setup-card, .exam-result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow-md);
}

.exam-setup-card h2, .exam-result-card h2 {
  margin: 0 0 6px;
  font-size: 21px;
}

.exam-setup-desc {
  color: var(--text-muted);
  margin: 0 0 22px;
  font-size: 14px;
}

.exam-presets {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.preset-card {
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  background: var(--surface);
  text-align: left;
  transition: all 0.15s;
}

.preset-card:hover {
  border-color: var(--primary);
}

.preset-card.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.preset-card h4 {
  margin: 0 0 5px;
  font-size: 15px;
}

.preset-card p {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

.exam-scope-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.exam-scope-row select {
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-size: 14px;
}

.exam-header-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 18px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  box-shadow: var(--shadow-sm);
}

.exam-timer {
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 5px 12px;
  border-radius: 9px;
}

.exam-score-hero {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 18px 20px;
  background: var(--surface-subtle);
  border-radius: 12px;
  margin: 16px 0 20px;
  flex-wrap: wrap;
}

.score-big {
  font-size: 40px;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
}

.score-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.exam-review-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 20px;
}

.exam-review-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  background: var(--surface);
}

.exam-review-item.is-wrong {
  border-color: var(--danger-border);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  width: min(560px, 100%);
  max-height: 86vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25);
}

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

.modal-header h3 {
  margin: 0;
  font-size: 16.5px;
}

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.stats-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}

.stats-row:last-child {
  border-bottom: none;
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(2, 6, 23, 0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  cursor: zoom-out;
}

.lightbox img {
  max-width: 94vw;
  max-height: 84vh;
  border-radius: 10px;
  background: #fff;
  padding: 6px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.lightbox-close {
  position: fixed;
  top: 18px;
  right: 22px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}

.lightbox-hint {
  color: rgba(255, 255, 255, 0.65);
  font-size: 12.5px;
  margin-top: 12px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 500;
  z-index: 120;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.25);
}

/* Responsive */
@media (max-width: 980px) {
  .topbar-inner {
    flex-wrap: wrap;
    padding: 10px 14px;
  }
  .mode-nav {
    order: 3;
    width: 100%;
    overflow-x: auto;
  }
  .mobile-menu-btn {
    display: inline-flex;
  }
  .workspace {
    grid-template-columns: 1fr;
    padding: 14px;
  }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 290px;
    max-height: 100vh;
    background: var(--bg);
    padding: 16px;
    z-index: 65;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-backdrop.open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 60;
  }
  .question-card {
    padding: 18px;
  }
  .q-stem {
    font-size: 16.5px;
  }
  .search-box {
    width: 100%;
  }
  .shortcut-hint {
    display: none;
  }
}
