/* Instrument-panel aesthetic: warm concrete ground, off-white panels,
   hi-vis lime live data, deep blue overlays, vermilion overload. */
:root {
  --ground: #34322d;
  --ground-2: #3d3a34;
  --panel: #f5f2ea;
  --panel-2: #eae5d8;
  --ink: #23211c;
  --ink-soft: #5c574c;
  --hair: #c9c2b0;
  --hair-dark: #4b473f;
  --lime: #c8f000;
  --lime-dim: #8fa600;
  --blue: #1f3a93;
  --blue-soft: #4a63b8;
  --vermilion: #e5381a;
  --amber: #e08a1e;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --tap: 44px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--ground);
  color: var(--panel);
  font-family: var(--sans);
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { font-weight: 600; letter-spacing: 0.01em; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
button, input, select { font-family: inherit; font-size: inherit; }
:focus-visible { outline: 3px solid var(--lime); outline-offset: 2px; }

/* --- layout --- */
#app { max-width: 720px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; }
header.top {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px calc(10px + env(safe-area-inset-top)); padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--hair-dark);
}
header.top .title { font-size: 14px; letter-spacing: 0.08em; text-transform: uppercase; color: #d7d2c4; }
header.top .rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #6b6b6b; }
header.top .rec-dot.live { background: var(--vermilion); box-shadow: 0 0 0 0 rgba(229,56,26,.6); animation: pulse 1.4s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(229,56,26,0); } 100% { box-shadow: 0 0 0 0 rgba(229,56,26,0); } }
.grow { flex: 1; }

main { flex: 1; padding: 12px 14px 96px; }
.screen { display: none; }
.screen.active { display: block; }

/* --- panels --- */
.panel { background: var(--panel); color: var(--ink); border-radius: 10px; padding: 14px; margin-bottom: 12px; }
.panel h2 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); }
.panel.dark { background: var(--ground-2); color: var(--panel); border: 1px solid var(--hair-dark); }
.hair { border: 0; border-top: 1px solid var(--hair); margin: 12px 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }

/* --- big readout --- */
.readout { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.readout .big { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 56px; line-height: 1; color: var(--ink); font-weight: 600; }
.readout .big.live { color: #4f6b00; }
.readout .unit { font-family: var(--mono); font-size: 18px; color: var(--ink-soft); }
.readout .sub { font-family: var(--mono); font-size: 13px; color: var(--ink-soft); }
.uncal-badge { display: inline-block; font-size: 11px; letter-spacing: .05em; text-transform: uppercase; background: var(--amber); color: #fff; padding: 2px 7px; border-radius: 5px; }
.cal-badge { background: #2e7d32; }

/* --- band ladder --- */
.ladder { display: flex; flex-direction: column; gap: 4px; }
.ladder .band { display: grid; grid-template-columns: 46px 1fr 60px; align-items: center; gap: 8px; }
.ladder .band .lab { font-family: var(--mono); font-size: 12px; color: var(--ink-soft); text-align: right; }
.ladder .band .bar-wrap { position: relative; height: 20px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.ladder .band .bar { position: absolute; left: 0; top: 0; bottom: 0; background: var(--lime-dim); }
.ladder .band .bar.live { background: var(--lime); }
.ladder .band .bar.over { background: var(--vermilion); }
.ladder .band .val { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 13px; text-align: right; color: var(--ink); }
.ladder .band .peak-tick { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--blue); }

/* --- buttons --- */
button { min-height: var(--tap); border-radius: 9px; border: 1px solid var(--hair-dark); background: var(--ground-2); color: var(--panel); padding: 0 16px; cursor: pointer; }
button.primary { background: var(--lime); color: #1a1e00; border-color: var(--lime); font-weight: 700; }
button.danger { background: var(--vermilion); color: #fff; border-color: var(--vermilion); font-weight: 700; }
button.ghost { background: transparent; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.chip { min-height: 38px; padding: 0 12px; border-radius: 20px; font-size: 13px; }
button.chip.sel { background: var(--lime); color: #1a1e00; border-color: var(--lime); }
input[type=text], input[type=number], select { min-height: var(--tap); border-radius: 8px; border: 1px solid var(--hair); background: #fff; color: var(--ink); padding: 0 12px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-soft); }
.toggle { display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap); }

/* --- bottom controls (one-handed) --- */
.bottombar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: linear-gradient(to top, var(--ground) 70%, transparent);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  display: flex; gap: 10px; max-width: 720px; margin: 0 auto;
}
.bottombar button { flex: 1; }

/* --- tab bar --- */
nav.tabs { position: fixed; bottom: 0; left: 0; right: 0; display: none; }
.navwrap { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: var(--ground-2); border-top: 1px solid var(--hair-dark); padding-bottom: env(safe-area-inset-bottom); }
.navwrap .inner { max-width: 720px; margin: 0 auto; display: flex; }
.navwrap button { flex: 1; background: transparent; border: 0; border-radius: 0; min-height: 54px; color: #b7b2a4; font-size: 12px; letter-spacing: .04em; }
.navwrap button.active { color: var(--lime); box-shadow: inset 0 2px 0 var(--lime); }

/* --- tables --- */
table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 13px; }
th, td { text-align: right; padding: 6px 6px; border-bottom: 1px solid var(--hair); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
.scroll-x { overflow-x: auto; }

/* --- waterfall --- */
.wf-wrap { position: relative; background: #14130f; border-radius: 8px; overflow: hidden; touch-action: none; }
#wf-canvas { display: block; width: 100%; height: 360px; }
.wf-sel { position: absolute; top: 0; bottom: 0; background: rgba(200,240,0,.18); border-left: 2px solid var(--lime); border-right: 2px solid var(--lime); pointer-events: none; }
.legend { display: flex; gap: 6px; align-items: center; font-size: 11px; color: #cfcabb; }
.legend .grad { height: 10px; width: 120px; border-radius: 3px; background: linear-gradient(to right, #14130f, #14213f, #1f3a93, #2e8b57, #c8f000, #e5381a); }

/* --- notes / warnings --- */
.note { font-size: 13px; color: var(--ink-soft); line-height: 1.45; }
.panel.dark .note { color: #c8c3b5; }
.warn { background: #fff4e0; border-left: 4px solid var(--amber); color: #5a4300; padding: 10px 12px; border-radius: 6px; font-size: 13px; }
.warn.bad { background: #ffe6e0; border-left-color: var(--vermilion); color: #6a1a0c; }
.ok { color: #2e7d32; }
.bad { color: var(--vermilion); }
.pill { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--panel-2); color: var(--ink-soft); }
.pill.modelled { background: #ede0ff; color: #5b2a9e; }
.pill.nodata { background: #eee; color: #999; }

.coverage-bar { height: 10px; background: var(--panel-2); border-radius: 5px; overflow: hidden; }
.coverage-bar > i { display: block; height: 100%; background: var(--lime-dim); }

.hint { font-size: 12px; color: #b7b2a4; }
.center { text-align: center; }
.mt { margin-top: 10px; } .mb { margin-bottom: 10px; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media (max-width: 480px) { .readout .big { font-size: 46px; } }
