/* Watch2A: basato sul design system "theShow" (scuro, grana, rosso come unico accento).
   Scelta del progetto: angoli sempre quadrati (nessun raggio). */

:root {
  --bg: #0f0f0f;
  --bg-end: #1b1a18;
  --surface: #161615;
  --surface-2: #1f1e1c;
  --surface-3: #2a2926;
  --border: #302f2b;
  --fg: #fffced;
  --fg-muted: #c9c6b9;
  --brand: #fc0202;
  --brand-solid: #9c0005;
  --brand-hover: #b8000a;
  --yellow: #ffe500;
  --danger: #ff4a3d;
  --ink: #0f0f0f;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;
  --space-12: 48px;

  --display: "Archivo Black", "Archivo", ui-sans-serif, system-ui, sans-serif;
  --sans: "Archivo", ui-sans-serif, system-ui, sans-serif;
}

* { box-sizing: border-box; border-radius: 0; }
[hidden] { display: none !important; }
html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--fg);
  background: linear-gradient(180deg, var(--bg), var(--bg-end)) fixed;
  background-color: var(--bg);
  position: relative;
  overflow-x: hidden;
}

/* grana: parte dell'identità */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: url("grain.png") repeat;
  background-size: 512px 512px;
  pointer-events: none;
  z-index: 0;
}

.glow {
  position: absolute;
  inset: 0 0 auto 0;
  height: 70vh;
  background: radial-gradient(60% 55% at 50% 0%, rgb(252 2 2 / 0.3), transparent 65%);
  pointer-events: none;
  z-index: 0;
}

.topbar, main, .toast { position: relative; z-index: 1; }

h1, h2 { font-family: var(--display); font-weight: 400; margin: 0; }
p { margin: 0; }
a { color: var(--brand); }
strong { font-weight: 700; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

:focus-visible { outline: 2px solid var(--yellow); outline-offset: 2px; }

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--border);
  background: rgb(15 15 15 / 0.6);
  backdrop-filter: blur(6px);
}

.brand { display: flex; align-items: center; gap: var(--space-3); color: var(--fg); text-decoration: none; }
.logo { display: grid; place-items: center; }
.logo img { display: block; width: 64px; height: 64px; }
@media (max-width: 520px) { .logo img { width: 48px; height: 48px; } }
.wordmark { font-family: var(--display); font-size: 16px; letter-spacing: 0.04em; }

.topbar-room { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; justify-content: flex-end; }
.code { font-size: 14px; color: var(--fg-muted); margin-right: var(--space-2); }
.code b { font-family: var(--display); font-weight: 400; color: var(--fg); letter-spacing: 0.12em; margin-left: 4px; }

/* ---------- buttons / inputs ---------- */
.btn {
  appearance: none;
  border: 1px solid transparent;
  padding: 10px 16px;
  font-family: var(--display);
  font-size: 14px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  text-decoration: none;
  line-height: 1.2;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand-solid); color: var(--fg); }
.btn-primary:hover { background: var(--brand-hover); }
.btn-ghost { background: var(--surface-3); color: var(--fg); border-color: var(--border); padding: 8px 12px; font-size: 12px; }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--fg-muted); }
.btn[disabled] { opacity: 0.55; cursor: progress; }

input[type="text"] {
  width: 100%;
  font: inherit;
  color: var(--fg);
  background: var(--surface-3);
  border: 1px solid var(--border);
  padding: 11px 14px;
}
input[type="text"]::placeholder { color: #9d9a8e; }
input[type="text"]:hover { border-color: var(--fg-muted); }

.card { background: var(--surface); border: 1px solid var(--border); }

/* ---------- home ---------- */
main { padding: clamp(24px, 5vw, 56px) clamp(16px, 4vw, 40px) var(--space-12); }

.home { max-width: 1040px; margin: 0 auto; display: grid; gap: var(--space-12); }

.hero { max-width: 42rem; margin: 0 auto; width: 100%; display: grid; gap: var(--space-6); }
.hero h1 { font-size: clamp(40px, 9vw, 72px); line-height: 1.02; text-transform: uppercase; }
.lead { font-size: 18px; color: var(--fg-muted); max-width: 36rem; }

.start { padding: var(--space-6); display: grid; gap: var(--space-4); }
.field { display: grid; gap: var(--space-2); font-size: 14px; color: var(--fg-muted); }
.hint { font-size: 14px; color: var(--fg-muted); }

.join-code { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; font-size: 14px; color: var(--fg-muted); }
.join-code input { width: auto; flex: 1 1 160px; max-width: 260px; padding: 8px 12px; }

.steps {
  list-style: none; margin: 0; padding: var(--space-8) 0 0;
  border-top: 1px solid var(--border);
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--space-8);
  max-width: 42rem; margin-inline: auto; width: 100%;
}
@media (min-width: 900px) { .steps { max-width: none; } }
.steps h2 { font-size: 24px; line-height: 1.25; margin-bottom: var(--space-2); }
.steps h2 span { color: var(--brand); margin-right: 2px; }
.steps p { color: var(--fg-muted); }

/* ---------- lobby: video in primo piano ---------- */
.room {
  --vw: min(100%, 1280px, max(480px, calc((100dvh - 180px) * 16 / 9)));
  display: grid; justify-items: center; gap: var(--space-8);
}
.watch, .queue { width: var(--vw); min-width: 0; }
.watch { display: grid; gap: var(--space-4); }

main:has(> .room:not([hidden])) { padding-top: clamp(12px, 2.5vw, 28px); }

.stage {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  border: 1px solid var(--border);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
/* Dimensioni e posizione dell'iframe le imposta fitIframe() in app.js: l'iframe è più alto del video
   e il bordo in eccesso resta fuori dallo stage (overflow nascosto), così la barra del titolo in alto
   e il logo "Watch on YouTube" in basso non sono mai nell'inquadratura. */
.stage iframe, .stage #player { position: absolute; left: 0; top: 0; width: 100%; height: 100%; border: 0; pointer-events: none; }
/* link diretti: <video> nativo, senza interfaccia di terzi */
.stage #video { display: none; position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; pointer-events: none; }
.stage.is-file #video { display: block; }
.stage.is-file #player, .stage.is-vimeo #player { display: none; }
/* Vimeo: iframe del player ufficiale, senza interazione (i controlli sono i nostri) */
.stage #vimeo { display: none; position: absolute; inset: 0; background: #000; }
.stage.is-vimeo #vimeo { display: block; }
.stage #vimeo iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; pointer-events: none; }
.q-thumb-file { display: grid; place-items: center; background: var(--surface-3); color: var(--fg-muted); }
.q-thumb-file svg { width: 28px; height: 28px; }
.stage:fullscreen { aspect-ratio: auto; border: 0; width: 100vw; height: 100vh; }
.stage:fullscreen.idle { cursor: none; }

.hit { position: absolute; inset: 0; z-index: 1; }
.stage.is-host .hit { cursor: pointer; }

/* copertina: nasconde i suggerimenti di YouTube quando il video è fermo */
.cover { position: absolute; inset: 0; z-index: 2; display: grid; place-items: center; pointer-events: none; }
.cover img { display: none; position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0.55; }
.cover.thumb { background: #000; }
.cover.thumb img { display: block; }
.cover-icon {
  position: relative; width: 72px; height: 72px; display: none; place-items: center;
  background: var(--brand-solid); color: var(--fg);
}
.cover.paused .cover-icon { display: grid; }
.cover-icon svg { width: 32px; height: 32px; }

/* controlli custom */
.controls {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 3;
  padding: 36px var(--space-3) var(--space-2);
  background: linear-gradient(180deg, transparent, rgb(0 0 0 / 0.82));
  opacity: 0; transition: opacity 0.2s;
}
.stage.ui .controls, .stage.paused .controls, .controls:focus-within { opacity: 1; }
.stage.no-video .controls { display: none; }

.seek { position: relative; height: 20px; display: flex; align-items: center; cursor: default; touch-action: none; }
.stage.is-host .seek { cursor: pointer; }
.seek::before { content: ""; position: absolute; left: 0; right: 0; height: 4px; background: rgb(255 252 237 / 0.3); transition: height 0.1s; }
.seek-fill { position: relative; height: 4px; width: 0; background: var(--brand); transition: height 0.1s; }
.stage.is-host .seek:hover::before, .stage.is-host .seek:hover .seek-fill { height: 6px; }

.crow { display: flex; align-items: center; gap: var(--space-1); }
.spacer { flex: 1; }
.time { font-size: 13px; color: var(--fg); font-variant-numeric: tabular-nums; margin-left: var(--space-2); white-space: nowrap; }

.cbtn {
  all: unset; box-sizing: border-box; cursor: pointer; width: 40px; height: 40px;
  display: grid; place-items: center; color: var(--fg);
}
.cbtn:hover { background: rgb(255 252 237 / 0.16); }
.cbtn:focus-visible { outline: 2px solid var(--yellow); outline-offset: -2px; }
.cbtn svg { width: 22px; height: 22px; }
.cbtn[hidden] { display: none; }

.controls input[type="range"] { width: 84px; accent-color: var(--brand); }
@media (max-width: 520px) { .controls input[type="range"] { display: none; } .cbtn { width: 36px; height: 36px; } }

.stage-msg {
  position: absolute; inset: 0; z-index: 4;
  display: grid; place-items: center; text-align: center; padding: var(--space-6);
  background:
    radial-gradient(60% 70% at 50% 0%, rgb(252 2 2 / 0.22), transparent 70%),
    linear-gradient(180deg, var(--surface), var(--bg));
}
.stage-msg strong { display: block; font-family: var(--display); font-weight: 400; font-size: clamp(20px, 3.4vw, 32px); line-height: 1.15; text-transform: uppercase; }
.stage-msg span { display: block; margin-top: var(--space-2); color: var(--fg-muted); }
.stage-msg.tap { background: rgb(15 15 15 / 0.78); z-index: 5; }

/* titolo + occhio */
.meta { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); }
.meta-text { min-width: 0; }
.meta h2 { font-size: clamp(20px, 2.6vw, 28px); line-height: 1.2; overflow-wrap: anywhere; }
.meta p { color: var(--fg-muted); font-size: 14px; margin-top: var(--space-1); }
.meta-side { display: flex; align-items: center; gap: var(--space-4); flex: none; padding-top: 4px; }

.viewers { display: inline-flex; align-items: center; gap: var(--space-2); color: var(--fg-muted); cursor: default; }
.viewers-icon { display: grid; }
.viewers-icon svg { width: 24px; height: 24px; }
.viewers b { font-family: var(--display); font-weight: 400; font-size: 16px; color: var(--fg); }
.conn { font-size: 13px; color: var(--danger); }

/* ---------- coda (solo host) ---------- */
.queue { display: grid; gap: var(--space-3); border-top: 1px solid var(--border); padding-top: var(--space-6); }
.queue-head h2 { font-size: 24px; line-height: 1.25; display: flex; align-items: center; gap: var(--space-3); }
.count { font-family: var(--sans); font-weight: 700; font-size: 14px; background: var(--surface-3); border: 1px solid var(--border); padding: 0 10px; color: var(--fg-muted); }

.add { display: flex; gap: var(--space-2); max-width: 640px; }
.add .btn { flex: none; }
.add-err { color: var(--danger); font-size: 14px; }

.queue-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); }
.queue-empty { color: var(--fg-muted); font-size: 14px; }
.queue-list:not(:empty) + .queue-empty { display: none; }

.q-item {
  display: grid; grid-template-columns: 112px minmax(0, 1fr) auto; gap: var(--space-3); align-items: center;
  padding: var(--space-2); border: 1px solid var(--border); background: var(--surface);
}
.q-item.clickable { cursor: pointer; transition: background 0.15s, border-color 0.15s; }
.q-item.clickable:hover { background: var(--surface-2); border-color: var(--fg-muted); }
.q-item.current { border-color: var(--brand); }
.q-item.played { opacity: 0.55; }
.q-thumb { position: relative; aspect-ratio: 16 / 9; overflow: hidden; background: #000; }
.q-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.q-badge {
  position: absolute; left: 0; bottom: 0; background: var(--yellow); color: var(--ink);
  font-family: var(--display); font-size: 10px; letter-spacing: 0.04em; padding: 1px 6px;
}
.q-main { min-width: 0; }
.q-title { font-size: 14px; font-weight: 700; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.q-author { font-size: 12px; color: var(--fg-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q-title-btn { all: unset; cursor: pointer; display: block; min-width: 0; }
.q-title-btn:focus-visible { outline: 2px solid var(--yellow); outline-offset: 2px; }
.q-title-btn:hover .q-title { text-decoration: underline; }
.q-actions { display: flex; flex-direction: column; gap: 2px; }
.q-actions button { all: unset; cursor: pointer; width: 28px; height: 28px; display: grid; place-items: center; color: var(--fg-muted); }
.q-actions button:hover { background: var(--surface-3); color: var(--fg); }
.q-actions button:focus-visible { outline: 2px solid var(--yellow); outline-offset: 1px; }
.q-actions button[disabled] { opacity: 0.25; cursor: default; pointer-events: none; }
.q-actions svg { width: 18px; height: 18px; }
.q-actions .rm:hover { color: var(--danger); }

@media (max-width: 420px) { .q-item { grid-template-columns: 88px minmax(0, 1fr) auto; } }

/* ---------- avvisi ---------- */
.notice { max-width: 42rem; margin: 8vh auto 0; display: grid; gap: var(--space-6); justify-items: start; }
.notice h1 { font-size: clamp(36px, 8vw, 56px); line-height: 1.05; text-transform: uppercase; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--surface-3); border: 1px solid var(--fg-muted); color: var(--fg);
  padding: 10px 18px; font-size: 14px; z-index: 50;
  max-width: calc(100vw - 32px); text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  .btn, .controls { transition: none; }
}
