/* ==========================================================================
   UN GDP Games — shared styles
   Dark navy "atlas of nations", role-coded causal / spurious / incidental.
   ========================================================================== */

:root {
  --bg:           #0a1830;
  --bg-card:      #11213f;
  --bg-elevated:  #162849;
  --border:       #233966;
  --text:         #e6eaf2;
  --text-muted:   #94a3b8;
  --text-dim:     #6b7b97;

  --role-causal:     #22c55e;
  --role-spurious:   #ef4444;
  --role-incidental: #94a3b8;
  --accent-gold:     #f59e0b;

  --font-serif: 'DM Serif Display', Georgia, serif;
  --font-sans:  'Inter', system-ui, -apple-system, sans-serif;
  --font-mono:  'JetBrains Mono', ui-monospace, Menlo, monospace;

  --page-max: 1200px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.page-wrapper {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 3rem 1.5rem 6rem;
}

a { color: var(--accent-gold); text-decoration: none; transition: color .15s; }
a:hover { color: #fcd34d; }

h1, h2, h3 { font-weight: 400; line-height: 1.15; font-family: var(--font-serif); }
h1 { font-size: clamp(2.5rem, 5vw, 4.2rem); margin-bottom: 1rem; letter-spacing: -0.01em; }
h2 { font-size: clamp(1.6rem, 2.4vw, 2.1rem); margin-bottom: 1rem; margin-top: 3rem; }
h3 { font-size: 1.2rem; font-family: var(--font-sans); font-weight: 600; margin-bottom: .5rem; }

p { margin-bottom: 1rem; color: var(--text); }
.muted { color: var(--text-muted); }

code, .mono { font-family: var(--font-mono); font-size: .92em; }

/* --- Hero --- */
.hero {
  padding: 3rem 0 4rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 3rem;
}
.hero .eyebrow {
  font-family: var(--font-mono);
  font-size: .78rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 1.5rem;
}
.hero h1 .accent { color: var(--accent-gold); font-style: italic; }
.hero .hook {
  font-size: 1.15rem;
  max-width: 60ch;
  color: var(--text-muted);
  line-height: 1.55;
}

/* --- Role legend (compact) --- */
.role-legend {
  display: flex;
  gap: 1.75rem;
  flex-wrap: wrap;
  font-family: var(--font-mono);
  font-size: .82rem;
  color: var(--text-muted);
  margin-top: 1.5rem;
}
.role-legend .chip {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
}
.role-legend .chip::before {
  content: "";
  width: 11px;
  height: 11px;
  border-radius: 2px;
  display: inline-block;
}
.role-legend .chip.causal::before     { background: var(--role-causal); }
.role-legend .chip.spurious::before   { background: var(--role-spurious); }
.role-legend .chip.incidental::before { background: var(--role-incidental); }

/* --- Module card grid --- */
.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}
.module-card {
  display: block;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.75rem 1.5rem;
  color: var(--text);
  transition: border-color .15s, transform .15s, background .15s;
  min-height: 210px;
  position: relative;
}
.module-card.ready:hover {
  border-color: var(--accent-gold);
  transform: translateY(-2px);
  background: var(--bg-elevated);
}
.module-card .num {
  font-family: var(--font-mono);
  font-size: .78rem;
  letter-spacing: .14em;
  color: var(--text-dim);
  margin-bottom: .75rem;
}
.module-card .title {
  font-family: var(--font-serif);
  font-size: 1.35rem;
  line-height: 1.2;
  margin-bottom: .75rem;
  color: var(--text);
}
.module-card .desc {
  font-size: .95rem;
  color: var(--text-muted);
  line-height: 1.5;
}
.module-card.stub .title { color: var(--text-muted); }
.module-card.stub::after {
  content: "coming soon";
  position: absolute;
  top: 1rem;
  right: 1rem;
  font-family: var(--font-mono);
  font-size: .7rem;
  letter-spacing: .14em;
  color: var(--text-dim);
  text-transform: uppercase;
}

/* --- Back nav on module pages --- */
.module-nav {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: var(--font-mono);
  font-size: .85rem;
  margin-bottom: 2rem;
  color: var(--text-dim);
}
.module-nav a { color: var(--text-muted); }
.module-nav a:hover { color: var(--accent-gold); }

/* --- Widget container (module-level) --- */
.widget {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 2.5rem;
}
.widget h2 { margin-top: 0; }
.widget .help {
  font-size: .9rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

.controls {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  font-family: var(--font-mono);
  font-size: .88rem;
  color: var(--text-muted);
}
.controls label { display: flex; align-items: center; gap: .5rem; }
.controls select, .controls input[type="text"] {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: .45rem .6rem;
  font-family: var(--font-mono);
  font-size: .88rem;
  min-width: 240px;
}
.controls select:focus, .controls input:focus { outline: 2px solid var(--accent-gold); outline-offset: 1px; }
.controls button {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: .45rem 1rem;
  font-family: var(--font-mono);
  font-size: .85rem;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.controls button:hover { border-color: var(--accent-gold); color: var(--accent-gold); }

/* --- Plot host --- */
.plot { min-height: 420px; }
.plot-tall { min-height: 640px; }

/* --- Takeaway card --- */
.takeaway {
  background: linear-gradient(180deg, #1a2b50 0%, #132241 100%);
  border-left: 3px solid var(--accent-gold);
  border-radius: 4px;
  padding: 1.25rem 1.5rem;
  margin: 2rem 0;
}
.takeaway .label {
  font-family: var(--font-mono);
  font-size: .72rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--accent-gold);
  margin-bottom: .4rem;
}
.takeaway p { font-size: 1.05rem; line-height: 1.55; margin: 0; }
.takeaway p em { color: var(--accent-gold); font-style: italic; }

/* --- Quiz --- */
.quiz-card {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.quiz-question .feature-name {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  color: var(--accent-gold);
}
.quiz-question .feature-desc {
  font-size: .95rem;
  color: var(--text-muted);
  margin-top: .25rem;
}
.quiz-choices {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
}
.quiz-choices button {
  padding: .55rem 1.25rem;
  border-radius: 4px;
  cursor: pointer;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: .92rem;
  transition: border-color .15s, color .15s;
}
.quiz-choices button:hover { border-color: var(--accent-gold); }
.quiz-choices button.chosen-correct   { border-color: var(--role-causal);     color: var(--role-causal); }
.quiz-choices button.chosen-incorrect { border-color: var(--role-spurious);   color: var(--role-spurious); }
.quiz-choices button.is-answer        { border-color: var(--accent-gold); }
.quiz-choices button:disabled { cursor: default; }
.quiz-explain {
  min-height: 1.25rem;
  font-size: .92rem;
  color: var(--text-muted);
}
.quiz-progress {
  font-family: var(--font-mono);
  font-size: .8rem;
  color: var(--text-dim);
}

/* --- Load state --- */
.loading {
  padding: 2rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: .88rem;
}

footer {
  margin-top: 5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: .82rem;
  font-family: var(--font-mono);
}
footer a { color: var(--text-muted); }

/* ==========================================================================
   Preview banner (proposals-preview branch only)
   ========================================================================== */
.preview-banner {
  background: linear-gradient(90deg, #3a1e0a 0%, #4a2a12 100%);
  border-bottom: 1px solid #7a4d1c;
  color: #fbbf24;
  font-family: var(--font-mono);
  font-size: .82rem;
  padding: .55rem 1.5rem;
  text-align: center;
  letter-spacing: .04em;
}
.preview-banner strong { color: #fcd34d; }
.preview-banner a { color: #fde68a; text-decoration: underline; }
.preview-note {
  display: inline-block;
  margin-left: .5rem;
  font-family: var(--font-mono);
  font-size: .7rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  padding: .15rem .5rem;
  border: 1px solid var(--accent-gold);
  color: var(--accent-gold);
  border-radius: 3px;
  vertical-align: middle;
}

/* ==========================================================================
   Proposal 1: scroll-driven confidence-crash gradient on ch02.
   Two CSS variables (--crash-top, --crash-bottom) are set by the scroll
   listener with explicit rgb() strings. 0 = calm navy, 1 = alarm red + black.
   ========================================================================== */
body.crash-scroll {
  background:
    linear-gradient(
      180deg,
      var(--crash-top, #0a1830) 0%,
      var(--crash-bottom, #050810) 100%
    );
  transition: background 180ms linear;
  background-attachment: fixed;
}

/* ==========================================================================
   Proposal 6: depth toggle for math.
   A fixed three-state control (intuitive / technical / deep) drives body
   classes `.depth-intuitive | .depth-technical | .depth-deep`. Any
   <details data-depth="technical|deep"> only pops open at or above its depth.
   ========================================================================== */
#depth-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 200;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .35rem;
  display: flex;
  gap: .15rem;
  font-family: var(--font-mono);
  font-size: .75rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
#depth-toggle button {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: .3rem .65rem;
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: .75rem;
  letter-spacing: .04em;
  transition: color .15s, border-color .15s, background .15s;
}
#depth-toggle button:hover { color: var(--accent-gold); }
#depth-toggle button.active {
  background: var(--bg);
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}
#depth-toggle .depth-label {
  padding: .3rem .5rem;
  color: var(--text-dim);
  letter-spacing: .14em;
  text-transform: uppercase;
  font-size: .65rem;
  align-self: center;
}

/* Disclosure blocks: intuitive is always visible; technical shows at
   technical+; deep shows only at deep. */
details.depth-block {
  background: var(--bg-elevated);
  border-left: 3px solid var(--border);
  border-radius: 4px;
  padding: .75rem 1rem;
  margin: .75rem 0;
}
details.depth-block > summary {
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: .78rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-muted);
  list-style: none;
  outline: none;
}
details.depth-block > summary::-webkit-details-marker { display: none; }
details.depth-block > summary::before {
  content: "▸ ";
  display: inline-block;
  transition: transform .15s;
  color: var(--accent-gold);
}
details.depth-block[open] > summary::before { content: "▾ "; }
details.depth-block[data-depth="technical"] { border-left-color: #60a5fa; }
details.depth-block[data-depth="deep"]      { border-left-color: #a78bfa; }
details.depth-block > .depth-body { margin-top: .75rem; }

/* Hiding rules: in intuitive mode, hide technical + deep wrappers. In
   technical mode, hide deep wrappers. In deep mode, all visible. */
body.depth-intuitive details.depth-block[data-depth="technical"],
body.depth-intuitive details.depth-block[data-depth="deep"]      { display: none; }
body.depth-technical details.depth-block[data-depth="deep"]      { display: none; }

/* Auto-open everything in a deeper mode to remove ceremony. */
body.depth-deep details.depth-block,
body.depth-technical details.depth-block[data-depth="technical"] {
  /* keep details controllable by the user — don't force open */
}

/* ==========================================================================
   Proposal 8: journey souvenir card on ch05 outro.
   ========================================================================== */
.souvenir-card {
  background: linear-gradient(160deg, #1a2b50 0%, #0f1e3b 100%);
  border: 1px solid var(--accent-gold);
  border-radius: 8px;
  padding: 1.5rem;
  margin: 2rem 0;
  display: grid;
  grid-template-columns: 1fr minmax(260px, 380px);
  gap: 1.5rem;
  align-items: center;
}
.souvenir-card .souvenir-caption {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  line-height: 1.3;
  color: var(--text);
}
.souvenir-card .souvenir-caption .country {
  color: var(--accent-gold);
  font-style: italic;
}
.souvenir-card .souvenir-stats {
  font-family: var(--font-mono);
  font-size: .85rem;
  color: var(--text-muted);
  margin-top: .75rem;
  line-height: 1.7;
}
.souvenir-card .souvenir-stats .actual  { color: var(--role-causal); }
.souvenir-card .souvenir-stats .predicted { color: var(--role-spurious); }
.souvenir-card .souvenir-share {
  margin-top: 1rem;
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}
.souvenir-card .souvenir-share button {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: .4rem .85rem;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: .8rem;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.souvenir-card .souvenir-share button:hover { border-color: var(--accent-gold); color: var(--accent-gold); }
.souvenir-card .souvenir-plot { min-height: 260px; }
@media (max-width: 720px) {
  .souvenir-card { grid-template-columns: 1fr; }
}

/* ==========================================================================
   Proposal 5: resampling ribbon (replaces repeated-splits box).
   ========================================================================== */
.ribbon-controls {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: .75rem;
  font-family: var(--font-mono);
  font-size: .82rem;
  color: var(--text-muted);
}
.ribbon-controls input[type="range"] {
  accent-color: var(--accent-gold);
  width: 220px;
}
.ribbon-controls button {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: .35rem .85rem;
  font-family: var(--font-mono);
  font-size: .8rem;
  cursor: pointer;
}
.ribbon-controls button:hover { border-color: var(--accent-gold); color: var(--accent-gold); }

/* ==========================================================================
   Fixed UI toggles (theme, density). Top-left stack; depth-toggle is
   separately styled at top-right on ch03.
   ========================================================================== */
.ui-toggle {
  position: fixed;
  left: 1rem;
  z-index: 200;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .35rem;
  display: flex;
  gap: .15rem;
  font-family: var(--font-mono);
  font-size: .75rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  align-items: center;
}
#theme-toggle   { top: 1rem; }
#density-toggle { top: 3.25rem; }
.ui-toggle button {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: .3rem .65rem;
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: .75rem;
  letter-spacing: .04em;
  transition: color .15s, border-color .15s, background .15s;
}
.ui-toggle button:hover { color: var(--accent-gold); }
.ui-toggle button.active {
  background: var(--bg);
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}
.ui-toggle .ui-toggle-label {
  padding: .3rem .5rem;
  color: var(--text-dim);
  letter-spacing: .14em;
  text-transform: uppercase;
  font-size: .65rem;
  align-self: center;
}

/* ==========================================================================
   Light-theme palette overrides.
   Only the surface / text tokens change; role colours stay semantic.
   ========================================================================== */
body.theme-light {
  --bg:           #f8fafc;
  --bg-card:      #ffffff;
  --bg-elevated:  #f1f5f9;
  --border:       #cbd5e1;
  --text:         #0f172a;
  --text-muted:   #475569;
  --text-dim:     #64748b;
}
body.theme-light .takeaway {
  background: linear-gradient(180deg, #fef3c7 0%, #fde68a 100%);
}
body.theme-light .souvenir-card {
  background: linear-gradient(160deg, #fef3c7 0%, #fde68a 100%);
}
body.theme-light .module-card.ready:hover { background: #f1f5f9; }
body.theme-light .ui-toggle { box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08); }
/* Crash-scroll gradient is dark-theme flavour; disable in light mode so the
   page doesn't darken beneath the light surface tokens. */
body.theme-light.crash-scroll { background: var(--bg); }

/* ==========================================================================
   Density toggle (overview): hide descriptive prose, keep structural /
   semantic content (titles, widgets, controls, plots, featured examples,
   role legend, nav). Use !important so this wins over inline styles.
   ========================================================================== */
body.density-overview .hero .hook,
body.density-overview .widget .help,
body.density-overview .takeaway,
body.density-overview .module-card .desc,
body.density-overview footer,
body.density-overview .muted {
  display: none !important;
}
/* Keep widget controls + featured examples + plots visible. Featured example
   tiles carry the feature names and short inline labels, which the user
   specifically asked to keep — they're the visual, not prose decoration. */

