:root {
  --bg: #fbfbf9;
  --card: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6b66;
  --line: #e2e1db;
  --accent: #0b6bcb;
  --halo: #fbfbf9;
  --node-fill: #ffffff;
  --node-stroke: #1d1d1b;
  --me: #1a73e8;
  --shadow: 0 2px 10px rgba(0, 0, 0, .12), 0 0 0 1px rgba(0, 0, 0, .04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121211; --card: #1f1f1d; --text: #ecebe6; --muted: #9c9b94; --line: #34332f; --accent: #5aa4f0;
    --halo: #121211; --node-fill: #121211; --node-stroke: #ecebe6; --me: #4c9bff;
    --shadow: 0 2px 12px rgba(0, 0, 0, .5), 0 0 0 1px rgba(255, 255, 255, .06);
  }
}
:root[data-theme="dark"] {
  --bg: #121211; --card: #1f1f1d; --text: #ecebe6; --muted: #9c9b94; --line: #34332f; --accent: #5aa4f0;
  --halo: #121211; --node-fill: #121211; --node-stroke: #ecebe6; --me: #4c9bff;
  --shadow: 0 2px 12px rgba(0, 0, 0, .5), 0 0 0 1px rgba(255, 255, 255, .06);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent; }
svg#map { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; user-select: none;
  -webkit-user-select: none; cursor: grab; }
svg#map.dragging { cursor: grabbing; }
svg text { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }

#title { position: fixed; top: calc(12px + env(safe-area-inset-top)); left: 16px; pointer-events: none;
  background: color-mix(in srgb, var(--bg) 82%, transparent); padding: 6px 10px; border-radius: 10px; }
#title h1 { margin: 0; font-size: 20px; line-height: 1.1; letter-spacing: -.01em; }
#title p { margin: 0; font-size: 12px; color: var(--muted); }

#morphCtl { position: fixed; top: calc(14px + env(safe-area-inset-top)); right: 16px; display: flex; align-items: center; gap: 6px;
  background: var(--card); box-shadow: var(--shadow); border-radius: 12px; padding: 6px 10px; font-size: 12px; color: var(--muted); }
#morphCtl input { width: 96px; margin: 0; accent-color: var(--accent); }
#controls { position: fixed; right: 16px; bottom: calc(28px + env(safe-area-inset-bottom)); display: flex; flex-direction: column;
  gap: 10px; align-items: flex-end; transition: transform .2s; }
body.has-card #controls { transform: translateY(calc(-1 * var(--card-h, 0px))); }
.ctl { width: 44px; height: 44px; border-radius: 12px; border: 0; background: var(--card); color: var(--text);
  box-shadow: var(--shadow); font: 22px/1 -apple-system, sans-serif; cursor: pointer; display: grid; place-items: center; padding: 0; }
.ctl:hover { color: var(--accent); }
.ctl.on { color: var(--me); }
.ctl.busy svg { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.zoom { display: flex; flex-direction: column; border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.zoom .ctl { box-shadow: none; border-radius: 0; }
.zoom .ctl + .ctl { border-top: 1px solid var(--line); }
@media (pointer: coarse) { .zoom { display: none; } }

#card { position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(440px, calc(100% - 24px)); background: var(--card); border-radius: 16px; box-shadow: var(--shadow);
  padding: 14px 16px 14px; }
#cardClose { position: absolute; top: 6px; right: 8px; border: 0; background: none; color: var(--muted); font-size: 24px;
  line-height: 1; padding: 4px 8px; cursor: pointer; }
#cardBody .kicker { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 2px; }
#cardBody h2 { margin: 0 32px 2px 0; font-size: 18px; line-height: 1.25; display: flex; align-items: center; gap: 8px; }
#cardBody h2 .chip { width: 14px; height: 14px; border-radius: 4px; flex: none; }
#cardBody .meta { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
#cardBody .roads { display: flex; flex-wrap: wrap; gap: 4px 6px; margin: 2px 0 10px; }
#cardBody .road { font-size: 12px; padding: 1px 8px 1px 6px; border-radius: 10px; background: color-mix(in srgb, var(--muted) 14%, transparent);
  display: inline-flex; align-items: center; gap: 5px; }
#cardBody .road i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions a, .actions button { flex: 1 1 0; min-width: 0; text-align: center; font: inherit; font-size: 14px; font-weight: 500; padding: 9px 8px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); text-decoration: none; cursor: pointer; white-space: nowrap; }
.actions a:hover, .actions button:hover { border-color: var(--accent); }
.actions .primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.directions { font-size: 13px; color: var(--muted); margin-top: 8px; }
.directions a { color: var(--accent); text-decoration: none; }

#toast { position: fixed; top: calc(16px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); background: rgba(17, 17, 17, .86);
  color: #fff; padding: 7px 14px; border-radius: 18px; font-size: 14px; pointer-events: none; z-index: 10; white-space: nowrap; }
#attrib { position: fixed; left: 12px; bottom: calc(6px + env(safe-area-inset-bottom)); font-size: 11px; color: var(--muted); }
#attrib a { color: inherit; }
body.has-card #attrib { display: none; }
#loading { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); color: var(--muted); padding: 24px; text-align: center; z-index: 20; }
