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

body {
  background: #0a0a0a;
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  height: 100vh;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hidden { display: none !important; }

/* ── Brand bar ── */
#brand-bar {
  position: fixed;
  top: 20px;
  left: 24px;
  display: inline-flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  z-index: 999;
  opacity: 1;
  transition: opacity 0.6s ease;
  pointer-events: none;
}
#brand-bar a {
  pointer-events: auto;
  cursor: pointer;
}
#brand-bar.fade-out a {
  pointer-events: none;
}

#brand-bar.fade-out {
  opacity: 0;
}

#brand-logo {
  height: 32px;
  width: auto;
  display: block;
  flex-shrink: 0;
}

.brand-sub {
  font-size: 0.9rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.75);
  letter-spacing: 0.04em;
  flex-shrink: 0;
  line-height: 1;
}

/* ── Drop Zone ── */
#drop-zone {
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed transparent;
  transition: border-color 0.2s, background 0.2s;
}

#drop-zone.drag-over {
  border-color: #e040fb;
  background: rgba(224, 64, 251, 0.06);
}

.drop-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
  color: #666;
}

.drop-inner svg { color: #444; }

.drop-inner p {
  font-size: 1.1rem;
  color: #aaa;
}

.drop-inner span {
  font-size: 0.85rem;
  color: #444;
  max-width: 340px;
  line-height: 1.5;
}

#drop-error p { color: #f44336; }

#drop-error-btn {
  background: transparent;
  color: #e040fb;
  border: 1px solid #e040fb;
  border-radius: 8px;
  padding: 8px 22px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.2s;
  margin-top: 4px;
}
#drop-error-btn:hover { background: rgba(224,64,251,0.12); }

#browse-btn {
  background: #e040fb;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 28px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.2s;
}

#browse-btn:hover { background: #ce35df; }

/* ── Player ── */
#player-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

/* ── Controls ── */
#controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 16px 16px;
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
  opacity: 0;
  transition: opacity 0.25s;
}

#player-container.paused #controls,
#player-container.controls-visible #controls,
#controls:hover {
  opacity: 1;
}

/* ── Back / change-movie button ── */
#back-btn {
  position: absolute;
  top: 16px;
  left: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(224,64,251,0.45);
  border-radius: 50%;
  color: #e040fb;
  cursor: pointer;
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, background 0.15s;
}

#back-btn:hover {
  background: rgba(224,64,251,0.25);
}

/* Show with controls */
#player-container.paused #back-btn,
#player-container.controls-visible #back-btn {
  opacity: 1;
  pointer-events: auto;
}

/* Hide in fullscreen */
:fullscreen #back-btn,
:-webkit-full-screen #back-btn {
  display: none !important;
}

#player-container.cursor-hidden,
#player-container.cursor-hidden * {
  cursor: none !important;
}

#progress-bar-wrap {
  padding: 6px 0;
  cursor: pointer;
}
#progress-bar-wrap.no-seek {
  pointer-events: none;
  opacity: 0.4;
  cursor: default;
}

#progress-bar {
  position: relative;
  height: 4px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
}

#progress-fill {
  height: 100%;
  background: #e040fb;
  border-radius: 2px;
  width: 0%;
  pointer-events: none;
}

#progress-thumb {
  position: absolute;
  top: 50%;
  left: 0%;
  transform: translate(-50%, -50%);
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}

#progress-bar-wrap:hover #progress-thumb { opacity: 1; }
#progress-bar-wrap:hover #progress-bar { height: 6px; }

#controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
}

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

.ctrl-btn {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: color 0.15s;
}

.ctrl-btn:hover { color: #e040fb; }

#volume-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
}

#volume {
  width: 80px;
  accent-color: #e040fb;
  cursor: pointer;
}

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

/* ── Subtitle button ── */
#sub-btn {
  display: flex;
  align-items: center;
  gap: 4px;
}

#sub-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

#sub-btn.active { color: #e040fb; }

/* ── Sync indicator ── */
#sync-wrap {
  display: flex;
  align-items: center;
  gap: 5px;
}

#sync-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4caf50;
  transition: background 0.3s;
  flex-shrink: 0;
}

#sync-dot.syncing { background: #ff9800; animation: pulse-dot 0.8s infinite; }
#sync-dot.unsynced { background: #f44336; }

/* ── Guest waiting state ── */
#drop-guest svg { animation: spin 3s linear infinite; }

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


/* ── Native subtitle styling ── */
video::cue {
  background: transparent;
  color: #fff;
  font-size: 1rem;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  text-shadow:
    -1px -1px 3px #000,
     1px -1px 3px #000,
    -1px  1px 3px #000,
     1px  1px 3px #000,
     0    2px 6px #000;
}

/* ── Shared pip styles ── */
#cam-overlay,
#self-preview {
  position: fixed;
  border-radius: 12px;
  overflow: hidden;
  background: #111;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  z-index: 50;
  cursor: grab;
  user-select: none;
}

#cam-overlay.dragging,
#self-preview.dragging {
  cursor: grabbing;
  box-shadow: 0 8px 32px rgba(0,0,0,0.7);
}

/* ── Resize handle (bottom-right corner) ── */
.pip-resize-handle {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 18px;
  height: 18px;
  cursor: nwse-resize;
  z-index: 10;
  /* Visual: two diagonal lines */
  background: linear-gradient(
    135deg,
    transparent 40%,
    rgba(255,255,255,0.25) 40%,
    rgba(255,255,255,0.25) 50%,
    transparent 50%,
    transparent 65%,
    rgba(255,255,255,0.25) 65%,
    rgba(255,255,255,0.25) 75%,
    transparent 75%
  );
  opacity: 0;
  transition: opacity 0.15s;
}

#cam-overlay:hover .pip-resize-handle,
#self-preview:hover .pip-resize-handle { opacity: 1; }

/* ── Girlfriend overlay (top-right) ── */
#cam-overlay {
  top: 16px;
  right: 16px;
  width: 200px;
  height: 150px;
  border: 2px solid rgba(255,255,255,0.15);
  transition: border-color 0.3s ease;
}

/* ── Remote cam health states ── */
/* `degraded` = inbound track muted for >3 s (likely RTP starvation from
   chunk transfer saturating the link). `lost` = >10 s or track ended. */
#cam-overlay.cam-degraded { border-color: rgba(255, 196, 0, 0.9); }
#cam-overlay.cam-lost     { border-color: rgba(244, 67, 54, 0.95); }

#cam-overlay.cam-degraded::before,
#cam-overlay.cam-lost::before {
  content: '';
  position: absolute;
  top: 8px;
  left: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ffc400;
  box-shadow: 0 0 6px rgba(255, 196, 0, 0.8);
  z-index: 5;
  animation: smingle-pulse 1.2s ease-in-out infinite;
}

#cam-overlay.cam-lost::before {
  background: #f44336;
  box-shadow: 0 0 6px rgba(244, 67, 54, 0.9);
}

@keyframes smingle-pulse {
  0%, 100% { opacity: 0.6; transform: scale(1); }
  50%      { opacity: 1;   transform: scale(1.15); }
}

#remote-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#cam-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: #444;
  font-size: 0.75rem;
}

/* ── Self-preview (bottom-left) ── */
#self-preview {
  bottom: 80px;
  left: 16px;
  width: 120px;
  height: 90px;
  border: 2px solid rgba(255,255,255,0.1);
  opacity: 0;
  transition: opacity 0.3s;
}

#self-preview.visible { opacity: 1; }

#self-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

#self-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #333;
}

#self-placeholder.hidden { display: none; }

/* ── Overlay label ── */
.overlay-label {
  position: absolute;
  bottom: 6px;
  left: 8px;
  font-size: 0.65rem;
  font-weight: 600;
  color: rgba(255,255,255,0.6);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  pointer-events: none;
}

/* ── Mic level bars ── */
#mic-level {
  position: absolute;
  bottom: 6px;
  right: 6px;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 14px;
}

#mic-level span {
  width: 3px;
  background: #e040fb;
  border-radius: 2px;
  height: 3px;
  transition: height 0.08s;
}

/* ── Camera/mic permission prompt ── */
#media-prompt {
  position: fixed;
  bottom: 80px;
  left: 16px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: rgba(28,28,28,0.97);
  border: 1px solid rgba(224,64,251,0.4);
  border-radius: 12px;
  padding: 10px 14px;
  z-index: 50;
  max-width: 220px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  color: rgba(255,255,255,0.85);
}

#media-prompt svg { flex-shrink: 0; margin-top: 2px; color: #e040fb; }

#media-prompt-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

#media-prompt-text span {
  font-size: 0.8rem;
  font-weight: 600;
}

#media-prompt-text small {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.5);
  line-height: 1.4;
}

/* ── Hide-self button (appears on hover over self-preview) ── */
#hide-self-btn {
  position: absolute;
  top: 5px;
  right: 5px;
  background: rgba(0,0,0,0.55);
  border: none;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
  padding: 0;
}

#self-preview:hover #hide-self-btn { opacity: 1; }
#hide-self-btn:hover { color: #fff; background: rgba(0,0,0,0.8); }

#hide-cam-btn {
  position: absolute;
  top: 5px;
  right: 5px;
  background: rgba(0,0,0,0.55);
  border: none;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
  padding: 0;
  z-index: 5;
}

#cam-overlay:hover #hide-cam-btn { opacity: 1; }
#hide-cam-btn:hover { color: #fff; background: rgba(0,0,0,0.8); }

/* ── Eye restore buttons in controls bar ── */
.eye-restore-btn {
  opacity: 0;
  transform: scale(0.5);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease, color 0.15s;
  margin-left: 2px;
}

.eye-restore-btn.visible {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

#self-eye-btn { color: #e040fb; }
#cam-eye-btn  { color: #40c4ff; }
#self-eye-btn:hover { color: #f590ff; }
#cam-eye-btn:hover  { color: #90e0ff; }


/* ── Mic/Cam active state ── */
#mic-btn.muted,
#cam-btn.off { color: #e040fb; }

/* ── Voice volume control (on girlfriend overlay) ── */
#voice-volume-wrap {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 4px;
  padding-bottom: 8px;
  background: linear-gradient(transparent 40%, rgba(0,0,0,0.7));
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

#cam-overlay:hover #voice-volume-wrap {
  opacity: 1;
  pointer-events: all;
}

#voice-volume-wrap svg { color: rgba(255,255,255,0.7); flex-shrink: 0; }

#voice-volume {
  width: 80px;
  accent-color: #e040fb;
  cursor: pointer;
}


/* ── Connection Panel ── */
#connect-panel {
  position: fixed;
  bottom: 90px;
  right: 24px;
  width: 260px;
  background: rgba(18, 18, 18, 0.95);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
  backdrop-filter: blur(12px);
  z-index: 100;
  overflow: hidden;
  opacity: 1;
  transition: opacity 0.25s;
  pointer-events: auto;
}

/* Once a movie is loaded, follow the same hide logic as the controls bar */
body.movie-loaded #connect-panel {
  opacity: 0;
  pointer-events: none;
}

body.movie-loaded #connect-panel.controls-visible,
body.movie-loaded #connect-panel:hover {
  opacity: 1;
  pointer-events: auto;
}

body.movie-paused #connect-panel {
  opacity: 1;
  pointer-events: auto;
}

#connect-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  cursor: default;
}

#connect-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #555;
  flex-shrink: 0;
  transition: background 0.3s;
}

#connect-status-dot.connected { background: #4caf50; }
#connect-status-dot.connecting { background: #ff9800; animation: pulse-dot 1s infinite; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

#connect-status-text {
  flex: 1;
  font-size: 0.8rem;
  color: #aaa;
}

#connect-toggle-btn {
  background: none;
  border: 1px solid rgba(255,255,255,0.15);
  color: #ccc;
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

#connect-toggle-btn:hover { border-color: #e040fb; color: #e040fb; }

#connect-body {
  border-top: 1px solid rgba(255,255,255,0.07);
  padding: 12px 14px 14px;
}

/* Tabs */
#connect-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
}

.tab-btn {
  flex: 1;
  background: none;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  color: #666;
  font-size: 0.8rem;
  padding: 5px 0;
  cursor: pointer;
  transition: all 0.15s;
}

.tab-btn.active {
  background: rgba(224,64,251,0.15);
  border-color: #e040fb;
  color: #e040fb;
}

/* Tab content */
.tab-hint {
  display: block;
  font-size: 0.75rem;
  color: #666;
  margin-bottom: 10px;
  line-height: 1.4;
}

.tab-hint.error { color: #f44336; }

.action-btn {
  width: 100%;
  background: #e040fb;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 0;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s;
}

.action-btn:hover { background: #ce35df; }
.action-btn:disabled { background: #444; cursor: default; }

/* Room code display */
#room-code-wrap { margin-top: 10px; }

#room-code-display {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 8px;
}

#room-code-text {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: #fff;
  font-family: monospace;
}

#copy-btn {
  background: none;
  border: none;
  color: #888;
  cursor: pointer;
  padding: 2px;
  transition: color 0.15s;
}

#copy-btn:hover { color: #e040fb; }

#waiting-text { margin-bottom: 0; }

/* Join input */
#join-input-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#join-code-input {
  width: 100%;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  color: #fff;
  font-size: 0.9rem;
  font-family: monospace;
  letter-spacing: 0.1em;
  padding: 7px 10px;
  outline: none;
  text-transform: lowercase;
}

#join-code-input:focus { border-color: #e040fb; }

#join-room-btn {
  width: 100%;
  padding: 8px 0;
  font-size: 0.85rem;
}

#join-room-btn.is-connected {
  background: #2a7a3b;
  cursor: default;
  opacity: 0.85;
}

#join-error { margin-top: 8px; margin-bottom: 0; }

/* ── Buffering indicator (MSE stall) ── */
#buffering-indicator {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0,0,0,0.8);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 0.85rem;
  color: #fff;
  z-index: 10000;
  pointer-events: none;
}

#buffering-indicator .spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.15);
  border-top-color: #e040fb;
  border-radius: 50%;
  animation: smingle-spin 0.8s linear infinite;
}

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