:root {
  --bg: #09090c;
  --surface: #15151b;
  --surface-2: #1f1f28;
  --border: #2a2a35;
  --text: #f1f1f5;
  --muted: #8d8da0;
  --accent: #9b6dff;
  --live: #ff4d5e;
  --ui-b: 1;            /* wird von app.js gesetzt: Helligkeit der Bedienelemente */
}
* { box-sizing: border-box; margin: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: radial-gradient(120% 60% at 50% -10%, #1a1230 0%, var(--bg) 60%) no-repeat, var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
}
a { color: inherit; text-decoration: none; }

button {
  font: inherit; color: inherit; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 14px; min-height: 52px; min-width: 52px; padding: 0 clamp(12px, 2vw, 20px);
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  font-size: clamp(16px, 2.2vmin, 20px);
}
button:active { background: var(--border); }
button.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Abdunkeln: Overlay über dem Inhalt (blockiert nichts). Bedienelemente (.ui) liegen darüber
   und werden nur sanft abgedunkelt, damit sie auffindbar bleiben. */
#dimmer { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; z-index: 50; }
.ui { position: relative; z-index: 100; }
main.ui { filter: brightness(var(--ui-b)); }   /* Buttons und Kopfzeile werden nie abgedunkelt, nur Inhalte */

/* Kopfzeile */
.bar {
  display: flex; align-items: center; gap: clamp(8px, 1.5vw, 16px);
  padding: clamp(8px, 1.5vh, 14px) clamp(12px, 2vw, 24px);
  background: rgba(9, 9, 12, .85); border-bottom: 1px solid var(--border);
}
.bar h1 { font-size: clamp(20px, 3.2vmin, 28px); font-weight: 700; letter-spacing: .04em; flex: 1; }
.bar h1 span { color: var(--accent); }
.bar .title {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px;
  font-size: clamp(16px, 2.6vmin, 22px); font-weight: 600;
}
.bar .title b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }

/* LIVE-Badge */
.badge {
  display: none; align-items: center; gap: 6px; flex: none;
  background: var(--live); color: #fff; border-radius: 999px;
  padding: 3px 10px; font-size: 12px; font-weight: 700; letter-spacing: .05em;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #fff; }
.live .badge, .badge.live { display: inline-flex; }

/* Startseite: Kacheln */
main { flex: 1; overflow-y: auto; padding: clamp(12px, 2.5vw, 32px); }
main h2 { font-size: clamp(14px, 2vmin, 17px); font-weight: 650; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; margin: 6px 2px 12px; }
.tiles {
  display: grid; gap: clamp(12px, 2vw, 24px); margin-bottom: clamp(18px, 3vh, 32px);
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
}
@media (max-width: 700px) { .tiles { grid-template-columns: repeat(2, 1fr); } }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }

/* Suche: Feld legt sich über die Kopfzeile (kein Verschieben der Kacheln) */
.bar { position: relative; }
.searchbar {
  position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: 0 clamp(12px, 2vw, 24px); background: var(--bg); border-bottom: 1px solid var(--border);
}
.searchbar[hidden], #menu[hidden], .openrow[hidden] { display: none; }
.sicon { color: var(--muted); display: grid; }
.searchbar input {
  flex: 1; min-width: 0; min-height: 52px; border-radius: 14px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); padding: 0 16px; font: inherit; font-size: clamp(16px, 2.2vmin, 20px);
}
.searchbar input:focus { outline: 2px solid var(--accent); }
.openrow { display: flex; gap: 10px; margin-bottom: 18px; }
.openrow > * { flex: 1; min-height: 56px; border-radius: 14px; }
.openrow .btn { display: flex; align-items: center; justify-content: center; background: var(--accent); color: #fff; font-weight: 650; overflow: hidden; text-overflow: ellipsis; }

.tile {
  position: relative; overflow: hidden; display: flex; align-items: flex-end;
  aspect-ratio: 16 / 9; border-radius: 22px; padding: clamp(10px, 2vmin, 18px);
  background: linear-gradient(145deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
}
.tile.live { border-color: rgba(255, 77, 94, .55); box-shadow: 0 0 0 1px rgba(255, 77, 94, .25), 0 8px 30px rgba(255, 77, 94, .12); }
.tile { content-visibility: auto; contain-intrinsic-size: auto 200px; }   /* nicht sichtbare Kacheln kosten kaum Rendering */
.tile:active { transform: scale(.985); }
.cover { position: absolute; inset: 0; z-index: 3; }
.thumb { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: none; }
.tile.live .thumb { display: block; }
.tile::after {   /* Verlauf für Lesbarkeit des Textes */
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, .85), rgba(0, 0, 0, .1) 60%, rgba(0, 0, 0, .25));
}
.chips { position: absolute; top: 12px; left: 12px; z-index: 2; display: flex; gap: 6px; }
.viewers { display: none; background: rgba(0, 0, 0, .6); border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 600; }
.tile.live .viewers:not(:empty) { display: block; }
.dots {
  position: absolute; top: 6px; right: 6px; z-index: 4; min-width: 44px; min-height: 44px; width: 44px; height: 44px;
  padding: 0; border-radius: 50%; background: rgba(0, 0, 0, .45); border: 0; font-size: 22px; line-height: 1;
}

/* Kachel-Menü */
#menu {
  position: fixed; z-index: 200; display: grid; gap: 4px; padding: 6px; min-width: 240px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 12px 40px rgba(0, 0, 0, .6);
}
#menu button { justify-content: flex-start; background: transparent; border: 0; min-height: 52px; }
#menu button:active { background: var(--border); }

.meta { position: relative; z-index: 2; display: flex; align-items: center; gap: clamp(8px, 1.5vmin, 14px); min-width: 0; width: 100%; }
.avatar {
  flex: none; width: clamp(40px, 8vmin, 60px); aspect-ratio: 1; border-radius: 50%; object-fit: cover;
  background: linear-gradient(135deg, var(--accent), #5b8cff);
  display: grid; place-items: center; font-weight: 700; color: #fff; font-size: clamp(18px, 3.4vmin, 26px);
  border: 2px solid rgba(255, 255, 255, .15);
}
.tile:not(.live) .avatar { filter: grayscale(.7); opacity: .85; }
.text { min-width: 0; }
.name { font-size: clamp(16px, 2.8vmin, 24px); font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game { color: #c9b6ff; font-size: clamp(12px, 1.9vmin, 15px); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game:empty { display: none; }
.sub { color: #c5c5d2; font-size: clamp(12px, 1.8vmin, 14px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile:not(.live) .game { color: var(--muted); font-weight: 400; }

/* Player-Seite */
#stage {
  --size: 100;
  flex: 1; min-height: 0; container-type: size; position: relative; overflow: hidden; background: #f4f7fb;
  display: grid; justify-items: var(--jx, center); align-items: var(--ay, center);
}
.pwrap {
  position: relative; z-index: 2; background: #000;
  width: min(calc(var(--size) * 1cqw), calc(var(--size) * 1cqh * 16 / 9));
  aspect-ratio: 16 / 9; box-shadow: 0 12px 50px rgba(30, 50, 90, .28);
}
#player { width: 100%; height: 100%; border: 0; display: block; }
.pwrap #dimmer { position: absolute; z-index: 3; }   /* nur über dem Video */

/* Navigations-Hintergrund: helle Karte in Perspektive, zweispurige Straße weit rechts */
#nav {
  --cx: 70%;            /* Horizontale Lage der Straßenmitte (Fluchtpunkt) */
  position: absolute; inset: 0; z-index: 0; overflow: hidden; perspective: 520px; perspective-origin: var(--cx) 0;
  background: linear-gradient(#e8eef6, #f6f8fc 45%, #f1f4f9);
}
#nav::after {   /* Dunst am Horizont */
  content: ""; position: absolute; inset: 0 0 auto 0; height: 45%; pointer-events: none;
  background: linear-gradient(#f9fbfe 0, rgba(249, 251, 254, 0));
}
.plane {
  position: absolute; left: calc(var(--cx) - 100%); width: 200%; bottom: -25%; height: 260%;
  transform-origin: 50% 100%; transform: rotateX(68deg); overflow: hidden; background: #eef2e6;
}
.scroller { position: absolute; left: 0; right: 0; top: -720px; bottom: 0; will-change: transform; animation: roll 4s linear infinite; }
@keyframes roll { to { transform: translateY(720px); } }   /* 720px = gemeinsame Periode aller Muster */

/* Ruhige Landschaft: sanfte Wiesen- und Feldflächen, vereinzelte Gebäude */
.scene {
  position: absolute; inset: 0;
  background:
    /* vereinzelte Gebäude (je eines pro 720 px) */
    linear-gradient(#d3dae6 0 64px, transparent 64px) 80% 120px / 7% 720px repeat-y,
    linear-gradient(#dde2ec 0 90px, transparent 90px) 22% 480px / 9% 720px repeat-y,
    linear-gradient(#cdd5e2 0 52px, transparent 52px) 91% 520px / 6% 720px repeat-y,
    linear-gradient(#d8dee9 0 70px, transparent 70px) 12% 60px / 6% 720px repeat-y,
    /* Felder */
    linear-gradient(#e2ecd6 0 260px, transparent 260px) 8% 0 / 24% 480px repeat-y,
    linear-gradient(#f3efdc 0 200px, transparent 200px) 94% 240px / 22% 360px repeat-y,
    linear-gradient(#e6efdb 0 180px, transparent 180px) 78% 0 / 18% 720px repeat-y,
    #eef2e6;
}

/* Zweispurige Straße: Randlinien, gestrichelte Mittellinie, blaue Route in der rechten Spur */
.road {
  position: absolute; top: 0; bottom: 0; left: 43%; width: 14%; background: #fff;
  box-shadow: 0 0 0 .5% #b9c5d6, 0 0 0 1.7% #fafbfd;
}
.road::before, .road::after { content: ""; position: absolute; top: 0; bottom: 0; width: 2%; background: #cfd8e4; }
.road::before { left: 5%; }
.road::after { right: 5%; }
.lanes { background: linear-gradient(#bcc8d9 0 40px, transparent 40px) 50% 0 / .42% 90px repeat-y; }
.route { position: absolute; top: 0; bottom: 0; left: 52.6%; width: 1.8%; background: #5b9dff; border-radius: 3px; box-shadow: 0 0 0 .3% #fff; }
.arrow {
  position: absolute; left: 77%; bottom: 1.5%; width: clamp(48px, 9vmin, 80px); transform: translateX(-50%);
  filter: drop-shadow(0 6px 8px rgba(30, 80, 190, .35)); animation: bob 1.8s ease-in-out infinite;
}
.arrow .halo { fill: rgba(91, 157, 255, .18); }
.arrow path { fill: #1a73e8; stroke: #fff; stroke-width: 3; stroke-linejoin: round; }
@keyframes bob { 50% { transform: translateX(-50%) translateY(-4px); } }

/* HUD: Spalte am rechten Rand */
.hud-col {
  position: absolute; z-index: 1; top: clamp(8px, 1.6vmin, 16px); right: clamp(8px, 1.6vmin, 16px);
  display: flex; flex-direction: column; align-items: flex-end; gap: clamp(6px, 1.2vmin, 12px);
}
.hud {
  display: flex; align-items: center; gap: clamp(8px, 1.4vmin, 14px);
  background: rgba(255, 255, 255, .92); color: #1c2b3a; border-radius: 16px;
  box-shadow: 0 4px 18px rgba(30, 50, 90, .15); font-size: clamp(15px, 2.9vmin, 24px);
}
.hud b { display: block; font-size: 1.25em; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.hud small { display: block; color: #6b7a8c; font-size: .85em; white-space: nowrap; }
.hud-turn { padding: clamp(6px, 1.2vmin, 12px) clamp(10px, 1.8vmin, 16px) clamp(6px, 1.2vmin, 12px) clamp(6px, 1.2vmin, 12px); }
.hud-ic { display: grid; place-items: center; width: 2.6em; height: 2.6em; border-radius: 12px; background: #1a73e8; color: #fff; }
.hud-ic .i { width: 1.7em; height: 1.7em; stroke-width: 2.6; }
.hud-eta { gap: clamp(12px, 2.2vmin, 22px); padding: clamp(6px, 1.2vmin, 12px) clamp(12px, 2vmin, 20px); }
.hud-eta small { text-align: center; }
.hud-limit { width: 3.4em; height: 3.4em; justify-content: center; border-radius: 50%; border: .4em solid #e5352b; font-weight: 800; font-size: clamp(16px, 3.2vmin, 28px); }
@media (prefers-reduced-motion: reduce) { .scroller, .arrow { animation: none; } }

/* Steuerleiste unten: Regler | Transport | Position */
.controls {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  gap: clamp(12px, 2.5vw, 32px);
  padding: clamp(10px, 1.8vh, 18px) clamp(12px, 2vw, 24px);
  background: rgba(9, 9, 12, .94); border-top: 1px solid var(--border);
}
.sliders { display: grid; gap: clamp(2px, .6vh, 8px); min-width: 0; }
.row { display: grid; grid-template-columns: 1fr auto; align-items: end; column-gap: 12px; }
.row label { grid-column: 1; grid-row: 1; color: var(--muted); font-size: clamp(14px, 2.1vmin, 19px); }
.row output { grid-column: 2; grid-row: 1; text-align: right; font-size: clamp(14px, 2.1vmin, 19px); font-variant-numeric: tabular-nums; }
.row input[type=range] { grid-column: 1 / -1; grid-row: 2; height: 46px; }

.transport { display: flex; align-items: center; justify-content: center; gap: clamp(12px, 2.4vw, 26px); }
.transport button { width: clamp(52px, 8vmin, 64px); height: clamp(52px, 8vmin, 64px); padding: 0; border-radius: 50%; }
.transport #playpause {
  width: clamp(68px, 11vmin, 88px); height: clamp(68px, 11vmin, 88px);
  background: #f1f1f5; border-color: #f1f1f5; color: #09090c; box-shadow: 0 6px 24px rgba(255, 255, 255, .12);
}
.transport #playpause:active { background: #d4d4dc; }
.transport #playpause .i { width: 1.9em; height: 1.9em; }

/* Positions-Pad 3x3 */
.pad { width: 100%; max-width: 340px; justify-self: center; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.pad button {
  --c: clamp(42px, 7.2vmin, 56px); width: 100%; height: var(--c); min-width: 0; min-height: 0; padding: 0;
  border-radius: 10px; position: relative;
}
.pad button::after { content: ""; width: 38%; height: 38%; border-radius: 4px; background: var(--muted); opacity: .6; }
.pad button.on::after { background: #fff; opacity: 1; }

input[type=range] { flex: 1; min-width: 0; height: 60px; background: transparent; -webkit-appearance: none; appearance: none; }
input[type=range]::-webkit-slider-runnable-track { height: 10px; border-radius: 5px; background: var(--border); }
input[type=range]::-moz-range-track { height: 10px; border-radius: 5px; background: var(--border); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 40px; height: 40px; margin-top: -15px; border-radius: 50%;
  background: var(--accent); border: 3px solid var(--bg); box-shadow: 0 0 0 1px var(--accent);
}
input[type=range]::-moz-range-thumb { width: 36px; height: 36px; border-radius: 50%; background: var(--accent); border: 3px solid var(--bg); }

@media (max-height: 520px) {
  button { min-height: 44px; }
  input[type=range] { height: 38px; }
}
@media (max-width: 460px) {
}

/* Startseite vs. Suche */
main:not(.searching) .s-search, main.searching .s-home { display: none; }
#sentinel { height: 1px; }
.gametxt { color: var(--muted); font-size: clamp(12px, 1.9vmin, 15px); font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 560px) { .gametxt { display: none; } }

/* Icons */
.i { width: 1.35em; height: 1.35em; flex: none; display: block; }
button .i { width: 1.4em; height: 1.4em; }
.star { display: inline-flex; vertical-align: -.15em; margin-right: .3em; color: #ffcf5c; }
.star .i { width: 1em; height: 1em; }
.viewers { align-items: center; gap: 5px; }
.viewers .i { width: 14px; height: 14px; }
.tile.live .viewers:not(:empty) { display: inline-flex; }
main h2 { display: flex; align-items: center; gap: 8px; }
main h2 .i { width: 1.1em; height: 1.1em; color: #ffcf5c; }
.livedot { width: 10px; height: 10px; border-radius: 50%; background: var(--live); box-shadow: 0 0 10px var(--live); }
#menu button .i { width: 1.2em; height: 1.2em; }
#menu button:first-child .i { color: #ffcf5c; }

/* Pause: Player ausgeblendet, nur die Navigation bleibt */
#stage.paused .pwrap { display: none; }

/* Schmale Bildschirme: Transport oben in der Leiste, darunter Regler und Pad */
@media (max-width: 760px) {
  .controls { grid-template-columns: 1fr auto; grid-template-areas: "tr tr" "sl pd"; }
  .transport { grid-area: tr; }
  .sliders { grid-area: sl; }
  .pad { grid-area: pd; width: clamp(160px, 42vw, 220px); }
}
