:root {
  color-scheme: light;
  --page: #f4f6f4;
  --surface: #ffffff;
  --surface-muted: #f0f3f0;
  --surface-strong: #e4eae5;
  --ink: #17201c;
  --ink-soft: #5d6963;
  --line: #d7ded9;
  --line-strong: #bcc8c0;
  --brand: #087f68;
  --brand-strong: #056552;
  --brand-soft: #e2f3ed;
  --info: #356ca8;
  --info-soft: #ebf3fc;
  --warning: #a65b18;
  --warning-soft: #fff1df;
  --danger: #b43d3d;
  --danger-soft: #ffefee;
  --shadow: 0 10px 32px rgba(23, 32, 28, 0.09);
  --topbar-height: 66px;
  --sidebar-width: 272px;
  --context-width: 292px;
  --reader-scale: 1;
  --radius: 6px;
  --font: Inter, "Noto Sans SC", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #171b19;
  --surface: #202522;
  --surface-muted: #292f2b;
  --surface-strong: #343c37;
  --ink: #eef2ef;
  --ink-soft: #aeb8b2;
  --line: #3a433e;
  --line-strong: #566259;
  --brand: #4bc3a1;
  --brand-strong: #76d7bb;
  --brand-soft: #193a31;
  --info: #91bdec;
  --info-soft: #22364b;
  --warning: #f0ac5d;
  --warning-soft: #422e1b;
  --danger: #ff8985;
  --danger-soft: #442626;
  --shadow: 0 12px 34px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  font-size: calc(15px * var(--reader-scale));
  line-height: 1.72;
  letter-spacing: 0;
}

button, input, select, textarea { font: inherit; letter-spacing: 0; }

button, a { -webkit-tap-highlight-color: transparent; }

a { color: var(--brand-strong); }

img { display: block; max-width: 100%; }

svg { flex: 0 0 auto; }

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--brand) 38%, transparent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  z-index: 300;
  top: 8px;
  left: 8px;
  padding: 8px 12px;
  border-radius: 4px;
  background: var(--ink);
  color: var(--surface);
  transform: translateY(-160%);
}

.skip-link:focus { transform: translateY(0); }

.topbar {
  position: sticky;
  z-index: 80;
  top: 0;
  height: var(--topbar-height);
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(260px, 480px) minmax(430px, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px);
}

.brand-area,
.brand,
.brand-copy,
.top-actions,
.global-search,
.top-navigation,
.top-navigation a,
.icon-button,
.button,
.meta-row,
.status-badge,
.chapter-meta,
.reference-meta,
.dialog-header,
.search-input-wrap,
.search-filters,
.pager,
.view-title-row,
.field-row,
.source-status,
.media-link,
.toast {
  display: flex;
  align-items: center;
}

.brand-area { min-width: 0; gap: 6px; }

.brand {
  min-width: 0;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  place-items: center;
  border-radius: 5px;
  background: var(--ink);
  color: var(--surface);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.brand-copy {
  min-width: 0;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.25;
}

.brand-copy strong,
.brand-copy small {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-copy strong { font-size: 14px; }
.brand-copy small { margin-top: 3px; color: var(--ink-soft); font-size: 11px; }

.global-search {
  width: 100%;
  height: 40px;
  gap: 9px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-muted);
  color: var(--ink-soft);
  cursor: pointer;
  text-align: left;
}

.global-search:hover { border-color: var(--line-strong); background: var(--surface); }

.global-search span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.global-search kbd {
  margin-left: auto;
  padding: 1px 6px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 11px;
  font-family: var(--font);
  white-space: nowrap;
}

.top-navigation {
  min-width: 0;
  justify-content: center;
  align-self: stretch;
  gap: 2px;
}

.top-navigation a {
  min-width: 0;
  height: 100%;
  gap: 6px;
  padding: 0 9px;
  border-bottom: 2px solid transparent;
  color: var(--ink-soft);
  text-decoration: none;
  white-space: nowrap;
}

.top-navigation a:hover { color: var(--ink); }
.top-navigation a.active { border-bottom-color: var(--brand); color: var(--ink); font-weight: 700; }
.top-navigation svg { width: 16px; height: 16px; }

.top-actions { gap: 2px; }

.icon-button {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  justify-content: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}

.icon-button:hover { border-color: var(--line); background: var(--surface-muted); color: var(--ink); }
.icon-button svg { width: 18px; height: 18px; }

.font-indicator {
  min-width: 34px;
  justify-content: center;
  color: var(--ink-soft);
  font-size: 11px;
}

.mobile-only { display: none; }

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr) var(--context-width);
  align-items: start;
  width: min(100%, 1760px);
  min-height: calc(100vh - var(--topbar-height));
  margin: 0 auto;
  background: var(--surface);
}

.primary-sidebar,
.context-panel {
  position: sticky;
  top: var(--topbar-height);
  height: calc(100vh - var(--topbar-height));
  overflow-y: auto;
  scrollbar-width: thin;
  background: var(--surface);
}

.primary-sidebar { border-right: 1px solid var(--line); }
.context-panel { border-left: 1px solid var(--line); }
.main-content { min-width: 0; min-height: calc(100vh - var(--topbar-height)); background: var(--surface); }

.sidebar-overlay {
  position: fixed;
  z-index: 89;
  inset: 0;
  display: none;
  border: 0;
  background: rgba(12, 18, 15, 0.56);
}

.sidebar-header,
.context-section {
  padding: 18px 16px;
  border-bottom: 1px solid var(--line);
}

.sidebar-header h2,
.context-section h2 { margin: 0; font-size: 14px; line-height: 1.4; }

.eyebrow,
.dialog-kicker {
  margin: 0 0 5px;
  color: var(--brand-strong);
  font-size: 11px;
  font-weight: 750;
}

.sidebar-summary { margin: 7px 0 0; color: var(--ink-soft); font-size: 12px; }

.view-switcher {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  padding: 8px;
  border-bottom: 1px solid var(--line);
  gap: 3px;
}

.view-switcher a {
  display: grid;
  min-width: 0;
  min-height: 42px;
  place-items: center;
  padding: 5px 2px;
  border-radius: 4px;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 10px;
  line-height: 1.2;
}

.view-switcher a:hover { background: var(--surface-muted); color: var(--ink); }
.view-switcher a.active { background: var(--brand-soft); color: var(--brand-strong); font-weight: 700; }
.view-switcher svg { width: 16px; height: 16px; margin-bottom: 3px; }

.progress-label {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  color: var(--ink-soft);
  font-size: 12px;
}

.progress-label strong { color: var(--ink); }

.progress-track {
  height: 6px;
  margin-top: 7px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--surface-strong);
}

.progress-value {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--brand);
  transition: width 180ms ease;
}

.phase-group { border-bottom: 1px solid var(--line); }

.phase-group > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 15px 8px;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 11px;
  font-weight: 750;
  list-style: none;
}

.phase-group > summary::-webkit-details-marker { display: none; }
.phase-group > summary span:last-child { white-space: nowrap; }

.chapter-list,
.filter-list,
.context-nav,
.source-list,
.task-list,
.plain-list,
.reference-list,
.favorite-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.chapter-list { padding: 0 8px 10px; }

.chapter-link {
  width: 100%;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) 18px;
  align-items: start;
  gap: 8px;
  padding: 9px 8px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  text-align: left;
  line-height: 1.45;
}

.chapter-link:hover { background: var(--surface-muted); color: var(--ink); }
.chapter-link.active { background: var(--brand-soft); color: var(--ink); font-weight: 680; }

.chapter-number {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  font-size: 10px;
  line-height: 1;
}

.chapter-link.active .chapter-number { border-color: var(--brand); background: var(--brand); color: #fff; }
.chapter-link.complete .chapter-number { border-color: var(--brand); color: var(--brand-strong); }
.chapter-link.complete .chapter-state { color: var(--brand); }
.chapter-state { padding-top: 2px; color: var(--line-strong); }

.sidebar-controls { padding: 14px 12px; border-bottom: 1px solid var(--line); }

.search-small {
  position: relative;
}

.search-small svg {
  position: absolute;
  top: 50%;
  left: 10px;
  width: 16px;
  height: 16px;
  color: var(--ink-soft);
  transform: translateY(-50%);
  pointer-events: none;
}

.search-small input,
.field select {
  width: 100%;
  min-height: 39px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface-muted);
  color: var(--ink);
}

.search-small input { padding: 7px 9px 7px 34px; }
.field select { padding: 7px 28px 7px 9px; }

.field { margin-top: 10px; }
.field label { display: block; margin-bottom: 4px; color: var(--ink-soft); font-size: 11px; font-weight: 700; }

.filter-list { padding: 8px; }

.filter-button {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 8px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  text-align: left;
}

.filter-button:hover { background: var(--surface-muted); color: var(--ink); }
.filter-button.active { background: var(--brand-soft); color: var(--brand-strong); font-weight: 700; }
.filter-count { color: var(--ink-soft); font-size: 11px; }

.reader,
.collection-view,
.reference-detail,
.favorites-view,
.system-message {
  width: min(100%, 930px);
  margin: 0 auto;
  padding: 30px 42px 76px;
}

.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 0 0 20px;
  color: var(--ink-soft);
  font-size: 12px;
}

.breadcrumbs a { color: inherit; text-decoration: none; }
.breadcrumbs a:hover { color: var(--brand-strong); text-decoration: underline; }

.content-header {
  padding-bottom: 27px;
  border-bottom: 1px solid var(--line);
}

.content-header h1,
.view-header h1 {
  max-width: 820px;
  margin: 0;
  font-size: 38px;
  line-height: 1.22;
  letter-spacing: 0;
}

.content-lead,
.view-header > p {
  max-width: 780px;
  margin: 13px 0 0;
  color: var(--ink-soft);
  font-size: 16px;
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 11px;
}

.status-badge {
  min-height: 25px;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--surface-muted);
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 700;
}

.status-badge.verified { background: var(--brand-soft); color: var(--brand-strong); }
.status-badge.warning { background: var(--warning-soft); color: var(--warning); }
.status-badge.info { background: var(--info-soft); color: var(--info); }
.status-badge.danger { background: var(--danger-soft); color: var(--danger); }
.status-badge svg { width: 14px; height: 14px; }

.chapter-meta,
.reference-meta {
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 18px;
  color: var(--ink-soft);
  font-size: 12px;
}

.chapter-meta span,
.reference-meta span { display: inline-flex; align-items: center; gap: 5px; }
.chapter-meta svg,
.reference-meta svg { width: 15px; height: 15px; }

.lesson-section {
  scroll-margin-top: calc(var(--topbar-height) + 16px);
  padding: 32px 0;
  border-bottom: 1px solid var(--line);
}

.section-title {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: start;
  gap: 12px;
  margin-bottom: 17px;
}

.section-index {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 5px;
  background: var(--ink);
  color: var(--surface);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.section-title h2 { margin: 0; font-size: 22px; line-height: 1.35; }
.section-title p { margin: 3px 0 0; color: var(--ink-soft); font-size: 12px; }

.section-body,
.reference-section { overflow-wrap: anywhere; }

.section-body > :first-child { margin-top: 0; }
.section-body > :last-child { margin-bottom: 0; }
.section-body p { margin: 0 0 13px; }
.section-body ul,
.section-body ol { margin: 0 0 15px; padding-left: 25px; }
.section-body li { margin: 7px 0; }

code {
  padding: 2px 5px;
  border-radius: 3px;
  background: var(--surface-muted);
  color: var(--ink);
  font-family: var(--font);
  font-size: 0.92em;
  font-weight: 650;
  overflow-wrap: anywhere;
}

pre {
  max-width: 100%;
  margin: 14px 0;
  overflow-x: auto;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface-muted);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
}

pre code { padding: 0; background: transparent; font-family: Consolas, "Microsoft YaHei", monospace; font-weight: 400; }

blockquote {
  margin: 16px 0;
  padding: 12px 15px;
  border-left: 3px solid var(--info);
  background: var(--info-soft);
  color: var(--ink);
}

.table-wrap { max-width: 100%; overflow-x: auto; margin: 14px 0; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--surface-muted); color: var(--ink); font-weight: 700; }

.task-list { display: grid; gap: 0; }

.task-item {
  display: grid;
  grid-template-columns: 22px 34px minmax(0, 1fr);
  align-items: start;
  gap: 9px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.task-item:last-child { border-bottom: 0; }
.task-item.simple { grid-template-columns: 22px 34px minmax(0, 1fr); }

.task-item input {
  grid-column: 1;
  width: 18px;
  height: 18px;
  margin: 3px 0 0;
  accent-color: var(--brand);
  cursor: pointer;
}

.task-item label {
  grid-column: 3;
  min-width: 0;
  overflow-wrap: anywhere;
  cursor: pointer;
}
.task-item input:checked ~ label { color: var(--ink-soft); text-decoration: line-through; }

.task-number {
  grid-column: 2;
  display: grid;
  width: 31px;
  height: 31px;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-muted);
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 750;
  line-height: 1;
}

.task-item:has(input:checked) .task-number { background: var(--brand); color: #fff; }

.example-callout,
.type-notice {
  padding: 18px;
  border-left: 4px solid var(--warning);
  background: var(--warning-soft);
}

.example-callout > :first-child,
.type-notice > :first-child { margin-top: 0; }
.example-callout > :last-child,
.type-notice > :last-child { margin-bottom: 0; }

.type-notice.info { border-left-color: var(--info); background: var(--info-soft); }
.type-notice.danger { border-left-color: var(--danger); background: var(--danger-soft); }

.media-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.media-card,
.reference-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.media-card button {
  width: 100%;
  display: block;
  padding: 0;
  border: 0;
  background: var(--surface-muted);
  cursor: zoom-in;
}

.media-card img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  background: var(--surface-muted);
}

.media-card-copy { padding: 11px 12px; }
.media-card-copy strong { display: block; font-size: 13px; }
.media-card-copy span { display: block; margin-top: 3px; color: var(--ink-soft); font-size: 11px; }

.video-card {
  min-height: 180px;
  display: grid;
  place-items: center;
  padding: 20px;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--surface);
  text-align: center;
  text-decoration: none;
}

.video-card:hover { background: color-mix(in srgb, var(--ink) 88%, var(--brand)); }
.video-card svg { width: 38px; height: 38px; margin: 0 auto 7px; color: var(--warning); }
.video-card strong { display: block; }
.video-card span { display: block; margin-top: 4px; color: color-mix(in srgb, var(--surface) 70%, transparent); font-size: 11px; }

.media-resource-list { margin-top: 12px; }
.media-link { gap: 7px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.media-link svg { width: 16px; height: 16px; }

.source-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 13px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.source-list li:last-child { border-bottom: 0; }
.source-list a { color: var(--ink); font-weight: 680; text-decoration: none; }
.source-list a:hover { color: var(--brand-strong); text-decoration: underline; }
.source-list small { display: block; margin-top: 2px; color: var(--ink-soft); }
.source-status { gap: 5px; color: var(--brand-strong); font-size: 11px; font-weight: 700; white-space: nowrap; }

.article-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-top: 28px;
}

.button {
  min-height: 40px;
  justify-content: center;
  gap: 7px;
  padding: 7px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-weight: 680;
  text-decoration: none;
}

.button:hover { border-color: var(--ink); }
.button.primary { border-color: var(--brand); background: var(--brand); color: #fff; }
.button.primary:hover { background: var(--brand-strong); }
.button.soft { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-strong); }
.button.danger { border-color: var(--danger); background: var(--danger); color: #fff; }
.button.ghost { border-color: transparent; background: transparent; color: var(--ink-soft); }
.button svg { width: 17px; height: 17px; }
.button.full { width: 100%; }

.context-section h2 { margin-bottom: 10px; }
.progress-big { font-size: 28px; font-weight: 800; line-height: 1; }
.progress-big small { color: var(--ink-soft); font-size: 11px; font-weight: 500; }

.context-nav { display: grid; gap: 2px; }
.context-nav a,
.context-nav button {
  width: 100%;
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 7px;
  padding: 7px 8px;
  border-top: 0;
  border-right: 0;
  border-bottom: 0;
  border-left: 2px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  text-decoration: none;
  text-align: left;
  font-size: 11px;
  line-height: 1.45;
}
.context-nav a:hover,
.context-nav button:hover { background: var(--surface-muted); color: var(--ink); }
.context-nav a.active,
.context-nav button.active { border-left-color: var(--brand); background: var(--brand-soft); color: var(--ink); font-weight: 700; }

.facts { display: grid; gap: 9px; }
.fact { display: grid; grid-template-columns: 18px minmax(0, 1fr); gap: 7px; align-items: start; color: var(--ink-soft); font-size: 11px; }
.fact svg { width: 16px; height: 16px; margin-top: 2px; color: var(--brand); }
.context-actions { display: grid; gap: 8px; }

.view-header { padding-bottom: 24px; border-bottom: 1px solid var(--line); }
.view-title-row { justify-content: space-between; gap: 14px; align-items: flex-start; }
.view-title-row .button { flex: 0 0 auto; }

.collection-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(190px, 260px);
  gap: 10px;
  padding: 18px 0;
}

.collection-toolbar .field { margin: 0; }

.collection-summary {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  color: var(--ink-soft);
  font-size: 12px;
}

.reference-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }

.reference-card {
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 17px;
}

.reference-card:hover { border-color: var(--line-strong); box-shadow: 0 5px 18px rgba(23, 32, 28, 0.06); }
.reference-card h2 { margin: 9px 0 4px; font-size: 17px; line-height: 1.4; }
.reference-card h2 a { color: var(--ink); text-decoration: none; }
.reference-card h2 a:hover { color: var(--brand-strong); }
.reference-card .en-title { margin: 0; color: var(--ink-soft); font-size: 11px; overflow-wrap: anywhere; }
.reference-card .purpose { display: -webkit-box; margin: 11px 0; overflow: hidden; color: var(--ink-soft); font-size: 13px; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.reference-card footer { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--line); }
.reference-card footer a { font-size: 12px; font-weight: 700; text-decoration: none; }

.reference-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.reference-id { color: var(--ink-soft); font-size: 11px; }

.bookmark-button {
  width: 34px;
  height: 34px;
  display: inline-grid;
  flex: 0 0 34px;
  place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}

.bookmark-button:hover { border-color: var(--line); background: var(--surface-muted); color: var(--ink); }
.bookmark-button.active { background: var(--warning-soft); color: var(--warning); }
.bookmark-button svg { width: 17px; height: 17px; }

.pager { justify-content: center; flex-wrap: wrap; gap: 5px; margin-top: 22px; }
.pager button { min-width: 36px; min-height: 36px; padding: 5px 9px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); color: var(--ink); cursor: pointer; }
.pager button:hover { border-color: var(--line-strong); }
.pager button.active { border-color: var(--brand); background: var(--brand); color: #fff; font-weight: 700; }
.pager button:disabled { opacity: .45; cursor: not-allowed; }
.pager .ellipsis { min-width: 30px; color: var(--ink-soft); text-align: center; }

.empty-state {
  padding: 48px 20px;
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  text-align: center;
}
.empty-state svg { width: 34px; height: 34px; margin: 0 auto 10px; color: var(--line-strong); }
.empty-state h2 { margin: 0 0 5px; color: var(--ink); font-size: 18px; }
.empty-state p { margin: 0; }

.reference-detail .content-header { margin-bottom: 0; }
.reference-section { padding: 27px 0; border-bottom: 1px solid var(--line); scroll-margin-top: calc(var(--topbar-height) + 15px); }
.reference-section h2 { margin: 0 0 13px; font-size: 21px; }
.reference-section > :last-child { margin-bottom: 0; }
.reference-section p { margin: 0 0 12px; }
.reference-section ol { margin: 0; padding-left: 25px; }
.reference-section li { margin: 9px 0; }

.source-box { padding: 17px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-muted); }
.source-box a { display: inline-flex; align-items: center; gap: 6px; color: var(--ink); font-weight: 700; overflow-wrap: anywhere; }
.source-box dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 12px; margin: 14px 0 0; font-size: 12px; }
.source-box dt { color: var(--ink-soft); }
.source-box dd { margin: 0; overflow-wrap: anywhere; }

.favorite-group { padding: 25px 0; border-bottom: 1px solid var(--line); }
.favorite-group h2 { margin: 0 0 12px; font-size: 20px; }
.favorite-list { display: grid; gap: 7px; }
.favorite-item { display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.favorite-item:last-child { border-bottom: 0; }
.favorite-item > svg { width: 19px; height: 19px; color: var(--brand); }
.favorite-item a { color: var(--ink); font-weight: 680; text-decoration: none; }
.favorite-item a:hover { color: var(--brand-strong); text-decoration: underline; }
.favorite-item small { display: block; color: var(--ink-soft); }

.system-message { padding-top: 70px; text-align: center; }
.system-message h1 { margin: 0; font-size: 28px; }
.system-message p { max-width: 600px; margin: 10px auto; color: var(--ink-soft); }

dialog {
  width: min(760px, calc(100vw - 28px));
  max-height: min(820px, calc(100vh - 28px));
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 72px rgba(0, 0, 0, .27);
}

dialog::backdrop { background: rgba(12, 18, 15, 0.58); backdrop-filter: blur(3px); }

.dialog-header { justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 0; font-size: 18px; }

.search-input-wrap { position: relative; gap: 9px; margin: 14px 16px 10px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 5px; background: var(--surface-muted); }
.search-input-wrap svg { width: 18px; height: 18px; color: var(--ink-soft); }
.search-input-wrap input { width: 100%; height: 46px; padding: 0; border: 0; outline: 0; background: transparent; color: var(--ink); }

.search-filters { gap: 5px; padding: 0 16px 10px; overflow-x: auto; }
.search-filters button { flex: 0 0 auto; padding: 5px 9px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); color: var(--ink-soft); cursor: pointer; font-size: 12px; }
.search-filters button[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-strong); font-weight: 700; }

.search-summary { min-height: 27px; padding: 0 16px 8px; color: var(--ink-soft); font-size: 11px; }
.search-results { max-height: 540px; overflow-y: auto; padding: 0 8px 12px; }

.search-result {
  width: 100%;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 11px 9px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.search-result:hover { background: var(--surface-muted); }
.search-result-icon { display: grid; width: 32px; height: 32px; place-items: center; border-radius: 4px; background: var(--brand-soft); color: var(--brand-strong); }
.search-result-icon svg { width: 16px; height: 16px; }
.search-result-title { display: block; font-weight: 700; }
.search-result-subtitle { display: block; overflow: hidden; color: var(--ink-soft); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.search-result-type { color: var(--ink-soft); font-size: 11px; white-space: nowrap; }

.image-dialog { width: min(1120px, calc(100vw - 28px)); background: #111; color: #fff; border-color: #3a3a3a; }
.image-dialog-header { border-color: #333; }
.image-dialog .icon-button { color: #fff; }
.image-dialog figure { margin: 0; }
.image-dialog img { width: 100%; max-height: calc(100vh - 145px); object-fit: contain; background: #111; }
.image-dialog figcaption { padding: 11px 16px; color: #d7ddd9; font-size: 12px; }

.confirm-dialog { width: min(480px, calc(100vw - 28px)); padding: 20px; }
.confirm-copy { text-align: center; }
.confirm-copy > svg { width: 35px; height: 35px; color: var(--danger); }
.confirm-copy h2 { margin: 8px 0 4px; font-size: 20px; }
.confirm-copy p { margin: 0; color: var(--ink-soft); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

.toast {
  position: fixed;
  z-index: 200;
  left: 50%;
  bottom: 22px;
  max-width: min(520px, calc(100vw - 28px));
  justify-content: center;
  padding: 9px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--ink);
  color: var(--surface);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 160ms ease, transform 160ms ease;
  font-size: 12px;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

.back-to-top {
  position: fixed;
  z-index: 60;
  right: calc(var(--context-width) + 18px);
  bottom: 18px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}
.back-to-top.visible { opacity: 1; pointer-events: auto; }

@media (max-width: 1320px) {
  :root { --sidebar-width: 250px; --context-width: 260px; }
  .topbar { grid-template-columns: var(--sidebar-width) minmax(250px, 1fr) auto; }
  .top-navigation { display: none; }
  .reader, .collection-view, .reference-detail, .favorites-view { padding-inline: 30px; }
}

@media (max-width: 1080px) {
  .app-shell { grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
  .context-panel { position: static; grid-column: 2; height: auto; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 0; }
  .context-section { border-right: 1px solid var(--line); }
  .context-section:nth-child(even) { border-right: 0; }
  .back-to-top { right: 18px; }
}

@media (max-width: 820px) {
  :root { --topbar-height: 60px; --sidebar-width: 270px; }
  .topbar { grid-template-columns: auto minmax(0, 1fr) auto; gap: 7px; padding: 0 9px; }
  .mobile-only { display: inline-flex; }
  .brand-copy { display: none; }
  .brand-mark { width: 34px; height: 34px; flex-basis: 34px; }
  .global-search { height: 38px; }
  .global-search kbd { display: none; }
  .top-actions .icon-button:not(#theme-toggle) { display: none; }
  .font-indicator { display: none; }
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .primary-sidebar { position: fixed; z-index: 95; top: 0; left: 0; width: min(var(--sidebar-width), calc(100vw - 46px)); height: 100vh; transform: translateX(-102%); transition: transform 180ms ease; box-shadow: var(--shadow); }
  body.nav-open { overflow: hidden; }
  body.nav-open .primary-sidebar { transform: translateX(0); }
  body.nav-open .sidebar-overlay { display: block; }
  .context-panel { grid-column: 1; grid-template-columns: 1fr 1fr; }
  .reader, .collection-view, .reference-detail, .favorites-view, .system-message { padding: 23px 20px 54px; }
  .content-header h1, .view-header h1 { font-size: 32px; }
  .content-lead, .view-header > p { font-size: 15px; }
  .reference-list { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .global-search span { font-size: 12px; }
  .reader, .collection-view, .reference-detail, .favorites-view, .system-message { padding-inline: 17px; }
  .content-header h1, .view-header h1 { font-size: 29px; }
  .view-title-row { align-items: stretch; flex-direction: column; }
  .view-title-row .button { width: 100%; }
  .section-title { grid-template-columns: 32px minmax(0, 1fr); gap: 10px; }
  .section-title h2 { font-size: 20px; }
  .media-grid { grid-template-columns: 1fr; }
  .task-item { grid-template-columns: 21px 30px minmax(0, 1fr); gap: 7px; }
  .task-item.simple { grid-template-columns: 21px 30px minmax(0, 1fr); }
  .task-number { width: 28px; height: 28px; }
  .article-footer { flex-direction: column; }
  .article-footer .button { width: 100%; }
  .collection-toolbar { grid-template-columns: 1fr; }
  .source-list li { grid-template-columns: 1fr; gap: 5px; }
  .source-status { justify-self: start; }
  .context-panel { grid-template-columns: 1fr; }
  .context-section { border-right: 0; }
  .search-result { grid-template-columns: 34px minmax(0, 1fr); }
  .search-result-type { grid-column: 2; }
  .favorite-item { grid-template-columns: 26px minmax(0, 1fr); }
  .favorite-item .bookmark-button { grid-column: 2; justify-self: start; }
}

@media (max-width: 400px) {
  .global-search span { display: none; }
  .global-search::after { content: "搜索教程"; color: var(--ink-soft); font-size: 12px; }
  .topbar { grid-template-columns: auto minmax(110px, 1fr) auto; }
  .reader, .collection-view, .reference-detail, .favorites-view { padding-inline: 14px; }
  .content-header h1, .view-header h1 { font-size: 27px; }
  .status-row { gap: 5px; }
  .chapter-meta, .reference-meta { gap: 10px; }
  .section-title { grid-template-columns: 30px minmax(0, 1fr); }
  .section-index { width: 29px; height: 29px; }
  .section-title h2 { font-size: 19px; }
  .source-box dl { grid-template-columns: 1fr; gap: 2px; }
  .source-box dd { margin-bottom: 6px; }
}

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

@media print {
  :root { color-scheme: light; --page: #fff; --surface: #fff; --ink: #111; --ink-soft: #444; --line: #bbb; }
  .topbar, .primary-sidebar, .context-panel, .sidebar-overlay, .article-footer, .bookmark-button, .back-to-top, dialog, .toast { display: none !important; }
  .app-shell { display: block; }
  .reader, .reference-detail { width: 100%; padding: 0; }
  .lesson-section, .reference-section { break-inside: avoid; }
  a { color: #111; text-decoration: underline; }
}
