:root {
  --bg: #0d1117; --panel: #161b22; --panel2: #1c2330; --border: #2d3646; --text: #e6edf3;
  --muted: #8b98a9; --accent: #3b82f6; --accent-text: #fff; --ok: #3fb950; --bad: #f85149;
  --shadow: 0 6px 24px rgba(0,0,0,.45); --map-bg: #0b1220;
  --hdr: 52px; --bar: 32px; --panel-w: 300px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
:root[data-theme="light"] {
  --bg: #f4f6fa; --panel: #ffffff; --panel2: #eef1f6; --border: #d5dbe6; --text: #1b2330;
  --muted: #5d6b80; --accent: #2563eb; --shadow: 0 6px 24px rgba(20,30,50,.18); --map-bg: #cfe3f3;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
body { font-size: 14px; line-height: 1.4; }
#app { height: 100%; display: flex; flex-direction: column; }
button, input, select { font: inherit; color: inherit; }
h2 { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; font-weight: 600; }
h3 { margin: 0 0 8px; font-size: 15px; padding-right: 26px; word-break: break-word; }
.muted { color: var(--muted); font-size: 12px; margin: 6px 0 0; }

#top { height: var(--hdr); flex: 0 0 auto; display: flex; align-items: center; gap: 10px; padding: 0 12px; background: var(--panel); border-bottom: 1px solid var(--border); z-index: 30; padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-weight: 650; font-size: 16px; white-space: nowrap; min-width: 0; }
.brand span { overflow: hidden; text-overflow: ellipsis; }
.pill { background: var(--panel2); border: 1px solid var(--border); color: var(--muted); border-radius: 999px; padding: 2px 10px; font-size: 12px; white-space: nowrap; }
.pill.small { padding: 0 8px; font-size: 11px; letter-spacing: 0; text-transform: none; }
.pill:empty { display: none; }
.icon-btn { background: transparent; border: 1px solid transparent; border-radius: 8px; width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; font-size: 20px; line-height: 1; flex: 0 0 auto; }
.icon-btn:hover { background: var(--panel2); border-color: var(--border); }
.icon-btn.small { width: 28px; height: 28px; font-size: 18px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.search { position: relative; flex: 1 1 360px; max-width: 520px; margin: 0 auto; display: flex; align-items: center; background: var(--panel2); border: 1px solid var(--border); border-radius: 10px; padding-right: 2px; min-width: 0; }
.search input { flex: 1; min-width: 0; background: transparent; border: 0; outline: 0; padding: 8px 12px; }
.search:focus-within { border-color: var(--accent); }
.search.ok { border-color: var(--ok); }
.search.bad { border-color: var(--bad); }
.search .icon-btn { width: 32px; height: 32px; }
.results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; margin: 0; padding: 4px; list-style: none; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); max-height: 50vh; overflow: auto; z-index: 50; }
.results li { padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 13px; }
.results li:hover, .results li.sel { background: var(--panel2); }
.results small { display: block; color: var(--muted); }

#body { flex: 1 1 auto; display: flex; min-height: 0; position: relative; }
#panel { flex: 0 0 var(--panel-w); width: var(--panel-w); background: var(--panel); border-right: 1px solid var(--border); overflow-y: auto; padding: 14px; z-index: 20; transition: margin-left .2s ease; }
#panel section { margin-bottom: 18px; }
#panel.collapsed { margin-left: calc(-1 * var(--panel-w)); }
select { width: 100%; background: var(--panel2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.choices { display: grid; gap: 6px; }
.choices label, .check { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 6px 8px; border-radius: 8px; }
.choices label:hover, .check:hover { background: var(--panel2); }
.choices label.on { background: var(--panel2); outline: 1px solid var(--accent); }
.check { padding: 5px 4px; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn { background: var(--panel2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.plist { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; max-height: 32vh; overflow: auto; }
.plist li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
.plist li:hover, .plist li.following { background: var(--panel2); }
.plist li.following { outline: 1px solid var(--accent); }
.dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.4); flex: 0 0 auto; }
.plist li:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.phead { width: 16px; height: 16px; flex: 0 0 auto; image-rendering: pixelated; border-radius: 2px; box-shadow: 0 0 0 1px rgba(0,0,0,.45); }
.plist .gm { font-size: 10px; font-weight: 700; color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 0 3px; line-height: 14px; }
.plist .gm:empty { display: none; }
.plist .fbtn { background: transparent; border: 1px solid var(--border); border-radius: 6px; padding: 1px 7px; font-size: 11px; cursor: pointer; color: var(--muted); }
.plist .fbtn:hover, .plist li.following .fbtn { border-color: var(--accent); color: var(--text); }
.plist .nm { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plist .xy { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; white-space: nowrap; }

#stage { position: relative; flex: 1 1 auto; min-width: 0; background: var(--map-bg); overflow: hidden; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; outline: 0; }
#map.dragging { cursor: grabbing; }
#map.hover { cursor: pointer; }
.zoomctl { position: absolute; right: 12px; top: 12px; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); overflow: hidden; }
.zoomctl .icon-btn { border-radius: 0; width: 38px; height: 38px; font-size: 22px; }
.zoomctl .icon-btn + .icon-btn { border-top: 1px solid var(--border); }
.card { position: absolute; left: 12px; bottom: 12px; width: min(360px, calc(100% - 24px)); background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 12px 14px; z-index: 10; }
.card .icon-btn { position: absolute; right: 6px; top: 6px; }
.card dl { margin: 0; display: grid; gap: 6px; }
.card .row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; background: var(--panel2); border-radius: 8px; padding: 6px 8px; }
.card .row span { display: block; }
.card .row small { color: var(--muted); display: block; font-size: 11px; }
.card .row code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; word-break: break-all; font-variant-numeric: tabular-nums; }
.card .row.info { grid-template-columns: 1fr auto; }
.card .row[hidden] { display: none; }
.card .copy { background: transparent; border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px; cursor: pointer; font-size: 12px; }
.card .copy:hover { border-color: var(--accent); }
.attrib { position: absolute; right: 0; bottom: 0; background: rgba(0,0,0,.6); color: #ddd; font-size: 11px; padding: 2px 8px; border-top-left-radius: 6px; max-width: 80%; z-index: 5; }
.attrib a { color: #9cc4ff; }
.offline { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); background: var(--bad); color: #fff; padding: 6px 14px; border-radius: 999px; font-size: 13px; z-index: 15; }
.toast { position: absolute; left: 50%; bottom: 60px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px; font-size: 13px; z-index: 40; box-shadow: var(--shadow); }
.card:not([hidden]) ~ .attrib { max-width: 55%; }

#bar { height: var(--bar); flex: 0 0 auto; display: flex; gap: 18px; align-items: center; padding: 0 14px; background: var(--panel); border-top: 1px solid var(--border); font-size: 12.5px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; padding-bottom: env(safe-area-inset-bottom); }
#bar b { color: var(--muted); font-weight: 600; margin-right: 2px; }
.ro { display: inline-flex; gap: 6px; }
.zoomro { margin-left: auto; }

@media (max-width: 760px) {
  :root { --panel-w: min(86vw, 320px); }
  #panel { position: absolute; left: 0; top: 0; bottom: 0; box-shadow: var(--shadow); }
  #scalePill { display: none; }
  .brand span { display: none; }
  .search { flex-basis: 0; }
  #bar { gap: 10px; font-size: 11.5px; padding: 0 8px; }
  .zoomro { display: none; }
  .card { bottom: 28px; }
}
@media (prefers-reduced-motion: reduce) { #panel { transition: none; } }
