:root {
  --bg: #121212;
  --bg-2: #1a1a1a;
  --panel: #1a1a1a;
  --panel-solid: #1a1a1a;
  --border: #333;
  --border-strong: #4a4a4a;
  --text: #ddd;
  --text-muted: #888;
  --accent: #c44;
  --accent-2: #c90;
  --self: #6ac;
  --target: #c44;
  --success: #6a6;
  --danger: #c44;
  --font: "Segoe UI", Tahoma, sans-serif;
  --mono: Consolas, "Courier New", monospace;
  --sidebar-w: 300px;
  --topbar-h: 40px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  overflow: hidden;
}

button, input, label { font-family: inherit; }
button { cursor: pointer; }
svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: square; stroke-linejoin: miter; }
kbd {
  font-family: var(--mono);
  font-size: 10px;
  padding: 0 3px;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
code {
  font-family: var(--mono);
  font-size: 11px;
}

#app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "top top"
    "side map";
  height: 100vh;
  height: 100dvh;
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 10px;
  background: #161616;
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

.brand { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.brand-logo { display: none; }
.brand-text { display: flex; align-items: baseline; gap: 8px; }
.brand-text strong { font-size: 13px; font-weight: 700; }
.brand-text span:last-child { font-size: 12px; color: var(--text-muted); font-weight: 400; text-transform: none; letter-spacing: 0; }

.map-tabs { display: flex; gap: 0; border: 1px solid var(--border); }
.map-tab {
  border: 0;
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  padding: 5px 12px;
  font-weight: 600;
  font-size: 12px;
}
.map-tab:last-child { border-right: 0; }
.map-tab:hover { color: var(--text); background: #222; }
.map-tab.active { color: #fff; background: #2a2a2a; }

.topbar-right { margin-left: auto; display: flex; align-items: center; }

.mode-switch { display: flex; gap: 0; border: 1px solid var(--border); }
.mode-btn {
  display: flex; align-items: center; gap: 6px;
  border: 0; border-right: 1px solid var(--border);
  background: transparent; color: var(--text-muted);
  padding: 5px 10px; font-weight: 600; font-size: 12px;
}
.mode-btn:last-child { border-right: 0; }
.mode-btn:hover { color: var(--text); background: #222; }
.mode-btn[aria-checked="true"] { color: #fff; background: #2a2a2a; }
.mode-btn[data-mode="self"][aria-checked="true"] { color: var(--self); }
.mode-btn[data-mode="target"][aria-checked="true"] { color: var(--target); }
.mode-btn[data-mode="ping"][aria-checked="true"] { color: var(--accent-2); }
.mode-btn svg { width: 14px; height: 14px; }

.dot { display: inline-block; width: 7px; height: 7px; flex: none; }
.dot.self { background: var(--self); }
.dot.target { background: var(--target); }
.dot.ping { background: var(--accent-2); }

.icon-btn {
  width: 28px; height: 28px; display: grid; place-items: center;
  border: 1px solid var(--border);
  background: var(--bg-2); color: var(--text);
}
.icon-btn:hover { background: #252525; border-color: var(--border-strong); }

.sidebar {
  grid-area: side;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  overflow: hidden;
  z-index: 15;
}
.sidebar-scroll { height: 100%; overflow-y: auto; padding: 0; display: flex; flex-direction: column; scrollbar-width: thin; scrollbar-color: #444 transparent; }
.sidebar-backdrop { display: none; }

.card {
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--border);
  padding: 12px 12px 10px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.card h2 { margin: 0; font-size: 14px; }
.card h3 { margin: 0; font-size: 12px; font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 6px; text-transform: none; letter-spacing: 0; }
.card h3 .count { color: var(--text-muted); font-weight: 600; font-family: var(--mono); }
.muted { color: var(--text-muted); margin: 0; }
.small-text { font-size: 12px; }
.hint { color: var(--text-muted); font-size: 12px; margin: 0; }
.hint b { color: var(--text); }

.badge { font-size: 11px; font-family: var(--mono); color: var(--text-muted); }
.badge.soon { color: var(--text-muted); }

.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.info-grid.empty { display: block; min-height: 0; }
.info-item { background: #141414; border: 1px solid var(--border); padding: 6px 8px; }
.info-item .k { font-size: 11px; color: var(--text-muted); }
.info-item .v { font-family: var(--mono); font-size: 13px; margin-top: 1px; }
.info-item.wide { grid-column: 1 / -1; }

.target-list { display: flex; flex-direction: column; gap: 4px; }
.target-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 6px 8px;
  background: #141414;
  border: 1px solid var(--border);
  cursor: pointer;
}
.target-item:hover { border-color: var(--border-strong); }
.target-item.selected { border-color: var(--accent); }
.target-num { width: 20px; height: 20px; display: grid; place-items: center; color: var(--accent); font-weight: 700; font-size: 12px; font-family: var(--mono); }
.target-main { min-width: 0; }
.target-dist { font-family: var(--mono); font-size: 13px; }
.target-sub { font-size: 11px; color: var(--text-muted); font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.target-del { width: 24px; height: 24px; border: 0; background: transparent; color: var(--text-muted); display: grid; place-items: center; }
.target-del:hover { color: var(--danger); }
.target-del svg { width: 13px; height: 13px; }

.btn-row { display: flex; gap: 6px; margin: 8px 0 0; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; font-weight: 600; font-size: 12px;
  border: 1px solid var(--border-strong); background: #222; color: var(--text);
}
.btn:hover { background: #2c2c2c; }
.btn svg { width: 13px; height: 13px; }
.btn.secondary { background: #222; }
.btn.ghost { background: transparent; }
.btn.danger-ghost { background: transparent; color: var(--danger); border-color: #633; }
.btn.danger-ghost:hover { background: #2a1515; }
.ghost-btn { border: 0; background: transparent; color: var(--text-muted); font-size: 12px; padding: 2px 4px; }
.ghost-btn:hover { color: var(--text); }
.ghost-btn.danger:hover { color: var(--danger); }

.field { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; font-size: 12px; color: var(--text-muted); }
.field input {
  background: #111; border: 1px solid var(--border); color: var(--text);
  padding: 5px 8px; font-family: var(--mono); font-size: 13px; outline: none;
}
.field input:focus { border-color: #666; }
.field input::placeholder { color: #555; }

.toggle { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 12px; cursor: pointer; user-select: none; }
.toggle input { width: 13px; height: 13px; margin: 0; accent-color: #888; }
.toggle span { display: none; }

.map-area { grid-area: map; position: relative; overflow: hidden; background: #111; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
#map.pan { cursor: grab; }
#map.dragging { cursor: grabbing; }
#map.over-marker { cursor: move; }

.map-overlay { position: absolute; z-index: 5; pointer-events: none; }
.map-overlay > * { pointer-events: auto; }
.top-left { top: 28px; left: 28px; }
.bottom-right { bottom: 10px; right: 10px; }
.bottom-left { bottom: 10px; left: 28px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }

.hud {
  display: flex; flex-direction: column;
  padding: 6px 10px; min-width: 140px;
  background: #1a1a1a; border: 1px solid var(--border);
}
.hud-label { font-size: 10px; color: var(--text-muted); }
.hud-value { font-family: var(--mono); font-size: 22px; font-weight: 700; line-height: 1.15; }
.hud-value .unit { font-size: 12px; color: var(--text-muted); margin-left: 3px; font-weight: 400; }
.hud-sub { font-family: var(--mono); font-size: 11px; color: var(--text-muted); margin-top: 2px; min-height: 12px; }
.hud.has-value .hud-value { color: #fff; }

.zoom-ctrls { display: flex; flex-direction: column; gap: 0; }
.zoom-ctrls .icon-btn { border-bottom: 0; }
.zoom-ctrls .icon-btn:last-child { border-bottom: 1px solid var(--border); }

.statusbar {
  display: flex; align-items: center; gap: 8px;
  padding: 3px 8px; font-family: var(--mono); font-size: 11px; color: var(--text-muted);
  background: #1a1a1a; border: 1px solid var(--border);
}
.statusbar .sep { width: 1px; height: 10px; background: var(--border); }
.statusbar #status-coords { color: var(--text); }

.coord-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.coord-row .field { margin-top: 0; }
.coord-row .field span { font-weight: 600; color: var(--text); }
.seg { display: flex; gap: 0; border: 1px solid var(--border); }
.style-btn { border: 0; border-right: 1px solid var(--border); background: transparent; color: var(--text-muted); font-size: 12px; font-weight: 600; padding: 3px 8px; }
.style-btn:last-child { border-right: 0; }
.style-btn:hover { color: var(--text); }
.style-btn[aria-checked="true"] { color: #fff; background: #2a2a2a; }
.copy-btn { width: 24px; height: 24px; border: 0; background: transparent; color: var(--text-muted); display: grid; place-items: center; }
.copy-btn:hover { color: var(--text); }
.copy-btn svg { width: 13px; height: 13px; }
.info-item.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 6px; }
.target-actions { display: flex; align-items: center; }
.card-head .seg { margin-left: auto; }
.btn .dot { width: 7px; height: 7px; }

.scalebar { display: flex; flex-direction: column; gap: 2px; padding: 3px 8px; background: #1a1a1a; border: 1px solid var(--border); }
.scalebar-line { display: block; height: 3px; border: 1px solid var(--text); border-top: 0; width: 100px; }
.scalebar-text { font-family: var(--mono); font-size: 10px; color: var(--text-muted); }

.toast {
  position: absolute; left: 50%; bottom: 16px; transform: translate(-50%, 8px);
  padding: 6px 10px; background: #1a1a1a; border: 1px solid var(--border);
  font-size: 12px; opacity: 0; pointer-events: none; transition: opacity 0.15s; z-index: 30;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.only-mobile { display: none; }

.coord-actions { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; }
.coord-actions .btn { justify-content: center; white-space: nowrap; }
.coord-actions .btn.ghost { padding: 5px 8px; }
.coord-actions .btn.ghost svg { width: 14px; height: 14px; }

.group-card .info-item.wide.row { margin-bottom: 8px; }
.member-list { display: flex; flex-direction: column; gap: 2px; margin: 4px 0 8px; }
.member {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 0;
  font-size: 12px;
}
.member .dot { width: 7px; height: 7px; }
.member .you { margin-left: auto; font-size: 11px; color: var(--text-muted); }
.member .coords { margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--text-muted); }

@media (max-width: 1100px) {
  .mode-btn kbd { display: none; }
  .map-tab, .mode-btn { padding: 5px 8px; }
}

@media (max-width: 860px) {
  #app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "map"; }
  .topbar, .map-area { min-width: 0; }
  .only-mobile { display: grid; }
  .brand-text span:last-child { display: none; }
  .map-tabs { order: 3; }
  .sidebar {
    position: fixed; top: var(--topbar-h); bottom: 0; left: 0; width: min(88vw, var(--sidebar-w));
    transform: translateX(-100%); transition: transform 0.15s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop { display: block; position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(0,0,0,0.55); opacity: 0; pointer-events: none; z-index: 14; }
  .sidebar-backdrop.show { opacity: 1; pointer-events: auto; }
  .mode-btn span.txt { display: none; }
}

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 6px 8px; row-gap: 6px; }
  #app { grid-template-rows: auto minmax(0, 1fr); }
  .map-tabs { order: 3; width: 100%; }
  .map-tab { flex: 1; justify-content: center; }
  .sidebar, .sidebar-backdrop { top: 0; }
  .sidebar { z-index: 40; }
  .sidebar-backdrop { z-index: 39; }
  .hud { min-width: 120px; }
  .hud-value { font-size: 18px; }
}
