:root {
  color-scheme: dark;
  --bar: #0c1620;
  --bg: #151c23;
  --raised: #222d38;
  --raised-2: #2c3945;
  --ink: #e8eef3;
  --muted: #93a1ad;
  --line: #2a3642;
  --blue: #2f95ff;
  --red: #ff5468;
  --orange: #f59a3c;
  --green: #35c46a;
  --amber: #ffd23f;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0; height: 100%; overflow: hidden;
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: #0a0f14;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}

input, textarea, select, button { font: inherit; color: inherit; }
input, textarea { -webkit-user-select: text; user-select: text; }
::placeholder { color: #6f7d89; opacity: 1; }

button {
  border: 0; border-radius: 10px; padding: 10px 14px; min-height: 44px;
  background: var(--raised); color: var(--ink); cursor: pointer; font-weight: 600;
}
button.primary { background: var(--blue); color: #fff; }
button.danger { background: #3d1820; color: #ff8a98; }
button:active { filter: brightness(1.25); }

#map { position: absolute; inset: 0; background: #0e1318; }
.leaflet-container { font: inherit; background: #0e1318; }
.leaflet-bottom { bottom: var(--sab); }
.leaflet-container .leaflet-control-attribution {
  font-size: 10px; background: rgba(12, 22, 32, .75); color: #8fa0ad;
}
.leaflet-container .leaflet-control-attribution a { color: #8fa0ad; }
.tiles-street { filter: invert(1) hue-rotate(180deg) brightness(.9) contrast(.9) saturate(.7); }
.tiles-sat { filter: brightness(.8); }

#topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 1000;
  padding: calc(var(--sat) + 8px) 10px 8px;
  background: var(--bar); color: var(--ink);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 12px rgba(0, 0, 0, .5);
}
#topbar .row { display: flex; gap: 8px; align-items: center; }
.iconbtn { width: 46px; height: 46px; padding: 0; font-size: 22px; flex: none; }
#searchWrap { flex: 1; min-width: 0; }
#search {
  width: 100%; height: 46px; border: 1.5px solid var(--line); border-radius: 10px; padding: 0 14px;
  font-size: 18px; font-weight: 600; background: var(--raised); color: var(--ink);
  -webkit-appearance: none; appearance: none; outline: none;
}
#search:focus { border-color: var(--blue); }
#parkName { font-size: 12px; color: var(--muted); padding: 3px 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#parkName:empty { display: none; }

#adminbar { display: flex; gap: 6px; margin-top: 8px; overflow-x: auto; scrollbar-width: none; }
#adminbar::-webkit-scrollbar { display: none; }
#adminbar button { flex: 1 0 auto; padding: 8px 8px; min-height: 40px; font-size: 13px; }
#adminbar button.on { background: var(--amber); color: #1a1a1a; }

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

#banner {
  position: absolute; left: 10px; right: 10px; z-index: 900;
  top: calc(var(--top, 78px) + 8px);
  background: #33290a; color: #ffe9a6; border: 1px solid #5c4a12;
  border-radius: 10px; padding: 8px 10px 8px 12px;
  display: flex; gap: 8px; align-items: center; font-size: 14px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .5);
}
#banner span { flex: 1; }
#banner button { min-height: 36px; padding: 6px 10px; font-size: 14px; background: var(--amber); color: #1a1a1a; }
#banner button.x { background: transparent; color: #ffe9a6; padding: 6px 8px; }

#toast {
  position: absolute; left: 50%; top: calc(var(--top, 78px) + 12px); transform: translateX(-50%);
  z-index: 3000; background: rgba(232, 238, 243, .96); color: #10171d; padding: 10px 16px;
  border-radius: 20px; font-size: 14px; font-weight: 600; max-width: 86vw; text-align: center; pointer-events: none;
}

#fabs {
  position: absolute; right: 10px; z-index: 800; display: flex; flex-direction: column; gap: 8px;
  top: calc(var(--top, 78px) + 66px);
}
.fab {
  width: 48px; height: 48px; padding: 0; border-radius: 50%; font-size: 22px;
  background: var(--bg); border: 1px solid var(--line); box-shadow: 0 2px 10px rgba(0, 0, 0, .5);
}
.fab.on { background: var(--blue); color: #fff; border-color: var(--blue); }

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

#sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 1200;
  background: var(--bg); border-top: 1px solid var(--line); border-radius: 16px 16px 0 0;
  padding: 14px 16px calc(var(--sab) + 14px);
  max-height: 62vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, .6);
}
#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.1; }
.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%; font-size: 18px; flex: none; }
.stat { display: flex; gap: 10px; align-items: baseline; margin: 10px 0 4px; }
.stat b { font-size: 24px; color: var(--blue); }
.stat span { color: var(--muted); font-size: 14px; }
.note {
  background: #33290a; color: #ffe9a6; border-radius: 10px; padding: 9px 12px; margin: 8px 0;
  font-size: 15px; white-space: pre-wrap; -webkit-user-select: text; user-select: text;
}
.note.warn { background: #3d1820; color: #ffb3bd; }
.note.ok { background: #14351f; color: #a6e8b8; }
ol.steps { list-style: none; margin: 8px 0 0; padding: 0; }
ol.steps li { padding: 9px 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; }
ol.steps li.walk .t { color: var(--orange); }
ol.steps li.arrive .t { font-weight: 700; }
details.rules { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 8px; }
details.rules summary { font-weight: 600; padding: 6px 0; }
button.go { font-size: 18px; min-height: 52px; }

.nav .navmain { display: flex; gap: 12px; align-items: baseline; }
.nav .navmain b { font-size: 34px; line-height: 1; color: var(--blue); white-space: nowrap; }
.nav .navmain span { font-size: 20px; font-weight: 700; line-height: 1.2; }
.nav.arrived .navmain span { color: var(--green); font-size: 26px; }
.nav .navsub { color: var(--muted); font-size: 14px; margin-top: 6px; }
.nav .navsub strong { color: var(--ink); }
.nav .btnrow { margin-top: 12px; }

.menu { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.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, .8); }
.menu .park { display: flex; align-items: center; gap: 10px; }
.menu .park.cur { background: #173a5c; }
.menu h3 { margin: 10px 0 0; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }

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

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

.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: #16202a; color: #fff; border: 1.5px solid #6fb1ff;
  border-radius: 6px; padding: 0 4px; font-size: var(--cvs, 11px); line-height: 1.5; font-weight: 700; white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .6);
}
.cv.target span {
  background: var(--red); color: #fff; border-color: #fff; font-size: 15px; padding: 2px 8px; border-radius: 8px;
  box-shadow: 0 0 0 4px rgba(255, 84, 104, .35), 0 2px 8px rgba(0, 0, 0, .6);
}
.cv.sel span { background: var(--amber); color: #1a1a1a; border-color: #fff; }
.ent span {
  position: absolute; transform: translate(-50%, -50%);
  background: #1e9e4a; color: #fff; border: 1.5px solid #fff; border-radius: 6px;
  padding: 1px 5px; font-size: 10px; font-weight: 800; letter-spacing: .04em; white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .6);
}
.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(--blue); }
.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; }

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;
}
button.go { display: flex; align-items: center; justify-content: center; gap: 10px; }
button.go svg.ic { margin: 0; }

.ft svg { position: absolute; transform: translate(-50%, -50%); filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .7)); }
.ft.sel svg { filter: drop-shadow(0 0 3px var(--amber)) drop-shadow(0 0 3px var(--amber)); }
.ent.target span {
  background: var(--red); font-size: 13px; padding: 2px 8px;
  box-shadow: 0 0 0 4px rgba(255, 84, 104, .35), 0 2px 8px rgba(0, 0, 0, .6);
}
.note.bump { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.note.bump svg { flex: none; }
body.admin #btnExit { display: none; }
#search:disabled { opacity: .55; }
body.tilt #map { will-change: transform; backface-visibility: hidden; }
body.tilt::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 34%; z-index: 500; pointer-events: none;
  background: linear-gradient(#0a0f14 22%, rgba(10, 15, 20, 0));
}
.fab.txt { font-size: 14px; font-weight: 800; letter-spacing: .02em; }
body.admin #btnTilt { display: none; }
body.tilt .cv span, body.tilt .ent span {
  transform: translate(-50%, -100%) scaleY(var(--up, 1.3)); transform-origin: 50% 100%;
}
body.tilt .ft svg {
  transform: translate(-50%, -100%) scale(1.25, calc(1.25 * var(--up, 1.3))); transform-origin: 50% 100%;
}
body.tilt .me img { transform: scaleY(var(--up, 1.3)); }
