:root {
  --bg: #140f3a;
  --bg2: #241a5c;
  --card: rgba(255, 255, 255, 0.08);
  --card-strong: rgba(255, 255, 255, 0.14);
  --line: rgba(255, 255, 255, 0.14);
  --text: #f6f3ff;
  --muted: #b9b1e0;
  --gold: #ffcf5a;
  --pink: #ff6fae;
  --cyan: #6fe7ff;
  --parc: #ff6fae;
  --village: #ffb347;
  --adventure: #6fe7ff;
  --accent: var(--parc);
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; width: 100%; margin: 0; overflow: hidden; }
body {
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(120% 60% at 50% 0%, #3b2a8a 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- App-Rahmen: alles auf einem Screen ---------- */
.app {
  height: 100dvh;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto 1fr auto auto;
  padding-top: var(--safe-t);
  overflow: hidden;
}
.app > * { min-width: 0; }

/* ---------- Header ---------- */
.top { padding: 12px 16px 8px; }
.brand { display: flex; gap: 12px; align-items: center; }
.badge-40 {
  flex: none;
  width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 900; font-size: 20px; color: #2b1600;
  background: conic-gradient(from 210deg, #ffe39a, var(--gold), #ff9f43, #ffe39a);
  box-shadow: 0 0 0 3px rgba(255, 207, 90, 0.25), 0 6px 20px rgba(255, 159, 67, 0.35);
}
h1 { margin: 0; font-size: 19px; line-height: 1.15; letter-spacing: -0.01em; }
.sub { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.next {
  margin-top: 10px;
  font-size: 13px;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  min-height: 36px;
}
.next:empty { display: none; }
.next .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 10px var(--gold); flex: none; animation: pulse 1.6s infinite; }
.next b { color: var(--gold); }

/* ---------- Tabs ---------- */
.tabs {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 4px; margin: 2px 12px 8px; padding: 4px;
  background: rgba(0, 0, 0, 0.25); border-radius: 14px; border: 1px solid var(--line);
}
.tab {
  border: 0; background: transparent; border-radius: 10px;
  padding: 8px 4px; font-size: 12.5px; font-weight: 700; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  transition: background 0.2s, color 0.2s;
}
.tab .e { font-size: 17px; }
.tab[aria-selected="true"] { background: var(--card-strong); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }

/* ---------- Karte ---------- */
.map-wrap { position: relative; margin: 0 12px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); min-height: 0; }
#map { position: absolute; inset: 0; background: #1d1650; }
.leaflet-container { font: inherit; }
.leaflet-control-attribution { font-size: 9px; background: rgba(20, 15, 58, 0.6) !important; color: var(--muted); }
.leaflet-control-attribution a { color: var(--muted); }
.leaflet-tile-pane { filter: saturate(1.1); }

.map-tools { position: absolute; right: 10px; top: 10px; z-index: 500; display: flex; flex-direction: column; gap: 8px; }
.fab {
  width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(20, 15, 58, 0.82);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: grid; place-items: center; font-size: 18px; color: var(--text);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
.fab.active { color: #0b2a44; background: var(--cyan); }
.fab[hidden] { display: none; }

.map-note {
  position: absolute; left: 10px; right: 62px; top: 10px; z-index: 500;
  font-size: 12px; line-height: 1.35; padding: 8px 10px; border-radius: 12px;
  background: rgba(20, 15, 58, 0.88); border: 1px solid var(--line);
}
.map-note[hidden] { display: none; }

/* Marker */
.pin {
  --c: var(--accent);
  width: 34px; height: 34px; border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: var(--c);
  display: grid; place-items: center;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.45), 0 0 0 2px #fff;
  transition: transform 0.2s;
}
.pin span { transform: rotate(45deg); font-size: 16px; line-height: 1; }
.pin.past { filter: grayscale(0.8) brightness(0.8); }
.pin.now { animation: bob 1.2s ease-in-out infinite; box-shadow: 0 0 0 3px var(--gold), 0 0 22px var(--gold); }
.pin.selected { transform: rotate(-45deg) scale(1.25); }
.pin-time {
  position: absolute; left: 50%; top: 38px; transform: translateX(-50%);
  font-size: 10.5px; font-weight: 800; white-space: nowrap;
  padding: 1px 6px; border-radius: 8px; background: rgba(20, 15, 58, 0.9); color: #fff;
}
.me-dot {
  width: 18px; height: 18px; border-radius: 50%;
  background: #2f8cff; border: 3px solid #fff;
  box-shadow: 0 0 0 0 rgba(47, 140, 255, 0.6); animation: ping 2s infinite;
}
.lm-dot { width: 12px; height: 12px; border-radius: 50%; background: rgba(255,255,255,0.75); border: 2px solid #140f3a; }
.calib-dot { width: 16px; height: 16px; border-radius: 50%; background: var(--gold); border: 3px solid #140f3a; box-shadow: 0 0 0 2px var(--gold); }

/* Kalibrier-Leiste */
.calib {
  position: absolute; left: 8px; right: 8px; bottom: 8px; z-index: 600;
  padding: 10px; border-radius: 14px; background: rgba(20, 15, 58, 0.95); border: 1px solid var(--gold);
}
.calib[hidden] { display: none; }
.calib-text { font-size: 13px; margin-bottom: 8px; }
.calib-text b { color: var(--gold); }
.calib-actions { display: flex; gap: 6px; }
.calib-actions button, .export-actions button {
  flex: 1; padding: 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-size: 13px; font-weight: 700;
}
.calib-actions .primary, .export-actions .primary { background: var(--gold); color: #2b1600; border-color: var(--gold); }

/* ---------- Stationen ---------- */
.stations {
  display: flex; gap: 10px;
  overflow-x: auto; scroll-snap-type: x mandatory;
  padding: 10px 12px 6px;
  scrollbar-width: none;
}
.stations::-webkit-scrollbar { display: none; }
.card {
  flex: 0 0 78%;
  scroll-snap-align: center;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 16px;
  padding: 10px 12px;
  display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; align-items: center;
  transition: background 0.2s, border-color 0.2s, opacity 0.2s;
  min-height: 92px;
}
.card .em { grid-row: span 3; font-size: 28px; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; background: rgba(0,0,0,0.25); }
.card .time { font-size: 12px; font-weight: 800; color: var(--accent); display: flex; gap: 6px; align-items: center; }
.card .title { font-size: 15px; font-weight: 800; line-height: 1.2; }
.card .place { font-size: 12px; color: var(--muted); line-height: 1.25; }
.card .tip { grid-column: 1 / -1; font-size: 11.5px; color: var(--muted); margin-top: 6px; line-height: 1.3; display: none; }
.card.selected { background: var(--card-strong); border-color: var(--accent); }
.card.selected .tip { display: block; }
.card.past { opacity: 0.55; }
.tag { font-size: 10px; font-weight: 800; padding: 1px 6px; border-radius: 6px; background: var(--gold); color: #2b1600; }
.tag.next { background: var(--cyan); color: #0b2a44; }
.tag.dist { background: rgba(255,255,255,0.15); color: var(--text); }
.tag.wait-low { background: #3ee07a; color: #052e16; }
.tag.wait-mid { background: var(--gold); color: #2b1600; }
.tag.wait-high { background: #ff5b84; color: #fff; }
.tag.wait-closed { background: rgba(255,255,255,0.14); color: var(--muted); }

/* ---------- Pawel-Leiste ---------- */
.pawel-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 12px calc(10px + var(--safe-b));
}
.pawel-avatar {
  position: relative; flex: none; padding: 0; border: 0; background: none;
  width: 56px; height: 56px; border-radius: 50%;
}
.pawel-avatar img {
  width: 56px; height: 56px; border-radius: 50%; object-fit: cover; display: block;
  box-shadow: 0 0 0 3px var(--gold), 0 6px 20px rgba(255, 207, 90, 0.35);
  animation: wave 4s ease-in-out infinite;
}
.online { position: absolute; right: 2px; bottom: 2px; width: 13px; height: 13px; border-radius: 50%; background: #3ee07a; border: 2px solid var(--bg); }
.pawel-prompt {
  flex: 1; min-width: 0; overflow: hidden; text-align: left;
  border: 1px solid var(--line); background: var(--card);
  border-radius: 999px; padding: 9px 16px;
  display: flex; flex-direction: column;
}
.pawel-prompt strong { font-size: 13px; }
.pawel-prompt span { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Chat ---------- */
dialog { color: var(--text); }
.chat {
  border: 0; padding: 0; margin: auto auto 0;
  width: 100%; max-width: 520px;
  height: min(78dvh, 680px); max-height: 100dvh;
  border-radius: 22px 22px 0 0;
  background: linear-gradient(180deg, #2a1f6b, #17113f);
  display: none; flex-direction: column;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
}
.chat[open] { display: flex; animation: up 0.28s ease-out; }
.chat::backdrop { background: rgba(5, 3, 20, 0.55); backdrop-filter: blur(2px); }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 14px 14px 10px; border-bottom: 1px solid var(--line); }
.chat-head img { border-radius: 50%; box-shadow: 0 0 0 2px var(--gold); }
.chat-head h2 { margin: 0; font-size: 16px; }
.chat-head p { margin: 0; font-size: 12px; color: var(--muted); }
.chat-close { margin-left: auto; width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--card); font-size: 15px; }
.chat-log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.msg { max-width: 84%; padding: 9px 12px; border-radius: 16px; font-size: 14px; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.bot { align-self: flex-start; background: var(--card-strong); border-bottom-left-radius: 4px; }
.msg.user { align-self: flex-end; background: linear-gradient(135deg, var(--pink), #b46bff); border-bottom-right-radius: 4px; }
.msg.typing { color: var(--muted); }
.msg.typing::after { content: "…"; animation: blink 1s infinite; }
.chat-suggest { display: flex; gap: 6px; overflow-x: auto; padding: 0 14px 8px; scrollbar-width: none; }
.chat-suggest:empty { display: none; }
.chat-suggest button { flex: none; font-size: 12px; padding: 6px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); }
.chat-form { display: flex; gap: 8px; padding: 8px 12px calc(12px + var(--safe-b)); border-top: 1px solid var(--line); }
.chat-form input {
  flex: 1; min-width: 0; font: inherit; font-size: 16px; color: var(--text);
  padding: 10px 14px; border-radius: 999px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.25);
}
.chat-form input:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
.chat-form button { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--gold); color: #2b1600; font-size: 18px; }

/* ---------- Export-Dialog ---------- */
.export {
  border: 1px solid var(--gold); border-radius: 18px; padding: 16px;
  width: min(92vw, 460px);
  background: #1d1650;
}
.export::backdrop { background: rgba(5, 3, 20, 0.6); }
.export h2 { margin: 0 0 6px; font-size: 17px; }
.export p { font-size: 13px; color: var(--muted); }
.export textarea { width: 100%; font: 11px ui-monospace, Menlo, monospace; color: var(--text); background: rgba(0,0,0,0.35); border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.export-actions { display: flex; gap: 8px; margin-top: 10px; }

/* ---------- Animationen ---------- */
@keyframes pulse { 50% { opacity: 0.4; } }
@keyframes bob { 0%, 100% { translate: 0 0; } 50% { translate: 0 -5px; } }
@keyframes ping { 0% { box-shadow: 0 0 0 0 rgba(47,140,255,0.6); } 100% { box-shadow: 0 0 0 18px rgba(47,140,255,0); } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes blink { 50% { opacity: 0.2; } }
@keyframes wave { 0%, 88%, 100% { rotate: 0deg; } 92% { rotate: -8deg; } 96% { rotate: 8deg; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Kleine Höhen (z. B. iPhone SE quer/klein): kompakter */
@media (max-height: 640px) {
  .sub { display: none; }
  .next { margin-top: 6px; padding: 6px 10px; }
  .card { min-height: 76px; }
  .tab .e { display: none; }
}
