:root {
  --bg: #0b0d13;
  --surface: #131722;
  --surface-2: #1b2131;
  --border: #272f45;
  --text: #eef2ff;
  --muted: #98a2b8;
  --accent: #6366f1;
  --accent-hover: #7c7ff6;
  --good: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Buttons & Inputs */
.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  background: var(--surface-2);
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
}

.btn:hover {
  background: #252d42;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
}

.btn-ghost:hover {
  background: var(--surface-2);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.18);
  border-color: rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.3);
}

.btn-lg {
  padding: 12px 20px;
  font-size: 1rem;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.82rem;
}

.btn-xs {
  padding: 4px 8px;
  font-size: 0.75rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.pill-muted {
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}

.pill-good {
  background: rgba(34, 197, 94, 0.14);
  color: #86efac;
  border: 1px solid rgba(34, 197, 94, 0.35);
}

.pill-warn {
  background: rgba(245, 158, 11, 0.16);
  color: #fcd34d;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: radial-gradient(circle at top, #1b2238 0%, #090b10 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  width: 100%;
  max-width: 430px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
}

.modal-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-brand h1 {
  margin: 0;
  font-size: 1.5rem;
}

.brand-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 14px var(--accent);
  display: inline-block;
}

.modal-subtitle {
  margin: 10px 0 22px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.join-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.84rem;
  color: var(--muted);
}

.field input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}

.field input:focus {
  outline: none;
  border-color: var(--accent);
}

.admin-details {
  font-size: 0.84rem;
  color: var(--muted);
}

.admin-details summary {
  cursor: pointer;
  margin-bottom: 8px;
}

.form-error {
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  font-size: 0.85rem;
}

/* App Shell */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.topbar {
  height: 54px;
  flex-shrink: 0;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-center {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.now-playing {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9rem;
  color: var(--muted);
}

.brand-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.98rem;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
}

/* Player Stage */
.player-stage {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: #050609;
}

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

.video-wrapper video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.stage-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 8, 13, 0.78);
  z-index: 10;
  padding: 20px;
}

.empty-card {
  max-width: 440px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
}

.empty-card h2 {
  margin: 0 0 10px;
}

.empty-card p {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
  margin: 0 0 18px;
}

.buffering-badge {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 12;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(15, 19, 30, 0.85);
  border: 1px solid var(--border);
  font-size: 0.82rem;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.reactions-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 11;
}

.floating-reaction {
  position: absolute;
  bottom: 74px;
  font-size: 2rem;
  animation: floatUp 2.2s ease-out forwards;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.7));
}

@keyframes floatUp {
  0% {
    opacity: 0;
    transform: translateY(10px) scale(0.8);
  }
  15% {
    opacity: 1;
    transform: translateY(-10px) scale(1.1);
  }
  100% {
    opacity: 0;
    transform: translateY(-210px) scale(1);
  }
}

/* Custom Player Controls */
.controls-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 15;
  padding: 28px 14px 10px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.88), rgba(0, 0, 0, 0));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.progress-row {
  position: relative;
  display: flex;
  align-items: center;
}

.seek-slider {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
  height: 6px;
}

.seek-tooltip {
  position: absolute;
  bottom: 18px;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 0.75rem;
  pointer-events: none;
}

.controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.controls-left,
.controls-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ctrl-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text);
  border-radius: 7px;
  padding: 5px 9px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.ctrl-btn:hover {
  background: rgba(255, 255, 255, 0.18);
}

.ctrl-btn.active {
  background: var(--accent);
  border-color: var(--accent);
}

.ctrl-select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 8px;
  font-size: 0.82rem;
}

.volume-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.volume-slider {
  width: 72px;
  accent-color: var(--accent);
  cursor: pointer;
}

.time-display {
  font-size: 0.82rem;
  color: #d6dcf0;
  font-variant-numeric: tabular-nums;
  margin-left: 4px;
}

.host-bar {
  height: 42px;
  flex-shrink: 0;
  padding: 0 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.host-bar-left,
.host-settings-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.role-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text);
  cursor: pointer;
}

/* Sidebar */
.sidebar {
  width: 360px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar.collapsed {
  display: none;
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 12px 8px;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.tab-panel {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  padding: 12px;
  gap: 10px;
}

.tab-panel.active {
  display: flex;
}

/* Chat */
.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
}

.chat-msg {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.86rem;
  line-height: 1.4;
  word-break: break-word;
}

.chat-msg.system {
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 2px 4px;
  text-align: center;
}

.chat-sender {
  font-weight: 700;
  color: #a5b4fc;
  margin-right: 6px;
}

.reactions-bar {
  display: flex;
  justify-content: space-between;
  gap: 6px;
}

.react-btn {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px;
  font-size: 1rem;
  cursor: pointer;
}

.react-btn:hover {
  background: #262f45;
}

.chat-form {
  display: flex;
  gap: 8px;
}

.chat-form input,
.url-form input {
  flex: 1;
  min-width: 0;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.86rem;
}

/* Upload & Library */
.upload-dropzone {
  border: 1.5px dashed var(--border);
  border-radius: 12px;
  padding: 14px;
  text-align: center;
  cursor: pointer;
  background: rgba(99, 102, 241, 0.05);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.upload-dropzone.dragover,
.upload-dropzone:hover {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.12);
}

.dropzone-icon {
  font-size: 1.25rem;
  margin-bottom: 4px;
}

.dropzone-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.82rem;
}

.dropzone-text span {
  color: var(--muted);
  font-size: 0.75rem;
}

.upload-progress-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.upload-progress-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.82rem;
}

.progress-track {
  height: 7px;
  border-radius: 999px;
  background: var(--bg);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.1s linear;
}

.upload-stats {
  font-size: 0.75rem;
  color: var(--muted);
}

.url-form {
  display: flex;
  gap: 6px;
}

.sub-select-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--muted);
}

.sub-select-row select {
  flex: 1;
  min-width: 0;
}

.library-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
  margin-top: 2px;
}

.video-list,
.friends-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.video-item,
.friend-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.video-item.active {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.14);
}

.video-item-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.video-name {
  font-size: 0.86rem;
  font-weight: 600;
  word-break: break-word;
}

.video-meta {
  font-size: 0.75rem;
  color: var(--muted);
}

.video-warn {
  font-size: 0.74rem;
  color: #fcd34d;
}

.video-actions {
  display: flex;
  gap: 6px;
}

.friend-item {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

.friend-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.friend-name {
  font-size: 0.88rem;
  font-weight: 600;
}

.friend-meta {
  font-size: 0.75rem;
  color: var(--muted);
}

.friends-hint {
  font-size: 0.8rem;
  color: var(--muted);
}

/* Toasts */
.toast-container {
  position: fixed;
  bottom: 18px;
  left: 18px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.85rem;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  max-width: 340px;
}

.toast.warn {
  border-left-color: var(--warn);
}

.toast.error {
  border-left-color: var(--danger);
}

/* Mobile / narrow screens */
@media (max-width: 920px) {
  .workspace {
    flex-direction: column;
  }

  .player-stage {
    flex: none;
    height: 48vh;
  }

  .sidebar {
    width: 100%;
    flex: 1;
    border-left: none;
    border-top: 1px solid var(--border);
  }

  .topbar-center {
    display: none;
  }
}
