/* ============================================================
   Physics Fundamentals — RETRO CRT TERMINAL theme
   Phosphor green (dark) / amber (light) terminal readouts.
   ============================================================ */

@import url('reset.css');

/* ---------- Tokens ------------------------------------------------ */

:root {
  /* Layout */
  --max-width: 1100px;
  --gap: clamp(1.5rem, 4vw, 2.5rem);
  --radius: 0px;
  --line: 1px solid var(--border);

  /* Terminal font stack */
  --font-mono: 'JetBrainsMono Nerd Font', 'JetBrainsMono NF', 'JetBrains Mono',
    'Adwaita Mono', 'DejaVu Sans Mono', ui-monospace, monospace;

  /* Light attr = AMBER phosphor terminal */
  --bg-paper: #0c0805;
  --bg-page: #070503;
  --bg-card: #16110a;
  --bg-recess: #050302;
  --text: #f7e6c2;
  --text-dim: #c2a87c;
  --accent: #ffb000;
  --accent-2: #ffd166;
  --accent-wash: #241a09;
  --border: #4d3b1d;
  --border-bright: #7d5f28;
  --math: #fff0cf;
  --code-bg: #1c150b;
  --code-ink: #ffd166;
  --link-underline: #ffd166;
  --sel-bg: #ffb000;
  --sel-text: #0c0805;

  /* Callout hues */
  --c-definition: #ffb000;
  --c-tip: #ffd166;
  --c-note: #ff7a45;
  --c-example: #4ee3c1;

  /* Diagram (inline SVG) ink */
  --diagram-ink: #f2dcb0;
  --diagram-line: #d3ad70;
  --diagram-accent: #ffb000;
  --diagram-panel: #16110a;
  --diagram-on-fill: #0c0805;
  --diagram-red: #ff8b6b;
  --diagram-blue: #9fd0ff;

  --glow: 0 0 6px color-mix(in srgb, var(--accent) 45%, transparent);
  --glow-soft: 0 0 4px color-mix(in srgb, var(--accent) 30%, transparent);
}

/* Dark attr = GREEN phosphor terminal (default CRT) */
:root[data-theme='dark'] {
  --bg-paper: #050805;
  --bg-page: #030503;
  --bg-card: #0b130c;
  --bg-recess: #010301;
  --text: #c8f5d5;
  --text-dim: #86c99b;
  --accent: #33ff66;
  --accent-2: #00ffa8;
  --accent-wash: #0f2517;
  --border: #1f4029;
  --border-bright: #31744a;
  --math: #ddffe7;
  --code-bg: #0d1810;
  --code-ink: #6effa6;
  --link-underline: #00ffa8;
  --sel-bg: #33ff66;
  --sel-text: #04140a;

  --c-definition: #33ff66;
  --c-tip: #00ffa8;
  --c-note: #ffb454;
  --c-example: #5ef2ff;

  --diagram-ink: #bdf5cf;
  --diagram-line: #7fd6a0;
  --diagram-accent: #33ff66;
  --diagram-panel: #0b130c;
  --diagram-on-fill: #04140a;
  --diagram-red: #ff7b6b;
  --diagram-blue: #9fd0ff;
}

/* ---------- Base -------------------------------------------------- */

html {
  font-size: 100%;
  scroll-behavior: smooth;
  scrollbar-color: var(--border-bright) var(--bg-recess);
  scrollbar-width: thin;
}

body {
  background: var(--bg-paper);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 1rem;
  line-height: 1.75;
  margin: 0;
  letter-spacing: 0.01em;
  -webkit-font-smoothing: antialiased;
}

/* CRT scanlines */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9000;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.26) 3px
  );
  opacity: 0.55;
}

/* CRT vignette / tube curvature */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9001;
  background:
    radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 52%, rgba(0, 0, 0, 0.42) 88%, rgba(0, 0, 0, 0.7) 100%),
    repeating-linear-gradient(to bottom, rgba(255, 255, 255, 0.012) 0 1px, rgba(0, 0, 0, 0) 1px 4px);
}

::selection {
  background: var(--sel-bg);
  color: var(--sel-text);
}

::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: var(--bg-recess); border: 1px solid var(--border); }
::-webkit-scrollbar-thumb {
  background: var(--border-bright);
  border: 2px solid var(--bg-recess);
}
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

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

.sans,
.eyebrow,
.byline,
.caption,
.topic-card h3,
.read,
.nav a,
.theme-toggle,
.menu-btn,
.site-footer,
.btn-sm {
  font-family: var(--font-mono);
}

.sans { font-family: var(--font-mono); }

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: clamp(1.25rem, 3vw, 2.25rem);
}

em { color: var(--accent-2); font-style: italic; }
strong { color: var(--text); font-weight: 700; }
mark {
  background: var(--accent);
  color: var(--sel-text);
  padding: 0 2px;
}

/* ---------- Header / status bar ----------------------------------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-page);
  border-bottom: 1px solid var(--border-bright);
}

.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0.6rem clamp(1rem, 3vw, 2.25rem);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  height: 58px;
  position: relative;
}

/* Title sits in the centre column, optically centred across the whole bar */
.header-inner .site-logo {
  grid-column: 2;
  justify-self: center;
  text-align: center;
}
/* Dropdown trigger hugs the left edge */
.header-inner .nav {
  grid-column: 1;
  justify-self: start;
}
/* Search box + theme toggle pushed to the right edge */
.header-inner .search-box {
  grid-column: 3;
  justify-self: end;
}

.site-logo {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  text-shadow: var(--glow);
  white-space: nowrap;
}
.site-logo::before { content: '['; color: var(--accent-2); }
.site-logo::after  { content: ']'; color: var(--accent-2); }
.site-logo .dot { color: var(--accent-2); }

.nav {
  display: flex;
  align-items: center;
  gap: 0.15rem;
}

.nav a {
  color: var(--text-dim);
  font-size: 0.74rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 0.4rem 0.55rem;
  border: 1px solid transparent;
  transition: color 0.15s linear, border-color 0.15s linear;
}
.nav a::before { content: '['; opacity: 0; transition: opacity 0.15s linear; }
.nav a::after  { content: ']'; opacity: 0; transition: opacity 0.15s linear; }
.nav a:hover,
.nav a:focus-visible,
.nav a[aria-current='page'],
.nav a.active {
  color: var(--accent);
  border-color: var(--border-bright);
  background: var(--accent-wash);
  text-shadow: var(--glow-soft);
}
.nav a:hover::before,
.nav a:focus-visible::before,
.nav a[aria-current='page']::before,
.nav a.active::before,
.nav a:hover::after,
.nav a:focus-visible::after,
.nav a[aria-current='page']::after,
.nav a.active::after { opacity: 1; }

.nav .theme-toggle,
.nav .menu-btn {
  margin-left: 0.35rem;
  padding: 0.3rem 0.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border-bright);
  color: var(--accent-2);
  font-size: 0.9rem;
  line-height: 1;
  transition: color 0.15s linear, border-color 0.15s linear;
}
.nav .theme-toggle:hover,
.nav .menu-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  text-shadow: var(--glow-soft);
}

/* ---------- Search (injected by js/main.js) ----------------------- */

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  margin-left: 0.5rem;
}
.search-box::before {
  content: '>';
  color: var(--accent);
  margin-right: 0.35rem;
  font-weight: 700;
}
.search-input {
  width: 190px;
  max-width: 40vw;
  padding: 0.35rem 0.55rem;
  border: var(--line);
  border-radius: 0;
  background: var(--bg-recess);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  caret-color: var(--accent-2);
}
.search-input:focus {
  outline: none;
  border-color: var(--accent);
  width: 240px;
  max-width: 50vw;
}
.search-input::placeholder {
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.search-results {
  position: absolute;
  top: 110%;
  left: 0;
  right: 0;
  max-height: 300px;
  overflow-y: auto;
  background: var(--bg-card);
  border: var(--line);
  display: none;
  z-index: 60;
}
.search-item {
  display: block;
  padding: 0.45rem 0.65rem;
  color: var(--text);
  font-size: 0.8rem;
  border-bottom: var(--line);
}
.search-item:last-child { border-bottom: none; }
.search-item:hover,
.search-item[aria-selected='true'],
.search-item.active {
  background: var(--accent-wash);
  color: var(--accent);
}
.search-title {
  display: block;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.search-url {
  display: block;
  font-size: 0.7rem;
  color: var(--text-dim);
}
.search-item.active .search-url { color: var(--accent-2); }

.menu-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg-card);
  border: 1px solid var(--border-bright);
  color: var(--accent-2);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s linear, border-color 0.15s linear, background 0.15s linear;
}
.menu-btn:hover,
.menu-btn[aria-expanded='true'] {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-wash);
  text-shadow: var(--glow-soft);
}

/* ---------- Topic dropdown ---------------------------------------- */
.nav {
  position: relative;
}
.nav-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 15rem;
  display: flex;
  flex-direction: column;
  background: var(--bg-page);
  border: 1px solid var(--border-bright);
  box-shadow: 4px 4px 0 rgb(0 0 0 / 0.45);
  z-index: 60;
  padding: 0.35rem;
}
.nav-dropdown[hidden] {
  display: none;
}
.nav-dropdown a {
  display: block;
  padding: 0.5rem 0.75rem;
  border: 1px solid transparent;
  color: var(--text-dim);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}
.nav-dropdown a:hover,
.nav-dropdown a:focus-visible {
  color: var(--accent);
  border-color: var(--border-bright);
  background: var(--accent-wash);
  outline: none;
}
.nav-dropdown a.active,
.nav-dropdown a[aria-current='page'] {
  color: var(--accent);
  border-color: var(--border-bright);
  background: var(--accent-wash);
  text-shadow: var(--glow-soft);
}
.dropdown-divider {
  height: 1px;
  margin: 0.35rem 0;
  background: var(--border-bright);
}
.nav-dropdown .theme-toggle {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.75rem;
  background: none;
  border: 1px solid transparent;
  color: var(--accent-2);
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  cursor: pointer;
}
.nav-dropdown .theme-toggle:hover {
  color: var(--accent);
  border-color: var(--border-bright);
  background: var(--accent-wash);
}

/* ---------- Hero / boot screen ------------------------------------ */

.hero {
  text-align: center;
  padding: clamp(2.5rem, 7vw, 4.5rem) clamp(1.25rem, 3vw, 2.25rem);
  background: var(--bg-paper);
  border-bottom: var(--line);
}

/* ASCII frame rails */
.hero::before,
.hero::after {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  color: var(--border-bright);
  font-size: 0.7rem;
  line-height: 1;
  letter-spacing: 0.02em;
  margin: 0 auto 1.5rem;
}
.hero::before {
  content: '┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐';
}
.hero::after {
  content: '└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘';
  margin: 2rem auto 0;
}

.hero .eyebrow,
.article-header .eyebrow,
.eyebrow {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.28em;
  color: var(--accent-2);
  font-weight: 700;
  margin-bottom: 0.9rem;
}
.eyebrow::before { content: '// '; color: var(--accent); }

.hero h1,
.article-header h1 {
  font-size: clamp(1.6rem, 4vw, 2.9rem);
  font-weight: 700;
  line-height: 1.25;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  text-shadow: var(--glow);
  margin-bottom: 0.9rem;
}

.hero p.lead {
  font-size: clamp(0.98rem, 2vw, 1.1rem);
  color: var(--text);
  max-width: 44rem;
  margin: 0 auto 2.25rem;
}

.hero .eyebrow::after {
  content: '_';
  animation: crt-blink 1.1s steps(2, start) infinite;
  color: var(--accent);
}

@keyframes crt-blink {
  to { opacity: 0; }
}

/* ---------- Topic cards ------------------------------------------- */

.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: var(--gap);
  margin: 0 auto;
  max-width: 1100px;
  text-align: left;
}

.topic-card {
  background: var(--bg-card);
  border: var(--line);
  border-left: 3px solid var(--border-bright);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
  text-align: left;
  color: var(--text);
  transition: border-color 0.15s linear, background-color 0.15s linear;
}
.topic-card:hover,
.topic-card:focus-visible {
  background: var(--accent-wash);
  border-color: var(--accent);
  border-left-color: var(--accent);
}
.topic-card:hover .icon {
  border-color: var(--accent);
  text-shadow: var(--glow);
}

.topic-card .icon {
  font-size: 1.35rem;
  line-height: 1;
  width: 2.5rem;
  height: 2.5rem;
  display: grid;
  place-items: center;
  border: var(--line);
  background: var(--bg-recess);
  margin-bottom: 0.85rem;
}
.topic-card h3 {
  font-size: 0.98rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  text-shadow: var(--glow-soft);
  margin-bottom: 0.5rem;
}
.topic-card p {
  color: var(--text-dim);
  font-size: 0.86rem;
  line-height: 1.65;
  margin: 0 0 0.9rem;
}
.topic-card .read {
  color: var(--accent-2);
  font-weight: 700;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}
.topic-card .read::after {
  content: '_';
  animation: crt-blink 1.1s steps(2, start) infinite;
}

/* ---------- Article shell ----------------------------------------- */

.article {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: clamp(2rem, 4.5vw, 3.5rem) clamp(1.25rem, 3vw, 2.25rem);
}

.article-header {
  text-align: center;
  padding-bottom: 1.75rem;
  border-bottom: 1px dashed var(--border-bright);
  margin-bottom: 2.25rem;
}
.article-header .byline {
  color: var(--text-dim);
  font-size: 0.88rem;
  line-height: 1.7;
  letter-spacing: 0.03em;
  max-width: 46rem;
  margin: 0 auto;
  font-style: normal;
}

/* ---------- Table of contents ------------------------------------- */

.toc {
  background: var(--bg-card);
  border: var(--line);
  border-radius: var(--radius);
  padding: 1.35rem 1.6rem;
  margin-bottom: 2.5rem;
}
.toc::before {
  content: 'FILE: CONTENTS';
  display: block;
  font-size: 0.7rem;
  letter-spacing: 0.22em;
  color: var(--accent-2);
  margin-bottom: 0.9rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px dashed var(--border);
}
.toc ol { counter-reset: toc olist; list-style: none; margin: 0; padding: 0; }
.toc li {
  margin: 0.45rem 0;
  padding-left: 2.75rem;
  position: relative;
  counter-increment: toc;
  font-size: 0.9rem;
}
.toc li::before {
  content: '[' counter(toc, decimal-leading-zero) ']';
  position: absolute;
  left: 0;
  top: 0.1rem;
  color: var(--accent-2);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
}
.toc a { color: var(--accent); font-weight: 500; }
.toc a:hover { color: var(--accent-2); text-shadow: var(--glow-soft); }
.toc li > span:not(.glossary-term) {
  background: var(--accent-wash) !important;
  border: var(--line);
  padding: 0 0.35rem !important;
  border-radius: 0;
}

/* ---------- Section headings -------------------------------------- */

.section-title {
  font-size: clamp(1.1rem, 2.4vw, 1.45rem);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 2.75rem 0 1.25rem;
  padding-bottom: 0.55rem;
  border-bottom: var(--line);
  color: var(--accent);
  text-shadow: var(--glow-soft);
}
.section-title::before {
  content: '## ';
  color: var(--accent-2);
}
.section-title .num {
  color: var(--accent-2);
  font-weight: 700;
}

h3 {
  font-size: 1.02rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent-2);
  margin: 2rem 0 0.75rem;
}
h4 {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent-2);
  margin: 1.5rem 0 0.6rem;
}

p { margin: 1.1em 0; }

.subtitle {
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent-2);
  margin: 1.2em 0;
}

eq {
  font-style: italic;
  color: var(--accent-2);
}

/* MathJax must stay high contrast on the dark terminal */
.mjx-ch { color: var(--math) !important; }

/* ---------- Equations: terminal readout --------------------------- */

.equation {
  position: relative;
  text-align: center;
  margin: 1.5em 0;
  padding: 0.9rem 1rem 1rem;
  background: var(--bg-recess);
  border: var(--line);
  border-top: 2px solid var(--border-bright);
  border-radius: var(--radius);
  font-size: 1.08rem;
  overflow-x: auto;
  color: var(--math);
}
.equation::before {
  content: '>> EQ';
  display: block;
  text-align: left;
  font-size: 0.66rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--accent-2);
  margin-bottom: 0.55rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px dashed var(--border);
}
.equation.equation-block { display: block; }
.equation-number {
  display: block;
  text-align: right;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  color: var(--accent-2);
  margin-top: 0.4rem;
}

/* ---------- Callout boxes ----------------------------------------- */

.definition,
.tip,
.note,
.example {
  border: var(--line);
  border-left: 4px solid var(--c-definition);
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 0.85rem 1.15rem 0.95rem;
  margin: 1.4em 0;
  color: var(--text);
}
.definition::before,
.tip::before,
.note::before,
.example::before {
  display: block;
  font-size: 0.66rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  font-weight: 700;
  margin-bottom: 0.4rem;
}
.definition::before { content: '>> DEFINITION'; color: var(--c-definition); }
.tip::before       { content: '>> TIP';       color: var(--c-tip); }
.note::before      { content: '>> NOTE';      color: var(--c-note); }
.example::before   { content: '>> EXAMPLE';   color: var(--c-example); }

.tip {
  border-left-color: var(--c-tip);
}
.note {
  border-left-color: var(--c-note);
}
.example {
  border-left-color: var(--c-example);
}
.definition strong,
.tip strong,
.note strong,
.example strong { color: var(--text); }

/* ---------- Lists ------------------------------------------------- */

.article ul,
.article ol,
ul,
ol {
  padding-left: 1.5rem;
  margin: 1em 0;
}
li { margin: 0.35em 0; }
ul { list-style: none; }
ol { list-style: none; counter-reset: olist; }
ul > li { position: relative; }
ul > li::before {
  content: '▸';
  position: absolute;
  left: -1.25rem;
  color: var(--accent-2);
}
ol > li { counter-increment: olist; }
ol > li::before {
  content: counter(olist) '. ';
  color: var(--accent-2);
}

blockquote {
  margin: 1.4em 0;
  padding: 0.7rem 1.1rem;
  border: var(--line);
  border-left: 4px solid var(--accent-2);
  background: var(--bg-card);
  color: var(--text-dim);
}

/* ---------- Code / formulas --------------------------------------- */

code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--code-bg);
  border: var(--line);
  padding: 0.1rem 0.4rem;
  border-radius: 0;
  color: var(--code-ink);
}
pre {
  background: var(--bg-recess);
  padding: 1rem 1.15rem;
  border: var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: 0.86rem;
  line-height: 1.6;
}
pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.86rem;
  color: var(--text-dim);
}

/* ---------- Tables ------------------------------------------------ */

table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5em 0;
  font-size: 0.85rem;
  border: var(--line);
  background: var(--bg-card);
}
th, td {
  text-align: left;
  padding: 0.55rem 0.8rem;
  border: var(--line);
}
th {
  background: var(--accent-wash);
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.74rem;
}
td { color: var(--text); }
tbody tr:nth-child(even) td { background: var(--bg-recess); }

/* ---------- Figures / inline SVG diagrams ------------------------- */

.figure {
  text-align: center;
  margin: 1.8em 0;
  padding: 1.25rem 1rem;
  background: var(--bg-card);
  border: var(--line);
  border-radius: var(--radius);
}
.figure.center { text-align: center; }
.figure img,
.figure svg {
  max-width: 100%;
  height: auto;
  margin: 0 auto;
}
.figure svg text {
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}
.figure .caption,
.caption {
  font-size: 0.74rem;
  color: var(--text-dim);
  letter-spacing: 0.05em;
  line-height: 1.6;
  margin-top: 0.85rem;
  font-style: normal;
}
.caption::before {
  content: '// ';
  color: var(--accent-2);
}

/* Recolour the hard-coded diagram palette onto the terminal background.
   SVG presentation attributes are overridden by any CSS declaration. */
.figure svg [stroke='#333'],
.figure svg [stroke='#334155'] { stroke: var(--diagram-line); }
.figure svg [fill='#333'],
.figure svg [fill='#555'],
.figure svg [fill='#777'],
.figure svg [fill='#334155'] { fill: var(--diagram-ink); }
.figure svg [fill='#faf8f5'] { fill: var(--diagram-panel); }
.figure svg [fill='#000'] { fill: var(--diagram-ink); }
.figure svg [fill='#fff'] { fill: var(--diagram-on-fill); }
.figure svg [fill='#2563eb'],
.figure svg [fill='#1e40af'] { fill: var(--diagram-accent); }
.figure svg [stroke='#2563eb'],
.figure svg [stroke='#1e40af'],
.figure svg [stroke='#0ea5e9'] { stroke: var(--diagram-accent); }
.figure svg [fill='#0ea5e9'] { fill: var(--diagram-blue); }
.figure svg [fill='#ef4444'],
.figure svg [stroke='#ef4444'] { fill: var(--diagram-red); stroke: var(--diagram-red); }
.figure svg [fill='#93c5fd'],
.figure svg [stroke='#93c5fd'] { fill: var(--diagram-blue); stroke: var(--diagram-blue); }
.figure svg [fill='#cbd5e1'] { fill: var(--diagram-line); }

/* ---------- Simulations ------------------------------------------- */

.sim {
  background: var(--bg-card);
  border: var(--line);
  border-top: 2px solid var(--border-bright);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem 1.25rem;
  margin: 1.6em 0;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.sim::before {
  content: '>> SIMULATION';
  font-size: 0.66rem;
  letter-spacing: 0.24em;
  color: var(--accent-2);
}

/* Canvas keeps its own JS-drawn light plot area; only frame it. */
.sim canvas,
.sim Canvas,
canvas.sim-canvas {
  background: #f5f3f0;
  border: var(--line);
  border-radius: 0;
  width: 100%;
  display: block;
}
.sim .controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  align-items: center;
  padding-top: 0.35rem;
  border-top: 1px dashed var(--border);
}
.sim label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.sim label span { color: var(--accent); min-width: 2.2rem; }
.sim input[type='range'] {
  width: 130px;
  accent-color: var(--accent);
  background: transparent;
}

/* Buttons injected by js/simulations.js */
.btn-sm {
  background: var(--bg-recess);
  border: var(--line);
  border-color: var(--border-bright);
  color: var(--accent);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  padding: 0.3rem 0.7rem;
  transition: color 0.15s linear, border-color 0.15s linear, background-color 0.15s linear;
}
.btn-sm:hover {
  background: var(--accent-wash);
  border-color: var(--accent);
  text-shadow: var(--glow-soft);
}
.btn-sm::before { content: '['; opacity: 0.5; }
.btn-sm::after  { content: ']'; opacity: 0.5; }

/* ---------- Glossary terms ---------------------------------------- */

.glossary-term {
  display: inline-block;
  border-bottom: 2px dotted var(--accent-2);
  color: var(--text);
  cursor: help;
  position: relative;
}
.glossary-term:hover {
  color: var(--accent);
  text-shadow: var(--glow-soft);
}
.glossary-term:hover::after {
  content: '// ' attr(data-term);
  position: absolute;
  bottom: 130%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: 0;
  padding: 0.45rem 0.7rem;
  font-size: 0.74rem;
  line-height: 1.5;
  letter-spacing: 0.04em;
  white-space: normal;
  text-align: left;
  text-shadow: none;
  color: var(--text);
  z-index: 30;
  max-width: min(260px, 80vw);
  width: max-content;
}

/* ---------- Footer ------------------------------------------------ */

.site-footer {
  background: var(--bg-page);
  border-top: 1px solid var(--border-bright);
  text-align: center;
  padding: 2rem clamp(1.25rem, 3vw, 2.25rem);
  color: var(--text-dim);
  font-size: 0.76rem;
  letter-spacing: 0.08em;
}
.site-footer::before {
  content: '─[ END OF SESSION ]─';
  display: block;
  color: var(--accent-2);
  font-size: 0.7rem;
  letter-spacing: 0.3em;
  margin-bottom: 1rem;
}
.site-footer a {
  color: var(--accent);
  border-bottom: 1px solid var(--accent);
}
.site-footer a:hover { color: var(--accent-2); }

/* ---------- Reveal animation --------------------------------------- */

.fade-in {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.4s linear, transform 0.4s ease;
}
.fade-in.visible {
  opacity: 1;
  transform: none;
}

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

@media (max-width: 860px) {
  .nav a {
    font-size: 0.7rem;
    padding: 0.35rem 0.4rem;
    letter-spacing: 0.06em;
  }
}

@media (max-width: 720px) {
  .header-inner {
    padding: 0 0.75rem;
    height: 52px;
  }
  .header-inner {
    grid-template-columns: auto 1fr auto;
  }
  .header-inner .site-logo {
    grid-column: 2;
    font-size: 0.82rem;
    letter-spacing: 0.1em;
  }
  .header-inner .nav {
    grid-column: 1;
  }
  .header-inner .search-box {
    grid-column: 3;
  }
  .nav-dropdown {
    position: fixed;
    top: 52px;
    left: 0;
    right: 0;
    max-height: calc(100vh - 52px);
    overflow-y: auto;
    padding: 0.85rem clamp(1.25rem, 3vw, 2.25rem);
    border-bottom: 1px solid var(--border-bright);
    border-top: 1px solid var(--border-bright);
  }
  .nav-dropdown a {
    width: 100%;
    justify-content: flex-start;
    border-bottom: 1px solid var(--border);
  }
  .nav-dropdown a:last-of-type {
    border-bottom: none;
  }
  .menu-btn { display: block; }
  .search-box { margin: 0.35rem 0; width: 100%; }
  .search-input { width: 100% !important; max-width: 100% !important; }
  .hero { padding: clamp(2rem, 6vw, 3rem) 0.9rem; }
  .article { padding: 1.5rem 0.9rem; }
  .definition, .tip, .note, .example { padding: 0.75rem 0.9rem; }
  .hero::before, .hero::after { font-size: 0.55rem; }
  .equation { font-size: 1rem; }
}

/* ---------- Narrow phones (320-400px) --------------------------------- */

/* Global guard: MathJax sets overflow-x:auto on mjx-container, but the
   elements it wraps can still exceed the viewport. This clips the page
   itself so a wide equation can never create a whole-body sideways scroll. */
html, body { max-width: 100%; overflow-x: hidden; }

/* Below ~400px the header logo, search field and wide display equations
   together exceed the viewport, forcing a horizontal scroll. Fix by letting
   the search collapse, allowing the logo to shrink, and scrolling wide math
   inside its own box rather than the page. */

@media (max-width: 400px) {
  .header-inner {
    grid-template-columns: auto minmax(0, 1fr) auto;
    padding: 0 0.5rem;
  }
  .header-inner .site-logo {
    font-size: 0.66rem !important;
    letter-spacing: 0.06em !important;
    min-width: 0 !important;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  /* Grid children default to min-width:auto, which lets them push the track
     wider than the viewport. This is what forces the horizontal scroll. */
  .header-inner > * { min-width: 0 !important; }
  .header-inner .nav { min-width: 0; }
  .header-inner .search-box {
    min-width: 0 !important;
    max-width: min(40vw, 130px) !important;
    width: auto !important;
    flex: 0 1 auto;
  }
  .header-inner .search-input {
    min-width: 0 !important;
    max-width: 100% !important;
  }
  .search-input {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0;
  }
  .article, .hero { padding-left: 0.75rem; padding-right: 0.75rem; }

  /* Math wider than the screen scrolls inside its own container. */
  .equation, mjx-container, .math-block {
    display: block;
    max-width: 100% !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch;
  }
  /* MathJax wraps typeset math in an inner mjx-math that must be allowed to
     be wider than the screen; the SCROLLING happens on mjx-container. */
  mjx-container { min-width: 0 !important; }
  mjx-container > mjx-math { display: inline-block; min-width: max-content; }
  .equation { font-size: 0.9rem; }
}

/* ============================================================
   ADDITIONS — inline SVG diagram utilities + live-API widgets
   Appended only. No existing selector above is renamed, removed
   or restructured, so the 9 original pages render exactly as
   before.
   ============================================================ */

/* Components that toggle visibility in JS must always win. */
[hidden] { display: none !important; }

/* ---------- Diagrams: responsive hand-authored inline SVG ---------
   Rule of use:  <div class="figure center">
                   <div class="diagram-scroll">
                     <svg class="svg-diagram" viewBox="...">...</svg>
                   </div>
                   <div class="caption">...</div>
                 </div>
   width:100% + height:auto keeps the aspect ratio; the min-width on
   .diagram-scroll > svg means a wide diagram shrinks to its floor and
   then scrolls inside its own box instead of pushing the page sideways. */

.svg-diagram {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 auto;
  color: var(--diagram-ink);
}
.diagram-scroll {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}
.diagram-scroll > .svg-diagram { min-width: 470px; }

/* Strokes and fills, mapped onto the existing diagram tokens. */
.svg-diagram .ln        { fill: none; stroke: var(--diagram-line); stroke-width: 1.5; stroke-linecap: round; }
.svg-diagram .ln-soft   { fill: none; stroke: var(--diagram-line); stroke-width: 1; opacity: 0.5; }
.svg-diagram .ln-acc    { fill: none; stroke: var(--diagram-accent); stroke-width: 2; stroke-linecap: round; }
.svg-diagram .ln-red    { fill: none; stroke: var(--diagram-red); stroke-width: 2; stroke-linecap: round; }
.svg-diagram .ln-blue   { fill: none; stroke: var(--diagram-blue); stroke-width: 2; stroke-linecap: round; }
.svg-diagram .ln-thick  { fill: none; stroke: var(--diagram-ink); stroke-width: 2.4; stroke-linecap: round; }
.svg-diagram .dash      { stroke-dasharray: 5 4; }
.svg-diagram .dash-fine { stroke-dasharray: 2 4; opacity: 0.6; }
.svg-diagram .dot       { fill: var(--diagram-accent); }
.svg-diagram .dot-red   { fill: var(--diagram-red); }
.svg-diagram .fill-acc  { fill: var(--diagram-accent); }
.svg-diagram .fill-ink  { fill: var(--diagram-ink); }
.svg-diagram .fill-dim  { fill: var(--diagram-line); }
.svg-diagram .wash      { fill: var(--accent-wash); stroke: var(--border); }
.svg-diagram .wash-2    { fill: var(--diagram-panel); stroke: var(--diagram-line); }
.svg-diagram .box       { fill: none; stroke: var(--border-bright); }

/* Labels: .figure svg text already inherits the mono stack. */
.svg-diagram text { font-size: 12px; fill: var(--diagram-ink); }
.svg-diagram .t-xs  { font-size: 9px; }
.svg-diagram .t-sm  { font-size: 10px; }
.svg-diagram .t-md  { font-size: 13px; }
.svg-diagram .t-lg  { font-size: 16px; }
.svg-diagram .t-dim { fill: var(--diagram-line); }
.svg-diagram .t-acc { fill: var(--diagram-accent); }
.svg-diagram .t-red { fill: var(--diagram-red); }
.svg-diagram .t-bold{ font-weight: 700; }
.svg-diagram .t-mid { text-anchor: middle; }
.svg-diagram .t-end { text-anchor: end; }

/* ---------- Live API widgets (js/live-data.js) --------------------- */

.live-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  border-bottom: 1px dashed var(--border);
  padding-bottom: 0.4rem;
  margin-bottom: 0.85rem;
}
.live-head h3 { margin: 0; }
.live-badge {
  font-size: 0.62rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 0.1rem 0.4rem;
  white-space: nowrap;
}
.live-status {
  font-size: 0.76rem;
  letter-spacing: 0.06em;
  color: var(--accent-2);
  background: var(--bg-recess);
  border: var(--line);
  border-left: 3px solid var(--accent-2);
  padding: 0.5rem 0.7rem;
  margin: 0 0 0.85rem;
}
.live-status.is-error {
  color: var(--c-note);
  border-left-color: var(--c-note);
}
.live-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--accent);
  margin: 0.4rem 0 0.35rem;
}
.live-body { font-size: 0.86rem; line-height: 1.7; color: var(--text); }
.live-body:empty, .live-title:empty { display: none; }
.live-meta { font-size: 0.72rem; letter-spacing: 0.06em; color: var(--text-dim); margin: 0.5rem 0 0; }
.live-meta a { color: var(--accent); border-bottom: 1px solid var(--accent); }
.apod-media {
  display: block;
  width: 100%;
  height: auto;
  max-height: 420px;
  object-fit: contain;
  border: var(--line);
  background: var(--bg-recess);
  margin: 0 auto;
}
.live-list { list-style: none; padding-left: 0; margin: 0; }
.live-list > li {
  padding: 0.5rem 0 0.5rem 1.15rem;
  border-bottom: var(--line);
  margin: 0;
}
.live-list > li:last-child { border-bottom: none; }
.live-list .qmag {
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.04em;
}
.live-list .qplace { color: var(--text); }
.live-list .qtime { display: block; font-size: 0.7rem; color: var(--text-dim); }
.live-list a { color: var(--accent); }
.live-list a:hover { color: var(--accent-2); }

/* ISS readout rows: label / value on a 2-column grid. */
.live-row {
  display: grid;
  grid-template-columns: 5.5rem minmax(0, 1fr);
  gap: 0.2rem 0.6rem;
  font-size: 0.8rem;
  margin: 0.2rem 0;
}
.live-row dt { color: var(--accent-2); letter-spacing: 0.1em; }
.live-row dd { margin: 0; color: var(--text); }

@media (max-width: 400px) {
  .diagram-scroll > .svg-diagram { min-width: 390px; }
  .live-head h3 { font-size: 0.92rem; }
  .live-row { grid-template-columns: 4.2rem minmax(0, 1fr); font-size: 0.72rem; }
  .apod-media { max-height: 240px; }
}

/* ---------- Inline SVG diagrams ------------------------------------- */
/* Diagrams are hand-authored SVG using currentColor, so they inherit the
   theme automatically and need no image assets. Wide diagrams scroll inside
   their own container rather than forcing the page sideways. */

.diagram-scroll {
  margin: 1.6rem 0;
  border: 1px solid var(--border, rgba(255,179,0,0.28));
  border-radius: 6px;
  padding: 1rem 0.6rem;
  background: var(--surface-2, rgba(255,255,255,0.03));
  color: var(--accent, #ffb300);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.diagram-scroll > .svg-diagram {
  display: block;
  width: 100%;
  height: auto;
  min-width: 460px;   /* below this the labels become illegible; scroll instead */
}

.diagram-scroll > .svg-diagram.svg-penrose {
  min-width: 540px;
  max-width: 720px;
  margin: 0 auto;
}

.diagram-scroll .caption {
  margin: 0.9rem 0.6rem 0.2rem;
  color: var(--text, inherit);
}

/* Narrow phones: keep the diagram readable, let it scroll in place. */
@media (max-width: 400px) {
  .diagram-scroll { padding: 0.8rem 0.4rem; }
  .diagram-scroll > .svg-diagram { min-width: 420px; }
}

/* ---------- Accessibility ----------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .fade-in {
    opacity: 1;
    transform: none;
    transition: none;
  }
  .hero .eyebrow::after,
  .topic-card .read::after { animation: none; }
  body::after { background: none; }
}