/* =========================================================
   RULETA DEL CUMPLE — estilos de la pantalla de la TV
   Todo se escala con vh/vw: ocupa el ancho de la tele en Full HD o 4K.
   ========================================================= */

:root {
  --fondo: #14052e;
  --fondo-2: #2b0b63;
  --dorado: #ffc83d;
  --dorado-claro: #ffe08a;
  --rosa: #ff2d87;
  --violeta: #7b2ff7;

  /* Diámetro de la ruleta: lo más grande posible sin pisar el historial */
  --rueda: min(90vh, 62vw);

  --fuente-titulo: 'Luckiest Guy', 'Arial Black', 'Segoe UI Black', system-ui, sans-serif;
  --fuente-texto: 'Fredoka', 'Segoe UI', system-ui, sans-serif;
}

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

html {
  /* 1rem ≈ 19px en Full HD y ≈ 39px en 4K */
  font-size: calc(0.9vh + 0.5vw);
  font-size: max(14px, calc(0.9vh + 0.5vw));
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  color: #fff;
  font-family: var(--fuente-texto);
  background-color: var(--fondo);
  background-image:
    radial-gradient(circle at 15% 20%, rgba(255, 45, 135, 0.35), transparent 38%),
    radial-gradient(circle at 85% 85%, rgba(0, 194, 255, 0.28), transparent 40%),
    radial-gradient(circle at 70% 10%, rgba(255, 200, 61, 0.18), transparent 30%),
    radial-gradient(circle at 50% 50%, var(--fondo-2), var(--fondo) 75%);
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- Estado 2: ruleta + historial ---------- */

.escena {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 27vw);
  align-items: center;
  gap: 2vw;
  height: 100vh;
  padding: 3vh 2.5vw;
}

.rueda-zona {
  position: relative;
  display: grid;
  place-items: center;
  height: 100%;
}

/* Rayos de luz girando lentamente detrás de la ruleta */
.rueda-zona::before {
  content: '';
  position: absolute;
  width: calc(var(--rueda) * 1.7);
  height: calc(var(--rueda) * 1.7);
  border-radius: 50%;
  background: repeating-conic-gradient(rgba(255, 255, 255, 0.07) 0deg 9deg, transparent 9deg 18deg);
  -webkit-mask-image: radial-gradient(circle, #000 25%, transparent 68%);
          mask-image: radial-gradient(circle, #000 25%, transparent 68%);
  animation: girar-lento 80s linear infinite;
  will-change: transform;
  pointer-events: none;
}

.rueda-marco {
  position: relative;
  width: var(--rueda);
  height: var(--rueda);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, #4a148f 0 72%, #1b0640 100%);
  box-shadow:
    0 0 0 calc(var(--rueda) * 0.012) var(--dorado),
    0 0 0 calc(var(--rueda) * 0.02) #6b2a00,
    0 0 calc(var(--rueda) * 0.09) rgba(255, 200, 61, 0.45),
    0 calc(var(--rueda) * 0.03) calc(var(--rueda) * 0.06) rgba(0, 0, 0, 0.6);
}

#rueda {
  position: absolute;
  top: 7%;
  left: 7%;
  width: 86%;
  height: 86%;
  border-radius: 50%;
  will-change: transform;
  box-shadow:
    0 0 0 calc(var(--rueda) * 0.008) var(--dorado-claro),
    0 0 calc(var(--rueda) * 0.035) rgba(0, 0, 0, 0.7);
}

/* Lamparitas alrededor de la ruleta */
.focos { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; }

.foco {
  position: absolute;
  width: calc(var(--rueda) * 0.03);
  height: calc(var(--rueda) * 0.03);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 35% 35%, #fff 0 15%, #ffe27a 45%, #ff9d00 100%);
  box-shadow: 0 0 calc(var(--rueda) * 0.022) #ffd34d;
  animation: parpadeo 1.2s steps(1, end) infinite;
}
.foco:nth-child(even) { animation-delay: -0.6s; }

.rueda-marco.girando .foco { animation-duration: 0.28s; }
.rueda-marco.girando .foco:nth-child(even) { animation-delay: -0.14s; }
.rueda-marco.festejo .foco { animation: destello 0.18s steps(1, end) infinite; }

@keyframes parpadeo {
  0%   { opacity: 1; }
  50%  { opacity: 0.25; box-shadow: none; }
}
@keyframes destello {
  0%   { opacity: 1; filter: hue-rotate(0deg); }
  50%  { opacity: 0.4; filter: hue-rotate(140deg); }
}

.rueda-centro {
  position: absolute;
  left: 40%;
  top: 40%;
  width: 20%;
  height: 20%;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: calc(var(--rueda) * 0.008) solid #fff6d6;
  background: radial-gradient(circle at 35% 30%, #fff3c4 0%, var(--dorado) 40%, #d9860b 100%);
  font-size: calc(var(--rueda) * 0.09);
  line-height: 1;
  box-shadow:
    0 calc(var(--rueda) * 0.008) 0 #a65d00,
    0 0 calc(var(--rueda) * 0.04) rgba(0, 0, 0, 0.55);
}
.rueda-marco.girando .rueda-centro { animation: latido 0.6s ease-in-out infinite; }

@keyframes latido {
  50% { transform: scale(1.07); }
}

/* Flecha superior: el pivote queda sobre el marco y la punta entra en la rueda */
.flecha {
  position: absolute;
  left: calc(50% - var(--rueda) * 0.05);
  top: calc(var(--rueda) * -0.015);
  width: calc(var(--rueda) * 0.1);
  height: calc(var(--rueda) * 0.142);
  overflow: visible;
  transform-origin: 50% 29.6%;
  filter: drop-shadow(0 calc(var(--rueda) * 0.008) calc(var(--rueda) * 0.008) rgba(0, 0, 0, 0.55));
  z-index: 2;
  pointer-events: none;
}

/* ---------- Panel derecho: título + historial ---------- */

.panel {
  display: flex;
  flex-direction: column;
  gap: 2.4vh;
  height: 100%;
  min-height: 0;
  padding: 1vh 0;
}

.titulo {
  margin: 0;
  font-family: var(--fuente-titulo);
  font-weight: 400;
  font-size: 3.3rem;
  line-height: 1.05;
  text-align: center;
  color: var(--dorado);
  text-shadow:
    0 0.05em 0 var(--rosa),
    0 0.1em 0 var(--violeta),
    0 0.18em 0.25em rgba(0, 0, 0, 0.55);
  transform: rotate(-3deg);
}

.historial {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 2.2vh 1.3vw 0;
  border-radius: 2.6vh;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 2vh 4vh rgba(0, 0, 0, 0.3);
}

.historial-cabecera {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1vw;
  margin-bottom: 1.6vh;
}

.historial-titulo {
  margin: 0;
  font-family: var(--fuente-titulo);
  font-weight: 400;
  font-size: 4.2vh;
  letter-spacing: 0.03em;
}

.historial-total {
  font-size: 2.4vh;
  font-weight: 600;
  opacity: 0.75;
}

.historial-lista {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 1.1vh;
  margin: 0;
  padding: 0.6vh 0.4vw 2vh;
  list-style: none;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(#000 75%, transparent);
          mask-image: linear-gradient(#000 75%, transparent);
}

.historial-item {
  --color: var(--violeta);
  display: flex;
  align-items: center;
  gap: 1vw;
  flex: none;
  padding: 0.9vh 1vw 0.9vh 0.9vh;
  border-radius: 1.8vh;
  background: rgba(0, 0, 0, 0.28);
}
.historial-item:first-child {
  background: rgba(255, 255, 255, 0.14);
  box-shadow: 0 0 0 0.35vh var(--color);
}
.historial-item.nuevo { animation: entrar 0.7s cubic-bezier(0.2, 1.4, 0.4, 1); }

.historial-numero {
  width: 7.4vh;
  height: 7.4vh;
  display: grid;
  place-items: center;
  flex: none;
  padding-top: 0.12em;
  border-radius: 1.5vh;
  background: var(--color);
  font-family: var(--fuente-titulo);
  font-size: 4.6vh;
  text-shadow: 0 0.06em 0 rgba(0, 0, 0, 0.35);
  box-shadow: inset 0 -0.5vh 0 rgba(0, 0, 0, 0.2);
}

.historial-detalle {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}
.historial-puntos {
  font-family: var(--fuente-titulo);
  font-size: 3vh;
  letter-spacing: 0.04em;
}
.historial-hora {
  font-size: 2vh;
  font-weight: 600;
  opacity: 0.65;
}
.historial-orden {
  font-size: 2.4vh;
  font-weight: 700;
  opacity: 0.55;
}

.historial-lista:empty { display: none; }

.historial-vacio {
  flex: 1;
  display: grid;
  place-items: center;
  margin: 0 0 2vh;
  text-align: center;
  font-size: 2.8vh;
  font-weight: 600;
  opacity: 0.7;
}

.control-activo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6em;
  margin: 0;
  font-size: 2.2vh;
  font-weight: 600;
  opacity: 0.8;
}
.control-punto {
  width: 0.8em;
  height: 0.8em;
  border-radius: 50%;
  background: #12b76a;
  box-shadow: 0 0 0.6em #12b76a;
}

@keyframes entrar {
  from { transform: translateX(30%) scale(0.8); opacity: 0; }
}

/* ---------- Estado 1: pantalla del QR ---------- */

.pantalla-qr {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 5vw;
  padding: 6vh 7vw;
  background: rgba(16, 3, 40, 0.86);
  -webkit-backdrop-filter: blur(10px);
          backdrop-filter: blur(10px);
  animation: aparecer 0.4s ease-out;
}

.qr-texto {
  display: flex;
  flex-direction: column;
  gap: 4vh;
}

.qr-titulo {
  margin: 0;
  font-family: var(--fuente-titulo);
  font-weight: 400;
  font-size: 12vh;
  line-height: 1;
  color: var(--dorado);
  text-shadow:
    0 0.05em 0 var(--rosa),
    0 0.1em 0 var(--violeta),
    0 0.18em 0.25em rgba(0, 0, 0, 0.55);
  transform: rotate(-3deg);
  transform-origin: left center;
}

.qr-pasos {
  display: flex;
  flex-direction: column;
  gap: 2.2vh;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 4.4vh;
  font-weight: 600;
}
.qr-pasos li {
  display: flex;
  align-items: center;
  gap: 1.2vw;
}
.qr-pasos span {
  width: 7vh;
  height: 7vh;
  display: grid;
  place-items: center;
  flex: none;
  padding-top: 0.12em;
  border-radius: 50%;
  background: var(--rosa);
  font-family: var(--fuente-titulo);
  font-size: 4vh;
  box-shadow: 0 0.5vh 0 #9c0048;
}
.qr-pasos strong { color: var(--dorado); }

.conexion {
  display: flex;
  align-items: center;
  gap: 0.6em;
  margin: 0;
  font-size: 2.8vh;
  font-weight: 600;
  opacity: 0.9;
}
.conexion-punto {
  width: 0.8em;
  height: 0.8em;
  border-radius: 50%;
  background: #f5a623;
  flex: none;
}
.conexion[data-estado="conectando"] .conexion-punto { animation: pulso 1s ease-in-out infinite; }
.conexion[data-estado="ok"] .conexion-punto { background: #12b76a; box-shadow: 0 0 0.6em #12b76a; }
.conexion[data-estado="error"] .conexion-punto { background: #e5383b; }

.aviso-local {
  margin: 0;
  font-size: 2.4vh;
  color: #ffd9a8;
}

.qr-tarjeta {
  padding: 3.5vh;
  border-radius: 4vh;
  background: #fff;
  color: #2b0b63;
  text-align: center;
  box-shadow:
    0 0 0 1.2vh rgba(255, 255, 255, 0.2),
    0 0 12vh rgba(255, 45, 135, 0.45),
    0 3vh 6vh rgba(0, 0, 0, 0.5);
  animation: invitar 2.4s ease-in-out infinite;
}

.qr {
  display: block;
  width: 62vh;
  height: 62vh;
  image-rendering: pixelated;
}

.qr-codigo {
  margin: 1.6vh 0 0;
  font-size: 3vh;
  font-weight: 600;
}
.qr-codigo strong {
  font-family: var(--fuente-titulo);
  font-weight: 400;
  font-size: 1.4em;
  letter-spacing: 0.14em;
  color: var(--violeta);
}

@keyframes pulso { 50% { opacity: 0.25; } }
@keyframes invitar { 50% { transform: scale(1.015); } }

/* ---------- Estado 3: tarjeta de resultado ---------- */

.resultado {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: rgba(10, 0, 30, 0.72);
  -webkit-backdrop-filter: blur(6px);
          backdrop-filter: blur(6px);
  animation: aparecer 0.3s ease-out;
}

.resultado-rayos {
  position: absolute;
  width: 170vmax;
  height: 170vmax;
  background: repeating-conic-gradient(var(--color-rayos, rgba(255, 255, 255, 0.12)) 0deg 8deg, transparent 8deg 16deg);
  -webkit-mask-image: radial-gradient(circle, #000 10%, transparent 55%);
          mask-image: radial-gradient(circle, #000 10%, transparent 55%);
  animation: girar-lento 30s linear infinite;
  will-change: transform;
}
.resultado--jackpot .resultado-rayos {
  --color-rayos: rgba(255, 200, 61, 0.4);
  animation-duration: 8s;
}
.resultado--triste .resultado-rayos { display: none; }

.tarjeta {
  --color: var(--violeta);
  position: relative;
  width: 62vw;
  width: min(62vw, 92vh);
  padding: 3.5vh 4vw 4vh;
  border-radius: 4vh;
  text-align: center;
  background: var(--color);
  background: radial-gradient(circle at 50% 0%,
    color-mix(in srgb, var(--color) 55%, #fff) 0%,
    var(--color) 45%,
    color-mix(in srgb, var(--color) 55%, #000) 100%);
  box-shadow:
    0 0 0 1vh rgba(255, 255, 255, 0.92),
    0 0 14vh var(--color),
    0 4vh 8vh rgba(0, 0, 0, 0.6);
  animation: pop 0.75s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}
.resultado--triste .tarjeta {
  filter: saturate(0.7);
  animation: pop 0.75s cubic-bezier(0.2, 1.6, 0.4, 1) both, desinflar 2.4s 0.8s ease-in-out infinite;
}
.resultado--jackpot .tarjeta {
  animation: pop 0.75s cubic-bezier(0.2, 1.6, 0.4, 1) both, brillar 0.9s 0.8s ease-in-out infinite;
}

.tarjeta-etiqueta {
  margin: 0;
  font-family: var(--fuente-titulo);
  font-size: 5vh;
  letter-spacing: 0.04em;
  text-shadow: 0 0.06em 0 rgba(0, 0, 0, 0.35);
}

.tarjeta-numero {
  margin: 0;
  font-family: var(--fuente-titulo);
  font-size: 32vh;
  line-height: 0.95;
  padding-top: 0.08em;
  color: #fff;
  text-shadow:
    0 0.035em 0 rgba(0, 0, 0, 0.35),
    0 0.07em 0.1em rgba(0, 0, 0, 0.45);
  animation: rebote 0.9s 0.25s cubic-bezier(0.3, 1.8, 0.5, 1) both;
}

.tarjeta-unidad {
  margin: -1vh 0 0;
  font-family: var(--fuente-titulo);
  font-size: 7vh;
  letter-spacing: 0.12em;
  text-shadow: 0 0.06em 0 rgba(0, 0, 0, 0.35);
}

.tarjeta-descripcion {
  margin: 2vh auto 3vh;
  max-width: 90%;
  font-size: 4.2vh;
  font-weight: 600;
  line-height: 1.2;
  text-shadow: 0 0.08em 0.15em rgba(0, 0, 0, 0.4);
}

.tarjeta-pista {
  display: inline-block;
  margin: 0;
  padding: 0.5em 1.2em;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.3);
  font-size: 3vh;
  font-weight: 600;
  animation: pulso 1.8s ease-in-out infinite;
}

@keyframes aparecer { from { opacity: 0; } }
@keyframes pop {
  from { transform: scale(0.2) rotate(-8deg); opacity: 0; }
}
@keyframes rebote {
  from { transform: scale(0.3); }
}
@keyframes desinflar {
  0%, 100% { transform: rotate(0deg); }
  50%      { transform: rotate(-2deg) translateY(1vh) scale(0.98); }
}
@keyframes brillar {
  50% { box-shadow: 0 0 0 1vh #fff, 0 0 24vh #ffd23f, 0 4vh 8vh rgba(0, 0, 0, 0.6); }
}
@keyframes girar-lento {
  to { transform: rotate(360deg); }
}

/* ---------- Avisos y confeti ---------- */

.aviso {
  position: fixed;
  left: 2vw;
  bottom: 2vh;
  z-index: 70;
  margin: 0;
  padding: 0.5em 1em;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  font-size: 2.2vh;
  font-weight: 600;
}
.aviso-sonido { animation: pulso 2s ease-in-out infinite; cursor: pointer; }

.confeti {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 60;
  pointer-events: none;
}

/* ---------- Pantallas verticales o angostas ---------- */

@media (max-aspect-ratio: 1/1) {
  :root { --rueda: min(92vw, 58vh); }
  body { overflow-y: auto; }
  .escena {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto;
    height: auto;
    min-height: 100vh;
    padding: 3vh 4vw;
  }
  .rueda-zona { height: auto; padding: 3vh 0; }
  .panel { height: auto; }
  .titulo { order: -1; font-size: 2.4rem; }
  .historial { max-height: 40vh; }
  .historial-numero { width: 5vh; height: 5vh; font-size: 3vh; }

  .pantalla-qr {
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
    align-content: center;
    gap: 4vh;
    padding: 4vh 6vw;
    text-align: center;
  }
  .qr-texto { align-items: center; }
  .qr-titulo { font-size: 6vh; transform-origin: center; }
  .qr-pasos { font-size: 2.4vh; }
  .qr-pasos span { width: 4.5vh; height: 4.5vh; font-size: 2.4vh; }
  .qr { width: 40vh; height: 40vh; width: min(70vw, 40vh); height: min(70vw, 40vh); }

  .tarjeta { width: 92vw; }
  .tarjeta-numero { font-size: 22vh; }
}

@media (prefers-reduced-motion: reduce) {
  .rueda-zona::before,
  .resultado-rayos,
  .qr-tarjeta,
  .foco { animation: none !important; }
}

/* Smart TV (lo activa script.js): sin desenfoques ni animaciones caras */
.liviano .pantalla-qr,
.liviano .resultado {
  -webkit-backdrop-filter: none;
          backdrop-filter: none;
}
.liviano .pantalla-qr { background: rgba(16, 3, 40, 0.94); }
.liviano .rueda-zona::before,
.liviano .qr-tarjeta { animation: none; }
