:root {
  --bg: #0a0d13;
  --glass: rgba(14, 18, 26, 0.74);
  --line: rgba(255, 255, 255, 0.09);
  --text: #e8edf5;
  --dim: #8b96a8;
  --faint: #5b6577;
  --accent: #5eead4;
  --new: #6ee7b7;
  --quiet: #fb7185;
  --repeater: #38bdf8;
  --companion: #fbbf24;
  --room: #c084fc;
  --sensor: #4ade80;
  --radius: 16px;
  --gap: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
[hidden] { display: none !important; }

#map { position: fixed; inset: 0; background: var(--bg); }
#map canvas.overlay { position: absolute; inset: 0; pointer-events: none; }
.maplibregl-ctrl-attrib { background: rgba(10, 13, 19, 0.6) !important; color: var(--faint); font-size: 10px; }
.maplibregl-ctrl-attrib a { color: var(--dim) !important; }
.maplibregl-ctrl-bottom-right { bottom: calc(var(--dock-h, 170px) + var(--gap)); right: 6px; }
.maplibregl-ctrl-group { background: var(--glass) !important; backdrop-filter: blur(18px); border: 1px solid var(--line); box-shadow: none !important; border-radius: 12px !important; overflow: hidden; }
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--line) !important; }
.maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(1) brightness(0.85); }

.card {
  position: fixed;
  z-index: 5;
  background: var(--glass);
  -webkit-backdrop-filter: blur(22px) saturate(1.4);
  backdrop-filter: blur(22px) saturate(1.4);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

/* ---- top-left: date and counts ---- */
#hud { top: var(--gap); left: var(--gap); width: 330px; padding: 16px 18px 14px; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 11px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim); }
.brand svg { width: 16px; height: 16px; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; }
.date { margin-top: 10px; font-size: 27px; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sub { color: var(--dim); font-size: 12.5px; min-height: 18px; }
.sub .warn { color: var(--companion); }
.stats { display: grid; grid-template-columns: 1.25fr 1fr 1fr 1fr; gap: 6px; margin-top: 14px; }
.stats div { display: flex; flex-direction: column; }
.stats b { font-size: 21px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.stats span { font-size: 11px; color: var(--dim); white-space: nowrap; }
.stats .new b { color: var(--new); }
.stats .quiet b { color: var(--quiet); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px 5px 8px; border-radius: 999px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04); font-size: 12px; color: var(--text); transition: opacity 0.15s, background 0.15s; }
.chip:hover { background: rgba(255, 255, 255, 0.09); }
.chip i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); box-shadow: 0 0 8px var(--c); }
.chip.obs i { background: none; border: 1.5px solid #fff; border-radius: 1px; transform: rotate(45deg); box-shadow: none; width: 7px; height: 7px; }
.chip em { font-style: normal; color: var(--dim); font-variant-numeric: tabular-nums; }
.chip.off { opacity: 0.38; }
.chip.off i { box-shadow: none; }

/* ---- right: search, node detail, what changed ---- */
#panel { top: var(--gap); right: var(--gap); width: 320px; max-height: calc(100vh - var(--dock-h, 170px) - 3 * var(--gap)); display: flex; flex-direction: column; overflow: hidden; }
.search { display: flex; align-items: center; gap: 8px; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.search svg { width: 16px; height: 16px; flex: none; fill: none; stroke: var(--dim); stroke-width: 2; stroke-linecap: round; }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; font-size: 14px; }
.search input::placeholder { color: var(--faint); }
.search input::-webkit-search-cancel-button { filter: invert(0.7); }
.search, #results, #detail { flex: none; }
#detail { position: relative; }
#results { border-bottom: 1px solid var(--line); padding: 4px 6px; max-height: 260px; overflow-y: auto; }
#feed { overflow-y: auto; padding: 4px 6px 10px; scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.15) transparent; }
.group { display: flex; align-items: baseline; gap: 8px; padding: 12px 10px 5px; font-size: 11px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim); }
.group b { font-variant-numeric: tabular-nums; }
.group.new b { color: var(--new); }
.group.back b { color: var(--repeater); }
.group.quiet b { color: var(--quiet); }
.row { display: flex; align-items: center; gap: 9px; width: 100%; padding: 6px 10px; border-radius: 9px; text-align: left; }
.row:hover, .row:focus-visible { background: rgba(255, 255, 255, 0.07); outline: 0; }
.row i { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.row i.nopos { background: none; border: 1.5px solid var(--c); }
.row span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row small { flex: none; color: var(--faint); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.more, .empty { padding: 6px 10px; color: var(--faint); font-size: 12px; }
.empty { padding: 14px 10px; }

#detail { padding: 14px 16px; border-bottom: 1px solid var(--line); }
#detail h2 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -0.01em; overflow-wrap: anywhere; padding-right: 26px; }
#detail .close { position: absolute; right: 12px; top: 12px; color: var(--dim); width: 24px; height: 24px; border-radius: 8px; }
#detail .close:hover { background: rgba(255, 255, 255, 0.08); color: var(--text); }
#detail .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 5px; color: var(--dim); font-size: 12px; }
#detail .badge { display: inline-flex; align-items: center; gap: 5px; color: var(--text); }
#detail .badge i { width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
#detail code { font: 11.5px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--faint); }
#detail dl { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin: 12px 0 10px; }
#detail dt { font-size: 11px; color: var(--dim); }
#detail dd { margin: 0; font-variant-numeric: tabular-nums; }
#detail canvas { display: block; width: 100%; height: 22px; border-radius: 5px; background: rgba(255, 255, 255, 0.04); }
#detail .now { margin-top: 8px; font-size: 12.5px; color: var(--dim); }
#detail .actions { display: flex; gap: 6px; margin-top: 10px; }
.ghost { padding: 5px 11px; border-radius: 9px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04); font-size: 12px; color: var(--text); white-space: nowrap; }
.ghost:hover { background: rgba(255, 255, 255, 0.1); }

/* ---- bottom: transport and timeline ---- */
#dock { left: var(--gap); right: var(--gap); bottom: var(--gap); padding: 10px 14px 8px; }
.controls { display: flex; align-items: center; gap: 10px; }
.transport { display: flex; align-items: center; gap: 2px; }
.icon { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; color: var(--dim); }
.icon:hover { background: rgba(255, 255, 255, 0.08); color: var(--text); }
.icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon.play { width: 40px; height: 40px; margin: 0 4px; border-radius: 50%; background: var(--accent); color: #06231f; box-shadow: 0 0 22px rgba(94, 234, 212, 0.35); }
.icon.play:hover { background: #8ff3e2; color: #06231f; }
.icon.play svg { fill: currentColor; stroke: none; width: 20px; height: 20px; }
.seg { display: inline-flex; padding: 2px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.03); }
.seg button { padding: 4px 10px; border-radius: 8px; font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums; }
.seg button:hover { color: var(--text); }
.seg button.on { background: rgba(255, 255, 255, 0.12); color: var(--text); }
.seg-label { font-size: 12px; color: var(--dim); }
.spacer { flex: 1; }
#scrub { position: relative; margin-top: 8px; height: 96px; outline: 0; cursor: ew-resize; touch-action: none; border-radius: 10px; }
#scrub:focus-visible { box-shadow: 0 0 0 2px rgba(94, 234, 212, 0.5); }
#chart { display: block; width: 100%; height: 100%; }
#tip, #hover {
  position: absolute; z-index: 9; pointer-events: none; white-space: nowrap;
  padding: 5px 9px; border-radius: 9px; font-size: 12px;
  background: rgba(8, 10, 15, 0.92); border: 1px solid var(--line); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
#tip { bottom: calc(100% + 4px); transform: translateX(-50%); }
#tip b, #hover b { font-weight: 600; }
#tip span, #hover span { color: var(--dim); }
#hover { position: fixed; transform: translate(14px, 14px); max-width: 280px; white-space: normal; }

#loading { position: fixed; inset: 0; z-index: 20; display: grid; place-content: center; justify-items: center; gap: 14px; background: var(--bg); color: var(--dim); transition: opacity 0.5s; }
#loading.done { opacity: 0; pointer-events: none; }
.spinner { width: 30px; height: 30px; border-radius: 50%; border: 2.5px solid rgba(255, 255, 255, 0.1); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.only-mobile { display: none; }
:focus-visible { outline: 2px solid rgba(94, 234, 212, 0.6); outline-offset: 1px; }

@media (max-width: 760px) {
  :root { --gap: 8px; }
  #hud { width: auto; right: var(--gap); padding: 12px 14px; }
  .date { font-size: 21px; margin-top: 6px; }
  .stats { margin-top: 8px; }
  .stats b { font-size: 17px; }
  .chips { margin-top: 10px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .chip { flex: none; }
  .only-mobile { display: inline-grid; }
  #panel-open { right: var(--gap); bottom: calc(var(--dock-h, 170px) + 2 * var(--gap)); padding: 8px 14px; border-radius: 999px; font-size: 13px; }
  #panel { top: auto; left: var(--gap); width: auto; bottom: var(--gap); max-height: 70vh; z-index: 8; transform: translateY(calc(100% + 20px)); transition: transform 0.25s ease; }
  #panel.open { transform: none; }
  .controls { flex-wrap: wrap; gap: 8px; }
  .seg-label, #b-start, #b-end { display: none; }
  #scrub { height: 76px; }
  .maplibregl-ctrl-bottom-right { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 3s; }
  #panel { transition: none; }
}
