:root {
  color-scheme: light dark;
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #eeece7;
  --text: #1b1c1f;
  --muted: #6a6c73;
  --line: #dedbd4;
  --accent: #c2410c;
  --accent-text: #ffffff;
  --danger: #b42318;
  --row: 60px;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121316;
    --surface: #1b1d21;
    --surface-2: #25282e;
    --text: #eceae5;
    --muted: #9a9ca3;
    --line: #2e3138;
    --accent: #fb923c;
    --accent-text: #1a1206;
    --danger: #f97066;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.35;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
h1, h2, h3 { margin: 0; font-weight: 650; }
h2 { font-size: 1.05rem; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 6px; }
.muted { color: var(--muted); font-size: .875rem; }
.spacer { flex: 1; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg.fill { fill: currentColor; stroke: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Schaltflächen */
button, input { font: inherit; color: inherit; }
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 10px 18px; cursor: pointer; min-height: 44px; white-space: nowrap;
}
.btn.small { padding: 6px 14px; min-height: 36px; font-size: .875rem; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn:hover { filter: brightness(.96); }
.icon-btn {
  border: 0; background: transparent; width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer; flex: none; position: relative;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn.toggle[aria-pressed="true"] { color: var(--accent); }
.icon-btn .badge { display: none; position: absolute; right: 6px; bottom: 5px; font-size: .625rem; font-weight: 700; }
.icon-btn[data-mode="one"] .badge { display: block; }
.icon-btn.busy svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Anmeldung */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(360px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: 20px; padding: 28px; display: grid; gap: 10px; text-align: center;
}
.login-card img { margin: 0 auto; border-radius: 16px; }
.login-card label { text-align: left; font-size: .875rem; color: var(--muted); margin-top: 8px; }
.login-card input, .dialog input[type="text"] {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); min-height: 44px;
}
.error { color: var(--danger); min-height: 1.3em; margin: 0; font-size: .875rem; }

/* Grundgerüst */
.app { height: 100dvh; display: flex; flex-direction: column; max-width: 980px; margin: 0 auto; }
.top { display: flex; gap: 4px; align-items: center; padding: calc(10px + env(safe-area-inset-top)) 12px 6px; }
.search {
  flex: 1; display: flex; align-items: center; gap: 8px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 999px; padding: 0 14px; min-width: 0;
}
.search svg { color: var(--muted); width: 18px; height: 18px; }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; padding: 11px 0; outline: none; }
.search:focus-within { border-color: var(--accent); }

.tabs { display: flex; gap: 4px; padding: 4px 12px; border-bottom: 1px solid var(--line); }
.tabs button {
  border: 0; background: transparent; padding: 10px 14px; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 600; min-height: 44px;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }

.views { flex: 1; min-height: 0; display: flex; }
.view { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.view-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; min-height: 52px; }
.view-bar.wrap { flex-wrap: wrap; }
.view-bar h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }

/* Virtuelle Liste */
.vlist { flex: 1; min-height: 0; overflow-y: auto; position: relative; overscroll-behavior: contain; }
.vlist-inner { position: relative; }
.row {
  position: absolute; left: 0; right: 0; height: var(--row);
  display: flex; align-items: center; gap: 2px; padding: 0 6px 0 4px;
}
.row-main {
  flex: 1; min-width: 0; height: 100%; border: 0; background: transparent; text-align: left; cursor: pointer;
  display: flex; flex-direction: column; justify-content: center; padding: 0 10px; border-radius: 10px;
}
.row-main:hover { background: var(--surface); }
.row-title, .row-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { color: var(--muted); font-size: .8125rem; }
.row.current .row-title { color: var(--accent); font-weight: 650; }
.row.missing .row-main { opacity: .45; cursor: default; }
.row .icon-btn { width: 40px; height: 40px; color: var(--muted); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

/* Playlists */
.cards { list-style: none; margin: 0; padding: 4px 12px 12px; overflow-y: auto; display: grid; gap: 8px; align-content: start; flex: 1; }
.cards button {
  width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; cursor: pointer; display: flex; justify-content: space-between; gap: 12px; align-items: center; min-height: 56px;
}
.cards button:hover { border-color: var(--accent); }
.cards .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Player-Leiste */
.player {
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 8px 14px calc(10px + env(safe-area-inset-bottom));
}
.seek { display: flex; align-items: center; gap: 10px; }
.time { font-variant-numeric: tabular-nums; font-size: .75rem; color: var(--muted); min-width: 36px; text-align: center; }
input[type="range"] { flex: 1; accent-color: var(--accent); height: 28px; min-width: 0; cursor: pointer; }
.player-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; }
.now { min-width: 0; }
.now-title, .now-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.now-title { font-weight: 650; }
.controls { display: flex; align-items: center; gap: 2px; }
.icon-btn.play { width: 52px; height: 52px; background: var(--accent); color: var(--accent-text); }
.icon-btn.play:hover { background: var(--accent); filter: brightness(1.06); }
.icon-btn.play svg { width: 26px; height: 26px; }
.ico-pause { display: none; }
.playing .ico-play { display: none; }
.playing .ico-pause { display: block; }
.loading .icon-btn.play { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.volume { display: flex; align-items: center; gap: 8px; justify-self: end; color: var(--muted); width: min(160px, 100%); }

/* Dialoge + Hinweise */
.dialog {
  border: 1px solid var(--line); border-radius: 18px; background: var(--surface); color: var(--text);
  padding: 20px; width: min(420px, calc(100vw - 32px)); max-height: 80dvh;
}
.dialog::backdrop { background: rgb(0 0 0 / .5); }
.dialog h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 12px; }
.dialog label { display: block; font-size: .875rem; color: var(--muted); margin-bottom: 6px; }
.dlg-actions { display: grid; gap: 8px; }
.dlg-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 34dvh; overflow-y: auto; }
.dlg-list button { width: 100%; text-align: left; border-radius: 10px; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.toast {
  position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translate(-50%, 12px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 18px; font-size: .875rem; width: max-content;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); text-align: center; z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Videos: Kachelraster + Vollbild-Wiedergabe */
.vgrid {
  flex: 1; min-height: 0; overflow-y: auto; padding: 4px 12px 16px; align-content: start;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px 12px;
}
.vcard { border: 0; background: transparent; padding: 0; text-align: left; cursor: pointer; min-width: 0; content-visibility: auto; contain-intrinsic-size: auto 150px; }
.vthumb {
  position: relative; aspect-ratio: 16 / 9; border-radius: 10px; overflow: hidden; background: var(--surface-2);
  display: grid; place-items: center; color: var(--muted);
}
.vthumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.vthumb svg { width: 30px; height: 30px; }
.vdur {
  position: absolute; right: 6px; bottom: 6px; background: rgb(0 0 0 / .75); color: #fff; border-radius: 6px;
  padding: 1px 6px; font-size: .75rem; font-variant-numeric: tabular-nums;
}
.vcard:hover .vthumb, .vcard:focus-visible .vthumb { outline: 2px solid var(--accent); outline-offset: 1px; }
.vtitle { margin-top: 6px; font-weight: 600; font-size: .875rem; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.vfolder { font-size: .75rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vmsg { grid-column: 1 / -1; padding: 40px 12px; text-align: center; color: var(--muted); display: grid; gap: 14px; justify-items: center; }
.link-btn { border: 0; background: transparent; color: var(--muted); font-size: .8125rem; text-decoration: underline; cursor: pointer; padding: 8px 6px; min-height: 36px; }
.vwarn {
  margin: 0 12px 10px; padding: 12px 14px; border-radius: var(--radius); text-align: left; cursor: pointer;
  border: 1px solid var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); font-weight: 600;
}
.vwarn.expired { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 16%, transparent); }
.cert-status { font-weight: 650; margin: 0 0 10px; }
.cert-steps { padding-left: 20px; margin: 10px 0; display: grid; gap: 10px; font-size: .9375rem; }
.cert-steps code, #dlg-cert code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: .8125rem; overflow-wrap: anywhere; }
#dlg-cert { width: min(520px, calc(100vw - 32px)); overflow-y: auto; }
#dlg-cert h2 { white-space: normal; }
.vplayer { position: fixed; inset: 0; z-index: 30; background: #000; color: #fff; display: flex; flex-direction: column; }
.vplayer-bar { display: flex; align-items: center; gap: 4px; padding: calc(4px + env(safe-area-inset-top)) 8px 4px; }
.vplayer-bar .icon-btn { color: #fff; }
.vplayer-bar .icon-btn:hover { background: #222; }
.vplayer-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vplayer video { flex: 1; min-height: 0; width: 100%; background: #000; }
@media (orientation: landscape) and (max-height: 540px) { .vplayer-bar { position: absolute; z-index: 1; background: linear-gradient(#000a, #0000); width: 100%; pointer-events: none; } .vplayer-bar > * { pointer-events: auto; } }

/* Radio-Modus: Kurzwellen-Skala wie an einem alten Röhrenradio */
.radio {
  position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column;
  background: #120b04; color: #ffd9a0; user-select: none; -webkit-user-select: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.radio-band { flex: 1; min-height: 0; width: 100%; display: block; touch-action: none; cursor: grab; }
.radio-band:active { cursor: grabbing; }
.radio-panel { display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-top: 1px solid #3b2a12; }
.radio-eye {
  --gap: 130deg;
  width: 34px; height: 34px; border-radius: 50%; flex: none; margin-right: 6px;
  background: conic-gradient(from calc(180deg - var(--gap) / 2), #04140a 0 var(--gap), #3dff8a var(--gap) 360deg);
  border: 2px solid #3b2a12; box-shadow: 0 0 10px rgb(61 255 138 / .35), inset 0 0 6px #000;
}
.radio-now { flex: 1; min-width: 0; line-height: 1.25; }
.radio-freq { font-size: .6875rem; letter-spacing: .08em; color: #c9a36a; font-variant-numeric: tabular-nums; }
.radio-title, .radio-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.radio-title { font-weight: 650; }
.radio-sub { font-size: .8125rem; color: #c9a36a; }
.radio .icon-btn { color: #ffd9a0; }
.radio .icon-btn:hover { background: #2b1d0c; }
.radio-chip {
  border: 1px solid #5a4326; background: transparent; color: #c9a36a; border-radius: 999px;
  padding: 6px 12px; min-height: 36px; font-size: .8125rem; cursor: pointer;
}
.radio-chip[aria-pressed="true"] { background: #ffd9a0; color: #120b04; border-color: #ffd9a0; font-weight: 600; }
.radio-wheel {
  height: 46px; margin: 0 12px 8px; border-radius: 10px; touch-action: none; cursor: ew-resize; position: relative;
  background: repeating-linear-gradient(90deg, #1a1208 0 3px, #6b5230 3px 5px, #2b1e0e 5px 10px);
  border: 1px solid #3b2a12;
}
.radio-wheel::after { /* Wölbung des Rändelrads */
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: linear-gradient(180deg, rgb(0 0 0 / .7), rgb(255 220 160 / .12) 45%, rgb(0 0 0 / .75));
}
@media (max-height: 300px) { .radio-wheel { height: 36px; } }

/* Easteregg „T1M3 R3WRITTEN“: andere Zeitlinie, andere Farbe */
body.rewritten { --accent: #0e7490; --accent-text: #ffffff; }
@media (prefers-color-scheme: dark) {
  body.rewritten { --accent: #22d3ee; --accent-text: #04222a; }
}
body.rewritten .time { color: var(--accent); }
body.glitch .player { animation: glitch .7s steps(2, jump-none); }
@keyframes glitch {
  0%, 100% { transform: none; filter: none; }
  20% { transform: translateX(-4px) skewX(-2deg); filter: hue-rotate(90deg); }
  40% { transform: translateX(5px); filter: invert(.15); }
  60% { transform: translateX(-2px) skewX(1deg); filter: hue-rotate(-60deg); }
  80% { transform: translateX(2px); }
}

/* Installierte Desktop-App ohne Titelleiste: die Suchzeile rückt nach oben und dient als Ziehfläche.
   Rechts bleibt Platz für die Fensterknöpfe (Minimieren/Maximieren/Schließen). */
@media (display-mode: window-controls-overlay) {
  .top {
    --controls: calc(100vw - env(titlebar-area-x, 0px) - env(titlebar-area-width, 100vw));
    --side: max(0px, (100vw - 980px) / 2);
    min-height: env(titlebar-area-height, 40px);
    padding-top: 6px;
    padding-left: calc(12px + max(0px, env(titlebar-area-x, 0px) - var(--side)));
    padding-right: calc(12px + max(0px, var(--controls) - var(--side)));
    -webkit-app-region: drag;
    app-region: drag;
  }
  .top .search, .top button { -webkit-app-region: no-drag; app-region: no-drag; }
}
/* Schmales Fenster: neben den Fensterknöpfen ist kein Platz für die Suche –
   dann bleibt oben ein leerer Ziehstreifen und die Suchzeile steht in voller Breite darunter. */
@media (display-mode: window-controls-overlay) and (max-width: 820px) {
  .top {
    padding-top: calc(env(titlebar-area-height, 34px) + 6px);
    padding-left: 12px;
    padding-right: 12px;
  }
}

@media (max-width: 640px) {
  .player-row { grid-template-columns: 1fr; gap: 4px; }
  .now { text-align: center; }
  .controls { justify-content: center; gap: 6px; }
  .volume { display: none; } /* am Handy regeln die Gerätetasten die Lautstärke */
  .tabs button { flex: 1; padding: 10px 6px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
