/* ============================================================================
   hcl-guide.com — global styles
   ============================================================================ */

:root {
  /* Dark theme (default) */
  --bg: #0a0e14;
  --bg-elev: #11151c;
  --bg-elev-2: #161c25;
  --bg-code: #0d1117;
  --bg-overlay: rgba(10, 14, 20, 0.78);
  --border: #1f2731;
  --border-strong: #2a3441;

  --fg: #e6edf3;
  --fg-dim: #94a3b8;
  --fg-muted: #64748b;

  --accent: #8b5cf6;
  --accent-2: #a78bfa;
  --accent-strong: #7c3aed;
  --accent-glow: rgba(139, 92, 246, 0.22);

  --link: #60a5fa;
  --link-hover: #93c5fd;

  /* HCL syntax */
  --kw: #ff7b8a;
  --str: #a5d6ff;
  --num: #ffb86c;
  --com: #6b7d8f;
  --type: #79c0ff;
  --fn: #d2a8ff;
  --var: #ffa657;

  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.35);
  --shadow-glow: 0 0 0 1px var(--accent-glow), 0 8px 32px rgba(139, 92, 246, 0.18);

  --t-fast: 0.15s ease;
  --t-base: 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  --t-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);

  --sidebar-w: 280px;
  --content-max: 880px;
  --toc-w: 220px;

  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #ffffff;
  --bg-elev: #f8fafc;
  --bg-elev-2: #f1f5f9;
  --bg-code: #f6f8fa;
  --bg-overlay: rgba(255, 255, 255, 0.85);
  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  --fg: #0f172a;
  --fg-dim: #475569;
  --fg-muted: #94a3b8;

  --accent: #7c3aed;
  --accent-2: #6d28d9;
  --accent-strong: #5b21b6;
  --accent-glow: rgba(124, 58, 237, 0.10);

  --link: #2563eb;
  --link-hover: #1d4ed8;

  --kw: #cf222e;
  --str: #0a3069;
  --num: #953800;
  --com: #6e7781;
  --type: #0550ae;
  --fn: #8250df;
  --var: #b35900;

  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.12);
  --shadow-glow: 0 0 0 1px var(--accent-glow), 0 8px 32px rgba(124, 58, 237, 0.12);

  color-scheme: light;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN",
    "Hiragino Sans", Meiryo, system-ui, sans-serif;
  font-feature-settings: "palt", "kern";
  font-kerning: normal;
  line-height: 1.75;
  font-size: 16px;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background var(--t-base), color var(--t-base);
  overflow-wrap: break-word;
  word-break: normal;
}

/* 日本語の見出しが横幅で重ならないように */
h1, h2, h3, h4, p, li, .card h3, .card p, .hero-index .lead {
  overflow-wrap: break-word;
}

a {
  color: var(--link);
  text-decoration: none;
  transition: color var(--t-fast);
}
a:hover {
  color: var(--link-hover);
  text-decoration: underline;
  text-underline-offset: 3px;
}

strong, b { color: var(--fg); font-weight: 600; }

/* ============================================================================
   Accessibility & global UI elements
   ============================================================================ */

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 9999;
  padding: 10px 18px;
  background: var(--accent);
  color: #fff;
  border-radius: 0 0 8px 0;
  font-weight: 600;
  font-size: 0.9rem;
}
.skip-link:focus { left: 0; }

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

/* Reading progress */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  z-index: 100;
  transition: width 0.05s linear;
  box-shadow: 0 0 8px var(--accent-glow);
}

/* Theme toggle */
.theme-toggle {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--fg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}
.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent-2);
}
.theme-toggle svg { width: 18px; height: 18px; }

/* Mobile hamburger (rendered fixed top-left on narrow viewports) */
.menu-toggle {
  display: none;
  position: fixed;
  top: 11px;
  left: 12px;
  z-index: 60;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--fg);
  cursor: pointer;
  align-items: center;
  justify-content: center;
}
.menu-toggle svg { width: 20px; height: 20px; }

/* ============================================================================
   Site header (sticky top bar)
   ============================================================================ */

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 28px;
  height: 60px;
  padding: 0 24px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}
.site-header .brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--fg);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  transition: opacity var(--t-fast);
  flex-shrink: 0;
  min-width: 0;
}
.site-header .theme-toggle { flex-shrink: 0; }
.site-header .brand:hover { opacity: 0.85; text-decoration: none; }
.site-header .brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  display: block;
}
.site-header .brand-text {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.header-nav {
  display: flex;
  gap: 6px;
  flex: 1;
}
.header-nav a {
  padding: 7px 14px;
  border-radius: 8px;
  color: var(--fg-dim);
  font-size: 0.92rem;
  font-weight: 500;
  text-decoration: none;
  transition: background var(--t-fast), color var(--t-fast);
}
.header-nav a:hover {
  background: var(--accent-glow);
  color: var(--fg);
  text-decoration: none;
}

/* ============================================================================
   Layout
   ============================================================================ */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: calc(100vh - 60px);
}

.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 28px 22px;
  position: sticky;
  top: 60px;
  height: calc(100vh - 60px);
  overflow-y: auto;
  z-index: 30;
}
.sidebar h1 {
  font-size: 1.05rem;
  margin: 0 0 4px 0;
  letter-spacing: -0.01em;
}
.sidebar h1 a {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-weight: 700;
  text-decoration: none;
}
.sidebar h1 a:hover { text-decoration: none; }
.sidebar .tagline {
  font-size: 0.78rem;
  color: var(--fg-dim);
  margin-bottom: 22px;
  line-height: 1.55;
}

.nav { list-style: none; padding: 0; margin: 0; }
.nav a {
  display: block;
  padding: 7px 12px;
  border-radius: 7px;
  color: var(--fg-dim);
  font-size: 0.92rem;
  border-left: 3px solid transparent;
  margin-left: -3px;
  transition: all var(--t-fast);
}
.nav a:hover {
  background: var(--accent-glow);
  color: var(--fg);
  text-decoration: none;
}
.nav a.active {
  background: var(--accent-glow);
  color: var(--fg);
  border-left-color: var(--accent);
  font-weight: 500;
}
.nav .section-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--fg-muted);
  margin: 22px 12px 6px 12px;
  font-weight: 600;
}

main {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 56px 64px 96px;
  position: relative;
}

/* index ページは main を全幅で使う（テキストだけ別途制限） */
body:has(.hero-index) main,
body.is-home main {
  max-width: none;
  margin: 0;
  padding: 48px 56px 96px;
}

/* hero 内のテキスト要素だけ読みやすい幅に制限 */
.hero-index .eyebrow,
.hero-index h1,
.hero-index .lead {
  max-width: 760px;
}
/* hero-stats は広がっても OK */
.hero-stats { max-width: none; }

/* panel header の見出し本文も読みやすい幅 */
.panel-header h2,
.panel-header p { max-width: 760px; }

/* card grid は使える幅を全部使う */
.card-grid { max-width: none; }

/* tab-bar も全幅 */
.tab-bar { max-width: none; }

/* ============================================================================
   Hero (chapter pages)
   ============================================================================ */

.hero {
  padding: 56px 0 28px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 36px;
}
.hero h1 {
  font-size: clamp(1.8rem, 3.2vw, 2.4rem);
  margin: 0 0 12px;
  letter-spacing: -0.02em;
  line-height: 1.2;
  background: linear-gradient(135deg, var(--fg) 0%, var(--accent-2) 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero p {
  color: var(--fg-dim);
  font-size: 1.05rem;
  max-width: 720px;
  line-height: 1.7;
  margin: 0;
}

/* ============================================================================
   Hero (index landing) — グラデーションメッシュ + 統計
   ============================================================================ */

.hero-index {
  position: relative;
  padding: 88px 0 56px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}
.hero-index::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(820px circle at 0% 0%, var(--accent-glow), transparent 50%),
    radial-gradient(620px circle at 100% 30%, rgba(96, 165, 250, 0.10), transparent 60%);
  pointer-events: none;
}
.hero-index > * { position: relative; }

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--accent-2);
  background: var(--accent-glow);
  padding: 6px 14px;
  border-radius: 999px;
  margin-bottom: 22px;
  letter-spacing: 0.04em;
  border: 1px solid transparent;
}
.eyebrow::before {
  content: "";
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.85); }
}

.hero-index h1 {
  font-size: clamp(2rem, 5vw, 3.4rem);
  margin: 0 0 18px;
  line-height: 1.1;
  letter-spacing: -0.03em;
  font-weight: 800;
  background: linear-gradient(135deg, var(--fg) 0%, var(--accent-2) 55%, var(--accent) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero-index .lead {
  font-size: 1.12rem;
  color: var(--fg-dim);
  max-width: 680px;
  line-height: 1.7;
  margin: 0 0 30px;
}

.hero-stats {
  display: flex;
  gap: 36px;
  margin-top: 20px;
  flex-wrap: wrap;
}
.hero-stat {
  display: flex;
  flex-direction: column;
}
.hero-stat .num {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.hero-stat .label {
  font-size: 0.76rem;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 6px;
  font-weight: 500;
}

/* ============================================================================
   Heading hierarchy
   ============================================================================ */

h2 {
  font-size: 1.55rem;
  margin: 64px 0 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  letter-spacing: -0.01em;
  scroll-margin-top: 24px;
}
h2:first-of-type { margin-top: 28px; }
h3 {
  font-size: 1.18rem;
  margin: 36px 0 10px;
  color: var(--fg);
  scroll-margin-top: 24px;
  letter-spacing: -0.005em;
}
h3::before {
  content: "#";
  color: var(--accent-2);
  margin-right: 10px;
  opacity: 0.45;
  font-weight: 400;
}
h4 { font-size: 1.02rem; margin: 22px 0 6px; color: var(--fg); }

p { margin: 12px 0; }
ul, ol { padding-left: 1.5em; }
li { margin: 5px 0; }

/* ============================================================================
   Code (inline & block)
   ============================================================================ */

code {
  font-family: "SFMono-Regular", "JetBrains Mono", Consolas, "Liberation Mono", Menlo, monospace;
  background: var(--accent-glow);
  color: var(--accent-2);
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 0.86em;
  font-weight: 500;
}
[data-theme="light"] code {
  color: var(--accent-strong);
  background: rgba(124, 58, 237, 0.08);
}

pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  overflow-x: auto;
  position: relative;
  font-size: 0.9rem;
  line-height: 1.65;
  margin: 16px 0;
}
pre code {
  background: transparent;
  color: var(--fg);
  padding: 0;
  font-size: 0.9rem;
  font-weight: 400;
  border: none;
}

.code-label {
  position: absolute;
  top: 10px;
  right: 14px;
  font-size: 0.7rem;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
  pointer-events: none;
}

.copy-btn {
  position: absolute;
  top: 8px;
  right: 60px;
  background: var(--bg-elev);
  color: var(--fg-dim);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--t-fast), color var(--t-fast), border-color var(--t-fast);
  font-family: inherit;
}
pre:hover .copy-btn,
pre:focus-within .copy-btn { opacity: 1; }
.copy-btn:hover { color: var(--fg); border-color: var(--accent); }
.copy-btn.copied { color: var(--success); border-color: var(--success); }

/* HCL syntax tokens */
.tok-kw   { color: var(--kw); font-weight: 500; }
.tok-str  { color: var(--str); }
.tok-num  { color: var(--num); }
.tok-com  { color: var(--com); font-style: italic; }
.tok-type { color: var(--type); }
.tok-fn   { color: var(--fn); }
.tok-var  { color: var(--var); }

/* ============================================================================
   Callouts
   ============================================================================ */

.callout {
  --callout-color: var(--accent);
  border-left: 3px solid var(--callout-color);
  background: var(--accent-glow);
  padding: 14px 18px;
  border-radius: 8px;
  margin: 22px 0;
}
.callout.warn {
  --callout-color: var(--warning);
  background: rgba(245, 158, 11, 0.08);
}
.callout.ok {
  --callout-color: var(--success);
  background: rgba(16, 185, 129, 0.08);
}
.callout .label {
  display: inline-block;
  font-weight: 600;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-right: 8px;
  color: var(--callout-color);
}

/* ============================================================================
   Tables
   ============================================================================ */

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 18px 0;
  font-size: 0.93rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
th, td {
  padding: 10px 14px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}
tr:last-child td, tr:last-child th { border-bottom: none; }
th {
  background: var(--bg-elev);
  color: var(--fg);
  font-weight: 600;
  font-size: 0.84rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
tbody tr:nth-child(even) td { background: var(--bg-elev); }
[data-theme="light"] tbody tr:nth-child(even) td { background: var(--bg-elev-2); }

/* Responsive table wrapper（widthが厳しいとき横スクロール）*/
@media (max-width: 700px) {
  main > table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}

/* ============================================================================
   Difficulty level badges
   ============================================================================ */

.level {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 500;
  letter-spacing: 0.03em;
  vertical-align: middle;
  white-space: nowrap;
}
.level-beginner {
  background: rgba(16, 185, 129, 0.14);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.32);
}
.level-intermediate {
  background: rgba(245, 158, 11, 0.14);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.32);
}
.level-advanced {
  background: rgba(239, 68, 68, 0.14);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.32);
}
[data-theme="light"] .level-beginner    { color: #047857; }
[data-theme="light"] .level-intermediate { color: #b45309; }
[data-theme="light"] .level-advanced     { color: #b91c1c; }

.hero .level, .hero-index .level { margin-bottom: 12px; }

.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.level-legend {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 0.84rem;
  color: var(--fg-dim);
  margin-top: 12px;
}
.level-legend .level { font-size: 0.7rem; }

/* ============================================================================
   Tab bar (index)
   ============================================================================ */

.tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin: 32px 0 28px;
  position: sticky;
  top: 60px;
  background: var(--bg);
  z-index: 10;
  padding: 8px 0 0;
}
.tab {
  background: transparent;
  color: var(--fg-dim);
  border: none;
  padding: 12px 20px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color var(--t-fast), border-color var(--t-fast), background var(--t-fast);
  border-radius: 8px 8px 0 0;
  font-family: inherit;
  letter-spacing: -0.005em;
}
.tab:hover {
  color: var(--fg);
  background: var(--accent-glow);
}
.tab.active {
  color: var(--fg);
  border-bottom-color: var(--accent);
}
.tab-badge {
  display: inline-block;
  margin-left: 8px;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-glow);
  color: var(--accent-2);
  vertical-align: 1px;
  font-weight: 500;
}
.tab-badge.soon {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning);
}

.panel { display: none; }
.panel.active {
  display: block;
  animation: fadeup 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes fadeup {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 8px 0 18px;
  flex-wrap: wrap;
  gap: 10px;
}
.panel-header h2 {
  margin: 0;
  border: none;
  padding: 0;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
}
.panel-header p {
  margin: 0;
  color: var(--fg-dim);
  font-size: 0.96rem;
}

/* Coming soon */
.coming-soon {
  border: 1px dashed var(--border-strong);
  background: linear-gradient(135deg, var(--bg-elev) 0%, var(--bg-elev-2) 100%);
  border-radius: 14px;
  padding: 56px 28px;
  text-align: center;
  color: var(--fg-dim);
}
.coming-soon h3 {
  color: var(--fg);
  margin: 0 0 8px;
  font-size: 1.4rem;
}
.coming-soon h3::before { content: ""; margin: 0; }

/* ============================================================================
   Cards (chapter index)
   ============================================================================ */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
  margin-top: 8px;
}
.card {
  display: block;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  border-radius: 12px;
  padding: 22px 24px;
  transition: transform var(--t-base), border-color var(--t-base), box-shadow var(--t-base), background var(--t-base);
  position: relative;
  overflow: hidden;
}
.card::after {
  content: "";
  position: absolute;
  top: -2px; right: -2px; bottom: -2px; left: -2px;
  border-radius: 14px;
  background: linear-gradient(135deg, transparent 35%, var(--accent) 100%);
  opacity: 0;
  z-index: -1;
  transition: opacity var(--t-base);
  filter: blur(12px);
}
.card:hover {
  transform: translateY(-3px);
  text-decoration: none;
  border-color: var(--accent);
  box-shadow: var(--shadow-glow);
}
.card:hover::after { opacity: 0.4; }

.card .step {
  display: inline-block;
  font-size: 0.74rem;
  color: var(--accent-2);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 600;
  background: var(--accent-glow);
  padding: 3px 10px;
  border-radius: 999px;
}
.card h3 {
  margin: 12px 0 6px;
  color: var(--fg);
  font-size: 1.08rem;
  letter-spacing: -0.005em;
}
.card h3::before { content: ""; margin: 0; }
.card p {
  margin: 0;
  color: var(--fg-dim);
  font-size: 0.9rem;
  line-height: 1.55;
}

/* ============================================================================
   Pager
   ============================================================================ */

.pager {
  display: flex;
  justify-content: space-between;
  margin-top: 72px;
  padding-top: 28px;
  border-top: 1px solid var(--border);
  gap: 14px;
}
.pager a {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
  background: var(--bg-elev);
  transition: border-color var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
}
.pager a:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  text-decoration: none;
  box-shadow: var(--shadow-md);
}
.pager .dir {
  display: block;
  font-size: 0.74rem;
  color: var(--accent-2);
  font-weight: 500;
  letter-spacing: 0.04em;
}
.pager .title {
  display: block;
  color: var(--fg);
  margin-top: 2px;
  font-weight: 500;
}
.pager .next { text-align: right; }

/* ============================================================================
   Mini TOC at top of chapter
   ============================================================================ */

.toc-mini {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
  margin: 22px 0 32px;
}
.toc-mini .label {
  font-size: 0.74rem;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}
.toc-mini ul { margin: 6px 0 0; padding-left: 22px; }
.toc-mini li { margin: 3px 0; }
.toc-mini a { color: var(--fg-dim); }
.toc-mini a:hover { color: var(--accent-2); }

/* ============================================================================
   Floating "On this page" rail (wide viewports only)
   ============================================================================ */

.toc-rail {
  position: fixed;
  top: 80px;
  right: 24px;
  width: var(--toc-w);
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  font-size: 0.85rem;
  display: none;
  z-index: 5;
}
.toc-rail .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-muted);
  margin-bottom: 10px;
  font-weight: 600;
}
.toc-rail ul { list-style: none; margin: 0; padding: 0; }
.toc-rail a {
  display: block;
  padding: 5px 12px;
  color: var(--fg-dim);
  border-left: 2px solid var(--border);
  font-size: 0.85rem;
  line-height: 1.45;
  transition: color var(--t-fast), border-color var(--t-fast);
}
.toc-rail a:hover {
  color: var(--fg);
  text-decoration: none;
}
.toc-rail a.active {
  color: var(--accent-2);
  border-left-color: var(--accent);
  font-weight: 500;
}

/* Wider viewports show the floating TOC */
@media (min-width: 1320px) {
  .toc-rail.has-headings { display: block; }
}

/* ============================================================================
   Site footer
   ============================================================================ */

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
  padding: 56px 24px 28px;
  margin-top: 0;
  grid-column: 1 / -1;
}
.footer-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr 1fr;
  gap: 36px 28px;
}
.footer-col h4 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--fg-muted);
  font-weight: 600;
  margin: 0 0 12px;
}
.footer-col ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.footer-col li { margin: 6px 0; }
.footer-col a {
  color: var(--fg-dim);
  font-size: 0.92rem;
  text-decoration: none;
  transition: color var(--t-fast);
}
.footer-col a:hover {
  color: var(--accent-2);
  text-decoration: none;
}
.footer-brand .brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.1rem;
  margin-bottom: 8px;
}
.footer-brand .brand-mark { width: 30px; height: 30px; border-radius: 7px; }
.footer-brand .brand-text {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.footer-tag {
  color: var(--fg-dim);
  font-size: 0.92rem;
  margin: 4px 0 0;
  max-width: 320px;
  line-height: 1.6;
}
.footer-bottom {
  max-width: 1100px;
  margin: 36px auto 0;
  padding-top: 22px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--fg-muted);
  font-size: 0.85rem;
}
.footer-meta a { color: var(--fg-dim); }

/* For chapter pages, footer should span full width below sidebar+main */
body > .site-footer { grid-column: unset; }

/* ============================================================================
   Sidebar (mobile)
   ============================================================================ */

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 35;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-base);
}
.sidebar-backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

@media (max-width: 920px) {
  .site-header { padding: 0 16px 0 60px; gap: 8px; }
  .site-header .brand-text { display: none; }
  .header-nav { gap: 0; overflow-x: auto; flex-wrap: nowrap; }
  .header-nav a { padding: 6px 10px; font-size: 0.85rem; white-space: nowrap; }

  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 280px;
    transform: translateX(-100%);
    transition: transform var(--t-base);
    box-shadow: var(--shadow-lg);
    padding-top: 24px;
  }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: flex; }
  main { padding: 32px 22px 64px; }
  .hero-index { padding: 48px 0 32px; }
  .hero-index h1 { font-size: clamp(1.6rem, 6vw, 2.2rem); }
  .hero h1 { font-size: 1.5rem; }
  h2 { font-size: 1.3rem; margin-top: 48px; }
  .tab-bar { gap: 0; }
  .tab { padding: 10px 14px; font-size: 0.92rem; }
  .copy-btn { opacity: 1; right: 14px; top: 38px; }
  .code-label { display: none; }
  .footer-inner { grid-template-columns: 1fr 1fr; }
  .footer-bottom { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 520px) {
  .footer-inner { grid-template-columns: 1fr; gap: 24px; }
}

/* ============================================================================
   Print
   ============================================================================ */

@media print {
  .sidebar, .theme-toggle, .menu-toggle, .reading-progress, .toc-rail, .copy-btn,
  .tab-bar, .pager { display: none !important; }
  .layout { grid-template-columns: 1fr; }
  main { padding: 0; max-width: 100%; }
  pre { white-space: pre-wrap; word-wrap: break-word; page-break-inside: avoid; }
  body { color: #000; background: #fff; }
  .panel { display: block !important; }
  a { color: #000; text-decoration: underline; }
}

/* ============================================================================
   Scrollbar
   ============================================================================ */

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 5px;
}
::-webkit-scrollbar-thumb:hover { background: var(--fg-muted); }

/* Reduce motion accessibility */
@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;
  }
}
