:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --surface-3: #e3e8ed;
  --ink: #111827;
  --muted: #5f6b7a;
  --line: #dde3ea;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --accent-soft: #dbe7ff;
  --danger: #dc2626;
  --danger-soft: #fde4e4;
  --warn-bg: #fff4d6;
  --warn-ink: #6b4a00;
  --ok-bg: #dcf5e6;
  --ok-ink: #0f5a2c;
  --shadow: 0 6px 24px rgba(16, 24, 40, .14), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-sm: 0 2px 10px rgba(16, 24, 40, .14);
  --radius: 18px;
  --map-bg: #dfe6ec;
  --tile-filter: none;
  --road-ink: #1e4fb8;
  --me: #2563eb;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}
html.dark {
  --bg: #0f141a;
  --surface: #171d25;
  --surface-2: #212a34;
  --surface-3: #2b3643;
  --ink: #e8edf3;
  --muted: #9aa7b5;
  --line: #2b3643;
  --accent: #4f8cff;
  --accent-ink: #ffffff;
  --accent-soft: #1b2f52;
  --danger: #ff6b6b;
  --danger-soft: #3d1d22;
  --warn-bg: #3a2e0c;
  --warn-ink: #ffe3a3;
  --ok-bg: #123a22;
  --ok-ink: #a9ebbf;
  --shadow: 0 8px 28px rgba(0, 0, 0, .55), 0 1px 3px rgba(0, 0, 0, .4);
  --shadow-sm: 0 2px 12px rgba(0, 0, 0, .5);
  --map-bg: #0e1318;
  --tile-filter: invert(1) hue-rotate(180deg) brightness(.9) contrast(.9) saturate(.7);
  --road-ink: #5b9cff;
  --me: #4f8cff;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  color: var(--ink); background: var(--bg);
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-font-smoothing: antialiased;
}
input, textarea, select, button { font: inherit; color: inherit; }
input, textarea { -webkit-user-select: text; user-select: text; }
::placeholder { color: var(--muted); opacity: .9; }

button {
  border: 0; border-radius: 12px; padding: 10px 14px; min-height: 44px;
  background: var(--surface-2); color: var(--ink); cursor: pointer; font-weight: 600;
  transition: background .15s, transform .08s;
}
button:active { transform: scale(.98); background: var(--surface-3); }
button.primary { background: var(--accent); color: var(--accent-ink); }
button.primary:active { background: var(--accent); filter: brightness(.92); }
button.danger { background: var(--danger-soft); color: var(--danger); }

svg.ic {
  width: 22px; height: 22px; display: block; margin: auto; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- map ---------- */
#map { position: absolute; inset: 0; background: var(--map-bg); }
.leaflet-container { font: inherit; background: var(--map-bg); }
.leaflet-bottom { bottom: var(--sab); }
.leaflet-container .leaflet-control-attribution {
  font-size: 10px; background: color-mix(in srgb, var(--surface) 80%, transparent); color: var(--muted);
  border-radius: 8px 0 0 0;
}
.leaflet-container .leaflet-control-attribution a { color: var(--muted); }
.tiles-street { filter: var(--tile-filter); }
html.dark .tiles-sat { filter: brightness(.8); }

/* ---------- top bar ---------- */
#topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 1000;
  padding: calc(var(--sat) + 10px) 12px 0;
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }
#topbar .row { display: flex; gap: 8px; align-items: center; }
.iconbtn {
  width: 48px; height: 48px; padding: 0; flex: none; border-radius: 14px;
  background: var(--surface); box-shadow: var(--shadow-sm);
}
#searchWrap {
  flex: 1; min-width: 0; position: relative; height: 48px;
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-sm);
}
#searchWrap .lens {
  position: absolute; left: 14px; top: 13px; color: var(--muted); pointer-events: none; margin: 0;
}
#search {
  width: 100%; height: 48px; border: 2px solid transparent; border-radius: 14px; padding: 0 14px 0 44px;
  font-size: 17px; font-weight: 600; background: transparent; color: var(--ink);
  -webkit-appearance: none; appearance: none; outline: none;
}
#search:focus { border-color: var(--accent); }
#search:disabled { opacity: .6; }
#search::-webkit-search-cancel-button { -webkit-appearance: none; }
#parkName {
  display: inline-block; margin: 8px 0 0 58px; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface); box-shadow: var(--shadow-sm);
  max-width: calc(100% - 58px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#parkName:empty { display: none; }

#adminbar {
  display: flex; gap: 6px; margin-top: 8px; padding: 6px; border-radius: 14px;
  background: var(--surface); box-shadow: var(--shadow-sm);
  overflow-x: auto; scrollbar-width: none;
}
#adminbar::-webkit-scrollbar { display: none; }
#adminbar button {
  flex: 0 0 auto; padding: 8px 12px; min-height: 38px; font-size: 13px; border-radius: 10px;
  background: transparent;
}
#adminbar button.on { background: var(--accent); color: var(--accent-ink); }

#results {
  margin-top: 8px; max-height: 50vh; overflow-y: auto; border-radius: 14px;
  background: var(--surface); box-shadow: var(--shadow); -webkit-overflow-scrolling: touch;
}
#results .res {
  display: flex; gap: 12px; align-items: center; padding: 12px 16px;
  border-bottom: 1px solid var(--line); min-height: 54px;
}
#results .res:last-child { border-bottom: 0; }
#results .res:active { background: var(--surface-2); }
#results .res b { font-size: 19px; min-width: 60px; white-space: nowrap; }
#results .res span { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#results .none { padding: 16px; color: var(--muted); }

/* ---------- banner / toast ---------- */
#banner {
  position: absolute; left: 12px; right: 12px; z-index: 900;
  top: calc(var(--top, 78px) + 10px);
  background: var(--warn-bg); color: var(--warn-ink);
  border-radius: 14px; padding: 8px 8px 8px 14px;
  display: flex; gap: 8px; align-items: center; font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow-sm);
}
#banner span { flex: 1; }
#banner button { min-height: 36px; padding: 6px 12px; font-size: 14px; background: var(--surface); color: var(--ink); }
#banner button.x { background: transparent; color: inherit; padding: 6px 8px; }

#toast {
  position: absolute; left: 50%; top: calc(var(--top, 78px) + 14px); transform: translateX(-50%);
  z-index: 3000; background: var(--ink); color: var(--bg); padding: 10px 16px;
  border-radius: 999px; font-size: 14px; font-weight: 600; max-width: 86vw; text-align: center;
  pointer-events: none; box-shadow: var(--shadow);
}

/* ---------- floating buttons ---------- */
#fabs {
  position: absolute; right: 12px; z-index: 800; display: flex; flex-direction: column; gap: 10px;
  top: calc(var(--top, 78px) + 70px);
}
.fab {
  width: 46px; height: 46px; padding: 0; border-radius: 14px;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm);
}
.fab.on { background: var(--accent); color: var(--accent-ink); }
body.admin #btnExit { display: none; }

#drawbar {
  position: absolute; left: 12px; right: 12px; bottom: calc(var(--sab) + 14px); z-index: 1100;
  background: var(--surface); border-radius: 16px; padding: 8px;
  display: flex; gap: 6px; align-items: center; box-shadow: var(--shadow);
}
#drawbar span { flex: 1; font-size: 13px; color: var(--muted); padding-left: 6px; }
#drawbar button { padding: 8px 12px; }

/* ---------- bottom sheet ---------- */
#sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 1200;
  background: var(--surface); border-radius: 22px 22px 0 0;
  padding: 10px 18px calc(var(--sab) + 16px);
  max-height: 62vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .18);
}
#sheet::before {
  content: ""; display: block; width: 40px; height: 5px; border-radius: 3px;
  background: var(--line); margin: 0 auto 12px;
}
#sheet.compact { max-height: 46vh; }
.sheet-head { display: flex; align-items: flex-start; gap: 10px; }
.sheet-head .grow { flex: 1; min-width: 0; }
.sheet-head h2 { margin: 0; font-size: 26px; line-height: 1.15; font-weight: 700; letter-spacing: -.01em; }
.sheet-head .sub { color: var(--muted); font-size: 15px; margin-top: 2px; }
.sheet-head .x { width: 40px; min-height: 40px; padding: 0; border-radius: 50%; flex: none; }
.sheet-head .x svg { width: 20px; height: 20px; }
.stat { display: flex; gap: 10px; align-items: baseline; margin: 12px 0 4px; }
.stat b { font-size: 26px; color: var(--accent); letter-spacing: -.01em; }
.stat span { color: var(--muted); font-size: 14px; }
.note {
  background: var(--warn-bg); color: var(--warn-ink); border-radius: 12px; padding: 10px 14px; margin: 10px 0;
  font-size: 15px; white-space: pre-wrap; -webkit-user-select: text; user-select: text;
}
.note.warn { background: var(--danger-soft); color: var(--danger); }
.note.ok { background: var(--ok-bg); color: var(--ok-ink); }
.note.bump { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.note.bump svg { flex: none; }
ol.steps { list-style: none; margin: 10px 0 0; padding: 0; }
ol.steps li { padding: 10px 0; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: baseline; }
ol.steps li .t { flex: 1; }
ol.steps li .t small { display: block; color: var(--muted); }
ol.steps li .d { color: var(--muted); font-size: 14px; white-space: nowrap; font-variant-numeric: tabular-nums; }
ol.steps li.walk .t { color: #c2410c; }
html.dark ol.steps li.walk .t { color: #fdba74; }
ol.steps li.arrive .t { font-weight: 700; }
details.rules { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; }
details.rules summary { font-weight: 600; padding: 6px 0; cursor: pointer; }
button.go { font-size: 18px; min-height: 54px; display: flex; align-items: center; justify-content: center; gap: 10px; border-radius: 14px; }
button.go svg.ic { margin: 0; }

/* navigation panel */
.nav .navmain { display: flex; gap: 12px; align-items: baseline; }
.nav .navmain b { font-size: 36px; line-height: 1; color: var(--accent); white-space: nowrap; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.nav .navmain span { font-size: 20px; font-weight: 700; line-height: 1.2; }
.nav.arrived .navmain span { color: var(--ok-ink); font-size: 26px; }
html.dark .nav.arrived .navmain span { color: #4ade80; }
.nav .navsub { color: var(--muted); font-size: 14px; margin-top: 6px; }
.nav .navsub strong { color: var(--ink); }
.nav .btnrow { margin-top: 12px; }

/* menus */
.menu { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.menu button { text-align: left; }
.menu button small { display: block; font-weight: 400; color: var(--muted); }
.menu button.primary small { color: rgba(255, 255, 255, .85); }
.menu .park { display: flex; align-items: center; gap: 10px; }
.menu .park.cur { background: var(--accent-soft); color: var(--ink); }
.menu h3 { margin: 12px 0 0; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.seg { display: flex; padding: 4px; gap: 4px; background: var(--surface-2); border-radius: 12px; }
.seg button { flex: 1; min-height: 38px; padding: 6px; background: transparent; border-radius: 9px; font-size: 14px; }
.seg button.on { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-sm); }

/* ---------- forms ---------- */
label.f { display: block; margin-top: 12px; font-size: 13px; font-weight: 600; color: var(--muted); }
label.f input, label.f textarea, label.f select {
  display: block; width: 100%; margin-top: 5px; padding: 11px 13px; font-size: 17px; font-weight: 400;
  color: var(--ink); border: 1.5px solid var(--line); border-radius: 12px; background: var(--bg);
  -webkit-appearance: none; appearance: none; outline: none;
}
label.f input:focus, label.f textarea:focus, label.f select:focus { border-color: var(--accent); }
label.f textarea { min-height: 80px; resize: vertical; }
.btnrow { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.btnrow button { flex: 1; white-space: nowrap; }
.progress { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin: 12px 0 6px; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* ---------- modal ---------- */
#modal {
  position: absolute; inset: 0; z-index: 2000; background: rgba(10, 14, 20, .5);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
#modal .box {
  background: var(--surface); border-radius: 20px; padding: 20px;
  width: 100%; max-width: 380px; max-height: 80vh; overflow-y: auto; box-shadow: var(--shadow);
}
#modal h3 { margin: 0 0 6px; font-size: 19px; }
#modal p { margin: 0; color: var(--muted); font-size: 15px; white-space: pre-wrap; }

/* ---------- map markers ---------- */
.cv, .pt, .arrow, .ent, .me, .ft { width: 0 !important; height: 0 !important; background: none; border: 0; }
.cv span {
  position: absolute; transform: translate(-50%, -50%);
  background: var(--surface); color: var(--ink); border: 1.5px solid var(--road-ink);
  border-radius: 7px; padding: 0 5px; font-size: var(--cvs, 11px); line-height: 1.5; font-weight: 700; white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
}
.cv.target span {
  background: var(--danger); color: #fff; border-color: #fff; font-size: 15px; padding: 3px 9px; border-radius: 9px;
  box-shadow: 0 0 0 4px rgba(220, 38, 38, .25), 0 2px 8px rgba(0, 0, 0, .35);
}
.cv.sel span { background: #ffd23f; color: #1a1a1a; border-color: #fff; }
.ent span {
  position: absolute; transform: translate(-50%, -50%);
  background: #16a34a; color: #fff; border: 1.5px solid #fff; border-radius: 7px;
  padding: 1px 6px; font-size: 10px; font-weight: 800; letter-spacing: .05em; white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
}
.ent.target span {
  background: var(--danger); font-size: 13px; padding: 2px 8px;
  box-shadow: 0 0 0 4px rgba(220, 38, 38, .25), 0 2px 8px rgba(0, 0, 0, .35);
}
.pt i {
  position: absolute; transform: translate(-50%, -50%);
  width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 3px solid #222;
}
.pt.draw i { width: 12px; height: 12px; border-color: var(--accent); }
.arrow svg { position: absolute; left: -8px; top: -10px; pointer-events: none; }
.me img { position: absolute; left: -21px; top: -21px; width: 42px; height: 42px; pointer-events: none; }
.ft svg { position: absolute; transform: translate(-50%, -50%); filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .5)); }
.ft.sel svg { filter: drop-shadow(0 0 3px #ffd23f) drop-shadow(0 0 3px #ffd23f); }

path.rt { stroke: var(--accent); }
path.rt-case { stroke: var(--surface); }
path.rt-conn { stroke: var(--muted); }
path.rt-off { stroke: var(--danger); }
path.drawline { stroke: var(--accent); }
