:root {
  --bg: #0b1220;
  --panel: #111827;
  --card: #1e293b;
  --card2: #243247;
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #f59e0b;
  --accent2: #38bdf8;
  --ok: #22c55e;
  --warn: #fbbf24;
  --danger: #ef4444;
  --line: #334155;
  --radius: 16px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --touch: 48px;
  font-family: system-ui, -apple-system, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  height: 100%;
  height: 100dvh;
  height: -webkit-fill-available;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
body { position: fixed; inset: 0; width: 100%; }

button, select { font: inherit; color: inherit; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); border: 0;
}
.hidden { display: none !important; }

.app {
  height: 100%;
  height: 100dvh;
  height: -webkit-fill-available;
  overflow: hidden;
}
.start-screen { overflow: auto; -webkit-overflow-scrolling: touch; }


/* ===== START SCREEN ===== */
.start-screen {
  min-height: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(20px + var(--safe-t)) 16px calc(20px + var(--safe-b));
  max-width: 560px;
  margin: 0 auto;
}
.start-hero h1 {
  margin: 4px 0 8px;
  font-size: clamp(1.8rem, 6vw, 2.4rem);
  letter-spacing: -0.02em;
}
.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  color: var(--accent);
  font-weight: 700;
}
.lede { margin: 0; color: var(--muted); line-height: 1.45; font-size: 1rem; }

.tour-picker {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 20px 0;
  padding-bottom: 8px;
}
.tour-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: start;
  text-align: left;
  width: 100%;
  background: linear-gradient(160deg, var(--card) 0%, #172033 100%);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  cursor: pointer;
  touch-action: manipulation;
  min-height: 88px;
  -webkit-tap-highlight-color: transparent;
}
.tour-card:active { transform: scale(0.985); }
.tour-card:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; }
.tour-emoji {
  width: 52px; height: 52px;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem;
  background: rgba(245,158,11,.12);
  border: 1px solid rgba(245,158,11,.25);
}
.tour-card h2 {
  margin: 0 0 4px;
  font-size: 1.1rem;
  line-height: 1.25;
}
.tour-card .sub {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip, .chip-mini {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.75rem;
  color: var(--text);
  font-weight: 600;
}
.chip-mini { padding: 2px 8px; font-size: 0.7rem; color: var(--accent2); }
.start-footer {
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}


/* ===== TOUR SCREEN: full-bleed map ===== */
.tour-screen {
  position: absolute;
  inset: 0;
  height: 100%;
  height: 100dvh;
  height: -webkit-fill-available;
  overflow: hidden;
}
.map-topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 800;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  padding: calc(8px + var(--safe-t)) 10px 8px;
  background: rgba(11,18,32,.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.map-topbar-title { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.map-topbar-title strong {
  font-size: 0.9rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.gps-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.72rem; color: var(--muted);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: #64748b; flex-shrink: 0; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(34,197,94,.25); }
.dot.warn { background: var(--warn); }
.dot.off { background: #64748b; }
.speed-wrap select {
  min-height: 40px; min-width: 64px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 0 8px;
}

#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  background: #070d18;
}
.leaflet-top.leaflet-left { display: none; } /* hide zoom — pinch is enough */
.leaflet-control-attribution {
  font-size: 9px !important;
  background: rgba(11,18,32,.75) !important;
  color: #94a3b8 !important;
  margin: 0 4px 2px 0 !important;
  max-width: 55vw;
}

.map-fabs {
  position: absolute;
  right: 10px;
  z-index: 750;
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* bottom set via --sheet-h in JS */
  bottom: calc(var(--sheet-h, 140px) + 12px);
  transition: bottom 0.22s ease;
}
.fab {
  min-height: 44px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(17,24,39,.92);
  backdrop-filter: blur(8px);
  color: var(--text);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 4px 16px rgba(0,0,0,.35);
}

/* ===== 3-STATE PLAYER SHEET ===== */
.player-sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 900;
  display: flex;
  flex-direction: column;
  background: rgba(17,24,39,.97);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  border: 1px solid var(--line);
  border-bottom: 0;
  box-shadow: 0 -8px 32px rgba(0,0,0,.45);
  transition: height 0.25s ease;
  overflow: hidden;
  padding-bottom: var(--safe-b);
  /* heights set by state classes */
}
.player-sheet.sheet-collapsed {
  height: calc(132px + var(--safe-b));
}
.player-sheet.sheet-collapsed.has-start-actions {
  height: calc(178px + var(--safe-b));
}
.player-sheet.sheet-half {
  height: min(42vh, 340px);
}
.player-sheet.sheet-expanded {
  height: min(78vh, 620px);
}

.sheet-handle-hit {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  min-height: 28px;
  padding: 8px 0 4px;
  background: transparent;
  border: 0;
  cursor: pointer;
  touch-action: none;
  flex-shrink: 0;
}
.sheet-handle {
  width: 42px; height: 4px;
  border-radius: 999px;
  background: #64748b;
  display: block;
}

.sheet-core {
  padding: 0 14px 8px;
  flex-shrink: 0;
}
.nav-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
}
.nav-compass {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: var(--card);
  border: 2px solid var(--line);
  display: flex; align-items: center; justify-content: center;
}
.nav-arrow {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--accent2);
  transform-origin: 50% 55%;
  transition: transform 0.2s ease;
}
.nav-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  display: flex; align-items: center; gap: 6px;
}
.chip-mini {
  display: inline-flex;
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 0.68rem;
  color: var(--accent2);
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0;
}
.nav-name {
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.2;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-meta {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.btn.play.compact {
  width: 52px;
  height: 52px;
  min-height: 52px;
  border-radius: 16px;
  padding: 0;
  font-size: 1.2rem;
  background: var(--accent2);
  color: #042f4a;
  border: 1px solid #0ea5e9;
  flex-shrink: 0;
}
.collapsed-actions {
  display: none;
  grid-template-columns: 1.4fr 0.8fr;
  gap: 8px;
  margin-top: 8px;
}
.player-sheet.has-start-actions .collapsed-actions { display: grid; }
.player-sheet.tour-started .collapsed-actions { display: none !important; }

.sheet-extra, .sheet-full {
  display: none;
  padding: 0 14px 10px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  min-height: 0;
}
.player-sheet.sheet-half .sheet-extra,
.player-sheet.sheet-expanded .sheet-extra { display: block; }
.player-sheet.sheet-expanded .sheet-full { display: block; }

.player-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.player-controls .btn.icon {
  flex: 1;
  min-height: 44px;
  font-size: 1.2rem;
}

.now-block {
  background: #0f172a;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
}
.now-title { color: var(--accent); font-weight: 800; margin-bottom: 6px; font-size: 0.95rem; }
.now-text {
  font-size: 0.88rem;
  line-height: 1.4;
  max-height: 6.5em;
  overflow: auto;
  color: #e2e8f0;
}
.player-sheet.sheet-expanded .now-text { max-height: 10em; }
.photo-tip {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(56,189,248,.1);
  border: 1px solid rgba(56,189,248,.35);
  color: #e0f2fe;
  font-size: 0.82rem;
  line-height: 1.35;
}
.photo-tip::before {
  content: "📷 Fototipp · ";
  font-weight: 800;
  color: var(--accent2);
}

.stops-heading {
  margin: 4px 0 8px;
  font-size: 0.85rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
#stops { margin: 0; padding-left: 1.1rem; }
#stops li {
  margin: 6px 0;
  padding: 8px 6px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.88rem;
}
#stops li.current { background: rgba(56,189,248,.15); color: var(--accent2); font-weight: 700; }
#stops li.done { color: var(--muted); }
#stops li .dist { display: block; font-size: 0.72rem; color: var(--muted); font-weight: 500; }
#stops li .tip {
  display: block; margin-top: 4px; font-size: 0.75rem; color: #7dd3fc; font-weight: 500;
}
.caveats-list {
  margin: 8px 0 4px; padding-left: 1.1rem;
  color: var(--muted); font-size: 0.8rem;
}
.caveats-list li { margin-bottom: 6px; }

.btn {
  min-height: var(--touch);
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card);
  padding: 10px 14px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  font-weight: 700;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #111; border-color: #d97706; }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; }
.btn.chip { min-height: 40px; border-radius: 999px; padding: 0 12px; font-size: 0.85rem; }

.leaflet-container { background: #070d18; font: inherit; }
.num-marker {
  background: var(--accent); color: #111;
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 0.8rem;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.45);
}
.num-marker.done { background: #64748b; }
.num-marker.current { background: var(--accent2); color: #042; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 3000;
  background: #0f172a;
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 8px 10px 8px 16px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  font-size: 0.9rem;
  white-space: nowrap;
}

@media (min-width: 900px) {
  .player-sheet.sheet-collapsed { height: calc(140px + var(--safe-b)); }
  .player-sheet.sheet-half { height: 380px; }
  .player-sheet.sheet-expanded { height: min(85vh, 720px); width: min(420px, 40vw); left: auto; right: 12px; bottom: 12px; border-radius: 18px; border: 1px solid var(--line); }
}

/* ---- fixes round 2 ---- */
.nav-text { min-width: 0; }
.nav-row { grid-template-columns: 52px minmax(0, 1fr) 52px; }
#stops { list-style: none; padding-left: 0; }
/* expanded: whole sheet scrolls, sections stack naturally */
.player-sheet.sheet-expanded { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.player-sheet.sheet-expanded .sheet-extra,
.player-sheet.sheet-expanded .sheet-full { flex: none; overflow: visible; }
.player-sheet.sheet-expanded .now-text { max-height: none; }
.player-sheet.sheet-expanded .sheet-handle-hit {
  position: sticky; top: 0; z-index: 2;
  background: rgba(17,24,39,.97);
}
/* hide FABs when sheet is not collapsed or when they'd collide with header */
.tour-screen.sheet-open .map-fabs { opacity: 0; pointer-events: none; }
.map-fabs { transition: bottom .22s ease, opacity .15s ease; }

/* prev / transport */
.nav-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.nav-actions .btn.mini {
  width: 40px; height: 40px; min-width: 40px; padding: 0;
  font-size: 16px; border-radius: 12px;
  opacity: 0; pointer-events: none;
}
.player-sheet.tour-started .nav-actions .btn.mini {
  opacity: 1; pointer-events: auto;
}
.player-sheet:not(.tour-started) #btn-prev-mini { display: none; }
.nav-row { grid-template-columns: 52px minmax(0, 1fr) auto; }
.player-controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
