/* ============================================================================
   Journo Run-View — styles.css   (PIVOT: deep-black outward spiral)
   A full-bleed near-black stage; the spiral + its luminous outward pulse own the
   screen. Brief tucked to a top-left pill, telemetry to a compact HUD + subtle
   lower-left stream, transport to a slim bottom pill. Tokens in tokens.css.
   ========================================================================== */

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg-edge);
}
body {
  font-family: var(--font-ui);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ───────────────────────────── stage ───────────────────────────── */

.run { position: fixed; inset: 0; overflow: hidden; }

.stage {
  position: absolute;
  inset: 0;
  /* Lodestar-style dot-matrix field over a centre-lifted deep-black gradient. */
  background:
    radial-gradient(var(--dot) 1.1px, transparent 1.4px) -1px -1px / 22px 22px,
    radial-gradient(ellipse 120% 85% at 50% 42%,
              var(--bg-center) 0%, var(--bg) 46%, var(--bg-edge) 100%);
}
/* vignette to focus the eye + a 2.5% dither to kill 8-bit banding on the gradient. */
.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at center, transparent 54%, rgba(0,0,0,.55) 100%),
    radial-gradient(rgba(255,255,255,.025) 1px, transparent 1px) 0 0 / 3px 3px;
}

#graph { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ───────────────────────────── architectural underlay (blueprint sheet) ──────── */

.frame__outer { stroke: var(--frame); stroke-width: .6; }
.frame__inner { stroke: var(--frame-soft); stroke-width: .5; }
.crop { stroke: var(--tick); stroke-width: .6; }

.tick { stroke: var(--frame-soft); stroke-width: .5; }
.tick--major { stroke: var(--tick); stroke-width: .6; }
.tick__label {
  fill: var(--tick);
  font: 500 8px/1 var(--font-mono);
  letter-spacing: .04em;
}

/* ───────────────────────────── spiral track + arcs + returns ───────────────── */

.track {
  fill: none;
  stroke: rgba(160,186,236,.20);
  stroke-width: .5;
  stroke-dasharray: 1.5 3.5;            /* dotted "construction line" — the un-traversed guide */
  stroke-linecap: round;
}

/* Lit trail (eye→beam): the traversed portion of the spiral, drawn as a delicate cool hairline
   over the dotted guide; revealed via stroke-dash from graph.js. The wide soft bloom is suppressed
   so the spiral reads as a thin schematic line — the nodes are the points of light, not the path. */
.lit { fill: none; stroke-linecap: round; }
.lit--core { stroke: rgba(190,214,255,.55); stroke-width: .7; }
.lit--bloom { display: none; }

/* Flow arcs ride the track: invisible until the pulse has crossed them, then they
   settle to a calm lit tint; the active arc glows in its stage accent. */
.arc {
  fill: none;
  stroke: var(--track);
  stroke-width: 1.4;
  stroke-linecap: round;
  opacity: 0;
  transition: opacity var(--state-dur) var(--ease-calm), stroke var(--state-dur) var(--ease-calm);
}
.arc.is-lit { opacity: .85; stroke: var(--track-lit); }
.arc.is-active { opacity: 1; stroke: var(--accent); stroke-width: 1.8; filter: url(#glow-soft); }
.arc.is-surge { animation: surge var(--surge-dur) var(--ease-out); }

/* Return / rewrite swoops: only visible while a loop-back is happening (counter-motion). */
.return {
  fill: none;
  stroke: var(--rewrite);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-dasharray: 5 9;
  opacity: 0;
  transition: opacity var(--state-dur) var(--ease-calm);
}
.return.is-active { opacity: .7; filter: url(#glow-soft); animation: returnflow 2.2s linear infinite; }

/* Backward "go-back & redo" flow-lines: a thin luminous swoop from a rewrite/rollback/escalate
   station back to where its phase restarts. Same light as the trail, slimmer; the dash streams in
   the backward direction to read as a return of energy. */
.return-flow__glow { display: none; }   /* drop the soft glow — keep only the thin dashed core */
.return-flow__core {
  stroke: var(--rewrite);
  stroke-width: .7;
  stroke-linecap: round;
  stroke-dasharray: 6 10;
  opacity: .85;
  animation: returnflow2 1.5s linear infinite;
}
@keyframes returnflow2 { from { stroke-dashoffset: 0; } to { stroke-dashoffset: -32; } }

/* ───────────────────────────── the hero: outward comet ───────────────────────── */

.comet { fill: none; stroke-linecap: round; }
.comet--core {
  stroke: var(--comet);
  stroke-width: 2.4;
  stroke-dasharray: 140 860;          /* one luminous segment per 1000-unit path */
  animation: cometflow var(--flow-dur) linear infinite;
}
.comet--bloom {
  stroke: #7FB6FF;
  stroke-width: 8;
  opacity: .42;
  stroke-dasharray: 140 860;
  animation: cometflow var(--flow-dur) linear infinite;
}
.comet-head {
  offset-rotate: 0deg;
  offset-anchor: 50% 50%;             /* ride by the centre, not the bbox top-left */
  transform-box: fill-box;
  filter: url(#glow-mid);
  will-change: offset-distance, opacity;
  animation: comethead var(--flow-dur) linear infinite;
}

/* ───────────────────────────── seed nucleus (the eye) ───────────────────────── */

.seed__halo {
  opacity: .26;
  transform-box: fill-box; transform-origin: center;
  animation: breathe var(--breathe-dur) var(--ease-calm) infinite;
}
.seed__ring { stroke: rgba(239,231,214,.32); stroke-width: 1; opacity: .5; }
.seed__core {
  transform-box: fill-box; transform-origin: center;
  animation: breathe-core var(--breathe-dur) var(--ease-calm) infinite;
}
.seed__cap {
  fill: var(--text-faint);
  font: 600 var(--fs-cap)/1 var(--font-ui);
  letter-spacing: var(--ls-cap);
  text-anchor: middle; dominant-baseline: middle;
}
.seed__topic {
  fill: var(--text-dim);
  font: 500 var(--fs-topic)/1 var(--font-ui);
  letter-spacing: .04em;
  opacity: .85;
}

/* ───────────────────────────── stations ───────────────────────────── */

.station__halo {
  opacity: .08;
  transform-box: fill-box; transform-origin: center;
  transition: opacity var(--state-dur) var(--ease-calm);
}
.station__ring {
  fill: none;
  stroke-width: .6;
  opacity: .32;
  transition: opacity var(--state-dur) var(--ease-calm), stroke-width var(--state-dur);
}
.station__core {
  opacity: .55;
  transform-box: fill-box; transform-origin: center;
  transition: opacity var(--state-dur) var(--ease-calm), transform var(--state-dur) var(--ease-out);
}
.station__label, .station__sub {
  dominant-baseline: middle;
  paint-order: stroke;                 /* dark outline → legible over any glow */
  stroke: rgba(6,8,12,.85);
  stroke-width: 2;                      /* slimmer outline for the tiny mono glyphs */
  stroke-linejoin: round;
}
.station__label {
  fill: var(--text-dim);
  font: 500 var(--fs-station)/1 var(--font-mono);   /* mono = schematic / equation feel */
  letter-spacing: var(--ls-station);
  transition: fill var(--state-dur) var(--ease-calm);
}
.station__sub {
  fill: var(--text-dim);
  font: 500 var(--fs-sub)/1 var(--font-mono);
  letter-spacing: .02em;
}

/* state machine */
.station.is-idle  .station__halo { opacity: .10; }
.station.is-idle  .station__core { opacity: .34; }
.station.is-idle  .station__ring { opacity: .20; }

.station.is-done  .station__halo,
.station.is-pass  .station__halo { opacity: .42; }
.station.is-done  .station__core,
.station.is-pass  .station__core { opacity: .85; }
.station.is-done  .station__label,
.station.is-pass  .station__label { fill: var(--text-dim); }
.station.is-done  .station__ring,
.station.is-pass  .station__ring { opacity: .6; }

.station.is-active .station__halo {
  opacity: .5;
  animation: breathe var(--breathe-dur) var(--ease-calm) infinite;
}
.station.is-active .station__core { opacity: 1; }
.station.is-active .station__ring { opacity: .95; stroke-width: .9; }
.station.is-active .station__label { fill: var(--text); font-weight: 600; }

.station.is-fail  .station__halo { opacity: .6; animation: breathe calc(var(--breathe-dur) * .7) var(--ease-calm) infinite; }
.station.is-fail  .station__core { opacity: 1; }
.station.is-fail  .station__ring { opacity: .9; }
.station.is-fail  .station__label { fill: var(--error); }

.station.is-warn  .station__halo { opacity: .7; }
.station.is-warn  .station__core { opacity: .95; }
.station.is-warn  .station__label { fill: var(--warn); }

/* ───────────────────────────── event blooms (fx) ───────────────────────────── */

.bloom__glow {
  opacity: .55;
  transform-box: fill-box; transform-origin: center;
}
.bloom__ring {
  fill: none;
  stroke-width: 1.5;
  transform-box: fill-box; transform-origin: center;
}
.bloom--error  .bloom__glow { animation: bloomglow var(--ping-dur)  var(--ease-out) forwards; }
.bloom--crucial .bloom__glow { animation: bloomglow var(--bloom-dur) var(--ease-out) forwards; }
.bloom--error  .bloom__ring { animation: bloomring var(--ping-dur)  var(--ease-out) forwards; }
.bloom--crucial .bloom__ring { animation: bloomring var(--bloom-dur) var(--ease-out) forwards; }

/* ───────────────────────────── brief pill (top-left) ───────────────────────── */

.brief { position: absolute; top: 20px; left: 20px; z-index: 5; width: 244px; }
.brief__form {
  background: rgba(14,19,28,.66);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border: 1px solid var(--hairline);
  border-radius: 13px;
  padding: 11px 13px;
  transition: border-color .3s, background .3s;
}
.brief:hover .brief__form, .brief:focus-within .brief__form {
  border-color: var(--hairline-2);
  background: rgba(16,22,32,.82);
}
.brief__fields { display: flex; flex-direction: column; gap: 9px; }
.brief__field { display: flex; flex-direction: column; gap: 3px; }
.brief__label {
  font-size: var(--fs-cap); letter-spacing: var(--ls-cap);
  text-transform: uppercase; color: var(--text-faint);
}
.brief__input {
  background: rgba(255,255,255,.045);
  border: 1px solid var(--hairline-2);
  border-radius: 7px;
  outline: none;
  padding: 6px 9px;
  color: var(--text);
  font: 500 var(--fs-topic)/1.35 var(--font-ui);
  width: 100%; box-sizing: border-box; resize: none;
  transition: border-color .18s, background .18s, box-shadow .18s;
}
.brief__input:hover { border-color: var(--text-faint); }
.brief__input:focus {
  border-color: var(--gate);
  background: rgba(63,224,176,.06);
  box-shadow: 0 0 0 3px rgba(63,224,176,.14);
}
.brief__input::placeholder { color: var(--text-faint); }
textarea.brief__input { line-height: 1.4; }

/* All three input fields + the Run action are shown up front (no hover-to-reveal). */
.brief__actions { margin-top: 4px; display: flex; }
.brief__run {
  flex: 1;
  background: var(--gate); color: #052a20;
  border: 1px solid transparent; border-radius: 8px;
  padding: 8px 14px;
  font: 700 var(--fs-cap)/1 var(--font-ui); letter-spacing: var(--ls-cap);
  text-transform: uppercase; cursor: pointer;
  box-shadow: 0 0 0 0 rgba(63,224,176,0);
  transition: background .2s, box-shadow .2s, opacity .2s;
}
.brief__run:hover { background: #56eec0; box-shadow: 0 0 16px rgba(63,224,176,.4); }
.brief__run:active { background: #34c89b; }
.brief.is-running .brief__run { background: var(--surface-2); color: var(--text-dim); cursor: default; box-shadow: none; }

/* ───────────────────────────── HUD (top-right) ───────────────────────────── */

.hud {
  position: absolute; top: 20px; right: 24px; z-index: 5;
  display: flex; align-items: center; gap: 22px;
  font-variant-numeric: var(--tnum);
}
.hud__status { display: flex; align-items: center; gap: 7px; }
.hud__dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-faint); color: var(--text-faint);
  box-shadow: 0 0 7px currentColor;
}
.hud__dot.is-running { background: var(--band1); color: var(--band1); animation: pulse-dot 2.2s var(--ease-calm) infinite; }
.hud__dot.is-done { background: var(--gate); color: var(--gate); }
.hud__dot.is-needs-review { background: var(--warn); color: var(--warn); }
.hud__dot.is-failed { background: var(--error); color: var(--error); }
.hud__status-text {
  font-size: var(--fs-cap); letter-spacing: var(--ls-cap);
  text-transform: uppercase; color: var(--text-dim);
}
.hud__metric { display: flex; flex-direction: column; gap: 3px; align-items: flex-start; }
.hud__cap {
  font-size: var(--fs-cap); letter-spacing: var(--ls-cap);
  text-transform: uppercase; color: var(--text-faint);
}
.hud__val { font-family: var(--font-mono); font-size: var(--fs-value); color: var(--text); }
.hud__val.is-warn { color: var(--warn); }
.hud__val.is-over { color: var(--error); }
.hud__iter-dots { display: flex; gap: 9px; }
.hud__iter-item { display: flex; align-items: center; gap: 4px; }
.hud__iter-dot { width: 6px; height: 6px; border-radius: 50%; box-shadow: 0 0 6px currentColor; }
.hud__iter-item--b1 .hud__iter-dot { background: var(--band1); color: var(--band1); }
.hud__iter-item--b2 .hud__iter-dot { background: var(--band2); color: var(--band2); }
.hud__iter-item--b3 .hud__iter-dot { background: var(--band3); color: var(--band3); }
.hud__iter-n { font-family: var(--font-mono); font-size: var(--fs-value); color: var(--text-dim); }
.hud__best.is-empty { display: none; }
.hud__best .hud__val { color: var(--crucial); }
.hud__best.is-bump { animation: best-bump .6s var(--ease-out); }

/* ───────────────────────────── rail (lower-left telemetry) ───────────────────── */

.rail {
  position: absolute; left: 20px; bottom: 86px; z-index: 4;
  width: 340px; max-height: 42vh;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.rail__cap {
  font-size: var(--fs-cap); letter-spacing: var(--ls-cap);
  text-transform: uppercase; color: var(--text-faint);
}
/* TELEMETRY cap doubles as a collapse toggle (the rail is otherwise click-through). */
.rail__toggle {
  pointer-events: auto; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; align-self: flex-start;
  background: none; border: none; padding: 2px 0; margin: 0;
  font: inherit; font-size: var(--fs-cap); letter-spacing: var(--ls-cap);
  text-transform: uppercase; color: var(--text-faint);
  transition: color .2s;
}
.rail__toggle:hover { color: var(--text-dim); }
.rail__caret { font-size: 8px; line-height: 1; opacity: .8; }
.rail.is-telemetry-collapsed #rail-log { display: none; }
#rail-faults:empty { display: none; }
.faults__header {
  font-size: var(--fs-cap); letter-spacing: var(--ls-cap);
  text-transform: uppercase; color: var(--error); margin-bottom: 5px; opacity: .9;
}
.fault-row {
  display: flex; align-items: center; gap: 8px;
  padding: 3px 0; font-size: var(--fs-sub); color: var(--text-dim);
  pointer-events: auto;
}
.fault-row__bullet { color: var(--error); }
.fault-row__balloon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; border-radius: 50%;
  border: 1px solid var(--error); color: var(--error);
  font-size: 8.5px; font-family: var(--font-mono);
}
.fault-row__claim { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fault-row__sev { font-size: var(--fs-cap); letter-spacing: .04em; color: var(--text-faint); }

#rail-log {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 1px;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 14%, #000 100%);
  mask-image: linear-gradient(to bottom, transparent, #000 14%, #000 100%);
}
.log-row {
  display: flex; align-items: center; gap: 8px;
  font-size: var(--fs-sub); color: var(--text-dim); opacity: .78;
  padding: 2px 0; animation: logrow-in .4s var(--ease-out);
}
.log-row__t { font-family: var(--font-mono); font-size: var(--fs-cap); color: var(--text-faint); }
.log-row__zone {
  font-family: var(--font-mono); font-size: var(--fs-cap); color: var(--text-faint);
  width: 52px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.log-row__chip { display: inline-flex; gap: 3px; font-size: var(--fs-cap); letter-spacing: .04em; }
.log-row__label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-row--pass    .log-row__chip { color: var(--pass); }
.log-row--fail    .log-row__chip { color: var(--error); }
.log-row--crucial .log-row__chip { color: var(--crucial); }
.log-row--rewrite .log-row__chip { color: var(--rewrite); }
.log-row--stage   .log-row__chip { color: var(--text-dim); }

/* ───────────────────────────── transport (bottom centre) ───────────────────── */

.transport {
  position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 6;
  display: flex; align-items: center; gap: 14px;
  background: rgba(14,19,28,.7);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border: 1px solid var(--hairline); border-radius: 999px;
  padding: 8px 16px;
}
.transport__btn {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--hairline-2); border-radius: 999px;
  padding: 6px 17px;
  font: 600 var(--fs-cap)/1 var(--font-ui); letter-spacing: var(--ls-cap);
  text-transform: uppercase; cursor: pointer; transition: background .2s;
}
.transport__btn:hover { background: #1b2331; }
.transport__clock {
  font-family: var(--font-mono); font-size: var(--fs-value);
  color: var(--text-dim); min-width: 108px; text-align: center;
}
.transport__scrub {
  -webkit-appearance: none; appearance: none;
  width: 340px; height: 3px; border-radius: 2px;
  background: rgba(170,182,210,.18); outline: none; cursor: pointer;
}
.transport__scrub::-webkit-slider-thumb {
  -webkit-appearance: none; width: 13px; height: 13px; border-radius: 50%;
  background: var(--comet); box-shadow: 0 0 8px rgba(234,244,255,.75); cursor: pointer;
}
.transport__scrub::-moz-range-thumb {
  width: 13px; height: 13px; border: none; border-radius: 50%;
  background: var(--comet); box-shadow: 0 0 8px rgba(234,244,255,.75); cursor: pointer;
}

/* ───────────────────────────── keyframes ───────────────────────────── */

/* comet dash sweeps outward (eye→rim); leading edge leads, glowing tail trails inward. */
@keyframes cometflow { from { stroke-dashoffset: 140; } to { stroke-dashoffset: -860; } }
@keyframes comethead {
  0%   { offset-distance: 0%;   opacity: 0; }
  8%   { opacity: 1; }
  92%  { opacity: 1; }
  100% { offset-distance: 100%; opacity: 0; }
}
@keyframes returnflow { from { stroke-dashoffset: 0; } to { stroke-dashoffset: -28; } }
@keyframes breathe {
  0%, 100% { opacity: .55; transform: scale(1); }
  50%      { opacity: .95; transform: scale(1.06); }
}
@keyframes breathe-core {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.05); }
}
@keyframes surge {
  0%   { opacity: .5; stroke-width: 1.4; }
  30%  { opacity: 1; stroke-width: 3; }
  100% { opacity: 1; stroke-width: 1.8; }
}
@keyframes bloomglow {
  0%   { opacity: .6; transform: scale(.7); }
  55%  { opacity: .5; }
  100% { opacity: 0; transform: scale(1.6); }
}
@keyframes bloomring {
  0%   { opacity: .9; transform: scale(.6); }
  100% { opacity: 0; transform: scale(2.9); }
}
@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 4px currentColor; }
  50%      { box-shadow: 0 0 11px currentColor; }
}
@keyframes best-bump {
  0% { transform: scale(1); } 40% { transform: scale(1.13); } 100% { transform: scale(1); }
}
@keyframes logrow-in {
  from { opacity: 0; transform: translateY(-3px); }
  to   { opacity: .78; transform: none; }
}

/* ───────────────────────────── reduced motion ───────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .comet { opacity: 0; }
  .comet-head { display: none; }
  .arc { opacity: .7; stroke: var(--track-lit); }          /* freeze: spiral shown lit */
  .station.is-active .station__halo,
  .station.is-fail   .station__halo,
  .seed__halo, .seed__core { animation: none; }
  .return.is-active { animation: none; }
  .return-flow__core { animation: none; }
  .hud__dot.is-running { animation: none; }
  .bloom__glow, .bloom__ring { animation: none; opacity: 0; }
  .log-row { animation: none; }
}
