:root {
  --bg: #0f1324;
  --panel: #171c33;
  --panel-2: #20264a;
  --line: #2c3360;
  --text: #f3f4fb;
  --muted: #9aa1c7;
  --accent: #ff3d6e;
  --accent-2: #7b5cff;
  --ok: #2ec4a6;
  --radius: 16px;
  --tab-h: 64px;
  --top-h: 52px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.4 "Inter", "Segoe UI", Roboto, system-ui, sans-serif; overscroll-behavior: none; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

#app { display: grid; height: 100dvh; grid-template-rows: calc(var(--top-h) + var(--safe-t)) minmax(0, 1fr) auto calc(var(--tab-h) + var(--safe-b)); grid-template-areas: "top" "stage" "sheet" "tabs"; }
.topbar { grid-area: top; display: flex; align-items: center; gap: 10px; padding: var(--safe-t) 12px 0; background: var(--panel); border-bottom: 1px solid var(--line); }
.logo { width: 30px; height: 30px; border-radius: 8px; }
.title-input { flex: 1; min-width: 0; background: transparent; border: 0; font-weight: 700; font-size: 17px; padding: 6px 4px; border-radius: 8px; }
.title-input:focus { outline: none; background: var(--panel-2); }
.icon-btn { background: transparent; border: 0; padding: 8px; border-radius: 10px; display: grid; place-items: center; }
.icon-btn:active { background: var(--panel-2); }
.busy { width: 18px; height: 18px; border: 2.5px solid var(--muted); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.stage-wrap { grid-area: stage; position: relative; overflow: hidden; display: grid; place-items: center; background: radial-gradient(circle at 50% 40%, #1d2550, #0b0e1c); }
.stage { position: absolute; inset: 0; }
#app:not(.mode-route) .stage { position: relative; inset: auto; border-radius: 10px; overflow: hidden; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.stage-empty { position: absolute; inset: auto 16px 16px; display: grid; place-items: center; pointer-events: none; }
.stage-empty > div { background: rgba(15,19,36,.86); backdrop-filter: blur(8px); padding: 14px 18px; border-radius: var(--radius); text-align: center; max-width: 360px; }
.stage-empty p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

.sheet { grid-area: sheet; background: var(--panel); border-top: 1px solid var(--line); max-height: 46dvh; overflow: auto; padding: 14px 14px 10px; }
.panel { display: none; }
#app.mode-route .panel[data-panel=route], #app.mode-preview .panel[data-panel=preview], #app.mode-style .panel[data-panel=style], #app.mode-export .panel[data-panel=export] { display: block; }

.tabbar { grid-area: tabs; display: grid; grid-template-columns: repeat(4, 1fr); background: var(--panel); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
.tabbar button { background: transparent; border: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 12px; font-weight: 600; }
.tabbar button.active { color: var(--text); }
.tabbar button.active svg { stroke: var(--accent); }

.search { position: relative; }
.search input { width: 100%; padding: 12px 14px 12px 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel-2); }
.search input:focus { outline: 2px solid var(--accent-2); border-color: transparent; }
.search-ico { position: absolute; left: 12px; top: 12px; color: var(--muted); }
.results { list-style: none; margin: 6px 0 0; padding: 0; }
.results li { padding: 10px 12px; border-radius: 10px; display: flex; gap: 10px; align-items: center; }
.results li:active, .results li:hover { background: var(--panel-2); }
.results small { color: var(--muted); display: block; }
.results li.info { color: var(--muted); font-size: 14px; cursor: default; }

.stops { list-style: none; margin: 12px 0; padding: 0; }
.stop { display: flex; align-items: center; gap: 10px; padding: 8px 6px; border-radius: 12px; }
.stop:active { background: var(--panel-2); }
.stop .pin { width: 28px; height: 28px; flex: none; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 13px; background: var(--panel-2); border: 2px solid var(--accent-2); }
.stop.start .pin { background: var(--ok); border-color: var(--ok); color: #062; }
.stop.end .pin { background: var(--accent); border-color: var(--accent); }
.stop .name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.stop .night { font-size: 14px; opacity: .9; }
.leg { display: flex; align-items: center; gap: 8px; margin: 0 0 0 13px; padding: 4px 0 4px 20px; border-left: 2px dashed var(--line); }
.leg button { display: inline-flex; align-items: center; gap: 6px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px 4px 6px; font-size: 13px; }
.leg img { width: 26px; height: 26px; object-fit: contain; }
.leg .dist { color: var(--muted); font-size: 12px; }
.leg.err button { border-color: #ff8a00; }

.btn { border: 0; border-radius: 12px; padding: 10px 14px; font-weight: 700; background: var(--panel-2); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.small, .small { font-size: 13px; }
.btn:disabled { opacity: .5; }
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; margin-top: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.hint, .muted { color: var(--muted); font-size: 13px; }
.card { background: var(--panel-2); border-radius: var(--radius); padding: 12px; margin-top: 12px; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--line); }
.badge.ai { background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.field { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); margin-top: 6px; }
.storyboard { margin-top: 10px; font-size: 13px; color: var(--muted); }
.storyboard li { margin: 2px 0; }

.player { display: flex; align-items: center; gap: 12px; }
.quick-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.quick-row .view-quick { margin-top: 0; }
.duration-row .row { align-items: center; }
.duration-row input { flex: 1; }
#btn-dur-auto.on { border-color: var(--accent); color: var(--text); }
.play-btn { width: 52px; height: 52px; border-radius: 50%; border: 0; background: linear-gradient(135deg, var(--accent), var(--accent-2)); display: grid; place-items: center; flex: none; }
.play-btn svg { fill: #fff; stroke: none; width: 26px; height: 26px; }
input[type=range] { flex: 1; width: 100%; accent-color: var(--accent); }
.time { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 76px; text-align: right; font-size: 13px; }

.lbl { display: block; margin: 14px 0 6px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.lbl:first-child { margin-top: 0; }
.seg { display: flex; background: var(--panel-2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px 4px; border-radius: 9px; font-weight: 600; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--bg); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.3); }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatches button { width: 32px; height: 32px; border-radius: 50%; border: 3px solid transparent; }
.swatches button.on { border-color: #fff; }
.toggles { display: grid; gap: 8px; }
.toggles label { display: flex; gap: 10px; align-items: center; }
.toggles input { width: 20px; height: 20px; accent-color: var(--accent); }
.music-detail { margin-top: 8px; font-size: 13px; color: var(--muted); }
.music-detail select { width: 100%; padding: 8px; border-radius: 10px; background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }

.export-choices { display: grid; gap: 10px; margin-top: 12px; }
.choice { text-align: left; border: 1px solid var(--line); background: var(--panel-2); border-radius: var(--radius); padding: 14px; display: grid; gap: 4px; }
.choice span { color: var(--muted); font-size: 13px; }
.choice:active { border-color: var(--accent); }
.progress { margin-top: 14px; }
.bar { height: 10px; border-radius: 99px; background: var(--panel-2); overflow: hidden; margin-bottom: 8px; }
.bar > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .3s; }

.modal { position: fixed; inset: 0; background: rgba(5,7,15,.6); display: grid; align-items: end; z-index: 50; }
.modal-card { background: var(--panel); border-radius: 20px 20px 0 0; padding: 16px 16px calc(16px + var(--safe-b)); max-height: 80dvh; overflow: auto; }
.modal-card h3 { margin: 0 0 10px; }
.grid-modes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.grid-modes button { background: var(--panel-2); border: 2px solid transparent; border-radius: 14px; padding: 10px 4px; display: grid; justify-items: center; gap: 4px; font-size: 12px; }
.grid-modes button.on { border-color: var(--accent); }
.grid-modes img { width: 52px; height: 52px; object-fit: contain; filter: drop-shadow(0 3px 4px rgba(0,0,0,.45)); }
.modal .swatches button { width: 30px; height: 30px; }
.list-btns { display: grid; gap: 8px; margin-top: 12px; }
.list-btns .btn { text-align: left; }
.proj { display: flex; gap: 10px; align-items: center; padding: 10px; border-radius: 12px; background: var(--panel-2); margin-bottom: 8px; }
.proj .name { flex: 1; font-weight: 600; }
.proj small { color: var(--muted); display: block; font-weight: 400; }

.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 16px); transform: translateX(-50%); background: #fff; color: #111; padding: 10px 16px; border-radius: 12px; font-weight: 600; z-index: 60; box-shadow: 0 8px 30px rgba(0,0,0,.4); max-width: 90vw; }
.toast.err { background: #ffb3c1; }

/* Karten-Marker */
.mc-stop { width: 30px; height: 30px; border-radius: 50%; background: #20264a; color: #fff; border: 3px solid #fff; display: grid; place-items: center; font-weight: 800; font-size: 13px; box-shadow: 0 3px 10px rgba(0,0,0,.45); cursor: grab; }
.mc-stop.start { background: #2ec4a6; }
.mc-stop.end { background: #ff3d6e; }
.mc-via { width: 16px; height: 16px; border-radius: 50%; background: #fff; border: 3px solid #7b5cff; box-shadow: 0 2px 6px rgba(0,0,0,.4); cursor: grab; }
.mc-via.dragging { width: 22px; height: 22px; }
.maplibregl-ctrl-attrib { font-size: 10px; }

/* Breite Bildschirme: Bedienleiste links, Karte rechts */
@media (min-width: 900px) {
  #app { grid-template-columns: 400px minmax(0, 1fr); grid-template-rows: var(--top-h) var(--tab-h) minmax(0, 1fr); grid-template-areas: "top top" "tabs stage" "sheet stage"; }
  .tabbar { border-top: 0; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); }
  .sheet { max-height: none; border-top: 0; border-right: 1px solid var(--line); }
  .modal { place-items: center; }
  .modal-card { border-radius: 20px; width: 520px; }
}

/* Fertiges Video vor dem Speichern ansehen */
.export-result { margin-top: 12px; display: flex; justify-content: center; }
.export-result video { display: block; max-width: 100%; max-height: 55vh; border-radius: 14px; background: #000; box-shadow: 0 8px 30px rgba(0,0,0,.35); }

/* Musikauswahl mit Probehören */
.track-list { display: flex; flex-direction: column; gap: 4px; max-height: 300px; overflow-y: auto; margin-top: 6px; padding-right: 2px; }
.track-row { display: flex; align-items: center; gap: 10px; padding: 6px 10px 6px 6px; border-radius: 12px; background: rgba(255,255,255,.04); cursor: pointer; border: 1px solid transparent; margin-top: 6px; }
.track-list .track-row { margin-top: 0; }
.track-row:hover { background: rgba(255,255,255,.08); }
.track-row.sel { border-color: var(--accent); background: rgba(255,61,110,.10); }
.track-name { flex: 1; font-weight: 600; }
.track-dur { opacity: .6; font-size: .85em; }
.track-check { width: 1em; color: var(--accent); font-weight: 800; }
.listen-btn { flex: none; width: 34px; height: 34px; border-radius: 50%; border: 0; cursor: pointer; font-size: 13px; color: #fff; background: rgba(255,255,255,.12); }
.listen-btn:hover { background: rgba(255,255,255,.2); }
.listen-btn.on { background: linear-gradient(135deg, var(--accent), var(--accent-2)); }

/* Neue Reise / Reise löschen auf der Routenseite */
.trip-actions { margin-top: 14px; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.08); }
.btn.danger { color: #ff8a9b; }
.btn.danger:hover { background: rgba(255,61,110,.12); }

/* Vollständige Fehlermeldung */
.error-text { max-height: 50vh; overflow: auto; white-space: pre-wrap; word-break: break-word; font: 12px/1.45 ui-monospace, Consolas, monospace; background: rgba(0,0,0,.35); color: #ffd6dc; padding: 12px; border-radius: 10px; margin: 0 0 14px; user-select: text; }

/* Rechtliches im Menü „Meine Reisen“ */
.menu-links { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 16px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,.08); font-size: .9em; }
.menu-links a { color: inherit; opacity: .75; text-decoration: none; }
.menu-links a:hover { opacity: 1; text-decoration: underline; }

/* Halte per Drag & Drop sortieren */
.stop .drag { flex: none; width: 32px; height: 32px; display: grid; place-items: center; font-size: 18px; color: var(--muted); cursor: grab; touch-action: none; user-select: none; border-radius: 8px; }
.stop .drag:hover { background: rgba(255,255,255,.07); color: var(--text); }
.stops.sorting { user-select: none; }
.stops.sorting .leg { opacity: .35; }
.stop.dragging { position: relative; z-index: 5; background: var(--panel-2); box-shadow: 0 10px 28px rgba(0,0,0,.45); cursor: grabbing; }
.stop.dragging .drag { cursor: grabbing; color: var(--accent); }
.stop.drop-before { box-shadow: inset 0 3px 0 var(--accent); }
.stop.drop-after { box-shadow: inset 0 -3px 0 var(--accent); }
