/* ============================================================
   数形结合实验室 — Visual Math Lab
   ============================================================ */

:root {
  --paper: #f5f2ea;
  --panel: #fffdf7;
  --panel-2: #faf7ee;
  --soft: #f0ece1;
  --soft-2: #e9e4d6;
  --ink: #1e241f;
  --ink-soft: #3c443d;
  --muted: #6d756c;
  --faint: #9aa096;
  --line: #e2dccd;
  --line-strong: #d2cab8;
  --grid: #e9e4d7;
  --axis: #a3a99e;
  --glow-a: rgba(207, 229, 213, 0.55);
  --glow-b: rgba(245, 228, 194, 0.42);

  --c-junior: #2f7d5d;
  --tint-junior: #e6f1ea;
  --c-senior: #2e609e;
  --tint-senior: #e7eef8;
  --c-uni: #6b4c9e;
  --tint-uni: #eee9f7;

  --m1: #2e609e;
  --m2: #c27a2c;
  --m3: #2f7d5d;
  --m4: #7a4fa3;
  --m5: #bf5a4f;
  --m6: #2b858a;

  --shadow-sm: 0 1px 2px rgba(48, 42, 26, 0.05);
  --shadow-md: 0 2px 4px rgba(48, 42, 26, 0.04), 0 20px 44px -28px rgba(48, 42, 26, 0.38);
  --shadow-lg: 0 4px 10px rgba(48, 42, 26, 0.05), 0 30px 70px -36px rgba(48, 42, 26, 0.45);

  --radius: 16px;
  --sans: "Inter", "Segoe UI", "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", system-ui, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", "Songti SC", "Noto Serif SC", "STSong", "SimSun", serif;
  --mono: "Cascadia Code", "SFMono-Regular", "JetBrains Mono", Consolas, "Liberation Mono", monospace;
}

[data-theme="dark"] {
  --paper: #0f1311;
  --panel: #161b18;
  --panel-2: #1a201c;
  --soft: #1e2521;
  --soft-2: #252d28;
  --ink: #eae7dd;
  --ink-soft: #c9ccc2;
  --muted: #99a29a;
  --faint: #6f7a70;
  --line: #2a332d;
  --line-strong: #38443b;
  --grid: #232c26;
  --axis: #5a665d;
  --glow-a: rgba(46, 100, 76, 0.22);
  --glow-b: rgba(120, 92, 38, 0.13);

  --c-junior: #6cc49b;
  --tint-junior: #1b2b23;
  --c-senior: #7fa9e2;
  --tint-senior: #1b2532;
  --c-uni: #b59ade;
  --tint-uni: #262034;

  --m1: #74a8e4;
  --m2: #e0a45c;
  --m3: #6cc49b;
  --m4: #b79ce0;
  --m5: #e5887d;
  --m6: #62bcc1;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.2), 0 24px 48px -30px rgba(0, 0, 0, 0.8);
  --shadow-lg: 0 6px 14px rgba(0, 0, 0, 0.24), 0 36px 80px -40px rgba(0, 0, 0, 0.9);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(1100px 620px at 78% -8%, var(--glow-a), transparent 68%),
    radial-gradient(900px 520px at -6% 102%, var(--glow-b), transparent 62%);
}

::selection { background: rgba(46, 96, 158, 0.2); }

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }

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

/* ---------- Layout ---------- */

.app {
  position: relative;
  z-index: 1;
  display: flex;
  min-height: 100vh;
}

.main-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.main {
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 34px 42px 80px;
}

.view { animation: viewIn 0.35s ease both; }

@keyframes viewIn {
  from { transform: translateY(6px); }
  to { transform: none; }
}

/* ---------- Sidebar ---------- */

.sidebar {
  position: sticky;
  top: 0;
  z-index: 50;
  width: 282px;
  flex: 0 0 282px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 18px 14px;
  padding: 6px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  text-align: left;
}

.brand-mark {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: #fffdf7;
  background: linear-gradient(145deg, var(--c-junior), var(--c-senior) 56%, var(--c-uni));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 6px 14px -8px rgba(30, 36, 31, 0.6);
}

.brand-mark svg { width: 23px; height: 23px; }

.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 16px; font-weight: 650; letter-spacing: 0.02em; }
.brand-text small {
  margin-top: 3px;
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.17em;
  color: var(--faint);
}

.search-box {
  position: relative;
  margin: 4px 18px 12px;
}

.search-box input {
  width: 100%;
  height: 38px;
  padding: 0 36px 0 34px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--soft);
  font-size: 13px;
  color: var(--ink);
  transition: border-color 0.18s, background 0.18s;
}

.search-box input::placeholder { color: var(--faint); }
.search-box input:focus {
  outline: none;
  border-color: var(--line-strong);
  background: var(--panel-2);
}
.search-box input::-webkit-search-cancel-button { display: none; }

.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  width: 15px;
  height: 15px;
  transform: translateY(-50%);
  color: var(--faint);
  pointer-events: none;
}

.search-box kbd {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  min-width: 18px;
  height: 19px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--faint);
  background: var(--panel);
}

.nav {
  flex: 1;
  overflow-y: auto;
  padding: 2px 12px 24px;
  scrollbar-width: thin;
}

.nav-group { margin-bottom: 16px; }
.nav-group[hidden] { display: none; }

.nav-label {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 8px 6px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--faint);
  text-transform: uppercase;
}

.nav-label .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--c-junior);
}
.nav-group[data-level="senior"] .nav-label .dot { background: var(--c-senior); }
.nav-group[data-level="university"] .nav-label .dot { background: var(--c-uni); }

.nav-count { margin-left: auto; font-family: var(--mono); font-size: 9.5px; letter-spacing: 0; }

.nav-item {
  width: 100%;
  display: flex;
  align-items: baseline;
  gap: 9px;
  padding: 7px 9px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover { background: var(--soft); color: var(--ink); }
.nav-item[hidden] { display: none; }

.nav-idx {
  flex: 0 0 18px;
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--faint);
}

.nav-item.active {
  background: var(--tint-junior);
  color: var(--c-junior);
  font-weight: 650;
}
.nav-group[data-level="senior"] .nav-item.active { background: var(--tint-senior); color: var(--c-senior); }
.nav-group[data-level="university"] .nav-item.active { background: var(--tint-uni); color: var(--c-uni); }
.nav-item.active .nav-idx { color: currentColor; opacity: 0.7; }

.nav-empty {
  margin: 6px 8px;
  padding: 10px 12px;
  border: 1px dashed var(--line);
  border-radius: 9px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--faint);
}

.sidebar-foot {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 20px 15px;
  border-top: 1px solid var(--line);
  font-size: 10.5px;
  color: var(--faint);
}

.live-dot {
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-right: 5px;
  border-radius: 50%;
  background: var(--c-junior);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c-junior) 15%, transparent);
}

.sidebar-scrim { display: none; }

/* ---------- Topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 62px;
  flex: 0 0 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 38px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 84%, transparent);
  backdrop-filter: blur(14px) saturate(1.1);
}

.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }

.crumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 12.5px;
  color: var(--faint);
  white-space: nowrap;
  overflow: hidden;
}
.crumbs button {
  border: 0;
  background: none;
  padding: 0;
  color: var(--faint);
  font-size: 12.5px;
}
.crumbs button:hover { color: var(--ink); }
.crumbs .sep { opacity: 0.55; }
.crumbs .current { color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; }

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

.icon-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--muted);
  transition: color 0.16s, border-color 0.16s, transform 0.16s;
}
.icon-btn:hover { color: var(--ink); border-color: var(--line-strong); transform: translateY(-1px); }
.icon-btn svg { width: 18px; height: 18px; }

.menu-btn { display: none; }

.text-btn {
  height: 36px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12.5px;
  transition: color 0.16s, border-color 0.16s;
}
.text-btn:hover { color: var(--ink); border-color: var(--line-strong); }
.text-btn svg { width: 16px; height: 16px; }

[data-theme="light"] .icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }

/* ---------- Home / hero ---------- */

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.02fr) minmax(0, 0.98fr);
  gap: 42px;
  align-items: stretch;
  padding: 26px 0 44px;
}

.hero-copy { padding-top: 18px; }

.eyebrow {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.19em;
  text-transform: uppercase;
  color: var(--faint);
}

.eyebrow-line { width: 26px; height: 1px; background: var(--c-senior); opacity: 0.65; }

.hero h1 {
  margin: 20px 0 18px;
  font-family: var(--serif);
  font-size: clamp(42px, 4.5vw, 60px);
  font-weight: 600;
  line-height: 1.13;
  letter-spacing: -0.035em;
}

.hero-em {
  position: relative;
  display: inline-block;
  color: var(--c-senior);
  white-space: nowrap;
}
.hero-em::after {
  content: "";
  position: absolute;
  left: 1px;
  right: 1px;
  bottom: 5px;
  height: 9px;
  z-index: -1;
  border-radius: 2px;
  background: color-mix(in srgb, var(--m2) 26%, transparent);
  transform: skewX(-8deg);
}

.hero-lede {
  max-width: 520px;
  margin: 0;
  font-size: 15.5px;
  line-height: 1.85;
  color: var(--muted);
}

.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 28px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 20px;
  border-radius: 11px;
  border: 1px solid transparent;
  font-size: 13.5px;
  font-weight: 600;
  transition: transform 0.18s, background 0.18s, border-color 0.18s, color 0.18s;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--ink); color: var(--panel); }
.btn-primary:hover { background: var(--ink-soft); }
.btn-arrow { font-family: var(--sans); transition: transform 0.18s; }
.btn-primary:hover .btn-arrow { transform: translateX(3px); }
.btn-ghost { background: var(--panel); border-color: var(--line); color: var(--ink-soft); }
.btn-ghost:hover { border-color: var(--line-strong); }

.hero-stats {
  display: flex;
  gap: 34px;
  margin: 36px 0 0;
}
.hero-stats div { display: flex; flex-direction: column; }
.hero-stats dt {
  font-family: var(--serif);
  font-size: 24px;
  line-height: 1.1;
  color: var(--ink);
}
.hero-stats dd { margin: 4px 0 0; font-size: 10.5px; letter-spacing: 0.08em; color: var(--faint); }

.hero-art {
  position: relative;
  min-height: 390px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.hero-art::after {
  content: "";
  position: absolute;
  inset: 9px;
  border: 1px solid color-mix(in srgb, var(--line) 62%, transparent);
  border-radius: 15px;
  pointer-events: none;
}
.hero-art canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.hero-caption {
  position: absolute;
  left: 18px;
  bottom: 17px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(8px);
  font-size: 10.5px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.pulse-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--c-senior);
  animation: pulse 2.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--c-senior) 32%, transparent); }
  50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--c-senior) 0%, transparent); }
}

/* ---------- Principles ---------- */

.principles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin: 6px 0 52px;
}

.principle {
  position: relative;
  padding: 20px 20px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--panel) 58%, transparent);
}

.principle-num {
  position: absolute;
  top: 18px;
  right: 18px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--faint);
}
.principle h3 { margin: 0 0 7px; font-size: 15px; font-weight: 650; letter-spacing: 0.01em; }
.principle p { margin: 0; font-size: 12.5px; line-height: 1.75; color: var(--muted); }

/* ---------- Filter bar ---------- */

.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

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

.chip {
  height: 30px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  transition: background 0.16s, color 0.16s, border-color 0.16s;
}
.chip:hover { border-color: var(--line-strong); color: var(--ink); }
.chip.active { background: var(--ink); border-color: var(--ink); color: var(--panel); }

.filter-count { font-family: var(--mono); font-size: 10.5px; color: var(--faint); }

/* ---------- Level sections & cards ---------- */

.level-section { margin-bottom: 48px; scroll-margin-top: 80px; }
.level-section[hidden] { display: none; }

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

.section-head-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.section-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 27px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.section-head p {
  max-width: 420px;
  margin: 0 0 2px;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--muted);
  text-align: right;
}

.level-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 9px;
  border-radius: 6px;
  background: var(--tint-junior);
  color: var(--c-junior);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.08em;
  white-space: nowrap;
}
.level-badge.senior { background: var(--tint-senior); color: var(--c-senior); }
.level-badge.university { background: var(--tint-uni); color: var(--c-uni); }

.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 13px;
}

.model-card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 158px;
  padding: 17px 18px 15px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  text-align: left;
  overflow: hidden;
  transition: transform 0.18s ease, border-color 0.18s, box-shadow 0.18s;
}

.model-card::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 2px;
  background: var(--card-accent, var(--c-junior));
  opacity: 0;
  transition: opacity 0.18s;
}

.model-card:hover {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--card-accent) 38%, var(--line));
  box-shadow: var(--shadow-md);
}
.model-card:hover::before { opacity: 1; }
.model-card[hidden] { display: none; }

.card-num {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.08em;
  color: var(--faint);
}
.card-num em { font-style: normal; color: var(--card-accent); opacity: 0.8; }

.model-card h3 {
  margin: 7px 0 5px;
  padding-right: 20px;
  font-size: 15px;
  font-weight: 650;
  line-height: 1.4;
  letter-spacing: 0.005em;
}
.model-card p {
  margin: 0;
  font-size: 12px;
  line-height: 1.68;
  color: var(--muted);
}

.card-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: auto; padding-top: 12px; }
.card-tag {
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--soft);
  font-size: 9.5px;
  color: var(--faint);
  line-height: 1.5;
}

.card-arrow {
  position: absolute;
  top: 16px;
  right: 16px;
  font-size: 13px;
  color: var(--faint);
  opacity: 0;
  transform: translate(-2px, 2px);
  transition: opacity 0.18s, transform 0.18s, color 0.18s;
}
.model-card:hover .card-arrow { opacity: 1; transform: none; color: var(--card-accent); }

/* ---------- Knowledge map ---------- */

.map-card {
  margin-top: 14px;
  padding: 28px 30px 26px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  scroll-margin-top: 84px;
}
.map-head { max-width: 620px; margin-bottom: 22px; }
.map-head h2 {
  margin: 9px 0 8px;
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.map-head p:last-child { margin: 0; font-size: 12.5px; color: var(--muted); }

.map-row {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 18px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}
.map-row:last-child { border-bottom: 1px solid var(--line); }
.map-level { display: flex; flex-direction: column; gap: 4px; }
.map-level strong { font-size: 13px; font-weight: 650; }
.map-level span { font-family: var(--mono); font-size: 9.5px; color: var(--faint); }
.map-tags { display: flex; flex-wrap: wrap; gap: 5px; align-content: flex-start; }
.map-tag {
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: transparent;
  font-size: 10.5px;
  line-height: 1.65;
  color: var(--muted);
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.map-tag:hover { color: var(--ink); border-color: var(--line-strong); background: var(--soft); }

.home-foot {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-top: 50px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--faint);
}

/* ---------- Module head ---------- */

.module-view {
  --accent: var(--c-junior);
  --tint: var(--tint-junior);
}

.module-head { margin-bottom: 22px; }

.crumbs.module-crumbs { margin-bottom: 18px; font-size: 12px; }

.module-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 26px;
}

.module-title-block { min-width: 0; }
.module-title-line { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }

.module-title {
  margin: 10px 0 7px;
  font-family: var(--serif);
  font-size: clamp(28px, 3vw, 38px);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.025em;
}
.module-sub { margin: 0; font-size: 14px; color: var(--muted); }
.module-title:focus { outline: none; }

.module-index {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--faint);
  letter-spacing: 0.1em;
}

.tag-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.tag {
  padding: 3px 8px;
  border-radius: 5px;
  background: var(--soft);
  font-size: 10.5px;
  color: var(--muted);
}

.module-nav { display: flex; gap: 6px; flex: 0 0 auto; padding-top: 4px; }
.module-nav .jump-practice { height: 36px; padding: 0 10px; font-size: 11.5px; }

/* ---------- Workbench ---------- */

.workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 348px;
  gap: 20px;
  align-items: start;
}

.canvas-card {
  position: sticky;
  top: 82px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.canvas-toolbar {
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 12px 0 15px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.canvas-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
}
.canvas-label .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
}

.tool-group { display: flex; align-items: center; gap: 4px; }

.tool-btn {
  height: 27px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.tool-btn:hover { background: var(--soft); color: var(--ink); }
.tool-btn svg { width: 13px; height: 13px; }
.tool-btn.playing { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); background: var(--tint); }
.tool-btn:disabled { opacity: 0.35; cursor: default; }
.tool-btn.copied { color: var(--accent); }

.canvas-wrap {
  position: relative;
  height: clamp(400px, 56vh, 560px);
  background:
    radial-gradient(120% 100% at 50% 0%, color-mix(in srgb, var(--soft) 38%, transparent), transparent 70%),
    var(--panel);
}
.canvas-wrap.compact { height: clamp(380px, 46vh, 480px); }
.canvas-wrap canvas { display: block; width: 100%; height: 100%; }

.coord-chip {
  position: absolute;
  right: 12px;
  bottom: 10px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: blur(6px);
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  opacity: 0;
  transform: translateY(3px);
  transition: opacity 0.15s, transform 0.15s;
  pointer-events: none;
}
.coord-chip.ready { opacity: 1; transform: none; }

.canvas-foot {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 15px;
  border-top: 1px solid var(--line);
  font-size: 10.5px;
  color: var(--faint);
}
.canvas-hint { display: flex; align-items: center; gap: 6px; }
.canvas-hint svg { width: 13px; height: 13px; flex: 0 0 auto; }
.key-hint { font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.04em; white-space: nowrap; }
.key-hint kbd {
  display: inline-block;
  min-width: 17px;
  padding: 0 3px;
  border: 1px solid var(--line);
  border-radius: 4px;
  text-align: center;
  font-family: var(--mono);
  font-size: 9px;
  line-height: 15px;
  background: var(--panel-2);
}

/* ---------- Panel ---------- */

.panel { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.panel-block {
  padding: 15px 16px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 13px;
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--faint);
}
.panel-title .cn { font-family: var(--sans); font-size: 11.5px; letter-spacing: 0.03em; color: var(--muted); }

.control { margin-bottom: 14px; }
.control:last-child { margin-bottom: 0; }

.control-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 3px;
}
.control-head label { font-size: 12px; color: var(--ink-soft); }
.control-val {
  flex: 0 0 auto;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--tint);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 11px;
}

input[type="range"] {
  --fill: 50%;
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent) 0 var(--fill), var(--line) var(--fill) 100%);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  margin-top: -5.5px;
  border: 2px solid var(--panel);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 2px 4px rgba(0, 0, 0, 0.16);
}
input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 99px;
  background: var(--line);
}
input[type="range"]::-moz-range-progress {
  height: 4px;
  border-radius: 99px;
  background: var(--accent);
}
input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 2px solid var(--panel);
  border-radius: 50%;
  background: var(--accent);
}

.segmented {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 9px;
  background: var(--soft);
}
.segmented button {
  flex: 1;
  min-width: 0;
  padding: 5px 4px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.segmented button:hover { color: var(--ink); }
.segmented button.active {
  background: var(--panel);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(35, 30, 20, 0.1);
}
.segmented.compact button { font-size: 10px; letter-spacing: -0.01em; padding: 5px 2px; }

.presets {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 13px;
  padding-top: 11px;
  border-top: 1px dashed var(--line);
}
.presets > span { margin-right: 2px; font-size: 10px; color: var(--faint); }
.preset-btn {
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: transparent;
  font-size: 10px;
  color: var(--muted);
  line-height: 1.6;
  transition: color 0.15s, border-color 0.15s;
}
.preset-btn:hover { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 42%, var(--line)); }

/* ---------- Readouts ---------- */

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

.readout {
  min-width: 0;
  padding: 7px 9px 8px;
  border-radius: 8px;
  background: var(--soft);
}
.readout.wide { grid-column: 1 / -1; }

.readout .k {
  display: block;
  font-size: 9.5px;
  line-height: 1.4;
  color: var(--faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.readout .v {
  display: block;
  margin-top: 2px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.45;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.readout .v small { font-family: var(--sans); font-size: 9px; color: var(--faint); }
.readout.tone-accent { background: var(--tint); }
.readout.tone-accent .v { color: var(--accent); }

/* ---------- Notes ---------- */

.notes-idea {
  margin: 0 0 12px;
  font-size: 12.5px;
  line-height: 1.75;
  color: var(--ink-soft);
}
.notes-idea strong { color: var(--accent); font-weight: 650; }

.notes-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.notes-list li {
  position: relative;
  margin-bottom: 9px;
  padding-left: 22px;
  font-size: 12px;
  line-height: 1.7;
  color: var(--muted);
}
.notes-list li:last-child { margin-bottom: 0; }
.notes-list li::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  left: 0;
  top: 2px;
  width: 15px;
  height: 15px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--tint);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 8.5px;
  line-height: 1;
}
.notes-list { counter-reset: step; }

.ask-block {
  padding: 12px 13px;
  border-left: 2px solid var(--accent);
  border-radius: 0 8px 8px 0;
  background: var(--tint);
}
.ask-block .ask-label {
  display: block;
  margin-bottom: 3px;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  opacity: 0.85;
}
.ask-block p { margin: 0; font-size: 12px; line-height: 1.7; color: var(--ink-soft); }

/* ---------- Module footer nav ---------- */

.module-foot-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 26px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.foot-link {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel);
  text-align: left;
  transition: border-color 0.16s, transform 0.16s;
}
.foot-link:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.foot-link.next { text-align: right; align-items: flex-end; }
.foot-link .dir { font-family: var(--mono); font-size: 9.5px; color: var(--faint); letter-spacing: 0.08em; }
.foot-link .name { font-size: 12.5px; color: var(--ink-soft); }

/* ---------- Error ---------- */

.error-banner {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 200;
  max-width: min(680px, calc(100vw - 32px));
  padding: 10px 15px;
  border: 1px solid #c05050;
  border-radius: 9px;
  background: #2a1717;
  color: #ffd9d9;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.error-banner.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Practice / 真题与思路 ---------- */

.practice {
  margin-top: 32px;
  padding-top: 26px;
  border-top: 1px solid var(--line);
  scroll-margin-top: 82px;
}

.practice-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
}

.practice-head h2 {
  margin: 9px 0 7px;
  font-family: var(--serif);
  font-size: 25px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.practice-sub {
  max-width: 640px;
  margin: 0;
  font-size: 12px;
  line-height: 1.75;
  color: var(--muted);
}

.practice-count {
  flex: 0 0 auto;
  padding-bottom: 3px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--faint);
  white-space: nowrap;
}

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

.practice-card {
  padding: 16px 17px 15px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.18s, box-shadow 0.18s;
}
.practice-card:hover { border-color: var(--line-strong); }
.practice-card.open {
  border-color: color-mix(in srgb, var(--accent) 34%, var(--line));
  box-shadow: var(--shadow-md);
}

.practice-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.practice-type {
  padding: 1px 7px;
  border-radius: 5px;
  background: var(--tint);
  color: var(--accent);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.04em;
}
.practice-type.syn {
  background: color-mix(in srgb, var(--m2) 17%, transparent);
  color: color-mix(in srgb, var(--m2) 82%, var(--ink));
}

.practice-level {
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 9.5px;
  line-height: 1.6;
  color: var(--faint);
}

.practice-source {
  font-size: 10px;
  line-height: 1.6;
  color: var(--faint);
}

.practice-q {
  margin: 0;
  font-size: 13px;
  line-height: 1.85;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}

.practice-hint {
  margin: 10px 0 0;
  padding-left: 8px;
  border-left: 2px solid color-mix(in srgb, var(--accent) 32%, transparent);
  font-size: 11.5px;
  line-height: 1.7;
  color: var(--muted);
}

.practice-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 13px;
  padding: 4px 9px 4px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11px;
  transition: color 0.15s, border-color 0.15s;
}
.practice-toggle:hover {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 42%, var(--line));
}
.practice-toggle svg { width: 13px; height: 13px; transition: transform 0.18s; }
.practice-card.open .practice-toggle { color: var(--accent); }
.practice-card.open .practice-toggle svg { transform: rotate(180deg); }

.practice-body {
  display: none;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}
.practice-card.open .practice-body {
  display: block;
  animation: practiceIn 0.2s ease both;
}

@keyframes practiceIn {
  from { opacity: 0; transform: translateY(-3px); }
  to { opacity: 1; transform: none; }
}

.practice-steps {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: pstep;
}
.practice-steps li {
  position: relative;
  margin-bottom: 8px;
  padding-left: 21px;
  font-size: 12px;
  line-height: 1.75;
  color: var(--muted);
}
.practice-steps li:last-child { margin-bottom: 0; }
.practice-steps li::before {
  counter-increment: pstep;
  content: counter(pstep);
  position: absolute;
  left: 0;
  top: 2px;
  width: 14px;
  height: 14px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--tint);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 8px;
  line-height: 1;
}

.practice-answer {
  margin: 11px 0 0;
  padding: 9px 11px;
  border-radius: 8px;
  background: var(--tint);
  font-size: 12px;
  line-height: 1.7;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}
.practice-answer span {
  display: inline-block;
  margin-right: 7px;
  padding: 0 5px;
  border-radius: 4px;
  background: var(--accent);
  color: var(--panel);
  font-size: 9.5px;
  font-weight: 650;
  line-height: 1.6;
  vertical-align: 1px;
}

/* ---------- Responsive ---------- */

@media (max-width: 1180px) {
  .main { padding: 28px 30px 70px; }
  .topbar { padding: 0 26px; }
  .hero { gap: 28px; }
  .hero h1 { font-size: 46px; }
  .workbench { grid-template-columns: minmax(0, 1fr) 322px; }
  .canvas-wrap { height: clamp(380px, 50vh, 500px); }
}

@media (max-width: 1200px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-102%);
    transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1);
    box-shadow: 24px 0 60px -30px rgba(0, 0, 0, 0.4);
    width: 300px;
    flex-basis: 300px;
  }
  .sidebar.open { transform: none; }
  .sidebar-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 45;
    background: rgba(20, 24, 20, 0.34);
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
  }
  .sidebar-scrim.show { opacity: 1; pointer-events: auto; }
  .menu-btn { display: grid; }
  .hero { grid-template-columns: 1fr; }
  .hero-copy { padding-top: 4px; }
  .hero-art { min-height: 380px; }
  .principles { grid-template-columns: 1fr; gap: 8px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workbench { grid-template-columns: 1fr; }
  .canvas-card { position: static; }
  .canvas-wrap { height: clamp(400px, 58vh, 560px); }
  .panel { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .panel-block.notes-block, .panel-block.ask-panel { grid-column: 1 / -1; }
}

@media (max-width: 680px) {
  .main { padding: 20px 17px 60px; }
  .topbar { height: 56px; flex-basis: 56px; padding: 0 14px; }
  .text-btn span { display: none; }
  .text-btn { width: 36px; padding: 0; justify-content: center; }
  .crumbs { font-size: 11.5px; }
  .hero { padding-top: 10px; gap: 24px; }
  .hero h1 { font-size: 38px; margin-top: 16px; }
  .hero-lede { font-size: 14px; }
  .hero-stats { gap: 24px; margin-top: 26px; }
  .hero-stats dt { font-size: 21px; }
  .hero-art { min-height: 320px; }
  .hero-caption { font-size: 9.5px; left: 12px; bottom: 12px; }
  .section-head { display: block; }
  .section-head p { text-align: left; margin-top: 7px; }
  .cards { grid-template-columns: 1fr; }
  .model-card { min-height: 0; }
  .filter-bar { margin-bottom: 18px; }
  .filter-count { display: none; }
  .map-card { padding: 20px 17px; }
  .map-row { grid-template-columns: 1fr; gap: 8px; }
  .module-title-row { display: block; }
  .module-nav { display: none; }
  .canvas-toolbar { justify-content: flex-end; padding-left: 8px; }
  .canvas-label { display: none; }
  .canvas-wrap { height: 380px; }
  .canvas-foot .key-hint { display: none; }
  .panel { display: flex; }
  .readouts { gap: 5px; }
  .practice-head { display: block; }
  .practice-head h2 { font-size: 22px; }
  .practice-count { display: inline-block; margin-top: 6px; }
  .practice-grid { grid-template-columns: 1fr; }
  .module-foot-nav { grid-template-columns: 1fr; }
  .foot-link.next { text-align: left; align-items: flex-start; }
  .home-foot { flex-direction: column; gap: 6px; }
}

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

/* ---------- Print ---------- */

@media print {
  :root {
    --paper: #fff;
    --panel: #fff;
    --panel-2: #fff;
    --soft: #f4f4f1;
    --tint: #f0f4f1;
    --ink: #111;
    --ink-soft: #222;
    --muted: #444;
    --line: #ccc;
    --grid: #eee;
  }
  body { background: #fff; }
  body::before, .sidebar, .sidebar-scrim, .topbar, .module-nav, .canvas-toolbar,
  .module-foot-nav, .coord-chip, .home-foot, .key-hint { display: none !important; }
  .app { display: block; }
  .main { max-width: none; padding: 0; }
  .workbench { display: block; }
  .canvas-card { position: static; box-shadow: none; border-color: #bbb; page-break-inside: avoid; }
  .canvas-wrap { height: 420px; }
  .panel { display: block; margin-top: 14px; }
  .panel-block { break-inside: avoid; margin-bottom: 10px; box-shadow: none; }
  .module-head { margin-bottom: 12px; }
  .practice { margin-top: 18px; padding-top: 14px; page-break-before: auto; }
  .practice-head { display: block; margin-bottom: 10px; }
  .practice-head h2 { font-size: 19px; margin: 5px 0 0; }
  .practice-sub, .practice-count { display: none; }
  .practice-grid { grid-template-columns: 1fr; gap: 9px; }
  .practice-card { box-shadow: none; border-color: #bbb; break-inside: avoid; padding: 12px 13px; }
  .practice-body { display: block !important; border-top-color: #ddd; }
  .practice-toggle { display: none; }
  .practice-type { border: 1px solid #bbb; }
  .practice-type.syn { background: #f2eee4; color: #7a4a12; }
  .practice-answer span { background: transparent; border: 1px solid #999; color: #111; }
  .view[hidden] { display: none !important; }
}
