:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --green: #059669;
  --green-soft: #ecfdf5;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --purple: #7c3aed;
  --purple-soft: #f5f3ff;
  --shadow: 0 1px 3px rgba(15,23,42,.06), 0 4px 12px rgba(15,23,42,.04);
  --shadow-lg: 0 10px 30px rgba(15,23,42,.12);
  --radius: 14px;
  --radius-sm: 9px;
  --fs-stem: 16px;
  --fs-opt: 15px;
  --fs-exp: 14.5px;
  --fs-mat: 14.5px;
  --bottom-nav-h: 58px;
  --mobile-bar-h: 52px;
}
[data-font="lg"] {
  --fs-stem: 18px;
  --fs-opt: 16.5px;
  --fs-exp: 16px;
  --fs-mat: 16px;
}
[data-font="xl"] {
  --fs-stem: 20px;
  --fs-opt: 18px;
  --fs-exp: 17.5px;
  --fs-mat: 17px;
}
[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #131c31;
  --surface-2: #1a2540;
  --border: #263554;
  --text: #f1f5f9;
  --text-2: #cbd5e1;
  --text-3: #64748b;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-soft: rgba(59,130,246,.16);
  --green: #10b981;
  --green-soft: rgba(16,185,129,.15);
  --red: #ef4444;
  --red-soft: rgba(239,68,68,.16);
  --amber: #f59e0b;
  --amber-soft: rgba(245,158,11,.15);
  --purple: #a78bfa;
  --purple-soft: rgba(167,139,250,.15);
  --shadow: 0 2px 8px rgba(0,0,0,.35);
  --shadow-lg: 0 12px 32px rgba(0,0,0,.55);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  line-height: 1.65; min-height: 100vh;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font-family: inherit; }
a { color: var(--primary); text-decoration: none; }

/* Loading Screen */
.app-loading {
  max-width: 420px; margin: 18vh auto 0; padding: 28px 22px; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.spinner {
  width: 36px; height: 36px; margin: 0 auto 14px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Top Header */
.topbar {
  position: sticky; top: 0; z-index: 100;
  background: var(--surface); border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(15,23,42,.04);
}
.topbar-inner {
  max-width: 1180px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 54px;
}
.brand {
  display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 15px;
  color: var(--text); cursor: pointer; white-space: nowrap; flex-shrink: 0;
}
.brand-badge {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 14px;
}
.nav-tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; padding: 4px 0; }
.nav-tabs::-webkit-scrollbar { display: none; }
.nav-tab {
  border: none; background: transparent; color: var(--text-2);
  padding: 7px 14px; border-radius: 8px; font-size: 14px; font-weight: 600;
  cursor: pointer; white-space: nowrap; transition: all .15s;
}
.nav-tab:hover { background: var(--surface-2); color: var(--text); }
.nav-tab.active { background: var(--primary-soft); color: var(--primary); }
.top-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.icon-btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2);
  border-radius: 8px; padding: 5px 10px; font-size: 13px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px; transition: all .15s;
  min-height: 34px;
}
.icon-btn:hover { border-color: var(--primary); color: var(--primary); }
.icon-btn:active { transform: scale(.96); }

/* Mobile Bottom Tab Bar (hidden on desktop) */
.bottom-nav { display: none; }
.mobile-action-bar { display: none; }

/* Container */
.container { max-width: 1180px; margin: 0 auto; padding: 18px 16px 64px; }
.hidden { display: none !important; }

/* Segmented Control */
.seg-group {
  display: inline-flex; align-items: center; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 9px; padding: 2px; gap: 2px;
}
.seg-btn {
  border: none; background: transparent; color: var(--text-2);
  padding: 5px 11px; border-radius: 7px; font-size: 13px; font-weight: 600;
  cursor: pointer; white-space: nowrap; transition: all .15s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--surface); color: var(--primary); box-shadow: 0 1px 3px rgba(15,23,42,.1); }
.seg-btn.active-green { background: var(--green); color: #fff; box-shadow: 0 1px 3px rgba(5,150,105,.25); }
.seg-btn.active-bj { background: var(--surface); color: #b91c1c; box-shadow: 0 1px 3px rgba(15,23,42,.1); }
[data-theme="dark"] .seg-btn.active-bj { color: #fca5a5; }

/* Cards & Grids */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
  min-width: 0;
}
.hero {
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 60%, #4f46e5 100%);
  color: #fff; border: none; padding: 22px 24px; position: relative; overflow: hidden;
  margin-bottom: 18px;
}
.hero::after {
  content: ""; position: absolute; right: -40px; top: -40px; width: 220px; height: 220px;
  border-radius: 50%; background: rgba(255,255,255,.07); pointer-events: none;
}
.badge-bj { background: rgba(185,28,28,.12); color: #b91c1c; border: 1px solid rgba(185,28,28,.22); }
[data-theme="dark"] .badge-bj { background: rgba(248,113,113,.16); color: #fca5a5; border-color: rgba(248,113,113,.28); }
.prog-fill.bj { background: linear-gradient(90deg, #b91c1c, #f59e0b); }
.year-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: center; }
.year-pill {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 9px; padding: 6px 12px; font-size: 13px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; transition: all .15s;
}
.year-pill:hover { border-color: #b91c1c; color: #b91c1c; }
.hero h1 { margin: 0 0 6px; font-size: 20px; line-height: 1.3; letter-spacing: -.2px; }
.hero p { margin: 0 0 16px; opacity: .9; font-size: 13.5px; max-width: 720px; }
.hero-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 16px; }
.hero-stat {
  background: rgba(255,255,255,.13); backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,.16); border-radius: 10px; padding: 10px 13px;
}
.hero-stat .val { font-size: 20px; font-weight: 800; line-height: 1.15; }
.hero-stat .lbl { font-size: 12px; opacity: .85; margin-top: 2px; }
.hero-btns { display: flex; flex-wrap: wrap; gap: 10px; }

.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 9px; padding: 8px 15px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  transition: all .15s; white-space: nowrap;
}
@media (hover: hover) {
  .btn:hover { border-color: var(--primary); color: var(--primary); }
  .btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
  .btn-white:hover { background: #eff6ff; color: #1e3a8a; border-color: #eff6ff; }
  .btn-glass:hover { background: rgba(255,255,255,.26); color: #fff; border-color: #fff; }
  .btn-green:hover, .btn-red:hover { filter: brightness(1.06); color: #fff; }
  .btn-ghost:hover { background: var(--surface-2); border-color: transparent; color: var(--primary); }
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-white { background: #fff; border-color: #fff; color: #1e3a8a; }
.btn-glass { background: rgba(255,255,255,.15); border-color: rgba(255,255,255,.32); color: #fff; }
.btn-green { background: var(--green); border-color: var(--green); color: #fff; }
.btn-red { background: var(--red); border-color: var(--red); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-speaking { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.tts-bar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 12px; margin-bottom: 14px; border-radius: 9px;
  background: var(--primary-soft); border: 1px solid rgba(37,99,235,.22); font-size: 12.5px;
}
.tts-status { display: inline-flex; align-items: center; gap: 7px; font-weight: 700; color: var(--primary); }
.tts-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--primary);
  animation: pulse 1.1s infinite;
}

.section-title { font-size: 15.5px; font-weight: 800; margin: 20px 0 12px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.dim-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); gap: 12px; }
.dim-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 15px 17px; cursor: pointer; transition: all .18s; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 9px; min-width: 0;
}
@media (hover: hover) {
  .dim-card:hover { transform: translateY(-2px); border-color: var(--primary); box-shadow: var(--shadow-lg); }
}
.dim-card:active { transform: scale(.99); }
.dim-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.dim-name { font-size: 15.5px; font-weight: 800; display: flex; align-items: center; gap: 7px; }
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px;
  border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge-blue { background: var(--primary-soft); color: var(--primary); }
.badge-purple { background: var(--purple-soft); color: var(--purple); }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-gray { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }

.prog-track { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--border); }
.prog-fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, #2563eb, #6366f1); transition: width .3s; }
.prog-fill.green { background: linear-gradient(90deg, #059669, #34d399); }
.dim-meta { display: flex; justify-content: space-between; gap: 6px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); }

/* Streamlined Toolbar & Filter Bar */
.toolbar {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 14px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 10px;
}
.toolbar-main {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
}
.toolbar-group { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.toolbar-more {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding-top: 10px; border-top: 1px dashed var(--border);
}
.custom-banner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 12px; border-radius: 9px; background: var(--primary-soft); color: var(--primary);
  font-size: 13px; font-weight: 600;
}
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2);
  border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all .15s;
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.input, .select {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 8px; padding: 6px 10px; font-size: 13px; font-weight: 500; outline: none;
}
.input:focus, .select:focus { border-color: var(--primary); background: var(--surface); }
.search-input { flex: 1; min-width: 180px; }
.toggle-pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 6px 11px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2);
  font-size: 13px; font-weight: 600; color: var(--text-2); cursor: pointer; user-select: none;
}
.toggle-pill.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }

/* Question Workspace (Split layout when material exists) */
.q-workspace { display: grid; grid-template-columns: 1fr; gap: 16px; align-items: start; }
.q-workspace > * { min-width: 0; }
.q-workspace.has-mat { grid-template-columns: minmax(320px, 1.05fr) minmax(360px, 1fr); }
@media (max-width: 920px) {
  .q-workspace.has-mat { grid-template-columns: 1fr; }
}
.mat-panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; min-width: 0;
}
@media (min-width: 921px) {
  .mat-panel { position: sticky; top: 70px; max-height: calc(100vh - 90px); display: flex; flex-direction: column; }
  .mat-body { overflow-y: auto; }
}
.mat-panel.collapsed .mat-body { display: none; }
.mat-header {
  padding: 11px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border);
  font-weight: 700; font-size: 13.5px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px;
}
.mat-panel.collapsed .mat-header { border-bottom: none; }
.mat-body { padding: 16px 18px; font-size: var(--fs-mat); line-height: 1.8; color: var(--text); }
.mat-body p { margin: 0 0 10px; }

/* Question Card */
.q-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 22px; min-width: 0;
}
.q-meta {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 8px; padding-bottom: 12px; margin-bottom: 14px; border-bottom: 1px solid var(--border);
}
.q-badges { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.q-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.q-num { font-weight: 800; font-size: 14.5px; color: var(--primary); }
.q-stem { font-size: var(--fs-stem); line-height: 1.82; margin-bottom: 16px; word-break: break-word; }
.q-stem p { margin: 0 0 8px; }
.q-blank {
  display: inline-block; min-width: 4.5em; border-bottom: 1.5px solid currentColor;
  margin: 0 4px; vertical-align: baseline; height: 1em;
}

/* Images inside questions & materials */
.q-img-wrap { margin: 10px 0; text-align: center; }
.q-img {
  max-width: 100%; max-height: 420px; border-radius: 8px;
  border: 1px solid var(--border); background: #ffffff; padding: 6px;
  cursor: zoom-in; display: inline-block; vertical-align: middle;
  transition: transform .15s;
}
@media (hover: hover) {
  .q-img:hover { box-shadow: 0 4px 16px rgba(37,99,235,.22); }
}
.opt-text .q-img { max-height: 120px; margin: 2px 4px; }

/* Markdown tables */
.md-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 12px 0; border-radius: 9px; border: 1px solid var(--border); }
.md-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.md-table th, .md-table td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; }
.md-table th { background: var(--surface-2); font-weight: 700; white-space: nowrap; }
.md-table tr:nth-child(even) td { background: rgba(148,163,184,.05); }

/* Options */
.opt-list { display: flex; flex-direction: column; gap: 9px; margin-bottom: 14px; }
.opt-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 15px; border-radius: 11px; min-height: 48px;
  border: 1.5px solid var(--border); background: var(--surface);
  cursor: pointer; transition: all .15s; user-select: none;
}
@media (hover: hover) {
  .opt-item:hover { border-color: var(--primary); background: var(--primary-soft); }
  .opt-item.readonly:hover { border-color: var(--border); background: var(--surface); }
  .opt-item.readonly.correct:hover { border-color: var(--green); background: var(--green-soft); }
}
.opt-item:not(.readonly):active { transform: scale(.99); }
.opt-item.readonly { cursor: default; }
.opt-item.selected { border-color: var(--primary); background: var(--primary-soft); }
.opt-item.correct { border-color: var(--green); background: var(--green-soft); }
.opt-item.wrong { border-color: var(--red); background: var(--red-soft); }
.opt-item.missed { border-color: var(--green); border-style: dashed; background: var(--green-soft); }
.opt-key {
  flex-shrink: 0; width: 27px; height: 27px; border-radius: 50%;
  border: 1.5px solid var(--border); background: var(--surface-2); color: var(--text-2);
  font-weight: 800; font-size: 13px; display: inline-flex; align-items: center; justify-content: center;
  margin-top: 1px;
}
.opt-item.selected .opt-key { background: var(--primary); border-color: var(--primary); color: #fff; }
.opt-item.correct .opt-key { background: var(--green); border-color: var(--green); color: #fff; }
.opt-item.wrong .opt-key { background: var(--red); border-color: var(--red); color: #fff; }
.opt-item.missed .opt-key { background: var(--green); border-color: var(--green); color: #fff; }
.opt-text { flex: 1; font-size: var(--fs-opt); line-height: 1.65; word-break: break-word; min-width: 0; }
.opt-tag {
  flex-shrink: 0; font-size: 12px; font-weight: 700; color: var(--green);
  background: var(--surface); border: 1px solid rgba(5,150,105,.25);
  border-radius: 999px; padding: 2px 8px; align-self: center;
}

/* Answer & Explanation Panel */
.exp-box {
  margin-top: 14px; padding: 15px 18px; border-radius: 11px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-left: 3.5px solid var(--green);
}
.exp-box.bad { border-left-color: var(--red); }
.exp-banner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 8px; padding-bottom: 9px; margin-bottom: 10px; border-bottom: 1px dashed var(--border);
}
.exp-verdict { font-weight: 800; font-size: 14.5px; display: flex; align-items: center; gap: 7px; }
.exp-verdict.ok { color: var(--green); }
.exp-verdict.bad { color: var(--red); }
.exp-verdict.info { color: var(--green); }
.exp-body { font-size: var(--fs-exp); line-height: 1.82; color: var(--text); word-break: break-word; }
.exp-body p { margin: 0 0 8px; }
.exp-foot { margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--text-2); display: flex; flex-wrap: wrap; gap: 12px; }

/* Notes */
.note-box { margin-top: 10px; }
.note-box textarea {
  width: 100%; min-height: 68px; padding: 9px 11px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 14px; resize: vertical;
}

/* Bottom Action Bar */
.q-nav-bar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 10px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border);
}
.kb-hint { font-size: 12px; color: var(--text-3); margin-top: 8px; text-align: right; }
.swipe-hint { display: none; font-size: 12px; color: var(--text-3); margin-top: 10px; text-align: center; }

/* Exam Header & Sheet */
.exam-bar {
  position: sticky; top: 58px; z-index: 80;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 11px 16px; margin-bottom: 14px; box-shadow: var(--shadow);
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
}
.timer {
  font-variant-numeric: tabular-nums; font-size: 17px; font-weight: 800;
  color: var(--primary); background: var(--primary-soft); padding: 4px 11px; border-radius: 8px;
}
.timer.warn { color: var(--red); background: var(--red-soft); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .65; } }

/* Question Navigator Grid */
.sheet-group-title { font-size: 13px; font-weight: 700; color: var(--text-2); margin: 12px 0 8px; }
.sheet-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 6px; }
.sheet-dot {
  height: 38px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-2); font-size: 13px; font-weight: 700;
  cursor: pointer; display: flex; align-items: center; justify-content: center; position: relative;
}
.sheet-dot:hover { border-color: var(--primary); color: var(--primary); }
.sheet-dot.cur { box-shadow: 0 0 0 2.5px var(--primary); border-color: var(--primary); }
.sheet-dot.ans { background: var(--primary); border-color: var(--primary); color: #fff; }
.sheet-dot.ok { background: var(--green); border-color: var(--green); color: #fff; }
.sheet-dot.bad { background: var(--red); border-color: var(--red); color: #fff; }
.sheet-dot.flag::after {
  content: ""; position: absolute; top: 3px; right: 3px; width: 7px; height: 7px;
  border-radius: 50%; background: var(--amber); border: 1px solid #fff;
}

/* Modal & Lightbox */
.modal-mask {
  position: fixed; inset: 0; z-index: 300; background: rgba(15,23,42,.58);
  backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  max-width: 720px; width: 100%; max-height: 86vh; display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg); overflow: hidden;
}
.modal-head {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; font-weight: 800; font-size: 16px;
}
.modal-body { padding: 16px 18px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.lightbox-mask {
  position: fixed; inset: 0; z-index: 500; background: rgba(0,0,0,.88);
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 18px;
  cursor: zoom-out; overflow: auto;
}
.lightbox-close {
  position: fixed; top: 14px; right: 14px; z-index: 510;
  border: 1px solid rgba(255,255,255,.3); background: rgba(15,23,42,.75); color: #fff;
  border-radius: 999px; padding: 6px 14px; font-size: 13px; font-weight: 700; cursor: pointer;
}
.lightbox-img {
  max-width: 95vw; max-height: 84vh; background: #fff; padding: 8px;
  border-radius: 10px; box-shadow: 0 10px 40px rgba(0,0,0,.6);
}
.lightbox-tip { color: #cbd5e1; font-size: 13px; margin-top: 10px; }

/* Exam Preset Cards */
.preset-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 12px; }
.preset-card {
  background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 9px;
}
.preset-card.featured { border-color: var(--primary); background: linear-gradient(180deg, var(--primary-soft), var(--surface) 45%); }
.preset-card h3 { margin: 0; font-size: 16px; }
.preset-card p { margin: 0; font-size: 13px; color: var(--text-2); flex: 1; }

/* Report Score */
.report-hero {
  display: grid; grid-template-columns: auto 1fr; gap: 22px; align-items: center;
  margin-bottom: 18px;
}
@media (max-width: 640px) { .report-hero { grid-template-columns: 1fr; text-align: center; justify-items: center; } }
.score-circle {
  width: 126px; height: 126px; border-radius: 50%;
  background: conic-gradient(var(--primary) calc(var(--pct) * 1%), var(--border) 0);
  display: flex; align-items: center; justify-content: center;
}
.score-circle-in {
  width: 102px; height: 102px; border-radius: 50%; background: var(--surface);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.score-big { font-size: 30px; font-weight: 900; color: var(--primary); line-height: 1.1; }
.score-sub { font-size: 12px; color: var(--text-2); }
.dim-bar-row { display: grid; grid-template-columns: 110px 1fr 90px; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 13.5px; }

/* Cheat Sheet */
.cheat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 14px; }
.cheat-card h3 { margin: 0 0 10px; font-size: 15.5px; color: var(--primary); border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.cheat-card ul { margin: 0; padding-left: 18px; font-size: 14px; line-height: 1.8; }
.cheat-card li { margin-bottom: 4px; }
.hl { font-weight: 700; color: var(--primary); }
.hl-red { font-weight: 700; color: var(--red); }

/* Empty state */
.empty { text-align: center; padding: 48px 16px; color: var(--text-2); }
.empty .ico { font-size: 40px; margin-bottom: 8px; }

/* History Table */
.hist-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.hist-table th, .hist-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.hist-table th { color: var(--text-2); font-weight: 700; background: var(--surface-2); }

/* Inline Wrong Exp */
.wrong-exp-details { margin-top: 8px; font-size: 13.5px; }
.wrong-exp-details summary { cursor: pointer; color: var(--primary); font-weight: 600; user-select: none; }
.wrong-exp-details[open] .wrong-exp-body {
  margin-top: 8px; padding: 10px 12px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border); line-height: 1.75;
}

/* Resume Study Card & Auto-Restore Banner */
.resume-card {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 18px; margin-bottom: 16px;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
}
.resume-card.exam-resume { border-left-color: var(--amber); }
.resume-info { flex: 1; min-width: 220px; display: flex; flex-direction: column; gap: 5px; }
.resume-head { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; font-size: 14px; font-weight: 700; }
.resume-preview {
  font-size: 13px; color: var(--text-2); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden;
}
.resume-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; flex-shrink: 0; }
.resume-banner {
  background: var(--green-soft); border: 1px solid rgba(5,150,105,.25); color: var(--text);
  border-radius: 10px; padding: 9px 14px; margin-bottom: 12px;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 13px;
}
.resume-banner-text { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-weight: 600; }
.dim-last {
  font-size: 12px; font-weight: 600; color: var(--primary);
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
}

/* ==================== MOBILE OPTIMIZATION (<= 768px) ==================== */
@media (max-width: 768px) {
  .topbar-inner { padding: 0 12px; min-height: 50px; gap: 8px; }
  .nav-tabs { display: none; }
  .brand { font-size: 14.5px; }
  .brand-badge { width: 26px; height: 26px; font-size: 13px; }
  .icon-btn { padding: 5px 8px; font-size: 12.5px; min-height: 34px; }

  .container {
    padding: 12px 10px calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + 22px);
  }
  body.has-mobile-bar .container {
    padding-bottom: calc(var(--bottom-nav-h) + var(--mobile-bar-h) + env(safe-area-inset-bottom) + 28px);
  }

  /* Prevent iOS Safari input auto-zoom */
  .input, .select, .note-box textarea { font-size: 15px; min-height: 38px; }

  /* Fixed Bottom Tab Bar */
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 200;
    background: var(--surface); border-top: 1px solid var(--border);
    box-shadow: 0 -2px 12px rgba(15,23,42,.07);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  }
  .bnav-item {
    border: none; background: transparent; color: var(--text-2);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; padding: 5px 2px; border-radius: 8px; cursor: pointer;
    font-size: 11px; font-weight: 600; min-height: 48px; transition: color .15s;
  }
  .bnav-item .bnav-ico { font-size: 18px; line-height: 1.1; }
  .bnav-item.active { color: var(--primary); }
  .bnav-item:active { background: var(--surface-2); }

  /* Floating/Docked Study Action Bar right above bottom-nav */
  .mobile-action-bar {
    display: flex; align-items: center; justify-content: space-between; gap: 6px;
    position: fixed; left: 0; right: 0;
    bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
    z-index: 190;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 7px 10px;
    box-shadow: 0 -4px 14px rgba(15,23,42,.06);
  }
  .mobile-action-bar.hidden { display: none !important; }
  .mab-btn {
    border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
    border-radius: 9px; padding: 0 10px; height: 38px; font-size: 13px; font-weight: 700;
    display: inline-flex; align-items: center; justify-content: center; gap: 4px;
    cursor: pointer; white-space: nowrap;
  }
  .mab-btn:active { transform: scale(.96); }
  .mab-btn:disabled { opacity: .4; }
  .mab-btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; flex: 1; max-width: 120px; }
  .mab-btn.green { background: var(--green); border-color: var(--green); color: #fff; flex: 1; max-width: 120px; }
  .mab-btn.speaking { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
  .mab-mid { display: flex; align-items: center; gap: 6px; flex: 1; justify-content: center; }

  /* Hero & Resume on Mobile */
  .hero { padding: 16px 15px; margin-bottom: 12px; }
  .hero h1 { font-size: 18px; }
  .hero p { font-size: 12.5px; margin-bottom: 12px; }
  .hero-stats { grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 12px; }
  .hero-stat { padding: 8px 10px; }
  .hero-stat .val { font-size: 18px; }
  .hero-btns { gap: 8px; }
  .hero-btns .btn { flex: 1 1 auto; padding: 9px 12px; font-size: 13px; }

  .resume-card { padding: 12px 14px; margin-bottom: 12px; gap: 10px; }
  .resume-actions { width: 100%; }
  .resume-actions .btn { flex: 1; }
  .resume-banner { padding: 8px 11px; font-size: 12.5px; }

  /* Cards & Question Area */
  .card { padding: 14px; }
  .q-card { padding: 14px 13px; border-radius: 12px; }
  .mat-header { padding: 10px 12px; font-size: 13px; }
  .mat-body { padding: 13px 13px; }
  .q-meta { padding-bottom: 10px; margin-bottom: 12px; }
  .q-actions { width: 100%; justify-content: flex-end; }
  .q-actions .btn-sm { padding: 6px 10px; font-size: 12.5px; }
  .opt-item { padding: 11px 12px; gap: 10px; }
  .opt-key { width: 25px; height: 25px; font-size: 12.5px; }
  .exp-box { padding: 12px 13px; }

  /* Toolbar compact on mobile */
  .toolbar { padding: 9px 10px; margin-bottom: 10px; gap: 8px; }
  .toolbar-main { gap: 7px; }
  .toolbar-group { width: 100%; gap: 6px; }
  .toolbar-group .select { flex: 1; min-width: 0; }
  .toolbar-group .seg-group { flex: 1; }
  .toolbar-group .seg-group .seg-btn { flex: 1; text-align: center; padding: 6px 8px; font-size: 12.5px; }
  .toolbar-more .select { flex: 1 1 46%; min-width: 0; }
  .toolbar-more .search-input { width: 100%; flex: 1 1 100%; min-width: 0; }

  /* Exam bar on mobile */
  .exam-bar { top: 52px; padding: 9px 11px; gap: 7px; margin-bottom: 10px; }
  .timer { font-size: 15px; padding: 3px 9px; }

  /* Bottom hints */
  .kb-hint { display: none; }
  .swipe-hint { display: block; }
  .q-nav-bar { gap: 8px; }
  .q-nav-bar > .btn { flex: 1; }

  /* Grids & Report */
  .dim-grid, .preset-grid, .cheat-grid { grid-template-columns: 1fr; gap: 10px; }
  .dim-card { padding: 13px 14px; }
  .section-title { margin: 16px 0 10px; font-size: 15px; }
  .dim-bar-row { grid-template-columns: 88px 1fr 78px; gap: 7px; font-size: 12.5px; }

  /* Bottom-sheet style Modal on mobile */
  .modal-mask { padding: 0; align-items: flex-end; }
  .modal-box {
    max-width: 100%; max-height: 84vh;
    border-radius: 18px 18px 0 0; border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .modal-head { padding: 13px 16px; font-size: 15px; }
  .modal-body { padding: 14px 14px; }
  .sheet-grid { grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 7px; }
  .sheet-dot { height: 40px; font-size: 13.5px; }
}
