/* =====================================================================
   Máquina de sorteo · escenario, revelado y celebración
   ===================================================================== */
.stage-section { padding: 10px 0 60px; scroll-margin-top: calc(var(--header-h) + 10px); }
.stage {
  position: relative; overflow: hidden; isolation: isolate;
  border-radius: 28px; border: 1px solid rgba(150,160,255,.22);
  background:
    radial-gradient(70% 55% at 50% 0%, rgba(124,77,255,.35), transparent 70%),
    radial-gradient(50% 40% at 50% 100%, rgba(47,123,255,.3), transparent 70%),
    linear-gradient(180deg, #0b0c25 0%, #070818 60%, #04040d 100%);
  box-shadow: 0 40px 120px rgba(0,0,0,.65), inset 0 1px 0 rgba(255,255,255,.08), 0 0 0 1px rgba(0,0,0,.4);
  display: flex; flex-direction: column;
  min-height: 760px;
}
.stage::before { /* reflectores */
  content: ''; position: absolute; inset: -20% -10% auto; height: 80%; z-index: -1; pointer-events: none;
  background:
    conic-gradient(from 160deg at 20% 0%, transparent 0deg, rgba(0,212,255,.16) 12deg, transparent 26deg),
    conic-gradient(from 175deg at 80% 0%, transparent 0deg, rgba(168,85,247,.18) 12deg, transparent 26deg),
    conic-gradient(from 168deg at 50% -10%, transparent 0deg, rgba(245,197,66,.10) 16deg, transparent 32deg);
  filter: blur(6px); animation: spotSweep 9s ease-in-out infinite alternate;
}
@keyframes spotSweep { from { transform: translateX(-3%) rotate(-2deg); } to { transform: translateX(3%) rotate(2deg); } }
.stage::after { /* suelo reflectante */
  content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 30%; z-index: -1; pointer-events: none;
  background: linear-gradient(180deg, transparent, rgba(47,123,255,.08)),
              repeating-linear-gradient(90deg, rgba(150,160,255,.06) 0 1px, transparent 1px 60px);
  mask-image: linear-gradient(180deg, transparent, #000);
  -webkit-mask-image: linear-gradient(180deg, transparent, #000);
}
.stage-lights { position: absolute; top: 0; left: 0; right: 0; height: 10px; display: flex; justify-content: space-around; z-index: 2; pointer-events: none; }
.stage-lights span { width: 10px; height: 10px; border-radius: 50%; margin-top: 10px; background: #fff3c4;
  box-shadow: 0 0 10px #ffd76a, 0 0 22px rgba(245,197,66,.6); animation: bulb 1.6s ease-in-out infinite; animation-delay: calc(var(--i) * .11s); }
@keyframes bulb { 0%,100% { opacity: .35; transform: scale(.8); } 50% { opacity: 1; transform: scale(1.1); } }
.stage.is-mixing .stage-lights span { animation-duration: .5s; }
.stage.final-mode .stage-lights span { animation-duration: .28s; background: #fff; box-shadow: 0 0 14px #ffd76a, 0 0 34px rgba(245,197,66,.9); }

.stage-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 30px 26px 0; flex-wrap: wrap; position: relative; z-index: 3; }
.stage-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.stage-title strong { font-family: var(--display); font-weight: 400; font-size: 1.7rem; letter-spacing: .05em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live-pill { display: inline-flex; align-items: center; gap: 7px; padding: .3em .8em; border-radius: 999px; font-size: .72rem; font-weight: 800; letter-spacing: .16em;
  background: rgba(255,59,92,.2); color: #ffb3c1; border: 1px solid rgba(255,59,92,.5); }

.attempt-tracker { list-style: none; margin: 0; padding: 0; display: flex; gap: 8px; align-items: center; }
.attempt-tracker li { display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border-radius: 999px; background: rgba(255,255,255,.05); border: 1px solid var(--border); transition: all .4s; }
.attempt-tracker li span { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: .86rem; background: rgba(255,255,255,.08); color: var(--muted); transition: all .4s; }
.attempt-tracker li small { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; font-weight: 700; }
.attempt-tracker li.current { border-color: rgba(0,212,255,.6); box-shadow: 0 0 20px rgba(0,212,255,.3); }
.attempt-tracker li.current span { background: linear-gradient(135deg, var(--cyan), var(--blue)); color: #fff; }
.attempt-tracker li.done span { background: rgba(150,160,255,.3); color: #fff; }
.attempt-tracker li.official.current, .attempt-tracker li.official.done { border-color: rgba(245,197,66,.7); box-shadow: 0 0 24px rgba(245,197,66,.35); }
.attempt-tracker li.official.current span, .attempt-tracker li.official.done span { background: linear-gradient(180deg, #fff3c4, var(--gold), #c98a12); color: #2a1700; }
.stage-tools { display: flex; gap: 8px; }
.tool-btn { width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--border-strong); background: rgba(255,255,255,.06); color: #fff; font-size: 1.1rem; cursor: pointer; transition: all .2s; }
.tool-btn:hover { border-color: var(--cyan); box-shadow: var(--glow-blue); }

.machine-wrap { position: relative; flex: 1; min-height: 540px; margin: 8px 0 0; }
#machineCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: pan-y; }
.machine-caption { position: absolute; left: 50%; bottom: 4px; transform: translateX(-50%); max-width: calc(100% - 24px); font-size: .78rem; color: #c3c8ff; letter-spacing: .04em; text-align: center; pointer-events: none;
  padding: 3px 12px; border-radius: 999px; background: rgba(5,6,20,.6); border: 1px solid rgba(150,160,255,.14); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.machine-caption:empty { display: none; }

.stage-controls { position: relative; z-index: 3; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 10px 20px 30px; text-align: center; }
.stage-note { color: var(--muted); font-size: .9rem; margin: 0; max-width: 620px; }
.stage-alert { max-width: 620px; margin: 0; font-size: .9rem; text-align: left; }
.stage-alert a { color: var(--gold, #f5c542); font-weight: 600; }
.viewer-note { display: inline-flex; align-items: center; gap: 10px; padding: 10px 18px; border-radius: 999px; background: rgba(255,255,255,.05); border: 1px solid var(--border); }
.btn-start {
  font-family: var(--display); font-weight: 400; font-size: clamp(1.7rem, 4vw, 2.4rem); letter-spacing: .08em;
  padding: .45em 1.6em .38em; border-radius: 999px; color: #2a1700;
  background: linear-gradient(180deg, #fff6d6 0%, #ffd76a 30%, #f5b82e 65%, #c98a12 100%);
  box-shadow: 0 14px 40px rgba(245,197,66,.45), inset 0 -4px 0 rgba(0,0,0,.18), inset 0 2px 0 rgba(255,255,255,.7), 0 0 0 6px rgba(245,197,66,.12);
  animation: pulseGlow 2.2s ease-in-out infinite;
}
.btn-start:hover { color: #2a1700; transform: translateY(-3px) scale(1.02); }
.btn-start.is-busy { pointer-events: none; opacity: .6; animation: none; }

/* Destello */
.stage-flash { position: absolute; inset: 0; z-index: 8; pointer-events: none; background: radial-gradient(circle at 50% 45%, rgba(255,255,255,.85), rgba(255,215,106,.4) 30%, transparent 65%); opacity: 0; }
.stage-flash.go { animation: flash 1s ease-out; }
@keyframes flash { 0% { opacity: 0; } 12% { opacity: 1; } 100% { opacity: 0; } }

/* ---------------------------------------------------------------------
   Capa de revelado
   --------------------------------------------------------------------- */
.reveal-layer { position: absolute; inset: 0; z-index: 10; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; padding: 30px 20px;
  background: radial-gradient(circle at 50% 42%, rgba(20,22,60,.55), rgba(3,3,10,.88) 70%); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  animation: layerIn .5s ease both; overflow-x: hidden; overflow-y: auto; }
@keyframes layerIn { from { opacity: 0; } to { opacity: 1; } }
.reveal-layer.leaving { animation: layerOut .4s ease forwards; }
@keyframes layerOut { to { opacity: 0; transform: scale(1.03); } }

.big-ball {
  --h: 220; --size: min(300px, 62vw, 44vh);
  width: var(--size); height: var(--size); border-radius: 50%; flex: none; position: relative; display: grid; place-items: center;
  background: radial-gradient(circle at 33% 28%, #fff 0 5%, hsl(var(--h) 95% 72%) 16%, hsl(var(--h) 88% 50%) 50%, hsl(var(--h) 90% 16%) 100%);
  box-shadow: inset calc(var(--size) * -.06) calc(var(--size) * -.09) calc(var(--size) * .16) rgba(0,0,0,.5),
              inset calc(var(--size) * .03) calc(var(--size) * .03) calc(var(--size) * .08) rgba(255,255,255,.3),
              0 calc(var(--size) * .12) calc(var(--size) * .2) rgba(0,0,0,.55), 0 0 80px hsl(var(--h) 90% 55% / .45);
  animation: ballPop .9s cubic-bezier(.2,1.4,.4,1) both;
}
.big-ball::after { content: ''; position: absolute; width: 34%; height: 18%; left: 16%; top: 11%; border-radius: 50%; transform: rotate(-30deg);
  background: radial-gradient(ellipse, rgba(255,255,255,.85), transparent 70%); }
.big-ball .label { width: 68%; height: 68%; border-radius: 50%; display: grid; place-items: center; padding: 8%; text-align: center;
  background: radial-gradient(circle at 42% 35%, #ffffff, #eceeff 70%, #cfd3f5); box-shadow: inset 0 -6px 14px rgba(0,0,0,.15), 0 2px 6px rgba(0,0,0,.25);
  color: #17123a; font-weight: 900; line-height: 1.05; overflow-wrap: anywhere; font-size: calc(var(--size) * .1); }
@keyframes ballPop { 0% { transform: scale(.15) translateY(-120px); opacity: 0; } 60% { opacity: 1; } 100% { transform: none; opacity: 1; } }
.big-ball.spin-in { animation: ballPop .9s cubic-bezier(.2,1.4,.4,1) both, ballWobble 3.5s ease-in-out .9s infinite; }
@keyframes ballWobble { 0%,100% { transform: rotate(0) translateY(0); } 50% { transform: rotate(4deg) translateY(-8px); } }

.reveal-card { text-align: center; max-width: 640px; animation: cardUp .6s cubic-bezier(.2,.8,.2,1) .45s both; }
@keyframes cardUp { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: none; } }
.attempt-badge { display: inline-flex; align-items: center; gap: 8px; padding: .35em .9em; border-radius: 999px; font-size: .74rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase;
  background: rgba(150,160,255,.14); color: #cfd3ff; border: 1px solid rgba(150,160,255,.3); margin-bottom: 14px; }
.attempt-badge.official { background: rgba(245,197,66,.18); color: var(--gold-2); border-color: rgba(245,197,66,.5); }
.reveal-name { font-size: clamp(1.3rem, 3.2vw, 1.8rem); font-weight: 800; margin: 0 0 6px; color: #fff; }
.reveal-title { font-family: var(--display); font-weight: 400; font-size: clamp(2.2rem, 6vw, 3.6rem); letter-spacing: .04em; margin: 0 0 8px; line-height: 1.05;
  color: #fff; text-shadow: 0 0 24px rgba(124,77,255,.7), 0 4px 0 rgba(30,20,90,.9); animation: titleShake .6s ease .7s both; }
@keyframes titleShake { 0% { transform: scale(.6); opacity: 0; } 60% { transform: scale(1.08); opacity: 1; } 80% { transform: scale(.97) rotate(-1deg); } 100% { transform: none; } }
.reveal-text { color: #c8cbf0; font-size: 1.08rem; margin-bottom: 22px; }
.reveal-note { color: var(--muted); font-size: .82rem; margin: 14px 0 0; }
.reveal-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ---------------------------------------------------------------------
   Ganador
   --------------------------------------------------------------------- */
.reveal-layer.is-winner { background: radial-gradient(circle at 50% 40%, rgba(120,70,0,.55), rgba(20,10,40,.9) 55%, rgba(3,3,10,.96) 80%); justify-content: flex-start; padding: 34px 20px 40px; gap: 18px; }
/* Con ganador (y en móviles con cualquier resultado) la capa pasa al flujo
   normal: el escenario crece con el contenido y nunca aparecen barras de desplazamiento. */
.stage.has-winner .machine-wrap, .stage.has-winner .stage-controls { display: none; }
.stage.has-winner .reveal-layer { position: relative; inset: auto; flex: 1; min-height: 700px; overflow: visible; }
.winner-fx { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: -1; border-radius: inherit; }
.winner-rays { position: absolute; left: 50%; top: 36%; width: 180vmax; height: 180vmax; transform: translate(-50%, -50%); z-index: -1; pointer-events: none;
  background: repeating-conic-gradient(from 0deg, rgba(255,215,106,.16) 0deg 6deg, transparent 6deg 18deg);
  mask-image: radial-gradient(circle, #000 0%, transparent 45%); -webkit-mask-image: radial-gradient(circle, #000 0%, transparent 45%);
  animation: raysSpin 22s linear infinite; }
@keyframes raysSpin { to { transform: translate(-50%, -50%) rotate(360deg); } }
.winner-heading { font-family: var(--display); font-weight: 400; text-align: center; margin: 0; line-height: 1; letter-spacing: .04em;
  font-size: clamp(2.2rem, 6.4vw, 4.6rem); color: #fff3c4; text-shadow: 0 0 30px rgba(245,197,66,.8), 0 6px 0 #8a4b00, 0 12px 30px rgba(0,0,0,.6);
  animation: titleShake .8s ease .2s both; }
.winner-sub { font-size: clamp(.9rem, 2vw, 1.15rem); font-weight: 800; letter-spacing: .4em; color: var(--gold-2); margin: 0; animation: cardUp .6s ease 1s both; }
.big-ball.winner { --size: min(40vh, 70vw, 380px); --h: 44;
  background: radial-gradient(circle at 33% 28%, #fff 0 5%, #fff1b8 14%, #ffd25e 32%, #f2a90f 58%, #8a4b00 100%);
  box-shadow: inset calc(var(--size) * -.06) calc(var(--size) * -.09) calc(var(--size) * .16) rgba(80,30,0,.55), 0 0 0 10px rgba(255,215,106,.12), 0 0 120px rgba(255,200,60,.8), 0 0 260px rgba(255,170,0,.45);
  animation: winnerGrow 2.2s cubic-bezier(.2,.9,.25,1) both, winnerFloat 4s ease-in-out 2.2s infinite; }
.big-ball.winner .label { font-size: calc(var(--size) * .085); }
@keyframes winnerGrow { 0% { transform: scale(.08); filter: brightness(2); } 55% { transform: scale(1.08); } 75% { transform: scale(.97); } 100% { transform: scale(1); filter: none; } }
@keyframes winnerFloat { 0%,100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-10px) rotate(2deg); } }
.winner-name { font-family: var(--display); font-weight: 400; text-align: center; line-height: .95; margin: 0; letter-spacing: .03em;
  font-size: clamp(2.6rem, 8vw, 6.2rem); max-width: 100%; overflow-wrap: anywhere; }
.winner-name .word { display: inline-block; white-space: nowrap; }
.winner-name .ch { display: inline-block; opacity: 0; transform: translateY(40px) scale(.5) rotate(-10deg);
  background: linear-gradient(180deg, #ffffff 0%, #fff1b8 35%, #ffc93c 65%, #c27c0e 100%); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 0 rgba(90,40,0,.9)) drop-shadow(0 0 22px rgba(255,200,60,.6));
  animation: chIn .6s cubic-bezier(.2,1.5,.4,1) forwards; animation-delay: calc(1.6s + var(--i) * .05s); }
@keyframes chIn { to { opacity: 1; transform: none; } }
.winner-details { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; animation: cardUp .7s ease 2.4s both; }
.winner-details div { padding: 12px 18px; border-radius: 14px; background: rgba(0,0,0,.35); border: 1px solid rgba(245,197,66,.35); text-align: center; min-width: 160px; }
.winner-details small { display: block; color: var(--gold-2); font-size: .7rem; letter-spacing: .16em; text-transform: uppercase; font-weight: 700; }
.winner-details strong { font-size: 1.05rem; }
.winner-official { color: #ffe6a0; font-size: .86rem; text-align: center; margin: 0; animation: cardUp .7s ease 2.6s both; }
.reveal-layer.is-winner .reveal-actions { animation: cardUp .7s ease 2.8s both; }
.sparkle { position: absolute; width: 6px; height: 6px; border-radius: 50%; background: #fff; pointer-events: none; z-index: 1;
  box-shadow: 0 0 10px #fff, 0 0 20px #ffd76a; animation: sparkle 1.8s ease-in-out infinite; }
@keyframes sparkle { 0%,100% { transform: scale(0); opacity: 0; } 50% { transform: scale(1.6); opacity: 1; } }

.confetti-canvas { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 12; pointer-events: none; }

/* Transparencia */
.transparency { margin-top: 24px; padding: 22px 24px; }
.transparency h3 { font-size: 1.05rem; margin-bottom: 14px; }
.transparency dl { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin: 0 0 14px; }
.transparency dl div { padding: 12px 14px; border-radius: 12px; background: rgba(0,0,0,.25); border: 1px solid var(--border); }
.transparency dl .wide { grid-column: 1 / -1; }
.transparency dt { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .12em; }
.transparency dd { margin: 4px 0 0; font-weight: 600; word-break: break-all; }
.annulled-box { margin-top: 18px; padding: 18px 22px; border-color: rgba(255,77,109,.35); }
.annulled-box h3 { font-size: 1rem; color: #ffb3c1; }
.annulled-box p { font-size: .9rem; color: #c8cbf0; margin: 0 0 6px; }
.winner-static { margin-top: 20px; padding: 28px; text-align: center; }
.winner-static .big-name { font-family: var(--display); font-size: 3rem; color: var(--gold-2); margin: 0; }

/* Pantalla completa */
.stage:fullscreen { border-radius: 0; width: 100vw; height: 100vh; min-height: 0; }
.stage:-webkit-full-screen { border-radius: 0; width: 100vw; height: 100vh; }
.stage.pseudo-fullscreen { position: fixed; inset: 0; z-index: 400; border-radius: 0; min-height: 0; height: 100%; }
body.has-pseudo-fullscreen { overflow: hidden; }

@media (max-width: 820px) {
  .stage { min-height: 560px; border-radius: 22px; }
  .stage.has-reveal .machine-wrap, .stage.has-reveal .stage-controls { display: none; }
  .stage.has-reveal .reveal-layer { position: relative; inset: auto; flex: 1; min-height: 480px; overflow: visible; padding: 26px 16px 34px; }
  .stage.has-winner .reveal-layer { min-height: 600px; }
  .stage-top { padding: 26px 16px 0; justify-content: center; text-align: center; }
  .stage-title { width: 100%; justify-content: center; }
  .stage-title strong { font-size: 1.4rem; }
  .attempt-tracker li small { display: none; }
  .attempt-tracker li { padding: 4px; }
  .machine-wrap { min-height: 400px; }
  .stage-tools { position: absolute; top: 22px; right: 12px; }
  .stage-tools .tool-btn { width: 36px; height: 36px; font-size: .95rem; }
  .stage-title { padding: 0 80px; }
}
@media (max-width: 480px) {
  .stage-title { padding: 0 70px 0 0; justify-content: flex-start; }
  .winner-details div { min-width: 0; flex: 1 1 40%; }
  .reveal-layer.is-winner { padding-top: 24px; gap: 14px; }
}
