:root {
  --bg: #ffffff;
  --panel: rgba(255, 255, 255, .92);
  --ink: #0f1a3a;
  --muted: #5d6b8f;
  --line: rgba(15, 26, 58, .1);
  --accent: #ff6b35;
  --accent2: #f72585;
  --chip: rgba(15, 26, 58, .06);
  --shadow: 0 10px 40px rgba(15, 26, 58, .18);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1228;
    --panel: rgba(16, 24, 52, .9);
    --ink: #eef2ff;
    --muted: #93a2c9;
    --line: rgba(255, 255, 255, .1);
    --chip: rgba(255, 255, 255, .08);
    --shadow: 0 10px 40px rgba(0, 0, 0, .5);
  }
}
:root[data-theme="dark"] {
  --bg: #0b1228; --panel: rgba(16, 24, 52, .9); --ink: #eef2ff; --muted: #93a2c9;
  --line: rgba(255, 255, 255, .1); --chip: rgba(255, 255, 255, .08); --shadow: 0 10px 40px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; font-size: 15px; }
button { font: inherit; color: inherit; cursor: pointer; }

#map { position: fixed; inset: 0; background: var(--bg); }
.leaflet-control-attribution { font-size: 10px; background: var(--panel) !important; color: var(--muted); }
.leaflet-control-attribution a { color: var(--muted); }
.leaflet-top.leaflet-left { top: calc(64px + var(--safe-t)); }
.leaflet-bar a { background: var(--panel); color: var(--ink); border-color: var(--line); }

/* ---------- Kopfzeile ---------- */
.topbar {
  position: fixed; z-index: 1000; top: calc(10px + var(--safe-t)); left: 12px; right: 12px;
  display: flex; align-items: center; gap: 10px; padding: 6px;
  background: var(--panel); border-radius: 18px; box-shadow: var(--shadow);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  animation: drop .6s cubic-bezier(.2, .9, .3, 1.2) both;
}
@keyframes drop { from { transform: translateY(-120%); opacity: 0; } }
.tabs { display: flex; background: var(--chip); border-radius: 13px; padding: 3px; position: relative; }
.tabs button {
  border: 0; background: none; padding: 7px 14px; border-radius: 10px; font-weight: 600; color: var(--muted);
  position: relative; z-index: 1; transition: color .25s;
}
.tabs button.active { color: #fff; }
.tabs .pill {
  position: absolute; top: 3px; bottom: 3px; border-radius: 10px; z-index: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  transition: left .35s cubic-bezier(.3, 1.3, .5, 1), width .35s;
}
.clock {
  margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 700; font-size: 22px; letter-spacing: -.02em;
}
.icon-btn { border: 0; background: var(--chip); width: 38px; height: 38px; border-radius: 12px; font-size: 20px; line-height: 1; }
.menu {
  position: absolute; top: calc(100% + 8px); right: 0; min-width: 230px; padding: 6px;
  background: var(--panel); border-radius: 16px; box-shadow: var(--shadow);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  animation: pop .2s ease-out;
}
@keyframes pop { from { transform: scale(.95) translateY(-6px); opacity: 0; } }
.menu button, .menu .menu-item {
  display: block; width: 100%; text-align: left; border: 0; background: none; padding: 11px 12px;
  border-radius: 10px; color: var(--ink); text-decoration: none; cursor: pointer;
}
.menu button:hover, .menu .menu-item:hover { background: var(--chip); }
.menu form { margin: 0; }

/* ---------- Bottom-Sheet ---------- */
.sheet {
  position: fixed; z-index: 1000; left: 0; right: 0; bottom: 0;
  background: var(--panel); border-radius: 22px 22px 0 0; box-shadow: var(--shadow);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  padding: 0 16px calc(12px + var(--safe-b));
  max-height: 72vh; display: flex; flex-direction: column;
  transform: translateY(calc(100% - var(--peek, 190px)));
  transition: transform .4s cubic-bezier(.2, .9, .3, 1);
  animation: up .7s .1s cubic-bezier(.2, .9, .3, 1.1) both;
}
@keyframes up { from { transform: translateY(100%); } }
.sheet.open { transform: translateY(0); }
.handle { padding: 10px 0 6px; display: grid; place-items: center; cursor: grab; touch-action: none; }
.handle span { width: 42px; height: 5px; border-radius: 3px; background: var(--line); background: var(--muted); opacity: .4; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--chip); border-radius: 14px; padding: 6px 6px; text-align: center; }
.stat b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; transition: transform .25s; }
.stat b.bump { animation: bump .45s; }
@keyframes bump { 40% { transform: scale(1.35); color: var(--accent); } }
.stat small { color: var(--muted); font-size: 11px; white-space: nowrap; }

.controls { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.play {
  flex: none; width: 48px; height: 48px; border-radius: 50%; border: 0; font-size: 18px; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent2)); box-shadow: 0 6px 18px #f7258555;
  transition: transform .15s;
}
.play:active { transform: scale(.92); }
.speed { flex: none; border: 0; background: var(--chip); border-radius: 12px; padding: 0 10px; height: 36px; font-weight: 700; min-width: 54px; font-size: 13px; }
.slider-wrap { flex: 1; position: relative; padding-top: 8px; }
.ticks { position: absolute; left: 11px; right: 11px; top: 0; height: 8px; }
.ticks i { position: absolute; top: 0; width: 3px; height: 8px; border-radius: 2px; transform: translateX(-50%); opacity: .8; }
input[type=range] { width: 100%; -webkit-appearance: none; appearance: none; background: none; height: 28px; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: linear-gradient(90deg, var(--accent) var(--p, 0%), var(--chip) var(--p, 0%)); }
input[type=range]::-moz-range-track { height: 6px; border-radius: 3px; background: linear-gradient(90deg, var(--accent) var(--p, 0%), var(--chip) var(--p, 0%)); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; margin-top: -8px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); box-shadow: 0 2px 8px rgba(0,0,0,.25); }
input[type=range]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); }
.range-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: -2px; }

.details { margin-top: 10px; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.seg { display: flex; gap: 6px; margin-bottom: 8px; }
.seg button { flex: 1; border: 0; background: var(--chip); padding: 8px; border-radius: 10px; font-weight: 600; color: var(--muted); }
.seg button.active { background: var(--ink); color: var(--bg); }
.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1; }
.list li {
  display: flex; align-items: center; gap: 10px; padding: 9px 6px; border-bottom: 1px solid var(--line);
  cursor: pointer; border-radius: 10px; transition: background .2s;
}
.list li:hover { background: var(--chip); }
.list li.selected { background: var(--chip); box-shadow: inset 3px 0 0 var(--accent); }
.list li .meta { flex: 1; min-width: 0; }
.list li .meta b { display: block; }
.list li .meta small { color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list li.past { opacity: .5; }
.list li.now { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.list .time { font-variant-numeric: tabular-nums; font-weight: 700; width: 46px; flex: none; }
.list .ev-icon { width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center; background: var(--chip); flex: none; }
.state { font-size: 11px; padding: 3px 8px; border-radius: 20px; background: var(--chip); color: var(--muted); white-space: nowrap; }
.state.driving { background: #2ec4b622; color: #12a594; }
.state.waiting { background: #ffbe0b26; color: #c48a00; }
.state.arrived { background: #8ac92626; color: #5b8f0f; }
.savings { color: var(--muted); font-size: 12.5px; text-align: center; margin: 8px 0 0; }

/* ---------- Kartenelemente ---------- */
.av {
  width: 26px; height: 26px; border-radius: 50%; display: inline-grid; place-items: center; flex: none;
  color: #fff; font-size: 10.5px; font-weight: 800; letter-spacing: -.02em; border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.list .av { width: 34px; height: 34px; font-size: 12px; }

.car-icon { background: none; border: 0; }
.car {
  position: absolute; left: 0; top: 0; width: 0; height: 0;
  transition: margin .4s ease, opacity .3s;
}
.car .dir { position: absolute; left: -30px; top: -20px; display: block; transform-origin: 30px 20px; transition: transform .25s; }
.car .toon { display: block; overflow: visible; filter: drop-shadow(0 3px 2px rgba(0,0,0,.35)); animation: carPop .45s cubic-bezier(.2, .9, .3, 1.6) both; }
@keyframes carPop { from { transform: scale(0) rotate(-20deg); } }
.car .chassis { animation: bob .32s ease-in-out infinite alternate; }
@keyframes bob { to { transform: translateY(-1.3px) rotate(-.6deg); } }
.car .wheel { animation: spin .35s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.car .speedlines path { stroke: currentColor; color: var(--ink); stroke-width: 2.4; stroke-linecap: round; fill: none; stroke-dasharray: 6 18; animation: whoosh .5s linear infinite; opacity: .55; }
.car .speedlines path:nth-child(2) { animation-delay: -.17s; }
.car .speedlines path:nth-child(3) { animation-delay: -.33s; }
@keyframes whoosh { from { stroke-dashoffset: 0; } to { stroke-dashoffset: 24; } }
.car .puffs circle { fill: #cfd6e6; stroke: #141414; stroke-width: 1; transform-box: fill-box; transform-origin: center; animation: puff 0.9s ease-out infinite; }
.car .puffs circle:nth-child(2) { animation-delay: -.45s; }
@keyframes puff { from { transform: translate(0, 0) scale(.4); opacity: .9; } to { transform: translate(-14px, -6px) scale(1.6); opacity: 0; } }
.car.dim { opacity: .3; }
.car.focus .toon { filter: drop-shadow(0 0 5px var(--c)) drop-shadow(0 0 2px #fff) drop-shadow(0 3px 2px rgba(0,0,0,.35)); }

/* Ein-/Aussteigen: Auto steht still und wackelt beim "Reinplumpsen" */
.car.boarding .chassis, .car.parking .chassis { animation: squash .35s var(--squash-delay, 0ms) cubic-bezier(.3, 1.8, .5, 1) both, bob .32s calc(var(--squash-delay, 0ms) + .35s) ease-in-out infinite alternate; }
.car.stopped .wheel, .car.parking .wheel { animation-play-state: paused; }
.car.stopped .speedlines, .car.parking .speedlines, .car.stopped .puffs, .car.parking .puffs { display: none; }
@keyframes squash { 0% { transform: scale(1); } 35% { transform: translateY(3px) scale(1.08, .86); } 70% { transform: translateY(-2px) scale(.96, 1.06); } 100% { transform: none; } }

.jumper { position: absolute; left: 0; top: 0; z-index: 2; pointer-events: none; }
.jumper .fig { position: absolute; left: -7px; top: -24px; }
.jumper.in .fig { animation: jumpIn .55s var(--d) cubic-bezier(.4, 0, .6, 1) both; }
@keyframes jumpIn {
  0% { transform: translate(var(--dx), -22px) scale(1); }
  20% { transform: translate(var(--dx), -18px) scale(1.15, .8); }
  55% { transform: translate(calc(var(--dx) * .4), -52px) scale(1) rotate(-15deg); }
  100% { transform: translate(0, 6px) scale(.35) rotate(-30deg); opacity: 0; }
}
.jumper.out .fig { animation: jumpOut .6s var(--d) cubic-bezier(.4, 0, .6, 1) both; }
@keyframes jumpOut {
  0% { transform: translate(0, 6px) scale(.35); opacity: 0; }
  15% { opacity: 1; }
  50% { transform: translate(calc(var(--dx) * .5), -50px) scale(1) rotate(15deg); }
  85% { transform: translate(var(--dx), -20px) scale(1.12, .85); }
  100% { transform: translate(var(--dx), -22px) scale(1); opacity: 0; }
}
.car.parking .toon { animation: poofCar .35s var(--poof-delay) ease-in both; }
@keyframes poofCar { to { transform: scale(0) rotate(15deg); opacity: 0; } }
.poof { position: absolute; left: 0; top: 0; }
.poof i {
  position: absolute; width: 16px; height: 16px; margin: -8px 0 0 -8px; border-radius: 50%;
  background: #eef1f8; border: 2px solid #141414; opacity: 0;
  animation: cloud .55s var(--poof-delay) ease-out both;
}
.poof i:nth-child(1) { --x: -18px; --y: -6px; }
.poof i:nth-child(2) { --x: 16px; --y: -8px; }
.poof i:nth-child(3) { --x: 0; --y: -18px; width: 20px; height: 20px; }
.poof i:nth-child(4) { --x: -10px; --y: 10px; }
.poof i:nth-child(5) { --x: 12px; --y: 9px; }
@keyframes cloud { 0% { transform: scale(.2); opacity: 1; } 60% { opacity: 1; } 100% { transform: translate(var(--x), var(--y)) scale(1.4); opacity: 0; } }

/* Comic-Figur: Kopf mit Initiale + Körper */
.fig {
  position: relative; display: inline-block; width: 14px; height: 24px; margin: 0 -1px;
  animation: idle 1.4s calc(var(--i, 0) * -.23s) ease-in-out infinite;
}
.fig b {
  position: absolute; left: 0; top: 0; width: 14px; height: 14px; border-radius: 50%;
  background: var(--c); border: 2px solid #141414; color: #fff;
  font: 800 8px/10px -apple-system, sans-serif; text-align: center; z-index: 1;
}
.fig::after {
  content: ""; position: absolute; left: 2px; top: 11px; width: 10px; height: 12px;
  border-radius: 5px 5px 3px 3px; background: var(--c); border: 2px solid #141414; filter: brightness(.8);
}
@keyframes idle { 50% { transform: translateY(-2px); } }
.fig.late { animation: figIn .3s both, idle 1.4s .3s ease-in-out infinite; }
@keyframes figIn { from { transform: scale(0); opacity: 0; } }

/* Comic-Ausruf an Treffpunkten */
.burst { position: absolute; left: 0; top: 0; pointer-events: none; }
.burst svg { position: absolute; width: 124px; height: 82px; left: -62px; top: -98px; overflow: visible; animation: burstPop 1.8s cubic-bezier(.2, 1.6, .4, 1) both; }
.burst path { fill: #ffe14d; stroke: #141414; stroke-width: 3; stroke-linejoin: round; }
.burst.split path { fill: #c9a7ff; }
.burst.arrive path { fill: #a6f07a; }
.burst.start path { fill: #fff; }
.burst span {
  position: absolute; z-index: 300; left: -60px; width: 120px; top: -66px; text-align: center; white-space: nowrap; line-height: 1;
  font-family: "Bangers", "Comic Sans MS", system-ui, sans-serif; font-size: 18px; letter-spacing: .03em; color: #141414;
  animation: burstPop 1.8s cubic-bezier(.2, 1.6, .4, 1) both; transform-origin: center 10px;
}
@keyframes burstPop {
  0% { transform: scale(0) rotate(-25deg); opacity: 0; }
  18% { transform: scale(1.1) rotate(-6deg); opacity: 1; }
  30% { transform: scale(1) rotate(-8deg); }
  80% { transform: scale(1) rotate(-8deg); opacity: 1; }
  100% { transform: scale(.6) rotate(-8deg) translateY(-10px); opacity: 0; }
}

.place-icon { background: none; border: 0; }
.place {
  position: absolute; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center;
}
.place .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--panel); border: 3px solid var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.3); }
.place.meet .dot { width: 16px; height: 16px; border-color: var(--accent); }
.place.goal .dot { width: 20px; height: 20px; border-color: var(--accent2); }
.place .label {
  margin-top: 4px; font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 6px;
  background: var(--panel); color: var(--ink); white-space: nowrap; box-shadow: 0 1px 4px rgba(0,0,0,.15);
}
.place .crowd { position: absolute; top: -27px; display: flex; align-items: flex-end; }
.place .crowd.home { opacity: .55; }
.place .crowd .more { font: 800 10px/1 -apple-system, sans-serif; background: var(--panel); border: 2px solid #141414; border-radius: 8px; padding: 2px 4px; margin-left: 3px; }
.place.active .dot::after {
  content: ""; position: absolute; left: 50%; top: 0; width: 16px; height: 16px; margin-left: -8px; border-radius: 50%;
  border: 2px solid var(--accent); animation: ping 1.6s ease-out infinite;
}
@keyframes ping { to { transform: scale(3); opacity: 0; } }
.place.flash .dot { animation: flash 1s ease-out 2; }
@keyframes flash { 50% { transform: scale(1.8); background: var(--accent); } }

.route-draw { animation: draw 1.6s ease-out both; }
@keyframes draw { from { stroke-dashoffset: var(--len); } }

/* ---------- Toasts / Overlay ---------- */
.toasts { position: fixed; z-index: 1100; top: calc(70px + var(--safe-t)); left: 12px; right: 12px; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast {
  background: var(--panel); box-shadow: 4px 4px 0 #141414; border: 2.5px solid #141414; border-radius: 14px; padding: 9px 14px; font-weight: 700; font-size: 14px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); max-width: 420px;
  animation: toastIn .45s cubic-bezier(.2, .9, .3, 1.3) both, toastOut .4s 2.2s ease-in forwards;
}
@keyframes toastIn { from { transform: translateY(-20px) scale(.9); opacity: 0; } }
@keyframes toastOut { to { transform: translateY(-10px); opacity: 0; } }
.overlay { position: fixed; inset: 0; z-index: 2000; display: grid; place-content: center; justify-items: center; background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(6px); text-align: center; padding: 16px; }
.overlay[hidden] { display: none; }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 4px solid var(--chip); border-top-color: var(--accent); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Desktop: Seitenleiste ---------- */
@media (min-width: 900px) {
  .topbar { right: auto; width: 420px; }
  .sheet {
    left: auto; right: 12px; top: calc(12px + var(--safe-t)); bottom: 12px; width: 380px; max-height: none;
    border-radius: 22px; transform: none !important; padding-bottom: 12px;
    animation: slideIn .7s .1s cubic-bezier(.2, .9, .3, 1.1) both;
  }
  @keyframes slideIn { from { transform: translateX(110%) !important; } }
  .handle { visibility: hidden; padding: 4px 0; }
  .toasts { left: 444px; right: 404px; }
  .leaflet-top.leaflet-left { top: 70px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
.zoom-low .place:not(.meet):not(.goal) .label { display: none; }
.leaflet-tile-pane { filter: saturate(.75) contrast(.95); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .leaflet-tile-pane { filter: invert(1) hue-rotate(185deg) brightness(.85) contrast(.9) saturate(.6); }
}
:root[data-theme="dark"] .leaflet-tile-pane { filter: invert(1) hue-rotate(185deg) brightness(.85) contrast(.9) saturate(.6); }

.list .own { font-size: 12px; margin-left: 2px; }
