/* Decremental — clinical dark. No external fonts or assets: everything
   here has to render identically in a browser tab and in an offline
   Electron window. */

:root {
  /* ============================================================
     IDENTITY — "Lab Glass, warm dark", locked by Design 8/27.
     Values below the LOCKED line are Design's, verbatim. Anything
     under DERIVED is computed from them by Code, with the reason
     stated; none of it overrides a locked value.
     ============================================================ */

  /* ---- LOCKED ---- */
  --bg: oklch(17% 0.02 75);
  --bg-elev: oklch(22% 0.024 75);
  --fg: oklch(92% 0.012 75);
  --fg-muted: oklch(64% 0.018 75);
  --border: oklch(32% 0.026 75);
  --accent-cold: oklch(77% 0.13 230);
  /* NOTE: oklch(78% 0.16 48) is outside sRGB — max chroma at that
     lightness and hue is 0.140, so a browser clips it and renders
     something Design did not pick. Left as specified rather than
     silently corrected; see tools/contrast.mjs. */
  --accent-warm: oklch(78% 0.16 48);
  --danger: oklch(68% 0.18 25);
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  /* ---- DERIVED ---- */

  /* Cure progress, 0-1, driven from JS. The accent shifts cold to warm
     as it rises, so the palette itself tracks how far the cure has
     come. Set per frame; every breach nudges it warmer. */
  --cure: 0;
  --accent: var(--accent-cold);

  /* Control boundaries only. --border is 1.50:1 against --bg, which is
     right for decorative rules but leaves a button's edge below the
     3:1 WCAG 1.4.11 needs for an identifiable control. L=49% is the
     minimum at Design's chroma and hue that reaches 3:1. */
  --border-interactive: oklch(49% 0.026 75);

  --surface-2: color-mix(in oklch, var(--bg-elev), var(--border) 45%);
  --hint: color-mix(in oklch, var(--fg-muted), var(--bg) 55%);
  --accent-soft: color-mix(in oklch, var(--accent), transparent 86%);
  --danger-soft: color-mix(in oklch, var(--danger), transparent 55%);

  /* Type roles: mono is reserved for numbers and data, sans for copy. */
  --font-ui: var(--font-sans);
  --font-num: var(--font-mono);

  --shake: 0px;
}

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

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 14px;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 20px 16px 40px;
  overflow-x: hidden;
  -webkit-user-select: none;
  user-select: none;
}

#shell {
  width: 100%;
  max-width: 780px;
  transform: translate(var(--shake), 0);
}

/* --- header ---------------------------------------------------- */

header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
  margin-bottom: 34px;
}
h1 {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.38em;
  color: var(--fg);
}
header span { font-size: 11px; color: var(--fg-muted); letter-spacing: 0.1em; }

/* --- the number ------------------------------------------------- */

#titer { text-align: center; margin-bottom: 18px; }

#titer .label {
  font-size: 10px;
  letter-spacing: 0.32em;
  color: var(--fg-muted);
  margin-bottom: 12px;
}

#readout {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.18em;
  color: var(--accent);
  transition: color 700ms ease;
  line-height: 1;
}

#mantissa {
  font-family: var(--font-num);
  font-size: clamp(2.8rem, 11vw, 6rem);
  font-weight: 300;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  /* Fixed width: 999 -> 99.9 must not shove the unit around. */
  min-width: 3.6ch;
  text-align: right;
}

#symbol {
  font-family: var(--font-num);
  font-size: clamp(1.4rem, 5.5vw, 3rem);
  font-weight: 400;
  min-width: 1.4ch;
  text-align: left;
}
#symbol.beyond { font-size: clamp(1rem, 3.4vw, 1.9rem); }

#units { font-size: 11px; color: var(--fg-muted); letter-spacing: 0.28em; margin-top: 14px; }

/* The crossing. Everything above ticks smoothly; this is the only
   thing in the game that punches. */
#readout.breach { animation: breach 900ms cubic-bezier(.16,1,.3,1); }
@keyframes breach {
  0%   { transform: scale(1.16); filter: brightness(2.4); letter-spacing: 0.06em; }
  55%  { transform: scale(0.985); filter: brightness(1.15); }
  100% { transform: scale(1); filter: brightness(1); letter-spacing: -0.02em; }
}

/* --- bracket progress ------------------------------------------- */

#bracket { max-width: 460px; margin: 0 auto 18px; }
#bracket .row {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  letter-spacing: 0.2em;
  color: var(--fg-muted);
  margin-bottom: 7px;
}
#bracket .row b { color: var(--accent); font-weight: 500; transition: color 700ms ease; }
#track {
  height: 3px;
  background: var(--surface-2);
  overflow: hidden;
}
#fill {
  height: 100%;
  width: 100%;
  background: var(--accent);
  transform-origin: left;
  transition: background 700ms ease;
}

/* --- panels ------------------------------------------------------ */

#body {
  display: grid;
  grid-template-columns: 1fr 1.25fr;
  gap: 14px;
  margin-bottom: 20px;
}
@media (max-width: 560px) { #body { grid-template-columns: 1fr; } }

.panel { background: var(--bg-elev); border: 1px solid var(--border); padding: 15px; }

.stat { display: flex; justify-content: space-between; align-items: baseline; padding: 7px 0; }
.stat + .stat { border-top: 1px solid var(--border); }
.stat .k { font-size: 10px; letter-spacing: 0.18em; color: var(--fg-muted); }
.stat .v { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-size: 15px; }
.stat .v small { font-size: 10px; color: var(--fg-muted); letter-spacing: 0.1em; }

/* --- actions ----------------------------------------------------- */

button {
  font: inherit;
  color: var(--fg);
  background: var(--surface-2);
  border: 1px solid var(--border-interactive);
  width: 100%;
  padding: 13px;
  cursor: pointer;
  letter-spacing: 0.18em;
  font-size: 11px;
  transition: background 120ms, border-color 120ms, transform 60ms;
}
button:hover:not(:disabled) { border-color: var(--fg-muted); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

#surge {
  border-color: var(--accent-cold);
  color: var(--accent-cold);
  position: relative;
}
#surge.held { background: rgba(255, 179, 71, 0.14); transform: translateY(1px); }

#surge-track { height: 3px; background: var(--surface-2); margin: 9px 0 4px; }
#surge-fill { height: 100%; width: 0%; background: var(--accent-cold); }

.hint { font-size: 10px; color: var(--fg-muted); letter-spacing: 0.08em; text-align: center; }

#culture { margin-top: 18px; }
#culture-meta {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--fg-muted);
  margin-top: 7px;
  letter-spacing: 0.08em;
}

/* Floating tick that confirms a surge landed. */
.pip {
  position: absolute;
  left: 50%;
  top: 4px;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--accent-cold);
  pointer-events: none;
  animation: pip 620ms ease-out forwards;
  font-variant-numeric: tabular-nums;
}
@keyframes pip {
  from { opacity: 1; transform: translate(-50%, 0); }
  to   { opacity: 0; transform: translate(-50%, -26px); }
}

/* --- log --------------------------------------------------------- */

#log {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  height: 132px;
  overflow-y: auto;
  padding: 11px 14px;
  font-size: 11px;
  line-height: 1.85;
  color: var(--fg-muted);
}
#log div { display: flex; gap: 10px; }
#log .t { color: var(--hint); font-family: var(--font-num); font-variant-numeric: tabular-nums; flex: none; }
#log .big { color: var(--accent); }

footer { margin-top: 16px; display: flex; justify-content: space-between; align-items: center; }
#reset { width: auto; padding: 7px 14px; font-size: 10px; color: var(--fg-muted); }

/* --- breach overlays --------------------------------------------- */

#flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 38%, var(--accent-soft), transparent 62%);
  opacity: 0;
}
#flash.go { animation: flash 820ms ease-out; }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }

#banner {
  position: fixed;
  left: 0;
  right: 0;
  top: 22%;
  text-align: center;
  pointer-events: none;
  opacity: 0;
}
#banner .k { font-size: 10px; letter-spacing: 0.5em; color: var(--fg-muted); }
#banner .n {
  font-size: clamp(1.5rem, 6vw, 2.6rem);
  letter-spacing: 0.2em;
  color: var(--accent);
  margin-top: 6px;
  text-transform: uppercase;
}
#banner.go { animation: banner 1700ms ease-out; }
@keyframes banner {
  0%   { opacity: 0; transform: translateY(14px); }
  12%  { opacity: 1; transform: translateY(0); }
  74%  { opacity: 1; }
  100% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  #readout.breach, #banner.go, #flash.go, .pip { animation-duration: 1ms; }
  #banner.go { animation: banner-still 1700ms steps(1, end); }
  @keyframes banner-still { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }
  #shell { transform: none; }
}


/* ================= the swarm field ================= */

#field {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 7;
  min-height: 210px;
  background: radial-gradient(ellipse at 50% 50%, var(--bg-elev) 0%, var(--bg) 72%);
  border: 1px solid var(--border);
  margin-bottom: 18px;
  overflow: hidden;
  cursor: none;
  touch-action: none;
  outline: none;
}
#field:focus-visible { border-color: var(--border-interactive); }

#field-hint {
  position: absolute;
  left: 0; right: 0; bottom: 12px;
  text-align: center;
  font-size: 10px;
  letter-spacing: 0.3em;
  color: var(--hint);
  pointer-events: none;
  transition: opacity 400ms;
}
#field.engaged #field-hint { opacity: 0; }

/* Damage read on the whole field, so a failing cursor is felt without
   having to watch a bar. */
#vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 50%, transparent 42%, var(--danger-soft) 100%);
  opacity: 0;
  transition: opacity 500ms ease;
}

/* --- viruses ------------------------------------------------------ */

.virus {
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: none;
  transition: opacity 220ms, filter 220ms;
}
.virus .body {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid currentColor;
  background: currentColor;
  opacity: 0.14;
}
/* Remaining hp, drawn as the ring closing. */
.virus .ring {
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  background: conic-gradient(currentColor var(--hp), transparent 0);
  -webkit-mask: radial-gradient(circle, transparent 62%, #000 64%);
  mask: radial-gradient(circle, transparent 62%, #000 64%);
  opacity: 0.85;
}

/* Skill points — a linear STRIP, not a ring or an orbit. The strip is
   what makes "3 of 6" countable at a glance, which is the entire point:
   currency buys removal one point at a time, and a player who cannot
   count them cannot see what they bought. Unlit pips stay in place as
   the track, so the original total remains readable. */
.virus .pips {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 2px;
  pointer-events: none;
}
.virus .pips i {
  width: 3px;
  height: 7px;
  background: currentColor;
  opacity: 0.16;
  transition: opacity 260ms ease;
}
.virus .pips i.on { opacity: 1; }

/* The spend itself: a mark that drifts off where the pip went dark.
   Never a gradient fade — the point is that something was removed. */
.pip-drift {
  position: absolute;
  width: 3px;
  height: 7px;
  background: var(--accent-warm);
  pointer-events: none;
  animation: pip-drift 700ms ease-out forwards;
}
@keyframes pip-drift {
  from { opacity: 1; transform: translate(0, 0); }
  to   { opacity: 0; transform: translate(0, -18px); }
}

.virus.dead { opacity: 0; filter: brightness(3); }
.virus.focused .body { opacity: 0.3; }
.virus.focused .ring { opacity: 1; }

/* --- the cursor: a core dot ---------------------------------------- */
/*
   Integrity lives in the dot's size and brightness — no bar, no health
   ring. Two reasons, one of them Design's and one mine, arrived at
   separately: it leaves any surrounding ring free to mean something
   else later, and cracks or chips would imply permanent damage when
   integrity in fact restores in full at every breach. A dot that dims
   and re-brightens reads a 20-40s sawtooth honestly.
*/
#reticle {
  position: absolute;
  width: 0;
  height: 0;
  pointer-events: none;
}
#reticle i {
  position: absolute;
  border-radius: 50%;
  width: var(--dot, 10px);
  height: var(--dot, 10px);
  margin: calc(var(--dot, 10px) / -2) 0 0 calc(var(--dot, 10px) / -2);
  background: var(--cursor-color, var(--accent));
  opacity: var(--dot-opacity, 1);
  box-shadow: 0 0 calc(var(--dot, 10px) * 1.1) var(--cursor-color, var(--accent));
  transition: background 300ms ease;
}
/* The breach restores the cursor; it blooms outward to say so. */
#reticle::after {
  content: '';
  position: absolute;
  width: 120px;
  height: 120px;
  margin: -60px 0 0 -60px;
  border-radius: 50%;
  border: 1px solid var(--accent);
  opacity: 0;
}
#reticle.bloom::after { animation: bloom 900ms cubic-bezier(.16,1,.3,1); }
@keyframes bloom {
  from { opacity: 0.85; transform: scale(0.06); }
  to   { opacity: 0; transform: scale(1); }
}

/* --- directional feedback ------------------------------------------ */
/*
   Application and retaliation must never be confusable. They differ on
   BOTH axes: antibody leaves the cursor outbound in cold accent,
   retaliation arrives inbound in danger red.
*/
.shot, .bite {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
}
.shot {
  width: 4px; height: 4px;
  margin: -2px 0 0 -2px;
  background: var(--accent-cold);
  animation: shot 240ms linear forwards;
}
@keyframes shot {
  from { opacity: 0.95; transform: translate(0, 0); }
  to   { opacity: 0; transform: translate(var(--dx), var(--dy)); }
}
.bite {
  width: 5px; height: 5px;
  margin: -2.5px 0 0 -2.5px;
  background: var(--danger);
  animation: bite 360ms ease-in forwards;
}
@keyframes bite {
  0%   { opacity: 0; transform: translate(var(--dx), var(--dy)); }
  30%  { opacity: 1; }
  100% { opacity: 0; transform: translate(0, 0); }
}

/* --- integrity meter ---------------------------------------------- */

#integrity-track { height: 3px; background: var(--surface-2); margin: 2px 0 4px; }
#integrity-fill { height: 100%; width: 100%; transform-origin: left; }

.meta {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--fg-muted);
  margin-top: 7px;
  letter-spacing: 0.08em;
}

#suppress { margin-top: 18px; color: var(--accent-warm); }

@media (prefers-reduced-motion: reduce) {
  .virus, .bite, .shot, .pip-drift, #vignette, #reticle.bloom::after {
    transition: none;
    animation-duration: 1ms;
  }
}
