/* ===========================================================================
   Infra Ambient — styles.

   Two rules this file is built around:

   1. Colour never carries meaning alone. Every health band has a text name next
      to it, every timeline series has a line style as well as a hue, and the
      freshness indicator spells out "STALE" rather than relying on a dot that
      stopped moving.
   2. Nothing here moves fast. The only animation is the heartbeat breath at
      roughly 1 Hz — well under the 3 Hz flash threshold, and an opacity breath
      rather than a blink. `.reduced-motion` removes it entirely.
   =========================================================================== */

:root {
  color-scheme: dark light;

  --bg: #0c0f13;
  --panel: #141920;
  --panel-2: #1b222b;
  --line: #273039;
  --text: #e6ecf2;
  --muted: #9aa8b6;          /* 5.1:1 on --panel */
  --accent: #7fd1c1;
  --grid: #2b3540;
  --tick: #6b7a89;
  --stale-band: rgba(232, 105, 125, 0.13);
  --focus: #8ec8ff;

  --calm: #5ecbb0;
  --drifting: #a9cf6a;
  --unsettled: #e8c23d;
  --degraded: #ef9a4a;
  --critical: #f0808f;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f7f9;
    --panel: #ffffff;
    --panel-2: #eef2f6;
    --line: #d7dee5;
    --text: #141a21;
    --muted: #55626f;        /* 6.4:1 on white */
    --accent: #0f7a69;
    --grid: #ccd5de;
    --tick: #7a8794;
    --stale-band: rgba(183, 28, 54, 0.1);
    --focus: #0b5fa8;

    --calm: #0d7a63;
    --drifting: #4d7a16;
    --unsettled: #8a6500;
    --degraded: #a2500c;
    --critical: #b3243c;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

main { max-width: 1180px; margin: 0 auto; position: relative; z-index: 1; }

/* The ambient field. Drawn at ~12% resolution and blurred here, which is both
   cheaper and softer than painting a real gradient at full size. */
#ambient {
  position: fixed;
  inset: -10%;
  width: 120%;
  height: 120%;
  z-index: 0;
  filter: blur(70px) saturate(130%);
  opacity: 0.4;
  pointer-events: none;
  transition: opacity 1.2s linear;
}
.reduced-motion #ambient { opacity: 0.22; }

/* --------------------------------------------------------------- a11y bits -- */

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip {
  position: absolute;
  left: -9999px;
  top: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  z-index: 10;
}
.skip:focus { left: 16px; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------------------------------------------------------------- chrome ---- */

.head {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 24px;
  align-items: flex-start;
  justify-content: space-between;
  padding: 8px 0 20px;
}

h1 { margin: 0; font-size: 20px; letter-spacing: 0.01em; }
.sub { margin: 4px 0 0; color: var(--muted); max-width: 52ch; }

.transport { text-align: right; }

.transport-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 18px;
}
.field.volume { min-width: 130px; text-align: left; }
.field.volume label { margin-bottom: 3px; font-size: 12.5px; color: var(--muted); }

.audio-state { margin: 8px 0 0; color: var(--muted); font-size: 12.5px; max-width: 38ch; }

button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button:disabled { opacity: 0.55; cursor: default; }

button.primary {
  background: var(--accent);
  color: #06100e;
  border-color: transparent;
  font-weight: 600;
  padding: 11px 22px;
}
@media (prefers-color-scheme: light) { button.primary { color: #fff; } }


input[type="text"] {
  font: inherit;
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
}

.hint { color: var(--muted); font-size: 12px; font-weight: 400; margin: 4px 0 0; }

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

.panel {
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 18px;
  backdrop-filter: blur(6px);
}
.panel h2 { margin: 0 0 4px; font-size: 14px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.panel h3 { margin: 18px 0 6px; font-size: 13px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.panel h3:first-child { margin-top: 0; }
.panel-note { margin: 0 0 14px; color: var(--muted); font-size: 12.5px; max-width: 60ch; }

.columns { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.columns > .panel { margin-bottom: 0; }
.columns + .panel { margin-top: 18px; }

/* ---------------------------------------------------------------- status ---- */

.status { display: flex; flex-wrap: wrap; gap: 10px 28px; align-items: center; }

.freshness {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  padding: 7px 14px 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
}
.freshness .pulse {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--calm);
  flex: none;
}
/* ~1.15 s cycle: a breath, not a blink, and far below any flash threshold. */
.freshness[data-state="fresh"] .pulse { animation: breath 1.15s ease-in-out infinite; }
.freshness[data-state="stale"] {
  background: color-mix(in srgb, var(--critical) 18%, var(--panel-2));
  border-color: var(--critical);
  color: var(--critical);
}
.freshness[data-state="stale"] .pulse {
  animation: none;
  background: transparent;
  border: 2px solid currentColor;   /* hollow: a shape change, not just a colour */
}

@keyframes breath {
  0%, 100% { opacity: 0.35; transform: scale(0.82); }
  50%      { opacity: 1;    transform: scale(1.12); }
}
.reduced-motion .freshness[data-state="fresh"] .pulse { animation: none; opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .freshness[data-state="fresh"] .pulse { animation: none; opacity: 1; transform: none; }
}

.band-line { margin: 0; color: var(--muted); }
.band-line strong { color: var(--text); }
#band-text[data-band="calm"]      { color: var(--calm); }
#band-text[data-band="drifting"]  { color: var(--drifting); }
#band-text[data-band="unsettled"] { color: var(--unsettled); }
#band-text[data-band="degraded"]  { color: var(--degraded); }
#band-text[data-band="critical"]  { color: var(--critical); }

/* ---------------------------------------------------------------- inputs ---- */

input[type="range"] { width: 100%; accent-color: var(--accent); }

.field.check { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.field.check label { margin: 0; font-weight: 500; }
.field.check .hint { flex-basis: 100%; margin: 2px 0 0; max-width: 54ch; }
.field.check input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--accent); }

.stale { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }

/* --------------------------------------------------------------- readout ---- */

.readout-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }

.bars { display: grid; gap: 14px; }
.bar-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.bar-label { font-weight: 500; }
.bar-val { display: flex; gap: 10px; align-items: baseline; font-variant-numeric: tabular-nums; }
.bar-smoothed { font-weight: 600; }

.bar-track {
  position: relative;
  height: 9px;
  margin-top: 5px;
  background: var(--panel-2);
  border-radius: 999px;
  overflow: hidden;
}
.bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: var(--c);
  border-radius: 999px;
  transition: width 0.18s linear;
}
.bar-note { margin: 4px 0 0; color: var(--muted); font-size: 11.5px; }

.derived { margin: 0; }
.derived .row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 5px 0;
  border-bottom: 1px solid var(--line);
}
.derived .row:last-child { border-bottom: 0; }
.derived dt { color: var(--muted); }
.derived dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; }

.scale { display: flex; gap: 4px; margin-top: 4px; }
.scale .dot { flex: 1; text-align: center; }
.scale .dot-mark {
  display: block;
  height: 22px;
  border-radius: 5px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.scale .dot.on .dot-mark { background: var(--accent); border-color: var(--accent); }
.scale .dot.root .dot-mark {
  background: var(--text);
  border-color: var(--text);
  box-shadow: inset 0 0 0 2px var(--panel);
}
.scale .dot-name { font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.scale .dot.on .dot-name { color: var(--text); }

#timeline {
  display: block;
  width: 100%;
  height: 190px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.legend { display: flex; flex-wrap: wrap; gap: 8px 20px; list-style: none; margin: 10px 0 0; padding: 0; color: var(--muted); font-size: 12.5px; }
.legend li { display: flex; align-items: center; gap: 7px; }
.legend .swatch { width: 18px; height: 3px; border-radius: 2px; background: var(--dash); flex: none; }

.axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 11.5px; margin: 6px 2px 0; }


/* ------------------------------------------------------------ responsive ---- */

@media (max-width: 860px) {
  .columns, .readout-grid { grid-template-columns: 1fr; }
  .columns > .panel { margin-bottom: 18px; }
  .head { flex-direction: column; }
  .transport { text-align: left; }
  .transport-row { justify-content: flex-start; flex-wrap: wrap; }
  .audio-state { max-width: none; }
}

/* ------------------------------------------------------------ source mode --- */



/* Only rendered when a poll has failed, so it is always the error styling. */
.source-status {
  flex-basis: 100%;
  margin: 0;
  padding: 8px 11px;
  border-radius: 8px;
  font-size: 12.5px;
  border: 1px solid var(--critical);
  color: var(--critical);
  background: color-mix(in srgb, var(--critical) 12%, var(--panel-2));
}
