:root {
  --bg: #0f1115;
  --surface: #1a1d24;
  --surface-2: #242833;
  --text: #e8eaf0;
  --muted: #9aa1b2;
  --accent: #6d8cff;
  --danger: #e5484d;
  --border: #2e3340;
  --radius: 10px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f8;
    --surface: #ffffff;
    --surface-2: #eceef3;
    --text: #1b1e26;
    --muted: #5d6475;
    --accent: #3f5fe0;
    --danger: #c9353a;
    --border: #d9dce4;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, sans-serif; }
[hidden] { display: none !important; }

button, input { font: inherit; color: inherit; }
input {
  width: 100%; padding: .55em .7em; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2);
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
button {
  padding: .55em 1em; border-radius: 8px; border: 0; cursor: pointer;
  background: var(--accent); color: #fff; white-space: nowrap;
}
button:disabled { opacity: .45; cursor: not-allowed; }
button.ghost { background: var(--surface-2); color: var(--text); }
button.danger { background: var(--danger); }
button.off { background: var(--surface-2); color: var(--muted); text-decoration: line-through; }

.muted { color: var(--muted); }
.error { color: var(--danger); margin: 0; }
.hint { color: var(--muted); font-size: .9em; margin: 0; border-left: 3px solid var(--accent); padding-left: .6em; }

/* join */
#join-view { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card {
  width: min(420px, 100%); display: grid; gap: 14px; padding: 24px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.card h1 { margin: 0; font-size: 1.5em; }
.card p { margin: 0; }
.card label { display: grid; gap: 4px; font-weight: 500; }

/* room */
#room-view {
  height: 100%; display: grid; row-gap: 12px; padding: 12px;
  grid-template-columns: 1fr 12px min(var(--chat-w, 400px), 60vw);
  grid-template-rows: auto 1fr auto;
  grid-template-areas: "bar bar bar" "grid split chat" "controls split chat";
}
/* drag handle between videos and chat; doubles as the gap */
#splitter { grid-area: split; cursor: col-resize; touch-action: none; position: relative; }
#splitter::after {
  content: ""; position: absolute; top: 50%; left: 4px; width: 4px; height: 40px; translate: 0 -50%;
  border-radius: 2px; background: var(--border);
}
#splitter:hover::after, #splitter.dragging::after { background: var(--accent); }
body.resizing { cursor: col-resize; user-select: none; }
.bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
#room-view > header { grid-area: bar; }
.controls { grid-area: controls; justify-content: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.size { display: flex; align-items: center; gap: 4px; color: var(--muted); }
.size input { width: 140px; padding: 0; accent-color: var(--accent); }

#grid {
  grid-area: grid; min-height: 0; overflow-y: auto; container-type: inline-size; position: relative;
  display: flex; justify-content: center; align-items: flex-start;
}
/* shrinks to the width of the others, so the own tile lines up with their right edge */
.stage { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; max-width: 100%; }
#remotes { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: flex-start; }
#remotes:empty { display: none; }
/* shared-link video player, twice as wide as a video tile */
#player {
  position: relative; margin: 0; align-self: center; overflow: hidden;
  width: min(var(--tile-w, 320px) * 2, 100cqw);
  background: #000; border: 1px solid var(--border); border-radius: var(--radius);
}
#player .frame { aspect-ratio: 16 / 9; }
#player .frame > *, #player iframe { width: 100%; height: 100%; border: 0; display: block; }
.player-bar {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px;
  background: var(--surface); color: var(--text); font-size: .9em;
}
.player-bar .pos { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.player-bar .now { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-bar button { padding: 2px 12px; }
#player .close {
  position: absolute; top: 6px; right: 6px; padding: 2px 8px;
  background: rgb(0 0 0 / .6); color: #fff;
}
#player .unmute {
  position: absolute; left: 50%; bottom: 56px; translate: -50% 0;
  box-shadow: 0 4px 14px rgb(0 0 0 / .4);
}
.tile {
  position: relative; margin: 0; overflow: hidden; flex: none;
  width: min(var(--tile-w, 320px), 100cqw); aspect-ratio: 16 / 9;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  cursor: zoom-in;
}
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; }
.tile:fullscreen { cursor: zoom-out; border: 0; border-radius: 0; }
.tile:fullscreen video { object-fit: contain; }
.tile.self { width: min(var(--tile-w, 320px) / 2, 100cqw); }
.tile.self video { transform: scaleX(-1); }
.tile.self figcaption { left: 4px; bottom: 4px; font-size: .75em; }
/* own tile can be dragged anywhere in the video area */
.tile.self { cursor: grab; touch-action: none; }
.tile.self.floating { position: absolute; z-index: 2; box-shadow: 0 6px 20px rgb(0 0 0 / .4); }
.tile.self.dragging { cursor: grabbing; opacity: .9; }
.tile .reset {
  display: none; position: absolute; top: 4px; right: 4px; padding: 0 6px; font-size: .8em;
  background: rgb(0 0 0 / .55); color: #fff;
}
.tile.self.floating:hover .reset { display: block; }
.tile .avatar {
  display: none; position: absolute; inset: 0; place-items: center;
  font-size: 2.6em; font-weight: 600; color: var(--muted); background: var(--surface);
}
.tile.novideo .avatar { display: grid; }
.tile figcaption {
  position: absolute; left: 8px; bottom: 8px; display: flex; gap: 6px; align-items: center;
  padding: 2px 8px; border-radius: 6px; background: rgb(0 0 0 / .55); color: #fff; font-size: .9em;
}
.tile .state:empty { display: none; }

#chat {
  grid-area: chat; min-height: 0; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
#messages { flex: 1; overflow-y: auto; list-style: none; margin: 0; padding: 12px; display: grid; align-content: start; gap: 8px; }
#messages li { overflow-wrap: anywhere; white-space: pre-wrap; }
#messages .meta { color: var(--muted); font-size: .8em; }
#messages .mine .who { color: var(--accent); }
#messages a { color: var(--accent); }
#messages .system { color: var(--muted); font-size: .85em; font-style: italic; }
#chat-form { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--border); }

/* buttons under a YouTube link in the chat, and in playlist rows */
.video-actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; white-space: normal; }
.video-actions button { padding: 2px 10px; font-size: .85em; }
.video-actions button.ghost:disabled { opacity: .7; }

.tabs { display: flex; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs button {
  flex: 1; padding: .6em .5em; border-radius: 0; background: none; color: var(--muted);
  border-bottom: 2px solid transparent; font-size: .9em;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tabs .count:not(:empty) {
  display: inline-block; min-width: 1.5em; padding: 0 .4em; border-radius: 999px;
  background: var(--surface-2); font-size: .8em; font-weight: 500;
}
.pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.playlist .hint-line { margin: 0; padding: 10px 12px 0; color: var(--muted); font-size: .85em; }
.playlist .items { flex: 1; overflow-y: auto; list-style: none; margin: 0; padding: 12px; display: grid; align-content: start; gap: 10px; }
.playlist .items:empty::before { content: "Noch keine Videos."; color: var(--muted); font-style: italic; }
.playlist li { display: grid; grid-template-columns: 96px 1fr; gap: 10px; align-items: start; }
.playlist img { width: 96px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 6px; background: var(--surface-2); }
.playlist .title { color: var(--text); font-weight: 500; overflow-wrap: anywhere; text-decoration: none; }
.playlist .title:hover { text-decoration: underline; }
.playlist .by { color: var(--muted); font-size: .8em; }
.playlist .actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px; border-top: 1px solid var(--border); }
.playlist .actions a { color: var(--accent); font-size: .9em; }
.playlist .actions [aria-disabled="true"] { pointer-events: none; opacity: .45; }

@media (max-width: 800px) {
  #room-view {
    height: auto; min-height: 100%;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto 360px;
    grid-template-areas: "bar" "grid" "controls" "chat";
  }
  #splitter { display: none; }
  #grid { overflow: visible; }
  .size input { width: 90px; }
}

/* live playlist: cover, title, duration */
.live-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.live-head .summary { flex: 1; color: var(--muted); font-size: .85em; text-align: right; }
.live .items { flex: 1; overflow-y: auto; list-style: none; margin: 0; padding: 6px; display: grid; align-content: start; gap: 2px; }
.live .items:empty::before {
  content: "Noch leer. YouTube-Links und Playlists aus dem Chat landen hier."; padding: 8px; color: var(--muted); font-style: italic;
}
.live li {
  display: grid; grid-template-columns: 72px 1fr auto auto; gap: 10px; align-items: center;
  padding: 6px; border-radius: 8px; cursor: pointer;
}
.live li:hover { background: var(--surface-2); }
.live li.current { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.live li.current .title { font-weight: 600; }
.live li.played { opacity: .55; }
.live li.blocked { opacity: .45; }
.live li.blocked .title { text-decoration: line-through; }
.live img { width: 72px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 4px; background: var(--surface-2); }
.live .title { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.live .time { color: var(--muted); font-size: .85em; font-variant-numeric: tabular-nums; }
.live .remove { visibility: hidden; padding: 0 6px; background: none; color: var(--muted); }
.live li:hover .remove, .live .remove:focus-visible { visibility: visible; }
.live .actions { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }

