:root {
  --bg: #0b0d10; --panel: #15191e; --text: #f2f4f6; --dim: #8a949e;
  --ok: #3ddc84; --warn: #ffb020; --bad: #ff5a5a; --accent: #4aa8ff;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
main { min-height: 100%; display: flex; flex-direction: column; gap: 16px;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(76px + env(safe-area-inset-bottom)); }
.view { flex: 1; display: flex; flex-direction: column; gap: 16px; min-height: 0; }
.view[hidden] { display: none; }
.bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.pill { padding: 6px 12px; border-radius: 999px; background: var(--panel); color: var(--dim); font-size: 15px; }
[data-state="live"] .pill { color: var(--ok); }
[data-state="stale"] .pill, [data-state="connecting"] .pill { color: var(--warn); }
button { font: inherit; font-size: 17px; font-weight: 600; padding: 12px 20px; border: 0; border-radius: 12px;
  background: var(--accent); color: #001428; min-height: 48px; }
button:disabled { opacity: .5; }
[data-state="live"] #connect, [data-state="stale"] #connect { background: var(--panel); color: var(--dim); }
.speeds { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 16px; }
.main-speed { text-align: center; }
.label { color: var(--dim); font-size: 16px; text-transform: uppercase; letter-spacing: .08em; }
.big { font-size: clamp(110px, 34vw, 240px); font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.mid { font-size: clamp(44px, 13vw, 88px); font-weight: 650; font-variant-numeric: tabular-nums; }
.unit { color: var(--dim); font-size: 18px; margin-left: 6px; }
.sub-speeds { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.cell { background: var(--panel); border-radius: 16px; padding: 14px; text-align: center; }
.status { background: var(--panel); border-radius: 16px; padding: 6px 14px; }
.row { display: flex; align-items: center; gap: 10px; padding: 10px 0; font-size: 17px; }
.row + .row { border-top: 1px solid #222830; }
.k { color: var(--dim); width: 76px; }
.v { flex: 1; text-align: right; font-variant-numeric: tabular-nums; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #39424c; flex: none; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }
.note { color: var(--dim); font-size: 15px; margin: 0; min-height: 1.4em; text-align: center; }
[data-state="stale"] .big, [data-state="stale"] .mid, [data-state="stale"] .evalue { color: var(--dim); }
.engine { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.ecell { background: var(--panel); border-radius: 12px; padding: 8px 4px; text-align: center; min-width: 0; }
.elabel { color: var(--dim); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.evalue { font-size: clamp(18px, 5.6vw, 30px); font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.enote { grid-column: 1 / -1; text-align: center; margin: 0; }
.enote:empty { display: none; }
.small.top { margin: 0 0 6px; }
.pids { font-size: 15px; }
.pid { display: flex; gap: 10px; padding: 5px 0; color: #c9d0d6; }
.pid + .pid { border-top: 1px solid #222830; }
.pid b { font-weight: 600; color: var(--dim); width: 24px; flex: none; font-variant-numeric: tabular-nums; }
.pid.read { color: var(--text); }
.pid.read b { color: var(--ok); }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--panel); border-top: 1px solid #222830; padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
.tab { background: none; color: var(--dim); border-radius: 0; min-height: 60px; font-size: 16px; }
.tab.active { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }
.card { background: var(--panel); border-radius: 16px; padding: 14px; }
.card h2 { margin: 0 0 8px; font-size: 14px; color: var(--dim); text-transform: uppercase; letter-spacing: .08em; font-weight: 600; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; font-size: 16px; }
.kv + .kv { border-top: 1px solid #222830; }
.kv span { color: var(--dim); flex: none; }
.kv b { font-weight: 500; text-align: right; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.meter { height: 12px; border-radius: 6px; background: #222830; overflow: hidden; margin: 4px 0 8px; }
.meter div { height: 100%; width: 0; background: var(--ok); transition: width .3s; }
.meter div.full { background: var(--bad); }
.small { color: var(--dim); font-size: 13px; margin: 8px 0 0; }
button.secondary { background: var(--panel); color: var(--text); }
.rel + .rel { border-top: 1px solid #222830; margin-top: 10px; padding-top: 10px; }
.relhead { display: flex; justify-content: space-between; align-items: baseline; }
.relhead span { color: var(--dim); font-size: 14px; }
.rel.current .relhead b { color: var(--ok); }
.rel ul { margin: 6px 0 0; padding-left: 20px; color: #c9d0d6; font-size: 15px; line-height: 1.4; }
@media (orientation: landscape) and (max-height: 500px) {
  #liveView { display: grid; grid-template-columns: 1.4fr 1fr; grid-template-rows: auto auto 1fr; column-gap: 16px; row-gap: 10px; }
  #liveView .speeds { grid-row: 1 / 4; }
  #liveView .engine, #liveView .status { grid-column: 2; }
  #liveView .note { grid-column: 1 / -1; }
  .evalue { font-size: clamp(14px, 2.4vw, 20px); }
  .row { padding: 6px 0; }
  .mid { font-size: clamp(32px, 10vh, 60px); }
  .cell { padding: 8px; }
  .tab { min-height: 44px; }
  main { padding-bottom: calc(56px + env(safe-area-inset-bottom)); }
  .big { font-size: clamp(90px, 26vh, 200px); }
  .status { align-self: center; }
}
.card button { width: 100%; margin-top: 10px; }

/* ---- Trends tab ---- */
#tBody { display: flex; flex-direction: column; gap: 16px; }
#tBody[hidden] { display: none; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--panel); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { background: none; color: var(--dim); min-height: 40px; padding: 8px; border-radius: 9px; font-size: 16px; }
.seg button.active { background: #26303a; color: var(--text); }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.tile { min-width: 0; }
.tlabel { color: var(--dim); font-size: 13px; }
.tvalue { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tdelta { color: var(--dim); font-size: 13px; min-height: 1.2em; }
.chead { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.chead select { font: inherit; font-size: 16px; font-weight: 600; color: var(--text); background: #222830; border: 0;
  border-radius: 10px; padding: 8px 10px; min-height: 40px; max-width: 100%; }
.chart { position: relative; width: 100%; touch-action: pan-y; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .grid { stroke: #262d35; stroke-width: 1; }
.chart .axis { fill: var(--dim); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--accent); opacity: .75; }
.chart .bar.now { opacity: 1; }
.chart .bar.hover { opacity: 1; fill: #8cc8ff; }
.tip { position: absolute; top: 0; transform: translate(-50%, -100%); background: #26303a; color: var(--text);
  font-size: 13px; padding: 5px 8px; border-radius: 8px; white-space: nowrap; pointer-events: none; z-index: 2; }
.tip[hidden] { display: none; }
.window { color: var(--dim); font-size: 14px; margin: 0; text-align: center; }
.band { display: grid; grid-template-columns: 106px 1fr 72px; align-items: center; gap: 10px; padding: 5px 0; font-size: 15px; }
.blabel { color: var(--dim); font-variant-numeric: tabular-nums; }
.btrack { height: 10px; }
.bfill { display: block; height: 100%; min-width: 2px; background: var(--accent); border-radius: 0 4px 4px 0; }
.bval { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.blabel { white-space: nowrap; }
#tDrives .more { width: 100%; margin-top: 8px; background: #222830; }
.drive { padding: 9px 0; }
.drive + .drive { border-top: 1px solid #222830; }
.dtop { display: flex; justify-content: space-between; gap: 10px; font-size: 16px; }
.dtop b { font-weight: 600; }
.dtop span { font-variant-numeric: tabular-nums; white-space: nowrap; }
.dsub { color: var(--dim); font-size: 14px; margin-top: 2px; }
