:root {
  --bg: #0b0710;
  --bg-2: #1a0b18;
  --text: #fff4f8;
  --muted: #c9a9bb;
  --red: #ff2d55;
  --pink: #ff6fae;
  --amber: #ffb547;
  --green: #3ddc84;
  --card: rgba(255, 255, 255, 0.06);
  --line: rgba(255, 111, 174, 0.35);
  color-scheme: dark;
}

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

html, body { height: 100%; margin: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: radial-gradient(ellipse at 50% 0%, #3a0d2a 0%, var(--bg-2) 35%, var(--bg) 75%) fixed;
  background-color: var(--bg);
  overflow: hidden;
}

/* Corazones de fondo */
.hearts { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.hearts span {
  position: absolute;
  bottom: -60px;
  color: var(--pink);
  animation: float-up linear infinite;
  will-change: transform;
}
@keyframes float-up {
  from { transform: translateY(0) rotate(-10deg); }
  50% { transform: translateY(-55vh) translateX(20px) rotate(10deg); }
  to { transform: translateY(-115vh) rotate(-10deg); }
}

/* Cabecera */
.top {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px clamp(16px, 3vw, 40px);
  flex-wrap: wrap;
}
.title {
  margin: 0;
  font-size: clamp(28px, 4.5vw, 64px);
  font-weight: 900;
  letter-spacing: 0.04em;
  line-height: 1;
  text-shadow: 0 0 24px rgba(255, 45, 85, 0.55);
}
.title span { color: var(--red); }
.title small {
  font-size: 0.42em;
  letter-spacing: 0.35em;
  color: var(--pink);
  vertical-align: middle;
  margin-left: 0.3em;
}

/* Indicador de estado */
.status {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  font-size: clamp(14px, 1.4vw, 18px);
  font-weight: 600;
}
.status .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); flex: none; }
.status[data-state="waiting"] .dot { background: var(--amber); }
.status[data-state="connecting"] .dot { background: var(--amber); animation: blink 1s ease-in-out infinite; }
.status[data-state="live"] { border-color: var(--red); }
.status[data-state="live"] .dot { background: var(--red); animation: blink 1.4s ease-in-out infinite; box-shadow: 0 0 10px var(--red); }
.status[data-state="error"] .dot { background: var(--red); }
.status[data-state="offline"] .dot { background: var(--muted); animation: blink 1s ease-in-out infinite; }
@keyframes blink { 50% { opacity: 0.25; } }

button {
  font: inherit;
  font-weight: 700;
  color: var(--text);
  background: linear-gradient(135deg, var(--red), var(--pink));
  border: 0;
  border-radius: 999px;
  padding: 12px 22px;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(255, 45, 85, 0.35);
  transition: transform 0.15s ease, opacity 0.15s ease;
}
button:hover { transform: translateY(-1px); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: wait; }
button.ghost { background: var(--card); border: 1px solid var(--line); box-shadow: none; }
button.danger { background: #3a0f1c; border: 1px solid var(--red); box-shadow: none; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--pink); outline-offset: 3px; }

/* ---------- Pantalla del evento ---------- */
.display { display: flex; flex-direction: column; }
.stage {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(16px, 3vw, 48px);
  padding: 0 clamp(16px, 3vw, 40px) 16px;
}
.frame {
  position: relative;
  flex: 1;
  max-width: 1400px;
  height: 100%;
  border-radius: 28px;
  overflow: hidden;
  background: #000;
  border: 3px solid var(--line);
  box-shadow: 0 0 60px rgba(255, 45, 85, 0.25), inset 0 0 80px rgba(255, 45, 85, 0.12);
  transition: box-shadow 0.6s ease, border-color 0.6s ease;
}
.live .frame {
  border-color: var(--red);
  animation: glow 2.4s ease-in-out infinite;
}
@keyframes glow {
  50% { box-shadow: 0 0 90px rgba(255, 45, 85, 0.55), inset 0 0 40px rgba(255, 45, 85, 0.15); }
}
.frame video { width: 100%; height: 100%; object-fit: contain; display: block; visibility: hidden; }
.live .frame video { visibility: visible; }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  background: radial-gradient(circle, rgba(58, 13, 42, 0.9), rgba(11, 7, 16, 0.96));
}
.big-heart {
  font-size: clamp(64px, 10vw, 160px);
  color: var(--red);
  line-height: 1;
  animation: beat 1.3s ease-in-out infinite;
  text-shadow: 0 0 40px rgba(255, 45, 85, 0.7);
}
@keyframes beat { 0%, 100% { transform: scale(1); } 15% { transform: scale(1.15); } 30% { transform: scale(1); } 45% { transform: scale(1.1); } }
.overlay-title { margin: 18px 0 6px; font-size: clamp(22px, 3vw, 44px); font-weight: 800; }
.overlay-sub { margin: 0; font-size: clamp(14px, 1.6vw, 22px); color: var(--muted); }

.join {
  flex: none;
  width: clamp(240px, 24vw, 380px);
  text-align: center;
  padding: 20px;
  border-radius: 24px;
  background: var(--card);
  border: 1px solid var(--line);
}
.qr { background: #fff; border-radius: 16px; padding: 8px; line-height: 0; }
.qr svg { width: 100%; height: auto; }
.join-text { margin: 14px 0 6px; color: var(--muted); font-size: 15px; line-height: 1.4; }
.join-text strong { color: var(--text); }
.code {
  margin: 0;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: clamp(22px, 2.4vw, 34px);
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--pink);
}

.has-camera .join { display: none; }

.controls {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 0 16px 18px;
  transition: opacity 0.4s ease;
}
.idle { cursor: none; }
.idle .controls { opacity: 0; pointer-events: none; }

@media (max-width: 820px), (orientation: portrait) {
  body.display { overflow: auto; }
  .stage { flex-direction: column; padding-bottom: 16px; }
  .frame { flex: none; width: 100%; height: auto; aspect-ratio: 16 / 9; }
  .join { width: min(100%, 340px); }
}

/* ---------- Cámara móvil ---------- */
body.camera { overflow-y: auto; min-height: 100%; }
.camera .top { justify-content: center; padding-top: max(16px, env(safe-area-inset-top)); }
.camera .title { font-size: 30px; }
.cam-main {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 8px 16px max(24px, env(safe-area-inset-bottom));
}
.card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px;
  border-radius: 24px;
  background: var(--card);
  border: 1px solid var(--line);
}
.card label { font-weight: 700; font-size: 15px; color: var(--muted); }
.card input {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-align: center;
  text-transform: uppercase;
  color: var(--text);
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 14px 8px;
  width: 100%;
}
button.primary { padding: 18px 22px; font-size: 18px; }
.hint { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.error {
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(255, 45, 85, 0.15);
  border: 1px solid var(--red);
  font-size: 15px;
  line-height: 1.4;
}

.preview {
  position: relative;
  border-radius: 24px;
  overflow: hidden;
  background: #000;
  border: 3px solid var(--line);
  aspect-ratio: 3 / 4;
  max-height: 60vh;
  margin: 0 auto;
}
.preview video { width: 100%; height: 100%; object-fit: cover; display: block; }
.preview video.mirror { transform: scaleX(-1); }
.badge {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(11, 7, 16, 0.85);
  border: 1px solid var(--amber);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}
#step-live .status { display: flex; justify-content: center; margin: 16px 0; text-align: center; }
.row { display: flex; gap: 12px; }
.row button { flex: 1; padding: 16px 12px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
