/* =============================================================================
   Web Stream Player – öffentliche Seite
   Modernes Karten-Design ("Glass"-Optik), heller und dunkler Modus über
   prefers-color-scheme. Die Akzentfarbe (--accent) kommt aus dem Admin-Bereich.
   ============================================================================= */

:root {
  --accent: #e4572e;
  --accent-soft: color-mix(in srgb, var(--accent) 16%, transparent);
  --accent-glow: color-mix(in srgb, var(--accent) 45%, transparent);

  --bg: #eef0f5;
  --fg: #15161a;
  --muted: #5d606b;
  --card: rgba(255, 255, 255, 0.72);
  --card-border: rgba(255, 255, 255, 0.85);
  --card-shadow: 0 30px 80px -20px rgba(20, 24, 40, 0.28), 0 8px 24px -8px rgba(20, 24, 40, 0.12);
  --chip: rgba(20, 24, 40, 0.06);
  --chip-border: rgba(20, 24, 40, 0.08);
  --track: rgba(20, 24, 40, 0.12);
  --on-accent: #ffffff;
  --live: #ef4444;
  --online: #16a34a;

  --radius-card: 32px;
  --radius-cover: 22px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0c10;
    --fg: #f3f4f7;
    --muted: #a3a6b3;
    --card: rgba(24, 25, 32, 0.62);
    --card-border: rgba(255, 255, 255, 0.08);
    --card-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.7), 0 8px 24px -8px rgba(0, 0, 0, 0.5);
    --chip: rgba(255, 255, 255, 0.07);
    --chip-border: rgba(255, 255, 255, 0.08);
    --track: rgba(255, 255, 255, 0.14);
    --online: #22c55e;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

a { color: var(--accent); }

/* --- Hintergrund ---------------------------------------------------------------
   Drei weich verlaufende Farbflächen in Varianten der Akzentfarbe. Ist ein Cover
   gesetzt, liegt es zusätzlich stark unscharf darüber. */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}
.blob {
  position: absolute;
  width: 70vmax;
  height: 70vmax;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.55;
  will-change: transform;
}
.blob-1 {
  background: var(--accent);
  top: -30vmax; left: -20vmax;
  animation: drift-1 26s ease-in-out infinite alternate;
}
.blob-2 {
  background: color-mix(in srgb, var(--accent) 55%, #7c3aed);
  bottom: -35vmax; right: -25vmax;
  animation: drift-2 32s ease-in-out infinite alternate;
}
.blob-3 {
  background: color-mix(in srgb, var(--accent) 50%, #06b6d4);
  top: 30%; left: 40%;
  width: 45vmax; height: 45vmax;
  opacity: 0.35;
  animation: drift-3 38s ease-in-out infinite alternate;
}
@media (prefers-color-scheme: dark) {
  .blob { opacity: 0.38; }
  .blob-3 { opacity: 0.22; }
}
.backdrop-cover {
  position: absolute;
  inset: -10%;
  background-image: var(--cover-image, none);
  background-size: cover;
  background-position: center;
  filter: blur(70px) saturate(1.5);
  opacity: 0;
  transition: opacity 0.6s ease;
}
body.has-cover .backdrop-cover { opacity: 0.55; }
@media (prefers-color-scheme: dark) {
  body.has-cover .backdrop-cover { opacity: 0.45; }
}

@keyframes drift-1 { to { transform: translate(18vw, 12vh) scale(1.1); } }
@keyframes drift-2 { to { transform: translate(-16vw, -10vh) scale(1.15); } }
@keyframes drift-3 { to { transform: translate(-20vw, 8vh) scale(0.9); } }

/* --- Bühne & Karte ------------------------------------------------------------ */
.stage {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: max(20px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
}

.card {
  width: 100%;
  max-width: 400px;
  padding: 22px 22px 26px;
  border-radius: var(--radius-card);
  background: var(--card);
  border: 1px solid var(--card-border);
  box-shadow: var(--card-shadow);
  -webkit-backdrop-filter: blur(28px) saturate(1.6);
  backdrop-filter: blur(28px) saturate(1.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
  animation: card-in 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
@keyframes card-in {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
}

/* Kopfzeile der Karte: LIVE-Badge links, Equalizer rechts */
.card-top {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 26px;
}
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 11px 4px 9px;
  border-radius: 999px;
  background: var(--chip);
  border: 1px solid var(--chip-border);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--muted);
}
.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.5;
}
/* Senderstatus (schon vor dem Abspielen): grün = sendet, rot = offline, grau = unbekannt */
.live-badge[data-online="true"] {
  color: var(--online);
  background: color-mix(in srgb, var(--online) 14%, transparent);
  border-color: color-mix(in srgb, var(--online) 30%, transparent);
}
.live-badge[data-online="true"] .live-dot { opacity: 1; animation: live-pulse 1.8s ease-out infinite; }
.live-badge[data-online="false"] {
  color: var(--live);
  background: color-mix(in srgb, var(--live) 12%, transparent);
  border-color: color-mix(in srgb, var(--live) 28%, transparent);
}
.live-badge[data-online="false"] .live-dot { opacity: 1; }
/* Prüfung läuft: grau, Punkt blinkt */
.live-badge[data-online="checking"] .live-dot,
.live-badge.is-checking .live-dot { opacity: 1; animation: blink 0.9s ease-in-out infinite; }
@keyframes blink { 50% { opacity: 0.2; } }

@keyframes live-pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 60%, transparent); }
  100% { box-shadow: 0 0 0 8px transparent; }
}

/* Kleiner Equalizer – bewegt sich nur während der Wiedergabe */
.eq {
  display: inline-flex;
  align-items: flex-end;
  gap: 3px;
  height: 18px;
  opacity: 0.35;
  transition: opacity 0.3s ease;
}
.eq i {
  display: block;
  width: 3px;
  height: 30%;
  border-radius: 2px;
  background: var(--accent);
}
body[data-state="playing"] .eq { opacity: 1; }
body[data-state="playing"] .eq i { animation: eq 1s ease-in-out infinite alternate; }
.eq i:nth-child(2) { animation-delay: -0.4s !important; animation-duration: 0.8s !important; }
.eq i:nth-child(3) { animation-delay: -0.7s !important; animation-duration: 1.2s !important; }
.eq i:nth-child(4) { animation-delay: -0.2s !important; animation-duration: 0.9s !important; }
.eq i:nth-child(5) { animation-delay: -0.5s !important; animation-duration: 1.1s !important; }
@keyframes eq { 0% { height: 20%; } 100% { height: 100%; } }

/* Cover */
.cover-wrap {
  width: min(100%, 46vh); /* auf niedrigen Bildschirmen kleiner, damit alles sichtbar bleibt */
  min-width: 180px;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-cover);
  overflow: hidden;
  box-shadow: 0 18px 40px -16px rgba(0, 0, 0, 0.45);
  transform: scale(0.96);
  transition: transform 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}
body[data-state="playing"] .cover-wrap { transform: scale(1); }
.cover {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Titel & Beschreibung */
.meta { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.meta:has(> .title[hidden]):has(> .description[hidden]) { display: none; }
.title {
  margin: 0;
  font-size: clamp(1.35rem, 5vw, 1.65rem);
  font-weight: 750;
  letter-spacing: -0.02em;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.description {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  white-space: pre-line; /* Zeilenumbrüche aus der Beschreibung anzeigen */
  overflow-wrap: anywhere;
}

.loading-line {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.92rem;
}
.mini-spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--track);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

/* Lange Beschreibung: auf 3 Zeilen gekürzt, unten weich ausgeblendet */
.description.is-clamped {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, #000 55%, transparent);
  mask-image: linear-gradient(to bottom, #000 55%, transparent);
}
.desc-toggle {
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: -2px;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--chip-border);
  background: var(--chip);
  color: var(--fg);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.desc-toggle:hover { border-color: var(--accent); }
.desc-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.desc-toggle svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.25s ease;
}
.desc-toggle[aria-expanded="true"] svg { transform: rotate(180deg); }

.notice {
  margin: 0;
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--chip);
  border: 1px solid var(--chip-border);
  font-size: 0.95rem;
}

/* --- Steuerung ---------------------------------------------------------------- */
.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 100%;
}

.now-playing {
  margin: 0;
  max-width: 100%;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--fg);
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.now-playing::before { content: "♪ "; color: var(--accent); }

/* Großer runder Play/Stop-Button */
.play-btn {
  position: relative;
  width: 96px;
  height: 96px;
  margin-top: 4px;
  border-radius: 50%;
  border: none;
  background:
    linear-gradient(145deg, color-mix(in srgb, var(--accent) 80%, #fff) 0%, var(--accent) 55%, color-mix(in srgb, var(--accent) 80%, #000) 100%);
  color: var(--on-accent);
  box-shadow: 0 14px 34px -8px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.15s ease, box-shadow 0.25s ease;
  touch-action: manipulation;
}
.play-btn:hover { transform: translateY(-1px) scale(1.03); box-shadow: 0 18px 40px -8px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.35); }
.play-btn:active { transform: scale(0.95); }
.play-btn:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, var(--fg)); outline-offset: 6px; }

.play-btn .icon {
  width: 40px;
  height: 40px;
  fill: currentColor;
  grid-area: 1 / 1;
}
.play-btn .icon-play { transform: translateX(2px); }
.play-btn .icon-stop { display: none; width: 34px; height: 34px; }
body:not([data-state="stopped"]) .play-btn .icon-play { display: none; }
body:not([data-state="stopped"]) .play-btn .icon-stop { display: block; }

/* Ring: dreht sich beim Verbinden, pulsiert beim Warten, "atmet" beim Abspielen */
.play-btn .ring {
  position: absolute;
  inset: -9px;
  border-radius: 50%;
  border: 3px solid transparent;
  pointer-events: none;
}
body[data-state="connecting"] .play-btn .ring,
body[data-state="reconnecting"] .play-btn .ring {
  border-top-color: var(--accent);
  border-right-color: color-mix(in srgb, var(--accent) 35%, transparent);
  animation: spin 0.9s linear infinite;
}
body[data-state="waiting-retry"] .play-btn .ring {
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
  animation: pulse 1.4s ease-in-out infinite;
}
body[data-state="playing"] .play-btn .ring {
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
  animation: breathe 2.8s ease-in-out infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: 0.25; } }
@keyframes breathe { 50% { transform: scale(1.08); opacity: 0.25; } }

/* Status als kleine Pille */
.status-pill {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--chip);
  border: 1px solid var(--chip-border);
  font-size: 0.85rem;
  color: var(--muted);
  max-width: 100%;
}
.status-dot {
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.6;
}
body[data-state="playing"] .status-pill { color: var(--fg); }
body[data-state="playing"] .status-dot { background: #22c55e; opacity: 1; }
body[data-state="connecting"] .status-dot,
body[data-state="reconnecting"] .status-dot { background: #f59e0b; opacity: 1; animation: pulse 1s ease-in-out infinite; }
body[data-state="waiting-retry"] .status-dot { background: var(--live); opacity: 1; }

/* --- Lautstärke ------------------------------------------------------------------ */
.volume {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 300px;
  color: var(--muted);
}
.volume svg { width: 18px; height: 18px; fill: currentColor; flex: none; }

.volume input[type="range"] {
  --vol: 100%;
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 22px;
  background: transparent;
  cursor: pointer;
}
.volume input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--accent) 0 var(--vol), var(--track) var(--vol) 100%);
}
.volume input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: var(--track);
}
.volume input[type="range"]::-moz-range-progress {
  height: 6px;
  border-radius: 999px;
  background: var(--accent);
}
.volume input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -6px;
  border-radius: 50%;
  background: #fff;
  border: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s ease;
}
.volume input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
.volume input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.15); }
.volume input[type="range"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 999px; }

/* --- PWA-Aktionen unter der Karte ----------------------------------------------- */
.pwa-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 400px;
}
.pwa-actions:not(:has(> :not([hidden]))) { display: none; }

.glass-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid var(--card-border);
  background: var(--card);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  color: var(--fg);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 8px 24px -10px rgba(0, 0, 0, 0.25);
}
.glass-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.glass-btn:hover { border-color: var(--accent); }

.hint {
  position: relative;
  margin: 0;
  padding: 10px 36px 10px 16px;
  border-radius: 16px;
  background: var(--card);
  border: 1px solid var(--card-border);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  font-size: 0.85rem;
  color: var(--muted);
}
.hint-close {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: var(--chip);
  color: var(--fg);
  cursor: pointer;
  line-height: 1;
}

.link-btn {
  background: none;
  border: none;
  padding: 0 4px;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* --- Banner (Update, Offline) -------------------------------------------------- */
.banner {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--card-border);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  box-shadow: var(--card-shadow);
  font-size: 0.88rem;
  white-space: nowrap;
}
.banner-warn { top: auto; bottom: max(12px, env(safe-area-inset-bottom)); }

/* --- Kleine Bildschirme --------------------------------------------------------- */
@media (max-width: 380px) {
  .card { padding: 18px 16px 22px; border-radius: 26px; gap: 16px; }
  .play-btn { width: 86px; height: 86px; }
}
/* Querformat auf dem Handy: Cover kleiner, damit alles auf den Bildschirm passt */
@media (max-height: 560px) and (orientation: landscape) {
  .cover-wrap { width: 46%; }
}

@media (prefers-reduced-motion: reduce) {
  .blob, .card, .play-btn .ring, .eq i, .live-dot, .status-dot, .mini-spinner { animation: none !important; }
}

/* --- Debug-Anzeige (?debug=1) ------------------------------------------------------ */
.debug {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-height: 40vh;
  overflow: auto;
  background: rgba(0, 0, 0, 0.88);
  color: #d6ffd6;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  z-index: 20;
  text-align: left;
}
.debug-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; color: #fff; margin-bottom: 4px; }
.debug-head .link-btn { color: #9cf; margin-left: auto; }
.debug ol { margin: 0; padding: 0; list-style: none; }
.debug li { white-space: pre-wrap; word-break: break-all; }
.debug .dbg-reconnect, .debug .dbg-watchdog, .debug .dbg-fail { color: #ffb4a8; }
.debug .dbg-playing, .debug .dbg-stable { color: #9effa0; font-weight: bold; }
.debug .dbg-state { color: #fff3a0; }
.debug .dbg-wait { color: #ffd27a; }
body:has(.debug:not([hidden])) .stage { padding-bottom: 42vh; }
