/* ============================================================================
   MEDBAY-SIM — TACTICAL TELEMETRY / CRT TERMINAL
   Jeden archetyp: ciemny terminal telemetryczny. Monospace dominuje wszędzie,
   akcent bursztynowy (dane / stan aktywny), czerwień WYŁĄCZNIE dla wartości
   krytycznych (klasa .crit: p(LOCL) > 20 %, nieobsłużone > 0, E[zgonów] >
   0,05), zieleń fosforowa tylko dla JEDNEGO elementu (wskaźnik SYS),
   geometria 90°, przegrody 1px.
   ========================================================================== */

@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 100 800; /* font zmienny */
  font-display: swap;
  src: url("./fonts/JetBrainsMono-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url("./fonts/JetBrainsMono-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --bg: #0C0D0E;         /* wygaszony CRT — nie czysta czerń */
  --bg2: #131517;        /* pola formularzy */
  --line: #26292D;       /* przegrody 1px */
  --text: #EAEAEA;       /* biały fosfor */
  --muted: #8F979F;
  --accent: #E8A33D;     /* bursztyn — domyślny kolor danych i stanu aktywnego */
  --crit: #FF2A2A;       /* czerwień — WYŁĄCZNIE wartości krytyczne (.crit) */
  --green: #4AF626;      /* fosfor terminalowy — WYŁĄCZNIE wskaźnik SYS */
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; border-radius: 0 !important; }

html { color-scheme: dark; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  padding-bottom: 44px; /* miejsce na stałą stopkę */
}

/* skanlinie CRT — bardzo subtelne, nie wpływają na kontrast */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, transparent, transparent 3px, rgba(0, 0, 0, 0.10) 3px, rgba(0, 0, 0, 0.10) 4px);
  z-index: 9;
}

/* ---------------------------------------------------------------- nagłówek */
.masthead { padding: 20px 24px 14px; border-bottom: 1px solid var(--line); }
.masthead-row { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 16px; }
.masthead h1 {
  font-size: clamp(2.2rem, 6vw, 4.5rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 0.9;
  text-transform: uppercase;
}
.masthead .sub {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  margin-top: 10px;
}
.sys { font-size: 12px; letter-spacing: 0.08em; color: var(--muted); white-space: nowrap; }
.sys span { font-weight: 700; }
.sys span::before { content: ">> "; }
.sys span[data-state="ready"] { color: var(--green); }
.sys span[data-state="busy"], .sys span[data-state="init"] { color: var(--accent); }

/* ---------------------------------------------------------------- siatka */
.grid {
  display: grid;
  grid-template-columns: 348px 1fr;
  max-width: 1320px;
  margin: 0 auto;
}
.controls {
  border-right: 1px solid var(--line);
  align-self: start;
  position: sticky;
  top: 0;
  max-height: calc(100vh - 44px);
  overflow-y: auto;
}
.results { min-width: 0; }

section { position: relative; padding: 16px 24px 20px; border-bottom: 1px solid var(--line); }
/* krzyżyki rejestracyjne na przecięciach siatki */
.results section::before {
  content: "+";
  position: absolute;
  top: -8px;
  left: -4px;
  color: var(--line);
  font-size: 12px;
  line-height: 1;
}

h2 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text);
  margin-bottom: 14px;
}
h2::before { content: "[ "; color: var(--muted); font-weight: 400; }
h2::after { content: " ]"; color: var(--muted); font-weight: 400; }
.unit { font-weight: 400; text-transform: none; letter-spacing: 0.02em; color: var(--muted); }
.hint { color: var(--muted); font-size: 11px; margin-top: 4px; letter-spacing: 0.03em; }

/* ---------------------------------------------------------------- parametry */
.param { margin-bottom: 14px; }
.param label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}
.param-row { display: flex; gap: 10px; align-items: center; }
.param-row input[type="range"] { flex: 1; }
#age-param[data-enabled="false"] { opacity: 0.4; }

input[type="number"] {
  width: 92px;
  background: var(--bg2);
  border: 1px solid var(--line);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  padding: 4px 6px;
  text-align: right;
}
#seed { width: 140px; }
input:disabled { cursor: not-allowed; }

/* suwaki — minimalne, natywne */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 20px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 2px; background: var(--line); }
input[type="range"]::-moz-range-track { height: 2px; background: var(--line); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  margin-top: -5px;
  background: var(--accent);
  border: none;
}
input[type="range"]::-moz-range-thumb { width: 12px; height: 12px; background: var(--accent); border: none; }
input[type="range"]:disabled::-webkit-slider-thumb { background: var(--muted); }
input[type="range"]:disabled::-moz-range-thumb { background: var(--muted); }

button {
  background: var(--bg2);
  border: 1px solid var(--line);
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 6px 10px;
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

:is(button, input, a):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.preset-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }

/* ---------------------------------------------------------------- model rozszerzony */
.ext-toggle {
  display: flex;
  gap: 10px;
  align-items: baseline;
  cursor: pointer;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
}
.ext-toggle span { color: var(--muted); }
.ext-toggle input:checked ~ span { color: var(--text); }

input[type="checkbox"] {
  appearance: none;
  width: 14px; height: 14px;
  flex: 0 0 auto;
  border: 1px solid var(--muted);
  cursor: pointer;
  display: inline-grid;
  place-content: center;
  vertical-align: -2px;
}
input[type="checkbox"]:checked { border-color: var(--accent); background: var(--accent); }
input[type="checkbox"]:checked::before { content: ""; width: 6px; height: 6px; background: var(--bg); }

/* ---------------------------------------------------------------- wyposażenie */
.caps { list-style: none; }
.caps li { border-top: 1px solid var(--line); }
.caps li:last-child { border-bottom: 1px solid var(--line); }
.caps label {
  display: grid;
  grid-template-columns: 16px 64px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 6px 2px;
  cursor: pointer;
  font-size: 11px;
}
.caps .cap-id { font-weight: 700; letter-spacing: 0.04em; }
.caps input:checked ~ .cap-id { color: var(--accent); }
.caps .cap-label { color: var(--muted); }
.caps .cap-note { font-style: normal; opacity: 0.75; }
.caps .cap-mass { color: var(--muted); }

.mass-total { margin-top: 12px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; }
.mass-total output { color: var(--accent); font-weight: 700; }

.export-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- wyniki */
.progress { height: 2px; background: transparent; }
.progress-bar {
  height: 100%;
  width: 100%;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: 0 0;
  transition: transform 120ms linear;
}
.progress[data-active="false"] .progress-bar { opacity: 0; }

.readouts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}
.readout-label {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 6px;
}
.readout-label::before { content: ">> "; }
.readout-value {
  font-size: clamp(28px, 3.5vw, 42px);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--accent);
}
.readout-ci {
  display: block;
  margin-top: 2px;
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--muted);
}
/* jedna reguła krytyczności — czerwień tylko tu */
.readout-value.crit, td.crit { color: var(--crit); }
.ext-info {
  grid-column: 1 / -1;
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.03em;
}

/* ---------------------------------------------------------------- wykresy */
/* na wąskich ekranach wykres przewija się poziomo zamiast kurczyć tekst */
.chart { position: relative; overflow-x: auto; }

/* tooltip krzywej masa–ryzyko (hover/tap, bez bibliotek) */
.tip {
  position: absolute;
  z-index: 5;
  background: var(--bg2);
  border: 1px solid var(--muted);
  padding: 6px 8px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text);
  pointer-events: none;
  white-space: nowrap;
}
.chart svg { display: block; width: 100%; min-width: 560px; height: auto; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.chart text { font-family: var(--mono); font-size: 11px; fill: var(--muted); }
.chart .axis { stroke: var(--line); }
.chart .gridline { stroke: var(--line); stroke-dasharray: 2 4; }
.chart .data { stroke: var(--accent); fill: none; stroke-width: 1.5; }
.chart .dot { fill: var(--accent); }
.chart .dot-label { fill: var(--muted); font-size: 10px; }
.chart .current { fill: none; stroke: var(--accent); stroke-width: 1.5; }
.chart .crosshair { stroke: var(--accent); stroke-dasharray: 2 3; opacity: 0.5; }
.chart .bar { fill: var(--accent); }
.chart .bar.ghost { fill: none; stroke: var(--accent); stroke-width: 1; }
.chart .bar-val { fill: var(--text); }
.chart-legend { color: var(--muted); font-size: 11px; margin-top: 6px; letter-spacing: 0.03em; }
.chart-legend b { color: var(--accent); font-weight: 400; }

/* ---------------------------------------------------------------- tabela */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 12px; }
th, td { padding: 5px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th {
  font-weight: 400;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.06em;
}
td.num, th.num { text-align: right; }
td.need { font-size: 11px; color: var(--muted); }
td.need .miss { color: var(--accent); }
tr[data-covered="false"] td:first-child { color: var(--muted); }

/* ---------------------------------------------------------------- stopka */
.footer {
  position: fixed;
  inset: auto 0 0 0;
  height: 44px;
  background: var(--bg);
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--muted);
  z-index: 10;
}

/* ---------------------------------------------------------------- mobile */
@media (max-width: 880px) {
  .grid { grid-template-columns: 1fr; }
  .controls { position: static; max-height: none; border-right: none; }
  .readouts { grid-template-columns: 1fr; gap: 14px; }
  .footer { position: static; height: auto; padding: 10px 24px; flex-wrap: wrap; }
  body { padding-bottom: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .progress-bar { transition: none; }
}
