/* ── Reset & base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --bg:        #0f0f11;
  --surface:   #1a1a1f;
  --surface2:  #25252d;
  --border:    #2e2e38;
  --accent:    #7c5cfc;
  --accent-h:  #9b7fff;
  --text:      #e8e8f0;
  --text-2:    #9090a8;
  --danger:    #f04040;
  --warn:      #c87a20;
  --radius:    10px;
  --font: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

html { font-size: 16px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

/* ── Utility ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  white-space: nowrap;
  background: none;
  color: var(--text);
}
.btn:disabled { opacity: 0.5; cursor: default; }

.btn-primary   { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-h); border-color: var(--accent-h); }

.btn-ghost     { border-color: var(--border); color: var(--text-2); }
.btn-ghost:hover { border-color: var(--accent); color: var(--text); }

.btn-sm  { padding: 5px 12px; font-size: 0.8rem; }
.btn-full { width: 100%; justify-content: center; }

.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 16px;
}
.alert-error { background: #2d1010; border: 1px solid var(--danger); color: #ff7070; }
.alert-warn  { background: #251800; border: 1px solid var(--warn);   color: #f0a850; }

/* ── Header ────────────────────────────────────────────────────────────────── */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.logo {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent);
  letter-spacing: 0.02em;
}

nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.username-badge {
  font-size: 0.8rem;
  color: var(--text-2);
  padding: 4px 10px;
  background: var(--surface2);
  border-radius: 99px;
}

.viewer-badge {
  font-size: 0.8rem;
  color: var(--text-2);
  padding: 4px 10px;
  background: var(--surface2);
  border-radius: 99px;
}
.viewer-badge:empty { display: none; }

/* ── Auth / Login ──────────────────────────────────────────────────────────── */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) * 1.5);
  padding: 40px 36px;
}

.auth-card .logo {
  display: block;
  text-align: center;
  font-size: 1.5rem;
  margin-bottom: 6px;
}

.tagline {
  text-align: center;
  color: var(--text-2);
  font-size: 0.85rem;
  margin-bottom: 32px;
}

.field {
  margin-bottom: 16px;
}
.field label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-2);
  margin-bottom: 6px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.field input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.15s;
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
}
.field input::placeholder { color: var(--text-2); }

.auth-card .btn-primary { margin-top: 8px; }

/* ── Library ───────────────────────────────────────────────────────────────── */
.library-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px;
}

.library-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.library-toolbar h2 {
  font-size: 1.3rem;
  font-weight: 600;
}

.empty-state {
  text-align: center;
  padding: 80px 24px;
  color: var(--text-2);
}
.empty-state p { margin-bottom: 8px; }
.empty-state .hint { font-size: 0.85rem; }
.empty-state code {
  background: var(--surface2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.8rem;
}

.movie-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 20px;
}

.movie-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s, transform 0.15s;
  cursor: pointer;
  display: flex;
  flex-direction: column;
}
.movie-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.movie-thumb {
  aspect-ratio: 16/9;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
}
.play-icon {
  font-size: 2.5rem;
  color: var(--accent);
  opacity: 0.7;
}
.movie-card:hover .play-icon { opacity: 1; }

.movie-info {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.movie-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.movie-filename {
  font-size: 0.72rem;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Party / Player ────────────────────────────────────────────────────────── */
.party-page { display: flex; flex-direction: column; }

.player-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px;
  gap: 16px;
  flex: 1;
}

.player-wrap {
  width: 100%;
  max-width: 1100px;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.video-el {
  display: block;
  width: 100%;
  max-height: 80vh;
  background: #000;
}

.player-meta {
  width: 100%;
  max-width: 1100px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.player-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

.player-status-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sync-status {
  font-size: 0.8rem;
  color: var(--text-2);
  padding: 4px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 99px;
}
.sync-status.connected    { border-color: #2ecc71; color: #2ecc71; }
.sync-status.disconnected { border-color: var(--danger); color: #ff7070; }

/* ── Player nav (prev / next) ──────────────────────────────────────────────── */
.player-nav {
  width: 100%;
  max-width: 1100px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.player-nav-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 45%;
  overflow: hidden;
}

.player-nav-btn .nav-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-nav-btn .nav-arrow { flex-shrink: 0; }

/* ── Library: now watching ─────────────────────────────────────────────────── */
.now-watching-section {
  margin-bottom: 32px;
}

.now-watching-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px 16px;
  max-width: 520px;
}

.now-watching-thumb {
  width: 40px;
  height: 40px;
  background: color-mix(in srgb, var(--accent) 15%, var(--surface2));
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  color: var(--accent);
}

.now-watching-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  overflow: hidden;
}

.now-watching-who {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.now-watching-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Library: continue watching ────────────────────────────────────────────── */
.section-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-2);
  margin-bottom: 12px;
}

.continue-section {
  margin-bottom: 32px;
}

.movie-card-wide {
  display: flex;
  flex-direction: row;
  max-width: 420px;
}

.movie-card-wide .movie-thumb {
  width: 140px;
  flex-shrink: 0;
  aspect-ratio: unset;
  height: 80px;
}

.movie-card-wide .movie-info {
  justify-content: center;
}

/* ── Library: last-watched badge ───────────────────────────────────────────── */
.movie-thumb { position: relative; }

.watched-badge {
  position: absolute;
  bottom: 6px;
  left: 6px;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--accent);
  color: #fff;
  padding: 2px 7px;
  border-radius: 99px;
}

.movie-card-watched { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }

/* ── Volume control ────────────────────────────────────────────────────────── */
.volume-control {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.volume-icon {
  font-size: 1rem;
  line-height: 1;
  user-select: none;
}

#volumeSlider {
  -webkit-appearance: none;
  appearance: none;
  width: 80px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}

#volumeSlider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

#volumeSlider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

/* ── iOS unlock overlay ────────────────────────────────────────────────────── */
.ios-unlock {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: var(--radius);
}

.ios-unlock-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
}

.ios-unlock-icon {
  font-size: 2.5rem;
  color: var(--accent);
}

/* ── Mobile ────────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  /* Header: hide username pill (user knows who they are), tighten gap */
  .site-header { padding: 0 14px; gap: 8px; }
  .username-badge { display: none; }
  .viewer-badge { font-size: 0.75rem; padding: 3px 8px; }

  /* Auth card */
  .auth-card { padding: 32px 20px; }

  /* Library */
  .library-main { padding: 20px 14px; }
  .movie-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .movie-card-wide { max-width: 100%; }
  .movie-card-wide .movie-thumb { width: 110px; }

  /* Now watching */
  .now-watching-card { max-width: 100%; }

  /* Player */
  .player-main { padding: 10px 10px 20px; gap: 10px; }
  .player-wrap { border-radius: 6px; }
  .video-el { max-height: 56vw; } /* ~16:9 on phone width */

  .player-meta { flex-direction: column; align-items: flex-start; gap: 8px; }
  .player-title { font-size: 0.95rem; }
  .player-status-row { width: 100%; justify-content: space-between; }

  .player-nav { flex-direction: row; gap: 8px; }
  .player-nav-btn { max-width: 48%; font-size: 0.78rem; padding: 6px 10px; }
}
