/* ─── Reset & Base ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0b0b12;
  --bg-2: #13131e;
  --bg-3: #1a1a28;
  --bg-4: #222235;
  --border: rgba(255,255,255,0.07);
  --border-strong: rgba(255,255,255,0.13);
  --text: #e6e6f0;
  --text-2: #9696aa;
  --text-muted: #5a5a70;
  --accent: #8b5cf6;
  --accent-hover: #a78bfa;
  --accent-dim: rgba(139,92,246,0.18);
  --accent-glow: rgba(139,92,246,0.35);
  --success: #34d399;
  --error: #f87171;
  --warn: #fbbf24;
  --system-color: #7a7a92;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 24px rgba(0,0,0,0.5);
  --transition: 0.18s ease;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-hover); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  border: none;
  border-radius: var(--radius-sm);
  transition: background var(--transition), opacity var(--transition);
}
button:disabled { opacity: 0.45; cursor: not-allowed; }

input, textarea {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--bg-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
input::placeholder, textarea::placeholder { color: var(--text-muted); }
input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* ─── Utility ────────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

/* ─── Landing Page ───────────────────────────────────────────────────────────── */
.landing {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  background: radial-gradient(ellipse 80% 50% at 50% 0%, rgba(139,92,246,0.12) 0%, transparent 70%), var(--bg);
}

.landing-logo {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
}
.landing-logo svg { width: 44px; height: 44px; }
.landing-logo h1 {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #fff 30%, var(--accent-hover));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.landing-tagline {
  color: var(--text-2);
  font-size: 16px;
  margin-bottom: 48px;
  text-align: center;
}

.landing-card {
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 36px 40px;
  width: 100%;
  max-width: 460px;
  box-shadow: var(--shadow);
}

.landing-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 28px 0;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.landing-divider::before, .landing-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-strong);
}

.drive-hint {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  background: var(--accent-dim);
  border: 1px solid rgba(139,92,246,0.25);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.5;
  margin-bottom: 14px;
}
.drive-hint strong { color: var(--text); }

.create-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.create-form input { width: 100%; }

.section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 10px;
}

.btn-primary {
  width: 100%;
  padding: 13px 20px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:active:not(:disabled) { transform: scale(0.98); }

.btn-secondary {
  padding: 10px 18px;
  background: var(--bg-4);
  color: var(--text);
  border: 1px solid var(--border-strong);
  font-weight: 500;
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-3); border-color: var(--accent); }

.join-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.join-row input { flex: 1; text-transform: uppercase; letter-spacing: 0.08em; }
.join-row input::placeholder { text-transform: none; letter-spacing: normal; }
.join-row button { flex-shrink: 0; }

.status-msg {
  margin-top: 16px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  display: none;
}
.status-msg.info { background: var(--accent-dim); color: var(--accent-hover); display: block; }
.status-msg.error { background: rgba(248,113,113,0.15); color: var(--error); display: block; }
.status-msg.success { background: rgba(52,211,153,0.12); color: var(--success); display: block; }

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Room Page Layout ───────────────────────────────────────────────────────── */
.room-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Top Bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: 52px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}
.topbar-logo {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent-hover);
  letter-spacing: -0.3px;
  margin-right: 4px;
}
.topbar-divider { width: 1px; height: 20px; background: var(--border-strong); }
.topbar-room-id {
  font-family: 'Courier New', monospace;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--text);
}
.topbar-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  transition: background var(--transition), color var(--transition);
}
.icon-btn:hover { background: var(--bg-3); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }
.participant-count {
  font-size: 13px;
  color: var(--text-2);
  margin-left: -2px;
}

/* Main content area */
.room-main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Video panel */
.video-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #000;
  min-width: 0;
  position: relative;
}

.video-container {
  position: relative;
  flex: 1;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.video-container video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Video overlay for host controls */
.video-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(transparent 60%, rgba(0,0,0,0.85) 100%);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 0;
  opacity: 0;
  transition: opacity 0.25s;
}
.video-container:hover .video-overlay,
.video-overlay.always-show { opacity: 1; }

.video-controls {
  padding: 12px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Seek bar */
.seek-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
}
.seek-bar {
  flex: 1;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  cursor: pointer;
  outline: none;
  border: none;
  padding: 0;
}
.seek-bar::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent-hover);
  cursor: pointer;
  box-shadow: 0 0 0 3px rgba(167,139,250,0.3);
}
.seek-bar::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent-hover);
  cursor: pointer;
  border: none;
}
.seek-bar.guest-seek { cursor: default; }
.seek-bar.guest-seek::-webkit-slider-thumb { cursor: default; background: rgba(255,255,255,0.5); box-shadow: none; }
.time-display {
  font-size: 12px;
  color: rgba(255,255,255,0.8);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  min-width: 90px;
  text-align: right;
}

/* Controls row */
.controls-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ctrl-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  background: transparent;
  border-radius: 50%;
  color: #fff;
  transition: background var(--transition);
}
.ctrl-btn:hover { background: rgba(255,255,255,0.15); }
.ctrl-btn svg { width: 20px; height: 20px; }
.ctrl-btn.play-btn { width: 44px; height: 44px; background: var(--accent); border-radius: 50%; }
.ctrl-btn.play-btn:hover { background: var(--accent-hover); }
.ctrl-btn.play-btn svg { width: 22px; height: 22px; }

/* Volume */
.volume-group { display: flex; align-items: center; gap: 6px; }
.volume-slider {
  width: 72px;
  height: 3px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255,255,255,0.3);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  border: none;
  padding: 0;
}
.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
}
.controls-spacer { flex: 1; }

/* Guest overlay badge */
.guest-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(0,0,0,0.7);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--text-2);
  pointer-events: none;
}

/* Buffering overlay */
.buffering-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.5);
  pointer-events: none;
}
.buffering-spinner {
  width: 48px; height: 48px;
  border: 4px solid rgba(255,255,255,0.2);
  border-top-color: var(--accent-hover);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ─── Drive fetch progress overlay ──────────────────────────────────────────── */
.fetch-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.82);
  z-index: 5;
}
.fetch-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 32px 40px;
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  min-width: 280px;
  max-width: 360px;
  text-align: center;
}
.fetch-spinner {
  width: 36px; height: 36px;
  border: 3px solid rgba(255,255,255,0.12);
  border-top-color: var(--accent-hover);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
.fetch-label {
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.5;
}
.fetch-bar-track {
  width: 100%;
  height: 6px;
  background: var(--bg-4);
  border-radius: 3px;
  overflow: hidden;
}
.fetch-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  width: 0%;
  transition: width 0.4s ease;
}
.fetch-pct {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-hover);
  font-variant-numeric: tabular-nums;
}

/* Video error message */
.video-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.8);
  gap: 12px;
  text-align: center;
  padding: 20px;
}
.video-error p { color: var(--text-2); font-size: 14px; max-width: 320px; }

/* ─── Chat Panel ─────────────────────────────────────────────────────────────── */
.chat-panel {
  width: 320px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-2);
  border-left: 1px solid var(--border);
}

.chat-header {
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  flex-shrink: 0;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 2px; }

.chat-msg {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.chat-msg-meta {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.chat-sender {
  font-size: 12px;
  font-weight: 600;
}
.chat-time {
  font-size: 11px;
  color: var(--text-muted);
}
.chat-text {
  font-size: 14px;
  color: var(--text);
  word-break: break-word;
  line-height: 1.4;
}

/* System message */
.chat-msg.system .chat-text {
  font-style: italic;
  color: var(--system-color);
  font-size: 13px;
}
.chat-msg.system .chat-sender { display: none; }
.chat-msg.system .chat-time { color: var(--text-muted); }

/* Chat input */
.chat-input-area {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.chat-input {
  flex: 1;
  resize: none;
  height: 38px;
  padding: 8px 10px;
  font-size: 14px;
  line-height: 1.3;
  border-radius: var(--radius-sm);
  background: var(--bg-3);
  border-color: var(--border-strong);
}
.chat-send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}
.chat-send-btn:hover { background: var(--accent-hover); }
.chat-send-btn svg { width: 16px; height: 16px; }

/* ─── Participant Panel (slide-in) ───────────────────────────────────────────── */
.participants-panel {
  position: fixed;
  top: 52px;
  right: 0;
  bottom: 0;
  width: 280px;
  background: var(--bg-2);
  border-left: 1px solid var(--border-strong);
  z-index: 50;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
}
.participants-panel.open { transform: translateX(0); }

.participants-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  font-weight: 600;
}
.participants-close {
  background: transparent;
  color: var(--text-2);
  font-size: 18px;
  line-height: 1;
  padding: 2px 6px;
}
.participants-close:hover { color: var(--text); }
.participants-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.participant-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
}
.participant-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.participant-name {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.participant-badges { display: flex; align-items: center; gap: 4px; }
.badge-host {
  font-size: 10px;
  background: var(--accent-dim);
  color: var(--accent-hover);
  padding: 2px 6px;
  border-radius: 3px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.badge-buffering {
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: var(--warn);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ─── Join Screen (overlay) ──────────────────────────────────────────────────── */
.join-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.join-card {
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 36px 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
  text-align: center;
}
.join-card h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
}
.join-card .room-code {
  font-family: 'Courier New', monospace;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.2em;
  color: var(--accent-hover);
  margin: 8px 0 20px;
}
.join-card p { color: var(--text-2); font-size: 14px; margin-bottom: 20px; }
.join-card input { width: 100%; margin-bottom: 12px; }
.join-card .btn-primary { width: 100%; }

/* Room ended overlay */
.room-ended-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(4px);
}
.room-ended-card {
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 40px;
  text-align: center;
  max-width: 360px;
}
.room-ended-card h2 { font-size: 20px; margin-bottom: 10px; }
.room-ended-card p { color: var(--text-2); font-size: 14px; margin-bottom: 20px; }

/* ─── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .room-main { flex-direction: column; }
  .chat-panel {
    width: 100%;
    height: 280px;
    border-left: none;
    border-top: 1px solid var(--border);
  }
}

@media (max-width: 768px) {
  .landing-card { padding: 28px 20px; }
  .topbar-logo { display: none; }
  .topbar-divider { display: none; }
  .chat-panel { height: 240px; }
  .volume-slider { width: 52px; }
  .join-card { padding: 28px 20px; }
}

/* ─── Scrollbar (global) ─────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ─── Toast notifications ────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--bg-4);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 13px;
  color: var(--text);
  box-shadow: var(--shadow);
  animation: toastIn 0.25s ease, toastOut 0.25s ease 2.75s forwards;
}
.toast.error { border-color: var(--error); color: var(--error); }
.toast.success { border-color: var(--success); color: var(--success); }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; } }

/* Seek bar: 3-zone gradient — played (purple) / buffered (light) / empty (dim) */
.seek-bar {
  background: linear-gradient(
    to right,
    var(--accent)               0%,
    var(--accent)               var(--progress, 0%),
    rgba(255,255,255,0.38)      var(--progress, 0%),
    rgba(255,255,255,0.38)      var(--buffered, 0%),
    rgba(255,255,255,0.13)      var(--buffered, 0%),
    rgba(255,255,255,0.13)      100%
  );
}

/* Non-intrusive buffer percentage label */
.buffer-pct {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  min-width: 72px;
  text-align: right;
  opacity: 0.85;
}
