/* ==========================================================================
   考研数学公式库 · 样式
   设计语言：暖纸底 + 墨色文字 + 三色层级标识
   ========================================================================== */

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --font-serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "SimSun",
    Georgia, "Times New Roman", serif;

  --bg: #f6f2e9;
  --bg-2: #efe9dc;
  --surface: #fffdf8;
  --surface-2: #f3ede1;
  --surface-3: #ebe4d5;
  --ink: #20242c;
  --ink-2: #3f4653;
  --muted: #7a7468;
  --line: #e4dccb;
  --line-strong: #d5cab4;
  --formula-bg: #fbf8f1;

  --accent: #1d4ed8;
  --accent-soft: #e8edfb;
  --gold: #a16207;

  --t1: #b42318;
  --t1-soft: #fef3f2;
  --t1-line: #fecdca;
  --t2: #1d4ed8;
  --t2-soft: #eff4ff;
  --t2-line: #c7d7fe;
  --t3: #047857;
  --t3-soft: #ecfdf3;
  --t3-line: #a6f4c5;

  --shadow-sm: 0 1px 2px rgba(32, 36, 44, 0.05);
  --shadow-md: 0 10px 30px -14px rgba(32, 36, 44, 0.22);
  --shadow-lg: 0 30px 70px -30px rgba(20, 24, 33, 0.45);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;

  --sidebar-w: 258px;
  --topbar-h: 68px;
  --content-max: 1280px;

  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0f141c;
  --bg-2: #131a24;
  --surface: #171f2a;
  --surface-2: #1d2733;
  --surface-3: #253140;
  --ink: #e9e5db;
  --ink-2: #cac5b9;
  --muted: #9097a6;
  --line: #2a3543;
  --line-strong: #3a4757;
  --formula-bg: #121923;

  --accent: #7aa2ff;
  --accent-soft: #1d2c4a;
  --gold: #d9a441;

  --t1: #ff8f85;
  --t1-soft: #351d1d;
  --t1-line: #5c2b2b;
  --t2: #8ab4ff;
  --t2-soft: #1a2942;
  --t2-line: #2f4670;
  --t3: #6ee7b7;
  --t3-soft: #112c25;
  --t3-line: #1f4d3d;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 12px 34px -16px rgba(0, 0, 0, 0.65);
  --shadow-lg: 0 30px 80px -30px rgba(0, 0, 0, 0.8);

  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body.modal-open {
  overflow: hidden;
}

mark {
  padding: 0 1px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--gold) 22%, transparent);
  color: inherit;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.65;
  color: var(--ink);
  background:
    radial-gradient(1100px 620px at 8% -8%, rgba(29, 78, 216, 0.055), transparent 62%),
    radial-gradient(900px 520px at 102% 2%, rgba(180, 35, 24, 0.045), transparent 58%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

[data-theme="dark"] body {
  background:
    radial-gradient(1100px 620px at 8% -8%, rgba(122, 162, 255, 0.08), transparent 62%),
    radial-gradient(900px 520px at 102% 2%, rgba(255, 143, 133, 0.05), transparent 58%),
    var(--bg);
}

::selection {
  background: var(--accent-soft);
  color: var(--ink);
}

a {
  color: var(--accent);
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 200;
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--surface);
  transform: translateY(-200%);
  transition: transform 0.15s ease;
}

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

/* --------------------------------------------------------------------------
   布局
   -------------------------------------------------------------------------- */

.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 24px 16px 18px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  box-shadow: 1px 0 0 rgba(255, 255, 255, 0.6) inset;
}

[data-theme="dark"] .sidebar {
  box-shadow: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(145deg, #24406f, #16233b);
  color: #f8f2e4;
  font-family: var(--font-serif);
  font-size: 24px;
  line-height: 1;
  box-shadow: 0 6px 14px -6px rgba(22, 35, 59, 0.6);
}

[data-theme="dark"] .brand-mark {
  background: linear-gradient(145deg, #34527f, #1d2c45);
}

.brand-title {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.35;
}

.brand-sub {
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-item svg {
  width: 19px;
  height: 19px;
  flex: 0 0 19px;
  color: var(--muted);
  transition: color 0.15s ease;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.nav-item.active svg {
  color: var(--accent);
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: -16px;
  top: 50%;
  width: 3px;
  height: 20px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
  transform: translateY(-50%);
}

.sidebar-foot {
  margin-top: auto;
  padding: 14px 8px 0;
  border-top: 1px solid var(--line);
}

.mini-progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 11.5px;
  color: var(--muted);
}

.mini-progress-head span:last-child {
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
  font-weight: 600;
}

.mini-progress-track {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}

.mini-progress-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #5b8def);
  transition: width 0.35s ease;
}

.sidebar-note {
  margin-top: 10px;
  font-size: 10.5px;
  line-height: 1.5;
  color: var(--muted);
}

.main {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-w);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 28px;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.menu-btn {
  display: none !important;
}

.search-wrap {
  position: relative;
  flex: 1;
  max-width: 620px;
  display: flex;
  align-items: center;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-icon {
  width: 17px;
  height: 17px;
  flex: 0 0 17px;
  color: var(--muted);
}

.search-wrap input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0 10px;
  border: 0;
  background: transparent;
  font-size: 14px;
  outline: none;
}

.search-wrap input::placeholder {
  color: var(--muted);
}

.search-wrap input::-webkit-search-cancel-button {
  cursor: pointer;
}

.search-kbd {
  flex: 0 0 auto;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 10px;
  line-height: 1.5;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.icon-btn {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink-2);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

/* --------------------------------------------------------------------------
   主视图
   -------------------------------------------------------------------------- */

#view {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 34px 36px 96px;
  outline: none;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.eyebrow::before {
  content: "";
  width: 18px;
  height: 1px;
  background: var(--line-strong);
}

.page-title {
  font-family: var(--font-serif);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.25;
}

.page-lead {
  max-width: 720px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.75;
}

.head-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 3px;
}

.stat-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 11.5px;
  white-space: nowrap;
}

.stat-chip b {
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   筛选栏
   -------------------------------------------------------------------------- */

.filterbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 12px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
  background: var(--surface-2);
}

.segmented button {
  padding: 6px 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.segmented button:hover {
  color: var(--ink);
}

.segmented button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

.select-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.select-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 11.5px;
  white-space: nowrap;
}

.select-label select {
  max-width: 150px;
  height: 32px;
  padding: 0 26px 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background-color: var(--surface);
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 14px) 13px, calc(100% - 9px) 13px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  color: var(--ink-2);
  font-size: 12px;
  appearance: none;
  outline: none;
  cursor: pointer;
}

.select-label select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.filter-spacer {
  flex: 1;
}

.filter-reset {
  padding: 6px 10px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
}

.filter-reset:hover {
  color: var(--ink);
  border-color: var(--muted);
}

/* --------------------------------------------------------------------------
   卡片
   -------------------------------------------------------------------------- */

.result-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin: 4px 2px 14px;
  color: var(--muted);
  font-size: 12px;
}

.result-row b {
  color: var(--ink);
  font-weight: 600;
}

.result-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.active-filter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11.5px;
}

.active-filter button {
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 14px;
  line-height: 1;
  padding: 0;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.formula-card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 17px 17px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.formula-card::after {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: var(--tier-color, var(--accent));
  opacity: 0.9;
}

.formula-card:hover {
  transform: translateY(-3px);
  border-color: var(--line-strong);
  box-shadow: var(--shadow-md);
}

.formula-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.formula-card.tier-1 {
  --tier-color: var(--t1);
}
.formula-card.tier-2 {
  --tier-color: var(--t2);
}
.formula-card.tier-3 {
  --tier-color: var(--t3);
}

.card-top {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 24px;
}

.tier-badge {
  display: inline-flex;
  align-items: center;
  height: 21px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.tier-badge.t1 {
  color: var(--t1);
  background: var(--t1-soft);
  border-color: var(--t1-line);
}
.tier-badge.t2 {
  color: var(--t2);
  background: var(--t2-soft);
  border-color: var(--t2-line);
}
.tier-badge.t3 {
  color: var(--t3);
  background: var(--t3-soft);
  border-color: var(--t3-line);
}

.freq-badge {
  display: inline-flex;
  align-items: center;
  height: 21px;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 10.5px;
  white-space: nowrap;
}

.freq-badge.high {
  color: var(--gold);
  border-color: color-mix(in srgb, var(--gold) 35%, var(--line));
  background: color-mix(in srgb, var(--gold) 8%, transparent);
}

.star-btn {
  width: 28px;
  height: 28px;
  margin-left: auto;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--line-strong);
  font-size: 17px;
  line-height: 1;
  transition: color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.star-btn:hover {
  background: var(--surface-2);
  color: var(--gold);
  transform: scale(1.08);
}

.star-btn.on {
  color: var(--gold);
}

.card-kicker {
  margin-top: 9px;
  color: var(--muted);
  font-size: 10.5px;
  letter-spacing: 0.02em;
}

.card-title {
  margin-top: 3px;
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.45;
  letter-spacing: 0.01em;
}

.formula-preview {
  position: relative;
  margin: 11px 0 10px;
  padding: 10px 12px;
  max-height: 96px;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  border-radius: 10px;
  background: var(--formula-bg);
  font-size: 13px;
}

.formula-preview::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 22px;
  background: linear-gradient(to bottom, transparent, var(--formula-bg));
  pointer-events: none;
}

.formula-preview .katex-display {
  margin: 0;
}

.formula-preview .katex {
  font-size: 0.92em;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: auto;
}

.tag {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 10.5px;
  line-height: 1.6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tag.more {
  color: var(--muted);
}

.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 11px;
  padding-top: 9px;
  border-top: 1px dashed var(--line);
  color: var(--muted);
  font-size: 10.5px;
}

.mastery-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.mastery-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--line-strong);
}

.mastery-pill[data-m="1"] .mastery-dot {
  background: var(--t1);
}
.mastery-pill[data-m="2"] .mastery-dot {
  background: var(--gold);
}
.mastery-pill[data-m="3"] .mastery-dot {
  background: var(--t3);
}

.load-more-wrap {
  display: flex;
  justify-content: center;
  margin-top: 28px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease,
    transform 0.15s ease;
}

.btn:hover {
  background: var(--surface-2);
  border-color: var(--line-strong);
  color: var(--ink);
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--surface);
}

.btn.primary:hover {
  background: var(--ink-2);
  border-color: var(--ink-2);
}

.btn.accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

[data-theme="dark"] .btn.accent {
  color: #0d1420;
}

.btn.ghost {
  background: transparent;
}

.btn.sm {
  min-height: 30px;
  padding: 4px 10px;
  font-size: 11.5px;
  border-radius: 8px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* --------------------------------------------------------------------------
   空状态
   -------------------------------------------------------------------------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 76px 24px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-xl);
  background: color-mix(in srgb, var(--surface) 60%, transparent);
  text-align: center;
}

.empty-icon {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--muted);
  font-family: var(--font-serif);
  font-size: 22px;
}

.empty h3 {
  font-family: var(--font-serif);
  font-size: 19px;
}

.empty p {
  max-width: 420px;
  color: var(--muted);
  font-size: 12.5px;
}

/* --------------------------------------------------------------------------
   详情弹窗
   -------------------------------------------------------------------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(16, 21, 30, 0.48);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  animation: fade-in 0.18s ease;
}

.modal-card {
  position: relative;
  width: min(900px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.modal-head {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 20px 26px 16px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.modal-head-top {
  display: flex;
  align-items: center;
  gap: 7px;
  padding-right: 42px;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 18px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
}

.modal-close:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.modal-title {
  margin-top: 10px;
  font-family: var(--font-serif);
  font-size: 27px;
  font-weight: 700;
  line-height: 1.35;
}

.modal-kicker {
  margin-top: 5px;
  color: var(--muted);
  font-size: 11.5px;
}

.modal-body {
  padding: 22px 26px 86px;
}

.katex .cjk_fallback {
  font-family: var(--font-serif);
  font-style: normal;
}

.modal-formula {
  padding: 20px 18px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--formula-bg);
}

.modal-formula .katex-display {
  margin: 0.35em 0;
}

.modal-formula .katex {
  font-size: 1.08em;
}

.detail-section {
  margin-top: 24px;
}

.detail-section h4 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.detail-section h4::before {
  content: "";
  width: 4px;
  height: 13px;
  border-radius: 2px;
  background: var(--accent);
}

.detail-section.conditions h4::before {
  background: var(--gold);
}
.detail-section.pitfalls h4::before {
  background: var(--t1);
}
.detail-section.steps h4::before {
  background: var(--t2);
}
.detail-section.example h4::before {
  background: var(--t3);
}

.bullet-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 7px;
}

.bullet-list li {
  position: relative;
  padding-left: 16px;
  color: var(--ink-2);
  font-size: 13.5px;
  line-height: 1.7;
}

.bullet-list li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 0.72em;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--line-strong);
}

.steps-list {
  counter-reset: step;
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 9px;
}

.steps-list li {
  counter-increment: step;
  position: relative;
  padding: 9px 12px 9px 42px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.65;
}

.steps-list li::before {
  content: counter(step);
  position: absolute;
  left: 11px;
  top: 10px;
  width: 21px;
  height: 21px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  color: var(--accent);
  font-size: 10.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.pitfall-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 7px;
}

.pitfall-list li {
  position: relative;
  padding: 8px 12px 8px 32px;
  border: 1px solid var(--t1-line);
  border-radius: 9px;
  background: var(--t1-soft);
  color: var(--ink-2);
  font-size: 12.5px;
  line-height: 1.65;
}

.pitfall-list li::before {
  content: "!";
  position: absolute;
  left: 10px;
  top: 9px;
  width: 15px;
  height: 15px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--t1);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
}

.memory-note {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 11px 13px;
  border-left: 3px solid var(--gold);
  border-radius: 0 9px 9px 0;
  background: color-mix(in srgb, var(--gold) 7%, var(--surface));
  color: var(--ink-2);
  font-size: 12.5px;
  line-height: 1.7;
}

.memory-note b {
  flex: 0 0 auto;
  color: var(--gold);
  font-size: 11px;
  letter-spacing: 0.06em;
}

.example-box {
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

.example-q {
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.7;
}

.example-tex {
  margin: 10px 0;
  padding: 10px 12px;
  overflow-x: auto;
  border-radius: 8px;
  background: var(--formula-bg);
}

.example-tex .katex-display {
  margin: 0.2em 0;
}

.example-a {
  margin-top: 8px;
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.75;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink-2);
  font-size: 11.5px;
}

.pill.signal {
  border-style: dashed;
  color: var(--muted);
}

.related-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.related-link {
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 11.5px;
}

.related-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.modal-foot {
  position: sticky;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 14px 26px;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 93%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.mastery-control {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  border-radius: 9px;
  background: var(--surface-2);
}

.mastery-control button {
  min-height: 30px;
  padding: 4px 11px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 500;
}

.mastery-control button:hover {
  color: var(--ink);
}

.mastery-control button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

.mastery-control button[data-mastery="1"].active {
  color: var(--t1);
}
.mastery-control button[data-mastery="2"].active {
  color: var(--gold);
}
.mastery-control button[data-mastery="3"].active {
  color: var(--t3);
}

.modal-foot .spacer {
  flex: 1;
}

/* --------------------------------------------------------------------------
   默写模式
   -------------------------------------------------------------------------- */

.flash-stage {
  max-width: 860px;
  margin: 0 auto;
}

.flash-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.flash-toolbar .spacer {
  flex: 1;
}

.flash-progress {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

.flash-progress-track {
  flex: 1;
  height: 5px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}

.flash-progress-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #5b8def);
  transition: width 0.25s ease;
}

.flash-card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 430px;
  padding: 34px 38px 26px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.flash-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: var(--tier-color, var(--accent));
}

.flash-card.tier-1 {
  --tier-color: var(--t1);
}
.flash-card.tier-2 {
  --tier-color: var(--t2);
}
.flash-card.tier-3 {
  --tier-color: var(--t3);
}

.flash-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.04em;
}

.flash-title {
  margin-top: 14px;
  font-family: var(--font-serif);
  font-size: 29px;
  font-weight: 700;
  line-height: 1.35;
}

.flash-hint {
  margin-top: 16px;
  padding: 14px 16px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.75;
}

.flash-hint b {
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  display: block;
  margin-bottom: 4px;
}

.flash-reveal {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px dashed var(--line);
  animation: fade-up 0.25s ease;
}

.flash-formula {
  padding: 18px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--formula-bg);
}

.flash-formula .katex {
  font-size: 1.05em;
}

.flash-note {
  margin-top: 14px;
  color: var(--ink-2);
  font-size: 12.5px;
  line-height: 1.75;
}

.flash-note b {
  color: var(--muted);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  display: block;
  margin-bottom: 3px;
}

.flash-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px;
  margin-top: auto;
  padding-top: 24px;
}

.flash-actions .spacer {
  flex: 1;
}

.flash-actions .btn {
  min-width: 84px;
}

.rate-btn[data-rate="1"]:hover {
  border-color: var(--t1);
  color: var(--t1);
  background: var(--t1-soft);
}
.rate-btn[data-rate="2"]:hover {
  border-color: var(--gold);
  color: var(--gold);
  background: color-mix(in srgb, var(--gold) 8%, transparent);
}
.rate-btn[data-rate="3"]:hover {
  border-color: var(--t3);
  color: var(--t3);
  background: var(--t3-soft);
}

.flash-keyhint {
  margin-top: 12px;
  color: var(--muted);
  font-size: 10.5px;
  text-align: center;
}

.flash-keyhint kbd {
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface-2);
  font-family: var(--font-sans);
  font-size: 10px;
}

/* --------------------------------------------------------------------------
   题型反查
   -------------------------------------------------------------------------- */

.type-search {
  position: relative;
  display: flex;
  align-items: center;
  max-width: 420px;
  height: 40px;
  margin-bottom: 20px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
}

.type-search svg {
  width: 16px;
  height: 16px;
  color: var(--muted);
}

.type-search input {
  flex: 1;
  height: 100%;
  padding-left: 9px;
  border: 0;
  background: transparent;
  font-size: 13px;
  outline: none;
}

.type-group {
  margin-bottom: 26px;
}

.type-group-head {
  display: flex;
  align-items: baseline;
  gap: 9px;
  margin-bottom: 11px;
}

.type-group-head h3 {
  font-family: var(--font-serif);
  font-size: 19px;
  font-weight: 700;
}

.type-group-head span {
  color: var(--muted);
  font-size: 11.5px;
}

.type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}

.type-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  text-align: left;
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.type-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
}

.type-name {
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.5;
}

.type-count {
  flex: 0 0 auto;
  min-width: 28px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.type-card:hover .type-count {
  background: var(--accent-soft);
  color: var(--accent);
}

/* --------------------------------------------------------------------------
   统计
   -------------------------------------------------------------------------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.stat-card {
  padding: 16px 17px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.stat-card .label {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.04em;
}

.stat-card .value {
  margin-top: 4px;
  font-family: var(--font-serif);
  font-size: 30px;
  font-weight: 700;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.stat-card .value small {
  margin-left: 2px;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 400;
}

.stat-card .sub {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.panel {
  padding: 20px 22px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 15px;
}

.panel-head h3 {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 700;
}

.panel-head span {
  color: var(--muted);
  font-size: 11px;
}

.bar-list {
  display: grid;
  gap: 13px;
}

.bar-row {
  display: grid;
  grid-template-columns: 112px 1fr 88px;
  align-items: center;
  gap: 12px;
}

.bar-label {
  color: var(--ink-2);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-track {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}

.bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.4s ease;
}

.bar-fill.t1 {
  background: var(--t1);
}
.bar-fill.t2 {
  background: var(--t2);
}
.bar-fill.t3 {
  background: var(--t3);
}

.bar-value {
  color: var(--muted);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.bar-value b {
  color: var(--ink-2);
  font-weight: 600;
}

.legend-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 14px;
  padding-top: 13px;
  border-top: 1px dashed var(--line);
  color: var(--muted);
  font-size: 10.5px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.chapter-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.chapter-table th {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}

.chapter-table td {
  padding: 9px 10px;
  border-bottom: 1px dashed var(--line);
  color: var(--ink-2);
  vertical-align: middle;
}

.chapter-table tr:last-child td {
  border-bottom: 0;
}

.chapter-table .num {
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.chapter-table .mini-bar {
  width: 100px;
}

.chapter-table .mini-track {
  height: 5px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}

.chapter-table .mini-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.danger-zone {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 17px;
  border: 1px dashed var(--t1-line);
  border-radius: var(--radius-md);
  background: var(--t1-soft);
}

.danger-zone p {
  color: var(--ink-2);
  font-size: 12px;
  line-height: 1.6;
}

.danger-zone .btn {
  border-color: var(--t1-line);
  color: var(--t1);
  background: var(--surface);
}

.danger-zone .btn:hover {
  background: var(--t1);
  border-color: var(--t1);
  color: #fff;
}

/* --------------------------------------------------------------------------
   说明页
   -------------------------------------------------------------------------- */

.prose {
  max-width: 820px;
}

.prose h2 {
  margin: 28px 0 10px;
  font-family: var(--font-serif);
  font-size: 21px;
  font-weight: 700;
}

.prose h2:first-child {
  margin-top: 0;
}

.prose p {
  margin: 8px 0;
  color: var(--ink-2);
  font-size: 13.5px;
  line-height: 1.85;
}

.prose ul {
  margin: 8px 0;
  padding-left: 20px;
  color: var(--ink-2);
  font-size: 13.5px;
  line-height: 1.85;
}

.prose li {
  margin: 4px 0;
}

.prose code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 0.9em;
}

.tier-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0 4px;
}

.tier-card {
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.tier-card h3 {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 6px;
  font-size: 13.5px;
}

.tier-card p {
  margin: 0;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.7;
}

/* --------------------------------------------------------------------------
   提示条
   -------------------------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 120;
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px 18px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--surface);
  font-size: 12.5px;
  line-height: 1.5;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

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

.scrim {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: rgba(16, 21, 30, 0.4);
  backdrop-filter: blur(2px);
  animation: fade-in 0.18s ease;
}

.noscript {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
  color: var(--ink);
  text-align: center;
}

/* --------------------------------------------------------------------------
   滚动条
   -------------------------------------------------------------------------- */

* {
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

*::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background: var(--line-strong);
  background-clip: padding-box;
}

/* --------------------------------------------------------------------------
   动画
   -------------------------------------------------------------------------- */

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.view-enter {
  animation: fade-up 0.22s ease;
}

/* --------------------------------------------------------------------------
   响应式
   -------------------------------------------------------------------------- */

@media (max-width: 1180px) {
  #view {
    padding: 30px 26px 80px;
  }

  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
    box-shadow: var(--shadow-lg);
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  body.sidebar-open {
    overflow: hidden;
  }

  .main {
    margin-left: 0;
  }

  .menu-btn {
    display: inline-grid !important;
  }

  .topbar {
    padding: 0 16px;
  }

  #view {
    padding: 24px 18px 72px;
  }

  .page-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 14px;
  }

  .page-title {
    font-size: 29px;
  }

  .tier-cards {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .search-kbd {
    display: none;
  }

  .filterbar {
    align-items: flex-start;
  }

  .segmented {
    width: 100%;
    justify-content: space-between;
  }

  .segmented button {
    flex: 1;
    padding: 6px 8px;
  }

  .select-group {
    width: 100%;
  }

  .select-label {
    flex: 1;
    min-width: 120px;
  }

  .select-label select {
    flex: 1;
    max-width: none;
    width: 100%;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .bar-row {
    grid-template-columns: 88px 1fr;
  }

  .bar-value {
    grid-column: 1 / -1;
    text-align: left;
    margin-top: -6px;
  }

  .modal-backdrop {
    padding: 10px;
  }

  .modal-card {
    max-height: 94vh;
    border-radius: 18px;
  }

  .modal-head,
  .modal-body,
  .modal-foot {
    padding-left: 16px;
    padding-right: 16px;
  }

  .modal-title {
    font-size: 22px;
  }

  .flash-card {
    min-height: 390px;
    padding: 24px 20px 20px;
  }

  .flash-title {
    font-size: 23px;
  }

  .flash-actions .btn {
    flex: 1;
    min-width: 0;
  }

  .flash-actions .spacer {
    display: none;
  }

  .chapter-table .mini-bar {
    width: 56px;
  }
}

@media (max-width: 480px) {
  .stat-grid {
    grid-template-columns: 1fr;
  }

  .page-title {
    font-size: 26px;
  }

  .head-stats {
    width: 100%;
  }

  .stat-chip {
    flex: 1;
    justify-content: center;
  }

  .type-grid {
    grid-template-columns: 1fr;
  }
}

/* --------------------------------------------------------------------------
   打印
   -------------------------------------------------------------------------- */

@media print {
  body {
    background: #fff;
  }

  .sidebar,
  .topbar,
  .filterbar,
  .flash-toolbar,
  .modal-backdrop,
  .toast,
  .scrim,
  .load-more-wrap,
  .head-stats {
    display: none !important;
  }

  .main {
    margin-left: 0;
  }

  #view {
    max-width: none;
    padding: 0;
  }

  .card-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .formula-card {
    break-inside: avoid;
    box-shadow: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
