:root {
  --bg: #0d1117;
  --panel: rgba(17, 22, 30, 0.82);
  --panel-solid: #141a23;
  --border: rgba(255, 255, 255, 0.09);
  --text: #e8edf3;
  --muted: #9aa7b6;
  --accent: #6cc58f;
  --accent-2: #4fa3e0;
  --warn: #f0b04a;
  --danger: #ea6a5a;
  --radius: 12px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }

.map {
  position: fixed;
  inset: 0;
  touch-action: none;
  user-select: none;
}
.map canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.map canvas.map2d { cursor: grab; }
.map canvas.map2d:active { cursor: grabbing; }

/* ---- top bar ---- */
.topbar {
  position: fixed;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: none;
  z-index: 10;
}
.topbar > * { pointer-events: auto; }

.brand, .clock, .modes, .icon-btn, .sidebar, .coords, .chip, .notice, .zoom-controls {
  background: var(--panel);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px 7px 10px;
  border-radius: var(--radius);
  min-width: 0;
}
.brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 34vw;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.status i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn);
}
.status[data-state="live"] i { background: var(--accent); box-shadow: 0 0 0 0 rgba(108, 197, 143, 0.6); animation: pulse 2s infinite; }
.status[data-state="offline"] i { background: var(--danger); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(108, 197, 143, 0.55); }
  70% { box-shadow: 0 0 0 8px rgba(108, 197, 143, 0); }
  100% { box-shadow: 0 0 0 0 rgba(108, 197, 143, 0); }
}

.clock {
  margin-left: auto;
  padding: 8px 14px;
  border-radius: var(--radius);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  white-space: nowrap;
}
.clock:empty { display: none; }

.modes {
  display: flex;
  padding: 3px;
  border-radius: var(--radius);
}
.modes button, .segmented button {
  border: 0;
  background: transparent;
  padding: 6px 14px;
  border-radius: 9px;
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
}
.modes button.active, .segmented button.active {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}
.icon-btn:hover, .modes button:hover, .segmented button:hover { color: #fff; }

/* ---- sidebar ---- */
.sidebar {
  position: fixed;
  top: 64px;
  left: 12px;
  bottom: 12px;
  width: 280px;
  border-radius: var(--radius);
  padding: 6px 14px 12px;
  overflow-y: auto;
  z-index: 9;
  transition: transform 0.25s ease, opacity 0.25s ease;
}
body.sidebar-hidden .sidebar { transform: translateX(calc(-100% - 20px)); opacity: 0; pointer-events: none; }

.sidebar section { padding: 8px 0 12px; border-bottom: 1px solid var(--border); }
.sidebar section:last-of-type { border-bottom: 0; }
.sidebar h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 6px 0 10px;
  font-weight: 650;
  display: flex;
  align-items: center;
  gap: 8px;
}
.badge {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11px;
  color: var(--text);
}

.player-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.player-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: 9px;
  cursor: pointer;
}
.player-list li:hover { background: rgba(255, 255, 255, 0.06); }
.player-list li.following { background: rgba(108, 197, 143, 0.14); }
.player-list .dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid #fff; flex: none; }
.player-list .name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-list .pos { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.player-list .follow {
  border: 0;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  padding: 2px 4px;
  border-radius: 6px;
}
.player-list .follow:hover, .player-list li.following .follow { color: var(--accent); }

.segmented {
  display: flex;
  background: rgba(0, 0, 0, 0.25);
  padding: 3px;
  border-radius: 10px;
  margin-bottom: 8px;
}
.segmented button { flex: 1; padding: 5px 8px; font-size: 13px; }

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 2px;
  cursor: pointer;
}
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.only2d {
  margin-left: auto;
  font-size: 10.5px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.07);
  border-radius: 999px;
  padding: 1px 7px;
  white-space: nowrap;
}
.sub { display: flex; align-items: center; margin: 0 2px 6px; font-size: 13px; }

.range { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 4px 2px 8px; align-items: center; }
.range span { grid-column: 1 / -1; color: var(--text); }
.range input { width: 100%; accent-color: var(--accent-2); }
.range output { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 32px; text-align: right; }

body:not(.mode-3d) .only-3d { display: none; }

.muted { color: var(--muted); }
.help { font-size: 12px; margin: 10px 0 4px; }
#stats { font-size: 11px; margin-top: 6px; }

/* ---- overlays ---- */
.zoom-controls {
  position: fixed;
  right: 12px;
  bottom: 12px;
  display: grid;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  z-index: 8;
}
.zoom-controls .icon-btn { box-shadow: none; border: 0; background: transparent; }
.zoom-controls .icon-btn:hover { background: rgba(255, 255, 255, 0.08); }

.coords {
  position: fixed;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  padding: 7px 14px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  white-space: nowrap;
  z-index: 8;
  max-width: calc(100vw - 120px);
  overflow: hidden;
  text-overflow: ellipsis;
}
.coords:empty { display: none; }
.coords b { font-weight: 600; color: var(--muted); margin-right: 2px; }
.coords .sep { color: rgba(255, 255, 255, 0.25); margin: 0 7px; }

.chip {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 8px 6px 14px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 8;
}
.chip button { border: 0; background: rgba(255, 255, 255, 0.1); border-radius: 999px; padding: 2px 10px; cursor: pointer; }

.notice {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  max-width: min(440px, calc(100vw - 32px));
  padding: 16px 20px;
  border-radius: var(--radius);
  text-align: center;
  z-index: 7;
}

[hidden] { display: none !important; }

@media (max-width: 720px) {
  .clock { display: none; }
  .brand h1 { max-width: 40vw; }
  .sidebar { top: 60px; width: min(300px, calc(100vw - 24px)); }
  .status span { display: none; }
  .coords { bottom: 64px; font-size: 12px; max-width: calc(100vw - 24px); }
}
