/* ==========================================================================
   CORPO RETRO WEB KIT - PRIMITIVES.   Hand-authored; consumes tokens.css.
   Load order:  tokens.css  ->  corpo-retro.css  ->  your site/app CSS.

   Each block names the game component it ports (cybertower/ui/...). These are
   PRIMITIVES: the chrome grammar, not page layout. A consumer composes them;
   it does not restyle them. Every value is a var() from tokens.css, which is
   generated from the game. A literal colour or size in this file is a defect.

   Classes are prefixed cr- so they can sit beside any site's own CSS.
   ========================================================================== */

/* -- base ---------------------------------------------------------------- */
/* terminal_theme.tres: one face, one weight (the embolden is baked into the
   face), amber on near-black. font-synthesis: none, because a faux bold or
   italic on a one-weight terminal face is the thing the grammar forbids. */
.cr-root {
  background: var(--cr-surface);
  color: var(--cr-value);
  font-family: var(--cr-font);
  font-size: var(--cr-fs-body);
  font-weight: 400;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
}

/* -- TerminalPalette text roles ------------------------------------------ */
.cr-hero   { color: var(--cr-hero); }
.cr-header { color: var(--cr-header); }
.cr-value  { color: var(--cr-value); }
.cr-label  { color: var(--cr-label); }
.cr-lore   { color: var(--cr-lore); }
.cr-dim    { color: var(--cr-dim); }
.cr-alert  { color: var(--cr-alert); }  /* never colour alone: pair with - or [ FAULT ] */
.cr-ok     { color: var(--cr-ok); }     /* a status verdict only, never a line item */

/* -- TerminalType rungs ------------------------------------------------------ */
.cr-fs-chip  { font-size: var(--cr-fs-chip); }
.cr-fs-row   { font-size: var(--cr-fs-row); }
.cr-fs-body  { font-size: var(--cr-fs-body); }
.cr-fs-label { font-size: var(--cr-fs-label); }
.cr-fs-title { font-size: var(--cr-fs-title); }
.cr-fs-hero  { font-size: var(--cr-fs-hero); }

/* -- Phosphor ------------------------------------------------------------ */
/* apply_glow: lit tokens only (titles, the active toggle, the balance). Body
   text, labels and values never glow. apply_bloom: hero surfaces only, opted
   in BY SURFACE, never by size. */
.cr-glow        { text-shadow: var(--cr-glow); }
.cr-glow--alert { text-shadow: var(--cr-glow-alert); }
.cr-bloom       { text-shadow: var(--cr-bloom); }

/* -- TerminalPanel + BorderOverlay + ScanlineOverlay ---------------------- */
/* Flat SURFACE fill, a 1px BORDER core with the GLOW_PASSES halo hugging it
   on both sides (draw_line is centred on the edge), square corners, and the
   static warm scanlines over the whole surface. No drop shadow, no gradient,
   no radius. */
.cr-panel {
  position: relative;
  background: var(--cr-surface);
  border: var(--cr-border-w) solid var(--cr-border);
  box-shadow: var(--cr-border-glow), var(--cr-border-glow-inset);
  border-radius: 0;
}
.cr-scan { position: relative; isolation: isolate; }
.cr-panel::after,
.cr-scan::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--cr-scanlines);
  pointer-events: none;
  z-index: 2;
}
/* TerminalPanel.build_std_root: margins 16/12/10, rows 5 apart. */
.cr-panel__body {
  padding: var(--cr-pad-top) var(--cr-pad-right) var(--cr-pad-bottom) var(--cr-pad-left);
  display: flex;
  flex-direction: column;
  gap: var(--cr-row-gap);
}
/* build_std_header: TITLE in HEADER + glow, a bracketed [ X ] at the right,
   one std divider underneath. */
.cr-panel__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--cr-btn-pad-x);
  padding-bottom: var(--cr-row-gap);
  border-bottom: 1px solid var(--cr-lore);
  font-size: var(--cr-fs-title);
  color: var(--cr-header);
  text-shadow: var(--cr-glow);
  text-transform: uppercase;
}
.cr-panel__head > .cr-btn { font-size: var(--cr-fs-label); text-shadow: none; }

/* VignetteOverlay: menus and boot only, never over the world (or game media). */
.cr-vignette { position: relative; }
.cr-vignette::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--cr-vignette);
  pointer-events: none;
  z-index: 1;
}

/* -- build_std_sep + the labelled section idiom --------------------------- */
.cr-sep { height: 1px; border: 0; background: var(--cr-lore); width: 100%; }
/* "── SECTION": LABEL rung, one step above the rows it introduces. */
.cr-section {
  font-size: var(--cr-fs-label);
  color: var(--cr-label);
  text-transform: uppercase;
}
.cr-section::before { content: "\2500\2500  "; color: var(--cr-lore); }

/* -- TerminalButton ------------------------------------------------------- */
/* Brackets are TEXT, written by the caller: "[ X ]" on HUD/toolbar-width
   controls, "[X]" on chip rows. Never compose them twice. The theme's button
   styleboxes are all EMPTY: hover is the font lift alone, no border.
   Two state sets, as in the game:
     .cr-btn          an ACTION (theme Button colours): VALUE -> hover HERO,
                      pressed at .7. The main menu's [ NEW GAME ] is this.
     .cr-btn--toggle  a TOGGLE (TerminalButton toggle_mode): off LABEL ->
                      hover VALUE -> on VALUE + glow -> hover-while-on HERO.
                      .is-on, aria-pressed="true" or aria-current="page". */
.cr-btn {
  appearance: none;
  background: none;
  border: 0;
  border-radius: 0;
  padding: var(--cr-btn-pad-y) var(--cr-btn-pad-x);
  font: inherit;
  color: var(--cr-value);
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  display: inline-block;
}
.cr-btn:hover { color: var(--cr-hero); }
.cr-btn:active { color: var(--cr-btn-pressed); }
.cr-btn--toggle { color: var(--cr-label); }
.cr-btn--toggle:hover { color: var(--cr-value); }
.cr-btn--toggle.is-on,
.cr-btn--toggle[aria-pressed="true"],
.cr-btn--toggle[aria-current="page"] { color: var(--cr-value); text-shadow: var(--cr-glow); }
.cr-btn--toggle.is-on:hover,
.cr-btn--toggle[aria-pressed="true"]:hover,
.cr-btn--toggle[aria-current="page"]:hover { color: var(--cr-hero); }
.cr-btn:disabled,
.cr-btn[aria-disabled="true"] { color: var(--cr-btn-disabled); cursor: default; text-shadow: none; }
/* Keyboard focus: the theme's focus colour is HERO. The web adds a 1px BORDER
   ring because a colour shift alone is not a visible-focus indicator. */
.cr-btn:focus-visible { color: var(--cr-hero); outline: 1px solid var(--cr-border); outline-offset: 0; }
/* strip_padding(): text that happens to be clickable, aligned with labels. */
.cr-btn--bare { padding: 0; }
/* A row of bracketed toggles carries its own dividers: separation 0. */
.cr-btn-row { display: flex; flex-wrap: wrap; gap: 0; }

/* -- Glyphs -------------------------------------------------------------- */
/* A glyph takes the ROW'S colour. It is set in the face itself, so it holds
   the line box (THE GLYPH RULE). A double-wide pair (TOGGLE/TAB/MODE) is one
   string of two characters: never split it, never letter-space it. */
.cr-glyph { font-family: var(--cr-font); font-style: normal; letter-spacing: 0; color: inherit; }

/* -- GaugeBar ------------------------------------------------------------ */
/* THE INSTRUMENT FORM's bar: set_value(frac, col, BORDER, 1.0). A 1px BORDER
   frame, a flush VALUE fill, both with the GLOW_SIZE/GLOW_ALPHA halo. Set the
   fraction as --v (0..1). .cr-gauge__tick = a reference mark (set_tick), HERO. */
.cr-gauge {
  --v: 0;
  position: relative;
  display: block;
  height: var(--cr-meter-bar-h);
  border: 1px solid var(--cr-border);
  box-shadow: 0 0 var(--cr-gauge-glow-size) rgb(var(--cr-amber-rgb) / var(--cr-gauge-glow-alpha));
}
.cr-gauge::before {
  content: "";
  position: absolute;
  inset: -1px auto -1px -1px;
  width: calc((100% + 2px) * var(--v));
  background: var(--cr-gauge-fill, var(--cr-value));
  box-shadow: 0 0 var(--cr-gauge-glow-size) rgb(var(--cr-amber-rgb) / var(--cr-gauge-glow-alpha));
}
.cr-gauge--alert { --cr-gauge-fill: var(--cr-alert); }
.cr-gauge--ok { --cr-gauge-fill: var(--cr-ok); }
.cr-gauge__tick {
  position: absolute;
  top: -3px;
  bottom: -3px;
  left: calc(var(--t, 0) * 100% - 1px);
  width: 2px;
  background: var(--cr-hero);
}

/* -- GaugeBar LED ladder -------------------------------------------------- */
/* PROGRESS is a segment ladder, never a smooth fill: ghost unlit segments,
   lit in VALUE, HERO on the leading edge (all HERO when complete). No frame:
   the segments are the instrument. Children are <i>; CorpoRetro.leds() sets
   their classes, or write .on / .edge by hand. */
.cr-leds {
  display: flex;
  gap: var(--cr-led-gap);
  height: var(--cr-meter-bar-h);
}
.cr-leds > i { flex: 1 1 0; background: var(--cr-led-unlit); }
.cr-leds > i.on { background: var(--cr-value); }
.cr-leds > i.edge { background: var(--cr-hero); }

/* -- InstrumentMeter: THE RAIL GRID -------------------------------------- */
/* glyph 22, 10, bar, 10, value 56 (+ an optional dim tail 56). The name lives
   on hover (title=) because the glyph already says it. */
.cr-meter {
  display: grid;
  grid-template-columns: var(--cr-meter-glyph-w) minmax(0, 1fr) var(--cr-meter-value-w);
  column-gap: var(--cr-meter-sep);
  align-items: center;
  font-size: var(--cr-fs-row);
}
.cr-meter--tail { grid-template-columns: var(--cr-meter-glyph-w) minmax(0, 1fr) var(--cr-meter-value-w) var(--cr-meter-tail-w); }
.cr-meter__glyph { color: var(--cr-value); text-align: center; font-size: var(--cr-fs-title); line-height: 1; }
.cr-meter__value { color: var(--cr-value); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cr-meter__tail { color: var(--cr-dim); white-space: nowrap; }

/* -- InstrumentStrip ------------------------------------------------------ */
/* One line of value cells split by 1px LORE rules, 14 tall, 7 apart. */
.cr-strip { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; font-size: var(--cr-fs-row); }
.cr-strip > * + *::before {
  content: "";
  display: inline-block;
  width: 1px;
  height: var(--cr-meter-bar-h);
  background: var(--cr-lore);
  margin-right: 7px;
  vertical-align: middle;
}

/* -- Key / value row (the ROW rung) --------------------------------------- */
.cr-kv { display: flex; justify-content: space-between; gap: var(--cr-btn-pad-x); font-size: var(--cr-fs-row); }
.cr-kv > :first-child { color: var(--cr-label); text-transform: uppercase; }
.cr-kv > :last-child { color: var(--cr-value); font-variant-numeric: tabular-nums; }

/* -- EffectChips ---------------------------------------------------------- */
/* Shape first, then colour: amber ▲ helps, ALERT ▼ hurts, bare amber has no
   direction. OK green NEVER appears on a chip. Only the selection is framed,
   and framing keeps the same margins (nothing moves). */
.cr-chip {
  display: inline-block;
  padding: 0 4px;
  border: 1px solid transparent;
  font-size: var(--cr-fs-chip);
  color: var(--cr-value);
  text-transform: uppercase;
  white-space: nowrap;
}
.cr-chip--up::before { content: "\25B2 "; }
.cr-chip--down { color: var(--cr-alert); }
.cr-chip--down::before { content: "\25BC "; }
.cr-chip--boxed { border-color: currentColor; }
.cr-chip--dim { opacity: 0.58; }

/* -- the blinking terminal cursor (60 BPM) -------------------------------- */
.cr-cursor {
  display: inline-block;
  width: 0.55em;
  height: 1em;
  vertical-align: -0.12em;
  background: var(--cr-value);
  animation: cr-blink 1s steps(1, end) infinite;
}
@keyframes cr-blink { 50% { opacity: 0; } }

/* -- tooltip (TooltipPanel / TooltipLabel) -------------------------------- */
.cr-tip {
  background: var(--cr-tip-bg);
  border: 1px solid var(--cr-border);
  padding: var(--cr-tip-pad);
  font-size: var(--cr-tip-fs);
  color: var(--cr-value);
}

/* -- scrollbars (terminal_theme.tres grabber styleboxes) ------------------- */
.cr-root { scrollbar-color: var(--cr-grab-normal) transparent; scrollbar-width: thin; }
.cr-root ::-webkit-scrollbar { width: 8px; height: 8px; }
.cr-root ::-webkit-scrollbar-track { background: transparent; }
.cr-root ::-webkit-scrollbar-thumb { background: var(--cr-grab-normal); box-shadow: var(--cr-grab-normal-glow); border-radius: 0; }
.cr-root ::-webkit-scrollbar-thumb:hover { background: var(--cr-grab-hover); box-shadow: var(--cr-grab-hover-glow); }
.cr-root ::-webkit-scrollbar-thumb:active { background: var(--cr-grab-pressed); box-shadow: var(--cr-grab-pressed-glow); }

@media (prefers-reduced-motion: reduce) {
  .cr-cursor { animation: none; }
}
