/* CineRoom v2 — cinematic dark theme */
:root {
  --bg: #0a0a0f;
  --panel: #14141c;
  --panel2: #1c1c26;
  --line: #2a2a38;
  --text: #f2f2f7;
  --muted: #8f8f9f;
  --accent: #e50914;
  --accent2: #ff2e3f;
  --ok: #2dd4a7;
  --warn: #f5a623;
  --whisper: #f0b429;
  --radius: 16px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body { background: var(--bg); color: var(--text); font-family: var(--font); overflow: hidden; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--accent2); min-height: 1.2em; margin-top: 10px; font-size: 14px; }
.spacer { flex: 1; }

.screen { height: 100dvh; display: flex; align-items: center; justify-content: center; animation: screenIn .35s ease; }
@keyframes screenIn { from { opacity: 0; transform: scale(.985); } to { opacity: 1; transform: none; } }

/* ---------- logo ---------- */
.logo { font-weight: 900; letter-spacing: 2px; font-size: 34px; color: var(--text); }
.logo span { color: var(--accent); }
.logo.mini { font-size: 15px; letter-spacing: 1px; }

/* ---------- lobby ---------- */
#lobby { position: relative; overflow: hidden; }
.hero-glow {
  position: absolute; width: 130vmax; height: 130vmax; border-radius: 50%;
  background: radial-gradient(circle, rgba(229,9,20,.14) 0%, transparent 55%);
  top: 50%; left: 50%; transform: translate(-50%, -60%);
  animation: breathe 8s ease-in-out infinite; pointer-events: none;
}
@keyframes breathe { 0%,100% { opacity: .7; } 50% { opacity: 1; } }
.lobby-card, .library-card {
  position: relative; background: rgba(20,20,28,.85); backdrop-filter: blur(20px);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 44px 36px;
  width: min(430px, 92vw); text-align: center; box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
.tagline { color: var(--muted); margin: 8px 0 28px; font-size: 15px; }
input[type=text], input[type=url] {
  width: 100%; padding: 14px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text); font-size: 15px; outline: none;
  transition: border-color .2s, box-shadow .2s;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(229,9,20,.15); }
.lobby-actions { display: flex; flex-direction: column; gap: 14px; margin: 18px 0; }
.or-line { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }
.or-line::before, .or-line::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.join-row { display: flex; gap: 8px; }
.join-row input { text-transform: uppercase; letter-spacing: 8px; text-align: center; font-weight: 800; font-size: 18px; }

/* ---------- buttons ---------- */
.btn {
  padding: 12px 20px; border-radius: 10px; border: 1px solid var(--line); cursor: pointer;
  background: var(--panel2); color: var(--text); font-size: 15px; font-weight: 600; font-family: var(--font);
  transition: transform .08s, background .2s, box-shadow .2s, border-color .2s;
}
.btn:hover { border-color: #3a3a4c; }
.btn:active { transform: scale(.96); }
.btn.primary { background: var(--accent); border-color: var(--accent); }
.btn.primary:hover { background: var(--accent2); box-shadow: 0 6px 24px rgba(229,9,20,.35); }
.btn.big { padding: 15px 26px; font-size: 16px; }
.btn.warn { background: var(--warn); border-color: var(--warn); color: #221600; }
.btn.ghost { background: transparent; }
.btn.leave { padding: 7px 14px; font-size: 13px; background: transparent; color: var(--muted); }
.btn.leave:hover { color: var(--accent2); border-color: var(--accent2); }
.btn.glow { animation: glowPulse 1.6s ease-in-out infinite; }
@keyframes glowPulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(229,9,20,.5); }
  50% { box-shadow: 0 0 30px 4px rgba(229,9,20,.55); }
}

/* ---------- library ---------- */
.library-card { text-align: left; }
.library-card h2 { margin-bottom: 4px; }
.dl-row { display: flex; flex-direction: column; gap: 8px; margin: 18px 0; }
.lib-list { list-style: none; margin-bottom: 16px; max-height: 30vh; overflow-y: auto; }
.lib-list li { display: flex; align-items: center; gap: 10px; padding: 12px 6px; border-bottom: 1px solid var(--line); }
.lib-list .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-list progress { width: 90px; accent-color: var(--accent); }
#libPlayer { width: 100%; border-radius: 10px; margin-bottom: 12px; background: #000; }

/* ---------- room chrome ---------- */
#room { flex-direction: column; align-items: stretch; justify-content: flex-start; }
#roomBar {
  display: flex; align-items: center; gap: 14px; padding: 10px 16px;
  background: linear-gradient(var(--panel), rgba(20,20,28,.92)); border-bottom: 1px solid var(--line);
  font-size: 14px; z-index: 10;
}
.room-code {
  font-weight: 800; letter-spacing: 4px; cursor: pointer; color: var(--text);
  background: var(--panel2); border: 1px dashed var(--line); border-radius: 8px; padding: 4px 12px;
  transition: border-color .2s, color .2s;
}
.room-code:hover { border-color: var(--accent); color: var(--accent2); }
.movie-title { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 30vw; }
#memberCount { color: var(--muted); font-variant-numeric: tabular-nums; }

#stage { flex: 1; display: flex; min-height: 0; }
#videoWrap { flex: 1; position: relative; background: #000; display: flex; align-items: center; justify-content: center; }
#video { width: 100%; height: 100%; object-fit: contain; }
#videoWrap.idle { cursor: none; }

/* ---------- overlay panels ---------- */
.overlay-panel {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 16px;
  align-items: center; justify-content: center; padding: 24px; z-index: 5;
  background: radial-gradient(ellipse at 50% 30%, rgba(20,20,28,.9), rgba(10,10,15,.97));
  animation: screenIn .3s ease;
}
.overlay-panel h3 { font-size: 22px; font-weight: 700; }
.src-row { display: flex; gap: 8px; width: min(560px, 92%); }
.fileBtn { display: inline-flex; align-items: center; justify-content: center; width: 100%; }
.pulse-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.6); opacity: .4; } }

/* ---------- pre-show ---------- */
.preshow-label { letter-spacing: 5px; font-size: 12px; color: var(--accent2); font-weight: 700; }
#preshowTitle { font-size: clamp(24px, 4vw, 42px); font-weight: 900; text-align: center; max-width: 80%; }
#preshowMembers { display: flex; gap: 22px; flex-wrap: wrap; justify-content: center; margin: 10px 0 6px; max-width: 90%; }
.preshow-member { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 92px; }
.ring {
  width: 64px; height: 64px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: conic-gradient(var(--accent) calc(var(--pct) * 1%), var(--panel2) 0);
  font-size: 13px; font-weight: 700; transition: background .5s;
}
.ring span { width: 52px; height: 52px; border-radius: 50%; background: var(--bg); display: flex; align-items: center; justify-content: center; }
.preshow-member.ok .ring { background: conic-gradient(var(--ok) 100%, var(--ok) 0); }
.preshow-member.ok .ring span { color: var(--ok); }
.pm-info { text-align: center; }
.pm-name { font-size: 13px; font-weight: 600; max-width: 92px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pm-sub { font-size: 11px; color: var(--muted); }

/* ---------- pause overlay ---------- */
.pause-overlay {
  position: absolute; inset: 0; z-index: 6;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px;
  background: rgba(5,5,8,.55); backdrop-filter: blur(3px);
  animation: screenIn .25s ease;
}
.reason-text { font-size: clamp(18px, 2.6vw, 26px); font-weight: 700; text-shadow: 0 2px 20px rgba(0,0,0,.8); }
.reason-text .who { color: var(--accent2); }
#pauseReason { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.banner-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.spinner {
  width: 42px; height: 42px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.15); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- pills ---------- */
.pill {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 84px; z-index: 7;
  background: rgba(20,20,28,.92); border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 18px; font-size: 13px; font-weight: 600; box-shadow: 0 8px 30px rgba(0,0,0,.5);
  animation: pillIn .25s ease;
}
@keyframes pillIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
.pill.whisper { border-color: var(--whisper); color: var(--whisper); }
#whisperIn { bottom: 128px; }

/* ---------- controls ---------- */
#controls {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 4;
  display: flex; align-items: center; gap: 14px; padding: 14px 18px 12px;
  background: linear-gradient(transparent, rgba(0,0,0,.9));
  transition: opacity .4s, transform .4s;
}
#videoWrap.idle #controls { opacity: 0; transform: translateY(8px); pointer-events: none; }
.ctl { background: none; border: none; color: var(--text); font-size: 21px; cursor: pointer; transition: transform .1s; }
.ctl:hover { transform: scale(1.15); }
#timeline { flex: 1; height: 5px; background: #ffffff26; border-radius: 3px; overflow: hidden; position: relative; transition: height .15s; }
#timeline:hover { height: 8px; }
#timelineBuffer { position: absolute; inset: 0 auto 0 0; background: #ffffff33; width: 0%; }
#timelineFill { position: absolute; inset: 0 auto 0 0; background: var(--accent); width: 0%; transition: width .3s linear; }
#timeLabel { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--muted); }
#timeline.host-seek { cursor: pointer; }
#cinemaHint {
  position: absolute; bottom: 60px; left: 50%; transform: translateX(-50%);
  font-size: 13px; color: var(--muted); background: rgba(0,0,0,.65); padding: 7px 14px; border-radius: 999px; z-index: 4;
  animation: pillIn .3s ease;
}

/* ---------- call strip ---------- */
#callStrip { width: 152px; background: var(--panel); border-left: 1px solid var(--line); padding: 8px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.peer-tile {
  position: relative; border-radius: 12px; overflow: hidden; background: #000; aspect-ratio: 4/3;
  cursor: pointer; transition: transform .15s, outline-color .2s; outline: 3px solid transparent;
  user-select: none; -webkit-user-select: none; touch-action: none;
  animation: screenIn .3s ease;
}
.peer-tile:hover { transform: scale(1.04); }
.peer-tile video { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.peer-tile .peer-name {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 3px 7px; font-size: 11px; font-weight: 600;
  background: linear-gradient(transparent, rgba(0,0,0,.8)); pointer-events: none;
}
.peer-tile.talking { outline-color: var(--ok); }
.peer-tile.whisper-out, .peer-tile.whisper-in { outline-color: var(--whisper); }
.peer-tile.buffering::after { content: "⏳"; position: absolute; top: 5px; right: 6px; font-size: 14px; }
.peer-tile.host-badge::before { content: "★"; position: absolute; top: 4px; left: 7px; color: gold; z-index: 2; font-size: 12px; text-shadow: 0 1px 4px #000; }

/* ---------- fullscreen camera overlay ---------- */
#fsCams {
  position: absolute; top: 18px; right: 18px; z-index: 8; width: 200px;
  border-radius: 14px; overflow: hidden; cursor: pointer;
  box-shadow: 0 12px 40px rgba(0,0,0,.6); outline: 2px solid rgba(255,255,255,.12);
  transition: opacity .5s;
}
#fsCams.faded { opacity: .25; }
#fsCams:hover { opacity: 1; }
#fsCamVideo { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; }
#fsCamName {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 4px 10px; font-size: 12px; font-weight: 600;
  background: linear-gradient(transparent, rgba(0,0,0,.85));
}
#fsTalkBtn {
  position: absolute; bottom: 22px; right: 22px; z-index: 8;
  width: 60px; height: 60px; border-radius: 50%; border: 2px solid rgba(255,255,255,.25);
  background: rgba(20,20,28,.8); color: var(--text); font-size: 24px; cursor: pointer;
  backdrop-filter: blur(8px); touch-action: none; user-select: none; -webkit-user-select: none;
  transition: background .15s, transform .1s;
}
#fsTalkBtn.on { background: var(--ok); transform: scale(1.1); }

/* ---------- talk bar ---------- */
#talkBar {
  display: flex; align-items: center; gap: 14px; padding: 10px 16px;
  background: var(--panel); border-top: 1px solid var(--line);
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}
#talkBtn {
  padding: 13px 26px; border-radius: 999px; border: 2px solid var(--line); font-size: 15px; font-weight: 700;
  background: var(--panel2); color: var(--text); cursor: pointer; user-select: none; -webkit-user-select: none;
  touch-action: none; font-family: var(--font); transition: background .12s, border-color .12s, transform .1s;
}
#talkBtn.on { background: var(--ok); border-color: var(--ok); color: #00281c; transform: scale(1.03); }
.key { background: #ffffff1e; padding: 2px 9px; border-radius: 6px; font-size: 12px; margin-left: 8px; }

/* ---------- toasts ---------- */
#toasts { position: fixed; top: 62px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
  background: rgba(28,28,38,.95); border: 1px solid var(--line); padding: 11px 16px; border-radius: 12px;
  font-size: 13px; font-weight: 500; box-shadow: 0 10px 34px rgba(0,0,0,.5); max-width: 70vw;
  animation: toastIn .25s cubic-bezier(.2,.9,.3,1.2); transition: opacity .5s, transform .5s;
}
.toast.out { opacity: 0; transform: translateX(20px); }
@keyframes toastIn { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: none; } }

/* ---------- TV mode (display-only member) ---------- */
.tv-mode #talkBar, .tv-mode #callStrip, .tv-mode #cinemaHint { display: none !important; }
.tv-mode #roomBar { padding: 14px 22px; font-size: 18px; }
.tv-mode .room-code { font-size: 24px; letter-spacing: 8px; padding: 6px 18px; }
.tv-mode .reason-text { font-size: clamp(26px, 4vw, 44px); }
.tv-mode #preshowTitle { font-size: clamp(34px, 5vw, 60px); }
.tv-mode #controls { display: none; }
.tv-mode .btn.big { font-size: 20px; padding: 18px 34px; }

/* TV tiles in the call strip */
.peer-tile.tv { background: var(--panel2); display: flex; align-items: center; justify-content: center; }
.peer-tile.tv .tv-icon { font-size: 34px; }
.peer-tile.tv.mine { outline-color: var(--accent); }

/* ---------- phone remote mode ---------- */
#remotePanel { gap: 10px; z-index: 6; }
.rp-title { font-size: clamp(20px, 5vw, 30px); font-weight: 800; text-align: center; max-width: 86%; }
.rp-time { font-size: 17px; color: var(--muted); font-variant-numeric: tabular-nums; }
.rp-play {
  width: 92px; height: 92px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 38px; margin: 10px 0;
  box-shadow: 0 10px 40px rgba(229,9,20,.45); transition: transform .1s, background .2s;
}
.rp-play:hover { background: var(--accent2); }
.rp-play:active { transform: scale(.94); }
#rpSeek { width: min(420px, 84%); accent-color: var(--accent); }
.remote-mode #controls, .remote-mode #cinemaHint { display: none !important; }

.lobby-secondary { display: flex; gap: 10px; justify-content: center; }

/* ---------- mobile ---------- */
@media (max-width: 720px) {
  #stage { flex-direction: column; }
  #callStrip {
    width: auto; border-left: none; border-top: 1px solid var(--line);
    flex-direction: row; overflow-x: auto; overflow-y: hidden; height: 100px; flex-shrink: 0;
  }
  .peer-tile { width: 116px; flex-shrink: 0; }
  #talkBtn { flex: 1; padding: 16px; font-size: 17px; }
  .key, #talkHint { display: none; }
  .movie-title { display: none; }
  #fsCams { width: 140px; }
  #preshowMembers { gap: 14px; }
  .lobby-card, .library-card { padding: 32px 24px; }
}
