/* Overclocked — act3.css (owner: js/act3.js)
 * ACT III "Galaxy Brain": the night palette, the banner interstitial, the page starfield,
 * deep-chapter styling and the fin coda. Class prefix: a3-.
 *
 * NIGHT PALETTE
 *   The engine sets --act-blend on :root (0 → 1 while the #act3 banner scrolls past the reading
 *   line, 1 afterwards, 0 outside Act III). It is remapped into --a3-night (a registered number,
 *   so it eases when the reader jumps straight into / out of Act III) and every palette token is
 *   re-defined from it under :root[data-act='3'].
 *   Two ramps, so text never sinks into a mid-grey page:
 *     --a3-night   backgrounds + hairlines (paper → night)
 *     --a3-k       text / lines / accents: stay dark until the page is dark enough, then flip light
 *   Tokens are registered as <color> so getComputedStyle / OC.util.css() return plain rgb()
 *   strings that any canvas or colour parser understands.
 */

@property --a3-night { syntax: '<number>'; inherits: true; initial-value: 0; }
@property --bg { syntax: '<color>'; inherits: true; initial-value: #fffff8; }
@property --bg-sunk { syntax: '<color>'; inherits: true; initial-value: #f6f5ea; }
@property --ink { syntax: '<color>'; inherits: true; initial-value: #111111; }
@property --ink-2 { syntax: '<color>'; inherits: true; initial-value: #3a3a3a; }
@property --muted { syntax: '<color>'; inherits: true; initial-value: #74746c; }
@property --rule { syntax: '<color>'; inherits: true; initial-value: #d9d8cc; }
@property --line { syntax: '<color>'; inherits: true; initial-value: #1a1a1a; }
@property --star { syntax: '<color>'; inherits: true; initial-value: #111111; }
@property --glow { syntax: '<color>'; inherits: true; initial-value: rgba(43, 96, 57, .45); }

:root {
  --a3-night: 0;
  --star: #111111;                       /* by day a "star" is an ink dot */
  --glow: rgba(43, 96, 57, .45);
  transition: --accent 900ms var(--ease), --accent-soft 900ms var(--ease), --a3-night 420ms var(--ease);
}
:root[data-branch='race'] { --glow: rgba(139, 0, 0, .45); }

:root[data-act='3'] {
  /* reach full night while the banner's stage is pinned (see js/act3.js for the timing) */
  --a3-night: clamp(0, calc((var(--act-blend, 1) - .08) / .34), 1);
  --a3-k: clamp(0, calc((var(--a3-night) - .5) / .14), 1);

  /* paper → a brief blue dusk → night */
  --a3-dusk: calc(var(--a3-night) * (1 - var(--a3-night)));
  --bg:      rgb(calc(255 - 245 * var(--a3-night) - 44 * var(--a3-dusk)) calc(255 - 245 * var(--a3-night) - 24 * var(--a3-dusk)) calc(248 - 237 * var(--a3-night) + 52 * var(--a3-dusk)));
  --bg-sunk: rgb(calc(246 - 226 * var(--a3-night) - 40 * var(--a3-dusk)) calc(245 - 225 * var(--a3-night) - 20 * var(--a3-dusk)) calc(234 - 212 * var(--a3-night) + 48 * var(--a3-dusk)));
  --rule:    rgb(calc(217 - 175 * var(--a3-night)) calc(216 - 174 * var(--a3-night)) calc(204 - 159 * var(--a3-night)));
  --ink:     rgb(calc(17 + 219 * var(--a3-k)) calc(17 + 215 * var(--a3-k)) calc(17 + 203 * var(--a3-k)));
  --ink-2:   rgb(calc(58 + 142 * var(--a3-k)) calc(58 + 137 * var(--a3-k)) calc(58 + 123 * var(--a3-k)));
  --muted:   rgb(calc(116 + 26 * var(--a3-k)) calc(116 + 22 * var(--a3-k)) calc(108 + 19 * var(--a3-k)));
  --line:    rgb(calc(26 + 204 * var(--a3-k)) calc(26 + 200 * var(--a3-k)) calc(26 + 188 * var(--a3-k)));
  --star:    rgb(calc(17 + 227 * var(--a3-k)) calc(17 + 222 * var(--a3-k)) calc(17 + 208 * var(--a3-k)));
  /* slowdown (and the never-used trunk) */
  --accent:      rgb(calc(43 + 68 * var(--a3-k)) calc(96 + 112 * var(--a3-k)) calc(57 + 86 * var(--a3-k)));
  --accent-soft: rgb(calc(90 - 27 * var(--a3-k)) 138 calc(104 - 12 * var(--a3-k)));
  --glow:        rgb(calc(43 + 68 * var(--a3-k)) calc(96 + 112 * var(--a3-k)) calc(57 + 86 * var(--a3-k)) / .45);
  scrollbar-color: var(--rule) var(--bg);
  /* the accent follows the scroll-driven blend directly (no extra 900ms lag) */
  transition: --accent 300ms var(--ease), --accent-soft 300ms var(--ease), --a3-night 420ms var(--ease);
}
:root[data-act='3'][data-branch='race'] {
  --accent:      rgb(calc(139 + 116 * var(--a3-k)) calc(90 * var(--a3-k)) calc(74 * var(--a3-k)));
  --accent-soft: rgb(184 calc(104 - 35 * var(--a3-k)) calc(104 - 45 * var(--a3-k)));
  --glow:        rgb(calc(139 + 116 * var(--a3-k)) calc(90 * var(--a3-k)) calc(74 * var(--a3-k)) / .45);
}

/* ---------- page chrome at night (tokens do most of the work) ---------- */
:root[data-act='3'] ::selection { background: color-mix(in srgb, var(--accent) 34%, transparent); color: var(--ink); }
:root[data-act='3'] .pill:hover,
:root[data-act='3'] .pill:focus-visible { box-shadow: 0 0 calc(var(--a3-night) * 22px) calc(var(--a3-night) * -2px) var(--glow); }
:root[data-act='3'] .sn-ref a { text-shadow: 0 0 calc(var(--a3-night) * 10px) var(--glow); }
:root[data-act='3'] .ch-notes li:target { background: color-mix(in srgb, var(--accent) 18%, transparent); }
:root[data-act='3'] .ui-card,
:root[data-act='3'] .ui-rail-tip { box-shadow: 0 16px 40px -18px rgba(0, 0, 0, calc(.45 + .4 * var(--a3-night))), 0 0 0 1px var(--rule); }
:root[data-act='3'] .fin-mark { text-shadow: 0 0 calc(var(--a3-night) * 18px) var(--glow); }
:root[data-act='3'] .ending-title { text-shadow: 0 0 calc(var(--a3-night) * 26px) var(--glow); }

/* ================================================================== *
 * page starfield — fixed, behind all content
 * ================================================================== */
.a3-sky {
  position: fixed; inset: 0; width: 100%; height: 100%; display: block;
  z-index: -1; pointer-events: none;
  opacity: 0; visibility: hidden;
}
:root[data-act='3'] .a3-sky { opacity: var(--a3-night); visibility: visible; }

/* ================================================================== *
 * the banner: #act3 (rendered by the engine, restructured by js/act3.js)
 * ================================================================== */
.act3 {
  position: relative; height: 170vh; margin: 72px 0 0;
  /* engine children before js/act3.js moves them into the stage (no-JS / early paint) */
  padding-top: 0;
}
.act3 > .act3-kicker, .act3 > .act3-title, .act3 > .act3-note { position: relative; }

/* feathered edge where the full-bleed stage slides over the dashboard column */
.a3-feather {
  position: absolute; left: 0; top: -22vh; height: 22vh; z-index: 4; pointer-events: none;
  width: var(--a3-vw, 100vw); margin-left: calc(-1 * var(--a3-left, 0px));
  background: linear-gradient(to bottom, transparent, var(--bg));
  /* only over the dashboard column — never dim the last lines of the story */
  -webkit-mask-image: linear-gradient(to right, transparent calc(var(--a3-left, 0px) + var(--story-w) + 12px), #000 calc(var(--a3-left, 0px) + var(--story-w) + 36px));
  mask-image: linear-gradient(to right, transparent calc(var(--a3-left, 0px) + var(--story-w) + 12px), #000 calc(var(--a3-left, 0px) + var(--story-w) + 36px));
}
.a3-stage {
  position: sticky; top: 0; z-index: 4;
  height: 100vh; height: 100svh; overflow: hidden;
  width: var(--a3-vw, 100vw); margin-left: calc(-1 * var(--a3-left, 0px));
  background: var(--bg); color: var(--ink);
  --a3-t: 0; --a3-c: 0; --a3-cue: 1;
}
.a3-gl, .a3-fx {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none;
  /* soft lower edge: the stage's bottom slides up over the page when it un-pins */
  -webkit-mask-image: linear-gradient(to bottom, #000 78%, transparent);
  mask-image: linear-gradient(to bottom, #000 78%, transparent);
}
.a3-gl[hidden] { display: none; }

.a3-copy {
  position: absolute; z-index: 1; top: 0; bottom: 0; left: var(--a3-pad, 24px);
  width: min(560px, calc(100% - var(--a3-pad, 24px) - 24px));
  display: flex; flex-direction: column; justify-content: center;
  pointer-events: none;
}
.a3-copy > * { pointer-events: auto; }

.a3-stage .act3-kicker {
  display: flex; align-items: center; gap: 12px; margin: 0 0 18px;
  font: 500 12px/1 var(--mono); letter-spacing: .16em; text-transform: uppercase; color: var(--accent);
  opacity: clamp(0, calc(var(--a3-t) * 5), 1);
  transform: translateY(calc((1 - clamp(0, calc(var(--a3-t) * 5), 1)) * 8px));
}
.a3-stage .act3-kicker::before {
  content: ''; flex: none; height: 1px; background: currentColor;
  width: calc(clamp(0, calc(var(--a3-t) * 3), 1) * 34px);
  box-shadow: 0 0 calc(var(--a3-night) * 8px) var(--glow);
}
.a3-stage .act3-title {
  --n: 11;
  margin: 0 0 26px; font-weight: 400; color: var(--ink);
  font-size: clamp(66px, 8.7vw, 134px); line-height: .9; letter-spacing: -.02em;
}
.a3-w { display: block; white-space: nowrap; }
.a3-l {
  --k: clamp(0, calc((var(--a3-t) * (var(--n) + 3) - var(--i)) / 3), 1);
  display: inline-block; will-change: opacity, transform, filter;
  opacity: var(--k);
  transform: translateY(calc((1 - var(--k)) * .26em)) scale(calc(.9 + .1 * var(--k)));
  filter: blur(calc((1 - var(--k)) * 9px));
  color: color-mix(in srgb, var(--accent) calc((1 - var(--k)) * 100%), var(--ink));
  text-shadow: 0 0 calc(var(--a3-night) * 30px + (1 - var(--k)) * 20px) var(--glow), 0 0 2px var(--bg);
}
.a3-stage .act3-note {
  margin: 0 0 14px; max-width: 29em;
  font-style: italic; font-size: 20px; line-height: 28px; color: var(--ink-2);
  opacity: clamp(0, calc(var(--a3-c) * 2.2), 1);
  transform: translateY(calc((1 - clamp(0, calc(var(--a3-c) * 2.2), 1)) * 12px));
}
.a3-theme {
  margin: 0; max-width: 29em; padding-top: 14px; position: relative;
  font-size: 20px; line-height: 28px; color: var(--ink);
  opacity: clamp(0, calc(var(--a3-c) * 2.2 - 1.1), 1);
  transform: translateY(calc((1 - clamp(0, calc(var(--a3-c) * 2.2 - 1.1), 1)) * 12px));
  text-shadow: 0 0 12px var(--bg);
}
.a3-theme::before {
  content: ''; position: absolute; left: 0; top: 0; height: 1px; width: 64px;
  background: linear-gradient(90deg, var(--accent), transparent);
}
.a3-theme .mono { font-size: .8em; letter-spacing: .02em; color: var(--accent); }
.a3-theme em { color: var(--accent); font-style: italic; text-shadow: 0 0 calc(var(--a3-night) * 14px) var(--glow); }

/* scroll cue: a slow signal crawling down a hairline */
.a3-cue {
  position: absolute; left: 50%; bottom: 22px; z-index: 1; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 9px;
  font: 500 10px/1 var(--mono); letter-spacing: .24em; text-indent: .24em; text-transform: uppercase; color: var(--muted);
  opacity: var(--a3-cue); pointer-events: none;
}
.a3-cue i { position: relative; display: block; width: 1px; height: 42px; overflow: hidden;
  background: linear-gradient(var(--muted), transparent); }
.a3-cue i::after {
  content: ''; position: absolute; left: -1.5px; top: -8px; width: 4px; height: 8px; border-radius: 2px;
  background: var(--accent); box-shadow: 0 0 8px var(--glow);
  animation: a3-cue 2.4s cubic-bezier(.45, 0, .55, 1) infinite;
}
@keyframes a3-cue { 0% { transform: translateY(0); opacity: 0; } 15% { opacity: 1; } 100% { transform: translateY(54px); opacity: 0; } }

@media (max-width: 960px) {
  .act3 { margin-top: 56px; }
  .a3-feather { display: none; }
  .a3-copy { left: 16px; right: 16px; width: auto; top: auto; bottom: max(7svh, 44px); justify-content: flex-end; }
  .a3-stage .act3-kicker { margin-bottom: 12px; font-size: 11px; }
  .a3-stage .act3-title { font-size: clamp(50px, 15.5vw, 92px); margin-bottom: 16px; }
  .a3-w { display: inline; }
  .a3-w + .a3-w::before { content: ' '; }
  .a3-stage .act3-note, .a3-theme { font-size: 17px; line-height: 24px; }
  .a3-theme { padding-top: 10px; }
  .a3-cue { display: none; }
}
@media (max-width: 960px) and (max-height: 700px) {
  .a3-stage .act3-note { display: none; }
}

/* ================================================================== *
 * deep chapters (.chapter--deep)
 * ================================================================== */
.chapter--deep .ch-date {
  background: transparent; color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent-soft), 0 0 14px -3px var(--glow);
  transition: background-color .35s var(--ease), color .35s var(--ease), box-shadow .35s var(--ease);
}
.chapter--deep.is-active .ch-date {
  background: var(--accent); color: var(--bg);
  box-shadow: 0 0 0 1px var(--accent), 0 0 18px 0 var(--glow);
}
.chapter--deep .ch-title-date { color: var(--accent); }
.ch-beyond {
  display: inline-block; padding: 2px 6px 1px; border: 1px solid var(--accent-soft); border-radius: 999px;
  font-size: 9.5px; line-height: 1.2; letter-spacing: .09em; color: var(--accent);
  white-space: nowrap;
}
.ch-beyond::before {
  content: ''; display: inline-block; width: 7px; height: 7px; margin: 0 5px 1px 0; vertical-align: middle;
  background: currentColor;
  -webkit-mask: var(--a3-star) center / contain no-repeat; mask: var(--a3-star) center / contain no-repeat;
}
/* hairline + star glyph between deep chapters */
.chapter--deep + .chapter--deep { position: relative; }
.chapter--deep + .chapter--deep::before {
  content: ''; position: absolute; left: 0; right: 0; top: 20px; height: 1px; pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--rule) 18%, var(--rule) calc(50% - 22px), transparent calc(50% - 22px),
    transparent calc(50% + 22px), var(--rule) calc(50% + 22px), var(--rule) 82%, transparent);
}
.chapter--deep + .chapter--deep::after {
  content: ''; position: absolute; left: 50%; top: 13px; width: 15px; height: 15px; margin-left: -7.5px; pointer-events: none;
  background: var(--accent);
  -webkit-mask: var(--a3-star) center / contain no-repeat; mask: var(--a3-star) center / contain no-repeat;
  filter: drop-shadow(0 0 calc(var(--a3-night) * 5px) var(--glow));
}
:root {
  --a3-star: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 0C12.9 7.6 16.4 11.1 24 12 16.4 12.9 12.9 16.4 12 24 11.1 16.4 7.6 12.9 0 12 7.6 11.1 11.1 7.6 12 0Z'/%3E%3C/svg%3E");
}

/* ================================================================== *
 * fin (coda happens on the starfield canvas; see js/act3.js)
 * ================================================================== */
.a3-top { white-space: nowrap; }

@media print {
  .a3-sky, .a3-feather, .a3-cue, .a3-gl, .a3-fx { display: none !important; }
  .act3 { height: auto; }
  .a3-stage { position: static; height: auto; width: auto; margin: 0; overflow: visible; background: none; }
  .a3-copy { position: static; width: auto; }
  .a3-stage .act3-kicker, .a3-l, .a3-stage .act3-note, .a3-theme { opacity: 1 !important; transform: none !important; filter: none !important; }
}

/* ================================================================== *
 * reduced motion: static poses
 * ================================================================== */
@media (prefers-reduced-motion: reduce) {
  .a3-stage { --a3-t: 1 !important; --a3-c: 1 !important; }
  .a3-l { filter: none; will-change: auto; }
  .a3-cue i::after { animation: none; top: 17px; }
}
