:root {
  --bg: #000;
  --panel: #0c0e12;
  --panel-2: #14171d;
  --line: #23262e;
  --maroon: rgba(150, 45, 55, .45);
  --maroon-hot: rgba(205, 70, 82, .9);
  --shell: 1560px;
  /* Side breathing room at any viewport, capped so it never eats the wall. */
  --gutter: clamp(18px, 4vw, 72px);
  --text: #e8ecf3;
  --muted: #8b95a7;
  --accent: #4ea1ff;
  --accent-2: #2b7fd4;
  --ok: #3fce8a;
  --bad: #ff6b6b;
  --radius: 12px;
}

* { box-sizing: border-box; }

/* `display` in a class rule outranks the UA sheet's [hidden] { display: none },
   so .modal/.spinner would stay on screen forever. Keep this above them. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, sans-serif;
}

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

header {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  padding: 16px 0 34px;
  position: sticky;
  top: 0;
  z-index: 5;
  /* Content scrolls under a black bar that dissolves instead of ending on a line. */
  background: linear-gradient(180deg, #000 0%, #000 55%, rgba(0, 0, 0, .82) 78%, transparent 100%);
  pointer-events: none;
}

header > * { pointer-events: auto; }

header h1 {
  margin: 0;
  font-size: 17px;
  letter-spacing: .3px;
}

header h1 span { color: var(--accent); }

.spacer { flex: 1; }

.status { font-size: 13px; color: var(--muted); }
.status.ok { color: var(--ok); }
.status.bad { color: var(--bad); }

input[type=text], input[type=search] {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 9px;
  min-width: 240px;
  outline: none;
}

input:focus { border-color: var(--accent-2); }

button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  padding: 9px 14px;
  border-radius: 9px;
  cursor: pointer;
  font: inherit;
}

button:hover { border-color: var(--accent-2); }
button.primary { background: var(--accent-2); border-color: var(--accent-2); }
button.primary:hover { background: var(--accent); }
button:disabled { opacity: .5; cursor: default; }

main {
  padding: 4px 0 56px;
  max-width: var(--shell);
  margin: 0 auto;
  padding-inline: var(--gutter);
}

header {
  max-width: var(--shell);
  margin: 0 auto;
  padding-inline: var(--gutter);
}

/* Search results are a plain grid — a moving row is no way to read a result set. */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 16px;
}

/* --------------------------------------------------- sliding library rows */

.rows { display: flex; flex-direction: column; gap: 18px; }
.sentinel { height: 1px; }

.row {
  overflow: hidden;
  cursor: grab;
  /* Horizontal drags belong to the row; vertical gestures still scroll the page. */
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  /* Fade the ends so cards enter and leave instead of popping. */
  mask-image: linear-gradient(90deg, transparent, #000 4%, #000 96%, transparent);
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 4%, #000 96%, transparent);
}

.row.grabbing { cursor: grabbing; }
.row * { -webkit-user-drag: none; }

.track {
  display: flex;
  gap: 14px;
  width: max-content;
  will-change: transform;
}

.track .card { width: 186px; flex: none; }

/* A card is the artwork and nothing else: the title sits on it, over a gradient. */
.card {
  background: #000;
  border: 1px solid var(--maroon);
  border-radius: 0;
  overflow: hidden;
  cursor: pointer;
  display: block;
  transition: border-color .15s ease, box-shadow .15s ease;
}

.card:hover {
  border-color: var(--maroon-hot);
  box-shadow: 0 0 0 1px rgba(205, 70, 82, .25), 0 6px 26px rgba(0, 0, 0, .7);
}

.card .poster {
  position: relative;
  aspect-ratio: 2 / 3;
  background: #07080a;
  display: block;
  overflow: hidden;
}

.card .poster img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Placeholder glyph, only visible until artwork arrives (or if there is none). */
.card .ph {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 34px;
  color: #2b3038;
}

.card .poster img ~ .ph { display: none; }

.card .cap {
  position: absolute;
  inset: auto 0 0 0;
  padding: 30px 10px 9px;
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, .8) 45%, #000 100%);
  pointer-events: none;
  /* Hidden until hover, then rises into place. */
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .25s ease, transform .25s ease;
}

.card:hover .cap,
.card:focus-visible .cap { opacity: 1; transform: none; }

/* No artwork means the title is the only identification: keep it visible. */
.card.noart .cap { opacity: 1; transform: none; }
.card.hasart .cap { opacity: 0; transform: translateY(8px); }
.card.hasart:hover .cap { opacity: 1; transform: none; }

.card .cap .t {
  display: block;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .9);
  /* Two lines at most, then ellipsis. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.notice {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 13px;
}

.notice.bad { border-left-color: var(--bad); color: #ffd7d7; }

.card .badge {
  position: absolute;
  top: 7px;
  left: 7px;
  z-index: 1;
  background: rgba(0, 0, 0, .8);
  border: 1px solid var(--maroon);
  border-radius: 0;
  color: var(--text);
  font-size: 10px;
  letter-spacing: .3px;
  padding: 3px 7px;
  opacity: 0;
  transition: opacity .15s ease;
}

.card:hover .badge { opacity: 1; }

/* ----------------------------------------------------------------- modal */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 10, .75);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 20;
}

.sheet {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  width: min(760px, 100%);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.sheethead {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.filelist { overflow-y: auto; padding: 6px; }

.sheethead select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 10px;
  font: inherit;
  font-size: 12px;
}

.filerow.dead { opacity: .45; }
.filerow.dead:hover { background: rgba(255, 107, 107, .08); }

.live {
  font-size: 10px;
  padding: 3px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  white-space: nowrap;
  color: var(--muted);
}

.live.ok { color: var(--ok); border-color: #245c41; }
.live.no { color: var(--bad); border-color: #6b2525; }

.filerow {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.filerow:hover { background: var(--panel-2); }
.filerow .n { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.filerow .n b { font-size: 13px; font-weight: 600; }
.filerow .n small,
.filerow .n b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filerow .n small { color: var(--muted); font-size: 11px; }
.filerow .z { color: var(--muted); font-size: 12px; white-space: nowrap; }
.filerow.err { color: #ffd7d7; background: rgba(255, 107, 107, .1); }

.qbadge {
  font-size: 11px;
  font-weight: 700;
  padding: 4px 7px;
  border-radius: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  min-width: 52px;
  text-align: center;
}

.qbadge.hi { color: #ffd166; border-color: #6b5a25; }

.pathbadge {
  font-size: 10px;
  padding: 3px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  white-space: nowrap;
}

.pathbadge.direct { color: var(--ok); border-color: #245c41; }
.pathbadge.remux { color: var(--accent); border-color: #244a6b; }
.pathbadge.encode { color: #ffb545; border-color: #6b5325; }

/* Resolution tier badge: 4K / 2K / FHD / HD / SD, always on the artwork. */
.card .res {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 1;
  width: 26px;
  height: 26px;
  color: #fff;
  opacity: 0;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, .95));
  transition: opacity .25s ease, transform .25s ease;
  transform: translateY(-4px);
}

.card:hover .res { opacity: 1; transform: none; }
.card .res svg { width: 100%; height: 100%; display: block; }

/* ------------------------------------------------------------------ room */

.room {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 16px;
  align-items: start;
}

@media (max-width: 900px) { .room { grid-template-columns: 1fr; } }

.stage {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  overflow: hidden;
}

video {
  width: 100%;
  background: #000;
  display: block;
  max-height: 72vh;
}

.stage:fullscreen video { max-height: 100vh; height: 100vh; }

.spinner {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  background: rgba(4, 6, 10, .55);
  color: var(--text);
  font-size: 13px;
}

.spinner span {
  width: 34px;
  height: 34px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.controls {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  flex-wrap: wrap;
}

.controls input[type=range] { accent-color: var(--accent); }

.controls select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 10px;
  font: inherit;
  font-size: 13px;
  max-width: 220px;
}

.controls select:disabled { opacity: .5; }

video::cue { background: rgba(0, 0, 0, .65); font-size: 90%; }
#seek { flex: 1; min-width: 140px; }
#vol { width: 90px; flex: none; }
.mono { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }

.bar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 12px;
}

.pill {
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 6px 11px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
}

.pill.live { color: var(--ok); }

.side {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 82vh;
}

.side h2 { margin: 0; font-size: 14px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .6px; }

.invite { display: flex; gap: 8px; }
.invite input { min-width: 0; flex: 1; font-size: 12px; }

#log {
  flex: 1;
  overflow-y: auto;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 160px;
}

#log .sys { color: var(--muted); font-style: italic; }
#log .who { color: var(--accent); font-weight: 600; }

.chatrow { display: flex; gap: 8px; }
.chatrow input { flex: 1; min-width: 0; }
