:root {
  --bg: #f6f7f8;
  --paper: #ffffff;
  --paper-subtle: #fafbfb;
  --ink: #18212a;
  --muted: #68737d;
  --faint: #8a949d;
  --line: #d9dee3;
  --line-soft: #e9edf0;
  --accent: #304a5f;
  --accent-hover: #263d50;
  --accent-soft: #eaf0f4;
  --accent-line: #9babb7;
  --danger: #7a4545;
  --danger-soft: #f7eeee;
  --ok: #476453;
  --ok-soft: #edf3ef;
  --radius-sm: 7px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-soft: 0 1px 2px rgba(19, 29, 38, .035), 0 8px 28px rgba(19, 29, 38, .035);
  --sidebar-w: 236px;
  --content-max: 1120px;
  --header-h: 60px;
}

* { box-sizing: border-box; }
html { color-scheme: light; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, select, summary { font: inherit; }
button, summary, label.menu-file { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .42; }
a { color: inherit; text-decoration: none; }
svg { width: 1.1em; height: 1.1em; fill: currentColor; }
.hidden { display: none !important; }
.mobile-only { display: none !important; }

:focus-visible {
  outline: 3px solid rgba(48, 74, 95, .22);
  outline-offset: 2px;
}

.app-shell { min-height: 100vh; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-h);
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(14px) saturate(120%);
}
.topbar-inner {
  max-width: 1560px;
  height: 100%;
  margin: 0 auto;
  padding: 0 22px;
  display: grid;
  grid-template-columns: minmax(190px, 1fr) auto minmax(190px, 1fr);
  align-items: center;
  gap: 18px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; min-width: 0; justify-self: start; }
.brand-mark {
  width: 36px; height: 36px;
  border: 1px solid #28323b;
  border-radius: 8px;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 800; letter-spacing: -.03em;
  background: #fff;
}
.brand-copy { display: grid; min-width: 0; }
.brand-copy strong { font-size: 14px; font-weight: 680; line-height: 1.2; white-space: nowrap; }
.brand-copy small { margin-top: 2px; color: var(--faint); font-size: 10px; letter-spacing: .04em; white-space: nowrap; }

.subject-tabs {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  background: #f7f8f9;
  justify-self: center;
}
.subject-tabs button,
.mobile-subject-strip button {
  border: 0;
  background: transparent;
  color: #56616b;
  border-radius: 6px;
  padding: 6px 11px;
  min-height: 32px;
  font-size: 12px;
  white-space: nowrap;
}
.subject-tabs button:hover { color: var(--ink); background: rgba(255,255,255,.72); }
.subject-tabs button.active,
.mobile-subject-strip button.active {
  background: #fff;
  color: #203748;
  box-shadow: 0 0 0 1px #cbd3d9 inset, 0 1px 2px rgba(28,36,43,.04);
  font-weight: 650;
}
.subject-tabs button span { margin-left: 5px; color: var(--faint); font-size: 10px; font-variant-numeric: tabular-nums; }

.top-actions { justify-self: end; display: flex; align-items: center; gap: 5px; }
.icon-action {
  width: 36px; height: 36px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  display: inline-grid; place-items: center;
  color: #55616b;
  background: transparent;
}
.icon-action:hover { background: #f5f6f7; border-color: var(--line-soft); color: var(--ink); }
.icon-action[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: #d5e0e7; }
.more-menu { position: relative; }
.more-menu > summary { list-style: none; }
.more-menu > summary::-webkit-details-marker { display: none; }
.more-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 180px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  box-shadow: 0 12px 34px rgba(17,26,34,.12);
  display: grid;
  z-index: 60;
}
.more-popover button,
.more-popover .menu-file {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  padding: 9px 10px;
  text-align: left;
  font-size: 12px;
  cursor: pointer;
}
.more-popover button:hover,
.more-popover .menu-file:hover { background: #f5f6f7; }
.mobile-subject-strip { display: none; }

.workspace {
  max-width: 1560px;
  margin: 0 auto;
  padding: 18px 22px 46px;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: 22px;
}
.sidebar {
  position: sticky;
  top: calc(var(--header-h) + 18px);
  align-self: start;
  max-height: calc(100vh - var(--header-h) - 36px);
  overflow: auto;
  padding: 3px 3px 10px 0;
  scrollbar-width: thin;
  scrollbar-color: #cfd5da transparent;
}
.sidebar-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 12px; }
.sidebar h2 { margin: 1px 0 0; font-size: 16px; font-weight: 680; letter-spacing: -.01em; }
.eyebrow { color: var(--faint); font-size: 9px; letter-spacing: .12em; font-weight: 700; }
.filter-summary {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 10px 0 13px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
}
.filter-summary strong { color: var(--ink); font-size: 20px; line-height: 1; font-variant-numeric: tabular-nums; }
.filters { display: grid; gap: 11px; padding: 15px 0 17px; border-bottom: 1px solid var(--line); }
.field { display: grid; gap: 5px; min-width: 0; }
.field > span { color: var(--muted); font-size: 10px; font-weight: 600; letter-spacing: .02em; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
select,
input[type="search"] {
  width: 100%;
  min-width: 0;
  height: 37px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  outline: none;
}
select:hover, input[type="search"]:hover { border-color: #c6cdd3; }
select:focus, input[type="search"]:focus { border-color: #91a2af; box-shadow: 0 0 0 3px rgba(48,74,95,.08); }
.search-control { position: relative; }
.search-control svg { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; color: #8d979f; pointer-events: none; }
.search-control input { padding-left: 29px; }
.text-button {
  justify-self: start;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 1px 0;
  font-size: 11px;
  text-decoration: underline;
  text-decoration-color: #c7cdd2;
  text-underline-offset: 3px;
}
.text-button:hover { color: var(--ink); }

.progress-panel { padding: 16px 0 4px; }
.section-heading { display: flex; justify-content: space-between; align-items: baseline; color: var(--muted); font-size: 10px; }
.section-heading span:last-child { font-variant-numeric: tabular-nums; }
.progress-track { height: 4px; margin-top: 9px; background: #e7ebee; border-radius: 99px; overflow: hidden; }
.progress-track div { height: 100%; width: 0; background: var(--accent); transition: width .18s ease; }
.progress-metrics { margin: 13px 0 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 12px; }
.progress-metrics div { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.progress-metrics dt { color: var(--muted); font-size: 10px; }
.progress-metrics dd { margin: 0; color: var(--ink); font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums; }
.shortcut-note { margin-top: 14px; color: #8b949b; font-size: 9px; display: flex; flex-wrap: wrap; gap: 5px 9px; }
.sidebar-backdrop { display: none; }

.main { min-width: 0; display: flex; justify-content: center; }
.mobile-tools { display: none; }
.question-sheet,
.empty-state { width: min(100%, var(--content-max)); }
.question-sheet {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  overflow: clip;
}
.question-header {
  padding: 22px 24px 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}
.question-context { min-width: 0; }
.meta-line { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; }
.subject-badge {
  display: inline-flex; align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
}
.meta-separator { color: #c1c7cc; }
.question-header h1 {
  margin: 11px 0 4px;
  font-size: 20px;
  line-height: 1.35;
  letter-spacing: -.018em;
  font-weight: 720;
}
.sub-line { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 11px; }
.status-badge { display: inline-flex; align-items: center; min-height: 21px; padding: 2px 7px; border: 1px solid var(--line); border-radius: 99px; color: #6f7981; background: #fff; font-size: 9px; white-space: nowrap; }
.status-badge.correct { color: var(--ok); border-color: #cddbd2; background: var(--ok-soft); }
.status-badge.wrong { color: var(--danger); border-color: #e2cccc; background: var(--danger-soft); }
.status-badge.mastered { color: var(--accent); border-color: #cedae2; background: var(--accent-soft); }
.question-header-actions { display: flex; align-items: center; gap: 9px; flex: 0 0 auto; }
.position-text { color: var(--faint); font-size: 11px; font-variant-numeric: tabular-nums; }
.bookmark-button {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #68737d;
}
.bookmark-button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.bookmark-button:hover { border-color: #bcc5cc; color: var(--ink); }
.bookmark-button.active { background: var(--accent-soft); border-color: #cdd9e1; color: var(--accent); }
.bookmark-button.active svg { fill: currentColor; }
.question-index-track { height: 2px; background: #edf0f2; }
.question-index-track div { height: 100%; width: 0; background: var(--accent-line); transition: width .18s ease; }

.question-content { padding: 20px 24px 22px; }
.image-stage {
  position: relative;
  width: 100%;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}
.image-stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.008);
}
.image-stage img { display: block; width: 100%; height: auto; margin: 0 auto; user-select: none; cursor: zoom-in; }
.image-zoom-button {
  position: absolute;
  top: 8px; right: 8px;
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border: 1px solid rgba(198,205,211,.86);
  border-radius: 7px;
  background: rgba(255,255,255,.90);
  color: #57636d;
  opacity: 0;
  transition: opacity .14s ease, background .14s ease;
  backdrop-filter: blur(6px);
}
.image-stage:hover .image-zoom-button,
.image-zoom-button:focus-visible { opacity: 1; }
.image-zoom-button:hover { background: #fff; color: var(--ink); }

.choice-area { margin-top: 14px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.choice-area button {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 14px;
  font-weight: 690;
  transition: background .12s ease, border-color .12s ease, transform .08s ease;
}
.choice-area button:hover { border-color: #aeb9c1; background: #fafbfb; }
.choice-area button:active { transform: translateY(1px); }
.choice-area button.selected { border-color: #8499a8; background: var(--accent-soft); color: #203b4f; }
.choice-area button.correct { border-color: #9fb5a7; background: var(--ok-soft); color: var(--ok); }
.choice-area button.wrong { border-color: #c3a0a0; background: var(--danger-soft); color: var(--danger); }

.feedback {
  margin-top: 12px;
  min-height: 38px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f7f8f9;
  color: #59656e;
  font-size: 12px;
  display: flex;
  align-items: center;
}
.feedback.ok { background: var(--ok-soft); color: var(--ok); border-color: #d0ddd5; }
.feedback.bad { background: var(--danger-soft); color: var(--danger); border-color: #e2cece; }
.feedback.neutral { background: #f4f6f7; color: #59656e; }
.study-actions { margin-top: 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.secondary-actions { display: flex; gap: 7px; }
.button {
  min-height: 39px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  font-weight: 580;
}
.button:hover { border-color: #bbc5cc; background: #fafbfb; }
.button.primary { color: #fff; background: var(--accent); border-color: var(--accent); }
.button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.button.secondary { background: #fff; }

.answer-panel {
  margin: 0 24px;
  padding: 22px 0 24px;
  border-top: 1px solid var(--line);
}
.answer-heading { margin-bottom: 12px; display: flex; justify-content: space-between; align-items: end; gap: 16px; }
.answer-heading h2 { margin: 2px 0 0; font-size: 16px; font-weight: 700; }
.answer-hint { color: var(--muted); font-size: 10px; }
.answer-stage { background: #fcfcfb; }
.self-check { margin-top: 12px; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; color: var(--muted); font-size: 10px; }
.self-check span { margin-right: 3px; }

.pager {
  min-height: 62px;
  padding: 11px 16px;
  border-top: 1px solid var(--line-soft);
  background: #fbfcfc;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.pager-button {
  min-height: 39px;
  padding: 8px 11px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: #58636c;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
}
.pager-button:hover:not(:disabled) { background: #f1f3f4; color: var(--ink); }
.pager-button.next { color: #fff; background: var(--accent); border-color: var(--accent); padding-left: 16px; padding-right: 13px; }
.pager-button.next:hover:not(:disabled) { background: var(--accent-hover); color: #fff; }

.empty-state {
  margin-top: 60px;
  min-height: 300px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 6px;
  text-align: center;
  color: var(--muted);
}
.empty-mark { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 50%; display: grid; place-items: center; font-size: 22px; color: #929ba2; }
.empty-state h2 { margin: 7px 0 0; color: var(--ink); font-size: 17px; }
.empty-state p { margin: 0 0 9px; font-size: 12px; }

/* Focus mode */
.focus-mode .topbar-inner { grid-template-columns: 1fr auto 1fr; }
.focus-mode .subject-tabs { opacity: .45; }
.focus-mode .workspace { grid-template-columns: minmax(0, 1fr); }
.focus-mode .sidebar { display: none; }
.focus-mode .question-sheet { --content-max: 1180px; }

/* Dialogs */
dialog { color: var(--ink); }
dialog::backdrop { background: rgba(20, 28, 35, .28); backdrop-filter: blur(2px); }
.sheet-dialog {
  width: min(720px, calc(100vw - 28px));
  max-height: min(82vh, 760px);
  padding: 0;
  border: 1px solid #cfd6db;
  border-radius: 13px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(18,27,34,.22);
}
.dialog-shell { display: flex; flex-direction: column; max-height: inherit; }
.dialog-header {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}
.dialog-header h2 { margin: 2px 0 0; font-size: 17px; }
.dialog-header p { margin: 4px 0 0; color: var(--muted); font-size: 10px; }
.navigator-legend { padding: 11px 18px 9px; display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 9px; }
.navigator-legend span { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 7px; height: 7px; border-radius: 50%; border: 1px solid #c7cdd2; background: #fff; }
.dot.correct { border-color: #9db1a4; background: var(--ok-soft); }
.dot.wrong { border-color: #c39b9b; background: var(--danger-soft); }
.dot.mastered { border-color: #9eafbc; background: var(--accent-soft); }
.question-grid {
  padding: 8px 18px 20px;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(8, minmax(0,1fr));
  gap: 7px;
}
.question-grid button {
  position: relative;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: #55616a;
  display: grid;
  place-items: center;
  gap: 0;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.question-grid button small { display: block; margin-top: -6px; color: #98a0a7; font-size: 7px; }
.question-grid button:hover { border-color: #aeb9c1; color: var(--ink); }
.question-grid button.current { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); color: var(--accent); font-weight: 700; }
.question-grid button.correct::after,
.question-grid button.wrong::after,
.question-grid button.mastered::after {
  content: ""; position: absolute; top: 4px; right: 4px; width: 5px; height: 5px; border-radius: 50%;
}
.question-grid button.correct::after { background: #7e9b88; }
.question-grid button.wrong::after { background: #a57272; }
.question-grid button.mastered::after { background: var(--accent); }
.question-grid button.favorite::before { content: "★"; position: absolute; top: 2px; left: 4px; font-size: 7px; color: #657784; }

.image-dialog {
  width: min(96vw, 1450px);
  height: min(94vh, 1000px);
  padding: 0;
  border: 1px solid #cbd2d8;
  border-radius: 12px;
  background: #f2f3f4;
  box-shadow: 0 24px 80px rgba(12,20,27,.28);
  overflow: hidden;
}
.image-dialog-shell { height: 100%; display: grid; grid-template-rows: 50px minmax(0,1fr); }
.image-dialog-toolbar {
  padding: 0 10px 0 15px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.95);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-size: 12px; color: #59656e;
}
.zoom-controls { display: flex; align-items: center; gap: 3px; }
.zoom-level { min-width: 58px; height: 34px; border: 0; background: transparent; color: var(--muted); font-size: 10px; }
.zoom-viewport { overflow: auto; padding: 20px; display: flex; justify-content: center; align-items: flex-start; touch-action: pan-x pan-y pinch-zoom; }
.zoom-viewport img { display: block; width: 100%; max-width: none; height: auto; box-shadow: 0 2px 14px rgba(12,20,27,.08); transform-origin: top center; }

.shortcuts-dialog { width: min(440px, calc(100vw - 28px)); }
.shortcut-list { margin: 0; padding: 8px 18px 18px; display: grid; }
.shortcut-list div { min-height: 48px; display: grid; grid-template-columns: 120px 1fr; align-items: center; border-bottom: 1px solid var(--line-soft); }
.shortcut-list div:last-child { border-bottom: 0; }
.shortcut-list dt, .shortcut-list dd { margin: 0; }
.shortcut-list dd { color: var(--muted); font-size: 11px; }
kbd { display: inline-flex; min-width: 25px; height: 24px; padding: 0 6px; align-items: center; justify-content: center; border: 1px solid #cfd5da; border-bottom-color: #b8c0c6; border-radius: 5px; background: #fafbfb; color: #48545e; font-size: 10px; box-shadow: 0 1px 0 #e5e8ea; }

.toast {
  position: fixed;
  left: 50%; bottom: 26px;
  transform: translate(-50%, 14px);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  padding: 9px 13px;
  border-radius: 7px;
  background: #26333d;
  color: #fff;
  font-size: 11px;
  box-shadow: 0 8px 24px rgba(14,23,30,.18);
  transition: opacity .16s ease, transform .16s ease;
}
.toast.show { opacity: 1; transform: translate(-50%,0); }

@media (max-width: 1080px) {
  :root { --sidebar-w: 220px; }
  .topbar-inner { grid-template-columns: minmax(160px, 1fr) auto minmax(120px, 1fr); padding: 0 16px; }
  .brand-copy small { display: none; }
  .subject-tabs button { padding-left: 9px; padding-right: 9px; }
  .workspace { padding-left: 16px; padding-right: 16px; gap: 16px; }
}

@media (max-width: 860px) {
  :root { --header-h: 54px; }
  body { background: #fff; }
  .topbar-inner { grid-template-columns: 1fr auto; padding: 0 12px; }
  .brand-mark { width: 34px; height: 34px; }
  .brand-copy strong { font-size: 13px; }
  .subject-tabs { display: none; }
  .top-actions #randomBtn { display: none; }
  .mobile-subject-strip {
    position: sticky;
    top: var(--header-h);
    z-index: 35;
    height: 45px;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px 10px;
    overflow-x: auto;
    border-bottom: 1px solid var(--line-soft);
    background: rgba(255,255,255,.96);
    backdrop-filter: blur(12px);
    scrollbar-width: none;
  }
  .mobile-subject-strip::-webkit-scrollbar { display: none; }
  .mobile-subject-strip button { flex: 0 0 auto; padding-left: 10px; padding-right: 10px; border: 1px solid transparent; }
  .workspace { display: block; padding: 0; }
  .sidebar {
    position: fixed;
    z-index: 80;
    top: 0; bottom: 0; left: 0;
    width: min(330px, 88vw);
    max-height: none;
    overflow: auto;
    padding: 18px 18px 28px;
    background: #fff;
    border-right: 1px solid var(--line);
    transform: translateX(-102%);
    transition: transform .18s ease;
    box-shadow: 14px 0 45px rgba(13,21,28,.12);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-only { display: inline-grid !important; }
  .sidebar-backdrop {
    position: fixed; inset: 0; z-index: 70;
    width: 100%; height: 100%;
    border: 0;
    background: rgba(18,26,33,.24);
    opacity: 0; pointer-events: none;
    display: block;
    transition: opacity .18s ease;
  }
  .sidebar.open + .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  .main { display: block; }
  .mobile-tools {
    min-height: 44px;
    padding: 7px 12px 6px;
    display: flex; align-items: center; gap: 7px;
    background: #fff;
  }
  .compact-action {
    height: 32px; padding: 0 9px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    color: #59656e;
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 11px;
  }
  .compact-action svg { width: 14px; height: 14px; }
  .mobile-position { margin-left: auto; color: var(--faint); font-size: 11px; font-variant-numeric: tabular-nums; }
  .question-sheet { width: 100%; border-left: 0; border-right: 0; border-radius: 0; box-shadow: none; }
  .question-header { padding: 17px 14px 13px; }
  .question-header h1 { font-size: 18px; margin-top: 9px; }
  .question-header-actions { align-items: flex-start; }
  .position-text { display: none; }
  .question-content { padding: 15px 14px 18px; }
  .answer-panel { margin: 0 14px; }
  .image-zoom-button { opacity: 1; top: 6px; right: 6px; width: 30px; height: 30px; }
  .study-actions { align-items: stretch; flex-direction: column; }
  .study-actions .button.primary { width: 100%; min-height: 44px; }
  .secondary-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .secondary-actions .button { min-height: 40px; }
  .pager {
    position: sticky;
    bottom: 0;
    z-index: 30;
    min-height: 60px;
    padding: 9px 12px calc(9px + env(safe-area-inset-bottom));
    background: rgba(255,255,255,.95);
    backdrop-filter: blur(12px);
    box-shadow: 0 -1px 0 var(--line-soft);
  }
  .pager-button { min-height: 42px; }
  .pager-button.next { min-width: 112px; justify-content: center; }
  .focus-mode .mobile-subject-strip { display: none; }
  .focus-mode .mobile-tools { padding-top: 10px; }
  .question-grid { grid-template-columns: repeat(6, minmax(0,1fr)); }
  .image-dialog { width: 100vw; height: 100dvh; max-width: none; max-height: none; border: 0; border-radius: 0; }
  .zoom-viewport { padding: 10px; }
}

@media (max-width: 520px) {
  .topbar .top-actions #focusBtn { display: none; }
  .brand-copy strong { font-size: 13px; }
  .mobile-subject-strip { padding-left: 8px; padding-right: 8px; }
  .mobile-subject-strip button { font-size: 11px; }
  .question-header { gap: 10px; }
  .meta-line { gap: 6px; font-size: 10px; flex-wrap: wrap; }
  .question-header h1 { font-size: 17px; }
  .sub-line { flex-wrap: wrap; }
  .bookmark-button { width: 34px; height: 34px; }
  .choice-area { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .choice-area button { min-height: 48px; }
  .answer-heading { align-items: flex-start; flex-direction: column; gap: 5px; }
  .self-check .button { flex: 1; }
  .question-grid { grid-template-columns: repeat(5, minmax(0,1fr)); }
  .shortcut-note { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}

/* v3 - knowledge tree / curriculum granularity */
:root { --sidebar-w: 272px; }
.curriculum-field { gap: 6px; }
.field-label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 10px; font-weight: 600; letter-spacing: .02em; }
.mini-text-button { border: 0; background: transparent; color: var(--faint); padding: 2px 0; font-size: 10px; }
.mini-text-button:hover { color: var(--ink); }
.mini-text-button.active { color: var(--accent); font-weight: 700; }
.field-help { color: #929ba3; font-size: 9px; line-height: 1.45; }
.chapter-tree { max-height: min(420px, 45vh); overflow-y: auto; overscroll-behavior: contain; border: 1px solid var(--line); border-radius: 8px; background: #fff; scrollbar-width: thin; scrollbar-color: #c9d0d5 transparent; }
.chapter-group + .chapter-group { border-top: 1px solid var(--line-soft); }
.chapter-row { display: grid; grid-template-columns: 28px minmax(0,1fr); align-items: stretch; min-height: 43px; }
.chapter-expander { border: 0; border-right: 1px solid var(--line-soft); background: transparent; color: #7d8790; display: grid; place-items: center; padding: 0; }
.chapter-expander:hover { background: #f7f8f9; color: var(--ink); }
.chapter-expander svg { width: 13px; height: 13px; transition: transform .14s ease; }
.chapter-group.expanded .chapter-expander svg { transform: rotate(90deg); }
.chapter-filter { min-width: 0; border: 0; background: transparent; padding: 7px 9px; color: var(--ink); text-align: left; display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: 8px; }
.chapter-filter:hover { background: #f7f8f9; }
.chapter-filter.active { background: var(--accent-soft); color: #203b4f; }
.chapter-title { min-width: 0; display: grid; gap: 1px; }
.chapter-title strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10.5px; font-weight: 650; }
.chapter-title small { color: var(--faint); font-size: 8.5px; font-weight: 500; }
.chapter-summary { color: #7d8790; font-size: 8.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.section-list { display: none; border-top: 1px solid var(--line-soft); background: #fbfcfc; }
.chapter-group.expanded .section-list { display: grid; }
.section-filter { width: 100%; border: 0; border-bottom: 1px solid #eef1f3; background: transparent; padding: 7px 8px 7px 36px; color: #56616b; text-align: left; display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: 8px; }
.section-filter:last-child { border-bottom: 0; }
.section-filter:hover:not(:disabled) { background: #f5f7f8; color: var(--ink); }
.section-filter.active { background: #edf2f5; color: #263f52; box-shadow: inset 2px 0 0 var(--accent); }
.section-filter.empty-section { opacity: .46; cursor: default; }
.section-main { min-width: 0; display: flex; align-items: baseline; gap: 6px; }
.section-id { flex: 0 0 auto; color: #7d8790; font-size: 9px; font-variant-numeric: tabular-nums; }
.section-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 9.5px; }
.section-stats { color: #89939b; font-size: 8px; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* grouped question navigator */
.question-grid-wrap { position: relative; overflow: auto; min-height: 0; }
.question-grid { overflow: visible; display: block; padding: 4px 18px 34px; }
.question-section-group + .question-section-group { margin-top: 15px; padding-top: 14px; border-top: 1px solid var(--line-soft); }
.question-section-head { position: sticky; top: 0; z-index: 2; margin: 0 -2px 8px; padding: 7px 2px 6px; background: rgba(255,255,255,.96); backdrop-filter: blur(5px); display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.question-section-head strong { font-size: 10px; font-weight: 680; color: #3b4852; }
.question-section-head span { color: var(--faint); font-size: 8px; font-variant-numeric: tabular-nums; }
.question-section-cells { display: grid; grid-template-columns: repeat(8,minmax(0,1fr)); gap: 7px; }
.question-section-cells button { position: relative; min-height: 46px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: #55616a; display: grid; place-items: center; gap: 0; font-size: 11px; font-variant-numeric: tabular-nums; }
.question-section-cells button small { display: block; margin-top: -6px; color: #98a0a7; font-size: 7px; }
.question-section-cells button:hover { border-color: #aeb9c1; color: var(--ink); }
.question-section-cells button.current { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); color: var(--accent); font-weight: 700; }
.question-section-cells button.correct::after,.question-section-cells button.wrong::after,.question-section-cells button.mastered::after { content:""; position:absolute; top:4px; right:4px; width:5px; height:5px; border-radius:50%; }
.question-section-cells button.correct::after { background:#7e9b88; }
.question-section-cells button.wrong::after { background:#a57272; }
.question-section-cells button.mastered::after { background:var(--accent); }
.question-section-cells button.favorite::before { content:"★"; position:absolute; top:2px; left:4px; font-size:7px; color:#657784; }
.question-grid-scroll-hint { position: sticky; bottom: 0; z-index: 3; margin-top: -29px; height: 29px; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 5px; pointer-events: none; color: #8c969e; font-size: 8px; background: linear-gradient(to bottom,rgba(255,255,255,0),rgba(255,255,255,.96) 62%); }

/* Wide scanned question images stay readable on narrow displays. */
.image-stage.wide-scan, .image-stage.very-wide-scan { overscroll-behavior-x: contain; }
@media (max-width: 1080px) and (min-width: 861px) { :root { --sidebar-w: 248px; } }
@media (max-width: 860px) {
  .sidebar { width: min(360px, 92vw); }
  .chapter-tree { max-height: min(47vh, 440px); }
  .image-stage.wide-scan { overflow-x: auto; }
  .image-stage.wide-scan img { width: 720px; max-width: none; }
  .image-stage.very-wide-scan img { width: 820px; max-width: none; }
  .question-section-cells { grid-template-columns: repeat(6,minmax(0,1fr)); }
  .question-grid-wrap { max-height: calc(82vh - 126px); }
}
@media (max-width: 520px) {
  .question-section-cells { grid-template-columns: repeat(5,minmax(0,1fr)); }
  .section-filter { padding-left: 31px; }
}

/* v3.1 readability pass: keep the dense research aesthetic without sub-10px UI text. */
.field-label-row { font-size: 11.5px; }
.mini-text-button { font-size: 11px; min-height: 30px; padding: 4px 0; }
.field-help { font-size: 10.5px; }
.chapter-row { grid-template-columns: 36px minmax(0,1fr); min-height: 48px; }
.chapter-expander { min-width: 36px; min-height: 44px; }
.chapter-expander svg { width: 14px; height: 14px; }
.chapter-filter { min-height: 48px; padding: 7px 9px; }
.chapter-title strong { font-size: 12px; }
.chapter-title small { font-size: 10px; }
.chapter-summary { font-size: 10px; }
.section-filter { min-height: 40px; padding-top: 8px; padding-bottom: 8px; }
.section-id { font-size: 10.5px; }
.section-name { font-size: 11.5px; }
.section-stats { font-size: 10px; }
.question-section-head strong { font-size: 12px; }
.question-section-head span { font-size: 10px; }
.question-section-cells button { min-height: 48px; font-size: 12px; }
.question-section-cells button small { font-size: 9px; margin-top: -5px; }
.question-section-cells button.favorite::before { font-size: 9px; }
.question-grid-scroll-hint { font-size: 10px; }
