:root {
  --bg: #0a0a0a;
  --panel: #161616;
  --panel-2: #1f1f1f;
  --fg: #f5f5f5;
  --accent: #f5a623;
  --muted: #8a8a8a;
  --line: #2a2a2a;
  --danger: #e0523c;
  --ok: #4caf6a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.view { min-height: 100%; }
[hidden] { display: none !important; }

/* ── PIN-Gate ─────────────────────────────────────────── */
.pin-gate { position: fixed; inset: 0; z-index: 200; background: radial-gradient(ellipse at center, #1c1408, #0a0a0a 72%);
  display: flex; align-items: center; justify-content: center; padding: 24px; }
.pin-box { text-align: center; max-width: 340px; width: 100%; }
.pin-logo { font-size: 56px; }
.pin-box h1 { font-size: 2rem; margin-top: 8px; }
.pin-sub { color: var(--muted); margin: 6px 0 20px; }
#pin-form { display: flex; gap: 10px; }
#pin-input { flex: 1; background: var(--panel); border: 1px solid var(--line); color: var(--fg);
  padding: 13px 15px; border-radius: 12px; font-size: 1.2rem; text-align: center; letter-spacing: .3em; outline: none; }
#pin-input:focus { border-color: var(--accent); }
#pin-form button { background: var(--accent); color: #1a1200; border: none; font-weight: 700; padding: 0 22px; border-radius: 12px; font-size: 1rem; cursor: pointer; }
.pin-msg { color: var(--danger); margin-top: 12px; font-size: .9rem; }

/* ── Topbar ─────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: rgba(10,10,10,.9); backdrop-filter: blur(8px); z-index: 5;
}
.brand { font-size: 1.15rem; font-weight: 700; letter-spacing: -.01em; }
.brand-logo { margin-right: 4px; }
.brand-tag {
  color: var(--accent); font-weight: 600; font-size: .62rem;
  letter-spacing: .09em; text-transform: uppercase; margin-left: 8px; vertical-align: middle;
}

/* ── Add-Form ───────────────────────────────────────── */
.add-form { display: flex; gap: 10px; padding: 20px; max-width: 720px; margin: 0 auto; width: 100%; }
.add-form input {
  flex: 1; background: var(--panel); border: 1px solid var(--line); color: var(--fg);
  padding: 13px 15px; border-radius: 12px; font-size: 1rem; outline: none;
}
.add-form input:focus { border-color: var(--accent); }
.add-form button {
  background: var(--accent); color: #1a1200; border: none; font-weight: 700;
  padding: 0 20px; border-radius: 12px; font-size: 1rem; cursor: pointer; white-space: nowrap;
}
.add-form button:disabled { opacity: .5; cursor: default; }
.add-msg { max-width: 720px; margin: -8px auto 0; padding: 0 20px 8px; width: 100%; font-size: .9rem; }
.add-msg.err { color: var(--danger); }
.add-msg.ok { color: var(--ok); }

/* ── Library ────────────────────────────────────────── */
.library {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 16px; padding: 8px 20px 40px; max-width: 1100px; margin: 0 auto;
}
.empty-hint { text-align: center; color: var(--muted); padding: 40px 20px; }

.section-head {
  max-width: 1100px; margin: 8px auto 0; padding: 6px 20px; width: 100%;
  display: flex; align-items: center; justify-content: space-between;
  color: var(--muted); font-size: .82rem; font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase;
}
h2.section-head { font-size: .82rem; }
.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; font-size: .82rem; }
.card.adding { opacity: .6; }
.card-btn:disabled { cursor: default; opacity: .85; }
.card.queued-ok .card-btn.process { background: var(--ok); color: #06210f; border-color: var(--ok); }
.card-dur { color: var(--muted); font-size: .78rem; margin-top: 2px; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  overflow: hidden; display: flex; flex-direction: column; position: relative;
}
.card-thumb {
  position: relative; aspect-ratio: 16/9; background: #000 center/cover no-repeat;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.card-thumb .thumb-badge {
  font-size: .78rem; font-weight: 600; padding: 6px 12px; border-radius: 999px;
  background: rgba(0,0,0,.65); backdrop-filter: blur(4px);
}
.card-thumb .play-overlay {
  font-size: 2.6rem; color: #fff; text-shadow: 0 2px 14px rgba(0,0,0,.6);
  opacity: .92; transition: transform .1s;
}
.card-thumb:hover .play-overlay { transform: scale(1.12); }
.badge-processing { color: var(--accent); }
.badge-queued { color: var(--muted); }
.badge-error { color: var(--danger); }

.card-body { padding: 11px 13px; display: flex; gap: 8px; align-items: flex-start; }
.card-info { flex: 1; min-width: 0; }
.card-title { font-weight: 600; font-size: .95rem; line-height: 1.25; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card-artist { color: var(--muted); font-size: .82rem; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.card-actions { display: flex; gap: 4px; }
.mini-btn {
  background: transparent; border: none; color: var(--muted); cursor: pointer;
  font-size: 1.05rem; padding: 4px 6px; border-radius: 8px; line-height: 1;
}
.mini-btn:hover { background: var(--panel-2); color: var(--fg); }
.mini-btn.danger:hover { color: var(--danger); }
.spin { display: inline-block; animation: spin 1.4s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Player ─────────────────────────────────────────── */
#player { background: #000; }
.player-shell { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; position: relative; }
.player-topbar {
  display: flex; align-items: center; gap: 14px; padding: 10px 14px;
  background: #0d0d0d; border-bottom: 1px solid var(--line); flex: none; z-index: 10;
}
.back-btn {
  background: var(--panel-2); color: var(--fg); border: 1px solid var(--line);
  padding: 8px 14px; border-radius: 999px; cursor: pointer; font-size: .95rem; flex: none;
}
.back-btn:hover { border-color: var(--accent); }
.p-title-top {
  flex: 1; font-weight: 600; color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Player: Mic-Button + Panel */
.mic-toggle.on { border-color: var(--accent); background: var(--accent); color: #1a1200; }
.mic-panel {
  position: absolute; top: 56px; right: 14px; z-index: 12; max-width: 300px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; font-size: .85rem;
}
.localmic-btn { width: 100%; background: var(--accent); color: #1a1200; border: none; font-weight: 700;
  padding: 11px 12px; border-radius: 10px; cursor: pointer; font-size: .9rem; }
.localmic-btn.on { background: var(--ok); color: #06210f; }
.localmic-ctrl { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.localmic-dev { width: 100%; background: var(--panel-2); color: var(--fg); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px; font-size: .82rem; }
.localmic-dev-row { display: flex; gap: 6px; }
.localmic-dev-row .localmic-dev { flex: 1; }
.localmic-dev-row .icon-btn { padding: 6px 10px; }
.localmic-vol-row { display: flex; align-items: center; gap: 8px; }
.localmic-vol-row input { flex: 1; }
.localmic-vol-row label { font-size: .82rem; }
.localmic-echo { display: flex; align-items: center; gap: 8px; font-size: .82rem; color: var(--muted); cursor: pointer; }
.mix-row { display: flex; align-items: center; gap: 8px; }
.mix-row input { flex: 1; }
.mix-end { font-size: .78rem; color: var(--muted); white-space: nowrap; }
.mic-panel-sep { color: var(--muted); font-size: .78rem; text-align: center; margin: 12px 0 8px;
  border-top: 1px solid var(--line); padding-top: 10px; }
.mic-src-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.mic-src-row label { font-size: .85rem; white-space: nowrap; }
.mic-src-row .localmic-dev { flex: 1; }
.mic-src-row .icon-btn { padding: 6px 10px; }
.mic-settings { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px; margin: 10px 0; display: flex; flex-direction: column; gap: 8px; }
.mic-echo-row { display: flex; align-items: center; gap: 10px; font-size: 1rem; }
.mic-panel-status { font-weight: 600; margin-bottom: 8px; font-size: .82rem; color: var(--muted); }
.mic-panel-hint { color: var(--muted); margin-bottom: 6px; }
.mic-qr { display: block; width: 180px; height: 180px; background: #fff; border-radius: 10px; padding: 8px; margin: 0 auto 8px; }
.mic-panel-link { color: var(--muted); text-align: center; }
.mic-panel-link a { color: var(--accent); word-break: break-all; }

/* Handy-Mikrofon-Seite (/karaoke/mikrofon) */
.mic-page { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 18px; padding: 32px; text-align: center; }
.mic-logo { font-size: 64px; line-height: 1; }
.mic-page h1 { font-size: 1.8rem; }
.mic-room { color: var(--muted); }
.mic-big-btn { background: var(--accent); color: #1a1200; border: none; font-weight: 700;
  font-size: 1.2rem; padding: 18px 30px; border-radius: 16px; cursor: pointer; }
.mic-big-btn:disabled { opacity: .5; }
.mic-status { font-size: 1.15rem; font-weight: 700; }
.mic-vol-row { display: flex; flex-direction: column; gap: 10px; width: min(360px, 82vw); }
.mic-vol-row input { width: 100%; }
.mic-stop-btn { background: var(--panel-2); color: var(--fg); border: 1px solid var(--line);
  padding: 12px 26px; border-radius: 12px; cursor: pointer; }
.mic-hint { color: var(--muted); font-size: .85rem; max-width: 340px; line-height: 1.5; }
.icon-btn {
  background: var(--panel-2); color: var(--fg); border: 1px solid var(--line);
  border-radius: 10px; cursor: pointer; font-size: 1rem; padding: 8px 12px;
}
.icon-btn:hover { border-color: var(--accent); }

.stage { flex: 1; display: flex; min-height: 0; }
.video-wrap { flex: 1.35; background: #000; display: flex; align-items: center; justify-content: center; min-width: 0; }
.video-wrap #yt-frame, .video-wrap iframe { width: 100%; height: 100%; border: 0; }
.video-wrap { position: relative; }
.video-wrap #yt-frame { aspect-ratio: 16/9; max-height: 100%; }

/* Transparente Schutzschicht ueber dem iframe: faengt Maus/Touch ab, damit YouTubes
   Hover-Overlays (Teilen, Spaeter ansehen, Titelleiste) nicht ausloesen. Wiedergabe
   laeuft ueber unsere eigenen Buttons, das Video ist nur Bild. */
.video-shield { position: absolute; inset: 0; z-index: 5; background: transparent; }

/* Deckt das Video bei Pause/Ende ab -> unterdrueckt YouTubes Vorschlags-Grid */
.video-cover {
  position: absolute; inset: 0; z-index: 6; display: none;
  flex-direction: column; align-items: center; justify-content: center; gap: 30px;
  background: radial-gradient(ellipse at center, #1c1408 0%, #0a0a0a 72%);
  overflow: hidden;
}
.player-shell.covered .video-cover { display: flex; }
.video-cover::before {   /* weicher Orange-Glow-Puls */
  content: ""; position: absolute; width: 62vmin; height: 62vmin; border-radius: 50%;
  background: radial-gradient(circle, rgba(245,166,35,.20), transparent 65%);
  animation: vcglow 3.2s ease-in-out infinite;
}
@keyframes vcglow { 0%,100% { transform: scale(.88); opacity: .55; } 50% { transform: scale(1.18); opacity: 1; } }
.vc-eq { display: flex; align-items: flex-end; gap: 8px; height: min(28vh, 150px); position: relative; }
.vc-eq span {
  width: min(2.6vw, 14px); border-radius: 6px;
  background: linear-gradient(180deg, #ffe0a3, var(--accent) 60%, #ff7a00);
  box-shadow: 0 0 14px rgba(245,166,35,.35);
  animation: vceq 2.6s ease-in-out infinite;
}
.vc-eq span:nth-child(1) { animation-delay: -.3s; animation-duration: 2.9s; }
.vc-eq span:nth-child(2) { animation-delay: -1.1s; animation-duration: 2.3s; }
.vc-eq span:nth-child(3) { animation-delay: -.7s; animation-duration: 2.7s; }
.vc-eq span:nth-child(4) { animation-delay: -1.6s; animation-duration: 2.1s; }
.vc-eq span:nth-child(5) { animation-delay: -.2s; animation-duration: 3.1s; }
.vc-eq span:nth-child(6) { animation-delay: -1.3s; animation-duration: 2.5s; }
.vc-eq span:nth-child(7) { animation-delay: -1.8s; animation-duration: 2.8s; }
.vc-eq span:nth-child(8) { animation-delay: -.6s; animation-duration: 2.2s; }
.vc-eq span:nth-child(9) { animation-delay: -2.1s; animation-duration: 3.0s; }
@keyframes vceq { 0%,100% { height: 32%; } 50% { height: 92%; } }
.vc-title { position: relative; color: #fff; font-weight: 700; font-size: 1.5rem; text-align: center; padding: 0 24px; text-shadow: 0 2px 18px rgba(0,0,0,.6); }
@media (prefers-reduced-motion: reduce) { .vc-eq span, .video-cover::before { animation: none; } .vc-eq span { height: 60%; } }

/* iframe leicht ueber den Rahmen skalieren + beschneiden -> Rand-Chrome
   (Logo, Teilen, Titelleiste, Rest-Untertitel) liegt ausserhalb des Sichtbaren */
.video-wrap #yt-frame { overflow: hidden; }
.video-wrap #yt-frame iframe { transform: scale(1.18); transform-origin: center center; }

/* ── Overlay-Modus: Text laeuft ueber dem Video ─────────────────── */
.player-shell.overlay .stage { position: relative; display: block; }
.player-shell.overlay .video-wrap { position: absolute; inset: 0; }
.player-shell.overlay .video-wrap #yt-frame { width: 100%; height: 100%; max-height: none; aspect-ratio: auto; }
.player-shell.overlay .video-wrap #yt-frame iframe { width: 100%; height: 100%; transform: scale(1.35); }
.player-shell.overlay .lyrics {
  position: absolute; left: 0; right: 0; bottom: 0; top: auto; height: 40%; z-index: 7;
  pointer-events: none; padding: 12px 6vw;
  justify-content: center;   /* Text innerhalb des unteren 40%-Bandes */
  background: linear-gradient(to top, rgba(0,0,0,.8), rgba(0,0,0,.45) 55%, rgba(0,0,0,0));
}
.player-shell.overlay .lyrics .lrc-line { text-shadow: 0 2px 14px rgba(0,0,0,.95), 0 0 4px rgba(0,0,0,.8); }
.player-shell.overlay .lyrics .lrc-line.active { color: #cfcfcf; }
.player-shell.overlay .lyrics .lrc-line.passed { color: #6a6a6a; }

.lyrics {
  flex: 1; overflow: hidden; padding: 16px 28px; text-align: center;
  background: linear-gradient(180deg, #0c0c0c, #050505);
  display: flex; flex-direction: column; justify-content: center; gap: 0;
  --lyric-scale: 1;
}
.lyrics .lrc-line {
  font-size: calc(2.0rem * var(--lyric-scale)); line-height: 1.2; color: #6a6a6a; padding: 0.12em 0;
  transition: color .18s, transform .18s, opacity .3s; font-weight: 700; letter-spacing: -.01em;
}
.lyrics .lrc-line.hidden-line { display: none; }
.lyrics .lrc-line.active { color: #7d7d7d; transform: scale(1.06); }
.lyrics .lrc-line.passed { color: #444; }
/* Wort-Sweep: gesungene Woerter der aktiven Zeile leuchten in Akzentfarbe auf */
.lyrics .lrc-word { transition: color .1s ease; }
.lyrics .lrc-line.active .lrc-word.sung { color: var(--accent); }
.lyrics.plain { white-space: pre-wrap; padding: 40px 28px; }
.lyrics.plain .plain-text { font-size: 1.5rem; line-height: 1.9; color: #cfcfcf; text-align: center; }

/* Vollbild: Text noch groesser */
#player-shell:fullscreen .lyrics .lrc-line { font-size: calc(2.7rem * var(--lyric-scale)); padding: 0.12em 0; }
#player-shell:-webkit-full-screen .lyrics .lrc-line { font-size: calc(2.7rem * var(--lyric-scale)); padding: 0.12em 0; }
.lyrics-empty { color: var(--muted); font-size: 1rem; }

/* ── Controls ───────────────────────────────────────── */
.controls { background: #0d0d0d; border-top: 1px solid var(--line); padding: 14px 20px calc(14px + env(safe-area-inset-bottom)); }
.song-meta { text-align: center; margin-bottom: 8px; }
.p-title { font-weight: 700; }
.p-artist { color: var(--muted); margin-left: 8px; }

.transport { display: flex; align-items: center; gap: 12px; max-width: 900px; margin: 0 auto; }
.play-btn {
  width: 46px; height: 46px; flex: none; border-radius: 50%; border: none; cursor: pointer;
  background: var(--accent); color: #1a1200; font-size: 1.1rem; display: flex; align-items: center; justify-content: center;
}
.time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .85rem; min-width: 38px; text-align: center; }

input[type=range] { -webkit-appearance: none; appearance: none; height: 6px; border-radius: 3px; background: var(--panel-2); outline: none; }
.seek { flex: 1; }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--accent); cursor: pointer; border: 2px solid #0d0d0d;
}
input[type=range]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--accent); cursor: pointer; border: none; }

.vocal-row { display: flex; align-items: center; gap: 12px; max-width: 900px; margin: 12px auto 0; }
.vocal-row label { font-weight: 600; font-size: .9rem; min-width: 56px; }
.avsync-row .icon-btn { padding: 5px 12px; font-size: .85rem; }
.av-val { min-width: 60px; text-align: center; font-variant-numeric: tabular-nums; color: var(--muted); font-size: .85rem; }

/* ── Katalog ─────────────────────────────────────────── */
.catalog { max-width: 1100px; margin: 0 auto; padding: 12px 20px 50px; width: 100%; }
.catalog-tabs { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 0 16px; }
.cat-tab { background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  padding: 8px 14px; border-radius: 999px; cursor: pointer; font-size: .9rem; font-weight: 600; }
.cat-tab:hover { color: var(--fg); }
.cat-tab.active { background: var(--accent); color: #1a1200; border-color: var(--accent); }
.catalog-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 8px; }
.cat-song { display: flex; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.cat-song-info { flex: 1; padding: 10px 14px; cursor: pointer; min-width: 0; }
.cat-song-info:hover { background: var(--panel-2); }
.cat-song-title { display: block; font-weight: 600; font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-song-artist { display: block; color: var(--muted); font-size: .82rem; }
.cat-search-btn { background: transparent; border: none; color: var(--muted); cursor: pointer; font-size: 1rem; padding: 10px 12px; align-self: stretch; }
.cat-search-btn:hover { background: var(--panel-2); color: var(--fg); }

/* Suchergebnis-Karte: Titel + 2 Aktionen */
.card-body-col { padding: 11px 13px; display: flex; flex-direction: column; gap: 10px; }
.card-btn-row { display: flex; gap: 8px; }
.card-btn { flex: 1; border: 1px solid var(--line); border-radius: 8px; padding: 8px 6px;
  cursor: pointer; font-size: .85rem; font-weight: 600; }
.card-btn.watch { background: var(--panel-2); color: var(--fg); }
.card-btn.watch:hover { border-color: var(--accent); }
.card-btn.process { background: var(--accent); color: #1a1200; border-color: var(--accent); }
.card-btn.process:hover { filter: brightness(1.08); }

/* YouTube-Vorschau-Lightbox */
.yt-preview { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.9);
  display: flex; align-items: center; justify-content: center; padding: 4vw; }
.yt-preview-frame { width: min(92vw, 1100px); aspect-ratio: 16/9; background: #000; }
.yt-preview-frame iframe, .yt-preview-frame #yt-preview-embed { width: 100%; height: 100%; border: 0; }
.yt-preview-close { position: absolute; top: 16px; right: 20px; width: 44px; height: 44px;
  border-radius: 50%; border: none; background: var(--panel); color: var(--fg); font-size: 1.2rem; cursor: pointer; }
.yt-preview-close:hover { background: var(--accent); color: #1a1200; }
.vocal { flex: 1; }
.vocal::-webkit-slider-thumb { background: #fff; }
.vocal-val { color: var(--muted); font-size: .85rem; min-width: 46px; text-align: right; font-variant-numeric: tabular-nums; }

.player-loading {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.75); color: var(--fg); font-size: 1.1rem; z-index: 20;
}

/* ── Mobile ─────────────────────────────────────────── */
@media (max-width: 720px) {
  .stage { flex-direction: column; }
  .video-wrap { flex: none; width: 100%; }
  .video-wrap #yt-frame { width: 100%; height: auto; aspect-ratio: 16/9; }
  .lyrics { flex: 1; padding: 12px 20px; }
  .lyrics .lrc-line { font-size: calc(1.6rem * var(--lyric-scale)); }
}
