/* ════════════════════════════════════════════════
   箏Lab — Guzheng Reading-first Design System
   Traditional Chinese · Ink & Vermillion palette
   ════════════════════════════════════════════════ */

/* ── Design tokens ───────────────────────────── */
:root {
  /* Brand palette: ink / vermillion / paper / jade */
  --ink-900: oklch(20% 0.012 270);
  --ink-800: oklch(28% 0.015 270);
  --ink-700: oklch(38% 0.018 270);
  --ink-100: oklch(94% 0.005 270);

  --vermillion-700: oklch(44% 0.155 30);
  --vermillion-600: oklch(52% 0.165 32);
  --vermillion-500: oklch(58% 0.16 32);
  --vermillion-100: oklch(94% 0.025 32);

  --jade-600: oklch(58% 0.085 160);
  --jade-500: oklch(62% 0.08 160);
  --jade-100: oklch(93% 0.02 160);

  --gold-500: oklch(68% 0.11 75);
  --gold-100: oklch(92% 0.04 75);

  /* Surfaces */
  --bg-primary: oklch(97% 0.005 60);
  --bg-secondary: oklch(94% 0.008 60);
  --bg-card: #ffffff;
  --bg-surface: oklch(93% 0.01 60);
  --bg-elevated: oklch(90% 0.012 60);
  --bg-input: #ffffff;

  /* Text */
  --text-primary: var(--ink-900);
  --text-secondary: var(--ink-700);
  --text-tertiary: oklch(50% 0.02 270);
  --text-on-dark: #ffffff;
  --text-on-light: var(--ink-900);

  --accent: var(--ink-900);
  --accent-hover: var(--ink-800);
  --accent-active: var(--ink-900);
  --accent-bg: var(--ink-100);
  --accent-dim: var(--text-tertiary);

  --action: var(--vermillion-600);
  --action-hover: var(--vermillion-500);
  --action-text: #ffffff;

  --jade: var(--jade-600);
  --jade-bg: var(--jade-100);
  --gold: var(--gold-500);

  /* Borders */
  --border-color: oklch(82% 0.012 60);
  --border-hover: oklch(68% 0.02 60);
  --border-light: oklch(90% 0.008 60);

  /* Shadows */
  --shadow-sm: 0 2px 4px rgba(42, 31, 26, 0.06);
  --shadow-base: 0 4px 8px rgba(42, 31, 26, 0.08);
  --shadow-lg: 0 8px 12px rgba(42, 31, 26, 0.12);

  /* Typography — CJK-optimized scale */
  --text-display: clamp(2.5rem, 5vw, 4.75rem);
  --text-h1: clamp(2rem, 3.5vw, 3.25rem);
  --text-h2: clamp(1.55rem, 2.4vw, 2.15rem);
  --text-h3: 1.35rem;
  --text-h4: 1.125rem;
  --text-body: 1rem;
  --text-sm: 0.8889rem;
  --text-xs: 0.7778rem;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 16px;

  /* Font stacks */
  --font-body: 'Noto Sans TC', 'PingFang TC', 'Microsoft JhengHei', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-heading: 'Noto Serif TC', 'Songti TC', 'STSong', 'Georgia', 'Times New Roman', serif;
  --font-mono: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', monospace;

  --nav-height: 64px;
  --max-width: 1180px;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 36px;
  --space-2xl: 64px;

  --reading-font-size: 1rem;
  --reading-line-height: 1.9;
  --reading-max-width: 40rem;
  --chapter-gap: 64px;

  --z-dropdown: 300;
  --z-sticky: 400;
  --z-progress: 450;
  --z-overlay: 500;
}

/* ── Reset & Base ─────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 18px;
  scroll-padding-top: calc(var(--nav-height) + 24px);
}

body {
  font-family: var(--font-body);
  color: var(--text-primary);
  background: var(--bg-primary);
  line-height: 1.75;
  letter-spacing: 0;
  line-break: strict;
  word-break: normal;
  overflow-wrap: break-word;
  font-kerning: normal;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

h1, h2, h3, h4 {
  font-family: var(--font-heading);
  text-wrap: balance;
  line-height: 1.22;
  letter-spacing: -0.01em;
}

p, li, dd { text-wrap: pretty; }

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

a { color: var(--action); text-decoration: none; transition: color .2s; }
a:hover { color: var(--action-hover); }

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

/* ── Skip link ── */
.skip-link {
  position: fixed;
  left: 16px;
  top: 12px;
  z-index: calc(var(--z-overlay) + 1);
  padding: 10px 14px;
  border-radius: 6px;
  background: #fff;
  color: var(--action);
  font-weight: 800;
  transform: translateY(-160%);
  transition: transform .18s ease;
}
.skip-link:focus { transform: translateY(0); }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }

/* ── Navigation ── */
.navbar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  height: var(--nav-height);
  background: var(--ink-900);
  border-bottom: 1px solid color-mix(in oklch, var(--ink-700), white 12%);
  display: flex;
  align-items: center;
  padding: 0 clamp(16px, 3vw, 48px);
}

.navbar-brand {
  font-size: 1.32rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.02em;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  font-family: var(--font-heading);
}
.navbar-brand:hover { color: #fff; }

.brand-icon {
  width: 38px;
  height: 32px;
  display: grid;
  place-items: center;
  position: relative;
}
.brand-icon svg {
  width: 100%;
  height: 100%;
}
.brand-icon svg path { fill: none; stroke: #fff; stroke-width: 1.5; }
.brand-icon svg .bridge-body { fill: var(--vermillion-600); stroke: none; }

.navbar-nav {
  display: flex;
  gap: 4px;
  margin-left: auto;
  align-items: center;
}

.nav-link {
  padding: var(--space-sm) var(--space-md);
  border-radius: 6px;
  color: rgba(255,255,255,.84);
  font-size: var(--text-sm);
  font-weight: 700;
  transition: color .18s ease, background .18s ease;
  white-space: nowrap;
  position: relative;
}
.nav-link:hover { color: #fff; background: rgba(255,255,255,.1); }
.nav-link.active {
  color: #fff;
  background: rgba(255,255,255,.14);
  box-shadow: inset 0 -2px 0 var(--vermillion-600);
}

/* Nav dropdown */
.nav-dropdown {
  position: relative;
  display: flex;
  align-items: center;
}
.dropdown-btn {
  cursor: pointer;
  background: none;
  border: none;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 700;
  padding: var(--space-sm) var(--space-md);
  border-radius: 6px;
  color: rgba(255,255,255,.84);
  transition: color .18s ease, background .18s ease;
  white-space: nowrap;
  min-height: 44px;
}
.dropdown-btn:hover,
.nav-dropdown:hover .dropdown-btn,
.nav-dropdown.open .dropdown-btn { color: #fff; background: rgba(255,255,255,.1); }
.nav-dropdown.active .dropdown-btn {
  color: #fff;
  background: rgba(255,255,255,.14);
  box-shadow: inset 0 -2px 0 var(--vermillion-600);
}
.dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px;
  min-width: 270px;
  box-shadow: var(--shadow-lg);
  z-index: var(--z-dropdown);
}
.nav-dropdown:hover .dropdown-menu,
.dropdown-menu:hover,
.nav-dropdown.open .dropdown-menu { display: block; }

@media (min-width: 1081px) {
  .nav-dropdown:focus-within .dropdown-menu { display: block; }
}

.dropdown-menu a {
  display: block;
  padding: 11px 12px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: var(--text-sm);
  border-radius: 6px;
  transition: color .15s ease, background .15s ease;
}
.dropdown-menu a:hover {
  color: var(--action);
  background: var(--vermillion-100);
}
.dropdown-menu a[aria-current="page"] {
  color: var(--action);
  font-weight: 700;
  background: var(--vermillion-100);
}

.nav-toggle {
  display: none;
  background: none;
  border: 1px solid rgba(255,255,255,.25);
  color: #fff;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 10px;
  min-width: 44px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: transform .25s ease, color .2s, background .2s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.nav-toggle:hover { background: rgba(255,255,255,.1); }
.nav-toggle:focus-visible { outline: 3px solid var(--vermillion-500); outline-offset: 2px; }
.nav-toggle[aria-expanded="true"] {
  color: #fff;
  background: rgba(255,255,255,.14);
}

/* ── Layout ───────────────────────────────────── */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 clamp(16px, 3vw, 32px);
  width: 100%;
}

.page {
  flex: 1;
  padding: clamp(32px, 5vw, 72px) 0;
}

.page-header {
  max-width: var(--reading-max-width);
  margin: 0 auto var(--space-xl);
  text-align: left;
}
.page-header h1 {
  font-size: var(--text-h1);
  color: var(--text-primary);
  margin-bottom: 12px;
}
.page-header-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-bottom: var(--space-md);
  background: var(--vermillion-100);
  border: 1px solid var(--border-color);
  border-radius: 10px;
}
.page-header p {
  color: var(--text-secondary);
  font-size: 1rem;
  line-height: 1.8;
  max-width: 38em;
  margin: 0;
}

/* Page transition */
.page {
  flex: 1;
  padding: var(--space-xl) 0;
}

/* ── Prose reading ── */
.prose {
  max-width: 720px;
  margin: 0 auto;
  line-height: 1.8;
}
.prose h2 {
  color: var(--text-primary);
  font-size: 1.4rem;
  margin-top: var(--space-xl);
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-sm);
  border-bottom: 2px solid var(--border-light);
}
.prose h3 {
  color: var(--text-primary);
  font-size: 1.1rem;
  margin-top: var(--space-lg);
  margin-bottom: var(--space-sm);
}
.prose p { margin-bottom: var(--space-md); color: var(--text-primary); }
.prose ul, .prose ol { margin-bottom: var(--space-md); padding-left: var(--space-lg); }
.prose li { margin-bottom: var(--space-xs); color: var(--text-secondary); }
.prose strong { color: var(--text-primary); }
.prose .info-box {
  background: var(--vermillion-100);
  border-left: 4px solid var(--action);
  padding: var(--space-md) var(--space-lg);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin: var(--space-lg) 0;
}

/* ── Cards ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  box-shadow: none;
  transition: border-color .2s, transform .2s;
}
.card:hover {
  border-color: var(--border-hover);
  transform: translateY(-2px);
}
.card-header {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-sm);
  border-bottom: 2px solid var(--border-light);
}
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-lg);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-lg);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all .2s ease;
  background: var(--bg-card);
  color: var(--text-primary);
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--bg-elevated); transform: translateY(-2px); box-shadow: var(--shadow-base); border-color: var(--border-hover); }
.btn:active { transform: translateY(0); box-shadow: var(--shadow-sm), inset 0 2px 6px rgba(42,31,26,0.08); }
.btn:focus-visible { outline: 2px solid var(--action); outline-offset: 2px; }
.btn-primary { background: var(--action); color: var(--action-text); border-color: var(--action); }
.btn-primary:hover { background: var(--action-hover); border-color: var(--action-hover); box-shadow: 0 2px 12px rgba(196, 62, 44, 0.35); }
.btn-primary:active { background: var(--vermillion-700); border-color: var(--vermillion-700); }
.btn-sm { padding: var(--space-xs) var(--space-md); font-size: 0.8rem; }

/* ── Select / Input ── */
select, input, .input-like {
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-input);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: var(--font-body);
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
select:focus, input:focus { border-color: var(--action); box-shadow: 0 0 0 3px var(--vermillion-100); }
select option { background: var(--bg-card); color: var(--text-primary); }

/* ── Tags / Badges ── */
.tag {
  display: inline-block;
  padding: 2px var(--space-sm);
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  color: var(--text-secondary);
}
.tag-vermillion { background: var(--vermillion-100); color: var(--action); }
.tag-jade { background: var(--jade-bg); color: var(--jade); }
.tag-gold { background: var(--gold-100); color: var(--gold-500); }

/* ── Table ── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.data-table th, .data-table td {
  padding: var(--space-sm) var(--space-md);
  text-align: left;
  border-bottom: 1px solid var(--border-light);
}
.data-table th {
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.8rem;
  letter-spacing: 0.5px;
  background: var(--bg-secondary);
}
.data-table tr:hover td { background: var(--vermillion-100); }

/* ── Footer ── */
.footer {
  text-align: center;
  padding: var(--space-lg);
  color: var(--text-secondary);
  font-size: 0.8rem;
  border-top: 2px solid var(--border-light);
  margin-top: var(--space-xl);
  background: var(--bg-secondary);
}

/* ── Reading progress line ── */
.reading-progress-line {
  position: fixed;
  top: var(--nav-height);
  left: 0;
  right: 0;
  height: 3px;
  z-index: var(--z-progress);
  pointer-events: none;
}
.reading-progress-line > span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--action);
  transform-origin: left center;
  transform: scaleX(var(--read-progress, 0));
}

/* ── Focus-visible ── */
:focus-visible {
  outline: 2px solid var(--action);
  outline-offset: 2px;
}
button:focus-visible,
a:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--action);
  outline-offset: 2px;
}

/* ── Back-to-top ── */
.back-to-top {
  position: fixed;
  bottom: var(--space-xl);
  right: var(--space-xl);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  transition: all .2s;
  z-index: 90;
  box-shadow: var(--shadow-base);
}
.back-to-top:hover {
  background: var(--action);
  color: var(--action-text);
  border-color: var(--action);
  transform: translateY(-2px);
}
.back-to-top.visible { display: flex; }

/* ── Course breadcrumb ── */
.course-breadcrumb {
  max-width: var(--reading-max-width);
  margin: 0 auto var(--space-lg);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 0.85rem;
  flex-wrap: wrap;
}
.course-breadcrumb a {
  color: var(--text-tertiary);
  text-decoration: none;
  transition: color .2s;
}
.course-breadcrumb a:hover { color: var(--action); }
.course-breadcrumb .sep {
  color: var(--border-color);
  font-size: 1.1rem;
}
.course-breadcrumb .current {
  color: var(--text-secondary);
  font-weight: 500;
}
.course-breadcrumb .progress {
  display: none;
}

/* ── Lesson utility ── */
.lesson-utility {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: var(--reading-max-width);
  margin: -8px auto 32px;
  padding: 12px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-card);
}
.lesson-utility-copy {
  color: var(--text-secondary);
  font-size: var(--text-sm);
}
.lesson-complete-button {
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--action);
  border-radius: 6px;
  background: #fff;
  color: var(--action);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 800;
  cursor: pointer;
}
.lesson-complete-button[aria-pressed="true"] {
  border-color: var(--action);
  background: var(--action);
  color: #fff;
}

/* ── Divider ── */
.section-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: var(--space-xl) 0;
  color: var(--jade);
  font-size: 0.85rem;
  opacity: 0.5;
}
.section-divider::before,
.section-divider::after {
  content: '';
  flex: 1;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--border-color), transparent);
  border-radius: 1px;
}

/* ── Loading ── */
.loading {
  color: var(--text-secondary);
  text-align: center;
  padding: var(--space-xl);
}
.loading::after { content: '…'; animation: dots 1.5s infinite; }
@keyframes dots { 0%,20% { content: '.'; } 40% { content: '..'; } 60%,100% { content: '...'; } }

/* ── 404 ── */
.release-error {
  width: min(620px, calc(100% - 32px));
  min-height: 100svh;
  margin: 0 auto;
  display: grid;
  align-content: center;
  justify-items: start;
  gap: 18px;
  padding-block: 64px;
}
.release-error-mark {
  color: var(--action);
  font-size: .82rem;
  font-weight: 900;
  letter-spacing: .16em;
}
.release-error h1 {
  margin: 0;
  font-size: clamp(2rem, 8vw, 4rem);
  line-height: 1.05;
}
.release-error p {
  max-width: 32em;
  margin: 0;
  color: var(--text-secondary);
  font-size: 1.05rem;
  line-height: 1.85;
}
.release-error-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 6px;
}

/* ════════════════════════════════════════════════
   Chapter Layout (for lesson content)
   ════════════════════════════════════════════════ */

.chapter-layout {
  display: flex;
  gap: 48px;
  align-items: flex-start;
  max-width: 1020px;
  margin: 0 auto;
}
.chapter-main {
  flex: 1;
  min-width: 0;
}

.chapter-toc {
  position: sticky;
  top: calc(var(--nav-height) + 24px);
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  padding: var(--space-md) 0;
  z-index: 1;
}
.chapter-toc h4 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-secondary);
  margin-bottom: var(--space-lg);
  font-weight: 700;
  padding-left: var(--space-md);
}
.toc-group {
  margin-bottom: var(--space-md);
}
.toc-group-label {
  display: block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-tertiary);
  margin-bottom: var(--space-xs);
  padding-left: var(--space-md);
  font-weight: 600;
  opacity: 0.8;
}
.toc-group a {
  display: block;
  padding: 6px 0 6px var(--space-md);
  border-left: 2px solid transparent;
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.15s;
  line-height: 1.4;
}
.toc-group a:hover {
  color: var(--text-primary);
  border-left-color: var(--action);
}
.toc-group a.active {
  color: var(--action);
  border-left-color: var(--action);
  background: var(--vermillion-100);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* ── Chapter content ── */
.learning-chapter {
  margin: 0 auto;
  max-width: var(--reading-max-width);
}
.learning-chapter + .learning-chapter {
  margin-top: var(--chapter-gap);
  padding-top: var(--chapter-gap);
  border-top: 1px solid var(--border-light);
}
.chapter-header {
  margin-bottom: var(--space-xl);
  padding-bottom: var(--space-lg);
  border-bottom: 2px solid var(--border-light);
}
.chapter-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--vermillion-100);
  color: var(--action);
  font-size: 0.85rem;
  font-weight: 800;
  margin-bottom: var(--space-sm);
  font-family: var(--font-heading);
}
.chapter-header h2 {
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: var(--space-xs) 0 var(--space-sm);
  line-height: 1.25;
  letter-spacing: -0.01em;
  font-family: var(--font-heading);
}
.chapter-header .chapter-subtitle {
  font-size: 0.95rem;
  color: var(--text-secondary);
  font-weight: 400;
  letter-spacing: 0.03em;
}
.chapter-body {
  font-size: var(--reading-font-size);
  line-height: var(--reading-line-height);
  color: var(--text-primary);
}
.chapter-body p { margin: 0 0 1.2em; }
.chapter-body h3 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 1.8em 0 0.6em;
  font-family: var(--font-heading);
}
.chapter-body h4 {
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 1.4em 0 0.4em;
  font-family: var(--font-heading);
}
.chapter-body ul { margin: 0 0 1.2em; padding-left: 1.5em; }
.chapter-body ul li { margin-bottom: 0.3em; list-style: disc; }
.chapter-body ol { margin: 0 0 1.2em; padding-left: 1.5em; }
.chapter-body ol li { margin-bottom: 0.5em; list-style: decimal; }
.chapter-body strong { color: var(--text-primary); font-weight: 700; }

.chapter-body .info-box {
  background: var(--vermillion-100);
  border: 1px solid rgba(196, 62, 44, 0.18);
  border-left: 4px solid var(--action);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  padding: var(--space-lg);
  margin: 1.5em 0;
  font-size: 0.95rem;
  line-height: 1.8;
}
.chapter-body .info-box strong { color: var(--action); }
.chapter-body .tip-box {
  background: var(--bg-secondary);
  border: 2px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-lg);
  margin: 1.2em 0;
  font-size: 0.92rem;
  line-height: 1.65;
  color: var(--text-secondary);
}
.chapter-body .tip-box strong { color: var(--text-primary); }

/* ── Chapter nav ── */
.chapter-nav {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) !important;
  align-items: center !important;
  gap: 12px !important;
  max-width: var(--reading-max-width);
  margin: var(--chapter-gap) auto 0 !important;
  padding-top: 18px !important;
  border-top: 1px solid var(--border-color) !important;
}
.chapter-nav a {
  display: inline-flex !important;
  min-height: 44px;
  align-items: center;
  padding: 9px 10px !important;
  border: 0 !important;
  border-radius: 6px !important;
  background: transparent !important;
  color: var(--action) !important;
  box-shadow: none !important;
  opacity: 1 !important;
  font-size: var(--text-sm) !important;
  font-weight: 800 !important;
}
.chapter-nav a:first-child { justify-self: start; }
.chapter-nav a:nth-child(2) { justify-self: center; color: var(--text-secondary) !important; }
.chapter-nav a:last-child { justify-self: end; text-align: right; }
.chapter-nav a:hover { background: var(--vermillion-100) !important; }

/* ════════════════════════════════════════════════
   Guzheng-specific components
   ════════════════════════════════════════════════ */

/* ── String diagram (21弦音位圖) ── */
.string-diagram-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}
.string-svg {
  width: 100%;
  min-width: 640px;
  height: auto;
  display: block;
  border: 2px solid var(--border-light);
  border-radius: 8px;
  background: var(--bg-card);
}
.string-note {
  stroke: #fff;
  stroke-width: 3;
}
.string-note-label {
  fill: #fff;
  font-family: var(--font-heading);
  font-size: 12px;
  font-weight: 800;
  text-anchor: middle;
  dominant-baseline: central;
}
.string-note-sub {
  fill: #fff;
  font-family: var(--font-body);
  font-size: 8px;
  font-weight: 800;
  text-anchor: middle;
  dominant-baseline: central;
}
.string-line {
  stroke: #9a8a7a;
  stroke-width: 2;
  stroke-linecap: round;
}
.string-bridge {
  fill: var(--vermillion-600);
  opacity: 0.7;
}

/* ── Scale / note boxes ── */
.scale-boxes {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin: var(--space-md) 0;
}
.scale-note {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--bg-card);
  border: 2px solid var(--border-light);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}
.scale-note.root { background: var(--vermillion-100); border-color: var(--action); color: var(--action); }
.scale-note.pentatonic-1 { background: var(--vermillion-100); border-color: var(--action); color: var(--action); }
.scale-note.pentatonic-2 { background: var(--jade-bg); border-color: var(--jade); color: var(--jade); }
.scale-note.pentatonic-3 { background: var(--gold-100); border-color: var(--gold-500); color: var(--ink-800); }
.scale-note.pentatonic-5 { background: var(--ink-100); border-color: var(--ink-700); color: var(--ink-700); }
.scale-note.pentatonic-6 { background: var(--bg-elevated); border-color: var(--border-hover); color: var(--text-primary); }

/* ── Fingering diagram ── */
.fingering-card {
  display: grid;
  grid-template-columns: minmax(160px, 0.8fr) minmax(260px, 1.2fr);
  gap: var(--space-md);
  align-items: center;
  padding: var(--space-md);
  margin-bottom: var(--space-md);
  border: 2px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.68);
}
.fingering-copy strong {
  display: block;
  margin-bottom: 4px;
  color: var(--text-primary);
  font-family: var(--font-heading);
}
.fingering-copy p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.92rem;
  line-height: 1.7;
}
.fingering-symbol {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--vermillion-100);
  color: var(--action);
  font-size: 1.2rem;
  font-weight: 900;
  font-family: var(--font-heading);
}

/* ── Score display (簡譜) ── */
.jianpu-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: var(--space-md);
  background: var(--bg-card);
  border: 2px solid var(--border-light);
  border-radius: var(--radius-md);
  margin: var(--space-md) 0;
  font-size: 1.4rem;
  font-weight: 800;
  font-family: var(--font-heading);
  justify-content: center;
}
.jianpu-note {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  min-width: 28px;
}
.jianpu-note .num { color: var(--text-primary); line-height: 1.2; }
.jianpu-note .fingering {
  font-size: 0.6rem;
  color: var(--action);
  font-weight: 700;
  margin-bottom: 2px;
}
.jianpu-note .dots-below {
  color: var(--text-tertiary);
  font-size: 0.7rem;
  line-height: 1;
}
.jianpu-note .dots-above {
  color: var(--text-tertiary);
  font-size: 0.7rem;
  line-height: 1;
}

/* ════════════════════════════════════════════════
   Responsive
   ════════════════════════════════════════════════ */

@media (max-width: 1080px) {
  .nav-toggle {
    display: inline-flex;
    margin-left: auto;
  }
  .navbar-nav {
    display: none;
    position: fixed;
    top: var(--nav-height);
    left: 0;
    right: 0;
    max-height: calc(100dvh - var(--nav-height));
    overflow-y: auto;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding: 12px 16px max(20px, env(safe-area-inset-bottom));
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
  }
  .navbar-nav.open { display: flex; }
  .navbar-nav.open::before {
    content: '';
    position: fixed;
    inset: var(--nav-height) 0 0;
    z-index: -1;
    background: rgba(42,31,26,.42);
  }
  .nav-link,
  .dropdown-btn {
    width: 100%;
    color: var(--text-primary);
    text-align: left;
  }
  .nav-link:hover,
  .dropdown-btn:hover,
  .nav-dropdown:hover .dropdown-btn,
  .nav-dropdown.open .dropdown-btn,
  .nav-dropdown.active .dropdown-btn,
  .nav-link.active {
    color: var(--action);
    background: var(--vermillion-100);
    box-shadow: none;
  }
  .nav-dropdown { flex-direction: column; align-items: stretch; }
  .nav-dropdown .dropdown-menu,
  .nav-dropdown:hover .dropdown-menu {
    display: none;
    position: static;
    width: 100%;
    min-width: 0;
    transform: none;
    margin-top: 4px;
    padding: 4px 8px 8px;
    border: 0;
    border-radius: 6px;
    box-shadow: none;
    background: var(--bg-surface);
  }
  .nav-dropdown.open .dropdown-menu { display: block; }
  body.nav-open { overflow: hidden; }
}

@media (max-width: 900px) {
  .chapter-layout { flex-direction: column; }
  .chapter-toc { display: none; }
}

@media (max-width: 768px) {
  .card-grid { grid-template-columns: 1fr; }
  .page-header h1 { font-size: 1.5rem; }
  .tool-controls { flex-direction: column; align-items: stretch; }
  .btn { width: 100%; justify-content: center; }
  .btn-sm { width: auto; }
  select, input, .input-like { font-size: 1rem; }
  .fingering-card { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  :root {
    --nav-height: 58px;
    --space-xl: 36px;
    --space-2xl: 56px;
  }
  html { font-size: 17px; }
  .navbar { padding-inline: 14px; }
  .navbar-brand { font-size: 1.12rem; }
  .learning-chapter { padding: 0 var(--space-md); }
  .chapter-header h2 { font-size: 1.3rem; }
  .chapter-body { font-size: 1.063rem; line-height: 2.0; }
  .course-breadcrumb {
    grid-template-columns: auto auto minmax(0, 1fr);
    font-size: .82rem;
  }
  .lesson-utility {
    align-items: stretch;
    flex-direction: column;
  }
  .lesson-complete-button { width: 100%; }
  .chapter-nav {
    grid-template-columns: 1fr !important;
    align-items: stretch !important;
  }
  .chapter-nav a,
  .chapter-nav a:first-child,
  .chapter-nav a:nth-child(2),
  .chapter-nav a:last-child {
    width: 100%;
    justify-self: stretch;
    justify-content: center;
    text-align: center;
  }
}

@media (pointer: coarse) {
  a, button, summary, select, input { min-height: 44px; }
}

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

@media print {
  body { background: #fff; color: #000; }
  .navbar, .footer, .reading-progress-line, .lesson-utility, .skip-link { display: none !important; }
  .card { background: #fff; border: 1px solid #ccc; box-shadow: none; }
  a { color: #000; text-decoration: underline; }
  .page { padding: 0; }
  .container { max-width: 100%; }
}

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