:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafd;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-soft: #eff6ff;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --purple: #7c3aed;
  --purple-soft: #f5f3ff;
  --shadow: 0 2px 8px rgba(15, 23, 42, 0.05);
  --radius: 12px;
}

[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #131c2e;
  --surface-2: #19243a;
  --border: #253451;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-soft: rgba(59, 130, 246, 0.16);
  --primary-hover: #60a5fa;
  --success: #22c55e;
  --success-soft: rgba(34, 197, 94, 0.15);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, 0.16);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.16);
  --purple: #a78bfa;
  --purple-soft: rgba(167, 139, 250, 0.16);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  font-size: 15px;
}

/* Font-Size 3-Tier Accessibility Scaling */
html[data-fontsize="large"] body {
  font-size: 16.5px;
}
html[data-fontsize="large"] .mcq-stem {
  font-size: 18px;
}
html[data-fontsize="large"] .mcq-opt {
  font-size: 16.5px;
}
html[data-fontsize="large"] .md-body {
  font-size: 17px;
}
html[data-fontsize="large"] textarea.editor-area {
  font-size: 16.5px;
}

html[data-fontsize="xlarge"] body {
  font-size: 18px;
}
html[data-fontsize="xlarge"] .mcq-stem {
  font-size: 20px;
}
html[data-fontsize="xlarge"] .mcq-opt {
  font-size: 18px;
  padding: 15px 16px;
}
html[data-fontsize="xlarge"] .md-body {
  font-size: 18.5px;
}
html[data-fontsize="xlarge"] textarea.editor-area {
  font-size: 18px;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

.brand-badge {
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  padding: 5px 10px;
  border-radius: 8px;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.brand-titles h1 {
  margin: 0;
  font-size: 17px;
  line-height: 1.25;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.global-search {
  flex: 1;
  max-width: 480px;
  min-width: 220px;
  display: flex;
  gap: 8px;
}

.global-search input {
  flex: 1;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13.5px;
  outline: none;
}

.global-search input:focus {
  border-color: var(--primary);
}

.global-search button {
  padding: 8px 15px;
  border-radius: 8px;
  border: none;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

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

.btn-drawer-trigger {
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid rgba(37, 99, 235, 0.35);
  padding: 5px 11px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 12.5px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.btn-drawer-trigger:hover {
  background: var(--primary);
  color: #fff;
}

.btn-drawer-trigger kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.countdown-pill {
  background: var(--warning-soft);
  color: var(--warning);
  font-weight: 700;
  font-size: 12.5px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid rgba(217, 119, 6, 0.25);
  white-space: nowrap;
}

/* Navigation Tabs */
.nav-tabs {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.nav-tabs::-webkit-scrollbar {
  display: none;
}

.nav-tab {
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 12px 13px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}

.nav-tab:hover {
  color: var(--text);
}

.nav-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Layout */
.container {
  max-width: 1420px;
  margin: 0 auto;
  padding: 20px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  gap: 18px;
  margin-bottom: 20px;
}

.split-layout {
  display: grid;
  grid-template-columns: 290px 1fr;
  gap: 18px;
  align-items: start;
}

@media (max-width: 960px) {
  .grid-2,
  .split-layout {
    grid-template-columns: 1fr;
  }
}

/* Cards & Buttons */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.card-clickable {
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}

.card-clickable:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
}

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

.card-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.stat-big {
  font-size: 28px;
  font-weight: 800;
  line-height: 1.2;
  margin: 6px 0;
}

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

.progress-bar {
  height: 7px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 10px;
  border: 1px solid var(--border);
}

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

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

.badge-blue { background: var(--primary-soft); color: var(--primary); }
.badge-green { background: var(--success-soft); color: var(--success); }
.badge-amber { background: var(--warning-soft); color: var(--warning); }
.badge-red { background: var(--danger-soft); color: var(--danger); }
.badge-purple { background: var(--purple-soft); color: var(--purple); }

button, .btn {
  font-family: inherit;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 8px 15px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
}

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

.btn-ghost {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 13px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

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

.btn-ghost.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12.5px;
}

.btn-success {
  background: var(--success);
  color: #fff;
  border: none;
  padding: 7px 13px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.btn-warning {
  background: var(--warning);
  color: #fff;
  border: none;
  padding: 7px 13px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

/* Dashboard 24-Chapter Mastery Heatmap */
.heatmap-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 10px;
}

.heat-cell {
  border-radius: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  transition: transform 0.14s, border-color 0.14s, box-shadow 0.14s;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 6px;
}

.heat-cell:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: var(--shadow);
}

.heat-cell.heat-none {
  background: var(--surface-2);
  border-color: var(--border);
}

.heat-cell.heat-low {
  background: var(--danger-soft);
  border-color: rgba(220, 38, 38, 0.35);
}

.heat-cell.heat-mid {
  background: var(--warning-soft);
  border-color: rgba(217, 119, 6, 0.38);
}

.heat-cell.heat-high {
  background: var(--success-soft);
  border-color: rgba(22, 163, 74, 0.38);
}

.heat-ch-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 600;
}

.heat-ch-title {
  font-weight: 700;
  font-size: 13.5px;
  line-height: 1.3;
}

.heat-ch-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-muted);
}

/* 49-Process 10x5 ITTO Matrix & 8 Performance Domains */
.itto-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.32fr) minmax(350px, 0.92fr);
  gap: 16px;
  align-items: start;
}

@media (max-width: 1180px) {
  .itto-workspace {
    grid-template-columns: 1fr;
  }
}

.itto-grid-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.itto-matrix-table {
  width: 100%;
  min-width: 740px;
  border-collapse: collapse;
  font-size: 13px;
}

.itto-matrix-table th,
.itto-matrix-table td {
  border: 1px solid var(--border);
  padding: 7px 8px;
  vertical-align: top;
}

.itto-matrix-table thead th {
  background: var(--surface-2);
  font-weight: 700;
  text-align: center;
  font-size: 13px;
  white-space: nowrap;
}

.itto-ka-cell {
  background: var(--surface-2);
  font-weight: 700;
  width: 116px;
  min-width: 116px;
  font-size: 12.5px;
  color: var(--text);
  position: sticky;
  left: 0;
  z-index: 2;
}

.proc-cell-stack {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.proc-pill {
  width: 100%;
  text-align: left;
  padding: 6px 8px;
  border-radius: 7px;
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.35;
  cursor: pointer;
  transition: all 0.14s;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.proc-pill:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.proc-pill.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.proc-pill.flow-out {
  border-color: var(--warning);
  background: var(--warning-soft);
}

.proc-pill.flow-in {
  border-color: var(--success);
  background: var(--success-soft);
}

.proc-pill.flow-both {
  border-color: var(--purple);
  background: var(--purple-soft);
}

.proc-pill.flow-tool {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.proc-pill.dimmed {
  opacity: 0.3;
}

.proc-flow-tag {
  font-size: 10.5px;
  font-weight: 700;
  display: inline-block;
}

.itto-inspector {
  position: sticky;
  top: 110px;
  max-height: calc(100vh - 130px);
  overflow-y: auto;
}

@media (max-width: 1180px) {
  .itto-inspector {
    position: static;
    max-height: none;
  }
}

.itto-three-cols {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

@media (max-width: 640px) {
  .itto-three-cols {
    grid-template-columns: 1fr;
  }
}

.itto-col-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 11px;
}

.itto-col-title {
  font-weight: 700;
  font-size: 12.5px;
  margin-bottom: 6px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--border);
}

.itto-line-item {
  font-size: 12.5px;
  line-height: 1.55;
  padding: 2px 4px;
  border-radius: 5px;
  cursor: pointer;
}

.itto-line-item:hover {
  background: var(--primary-soft);
  color: var(--primary);
}

.itto-line-item.sub-bullet {
  padding-left: 12px;
  color: var(--text-muted);
  font-size: 12px;
}

.itto-line-item.matched {
  background: #fde047;
  color: #111827;
  font-weight: 700;
}

.domain-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 16px;
}

/* Task Checklist */
.task-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.task-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 13px;
  border-radius: 9px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.task-item.done .task-text {
  text-decoration: line-through;
  color: var(--text-muted);
}

.task-label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  flex: 1;
}

.task-label input[type="checkbox"] {
  margin-top: 4px;
  width: 17px;
  height: 17px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* 14-day Bar Chart */
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 110px;
  padding-top: 16px;
  margin-top: 8px;
}

.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  height: 100%;
  justify-content: flex-end;
}

.bar-fill {
  width: 100%;
  max-width: 26px;
  background: var(--primary);
  border-radius: 5px 5px 2px 2px;
  min-height: 3px;
  transition: height 0.25s;
}

.bar-lbl {
  font-size: 10.5px;
  color: var(--text-muted);
}

/* Pomodoro Box */
.pomo-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 15px;
  border-radius: 10px;
  background: var(--primary-soft);
  border: 1px solid rgba(37, 99, 235, 0.25);
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.pomo-clock {
  font-size: 26px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--primary);
}

/* Sidebar List */
.sidebar-panel {
  max-height: calc(100vh - 150px);
  overflow-y: auto;
  position: sticky;
  top: 115px;
}

@media (max-width: 960px) {
  .sidebar-panel {
    position: static;
    max-height: 290px;
  }
}

.side-item {
  padding: 9px 11px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13.5px;
  margin-bottom: 4px;
  border: 1px solid transparent;
}

.side-item:hover {
  background: var(--surface-2);
}

.side-item.active {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: rgba(37, 99, 235, 0.3);
  font-weight: 600;
}

/* MCQ Options & Closed-Book Exam Styles */
.mcq-stem {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  line-height: 1.75;
}

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

.mcq-opt {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 15px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  text-align: left;
  font-size: 15px;
  color: var(--text);
  transition: border-color 0.12s, background 0.12s;
}

.mcq-opt:hover {
  border-color: var(--primary);
}

.mcq-opt .opt-key {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.mcq-opt.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
}

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

.mcq-opt.correct {
  border-color: var(--success);
  background: var(--success-soft);
}

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

.mcq-opt.wrong {
  border-color: var(--danger);
  background: var(--danger-soft);
}

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

.mcq-expl {
  margin-top: 18px;
  padding: 15px 18px;
  border-radius: 10px;
  background: var(--surface-2);
  border-left: 4px solid var(--primary);
}

.exam-report-card {
  margin-bottom: 16px;
  padding: 16px 18px;
  border-radius: 11px;
  border: 1.5px solid var(--primary);
  background: var(--surface);
}

.note-box {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px dashed var(--border);
}

.note-box textarea {
  width: 100%;
  min-height: 74px;
  padding: 8px 10px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.6;
  resize: vertical;
}

/* Case Flashcard Blur */
.blur-answer {
  filter: blur(7px);
  user-select: none;
  cursor: pointer;
  transition: filter 0.2s;
}

.blur-answer.revealed {
  filter: none;
  user-select: text;
  cursor: auto;
}

.mnemonic-box {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--warning-soft);
  border: 1px dashed rgba(217, 119, 6, 0.45);
  font-size: 14px;
}

/* Markdown & OCR Rendered Content */
.md-body {
  line-height: 1.8;
  font-size: 15.5px;
  overflow-x: auto;
}

.md-body h1, .md-body h2, .md-body h3 {
  margin-top: 1.3em;
  margin-bottom: 0.55em;
  line-height: 1.35;
}

.md-body h1 { font-size: 1.32em; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.md-body h2 { font-size: 1.18em; }
.md-body h3 { font-size: 1.06em; }

.md-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  font-size: 14px;
}

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

.md-body th, .md-body tr:first-child td {
  background: var(--surface-2);
  font-weight: 600;
}

.md-body img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin: 10px 0;
  cursor: zoom-in;
  background: #fff;
  padding: 4px;
}

.md-body mark, mark {
  background: #fde047;
  color: #111827;
  padding: 1px 4px;
  border-radius: 3px;
}

/* Essay & Calc Split-Screen Workbench */
.workbench-split {
  display: grid;
  grid-template-columns: minmax(0, 1.18fr) minmax(320px, 0.82fr);
  gap: 16px;
  align-items: start;
}

@media (max-width: 1080px) {
  .workbench-split {
    grid-template-columns: 1fr;
  }
}

.ref-pane {
  position: sticky;
  top: 112px;
  max-height: calc(100vh - 132px);
  overflow-y: auto;
}

@media (max-width: 1080px) {
  .ref-pane {
    position: static;
    max-height: 520px;
  }
}

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

.form-field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.form-field input, .form-field select, .form-field textarea, textarea.editor-area {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
}

textarea.editor-area {
  min-height: 460px;
  line-height: 1.8;
  font-size: 15px;
  resize: vertical;
}

.toolbar-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0;
}

/* Ctrl+K Slide-Over Quick Lookup Drawer */
.drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 140;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}

.drawer-backdrop.open {
  display: block;
}

.quick-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(590px, 95vw);
  z-index: 150;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 30px rgba(0, 0, 0, 0.22);
  display: flex;
  flex-direction: column;
  transform: translateX(103%);
  transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.quick-drawer.open {
  transform: translateX(0);
}

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

.drawer-tabs {
  padding: 9px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
}

.formula-card {
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  margin-bottom: 12px;
  font-size: 13.5px;
}

.formula-card h4 {
  margin: 0 0 8px 0;
  font-size: 14.5px;
  color: var(--primary);
}

/* Mobile Commute Single-Hand Thumb Bar */
.mobile-thumb-bar {
  display: none;
}

@media (max-width: 768px) {
  .topbar {
    padding: 10px 14px;
    gap: 10px;
  }
  .container {
    padding: 14px 12px;
  }
  body.has-thumb-bar .container {
    padding-bottom: 84px;
  }
  .mobile-thumb-bar.visible {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 95;
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.12);
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    gap: 8px;
    justify-content: space-between;
    align-items: center;
  }
  .mobile-thumb-bar button {
    flex: 1;
    padding: 10px 6px;
    border-radius: 9px;
    font-size: 13px;
    font-weight: 700;
    justify-content: center;
    white-space: nowrap;
  }
  body.has-thumb-bar .toast {
    bottom: 78px;
  }
}

/* Modal & Toast */
.img-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.82);
  align-items: center;
  justify-content: center;
  padding: 24px;
  cursor: zoom-out;
}

.img-modal.open {
  display: flex;
}

.img-modal img {
  max-width: 95vw;
  max-height: 92vh;
  background: #fff;
  padding: 8px;
  border-radius: 8px;
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 300;
  background: #1e293b;
  color: #fff;
  padding: 10px 18px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}
