:root {
  --bg: #0b0f17; --panel: rgba(16, 21, 32, .92); --panel2: #151b28; --line: rgba(255, 255, 255, .09);
  --text: #e6ebf5; --muted: #8f9bb3; --accent: #5cc8ff; --warn: #ffb547; --ok: #5fd38a; --bad: #ff6b6b;
  --tabs-h: calc(56px + env(safe-area-inset-bottom));
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; overscroll-behavior: none; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); } .small { font-size: 12px; }
[hidden] { display: none !important; }

.view { position: fixed; inset: 0 0 var(--tabs-h) 0; display: none; }
.view.active { display: block; }
#v-diag, #v-runs { overflow-y: auto; -webkit-overflow-scrolling: touch; padding-top: env(safe-area-inset-top); }

#offline { position: fixed; z-index: 50; top: env(safe-area-inset-top); left: 50%; transform: translateX(-50%); background: var(--warn); color: #000; font-size: 12px; padding: 3px 10px; border-radius: 0 0 8px 8px; }

/* bottom tabs */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; height: var(--tabs-h); padding-bottom: env(safe-area-inset-bottom); display: flex; background: #0d121c; border-top: 1px solid var(--line); z-index: 20; }
.tabs button { flex: 1; background: none; border: 0; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; }
.tabs button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.on { color: var(--accent); }

/* map */
#map { position: absolute; inset: 0; background: #0e1420; }
.maplibregl-ctrl-attrib { display: none; }
.map-top { position: absolute; top: calc(env(safe-area-inset-top) + 8px); left: 8px; right: 8px; display: flex; flex-direction: column; gap: 6px; pointer-events: none; z-index: 5; }
.map-top > * { pointer-events: auto; }
.row { display: flex; gap: 6px; align-items: center; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.chips button { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 11px; white-space: nowrap; font-size: 13px; backdrop-filter: blur(8px); }
.chips button.on { background: var(--accent); color: #04121d; border-color: var(--accent); font-weight: 600; }
.chips button .sub { opacity: .7; font-size: 11px; margin-left: 4px; }
select { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; backdrop-filter: blur(8px); max-width: 100%; }
.presets { position: absolute; right: 8px; top: calc(env(safe-area-inset-top) + 96px); z-index: 5; display: flex; flex-direction: column; gap: 4px; }
.presets button { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; font-size: 12px; }

.legend { position: absolute; left: 8px; bottom: 112px; z-index: 5; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; font-size: 11px; display: flex; flex-direction: column; gap: 4px; pointer-events: none; }
.legend .bar { display: flex; height: 10px; width: 210px; border-radius: 3px; overflow: hidden; }
.legend .bar span { flex: 1; }
.legend .ticks { position: relative; height: 13px; width: 210px; color: var(--muted); }
.legend .ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.legend .ticks span:first-child { transform: none; }
.legend .ttl { color: var(--text); font-weight: 600; }

.timebar { position: absolute; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--panel); border-top: 1px solid var(--line); padding: 8px 10px 10px; backdrop-filter: blur(10px); }
.timeline-label { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; gap: 8px; }
#t-label { font-weight: 650; font-size: 15px; font-variant-numeric: tabular-nums; }
#t-run { font-size: 12px; text-align: right; }
#slider { flex: 1; accent-color: var(--accent); height: 28px; }
.icon-btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; min-width: 36px; height: 34px; font-size: 16px; }
#play.on { background: var(--accent); color: #04121d; }

.sheet { position: absolute; left: 8px; right: 8px; bottom: 100px; z-index: 8; background: #111827f2; border: 1px solid var(--line); border-radius: 14px; padding: 12px; box-shadow: 0 10px 40px #0009; backdrop-filter: blur(12px); max-width: 520px; margin: 0 auto; }
.sheet h3 { margin: 0 0 6px; font-size: 15px; display: flex; justify-content: space-between; align-items: center; }
.sheet .x { background: none; border: 0; color: var(--muted); font-size: 20px; padding: 0 4px; }
.sheet .grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 10px; }
.sheet .grid div { background: var(--panel2); border-radius: 8px; padding: 5px 8px; }
.sheet .grid b { display: block; font-size: 15px; font-variant-numeric: tabular-nums; }
.sheet .grid small { color: var(--muted); font-size: 11px; }
.sheet .actions { display: flex; gap: 8px; margin-top: 10px; }
.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.btn.primary { background: var(--accent); color: #04121d; border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--bad); }

/* diagrams */
.diag-head { position: sticky; top: 0; z-index: 4; background: var(--bg); padding: 8px; display: flex; flex-direction: column; gap: 6px; border-bottom: 1px solid var(--line); }
#diag-body { padding: 6px 4px 20px; }
.card { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; margin: 8px 4px; padding: 8px 6px 4px; }
.card h4 { margin: 0 4px 2px; font-size: 13px; display: flex; justify-content: space-between; gap: 8px; }
.card h4 .muted { font-weight: 400; font-size: 11px; text-align: right; }
.card .note { margin: 2px 6px 6px; font-size: 12px; color: var(--muted); }
.uplot { font-family: inherit; }
.u-legend { font-size: 11px; color: var(--muted); }
.u-legend .u-series { padding: 0 4px; }
.u-legend .u-marker { width: 10px; height: 3px; }
.u-over { touch-action: pan-y; }
.episodes { list-style: none; padding: 0 6px; margin: 4px 0 8px; display: flex; flex-direction: column; gap: 4px; }
.episodes li { background: #0d1320; border-radius: 8px; padding: 6px 8px; font-size: 13px; }
.episodes b { color: var(--accent); }
.loading { text-align: center; padding: 30px; color: var(--muted); }
.err { color: var(--bad); padding: 16px; }

/* runs & settings */
.pad { padding: 12px 12px 40px; max-width: 640px; margin: 0 auto; }
h2 { font-size: 15px; margin: 18px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.run { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }
.run .top { display: flex; justify-content: space-between; align-items: baseline; }
.run .name { font-weight: 650; font-size: 15px; }
.run .badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: #1e2a40; }
.run .badge.new { background: var(--ok); color: #04120a; }
.run .meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.prog { height: 4px; background: #1e2a40; border-radius: 2px; overflow: hidden; margin-top: 6px; }
.prog i { display: block; height: 100%; background: var(--accent); }
.form { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 10px; }
.form label { display: flex; align-items: center; gap: 8px; }
.form .models { display: flex; gap: 6px; flex-wrap: wrap; }
.form .models label { background: #0d1320; padding: 4px 8px; border-radius: 8px; }
.rule { display: flex; gap: 6px; align-items: center; }
.rule input[type=number] { width: 70px; background: #0d1320; border: 1px solid var(--line); border-radius: 8px; padding: 5px; }
.fav { display: flex; justify-content: space-between; align-items: center; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin-bottom: 6px; }
.fav small { color: var(--muted); }

.maplibregl-canvas { outline: none; }
.marker { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; background: var(--accent); box-shadow: 0 0 0 3px #0008; }
@media (min-width: 900px) {
  .sheet { left: auto; right: 12px; width: 420px; bottom: 110px; }
  .timebar { left: 50%; transform: translateX(-50%); width: min(900px, 100%); border-radius: 14px 14px 0 0; border: 1px solid var(--line); }
}
#toast { position: fixed; left: 50%; bottom: calc(var(--tabs-h) + 120px); transform: translate(-50%, 20px); background: #1e2a40; border: 1px solid var(--line); color: var(--text); padding: 8px 14px; border-radius: 10px; z-index: 60; opacity: 0; transition: .25s; pointer-events: none; max-width: 90vw; font-size: 13px; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.card .plot { min-height: 40px; }
.chips button:disabled, .btn:disabled { opacity: .4; }

#model-chips button { padding: 5px 9px; }
#layer { flex: 1; min-width: 0; }
.card .u-legend { font-size: 11px; padding: 2px 6px 6px; text-align: left; }
.card .u-legend .u-series:first-child { display: none; }
.card .u-legend .u-series { padding: 1px 4px; }
.card .u-legend .u-series th { font-weight: 500; }
.card .u-legend .u-marker { width: 10px; height: 3px; margin-right: 4px; }
@media (min-width: 800px) { #layer { flex: 0 1 380px; } }
