/* ============================================================
   site.css — design system for the 24 lesson pages.
   Carries the homepage's starfield / Orbitron look across the
   whole site. Dark by default; html.light opts into light mode.
   Pairs with nav.css (injected by nav.js).
   ============================================================ */

/* ---------- tokens ---------- */
:root {
  --bg:          #020810;
  --panel:       rgba(15, 23, 42, 0.66);
  --panel-solid: #0f172a;
  --border:      rgba(96, 165, 250, 0.14);
  --border-warm: rgba(251, 191, 36, 0.35);

  --text:        #c8d6e5;
  --text-strong: #e2e8f0;
  --muted:       #94a3b8;
  /* #64748b measured 4.22:1 on the page background -- just under AA */
  --dim:         #8b9ab0;

  --accent:      #fbbf24;
  --accent-2:    #60a5fa;
  /* headings sit on top of legacy mid-dark panels (#2c3e50 etc), so they need
     more headroom than link blue to clear WCAG AA there */
  --heading:     #93c5fd;
  --code:        #4ade80;

  --font-display: 'Orbitron', "Trebuchet MS", Arial, sans-serif;
  --font-body:    'Exo 2', "Trebuchet MS", "Lucida Grande", Arial, sans-serif;

  --measure: 1100px;
  --radius: 12px;
}

html.light {
  --bg:          #f8fafc;
  --panel:       #ffffff;
  --panel-solid: #ffffff;
  --border:      #e2e8f0;
  --border-warm: #f59e0b;

  --text:        #334155;
  --text-strong: #0f172a;
  --muted:       #475569;
  --dim:         #64748b;

  /* deep enough to clear AA on the legacy pastel panels (#e8f5e8, #f8d7da…) */
  --accent:      #92400e;
  --accent-2:    #1d4ed8;
  --heading:     #1d4ed8;
  --code:        #15803d;
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1.02rem;
  line-height: 1.65;
  overflow-x: hidden;
  position: relative;
}

/* ---------- starfield (pseudo-elements: no markup needed) ---------- */
body::before, body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
}
body::before {
  background-image:
    radial-gradient(1px 1px at 10% 20%, rgba(255,255,255,.7), transparent),
    radial-gradient(1px 1px at 40% 60%, rgba(255,255,255,.5), transparent),
    radial-gradient(1.5px 1.5px at 70% 10%, rgba(255,255,255,.8), transparent),
    radial-gradient(1px 1px at 85% 45%, rgba(255,255,255,.4), transparent),
    radial-gradient(1px 1px at 25% 80%, rgba(255,255,255,.6), transparent),
    radial-gradient(1.2px 1.2px at 55% 35%, rgba(255,255,255,.5), transparent),
    radial-gradient(1px 1px at 92% 75%, rgba(255,255,255,.3), transparent);
  background-size: 250px 250px;
  animation: sw-drift 90s linear infinite;
}
body::after {
  background-image:
    radial-gradient(1px 1px at 15% 55%, rgba(180,210,255,.5), transparent),
    radial-gradient(1.5px 1.5px at 60% 25%, rgba(255,220,150,.6), transparent),
    radial-gradient(1px 1px at 80% 85%, rgba(200,200,255,.4), transparent);
  background-size: 350px 350px;
  animation: sw-drift 140s linear infinite reverse;
}
@keyframes sw-drift { to { background-position: 1000px 500px; } }
html.light body::before, html.light body::after { display: none; }

@media (prefers-reduced-motion: reduce) {
  body::before, body::after { animation: none; }
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- layout ---------- */
header, main, footer, .page-wrap {
  max-width: var(--measure);
  margin-left: auto;
  margin-right: auto;
  padding-left: 1.25rem;
  padding-right: 1.25rem;
}
header { padding-top: 3rem; padding-bottom: 1rem; text-align: center; }
main   { padding-bottom: 3rem; }
section { margin: 2.5rem 0; }

/* ---------- typography ---------- */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  color: var(--text-strong);
  line-height: 1.25;
  margin: 0 0 0.75rem;
  background: none;
  padding: 0;
}
h1 {
  font-weight: 900;
  font-size: clamp(1.7rem, 4.5vw, 2.9rem);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 40%, #fcd34d 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 0.6rem;
}
html.light h1 {
  background: linear-gradient(135deg, #b45309 0%, #d97706 60%, #92400e 100%);
  -webkit-background-clip: text; background-clip: text;
}
h2 {
  font-weight: 700;
  font-size: clamp(1.15rem, 2.6vw, 1.55rem);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--heading);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
  margin-top: 2.5rem;
}
h3 {
  font-weight: 700;
  font-size: clamp(1rem, 2.1vw, 1.2rem);
  color: var(--accent);
  letter-spacing: 0.04em;
  margin-top: 1.75rem;
}
h4, h5, h6 {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-strong);
  letter-spacing: 0.03em;
  margin-top: 1.25rem;
}
.subtitle {
  font-family: var(--font-body);
  font-weight: 300;
  font-size: clamp(0.95rem, 2.2vw, 1.2rem);
  color: var(--muted);
  max-width: 680px;
  margin: 0 auto;
}

p { margin: 0 0 1rem; }
strong { color: var(--text-strong); font-weight: 700; }
em { color: var(--text-strong); }
a { color: var(--accent-2); text-decoration: none; }
a:hover, a:focus-visible { color: var(--accent); text-decoration: underline; }
h3 a { color: var(--accent); }

/* ---------- lists ---------- */
ul, ol { margin: 0 0 1rem; padding-left: 1.5rem; }
li { margin-bottom: 0.5rem; }
ul li { list-style: disc; }
ol li { list-style: decimal; }
li::marker { color: var(--accent-2); }
dl { margin: 0 0 1rem; }
dt { font-weight: 700; color: var(--text-strong); margin-top: 0.75rem; }
dd { margin: 0 0 0.5rem 1.25rem; }

/* ---------- code ---------- */
code, pre {
  font-family: "JetBrains Mono", "Fira Code", "Courier New", monospace;
  color: var(--code);
  background: rgba(2, 8, 16, 0.7);
  border-radius: 6px;
}
html.light code, html.light pre { background: #f1f5f9; }
code { padding: 0.12em 0.4em; font-size: 0.9em; }
pre {
  padding: 1rem 1.15rem;
  overflow-x: auto;
  border: 1px solid var(--border);
  margin: 0 0 1.25rem;
  line-height: 1.55;
}
pre code { padding: 0; background: none; }

/* ---------- blockquote ---------- */
blockquote {
  margin: 1.5rem 0;
  padding: 1rem 1.25rem;
  background: var(--panel);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text);
  font-style: italic;
}

/* ---------- tables ---------- */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  background: var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 0.94rem;
}
th, td {
  border: 1px solid var(--border);
  padding: 0.6rem 0.75rem;
  text-align: left;
  color: var(--text);
}
th {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-2);
  background: rgba(2, 8, 16, 0.5);
}
html.light th { background: #f1f5f9; }
tbody tr:hover td { background: rgba(96, 165, 250, 0.05); }
.table-container { width: 100%; overflow-x: auto; }

/* ---------- media ---------- */
img { max-width: 100%; height: auto; border-radius: 8px; }

/* Canvas diagrams across this site were authored for a light page and draw
   their labels in dark ink straight onto the bitmap. Rather than re-theme
   ~14 pages of drawing code, give every canvas its own light surface so the
   artwork renders as designed in both themes. */
main canvas, .page-wrap canvas, #main canvas {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 1.5rem auto;
  background: #f5f7fa;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
}
svg { display: block; margin: 0 auto; max-width: 100%; }
.svg-container { display: flex; justify-content: center; align-items: center; }

/* ---------- footer ---------- */
footer {
  border-top: 1px solid var(--border);
  padding-top: 1.5rem;
  padding-bottom: 2.5rem;
  color: var(--dim);
  font-size: 0.88rem;
  text-align: center;
}

/* ---------- mermaid ----------
   These diagrams were authored for a light page: 21 of them carry hardcoded
   light `style X fill:#...` directives that cannot follow a theme. So they get
   their own light surface and render in mermaid's light theme in BOTH modes —
   same treatment as the canvases above. Dark ink is therefore always correct. */
.mermaid, .mermaid_container, .mermaid-diagram {
  margin: 1.75rem auto;
  padding: 1.25rem;
  background: #f5f7fa;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 100%;
  overflow-x: auto;
  text-align: center;
}
.mermaid svg { margin: 0 auto; display: block; height: auto; }

/* Mermaid renders labels as HTML in a foreignObject, which INHERITS the page
   text colour unless something sets it — light-on-light once the page went dark.
   So supply a dark default, but deliberately WITHOUT !important: nodes carrying
   a custom `style X fill:...,color:...` must be able to override it (light ink
   on dark fills). Specificity here is low on purpose. */
.mermaid .nodeLabel, .mermaid .nodeLabel p,
.mermaid .edgeLabel, .mermaid .edgeLabel p,
.mermaid .cluster-label, .mermaid .cluster-label p,
.mermaid .label, .mermaid .titleText, .mermaid .pieTitleText {
  color: #1f2937;
}
.mermaid .edgeLabel > * { background: transparent !important; }

/* Mindmaps are the exception: mermaid paints its own section palette and puts
   WHITE labels on it, which fails against every branch colour (measured 1.06 -
   2.57:1). Numbered sections are light, so they take dark ink; only the root
   node is dark and keeps white. */
.mermaid .mindmap-node .nodeLabel,
.mermaid .mindmap-node .nodeLabel p,
.mermaid .mindmap-node text {
  color: #1f2937 !important;
  fill: #1f2937 !important;
}
.mermaid .mindmap-node.section-root .nodeLabel,
.mermaid .mindmap-node.section-root .nodeLabel p,
.mermaid .mindmap-node.section-root text {
  color: #ffffff !important;
  fill: #ffffff !important;
}

/* ---------- generic panel helper (used by the darkened inline styles) ---------- */
.sw-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin: 1.5rem 0;
  color: var(--text);
}

/* ---------- callout ---------- */
.callout {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
}
.callout > :last-child { margin-bottom: 0; }
.callout h3, .callout h4 { margin-top: 0; }

/* ---------- three pillars (replaces a <canvas> that was
     invisible on dark and unreadable to screen readers) ---------- */
.pillars {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}
.pillar {
  background: var(--panel);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent-2);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
}
.pillar h4 { margin-top: 0; color: var(--accent); }
.pillar .pillar-line {
  display: block;
  font-family: var(--font-display);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.35rem;
}
.pillar p:last-child { margin-bottom: 0; }

/* ---------- die colour chip (inline background set per die) ---------- */
.die-chip {
  display: inline-block;
  width: 0.95em; height: 0.95em;
  border-radius: 3px;
  border: 1px solid rgba(148, 163, 184, 0.6);
  vertical-align: -0.1em;
  margin-right: 0.45em;
}

/* ---------- answer key ---------- */
details.answer {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin: 0.75rem 0 1.25rem;
}
details.answer > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent-2);
  font-family: var(--font-display);
  font-size: 0.85rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
details.answer[open] > summary { margin-bottom: 0.75rem; }
details.answer > :last-child { margin-bottom: 0; }

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

/* ---------- skip link ---------- */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: #020810;
  padding: 0.6rem 1rem;
  font-weight: 700;
  z-index: 2000;
  border-radius: 0 0 8px 0;
}
.skip-link:focus {
  left: 0;
  text-decoration: none;
}

@media (max-width: 600px) {
  body { font-size: 0.98rem; }
  header { padding-top: 2rem; }
  section { margin: 1.75rem 0; }
}
