:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --surface-raised: #ffffff;
  --text: #151a22;
  --muted: #707987;
  --muted-strong: #4c5664;
  --line: #e3e7ec;
  --line-strong: #cdd4dc;
  --blue: #2369df;
  --blue-soft: #eaf1ff;
  --teal: #0d8a72;
  --teal-soft: #e5f5f0;
  --coral: #d7664f;
  --coral-soft: #fff0ec;
  --gold: #a97500;
  --gold-soft: #fff5db;
  --shadow: 0 16px 40px rgba(22, 31, 43, .08);
  --radius: 8px;
}

:root[data-theme="dark"] {
  --bg: #171b21;
  --surface: #20262e;
  --surface-soft: #1c2229;
  --surface-raised: #28313b;
  --text: #edf1f5;
  --muted: #9ca8b5;
  --muted-strong: #c4ced8;
  --line: #35404b;
  --line-strong: #4c5967;
  --blue: #79a9ff;
  --blue-soft: #253a5f;
  --teal: #61d2b5;
  --teal-soft: #1d4038;
  --coral: #ff9b84;
  --coral-soft: #4b2924;
  --gold: #e7ba55;
  --gold-soft: #4b3c1d;
  --shadow: 0 16px 40px rgba(0, 0, 0, .22);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-width: 320px; min-height: 100%; background: var(--bg); color: var(--text); }
body { font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif; font-size: 14px; line-height: 1.5; overflow-x: hidden; }
button, input, textarea { font: inherit; color: inherit; }
button { border: 0; cursor: pointer; }
button:disabled { cursor: wait; opacity: .55; }
button:focus-visible, input:focus-visible, textarea:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
[hidden] { display: none !important; }

.app-shell { min-height: 100vh; background: var(--bg); }
.topbar { height: 66px; display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 0 24px; background: var(--surface); border-bottom: 1px solid var(--line); position: relative; z-index: 30; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; min-width: 188px; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; color: #fff; background: var(--blue); border-radius: 8px; font-weight: 700; font-size: 18px; }
.brand-copy { display: flex; flex-direction: column; line-height: 1.05; }
.brand-copy strong { font-size: 16px; letter-spacing: .02em; }
.brand-copy small { margin-top: 5px; color: var(--muted); font-size: 11px; }
.topbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex: 1; position: relative; }
.search-box { width: min(430px, 42vw); height: 38px; display: flex; align-items: center; gap: 9px; padding: 0 10px 0 12px; color: var(--muted); background: var(--surface-soft); border: 1px solid var(--line); border-radius: 6px; }
.search-box:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 18%, transparent); }
.search-box svg { width: 16px; flex: 0 0 auto; }
.search-box input { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 13px; }
.search-box kbd { padding: 1px 5px; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--muted); font-size: 11px; }
.search-results { position: absolute; z-index: 40; top: 46px; right: 125px; width: min(430px, 42vw); max-height: 420px; overflow: auto; padding: 5px; background: var(--surface-raised); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.search-result { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; padding: 10px 12px; text-align: left; background: transparent; border-radius: 5px; }
.search-result:hover { background: var(--blue-soft); }
.search-result strong { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-result small, .search-empty { color: var(--muted); font-size: 12px; }
.search-empty { padding: 14px 12px; }
.icon-button, .primary-button, .secondary-button, .text-button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; border-radius: 6px; white-space: nowrap; transition: background .16s ease, color .16s ease, border-color .16s ease; }
.icon-button { width: 36px; color: var(--muted-strong); background: transparent; position: relative; }
.icon-button:hover { color: var(--text); background: var(--surface-soft); }
.icon-button[data-tooltip]::after { content: attr(data-tooltip); position: absolute; z-index: 70; top: calc(100% + 8px); left: 50%; display: none; padding: 5px 8px; color: #fff; background: #242b33; border-radius: 4px; font-size: 11px; white-space: nowrap; transform: translateX(-50%); pointer-events: none; }
.icon-button[data-tooltip]:hover::after { display: block; }
.primary-button { min-height: 36px; padding: 0 13px; color: #fff; background: var(--blue); font-weight: 600; }
.primary-button:hover { background: color-mix(in srgb, var(--blue) 84%, #000); }
.secondary-button { padding: 0 12px; color: var(--muted-strong); background: var(--surface); border: 1px solid var(--line-strong); }
.secondary-button:hover { color: var(--text); border-color: var(--blue); }
.text-button { height: auto; padding: 4px 0; color: var(--blue); background: transparent; font-size: 12px; }
.text-button:hover { color: var(--text); }
.full-button { width: 100%; }
.mobile-nav-button, .chapters-close, .mobile-scrim, .mobile-button-text, .mobile-bottom-bar { display: none; }
.is-spinning svg { animation: spin .75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.app-body { display: grid; grid-template-columns: 254px minmax(0, 1fr) 340px; min-height: calc(100vh - 66px); }
.chapter-sidebar { display: flex; flex-direction: column; min-width: 0; background: var(--surface); border-right: 1px solid var(--line); }
.sidebar-heading { display: flex; align-items: center; justify-content: space-between; padding: 22px 18px 15px; }
.sidebar-heading-actions { display: flex; align-items: center; gap: 6px; }
.sidebar-heading strong { display: block; margin-top: 3px; font-size: 15px; }
.eyebrow { display: block; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.count-badge { display: grid; place-items: center; min-width: 24px; height: 22px; padding: 0 6px; color: var(--blue); background: var(--blue-soft); border-radius: 11px; font-size: 11px; font-weight: 700; }
.chapter-list { flex: 1; overflow: auto; padding: 0 8px 14px; }
.subject-group { padding: 8px 0 4px; }
.subject-heading { display: flex; align-items: center; justify-content: space-between; padding: 7px 10px 5px; color: var(--text); }
.subject-heading strong { font-size: 12px; }
.subject-heading small { color: var(--muted); font-size: 10px; }
.chapter-item { display: flex; align-items: center; gap: 9px; width: 100%; min-height: 53px; padding: 8px 10px; color: var(--muted-strong); text-align: left; background: transparent; border-radius: 6px; }
.chapter-item:hover { background: var(--surface-soft); color: var(--text); }
.chapter-item.is-active { color: var(--text); background: var(--blue-soft); }
.chapter-index { display: grid; place-items: center; width: 31px; height: 31px; flex: 0 0 auto; color: var(--blue); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; font-size: 10px; font-weight: 700; }
.chapter-item.is-active .chapter-index { color: var(--blue); border-color: color-mix(in srgb, var(--blue) 40%, var(--line)); }
.chapter-meta { display: flex; flex-direction: column; min-width: 0; gap: 3px; }
.chapter-meta strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.chapter-meta small { color: var(--muted); font-size: 10px; }
.chapter-state { margin-left: auto; color: var(--muted); font-size: 10px; }
.chapter-state.has-due { color: var(--gold); }
.chapter-state svg { width: 14px; }
.sidebar-footer { padding: 15px 18px 18px; border-top: 1px solid var(--line); }
.progress-summary { display: flex; align-items: center; gap: 10px; margin-bottom: 13px; }
.progress-ring { display: grid; place-items: center; width: 44px; height: 44px; flex: 0 0 auto; color: var(--blue); border: 4px solid var(--blue-soft); border-top-color: var(--blue); border-radius: 50%; font-size: 10px; font-weight: 700; }
.progress-summary strong, .progress-summary small { display: block; }
.progress-summary strong { font-size: 12px; }
.progress-summary small { margin-top: 3px; color: var(--muted); font-size: 10px; }

.workspace { display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.workspace-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 62px; padding: 0 20px; border-bottom: 1px solid var(--line); background: var(--surface); }
.breadcrumbs { display: flex; align-items: center; gap: 7px; min-width: 0; color: var(--muted); font-size: 12px; }
.breadcrumbs svg { width: 14px; flex: 0 0 auto; }
.breadcrumbs strong { overflow: hidden; color: var(--text); text-overflow: ellipsis; white-space: nowrap; }
.workspace-actions { display: flex; align-items: center; gap: 5px; }
.tree-action { height: 32px; padding: 0 9px; font-size: 11px; }
.tree-action svg { width: 14px; }
.segmented-control { display: flex; padding: 3px; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 6px; }
.segment { display: inline-flex; align-items: center; gap: 5px; min-height: 28px; padding: 0 8px; color: var(--muted); background: transparent; border-radius: 4px; font-size: 11px; }
.segment svg { width: 14px; }
.segment.is-active { color: var(--text); background: var(--surface); box-shadow: 0 1px 3px rgba(20, 31, 44, .08); }
.map-stage { position: relative; flex: 1; min-height: 560px; overflow: hidden; background: var(--surface-soft); }
#mindmap { display: block; width: 100%; height: 100%; min-height: 560px; cursor: grab; touch-action: none; }
#mindmap:active { cursor: grabbing; }
.map-viewport { transform-origin: 0 0; }
.map-edge { fill: none; stroke: var(--line-strong); stroke-width: 1.5; }
.map-node { outline: none; }
.map-node rect { fill: var(--surface-raised); stroke: var(--line-strong); stroke-width: 1.2; transition: fill .16s ease, stroke .16s ease; }
.map-node:hover rect, .map-node:focus rect { stroke: var(--blue); stroke-width: 1.7; }
.map-node.is-selected rect { fill: var(--blue-soft); stroke: var(--blue); stroke-width: 1.8; }
.map-node.node-chapter rect { fill: var(--blue); stroke: var(--blue); }
.map-node.node-chapter .node-label { color: #fff; font-weight: 600; }
.map-node.node-section rect { fill: color-mix(in srgb, var(--blue-soft) 55%, var(--surface-raised)); }
.map-node.node-subsection rect { fill: color-mix(in srgb, var(--teal-soft) 50%, var(--surface-raised)); }
.map-node.status-due rect { stroke: var(--gold); }
.map-node.status-weak rect { stroke: var(--coral); }
.map-node.status-mastered rect { stroke: var(--teal); }
.node-label { display: -webkit-box; width: 100%; overflow: hidden; color: var(--text); font-size: 12px; line-height: 1.45; -webkit-box-orient: vertical; -webkit-line-clamp: 2; word-break: break-all; }
.node-toggle { fill: var(--surface); stroke: var(--line-strong); stroke-width: 1; }
.toggle-symbol { fill: var(--muted-strong); text-anchor: middle; font-size: 14px; }
.status-dot { fill: var(--muted); }
.map-node.status-new .status-dot { fill: var(--muted); }
.map-node.status-learning .status-dot { fill: var(--blue); }
.map-node.status-due .status-dot { fill: var(--gold); }
.map-node.status-weak .status-dot { fill: var(--coral); }
.map-node.status-mastered .status-dot { fill: var(--teal); }
.map-node.node-chapter .status-dot { fill: #fff; }
.map-loading { position: absolute; top: 50%; left: 50%; display: flex; align-items: center; gap: 9px; color: var(--muted); transform: translate(-50%, -50%); }
.map-loading.is-hidden { display: none; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--line-strong); border-top-color: var(--blue); border-radius: 50%; animation: spin .75s linear infinite; }
.map-hint { position: absolute; left: 20px; bottom: 18px; display: flex; align-items: center; gap: 6px; padding: 7px 9px; color: var(--muted); background: color-mix(in srgb, var(--surface) 82%, transparent); border: 1px solid var(--line); border-radius: 5px; font-size: 11px; pointer-events: none; }
.map-hint svg { width: 14px; }
.map-legend { position: absolute; right: 18px; bottom: 18px; display: flex; align-items: center; gap: 12px; padding: 7px 9px; color: var(--muted); background: color-mix(in srgb, var(--surface) 88%, transparent); border: 1px solid var(--line); border-radius: 5px; font-size: 10px; }
.map-legend span { display: inline-flex; align-items: center; gap: 4px; }
.legend-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.legend-dot.status-learning { background: var(--blue); }.legend-dot.status-due { background: var(--gold); }.legend-dot.status-mastered { background: var(--teal); }
.outline-stage { flex: 1; min-height: 560px; overflow: auto; padding: 22px 28px 50px; background: var(--surface-soft); }
.outline-header { display: flex; align-items: baseline; justify-content: space-between; max-width: 900px; margin: 0 auto 16px; padding-bottom: 11px; border-bottom: 1px solid var(--line); }
.outline-header span { font-weight: 600; }.outline-header small { color: var(--muted); font-size: 11px; }
.outline-tree, .outline-tree ul { max-width: 900px; margin: 0 auto; padding-left: 20px; list-style: none; }.outline-tree { padding-left: 0; }
.outline-tree ul { border-left: 1px solid var(--line-strong); }
.outline-group { margin: 3px 0; }.outline-group-button, .outline-point { display: flex; align-items: center; width: 100%; gap: 7px; padding: 7px 8px; text-align: left; background: transparent; border-radius: 5px; }.outline-group-button:hover, .outline-point:hover { background: var(--surface); }.outline-group-button svg { width: 15px; color: var(--muted); }.outline-group-button strong { font-size: 12px; }.outline-group-button small { margin-left: auto; color: var(--muted); font-size: 10px; }.outline-point { color: var(--muted-strong); font-size: 12px; }.outline-point span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }.outline-dot { width: 7px; height: 7px; flex: 0 0 auto; border-radius: 50%; background: var(--muted); }.outline-point.status-learning .outline-dot { background: var(--blue); }.outline-point.status-due .outline-dot { background: var(--gold); }.outline-point.status-weak .outline-dot { background: var(--coral); }.outline-point.status-mastered .outline-dot { background: var(--teal); }

.inspector { min-width: 0; overflow: auto; background: var(--surface); border-left: 1px solid var(--line); }
.inspector-topline { display: flex; align-items: center; justify-content: space-between; padding: 22px 20px 12px; }.mobile-only { display: none; }
.inspector-content { padding: 0 20px 28px; }.inspector-empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 140px 15px 60px; color: var(--muted); text-align: center; }.inspector-empty svg { width: 28px; height: 28px; margin-bottom: 4px; color: var(--blue); }.inspector-empty strong { color: var(--text); font-size: 13px; }.inspector-empty span { font-size: 11px; }.detail-heading h1 { margin: 11px 0 6px; font-size: 18px; line-height: 1.35; }.detail-path { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.6; }.status-pill { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 10px; font-weight: 600; }.status-pill b { display: block; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }.status-pill.status-learning b { background: var(--blue); }.status-pill.status-due b { background: var(--gold); }.status-pill.status-weak b { background: var(--coral); }.status-pill.status-mastered b { background: var(--teal); }.detail-actions { margin: 20px 0 24px; }.detail-block { padding: 15px 0; border-top: 1px solid var(--line); }.block-label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }.block-label svg { width: 14px; }.source-text { margin: 10px 0 0; color: var(--text); white-space: pre-wrap; font-size: 13px; line-height: 1.85; }.citation-text { margin: 9px 0 0; color: var(--muted); font-size: 11px; line-height: 1.7; word-break: break-all; }.detail-footer { display: grid; grid-template-columns: 1fr auto; gap: 5px 10px; padding-top: 16px; color: var(--muted); border-top: 1px solid var(--line); font-size: 11px; }.detail-footer strong { color: var(--text); font-weight: 500; text-align: right; }.detail-footer small { grid-column: 1 / -1; color: var(--muted); }.mobile-only { display: none; }

.modal-backdrop { position: fixed; z-index: 80; inset: 0; display: grid; place-items: center; padding: 22px; background: rgba(11, 16, 22, .42); }.quiz-dialog, .stats-dialog { width: min(640px, 100%); max-height: min(760px, 92vh); overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; box-shadow: var(--shadow); }.stats-dialog { width: min(720px, 100%); }.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding: 22px 24px 16px; border-bottom: 1px solid var(--line); }.dialog-header h2 { margin: 5px 0 0; font-size: 18px; }.quiz-body, .stats-body { padding: 22px 24px 26px; }.quiz-question { padding: 18px; color: var(--text); background: var(--blue-soft); border-left: 3px solid var(--blue); font-size: 16px; line-height: 1.7; }.quiz-citation { margin: 11px 0 20px; color: var(--muted); font-size: 11px; line-height: 1.6; }.answer-label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 11px; font-weight: 700; }.quiz-body textarea { display: block; width: 100%; min-height: 110px; resize: vertical; padding: 12px; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 6px; outline: 0; }.quiz-body textarea:focus { border-color: var(--blue); }.quiz-actions { display: flex; align-items: center; gap: 13px; margin-top: 12px; }.answer-reveal { margin-top: 20px; padding: 15px; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 6px; }.answer-reveal p { margin: 10px 0; white-space: pre-wrap; font-size: 13px; line-height: 1.8; }.answer-reveal small { color: var(--muted); font-size: 10px; line-height: 1.6; }.quality-section { display: flex; flex-direction: column; gap: 13px; margin-top: 18px; padding-top: 17px; border-top: 1px solid var(--line); }.quality-section .block-label { letter-spacing: 0; text-transform: none; color: var(--text); font-size: 12px; }.quality-section > div:first-child small { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }.quality-options { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }.quality-option { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 9px 4px; color: var(--muted-strong); background: var(--surface-soft); border: 1px solid var(--line); border-radius: 6px; }.quality-option:hover { color: var(--blue); border-color: var(--blue); background: var(--blue-soft); }.quality-option strong { font-size: 16px; }.quality-option small { font-size: 10px; }.saved-message { display: flex; align-items: center; gap: 10px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }.saved-message > svg { width: 22px; color: var(--teal); }.saved-message div { display: flex; flex-direction: column; flex: 1; }.saved-message small { color: var(--muted); font-size: 11px; }.stats-metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }.stats-metrics > div { padding: 13px; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 6px; }.stats-metrics small, .stats-metrics strong { display: block; }.stats-metrics small { color: var(--muted); font-size: 11px; }.stats-metrics strong { margin-top: 6px; font-size: 22px; font-weight: 600; }.stats-section { margin-top: 22px; }.stats-section-title { display: flex; align-items: baseline; justify-content: space-between; padding-bottom: 8px; border-bottom: 1px solid var(--line); }.stats-section-title small { color: var(--muted); font-size: 10px; }.recent-row { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line); }.recent-row > div { display: flex; flex-direction: column; min-width: 0; }.recent-row strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }.recent-row small { margin-top: 3px; color: var(--muted); font-size: 10px; }.quality-chip { display: grid; place-items: center; width: 38px; height: 26px; color: var(--blue); background: var(--blue-soft); border-radius: 5px; font-size: 11px; font-weight: 700; }.stats-empty { padding: 32px 0; color: var(--muted); text-align: center; font-size: 12px; }
.toast { position: fixed; z-index: 100; right: 22px; bottom: 22px; max-width: min(360px, calc(100vw - 44px)); padding: 10px 14px; color: #fff; background: #202831; border-radius: 6px; box-shadow: var(--shadow); font-size: 12px; opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity .18s ease, transform .18s ease; }.toast.is-visible { opacity: 1; transform: translateY(0); }.toast[data-tone="error"] { background: var(--coral); }.toast[data-tone="success"] { background: var(--teal); }

@media (max-width: 1180px) { .app-body { grid-template-columns: 222px minmax(0, 1fr) 305px; }.topbar { padding: 0 16px; }.brand { min-width: 158px; }.search-box { width: min(350px, 36vw); }.search-results { right: 115px; width: min(350px, 36vw); } }
@media (max-width: 980px) {
  body.has-mobile-drawer { overflow: hidden; }
  .app-body { grid-template-columns: minmax(0, 1fr); }
  .mobile-nav-button { display: inline-flex; }
  .chapter-sidebar { display: flex; position: fixed; z-index: 85; inset: 0 auto 0 0; width: min(88vw, 360px); border-right: 1px solid var(--line); box-shadow: var(--shadow); transform: translateX(-105%); transition: transform .2s ease; }
  .chapter-sidebar.is-open { transform: translateX(0); }
  .chapters-close { display: inline-flex; }
  .mobile-scrim:not([hidden]) { display: block; position: fixed; z-index: 80; inset: 0; width: 100%; height: 100%; padding: 0; background: rgba(11, 16, 22, .48); }
  .inspector { position: fixed; z-index: 90; top: 66px; right: 0; bottom: 0; width: min(410px, 96vw); box-shadow: var(--shadow); transform: translateX(100%); transition: transform .2s ease; }
  .inspector.is-open { transform: translateX(0); }
  .mobile-only { display: inline-flex; }
  .mobile-button-text { display: inline; font-size: 11px; font-weight: 600; }
  .desktop-button-text { display: none; }
  #sync-button, #theme-button { width: auto; min-width: 48px; padding: 0 8px; }
  #random-button { min-width: 52px; padding: 0 9px; }
  .workspace-header { padding: 0 14px; }
  .workspace-actions { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
  .workspace-actions::-webkit-scrollbar { display: none; }
  .workspace-actions .icon-button { width: auto; min-width: 48px; padding: 0 8px; }
  .map-legend { right: 12px; bottom: 12px; gap: 7px; }
  .map-hint { left: 12px; bottom: 12px; }
}
@media (max-width: 860px) { .tree-action .desktop-button-text { display: none; }.tree-action .mobile-button-text { display: inline; }.tree-action { width: auto; min-width: 48px; padding: 0 8px; } }
@media (max-width: 720px) {
  html, body { min-height: 100%; }
  body { min-height: 100dvh; overscroll-behavior: none; }
  body.has-mobile-drawer { overflow: hidden; }
  .app-shell { min-height: 100dvh; }
  .topbar { position: sticky; top: 0; height: auto; min-height: 0; flex-wrap: wrap; gap: 8px; padding: max(8px, env(safe-area-inset-top)) 10px 9px; }
  .brand { min-width: 0; flex: 1; }
  .brand-mark { width: 32px; height: 32px; font-size: 16px; }
  .brand-copy small { display: none; }
  .mobile-nav-button { display: inline-flex; height: 34px; padding: 0 10px; }
  .mobile-nav-button span { display: inline; }
  .topbar-actions { order: 3; flex-basis: 100%; justify-content: stretch; gap: 6px; }
  .search-box { width: auto; min-width: 0; flex: 1; height: 36px; }
  .search-box kbd { display: none; }
  .search-results { position: fixed; top: 94px; left: 10px; right: 10px; width: auto; max-height: 45dvh; }
  #random-button { width: auto; min-width: 52px; padding: 0 9px; }
  #random-button .desktop-button-text { display: none; }
  #random-button .mobile-button-text { display: inline; }
  #sync-button, #theme-button { width: auto; min-width: 48px; flex: 0 0 auto; padding: 0 7px; }
  .app-body { grid-template-columns: 1fr; min-height: calc(100dvh - 94px); padding-bottom: calc(58px + env(safe-area-inset-bottom)); }
  .chapter-sidebar { display: flex; position: fixed; z-index: 85; inset: 0 auto 0 0; width: min(88vw, 360px); padding-top: env(safe-area-inset-top); border-right: 1px solid var(--line); box-shadow: var(--shadow); transform: translateX(-105%); transition: transform .2s ease; }
  .chapter-sidebar.is-open { transform: translateX(0); }
  .chapters-close { display: inline-flex; }
  .sidebar-heading { padding-top: 14px; }
  .chapter-item { min-height: 58px; }
  .mobile-scrim:not([hidden]) { display: block; position: fixed; z-index: 80; inset: 0; width: 100%; height: 100%; padding: 0; background: rgba(11, 16, 22, .48); }
  .workspace-header { min-height: 0; flex-wrap: wrap; gap: 7px; padding: 8px 10px; }
  .breadcrumbs { order: 1; width: 100%; min-height: 24px; font-size: 11px; }
  .workspace-actions { order: 2; width: 100%; gap: 4px; overflow-x: auto; padding-bottom: 1px; scrollbar-width: none; }
  .workspace-actions::-webkit-scrollbar { display: none; }
  .workspace-actions .icon-button { width: auto; min-width: 48px; padding: 0 8px; }
  .tree-action { width: auto; min-width: 48px; padding: 0 8px; }
  .tree-action .desktop-button-text { display: none; }
  .tree-action .mobile-button-text { display: inline; }
  .segmented-control { margin-right: auto; flex: 0 0 auto; }
  .segment { min-height: 30px; padding: 0 8px; }
  .map-stage, #mindmap, .outline-stage { min-height: calc(100dvh - 232px); }
  .map-stage { touch-action: none; }
  .map-legend { display: none; }
  .map-hint { left: 8px; right: 8px; bottom: calc(64px + env(safe-area-inset-bottom)); justify-content: center; max-width: none; padding: 6px 8px; font-size: 10px; text-align: center; }
  .outline-stage { padding: 14px 10px 80px; }
  .outline-tree ul { padding-left: 12px; }
  .outline-group-button, .outline-point { min-height: 44px; padding: 9px 7px; }
  .outline-point span:last-child { white-space: normal; line-height: 1.55; }
  .inspector { z-index: 95; top: 0; left: 0; width: 100%; max-width: none; padding-top: env(safe-area-inset-top); border: 0; transform: translateY(105%); transition: transform .22s ease; }
  .inspector.is-open { transform: translateY(0); }
  .inspector-topline { position: sticky; z-index: 2; top: 0; padding: 14px 16px 10px; background: var(--surface); border-bottom: 1px solid var(--line); }
  .inspector-content { padding: 14px 16px max(32px, env(safe-area-inset-bottom)); }
  .inspector-empty { padding: 30dvh 15px 60px; }
  .detail-heading h1 { font-size: 20px; }
  .source-text { font-size: 15px; line-height: 1.9; }
  .citation-text { font-size: 12px; }
  .modal-backdrop { align-items: end; padding: 0; }
  .quiz-dialog, .stats-dialog { width: 100%; max-height: 94dvh; border-radius: 14px 14px 0 0; border-bottom: 0; padding-bottom: env(safe-area-inset-bottom); }
  .dialog-header { position: sticky; z-index: 2; top: 0; background: var(--surface); }
  .quality-options { grid-template-columns: repeat(3, 1fr); }
  .quality-option { min-height: 48px; }
  .stats-metrics { grid-template-columns: repeat(2, 1fr); }
  .dialog-header, .quiz-body, .stats-body { padding-left: 16px; padding-right: 16px; }
  .mobile-bottom-bar { position: fixed; z-index: 70; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr); min-height: calc(58px + env(safe-area-inset-bottom)); padding: 5px 4px env(safe-area-inset-bottom); background: color-mix(in srgb, var(--surface) 96%, transparent); border-top: 1px solid var(--line); box-shadow: 0 -8px 24px rgba(22, 31, 43, .08); backdrop-filter: blur(12px); }
  .mobile-bottom-bar button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; min-width: 0; min-height: 48px; padding: 3px 1px; color: var(--muted); background: transparent; border-radius: 7px; }
  .mobile-bottom-bar button.is-active { color: var(--blue); background: var(--blue-soft); }
  .mobile-bottom-bar strong { font-size: 14px; line-height: 1.2; }
  .mobile-bottom-bar small { overflow: hidden; max-width: 100%; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
  .toast { right: 10px; bottom: calc(70px + env(safe-area-inset-bottom)); max-width: calc(100vw - 20px); }
}
