/* Colores que se animan suavemente (luz ambiental) */
@property --glow-a { syntax: "<color>"; inherits: true; initial-value: #7c3aed; }
@property --glow-b { syntax: "<color>"; inherits: true; initial-value: #fb7185; }

/* ---------- Tema claro (por defecto) ---------- */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: rgba(246, 244, 251, .82);
  --surface-2: #ece8f6;
  --surface-hover: #e1dbf0;
  --line: #ddd7ec;
  --text: #1c1730;
  --muted: #6a6383;
  --placeholder: #a29bbb;
  --accent: #7c3aed;
  --accent-ink: #ffffff;
  --accent-text: #5b21b6;
  --danger: #d23b3b;
  --shadow: 0 6px 14px -6px rgba(40, 25, 90, .3);
  --metal-top: #ffffff;
  --metal-mid: #f2f3f8;
  --metal-bottom: #dfe2ec;
  --metal-edge: rgba(255, 255, 255, .9);
  --metal-shadow: rgba(42, 34, 74, .18);
  --message-surface: #f5f3f8;
  --message-edge: rgba(255, 255, 255, .9);
  --message-shadow: rgba(40, 25, 90, .12);
  --glow-strength: .035;
  --halo-strength: .06;
  --radius: 14px;
  --radius-sm: 9px;
  --font-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --font-body: "Figtree", "Segoe UI", system-ui, sans-serif;

  transition: --glow-a 2.2s ease, --glow-b 2.2s ease;
}

/* ---------- Tema oscuro ---------- */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000;
  --surface: rgba(16, 16, 20, .82);
  --surface-2: #17171c;
  --surface-hover: #212128;
  --line: #26262e;
  --text: #f4f2fa;
  --muted: #9a97a8;
  --placeholder: #5f5c6e;
  --accent: #8b5cf6;
  --accent-ink: #0b0818;
  --accent-text: #c4b5fd;
  --danger: #ff8a8a;
  --shadow: 0 6px 14px -6px rgba(0, 0, 0, .8);
  --metal-top: #393840;
  --metal-mid: #29282f;
  --metal-bottom: #1d1c22;
  --metal-edge: rgba(255, 255, 255, .16);
  --metal-shadow: rgba(0, 0, 0, .42);
  --message-surface: #1b1b1a;
  --message-edge: rgba(255, 255, 255, .12);
  --message-shadow: rgba(0, 0, 0, .35);
  --glow-strength: .045;
  --halo-strength: .08;
}

* { box-sizing: border-box; margin: 0; }
[hidden] { display: none !important; }

html, body { min-height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color .3s, color .3s;
}

h1, h2 { font-family: var(--font-display); }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Luz ambiental (al fondo de la página) ---------- */
.ambient {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0;
  background:
    radial-gradient(60% 55% at 28% 30%, var(--glow-a), transparent 70%),
    radial-gradient(55% 50% at 76% 62%, var(--glow-b), transparent 70%);
  filter: blur(70px);
  transition: opacity 1.4s ease;
}
body.has-video .ambient { opacity: calc(var(--glow-strength) * .55); }
body.has-video.is-playing .ambient { opacity: var(--glow-strength); }

/* Halo justo alrededor del reproductor, como el modo ambiente de YouTube */
.player-stage { position: relative; z-index: 0; }
.player-stage::before {
  content: "";
  position: absolute;
  inset: -3% -2%;
  border-radius: 40px;
  background: linear-gradient(100deg, var(--glow-a), var(--glow-b));
  filter: blur(56px);
  opacity: 0;
  transition: opacity 1.4s ease;
  pointer-events: none;
}
body.has-video .player-stage::before { opacity: calc(var(--halo-strength) * .55); }
body.has-video.is-playing .player-stage::before { opacity: var(--halo-strength); }

/* ---------- Controles ---------- */
input {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font: inherit;
  font-size: 15px;
  transition: border-color .15s, box-shadow .15s, background-color .3s;
}
input::placeholder { color: var(--placeholder); }
input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent);
  outline: none;
}

.btn {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color .18s, box-shadow .18s, border-color .18s,
              transform .22s cubic-bezier(.3, 1.5, .5, 1);
}
/* Brillo que cruza el botón al pasar el cursor */
.btn::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(110deg, transparent 30%, rgba(255, 255, 255, .5) 50%, transparent 70%);
  transform: translateX(-120%);
  transition: transform .6s ease;
  pointer-events: none;
}
.btn:hover {
  background: var(--surface-hover);
  transform: translateY(-1.5px);
  box-shadow: var(--shadow);
}
.btn:hover::after { transform: translateX(120%); }
.btn:active {
  transform: translateY(0) scale(.95);
  box-shadow: none;
  transition-duration: .08s;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 86%, white); border-color: transparent; }

.btn-ghost { background: transparent; }

.field { display: grid; gap: 6px; }
.field span { font-size: 14px; color: var(--muted); }

.error { color: var(--danger); font-size: 14px; }
.startup-error {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 20px;
  width: min(560px, calc(100% - 32px));
  padding: 12px 16px;
  border: 1px solid var(--danger);
  border-radius: 12px;
  background: var(--surface-2);
  box-shadow: var(--shadow);
  text-align: center;
  transform: translateX(-50%);
}

/* ---------- Lobby ---------- */
.lobby {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  grid-template-rows: 1fr auto;
  gap: clamp(32px, 6vw, 96px);
  align-items: center;
  max-width: 1120px;
  margin: 0 auto;
  padding: 48px 24px;
}

.lobby-footer {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  width: 100%;
  color: var(--muted);
  font-size: 13px;
}
.kofi-link {
  display: inline-flex;
  flex: 0 0 auto;
  border-radius: 10px;
  transition: transform .18s;
}
.kofi-link:hover { transform: translateY(-2px); }
.kofi-link img {
  display: block;
  width: min(196px, 42vw);
  height: auto;
}
.kofi-button-dark { display: none !important; }
:root[data-theme="dark"] .kofi-button-light { display: none; }
:root[data-theme="dark"] .kofi-button-dark { display: block !important; }

.lobby-intro h1 {
  font-size: clamp(2.2rem, 5.5vw, 4.4rem);
  line-height: 1.02;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 20px;
}
.lobby-intro p {
  color: var(--muted);
  max-width: 46ch;
  font-size: 1.1rem;
}
.feature-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 16px;
  max-width: 560px;
  margin-top: 22px;
  padding: 0;
  list-style: none;
}
.feature-list li {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  color: #258653;
  font-size: 14px;
  font-weight: 600;
}
.feature-list .feature-icon {
  flex: 0 0 20px;
  width: 20px;
  height: 20px;
}
.feature-list .feature-unavailable {
  color: #c63d45;
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
}

.lobby-panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  display: grid;
  gap: 16px;
  box-shadow: 0 1px 0 var(--line), 0 18px 40px -24px rgba(40, 25, 90, .35);
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 14px;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.join-row { display: flex; gap: 8px; }
#codeInput {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

/* ---------- Sala ---------- */
.room {
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 1280px;
  margin: 0 auto;
  padding: 18px 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.room { --accent-text: color-mix(in srgb, var(--accent) 82%, black); }
:root[data-theme="dark"] .room { --accent-text: color-mix(in srgb, var(--accent) 55%, white); }

.room-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 2px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}
.room-coffee-link {
  color: var(--muted);
  text-decoration: none;
  transition: color .18s;
}
.room-coffee-link:hover { color: var(--accent-text); }

.accent-picker {
  position: relative;
  z-index: 2;
}
.accent-picker-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  transition: transform .18s;
}
.accent-picker-btn:hover { transform: scale(1.06); }
.accent-picker-swatch {
  display: block;
  width: 24px;
  height: 24px;
  background: var(--accent);
  border: 0;
  border-radius: 50%;
}
.accent-choice, .accent-custom-swatch {
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 50%;
}
.accent-options {
  position: absolute;
  z-index: 2;
  top: 46px;
  right: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: max-content;
  max-width: calc(100vw - 28px);
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}
.accent-choice {
  padding: 0;
  cursor: pointer;
  transition: transform .18s, box-shadow .18s;
}
.accent-choice:hover, .accent-choice[aria-pressed="true"] {
  transform: scale(1.12);
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text);
}
.accent-custom {
  position: relative;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  overflow: hidden;
  border: 2px dashed var(--muted);
  border-radius: 50%;
  color: var(--muted);
  cursor: pointer;
}
.accent-custom:focus-within {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}
.accent-custom-swatch { display: grid; place-items: center; font-size: 20px; line-height: 1; }
.accent-custom input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  opacity: 0;
  cursor: pointer;
}

.room-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
}

.room-code-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: inherit;
  color: var(--text);
  background: transparent;
  border: 0;
  padding: 4px 0;
  cursor: pointer;
  flex-shrink: 0;
  transition: color .18s, transform .18s;
}
.room-code-btn:hover { color: var(--accent-text); }
.room-code-btn:active { transform: scale(.97); }
.room-code-label { color: var(--muted); font-size: 13px; }
.room-code-value {
  position: relative;
  display: inline-block;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: 0.14em;
  transition: color .18s ease, text-shadow .18s ease;
}
.room-code-copy {
  display: grid;
  place-items: center;
  color: var(--muted);
}
.room-code-btn:hover .room-code-copy .icon { transform: scale(1.1); }
.room-code-copy .icon { transition: transform .2s; }
.room-code-controls {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.room-code-visibility {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background-color .18s, color .18s;
}
.room-code-visibility:hover {
  background: var(--surface-2);
  color: var(--text);
}
.room-code-visibility .eye-hidden { display: none; }
.room-code-visibility[aria-pressed="true"] .eye-visible { display: none; }
.room-code-visibility[aria-pressed="true"] .eye-hidden { display: block; }
#checkIcon:not([hidden]) { animation: icon-pop .4s cubic-bezier(.3, 1.6, .5, 1); }

.icon { width: 18px; height: 18px; display: block; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  color: var(--text);
  background: var(--surface-2);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  transition: background-color .18s, box-shadow .18s,
              transform .22s cubic-bezier(.3, 1.5, .5, 1);
}
.icon-btn .icon { transition: transform .25s cubic-bezier(.3, 1.5, .5, 1); }
.icon-btn:hover {
  background: var(--surface-hover);
  transform: translateY(-1.5px);
  box-shadow: var(--shadow);
}
.icon-btn:hover .icon { transform: rotate(-10deg) scale(1.12); }
.icon-btn:active {
  transform: scale(.9);
  box-shadow: none;
  transition-duration: .08s;
}

/* Botón con la lista abierta */
.icon-btn[aria-expanded="true"] { background: var(--accent); color: var(--accent-ink); }
.icon-btn[aria-expanded="true"]:hover { background: color-mix(in srgb, var(--accent) 86%, white); }

/* Botón de tema: luna en claro, sol en oscuro */
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
.theme-toggle .icon { animation: icon-pop .45s cubic-bezier(.3, 1.6, .5, 1); }
.theme-toggle:hover .icon { transform: rotate(25deg) scale(1.12); }

/* Esquina superior derecha del lobby: tema + GitHub */
.corner {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top));
  right: 14px;
  z-index: 5;
  display: flex;
  gap: 8px;
}

@keyframes icon-pop {
  from { transform: scale(.4) rotate(-50deg); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

.toolbar {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.mobile-panel-controls { display: none; }

/* Escenario: video + chat */
.stage {
  --pl-w: 296px;   /* ancho de la lista abierta, incluye 16px de separación */
  --chat-w: 320px;
  --playlist-track: 0px;
  --chat-track: var(--chat-w);
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--playlist-track) minmax(0, 1fr) var(--chat-track);
  grid-template-rows: 32px minmax(0, 1fr);
  row-gap: 16px;
  align-items: stretch;
  transition: grid-template-columns .35s cubic-bezier(.3, .9, .3, 1);
}
.stage.pl-open { --playlist-track: var(--pl-w); }
.stage.chat-closed { --chat-track: 0px; }
.stage.chat-closed .chat { margin-left: 0; }

.stage-controls {
  grid-column: 1 / -1;
  grid-row: 1;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}
.stage-toggle {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}
.stage-toggle:hover { background: var(--surface-hover); }
.playlist, .main-col, .chat { grid-row: 2; }

/* ---------- Lista de reproducción (panel izquierdo) ---------- */
.playlist {
  position: relative;
  z-index: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.playlist-inner {
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: calc(var(--pl-w) - 16px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 10px 12px 12px;
  background: var(--surface);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  backdrop-filter: blur(14px) saturate(1.2);
  border-radius: var(--radius);
}
.panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
  font-weight: 800;
}
.pl-form { display: flex; gap: 6px; }
.pl-form input { min-width: 0; padding: 7px 10px; font-size: 14px; }
.pl-form .pl-add-btn {
  display: grid;
  flex: 0 0 36px;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
}
.pl-clear {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
}
.pl-clear:disabled { opacity: .35; cursor: default; }

.pl-list {
  flex: 1;
  min-height: 0;
  list-style: none;
  padding: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--accent) 55%, var(--muted)) transparent;
  scrollbar-gutter: stable;
}
.pl-list::-webkit-scrollbar { width: 6px; }
.pl-list::-webkit-scrollbar-track { margin-block: 8px; background: transparent; }
.pl-list::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--accent) 55%, var(--muted));
  border: 2px solid transparent;
  border-radius: 999px;
  background-clip: padding-box;
}
.pl-list::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
  background-clip: padding-box;
}
.pl-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 20px 8px; }

.pl-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 6px 5px 0;
  border-radius: var(--radius-sm);
  transition: background-color .15s, opacity .15s;
}
.pl-item:hover, .pl-item:focus-within { background: var(--surface-2); }
.pl-item.is-current { background: var(--surface-2); }
.pl-item.dragging { opacity: .4; }
.pl-item.drop-before::before, .pl-item.drop-after::after {
  content: "";
  position: absolute;
  left: 4px; right: 4px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}
.pl-item.drop-before::before { top: -2px; }
.pl-item.drop-after::after { bottom: -2px; }

.pl-grip {
  flex-shrink: 0;
  align-self: stretch;
  display: grid;
  place-items: center;
  width: 16px;
  color: var(--placeholder);
  cursor: grab;
}
.pl-grip .icon { width: 14px; height: 14px; }
.pl-item:hover .pl-grip { color: var(--muted); }

.pl-play {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 6px;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.pl-thumb {
  flex-shrink: 0;
  width: 80px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 6px;
  background: var(--surface-hover);
}
.pl-title {
  font-size: 13px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.pl-item.is-current .pl-title { color: var(--accent-text); font-weight: 600; }

.pl-btn {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background-color .15s, color .15s;
}
.pl-btn .icon { width: 14px; height: 14px; }
.pl-btn:hover:not(:disabled) { background: var(--line); }
.pl-btn.danger { color: var(--danger); }
.pl-btn.danger:hover:not(:disabled) { background: color-mix(in srgb, var(--danger) 14%, transparent); }
.pl-delete {
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
}
.pl-btn:disabled { opacity: .3; cursor: default; }

.main-col {
  min-width: 0;
  display: grid;
  gap: 12px;
  align-content: start;
  min-width: 0;
}

.player-wrap {
  position: relative;
  z-index: 1;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}
.player-wrap iframe, .player-wrap #player {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 4px;
  padding: 16px;
  background: var(--surface-2);
  z-index: 2;
}
.empty-state p { font-family: var(--font-display); font-size: 1.5rem; font-weight: 800; }
.empty-state span { color: var(--muted); }

.video-ratings {
  display: grid;
  gap: 9px;
  width: 100%;
  margin: 0 auto;
  padding: 2px 0 4px;
}
.rating-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  align-items: center;
}
.rating-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 54px;
  padding: 5px 9px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: transform .18s, background .18s, border-color .18s, box-shadow .18s, opacity .18s;
}
.rating-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface-2));
  border-color: var(--metal-edge);
  box-shadow: 0 2px 6px var(--metal-shadow), inset 0 1px 0 var(--metal-edge);
}
.rating-btn[aria-pressed="true"] {
  background: color-mix(in srgb, var(--accent) 18%, var(--surface-2));
  border-color: color-mix(in srgb, var(--accent) 48%, var(--metal-edge));
  box-shadow: inset 0 1px 3px var(--metal-shadow);
}
.rating-btn:active:not(:disabled) { transform: scale(.94); }
.rating-btn:disabled { opacity: .45; cursor: default; }
.rating-icon { width: 18px; height: 18px; }
.rating-heart-filled { display: none; }
.rating-btn[aria-pressed="true"] .rating-heart-empty { display: none; }
.rating-btn[aria-pressed="true"] .rating-heart-filled { display: block; }
.rating-btn[aria-pressed="true"] .rating-icon { animation: rating-pop .32s cubic-bezier(.2, 1.6, .4, 1); }
.rating-btn[aria-pressed="true"]#likeVideoBtn { color: #ef476f; }
.rating-btn[aria-pressed="true"]#dislikeVideoBtn { color: var(--accent); }
@keyframes rating-pop {
  0% { transform: scale(.65); }
  65% { transform: scale(1.28); }
  100% { transform: scale(1); }
}
.rating-count { min-width: 1ch; color: var(--muted); font-size: 12px; font-weight: 700; }
.chat-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.chat-presence {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
}
.chat-presence .icon { width: 16px; height: 16px; }
.chat-clear {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
  transition: color .18s, border-color .18s, background .18s, transform .18s, opacity .18s;
}
.chat-clear:hover:not(:disabled) {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 48%, var(--line));
  background: color-mix(in srgb, var(--danger) 10%, var(--surface-2));
  transform: translateY(-1px);
}
.chat-clear:active:not(:disabled) { transform: scale(.92); }
.chat-clear:disabled { opacity: .4; cursor: default; }
.chat-clear .icon { width: 15px; height: 15px; }
.count {
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 999px;
  min-width: 20px;
  padding: 0 7px;
  font-size: 12px;
  font-weight: 600;
  line-height: 20px;
  text-align: center;
  font-family: var(--font-body);
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Chat: su alto lo marca la columna del video */
.chat {
  position: relative;
  margin-left: 16px;
  min-height: 0;
  overflow: hidden;
  background: var(--surface);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  backdrop-filter: blur(14px) saturate(1.2);
  border-radius: var(--radius);
}
.chat-inner {
  position: absolute;
  inset: 0;
  min-height: 0;
  overflow: visible;
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 10px;
}
.chat-title { font-size: 1rem; font-weight: 800; }

.messages {
  flex: 1;
  min-height: 0;
  list-style: none;
  padding: 0 10px 0 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--accent) 55%, var(--muted)) transparent;
  scrollbar-gutter: stable;
}
.messages::-webkit-scrollbar {
  width: 6px;
}
.messages::-webkit-scrollbar-track {
  margin-block: 8px;
  background: transparent;
}
.messages::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--accent) 55%, var(--muted));
  border: 2px solid transparent;
  border-radius: 999px;
  background-clip: padding-box;
}
.messages::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
  background-clip: padding-box;
}

.msg {
  position: relative;
  max-width: 86%;
  align-self: flex-start;
  background:
    linear-gradient(145deg, color-mix(in srgb, var(--message-surface) 94%, white), var(--message-surface) 55%, color-mix(in srgb, var(--message-surface) 88%, black));
  color: var(--text);
  border: 1px solid color-mix(in srgb, var(--message-edge) 50%, var(--line));
  border-radius: 18px 18px 18px 6px;
  box-shadow: 0 3px 9px var(--message-shadow), inset 0 1px 0 var(--message-edge);
  padding: 9px 13px;
  overflow-wrap: anywhere;
  font-size: 15px;
  line-height: 1.4;
}
.msg:not(.own):not(.system)::before,
.msg.own::before {
  content: "";
  position: absolute;
  bottom: 0;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: inherit;
}
.msg:not(.own):not(.system)::before { left: -3px; }
.msg-enter { animation: message-enter .34s cubic-bezier(.16, 1, .3, 1) both; }
@keyframes message-enter {
  from { opacity: 0; transform: translateY(12px) scale(.94); filter: blur(3px); }
  65% { opacity: 1; transform: translateY(-2px) scale(1.01); filter: blur(0); }
  to { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
}
.msg-name {
  display: block;
  margin-bottom: 3px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-text);
}
.msg.is-owner .msg-name { color: #ffcf33; }
.msg.own {
  align-self: flex-end;
  background: linear-gradient(145deg, color-mix(in srgb, var(--accent) 82%, white), color-mix(in srgb, var(--accent) 90%, var(--text)) 58%, color-mix(in srgb, var(--accent) 75%, black));
  color: #ffffff;
  border-color: color-mix(in srgb, white 22%, var(--accent));
  border-radius: 18px 18px 6px 18px;
  box-shadow: 0 3px 10px color-mix(in srgb, var(--accent) 22%, transparent), inset 0 1px 0 rgba(255, 255, 255, .35);
}
.msg.own::before {
  right: -3px;
  background: inherit;
}
.msg.system {
  align-self: center;
  max-width: 100%;
  background: none;
  color: var(--muted);
  font-size: 13px;
  padding: 0;
  text-align: center;
  border: 0;
  box-shadow: none;
}

.typing-indicator {
  display: flex;
  align-items: center;
  align-self: flex-start;
  justify-content: center;
  width: 54px;
  height: 38px;
  flex: 0 0 auto;
  padding: 9px 13px;
  border: 1px solid color-mix(in srgb, var(--message-edge) 50%, var(--line));
  border-radius: 17px 17px 17px 6px;
  background: linear-gradient(145deg, color-mix(in srgb, var(--message-surface) 94%, white), var(--message-surface) 58%, color-mix(in srgb, var(--message-surface) 88%, black));
  box-shadow: 0 3px 9px var(--message-shadow), inset 0 1px 0 var(--message-edge);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  transition: opacity .18s ease, transform .18s ease;
}
.typing-indicator.is-leaving { opacity: 0; transform: translateY(4px) scale(.94); }
.typing-dots { display: inline-flex; flex: 0 0 auto; align-items: center; gap: 3px; }
.typing-indicator[hidden] { display: none; }
.typing-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing-dot 1s ease-in-out infinite;
}
.typing-dots i:nth-child(2) { animation-delay: .15s; }
.typing-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes typing-dot {
  0%, 60%, 100% { opacity: .4; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}
@media (prefers-reduced-motion: reduce) {
  .typing-indicator { transition: none; }
}

.chat-form { position: relative; display: flex; align-items: center; gap: 8px; }
.chat-form input { flex: 1; min-width: 0; }
.chat-send {
  display: grid;
  flex: 0 0 40px;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
}
.chat-emoji-picker { position: relative; flex: 0 0 38px; }
.chat-emoji-toggle {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 0;
  border-radius: 11px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}
.chat-emoji-toggle .icon { width: 22px; height: 22px; }
.chat-emoji-toggle:hover, .chat-emoji-toggle[aria-expanded="true"] {
  background: color-mix(in srgb, var(--accent) 24%, var(--surface-2));
}
.chat-emoji-options {
  position: absolute;
  right: 0;
  bottom: calc(100% + 10px);
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(3, 42px);
  gap: 4px;
  padding: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.chat-emoji-options button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-size: 22px;
  cursor: pointer;
}
.chat-emoji-options button:hover { background: var(--surface-hover); transform: scale(1.08); }
.chat-reaction {
  position: absolute;
  z-index: 3;
  bottom: 70px;
  left: var(--reaction-x, 50%);
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  border-radius: 50%;
  background: var(--surface-2);
  box-shadow: var(--shadow);
  font-size: 26px;
  pointer-events: none;
  animation: chat-reaction-float 3.2s cubic-bezier(.2, .65, .4, 1) forwards;
}
@keyframes chat-reaction-float {
  0% { opacity: 0; transform: translate(-50%, 20px) scale(.55); }
  12% { opacity: 1; }
  75% { opacity: .95; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--reaction-drift, 0px)), -340px) scale(1.15); }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  font-size: 14px;
  padding: 9px 16px;
  border-radius: 999px;
  z-index: 10;
  max-width: calc(100% - 32px);
  text-align: center;
  animation: toast-in .25s cubic-bezier(.3, 1.4, .5, 1);
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- Pantallas medianas: laterales más angostos ---------- */
/* Acabado metálico compartido por los controles interactivos */
.btn,
.icon-btn,
.stage-toggle,
.room-code-visibility,
.pl-btn,
.chat-clear,
.rating-btn,
.chat-emoji-toggle,
.chat-emoji-options button,
.accent-picker-btn {
  border: 1px solid var(--metal-edge);
  background: linear-gradient(145deg, var(--metal-top), var(--metal-mid) 54%, var(--metal-bottom));
  box-shadow: 0 2px 6px var(--metal-shadow), inset 0 1px 0 var(--metal-edge);
  transition: background .18s, border-color .18s, box-shadow .18s, color .18s,
              transform .22s cubic-bezier(.3, 1.5, .5, 1);
}
.btn-primary,
.icon-btn[aria-expanded="true"],
.mobile-panel-btn[aria-expanded="true"] {
  border-color: color-mix(in srgb, var(--accent) 70%, white);
  background: linear-gradient(145deg, color-mix(in srgb, var(--accent) 72%, white), var(--accent) 55%, color-mix(in srgb, var(--accent) 82%, black));
  box-shadow: 0 3px 9px color-mix(in srgb, var(--accent) 28%, transparent), inset 0 1px 0 rgba(255, 255, 255, .45);
}
.btn-primary:hover,
.icon-btn[aria-expanded="true"]:hover,
.mobile-panel-btn[aria-expanded="true"]:hover {
  background: linear-gradient(145deg, color-mix(in srgb, var(--accent) 62%, white), color-mix(in srgb, var(--accent) 92%, white) 55%, var(--accent));
}
.btn:hover,
.icon-btn:hover,
.stage-toggle:hover,
.room-code-visibility:hover,
.pl-btn:hover:not(:disabled),
.rating-btn:hover:not(:disabled),
.chat-emoji-toggle:hover,
.chat-emoji-toggle[aria-expanded="true"],
.chat-emoji-options button:hover,
.accent-picker-btn:hover {
  border-color: color-mix(in srgb, var(--accent) 32%, var(--metal-edge));
  box-shadow: 0 4px 10px var(--metal-shadow), inset 0 1px 0 var(--metal-edge);
}
.btn:active,
.icon-btn:active,
.stage-toggle:active,
.room-code-visibility:active,
.pl-btn:active:not(:disabled),
.rating-btn:active:not(:disabled),
.chat-emoji-toggle:active,
.chat-emoji-options button:active,
.accent-picker-btn:active {
  box-shadow: inset 0 2px 4px var(--metal-shadow);
}
.accent-picker-btn {
  border-radius: 10px;
}
.accent-picker-swatch,
.accent-choice {
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, .45), 0 1px 3px var(--metal-shadow);
}

@media (max-width: 1180px) {
  .stage { --pl-w: 256px; --chat-w: 284px; }
}

/* ---------- Tablet y móvil ---------- */
@media (max-width: 900px) {
  .lobby { grid-template-columns: 1fr; padding: 64px 20px 32px; }
  .feature-list { max-width: none; }

  .room { padding: 14px 14px calc(20px + env(safe-area-inset-bottom)); }
  .room.accent-open .room-top { margin-bottom: 62px; }
  .accent-options {
    position: fixed;
    top: calc(60px + env(safe-area-inset-top));
    right: auto;
    left: 50%;
    transform: translateX(-50%);
  }
  .stage-controls,
  #playlistBtn { display: none; }
  .mobile-panel-controls { display: flex; gap: 6px; }
  .mobile-panel-btn[aria-expanded="true"] {
    background: var(--accent);
    color: var(--accent-ink);
  }

  .stage, .stage.pl-open, .stage.chat-closed {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto;
  }

  /* La lista y el chat pasan debajo del video con altura fija */
  .main-col { grid-row: 1; }
  .playlist { display: none; grid-row: 2; height: 360px; overflow: visible; }
  .stage.pl-open .playlist { display: block; }
  .playlist-inner { width: auto; right: 0; }
  .chat { grid-row: 3; height: 360px; margin-left: 0; }
  .stage.chat-closed .chat { display: none; }
}

@media (max-width: 600px) {
  .room { padding-right: 30px; }

  .lobby-panel { padding: 18px; }
  .lobby-footer { font-size: 12px; }
  .feature-list { grid-template-columns: 1fr; gap: 9px; margin-top: 18px; }

  .room-top { gap: 10px; }
  .room-code-value { font-size: 1rem; }

  .player-wrap { border-radius: 10px; }

  /* 16px evita el zoom automático de iOS al enfocar un campo */
  input { font-size: 16px; }
}

@media (max-width: 900px), (pointer: coarse) {
  :root { transition: none; }

  body { transition: none; }

  .ambient,
  .player-stage::before { display: none; }

  .chat,
  .playlist-inner {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  .stage { transition: none; }
  .msg-enter { animation-duration: .24s; }

  .btn,
  .icon-btn,
  .chat-emoji-options button {
    transition: none;
  }

  .btn::after { display: none; }
  .chat-emoji-options button:hover { transform: none; }

  .chat-reaction {
    box-shadow: none;
    animation-duration: 1.2s;
  }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .btn::after { display: none; }
  .chat-reaction { animation: chat-reaction-float 1ms forwards; }
}
