/* The Atlas of Emergence — house style.
   One design system for every entry. Dark "observatory" aesthetic:
   ink-black ground, warm paper text, a single living accent. */

:root {
  --bg:        #0a0c10;
  --bg-soft:   #11151c;
  --panel:     #151a23;
  --panel-2:   #1b212c;
  --line:      #283142;
  --ink:       #e7e2d6;   /* warm paper */
  --ink-soft:  #a7a294;
  --ink-faint: #6c6a60;
  --accent:    #7fd1c1;   /* phosphor teal */
  --accent-2:  #e0a35e;   /* amber */
  --accent-3:  #c98bd0;   /* orchid */
  --danger:    #e0675e;
  --maxw: 760px;
  --radius: 10px;
  --mono: "SFMono-Regular", "JetBrains Mono", "Consolas", ui-monospace, monospace;
  --serif: "Iowan Old Style", "Palatino Linotype", "Georgia", serif;
  --sans: "Inter", -apple-system, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 50% -10%, #121826 0%, transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; border-bottom: 1px solid transparent; }
a:hover { border-bottom-color: var(--accent); }

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 22px; }

/* ---- Masthead ---- */
.masthead { padding: 56px 0 22px; text-align: center; }
.masthead .kicker {
  font-family: var(--mono); font-size: 12px; letter-spacing: 0.28em;
  text-transform: uppercase; color: var(--ink-faint);
}
.masthead h1 {
  font-size: clamp(34px, 6vw, 56px); margin: 10px 0 6px; font-weight: 600;
  letter-spacing: -0.01em; line-height: 1.05;
}
.masthead .tagline { color: var(--ink-soft); font-style: italic; margin: 0; }

/* ---- Breadcrumb / entry header ---- */
.crumb { font-family: var(--mono); font-size: 12.5px; color: var(--ink-faint);
  letter-spacing: 0.04em; padding-top: 26px; }
.crumb a { color: var(--ink-soft); border: 0; }
.crumb a:hover { color: var(--accent); }

.entry-head { padding: 6px 0 8px; }
.entry-head .cat {
  font-family: var(--mono); font-size: 12px; letter-spacing: 0.2em;
  text-transform: uppercase; color: var(--accent); }
.entry-head h1 { font-size: clamp(28px, 5vw, 44px); margin: 8px 0 4px; font-weight: 600; }
.entry-head .blurb { color: var(--ink-soft); margin: 0; font-style: italic; }

/* ---- The stage: a simulation and its controls ---- */
.stage {
  margin: 26px 0 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.stage canvas {
  display: block; width: 100%; height: auto;
  background: #06070a; cursor: crosshair; touch-action: none;
}
.stage .controls {
  display: flex; flex-wrap: wrap; gap: 14px 18px; align-items: center;
  padding: 12px 14px; border-top: 1px solid var(--line);
  background: var(--panel-2); font-family: var(--sans); font-size: 13px;
}
.controls button {
  font-family: var(--mono); font-size: 12.5px; color: var(--ink);
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 12px; cursor: pointer; letter-spacing: 0.03em;
  transition: border-color .15s, color .15s, background .15s;
}
.controls button:hover { border-color: var(--accent); color: var(--accent); }
.controls button.primary { border-color: var(--accent); color: var(--accent); }
.controls button.primary[data-on="true"] { background: var(--accent); color: #06120f; }
.controls .ctl { display: flex; flex-direction: column; gap: 3px; min-width: 120px; }
.controls .ctl label {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--ink-faint); display: flex;
  justify-content: space-between; gap: 8px; }
.controls .ctl label .val { color: var(--ink-soft); }
.controls input[type=range] { -webkit-appearance: none; appearance: none;
  height: 4px; border-radius: 3px; background: var(--line); outline: none; }
.controls input[type=range]::-webkit-slider-thumb { -webkit-appearance: none;
  width: 14px; height: 14px; border-radius: 50%; background: var(--accent);
  cursor: pointer; border: 0; }
.controls input[type=range]::-moz-range-thumb { width: 14px; height: 14px;
  border-radius: 50%; background: var(--accent); cursor: pointer; border: 0; }
.controls select { font-family: var(--mono); font-size: 12.5px; color: var(--ink);
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 8px; }
.stage .readout { font-family: var(--mono); font-size: 11.5px; color: var(--ink-faint);
  padding: 0 14px 11px; background: var(--panel-2); margin-top: -1px; }
.caption { font-family: var(--sans); font-size: 13.5px; color: var(--ink-faint);
  margin: 8px 2px 0; }

/* ---- Prose ---- */
.prose { padding: 8px 0 60px; }
.prose h2 {
  font-family: var(--sans); font-weight: 600; font-size: 14px;
  letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent);
  margin: 40px 0 6px; }
.prose h3 { font-size: 21px; margin: 28px 0 4px; font-weight: 600; }
.prose p { margin: 12px 0; }
.prose ul, .prose ol { padding-left: 22px; }
.prose li { margin: 6px 0; }
.prose blockquote {
  margin: 18px 0; padding: 4px 18px; border-left: 2px solid var(--accent);
  color: var(--ink-soft); font-style: italic; }
.prose code { font-family: var(--mono); font-size: 0.86em; background: var(--panel);
  border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; }
.prose .refs { font-family: var(--sans); font-size: 14px; color: var(--ink-soft); }
.prose .refs li { margin: 9px 0; }
/* Glossary-term links: defined-term style (dotted underline), distinct from nav links. */
.prose a.g-term { color: inherit; border-bottom: 1px dotted var(--ink-faint); }
.prose a.g-term:hover { color: var(--accent); border-bottom-color: var(--accent); }

/* Glossary */
.glossary { margin: 8px 0 0; }
.glossary dt { font-size: 19px; font-weight: 600; color: var(--ink); margin: 28px 0 4px;
  scroll-margin-top: 16px; }
.glossary dt:first-of-type { margin-top: 8px; }
.glossary dd { margin: 0; color: var(--ink-soft); }
.glossary dd .see { display: block; margin-top: 6px; font-family: var(--sans);
  font-size: 13px; color: var(--ink-faint); }
.glossary dd .see a { font-size: 13px; }

/* ---- Home: the map of phenomena ---- */
.wrap.wide { max-width: 1000px; }
.legend { display: flex; flex-wrap: wrap; gap: 7px 16px; justify-content: center;
  font-family: var(--mono); font-size: 11.5px; color: var(--ink-soft); margin: 16px 0 0; }
.legend .leg { display: inline-flex; align-items: center; gap: 6px; }
.legend .leg i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
#info { font-family: var(--sans); font-size: 13.5px; color: var(--ink-soft);
  text-align: center; max-width: 580px; margin: 12px auto 0; min-height: 36px;
  opacity: 0; transition: opacity .15s; }
#info strong { color: var(--ink); }
#mapstage canvas { cursor: default; }
.maplink { text-align: center; font-family: var(--mono); font-size: 13px; margin: 0 auto 6px; }

.intro { color: var(--ink-soft); text-align: center; max-width: 600px;
  margin: 8px auto 22px; }
.search { max-width: 460px; margin: 0 auto; }
.search input { width: 100%; font-family: var(--mono); font-size: 13px;
  color: var(--ink); background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 14px; outline: none; transition: border-color .15s; }
.search input:focus { border-color: var(--accent); }
.search input::placeholder { color: var(--ink-faint); }
.no-results { text-align: center; color: var(--ink-soft); font-family: var(--sans);
  font-size: 14px; margin: 30px 0; }
.family, .essays { margin: 40px 0 0; }
.essays { margin-top: 52px; }
.family h2, .essays h2 {
  font-family: var(--sans); font-size: 13px; letter-spacing: 0.2em;
  text-transform: uppercase; color: var(--accent); border-bottom: 1px solid var(--line);
  padding-bottom: 8px; margin-bottom: 16px; font-weight: 600; }
.essays h2 { color: var(--accent-2); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px; }
.card { display: block; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 16px 18px; overflow: hidden;
  transition: border-color .15s, transform .15s; }
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card-thumb { display: block; width: calc(100% + 32px); margin: -16px -16px 14px;
  aspect-ratio: 16 / 9; object-fit: cover; object-position: center;
  background: var(--bg); border-bottom: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0; transition: filter .15s; }
.card-thumb[src=""], .card-thumb:not([src]) { display: none; }
.card:hover .card-thumb { filter: brightness(1.07) saturate(1.04); }
.card h3 { font-size: 19px; margin: 0 0 6px; font-weight: 600; color: var(--ink); }
.card p { font-family: var(--sans); font-size: 13.5px; color: var(--ink-soft);
  margin: 0; line-height: 1.5; }
.card .tags { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.card .tag { font-family: var(--mono); font-size: 10px; letter-spacing: 0.05em;
  color: var(--ink-faint); border: 1px solid var(--line); border-radius: 20px;
  padding: 2px 8px; }
.placeholder { opacity: 0.5; pointer-events: none; }
.placeholder .card-soon { font-family: var(--mono); font-size: 10px;
  color: var(--accent-2); letter-spacing: 0.1em; }

/* ---- Footer ---- */
footer { border-top: 1px solid var(--line); margin-top: 40px; padding: 22px 0 60px;
  font-family: var(--mono); font-size: 12px; color: var(--ink-faint); text-align: center; }
footer a { color: var(--ink-soft); border: 0; }

/* ---- Related strip ---- */
.related { margin: 30px 0 0; padding-top: 18px; border-top: 1px solid var(--line); }
.related h2 { font-family: var(--sans); font-size: 12px; letter-spacing: 0.2em;
  text-transform: uppercase; color: var(--ink-faint); margin: 0 0 10px; }
.related a { font-family: var(--mono); font-size: 13px; }
.related .rel-links { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.related .prevnext { display: flex; align-items: baseline; gap: 14px;
  margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--line); }
.related .prevnext .home { color: var(--ink-faint); letter-spacing: 0.12em;
  text-transform: uppercase; font-size: 11px; margin: 0 auto; }
.related .prevnext .prev { margin-right: auto; }
.related .prevnext .next { margin-left: auto; text-align: right; }
.related .prevnext span { color: var(--ink-soft); }
.related .navhint { font-family: var(--mono); font-size: 11px; color: var(--ink-faint);
  text-align: center; margin: 12px 0 0; letter-spacing: 0.03em; }
kbd { font-family: var(--mono); font-size: 0.88em; background: var(--panel);
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px;
  padding: 0 5px; color: var(--ink-soft); }

@media (max-width: 600px) {
  body { font-size: 17px; }
  .controls .ctl { min-width: 100px; }
}

/* ---- Accessibility ---- */
/* Visible keyboard focus for every interactive element (mouse focus stays clean). */
a:focus-visible, button:focus-visible, select:focus-visible,
input:focus-visible, .card:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px;
}
.controls input[type=range]:focus-visible { outline-offset: 4px; }

/* Respect users who prefer reduced motion: kill UI transitions/animations.
   (Simulations themselves start paused under this preference — see atlas.js —
   so nothing moves until the reader presses play.) */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
  }
}
