:root {
  color-scheme: dark;
  --night: #0a0b10;
  --basalt: #11131b;
  --basalt-2: #171a24;
  --papyrus: #e6dcc4;
  --papyrus-dim: #a89f88;
  --papyrus-faint: #6f6a5c;
  --gold: #d9a441;
  --gold-hot: #f2c860;
  --copper: #b4562a;
  --lapis: #3f8fae;
  --lapis-hot: #63c8bd;
  --red: #d8503b;
  --line: #262a38;
  --line-hot: #3c4256;
  --stage: #07080d;
  --display: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
  --serif: Georgia, "Times New Roman", serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --page: min(1460px, calc(100vw - 40px));
}

:root[data-cd-theme="light"] {
  color-scheme: light;
  --night: #ece4d0;
  --basalt: #f3ecdb;
  --basalt-2: #faf4e5;
  --papyrus: #1c1e19;
  --papyrus-dim: #4c4c41;
  --papyrus-faint: #6d685a;
  --gold: #8f6400;
  --gold-hot: #a97a00;
  --copper: #8f3c14;
  --lapis: #0d5c72;
  --lapis-hot: #0a6e64;
  --red: #a92e1e;
  --line: #c8bda4;
  --line-hot: #9a8f74;
  --stage: #f6efdf;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; background: var(--night); }

body {
  margin: 0;
  min-width: 320px;
  color: var(--papyrus);
  background:
    radial-gradient(circle at 18% -4%, #d9a44114, transparent 42%),
    radial-gradient(circle at 88% 12%, #3f8fae10, transparent 38%),
    var(--night);
  font-family: var(--mono);
  overflow-x: hidden;
}

button, select { font: inherit; }
a { color: inherit; }

.skip-link {
  position: fixed; top: 8px; left: 8px; z-index: 100;
  padding: 10px 14px; background: var(--gold); color: var(--night);
  transform: translateY(-160%); text-decoration: none; font-size: 11px;
}
.skip-link:focus { transform: translateY(0); }

/* ---- masthead ---- */
.masthead {
  width: var(--page);
  margin: 0 auto;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 34px;
  align-items: center;
  padding: 34px 0 26px;
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 14px; }
.brand svg { width: 52px; height: 52px; }
.mk-pyr { fill: none; stroke: var(--copper); stroke-width: 1.6; }
.mk-sun { fill: var(--gold); }
.mk-ln { fill: none; stroke: var(--papyrus); stroke-width: 1.2; }
.brand span { display: grid; gap: 3px; }
.brand b { font-family: var(--display); font-size: 30px; letter-spacing: .1em; font-weight: 500; }
.brand small { color: var(--gold); font-size: 8px; letter-spacing: .24em; }
.mast-note { max-width: 660px; margin: 0; color: var(--papyrus-dim); font: 14px/1.6 var(--serif); }
.mast-note b { display: block; margin-top: 6px; color: var(--gold); font: 10px var(--mono); letter-spacing: .12em; }
.mast-meta { display: grid; gap: 9px; justify-items: end; }
.mast-meta small { display: block; color: var(--papyrus-faint); font-size: 7px; letter-spacing: .2em; }
.mast-meta strong { color: var(--papyrus); font-size: 11px; letter-spacing: .06em; font-weight: 500; }

.live-rail {
  width: var(--page);
  margin: 0 auto;
  display: grid;
  grid-template-columns: auto auto 1fr auto auto;
  align-items: center;
  gap: 11px 18px;
  min-height: 48px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  color: var(--papyrus-faint);
  font-size: 8px;
  letter-spacing: .14em;
}
.live-rail b { color: var(--papyrus-dim); font-size: 9px; font-weight: 500; }
.live-lamp { width: 8px; height: 8px; border-radius: 50%; background: var(--papyrus-faint); box-shadow: 0 0 0 5px color-mix(in srgb, var(--papyrus-faint), transparent 84%); }
.live-rail[data-state="live"] .live-lamp { background: var(--lapis-hot); box-shadow: 0 0 0 5px color-mix(in srgb, var(--lapis-hot), transparent 84%), 0 0 18px var(--lapis-hot); }
.live-rail[data-state="live"] b { color: var(--lapis-hot); }
.live-rail[data-state="fault"] .live-lamp { background: var(--red); box-shadow: 0 0 16px var(--red); }
.live-rail[data-state="fault"] b { color: var(--red); }

/* ---- index ---- */
.deck-index {
  position: sticky; top: 0; z-index: 30;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 2px;
  padding: 10px max(12px, calc((100vw - 1460px) / 2));
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--night), transparent 8%);
  backdrop-filter: blur(14px);
}
.deck-index a {
  padding: 8px 13px; color: var(--papyrus-dim);
  font-size: 9px; letter-spacing: .14em; text-decoration: none;
  border: 1px solid transparent;
}
.deck-index a:hover, .deck-index a:focus-visible { color: var(--gold-hot); border-color: var(--line); outline: 0; }

/* ---- decks ---- */
main { width: var(--page); margin: 0 auto; }

.deck { padding: 84px 0 30px; border-bottom: 1px solid var(--line); }
.deck > header { max-width: 900px; }
.deck-kicker { margin: 0 0 18px; color: var(--copper); font-size: 10px; letter-spacing: .26em; }
.deck h2 {
  margin: 0;
  font: clamp(58px, 7.2vw, 116px)/.82 var(--display);
  font-weight: 500; letter-spacing: -.02em; text-transform: uppercase;
}
.deck-lede { max-width: 740px; margin: 26px 0 0; color: var(--papyrus-dim); font: 17px/1.55 var(--serif); }
.deck-lede::first-letter { color: var(--gold); }

.deck-stage {
  position: relative;
  margin: 34px 0 0;
  border: 1px solid var(--line);
  background: var(--stage);
  overflow: hidden;
}
.deck-stage canvas { display: block; width: 100%; height: 520px; touch-action: pan-y; }
.stage-tall canvas { height: 640px; cursor: grab; touch-action: none; }
.stage-tall canvas.dragging { cursor: grabbing; }

.deck-facts {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 12px;
}
.deck-facts span {
  padding: 8px 11px; border: 1px solid var(--line);
  color: var(--papyrus-dim); font-size: 8px; letter-spacing: .12em;
}
.deck-facts span b { color: var(--gold); font-weight: 500; }
.deck-facts span.flag { border-color: color-mix(in srgb, var(--copper), transparent 40%); color: var(--copper); }

/* ---- valley detail ---- */
.valley-detail {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 1px;
  margin-top: 1px; border: 1px solid var(--line); background: var(--line);
}
.valley-detail > div { min-width: 0; padding: 13px 15px; background: var(--basalt); }
.valley-detail small { display: block; color: var(--papyrus-faint); font-size: 7px; letter-spacing: .16em; }
.valley-detail strong { display: block; overflow: hidden; margin-top: 8px; color: var(--papyrus); font-size: 11px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.valley-detail a { color: var(--gold); text-decoration: none; }

/* ---- cartouche wall ---- */
.cartouche-wall { position: relative; display: grid; gap: 26px; margin-top: 34px; overflow: hidden; }
.cartouche-wall::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 -18%;
  width: 12%;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--live-color, var(--gold)), transparent 58%), transparent);
  transform: skewX(-10deg);
}
.cartouche-wall.live-strike::after { animation: wallLiveScan 1.15s ease-out; }
.wall-live-witness {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  color: var(--papyrus-faint);
  font-size: 8px;
  letter-spacing: .12em;
}
.wall-live-witness b { color: var(--lapis-hot); font-weight: 500; }
@keyframes wallLiveScan {
  0% { left: -18%; opacity: 0; }
  12% { opacity: .8; }
  100% { left: 108%; opacity: 0; }
}
.wall-course > h3 { margin: 0 0 10px; color: var(--copper); font-size: 10px; letter-spacing: .22em; font-weight: 500; }
.wall-course > div { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.cartouche {
  position: relative;
  display: grid; gap: 7px; align-content: start;
  min-height: 92px; padding: 13px 15px;
  border: 1px solid var(--line); border-radius: 26px;
  background: var(--basalt);
  color: var(--papyrus); text-align: left; cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.cartouche:hover, .cartouche:focus-visible { outline: 0; border-color: var(--gold); background: var(--basalt-2); }
.cartouche b { font-size: 10px; letter-spacing: .06em; font-weight: 500; }
.cartouche code { color: var(--gold); font-size: 9px; }
.cartouche small { color: var(--papyrus-faint); font-size: 7px; letter-spacing: .1em; }
.cartouche .seal {
  position: absolute; right: 10px; top: 10px;
  color: var(--lapis); font-size: 10px; text-decoration: none; padding: 4px;
}
.cartouche .seal:hover { color: var(--lapis-hot); }
.cartouche.copied { border-color: var(--lapis-hot); }
.cartouche.copied::after {
  content: "COPIED"; position: absolute; right: 12px; bottom: 10px;
  color: var(--lapis-hot); font-size: 7px; letter-spacing: .16em;
}

/* ---- footer ---- */
.site-foot {
  width: var(--page);
  display: grid; grid-template-columns: 1fr 1fr; gap: 40px;
  margin: 0 auto; padding: 40px 0 60px;
}
.site-foot b { color: var(--gold); font-size: 9px; letter-spacing: .2em; font-weight: 500; }
.site-foot p { margin: 12px 0 0; color: var(--papyrus-faint); font: 12px/1.6 var(--serif); }

/* ---- overlays ---- */
.viz-tooltip {
  position: fixed; z-index: 60; max-width: 300px;
  padding: 10px 12px; border: 1px solid var(--line-hot);
  background: color-mix(in srgb, var(--basalt), transparent 4%);
  color: var(--papyrus); font-size: 9px; line-height: 1.65; letter-spacing: .05em;
  pointer-events: none; white-space: pre-line;
}
.viz-tooltip b { color: var(--gold); }

.load-veil, .fault-veil {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-content: center; justify-items: center; gap: 12px;
  background: var(--night); text-align: center;
}
.load-veil span { color: var(--papyrus-dim); font-size: 10px; letter-spacing: .3em; animation: veilPulse 1.6s ease infinite; }
body:not([data-loading="true"]) .load-veil { display: none; }
.fault-veil[hidden] { display: none; }
.fault-veil b { color: var(--red); font-size: 13px; letter-spacing: .2em; }
.fault-veil span { max-width: 420px; color: var(--papyrus-dim); font-size: 10px; line-height: 1.7; }
@keyframes veilPulse { 50% { opacity: .35; } }

/* ---- responsive ---- */
@media (max-width: 1000px) {
  .masthead { grid-template-columns: 1fr; gap: 18px; padding-top: 26px; }
  .mast-meta { justify-items: start; grid-template-columns: repeat(3, auto); gap: 22px; }
  .live-rail { grid-template-columns: auto auto 1fr; }
  .live-rail span:nth-last-child(-n+2) { justify-self: start; }
}

@media (max-width: 760px) {
  :root { --page: calc(100vw - 22px); }
  .deck { padding-top: 60px; }
  .deck-stage canvas { height: 420px; }
  .stage-tall canvas { height: 500px; }
  .deck-lede { font-size: 15px; }
  .mast-meta { grid-template-columns: 1fr 1fr; gap: 12px; }
  .live-rail { grid-template-columns: auto 1fr; gap: 8px 10px; padding: 12px 0; }
  .live-rail > span:not(.live-lamp) { grid-column: 2; }
  .site-foot { grid-template-columns: 1fr; gap: 24px; }
  .deck-index { gap: 0; }
  .deck-index a { padding: 7px 9px; font-size: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
