/**
 * WatchTogether - Dark Cinema UI Stylesheet
 * Strict CSP compliant: ZERO inline styles required.
 */

:root {
  color-scheme: dark;
  --bg-canvas: #090a10;
  --bg-surface: #121420;
  --bg-card: #191c2b;
  --bg-card-hover: #22263a;
  --border: #282c42;
  --border-focus: #e50914;

  --text-primary: #f0f2fa;
  --text-secondary: #9da4be;
  --text-muted: #656c87;

  --accent: #e50914;
  --accent-hover: #f40612;
  --accent-dim: rgba(229, 9, 20, 0.16);

  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #38bdf8;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --header-height: 56px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  background-color: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Typography & Links */
a {
  color: var(--info);
  text-decoration: none;
  transition: color 0.15s ease;
}
a:hover {
  text-decoration: underline;
}

h1, h2, h3, h4 {
  font-weight: 600;
  color: var(--text-primary);
}

/* Common Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  text-decoration: none;
}
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background-color: var(--accent);
  color: #ffffff;
}
.btn-primary:hover:not(:disabled) {
  background-color: var(--accent-hover);
}

.btn-secondary {
  background-color: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) {
  background-color: var(--bg-card-hover);
  border-color: var(--text-muted);
}

.btn-danger {
  background-color: var(--danger);
  color: #ffffff;
}
.btn-danger:hover:not(:disabled) {
  background-color: #dc2626;
}

.btn-warning {
  background-color: var(--warning);
  color: #111827;
}
.btn-warning:hover:not(:disabled) {
  background-color: #d97706;
}

.btn-small {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
}

.btn-huge {
  padding: 1rem 1.75rem;
  font-size: 1.15rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(229, 9, 20, 0.4);
}

.btn-icon {
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
  background: var(--bg-surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.btn-icon:hover {
  color: var(--text-primary);
  background: var(--bg-card);
  text-decoration: none;
}

.btn-text {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
}
.btn-text:hover {
  color: var(--text-primary);
  text-decoration: underline;
}

/* Inputs & Form Elements */
input[type="text"],
input[type="password"],
select {
  width: 100%;
  padding: 0.6rem 0.85rem;
  font-size: 0.9rem;
  color: var(--text-primary);
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input[type="text"]:focus,
input[type="password"]:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

/* Badges & Pills */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 9999px;
  background-color: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.badge-latency {
  color: var(--success);
  border-color: rgba(16, 185, 129, 0.3);
}
.badge-secret {
  color: var(--warning);
  border-color: rgba(245, 158, 11, 0.3);
}

/* Alerts & Error Messages */
.error-msg {
  padding: 0.65rem 0.9rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  background-color: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-sm);
  color: #fca5a5;
}

/* ========================================================= */
/* Landing / Auth & Dashboard Layout                         */
/* ========================================================= */
.landing-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.landing-header {
  padding: 1.25rem 2rem;
  border-bottom: 1px solid var(--border);
  background-color: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  font-size: 1.35rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-primary);
}

.brand-badge {
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
  background: var(--accent-dim);
  color: var(--accent);
  border-radius: 4px;
  font-weight: 600;
}

.landing-main {
  flex: 1;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  padding: 2.5rem 1.5rem;
}

/* Auth Card */
.auth-container {
  max-width: 440px;
  margin: 1.5rem auto 0;
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.35);
}

.auth-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  padding: 0.6rem;
  color: var(--text-secondary);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}
.tab-btn.active {
  color: var(--text-primary);
  background-color: var(--bg-card);
}

.form-group {
  margin-bottom: 1.2rem;
}
.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

/* Dashboard Views */
.dashboard-container {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.dashboard-user-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.5rem;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}
@media (max-width: 720px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

.dashboard-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
}
.dashboard-card h2 {
  font-size: 1.15rem;
  margin-bottom: 1rem;
}

.rooms-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1rem;
}

.room-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  transition: border-color 0.15s ease;
}
.room-item:hover {
  border-color: var(--text-muted);
}

.room-info {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.room-title-heading {
  font-size: 1rem;
  font-weight: 600;
}
.room-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.room-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.empty-state {
  text-align: center;
  padding: 2.5rem;
  color: var(--text-muted);
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px dashed var(--border);
}

/* ========================================================= */
/* Cinema Room Layout                                        */
/* ========================================================= */
.cinema-body {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.cinema-header {
  height: var(--header-height);
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  gap: 1rem;
  flex-shrink: 0;
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-width: 0;
}

.header-title {
  font-size: 1.05rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}

.header-center {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.owner-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Cinema Main Split */
.cinema-container {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  height: calc(100vh - var(--header-height));
  overflow: hidden;
}

/* Video Stage (Left) */
.stage-section {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  gap: 1rem;
}

.video-bar {
  display: flex;
  gap: 0.5rem;
}

.player-container {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background-color: #000000;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6);
}

.player-container iframe,
.player-container #yt-mount {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.autoplay-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.yt-error-banner {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 0.75rem 1rem;
  background: rgba(220, 38, 38, 0.9);
  color: #ffffff;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 25;
}

.btn-close {
  background: none;
  border: none;
  color: #ffffff;
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
}

/* Floating Reaction Burst Layer */
.reaction-burst-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 15;
}

.floating-reaction {
  position: absolute;
  bottom: 20px;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  background: rgba(0, 0, 0, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 9999px;
  color: #ffffff;
  animation: floatUp 2.8s cubic-bezier(0.2, 0.8, 0.3, 1) forwards;
}
.slot-0 { left: 15%; }
.slot-1 { left: 32%; }
.slot-2 { left: 50%; }
.slot-3 { left: 68%; }
.slot-4 { left: 85%; }
.floating-reaction-emoji {
  font-size: 1.5rem;
}
.floating-reaction-name {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

@keyframes floatUp {
  0% {
    opacity: 0;
    transform: translateY(0) scale(0.6);
  }
  15% {
    opacity: 1;
    transform: translateY(-20px) scale(1.1);
  }
  80% {
    opacity: 0.9;
    transform: translateY(-130px) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-180px) scale(0.9);
  }
}

/* Sync Bar */
.sync-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 1rem;
  gap: 1rem;
}

.now-playing {
  flex: 1;
  min-width: 0;
}
.video-title {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.sync-status {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Queue Section */
.queue-section {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem;
}

.queue-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.queue-header h3 {
  font-size: 0.95rem;
}

.queue-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.queue-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.85rem;
  gap: 0.75rem;
}
.queue-item-info {
  flex: 1;
  min-width: 0;
}
.queue-item-title {
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.queue-item-by {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.queue-item-actions {
  display: flex;
  gap: 0.35rem;
}

.queue-empty {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 1.5rem 0;
}

/* Chat Sidebar (Right) */
.chat-sidebar {
  display: flex;
  flex-direction: column;
  background-color: var(--bg-surface);
  border-left: 1px solid var(--border);
  height: 100%;
  overflow: hidden;
}

.chat-header {
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.chat-header h3 {
  font-size: 0.95rem;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.message-bubble {
  max-width: 85%;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.message-self {
  align-self: flex-end;
}
.message-self .message-content {
  background-color: var(--accent-dim);
  border: 1px solid rgba(229, 9, 20, 0.4);
  color: var(--text-primary);
  border-bottom-right-radius: 2px;
}
.message-self .message-author {
  text-align: right;
  color: var(--accent);
}

.message-other {
  align-self: flex-start;
}
.message-other .message-content {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-bottom-left-radius: 2px;
}

.message-author {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.message-content {
  padding: 0.55rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  word-break: break-word;
}

.message-time {
  font-size: 0.68rem;
  color: var(--text-muted);
  align-self: flex-end;
  margin-top: 2px;
}

/* System Action Pill */
.message-system {
  align-self: center;
  text-align: center;
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.2);
  color: var(--info);
  font-size: 0.75rem;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  max-width: 90%;
}

.typing-indicator {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
  padding: 0.35rem 1.25rem;
  min-height: 1.5rem;
}

.reaction-bar {
  display: flex;
  justify-content: space-around;
  padding: 0.4rem 0.75rem;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
}

.reaction-btn {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  transition: transform 0.1s ease, background-color 0.1s ease;
}
.reaction-btn:hover {
  transform: scale(1.25);
  background: var(--bg-card);
}
.reaction-btn:active {
  transform: scale(0.95);
}

.chat-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
  background-color: var(--bg-surface);
}

/* Disconnected Banner */
.disconnected-banner {
  background: rgba(239, 68, 68, 0.95);
  color: #ffffff;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

/* Modal Dialogs */
dialog {
  margin: auto;
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  max-width: 440px;
  width: 90%;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}
dialog::backdrop {
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
}
.dialog-header {
  margin-bottom: 1rem;
}
.dialog-header h3 {
  font-size: 1.15rem;
}
.dialog-body {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Toast Container */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 200;
  pointer-events: none;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 0.65rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: toastIn 0.25s ease forwards;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Mobile Responsive */
@media (max-width: 900px) {
  .cinema-body {
    height: auto;
    overflow-y: auto;
  }
  .cinema-container {
    display: flex;
    flex-direction: column;
    height: auto;
  }
  .stage-section {
    padding: 0.75rem;
  }
  .player-container {
    position: sticky;
    top: 0;
    z-index: 30;
  }
  .chat-sidebar {
    height: 480px;
    border-left: none;
    border-top: 1px solid var(--border);
  }
}
