/* ====== Theme variables ====== */
:root {
  --bg: #0a0e1a;
  --bg-soft: #111727;
  --bg-card: #161e2e;
  --text: #e6edf3;
  --text-dim: #8a96a8;
  --text-mute: #5b6577;
  --accent: #4a8cff;
  --accent-2: #c1440e;
  --accent-3: #ffb347;
  --border: #232c40;
  --link: #5aa6ff;
  --shadow: 0 4px 24px rgba(0,0,0,.4);
  --max-width: 1100px;
  --content-width: 720px;
  --font-base: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", "SF Mono", Consolas, monospace;
  --radius: 8px;
  --transition: 0.2s ease;
}

[data-theme="mars-sand"] {
  --bg: #f4e8d4;
  --bg-soft: #ead7b8;
  --bg-card: #fff8eb;
  --text: #2d1b0f;
  --text-dim: #5b4530;
  --text-mute: #8a7860;
  --accent: #c1440e;
  --accent-2: #7a2412;
  --accent-3: #d97706;
  --border: #d4b890;
  --link: #b8400e;
  --shadow: 0 4px 20px rgba(193, 68, 14, 0.18);
}

/* =====================================================
   V11 Reading Mode — strong visual differences
   ===================================================== */

/* Base (immersive by default, also fallback when no data-reading-mode attr) */
html[data-reading-mode="immersive"],
html:not([data-reading-mode]) {
  /* immersive baseline; per-mode rules below override */
}

/* Annotation hint — hidden by default, only visible in annotated mode */
.annotation-hint {
  display: none;
}

/* Toolbar hint */
.reading-mode-hint {
  color: var(--text-dim);
  font-size: 0.82rem;
  margin-left: 0.5rem;
  padding-left: 0.5rem;
  border-left: 1px solid var(--border);
  letter-spacing: 0.01em;
  transition: color var(--transition);
}

/* ---- Active reading-mode button (strong contrast) ---- */
.tool-btn[data-reading-mode].active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(74, 140, 255, 0.18);
  font-weight: 600;
}
.tool-btn[data-reading-mode].active:hover {
  background: var(--accent);
  color: #fff;
}

/* =====================================================
   3.1 IMMERSIVE — continuous reading, hide TOC, center article
   ===================================================== */
html[data-reading-mode="immersive"] .layout {
  grid-template-columns: minmax(0, 1fr);
}

html[data-reading-mode="immersive"] .toc,
html[data-reading-mode="immersive"] .sidebar,
html[data-reading-mode="immersive"] .toc-panel {
  display: none !important;
}

html[data-reading-mode="immersive"] .main {
  padding: 3rem 2rem 4rem;
}

html[data-reading-mode="immersive"] .article,
html[data-reading-mode="immersive"] .article-body {
  max-width: 820px;
  margin-inline: auto;
}

html[data-reading-mode="immersive"] .article p,
html[data-reading-mode="immersive"] .article-body p {
  font-size: 1.08rem;
  line-height: 1.95;
}

html[data-reading-mode="immersive"] .article h1,
html[data-reading-mode="immersive"] .article h2,
html[data-reading-mode="immersive"] .article h3,
html[data-reading-mode="immersive"] .article h4 {
  letter-spacing: 0.01em;
}

html[data-reading-mode="immersive"] .context-panel,
html[data-reading-mode="immersive"] #context-section,
html[data-reading-mode="immersive"] #glossary-section,
html[data-reading-mode="immersive"] #timeline-section,
html[data-reading-mode="immersive"] .article-footnotes,
html[data-reading-mode="immersive"] .original-appendix,
html[data-reading-mode="immersive"] .sources-section {
  max-width: 920px;
  margin-inline: auto;
}

/* =====================================================
   3.2 ANNOTATED — research reading, highlight footnotes / links / sources
   ===================================================== */
html[data-reading-mode="annotated"] .layout {
  grid-template-columns: 260px minmax(0, 1fr);
}

html[data-reading-mode="annotated"] .toc,
html[data-reading-mode="annotated"] .sidebar,
html[data-reading-mode="annotated"] .toc-panel {
  display: block;
}

html[data-reading-mode="annotated"] .article,
html[data-reading-mode="annotated"] .article-body {
  max-width: 900px;
}

html[data-reading-mode="annotated"] .footnote-ref {
  background: rgba(74, 140, 255, 0.18);
  border: 1px solid rgba(74, 140, 255, 0.4);
  border-radius: 999px;
  padding: 0.05rem 0.32rem;
  color: var(--accent);
  font-weight: 600;
}
html[data-reading-mode="annotated"] .footnote-ref a {
  color: inherit;
  text-decoration: none;
}

html[data-reading-mode="annotated"] .article a,
html[data-reading-mode="annotated"] .article-body a {
  text-decoration: underline;
  text-underline-offset: 0.18em;
  text-decoration-thickness: 1px;
}

html[data-reading-mode="annotated"] .context-panel,
html[data-reading-mode="annotated"] .article-footnotes,
html[data-reading-mode="annotated"] .original-appendix,
html[data-reading-mode="annotated"] .sources-section {
  box-shadow: 0 0 0 1px rgba(74, 140, 255, 0.18);
  border-radius: 12px;
  padding: 1rem 1.15rem;
  margin-block: 1.2rem;
}

html[data-reading-mode="annotated"] #context-section,
html[data-reading-mode="annotated"] #glossary-section,
html[data-reading-mode="annotated"] #timeline-section {
  box-shadow: 0 0 0 1px rgba(74, 140, 255, 0.18);
  border-radius: 12px;
  padding: 1rem 1.15rem;
}

html[data-reading-mode="annotated"] .annotation-hint {
  display: block;
  background: rgba(74, 140, 255, 0.10);
  border-left: 3px solid var(--accent);
  padding: 0.65rem 0.95rem;
  margin: 0 0 1.5rem;
  color: var(--text);
  font-size: 0.95rem;
  border-radius: 4px;
}

html[data-reading-mode="annotated"] .source-card,
html[data-reading-mode="annotated"] .footnote-group {
  box-shadow: 0 0 0 1px rgba(74, 140, 255, 0.16);
  border-color: rgba(74, 140, 255, 0.32);
}

/* =====================================================
   3.3 COMPACT — denser reading, smaller line-height / margins
   ===================================================== */
html[data-reading-mode="compact"] .layout {
  grid-template-columns: 240px minmax(0, 1fr);
}

html[data-reading-mode="compact"] .toc {
  font-size: 0.82rem;
  padding: 1.25rem 1rem;
}

html[data-reading-mode="compact"] .article,
html[data-reading-mode="compact"] .article-body {
  max-width: 980px;
}

html[data-reading-mode="compact"] .article p,
html[data-reading-mode="compact"] .article-body p {
  font-size: 0.96rem;
  line-height: 1.62;
  margin: 0.62rem 0;
}

html[data-reading-mode="compact"] .article ul,
html[data-reading-mode="compact"] .article ol,
html[data-reading-mode="compact"] .article-body ul,
html[data-reading-mode="compact"] .article-body ol {
  margin: 0.5rem 0;
}

html[data-reading-mode="compact"] .article li,
html[data-reading-mode="compact"] .article-body li {
  margin: 0.18rem 0;
}

html[data-reading-mode="compact"] .article h1,
html[data-reading-mode="compact"] .article h2,
html[data-reading-mode="compact"] .article h3,
html[data-reading-mode="compact"] .article h4,
html[data-reading-mode="compact"] .article-body h1,
html[data-reading-mode="compact"] .article-body h2,
html[data-reading-mode="compact"] .article-body h3,
html[data-reading-mode="compact"] .article-body h4 {
  margin-top: 1.7rem;
  margin-bottom: 0.65rem;
}

html[data-reading-mode="compact"] .article-figure,
html[data-reading-mode="compact"] .article-body figure.article-figure {
  margin: 1.2rem auto;
}

html[data-reading-mode="compact"] .article-figure img,
html[data-reading-mode="compact"] .article-body figure.article-figure img {
  max-height: 520px;
  object-fit: contain;
}

html[data-reading-mode="compact"] .module,
html[data-reading-mode="compact"] .section-card,
html[data-reading-mode="compact"] .appendix-card,
html[data-reading-mode="compact"] .source-card,
html[data-reading-mode="compact"] .footnote-group,
html[data-reading-mode="compact"] #context-section,
html[data-reading-mode="compact"] #glossary-section,
html[data-reading-mode="compact"] #timeline-section,
html[data-reading-mode="compact"] .article-footnotes,
html[data-reading-mode="compact"] .original-appendix,
html[data-reading-mode="compact"] .sources-section {
  padding: 0.7rem 0.85rem;
  margin-block: 0.65rem;
}

html[data-reading-mode="compact"] .article hr,
html[data-reading-mode="compact"] .article-body hr {
  margin: 1rem 0;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-base);
  background: var(--bg);
  color: var(--text);
  line-height: var(--line-height, 1.75);
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  overflow-x: hidden;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-soft) 100%);
  min-height: 100vh;
  transition: background 0.4s ease, color 0.2s ease;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* ====== HERO ====== */
.hero {
  position: relative;
  min-height: 92vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4rem 1.5rem 6rem;
  overflow: hidden;
  text-align: center;
}

.hero-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  opacity: 0.95;
}

.hero-bg svg {
  width: 100%;
  height: 100%;
  display: block;
}

.starfield {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.hero-content {
  position: relative;
  z-index: 2;
  max-width: 880px;
  width: 100%;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-bottom: 1.5rem;
}

.badge {
  display: inline-block;
  padding: 0.3rem 0.8rem;
  background: rgba(74, 140, 255, 0.15);
  color: var(--accent);
  border: 1px solid rgba(74, 140, 255, 0.3);
  border-radius: 99px;
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  backdrop-filter: blur(8px);
}

.badge-source { background: rgba(193, 68, 14, 0.15); color: var(--accent-2); border-color: rgba(193, 68, 14, 0.3); }
.badge-translator { background: rgba(255, 179, 71, 0.15); color: var(--accent-3); border-color: rgba(255, 179, 71, 0.3); }

.hero-title {
  font-size: clamp(2.5rem, 7vw, 5rem);
  font-weight: 800;
  line-height: 1.1;
  margin: 0 0 1rem;
  background: linear-gradient(180deg, #fff 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

[data-theme="mars-sand"] .hero-title {
  background: linear-gradient(180deg, #2d1b0f 0%, #c1440e 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero-subtitle {
  font-size: clamp(1rem, 2vw, 1.4rem);
  color: var(--text-dim);
  margin: 0 0 2rem;
  font-weight: 300;
}

.hero-byline {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  justify-content: center;
  margin-bottom: 2.5rem;
  font-size: 0.92rem;
  color: var(--text-dim);
}

.hero-byline strong { color: var(--text); }

.hero-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 2rem;
  justify-content: center;
  margin: 2.5rem 0;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-num {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent);
  font-family: var(--font-mono);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-mute);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.hero-cta {
  display: inline-block;
  padding: 0.85rem 2.5rem;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #fff;
  border-radius: 99px;
  font-weight: 600;
  font-size: 1.05rem;
  transition: transform var(--transition), box-shadow var(--transition);
  box-shadow: 0 4px 16px rgba(74, 140, 255, 0.3);
}

.hero-cta:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(74, 140, 255, 0.5);
  text-decoration: none;
}

.progress-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.1);
  z-index: 3;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-2) 100%);
  transition: width 0.1s linear;
}

/* ====== TOOLBAR ====== */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.tool-group {
  display: flex;
  gap: 0.25rem;
  padding: 0 0.5rem;
  border-left: 1px solid var(--border);
}

.tool-group:first-of-type { border-left: none; padding-left: 0; }

.tool-btn {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid transparent;
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
  transition: all var(--transition);
}

.tool-btn:hover, .tool-btn.active {
  background: var(--bg-card);
  color: var(--text);
  border-color: var(--border);
}

.tool-icon { font-weight: bold; }

#topBtn { margin-left: auto; }

/* ====== LAYOUT ====== */
.layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  max-width: 1200px;
  margin: 0 auto;
  gap: 0;
}

/* ====== TOC ====== */
.toc {
  position: sticky;
  top: 60px;
  align-self: start;
  height: calc(100vh - 60px);
  overflow-y: auto;
  padding: 2rem 1.5rem 2rem 1.5rem;
  border-right: 1px solid var(--border);
  background: var(--bg-soft);
  font-size: 0.9rem;
  transition: transform var(--transition);
}

.toc::-webkit-scrollbar { width: 4px; }
.toc::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.toc-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-mute);
  margin: 0 0 1rem;
}

.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.toc-list ul { padding-left: 1rem; }

.toc-link {
  display: block;
  padding: 0.4rem 0.7rem;
  color: var(--text-dim);
  border-left: 2px solid transparent;
  transition: all var(--transition);
  line-height: 1.4;
}

.toc-link:hover {
  color: var(--text);
  text-decoration: none;
  border-left-color: var(--accent);
}

.toc-link.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: rgba(74, 140, 255, 0.05);
}

.toc-h1 { font-weight: 600; }
.toc-h2 { font-weight: 400; font-size: 0.85rem; }

/* ====== MAIN ====== */
.main {
  padding: 3rem 2.5rem 4rem;
  min-width: 0;
}

.article {
  max-width: var(--content-width);
  margin: 0 auto;
}

.article h1, .article h2, .article h3, .article h4 {
  color: var(--text);
  line-height: 1.3;
  margin: 2.5rem 0 1rem;
  scroll-margin-top: 80px;
}

.article h1 { font-size: 2.2rem; border-bottom: 2px solid var(--accent); padding-bottom: 0.5rem; }
.article h2 { font-size: 1.7rem; color: var(--accent); }
.article h3 { font-size: 1.3rem; color: var(--accent-3); }
.article h4 { font-size: 1.1rem; color: var(--text); font-weight: 600; }

.article p {
  margin: 0 0 1.2rem;
  font-size: 1.05rem;
  color: var(--text);
}

.article ul, .article ol {
  margin: 0 0 1.2rem;
  padding-left: 1.8rem;
}

.article li { margin: 0.4rem 0; }

/* Article figure (V8) */
.article-figure {
  margin: 2rem auto;
  max-width: 100%;
}
.article-figure img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  border-radius: 14px;
}
.article-figure a {
  display: block;
}
.article-figure figcaption {
  margin-top: .65rem;
  color: var(--muted, #94a3b8);
  font-size: .9rem;
  text-align: center;
  line-height: 1.5;
}
.image-fallback {
  border: 1px solid rgba(148, 163, 184, .25);
  border-radius: 12px;
  padding: 1rem;
  color: var(--muted, #94a3b8);
  background: rgba(15, 23, 42, .45);
  font-size: .9rem;
}

.article blockquote {
  border-left: 4px solid var(--accent-2);
  background: var(--bg-card);
  padding: 1rem 1.5rem;
  margin: 1.5rem 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-dim);
  font-style: italic;
}

.article strong { color: var(--accent-3); font-weight: 600; }
.article em { color: var(--accent); font-style: italic; }

.article a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-color: rgba(74, 140, 255, 0.3);
  text-underline-offset: 2px;
}

.article a:hover {
  text-decoration-color: var(--accent);
}

.article img {
  margin: 1.5rem auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  max-height: 70vh;
  object-fit: contain;
}

.article hr {
  border: none;
  border-top: 1px dashed var(--border);
  margin: 2.5rem 0;
}

/* Footnote refs */
.footnote-ref, sup a[href^="#footnote"] {
  display: inline-block;
  padding: 0 0.25em;
  font-size: 0.75em;
  vertical-align: super;
  line-height: 0;
  color: var(--accent);
  text-decoration: none;
}

sup a[href^="#footnote"]:hover {
  background: var(--accent);
  color: #fff;
  border-radius: 2px;
}

/* Footnote section styling */
.article details {
  margin: 0.5rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
  background: var(--bg-card);
  font-size: 0.92rem;
}

.article details summary {
  cursor: pointer;
  color: var(--text-dim);
  font-weight: 500;
}

.article details[open] summary {
  color: var(--accent);
  margin-bottom: 0.5rem;
}

/* ====== MODULES ====== */
.module {
  max-width: var(--content-width);
  margin: 5rem auto 0;
  padding: 2.5rem 0;
  border-top: 1px solid var(--border);
  scroll-margin-top: 80px;
}

.module-title {
  font-size: 1.8rem;
  color: var(--accent);
  margin: 0 0 0.5rem;
  line-height: 1.3;
}

.module-sub {
  color: var(--text-dim);
  font-size: 0.95rem;
  margin: 0 0 2rem;
}

.module-note {
  font-size: 0.88rem;
  color: var(--text-dim);
  font-style: italic;
  margin-top: 1rem;
  padding: 1rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  border-left: 3px solid var(--accent);
}

/* Why Mars Cards */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  transition: all var(--transition);
}

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

.card summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent);
  font-size: 1.05rem;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card summary::before {
  content: "→";
  color: var(--accent-2);
  font-weight: bold;
}

.card[open] summary::before { content: "↓"; }

.card p {
  margin: 0.8rem 0 0;
  color: var(--text-dim);
  font-size: 0.95rem;
}

/* Roadmap */
.roadmap {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.roadmap-step {
  display: flex;
  gap: 1.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  border-left: 4px solid var(--accent);
}

.roadmap-num {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
}

.roadmap-body h3 { margin: 0 0 0.6rem; color: var(--accent); font-size: 1.2rem; }
.roadmap-body p { margin: 0 0 0.8rem; color: var(--text); font-size: 0.95rem; }

.roadmap-tag {
  display: inline-block;
  padding: 0.25rem 0.7rem;
  border-radius: 4px;
  font-size: 0.78rem;
  margin-right: 0.5rem;
}

.roadmap-tag.status-2015 { background: rgba(74, 140, 255, 0.15); color: var(--accent); }
.roadmap-tag.status-2026 { background: rgba(193, 68, 14, 0.15); color: var(--accent-2); }

/* Cost curve */
.cost-curve {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.5rem;
  border: 1px solid var(--border);
}

.cost-curve svg { width: 100%; height: auto; max-width: 600px; display: block; margin: 0 auto; }

/* Backup diagram */
.backup-diagram {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 1.5rem;
  align-items: center;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 2rem;
  border: 1px solid var(--border);
}

.planet { text-align: center; }
.planet-circle {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  margin: 0 auto 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.4rem;
  color: #fff;
  box-shadow: 0 0 60px rgba(74, 140, 255, 0.4);
}

.earth-circle { background: radial-gradient(circle at 30% 30%, #6cb0ff 0%, #1e5a99 100%); }
.mars-circle { background: radial-gradient(circle at 30% 30%, #c1440e 0%, #5a1a08 100%); box-shadow: 0 0 60px rgba(193, 68, 14, 0.4); }

.planet-stats { font-size: 0.9rem; color: var(--text-dim); }
.planet-stats div { margin: 0.3rem 0; }

.arrow {
  font-size: 3rem;
  color: var(--accent);
  font-weight: 300;
  text-align: center;
}

/* Compare table */
.compare-table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }

.compare-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.compare-table th, .compare-table td {
  padding: 0.8rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.compare-table th {
  background: var(--bg-soft);
  color: var(--accent);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.78rem;
  letter-spacing: 0.05em;
}

.compare-table tr:hover { background: var(--bg-card); }

.compare-table td.ok { color: #4ade80; font-weight: 600; }
.compare-table td.warn { color: #fbbf24; font-weight: 600; }
.compare-table td.fail { color: #f87171; font-weight: 600; }

/* Glossary */
.glossary-search {
  width: 100%;
  padding: 0.7rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  margin-bottom: 1.5rem;
}

.glossary-search:focus { outline: none; border-color: var(--accent); }

.glossary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}

.glossary-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  border-left: 3px solid var(--accent);
}

.glossary-term {
  color: var(--accent);
  font-weight: 600;
  font-size: 1.05rem;
  margin: 0 0 0.4rem;
}

.glossary-def {
  color: var(--text-dim);
  font-size: 0.9rem;
  line-height: 1.5;
  margin: 0;
}

/* Timeline */
.timeline-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.filter-btn {
  background: var(--bg-card);
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 0.4rem 0.85rem;
  border-radius: 99px;
  cursor: pointer;
  font-size: 0.82rem;
  font-family: inherit;
  transition: all var(--transition);
}

.filter-btn:hover { color: var(--text); }

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

.timeline {
  list-style: none;
  padding: 0 0 0 1.5rem;
  border-left: 2px solid var(--border);
}

.timeline li {
  position: relative;
  padding: 0.8rem 0 0.8rem 1.5rem;
  margin: 0.3rem 0;
  background: var(--bg-card);
  border-radius: 0 var(--radius) var(--radius) 0;
  border: 1px solid var(--border);
  border-left: none;
  margin-left: -1.5rem;
  padding-left: 2.2rem;
}

.timeline li::before {
  content: "●";
  position: absolute;
  left: -0.5rem;
  top: 0.8rem;
  background: var(--bg);
  color: var(--accent);
  font-size: 1.2rem;
}

.timeline-date {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
}

.timeline-event {
  display: block;
  margin-top: 0.2rem;
  color: var(--text);
}

.timeline-cat {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0.1rem 0.5rem;
  background: var(--bg-soft);
  color: var(--text-mute);
  border-radius: 4px;
  font-size: 0.72rem;
  text-transform: uppercase;
}

/* Sources */
.sources-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
}

.source-block h3 {
  color: var(--accent);
  font-size: 1rem;
  margin: 0 0 0.5rem;
}

.source-block ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.source-block li {
  padding: 0.3rem 0;
  font-size: 0.88rem;
  color: var(--text-dim);
}

.source-block a { color: var(--link); }

/* Article footer */
.article-footer {
  max-width: var(--content-width);
  margin: 5rem auto 0;
  padding: 2rem 0 0;
  border-top: 1px solid var(--border);
  font-size: 0.88rem;
  color: var(--text-dim);
  text-align: center;
}

.footer-note { font-size: 0.78rem; color: var(--text-mute); }

/* Loading state */
.loading {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-mute);
  font-style: italic;
}

/* Search overlay */
.search-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 100;
  display: flex;
  flex-direction: column;
  padding: 4rem 1.5rem 1.5rem;
  backdrop-filter: blur(4px);
}

.search-overlay[hidden] {
  display: none !important;
}

/* No-JS fallback banner */
.noscript-banner {
  background: #fef3c7;
  border: 1px solid #f59e0b;
  color: #92400e;
  padding: 1.5rem;
  margin: 1.5rem auto;
  max-width: 900px;
  border-radius: 8px;
  font-size: 0.95rem;
  line-height: 1.7;
}

.noscript-banner ul {
  margin: 0.5rem 0 0.5rem 1.5rem;
}

.noscript-banner a {
  color: #92400e;
  text-decoration: underline;
  font-weight: 600;
}

.noscript-banner p {
  margin-top: 0.5rem;
}

.search-box {
  display: flex;
  gap: 0.5rem;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

.search-box input {
  flex: 1;
  padding: 1rem;
  font-size: 1.2rem;
  background: var(--bg-card);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
}

.search-box button {
  width: 50px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1.5rem;
  cursor: pointer;
}

.search-results {
  max-width: 800px;
  margin: 1.5rem auto 0;
  width: 100%;
  background: var(--bg-soft);
  border-radius: var(--radius);
  padding: 1rem;
  max-height: 70vh;
  overflow-y: auto;
}

.search-results .hit {
  padding: 0.8rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}

.search-results .hit:hover { background: var(--bg-card); }

.search-results mark {
  background: var(--accent-3);
  color: #000;
  padding: 0 2px;
  border-radius: 2px;
}

/* ====== RESPONSIVE ====== */
@media (max-width: 1024px) {
  .layout { grid-template-columns: 220px 1fr; }
  .main { padding: 2rem 1.5rem 3rem; }
}

@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }
  .toc {
    position: fixed;
    top: 60px;
    left: 0;
    width: 280px;
    height: calc(100vh - 60px);
    z-index: 60;
    transform: translateX(-100%);
    background: var(--bg-soft);
  }
  .toc.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5); }
  .hero { min-height: 80vh; padding: 2rem 1rem 4rem; }
  .hero-stats { gap: 1rem; }
  .stat-num { font-size: 1.4rem; }
  .main { padding: 1.5rem 1rem 2.5rem; }
  .toolbar { padding: 0.5rem 0.75rem; font-size: 0.8rem; }
  .tool-btn { padding: 0.35rem 0.6rem; font-size: 0.78rem; }
  .backup-diagram { grid-template-columns: 1fr; }
  .arrow { transform: rotate(90deg); }
  .planet-circle { width: 100px; height: 100px; font-size: 1.1rem; }
  .roadmap-step { flex-direction: column; gap: 1rem; }
  .roadmap-num { align-self: flex-start; }
  .module { margin-top: 3rem; }
  .hero-byline { gap: 0.75rem; font-size: 0.82rem; }
  #topBtn { display: none; }
}

@media (max-width: 480px) {
  .hero-stats { flex-direction: column; gap: 0.5rem; }
  .article h1 { font-size: 1.6rem; }
  .article h2 { font-size: 1.3rem; }
  .article h3 { font-size: 1.1rem; }
  .article p { font-size: 0.98rem; }
  .module-title { font-size: 1.4rem; }
}

/* V9C structure / appendix polish */
.article-footnotes,
.original-appendix,
.context-panel,
.sources-section {
  margin: 4rem auto;
  padding-top: 1.5rem;
  border-top: 1px solid rgba(148, 163, 184, 0.22);
}

.article-footnotes {
  font-size: 0.94rem;
  color: var(--text-muted, #94a3b8);
}

.footnote-list {
  padding-left: 1.35rem;
}

.footnote-list li {
  margin: 0.75rem 0;
  line-height: 1.75;
}

.footnote-ref {
  font-size: 0.75em;
  margin-left: 0.12rem;
}

.footnote-backref {
  margin-left: 0.5rem;
  text-decoration: none;
  opacity: 0.8;
}

.original-appendix details {
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 16px;
  padding: 1rem 1.15rem;
  background: rgba(15, 23, 42, 0.28);
}

.original-appendix summary {
  cursor: pointer;
  font-weight: 700;
}

.appendix-card,
.source-card {
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 14px;
  padding: 1rem;
  margin: 0.85rem 0;
  background: rgba(15, 23, 42, 0.20);
}

.sources-grid {
  display: grid;
  gap: 1rem;
}

@media (min-width: 900px) {
  .sources-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* V10 anchor / TOC / appendix / sources polish */
section[id],
h1[id],
h2[id],
h3[id] {
  scroll-margin-top: 112px;
}

.toc a[href="#article-footnotes"],
.toc a[href="#original-appendix"],
.toc a[href="#sources-section"] {
  font-weight: 650;
}

.footnote-help {
  color: var(--text-dim, #94a3b8);
  font-size: 0.95rem;
  margin-bottom: 1rem;
}

.footnote-group {
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 14px;
  padding: 0.85rem 1rem;
  margin: 0.85rem 0;
  background: rgba(15, 23, 42, 0.18);
}

.footnote-group > summary {
  cursor: pointer;
  font-weight: 700;
}

.source-card-title,
.appendix-card-title {
  margin: 0 0 0.5rem;
}

.source-card-meta {
  color: var(--text-dim, #94a3b8);
  font-size: 0.88rem;
  margin: 0 0 0.6rem;
}

.source-list {
  margin: 0;
  padding-left: 1.15rem;
}

.page-version-marker {
  margin-top: 1rem;
  font-size: 0.82rem;
  color: var(--text-mute, #5b6577);
  letter-spacing: 0.02em;
}
