:root {
  --bg: #ffffff;
  --fg: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2563eb;
  --red: #ef4444;
  --yellow: #f59e0b;
  --green: #22c55e;
  --shadow: 0 4px 16px rgba(0, 0, 0, .18);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1f2937; --fg: #f3f4f6; --muted: #9ca3af; --line: #374151; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif; color: var(--fg); background: var(--bg); }
#map { position: fixed; inset: 0; }
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--bg); color: var(--fg); border-radius: 8px; padding: 8px 12px; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
input { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--fg); width: 100%; }

/* 상단 검색 */
#topbar { position: fixed; top: 12px; left: 12px; right: 72px; max-width: 480px; z-index: 1000; }
#searchForm { display: flex; gap: 6px; box-shadow: var(--shadow); border-radius: 10px; background: var(--bg); padding: 6px; }
#searchForm input { border: none; }
#searchForm button { white-space: nowrap; flex: none; }
#searchResults { margin-top: 6px; background: var(--bg); border-radius: 10px; box-shadow: var(--shadow); max-height: 50vh; overflow: auto; }
#searchResults div { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 14px; }
#searchResults div:hover { background: rgba(37, 99, 235, .08); }

/* 내비 HUD */
#navHud { position: fixed; left: 12px; right: 12px; bottom: 16px; max-width: 520px; margin: 0 auto; z-index: 1000; background: var(--bg); border-radius: 12px; box-shadow: var(--shadow); padding: 12px 14px; }
.hud-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hud-row.small { margin-top: 6px; font-size: 14px; color: var(--muted); }
#navStep { font-size: 18px; font-weight: 700; }
#nextSignal { display: flex; align-items: center; gap: 6px; font-weight: 600; color: var(--fg); }

/* 우측 버튼 */
#fabs { position: fixed; right: 12px; top: 12px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; }
#fabs button { width: 48px; height: 48px; font-size: 20px; padding: 0; box-shadow: var(--shadow); border-radius: 12px; }
#fabs button.on { background: var(--accent); color: #fff; border-color: var(--accent); }

/* 그룹 패널 */
#groupPanel { position: fixed; right: 72px; top: 12px; width: min(300px, calc(100vw - 96px)); z-index: 1001; background: var(--bg); border-radius: 12px; box-shadow: var(--shadow); padding: 14px; }
#groupPanel h3 { margin: 0 0 10px; font-size: 16px; }
#groupPanel label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
#groupPanel label.row { display: flex; align-items: center; justify-content: space-between; }
#groupPanel label.row input { width: 48px; height: 32px; padding: 2px; }
#groupPanel button { width: 100%; margin-top: 4px; }
.error { color: var(--red); font-size: 13px; min-height: 1em; margin: 6px 0 0; }
#memberList { list-style: none; margin: 0 0 10px; padding: 0; max-height: 45vh; overflow: auto; }
#memberList li { display: flex; align-items: center; gap: 8px; padding: 8px 4px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 14px; }
#memberList li .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
#memberList li .meta { margin-left: auto; font-size: 12px; color: var(--muted); }

/* 멤버 마커 */
.member-marker { position: relative; }
.member-marker .pin { width: 22px; height: 22px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.member-marker .label { position: absolute; top: 24px; left: 50%; transform: translateX(-50%); white-space: nowrap; font-size: 12px; font-weight: 700; background: rgba(255,255,255,.9); color: #111; padding: 1px 6px; border-radius: 6px; }
.member-marker .arrow { position: absolute; left: 50%; top: 50%; width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 10px solid; margin: -24px 0 0 -6px; transform-origin: 6px 24px; }
.member-marker.stale .pin { opacity: .45; }
.me .pin { outline: 3px solid rgba(37, 99, 235, .35); }

/* 신호등 마커 */
.leaflet-marker-icon > .sig { transform: translate(-50%, -50%); width: max-content; }
.sig { display: flex; gap: 2px; background: #111; border-radius: 8px; padding: 3px; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.sig .lamp { min-width: 26px; height: 20px; border-radius: 5px; color: #fff; font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; padding: 0 3px; background: #444; }
.lamp.red { background: var(--red); }
.lamp.yellow { background: var(--yellow); color: #111; }
.lamp.green { background: var(--green); color: #111; }
.lamp.off, .lamp.unknown { background: #555; }
.sig-popup table { border-collapse: collapse; font-size: 12px; }
.sig-popup td, .sig-popup th { padding: 3px 6px; border-bottom: 1px solid #eee; text-align: center; }
.sig-popup .lamp { display: inline-flex; min-width: 42px; height: 18px; border-radius: 4px; font-size: 11px; font-weight: 700; color: #fff; align-items: center; justify-content: center; }

#toast { position: fixed; left: 50%; top: 76px; transform: translateX(-50%); z-index: 1100; background: rgba(17,24,39,.92); color: #fff; padding: 8px 14px; border-radius: 8px; font-size: 14px; max-width: 90vw; }
#modeBadge { position: fixed; left: 12px; bottom: 16px; z-index: 900; font-size: 11px; background: rgba(0,0,0,.6); color: #fff; padding: 3px 8px; border-radius: 6px; }
body.navigating #modeBadge { display: none; }
.lamp.expired { opacity: .45; }
