:root {
  --brand-primary: #32327D;
  --brand-primary-dark: #1B1B4D;
  --brand-secondary: #9DC33B;
  --brand-secondary-light: #EEF6DD;
  --surface: #ffffff;
  --text: #1a1a2e;
  --papel: #f5f6f8;
  --sombra: 0 16px 40px rgba(50, 50, 125, 0.1);
  --radio: 20px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

:focus-visible {
  outline: 3px solid var(--brand-secondary);
  outline-offset: 3px;
}

[hidden] { display: none !important; }

/* ——— Formulario público ——— */

.pagina-publica {
  color: var(--text);
  background:
    radial-gradient(900px 420px at 50% -80px, var(--brand-secondary-light) 0%, rgba(238, 246, 221, 0) 70%),
    var(--papel);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
}

.tarjeta {
  width: min(100%, 440px);
  background: var(--surface);
  border: 1px solid rgba(50, 50, 125, 0.06);
  border-top: 4px solid var(--brand-secondary);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  padding: 28px 18px 24px;
}

.marca-logo {
  display: block;
  margin: 0 auto 20px;
  text-align: center;
}

.marca-logo img,
.logo-institucional {
  display: block;
  width: 100%;
  max-width: 240px;
  height: auto;
  margin: 0 auto;
  object-fit: contain;
}

.pagina-publica h1 {
  margin: 0 0 8px;
  color: var(--brand-primary);
  font-size: 1.65rem;
  line-height: 1.15;
  letter-spacing: -0.02em;
  text-align: center;
}

.intro {
  margin: 0 0 18px;
  color: #5a5a72;
  text-align: center;
}

.campo { margin-bottom: 14px; }

label {
  display: block;
  margin-bottom: 6px;
  font-weight: 700;
  color: var(--brand-primary-dark);
}

input[type="text"],
input[type="tel"] {
  width: 100%;
  min-height: 54px;
  border: 1.5px solid #d8dae6;
  border-radius: 14px;
  padding: 12px 14px;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: #fafafc;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

input[type="text"]:focus,
input[type="tel"]:focus {
  outline: 3px solid rgba(157, 195, 59, 0.45);
  border-color: var(--brand-secondary);
  background: white;
}

::placeholder { color: #9a9ab0; }

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 56px;
  margin: 0;
  padding: 14px 18px;
  border: 0;
  border-radius: 14px;
  font: inherit;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.2s ease, filter 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
}

.btn-principal {
  margin-top: 6px;
  background: var(--brand-primary);
  color: #ffffff;
}

.btn-principal:hover {
  background: var(--brand-primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(50, 50, 125, 0.28);
}

.btn:disabled {
  opacity: 0.7;
  cursor: wait;
  transform: none;
  box-shadow: none;
}

.alerta {
  margin-bottom: 16px;
  padding: 14px;
  border-radius: 14px;
}

.alerta strong { display: block; margin-bottom: 2px; }

.alerta p { margin: 0; }

.alerta-exito {
  background: var(--brand-secondary-light);
  color: var(--brand-primary-dark);
  border-left: 4px solid var(--brand-secondary);
}

.alerta-error {
  background: #fdeeee;
  color: #8d2222;
  border-left: 4px solid #9d2c2c;
}

/* ——— Pantalla de rifas ——— */

.pagina-sorteo {
  color: var(--text);
  background:
    radial-gradient(300px 240px at -30px 70px, rgba(157, 195, 59, 0.55), transparent 70%),
    radial-gradient(520px 340px at -80px 40px, rgba(200, 224, 137, 0.35), transparent 72%),
    radial-gradient(360px 220px at calc(100% + 30px) -30px, rgba(70, 70, 160, 0.85), transparent 68%),
    radial-gradient(640px 360px at calc(100% + 100px) -40px, rgba(90, 90, 181, 0.28), transparent 72%),
    #f6f7fb;
  padding: max(20px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
}

.pagina-sorteo svg:not(.regalo) {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.contenedor-sorteo {
  width: min(100%, 900px);
  margin: 0 auto;
}

.cabecera-sorteo {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-bottom: 22px;
  text-align: center;
}

.logo-rifas {
  display: block;
  width: 100%;
  max-width: 230px;
  height: auto;
  object-fit: contain;
}

.pagina-sorteo h1 {
  display: flex;
  align-items: center;
  gap: 18px;
  width: min(100%, 340px);
  margin: 4px 0 0;
  color: var(--brand-primary);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.32em;
  text-transform: uppercase;
}

.pagina-sorteo h1::before,
.pagina-sorteo h1::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(50, 50, 125, 0.35);
}

.fecha-evento {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 0;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 4px 14px rgba(50, 50, 125, 0.08);
  color: #4a4a68;
  font-size: 0.85rem;
}

.fecha-evento svg {
  width: 16px;
  height: 16px;
  color: var(--brand-primary);
}

.stat,
.hero-sorteo,
.controles-admin,
.ultimo-ganador {
  background: var(--surface);
  border: 1px solid rgba(50, 50, 125, 0.06);
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(50, 50, 125, 0.07);
}

.estadisticas {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-bottom: 16px;
}

.stat {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 34px rgba(50, 50, 125, 0.1);
}

.stat-icono {
  display: inline-grid;
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  place-items: center;
  border-radius: 50%;
}

.stat-icono svg {
  width: 26px;
  height: 26px;
}

.stat-icono-azul {
  background: #ececf8;
  color: var(--brand-primary);
}

.stat-icono-verde {
  background: var(--brand-secondary-light);
  color: #5f8f22;
}

.stat strong {
  display: block;
  color: var(--brand-primary);
  font-size: clamp(2rem, 6vw, 2.4rem);
  font-weight: 800;
  line-height: 1;
}

.stat div span {
  display: block;
  margin-top: 4px;
  color: #4a4a68;
}

/* Tarjeta principal del sorteo */

.hero-sorteo {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  justify-items: center;
  margin-bottom: 16px;
  padding: 24px 20px;
  text-align: center;
  transition: box-shadow 0.3s ease, border-color 0.3s ease;
}

.hero-sorteo:has(.celebrando) {
  border-color: var(--brand-secondary);
  box-shadow:
    0 0 0 3px rgba(157, 195, 59, 0.35),
    0 18px 50px rgba(157, 195, 59, 0.28);
}

.ilustracion .regalo {
  display: block;
  width: 170px;
  height: auto;
}

.hero-sorteo:has(.sorteando) .regalo { animation: sacudir 0.35s ease-in-out infinite; }

.hero-sorteo:has(.celebrando) .regalo { animation: saltar 0.6s ease 2; }

.escenario {
  min-width: 0;
  max-width: 100%;
}

#etiqueta-ganador {
  display: inline-block;
  margin: 0 0 12px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--brand-secondary-light);
  color: #46661a;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

#etiqueta-ganador:empty { display: none; }

#nombre-ganador {
  margin: 0;
  color: var(--brand-primary);
  font-size: clamp(1.55rem, 5.5vw, 2.1rem);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.01em;
  overflow-wrap: break-word;
}

#cedula-ganador {
  margin: 10px 0 0;
  color: #5a5a72;
}

#cedula-ganador:empty { display: none; }

.sorteando #etiqueta-ganador {
  background: #ececf8;
  color: var(--brand-primary);
}

.sorteando #nombre-ganador { animation: pulso 0.12s linear infinite; }

.celebrando #etiqueta-ganador {
  background: var(--brand-secondary);
  color: var(--brand-primary-dark);
  font-size: 0.9rem;
}

.celebrando #nombre-ganador {
  font-size: clamp(1.9rem, 6.5vw, 2.8rem);
  animation: aparecer 0.45s ease;
}

.celebrando #cedula-ganador {
  color: var(--brand-primary);
  font-weight: 700;
  letter-spacing: 0.06em;
}

.zona-boton {
  width: 100%;
}

.btn-rifar {
  position: relative;
  gap: 14px;
  min-height: 72px;
  padding: 14px 64px;
  border-radius: 999px;
  background: linear-gradient(135deg, #95c13a 0%, #6f9f28 55%, #5e8f22 100%);
  color: #ffffff;
  font-size: 1.3rem;
  letter-spacing: 0.12em;
  text-shadow: 0 1px 2px rgba(40, 60, 10, 0.35);
  box-shadow: 0 12px 28px rgba(111, 159, 40, 0.38);
}

.btn-rifar::before,
.btn-rifar::after {
  content: "";
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}

.btn-rifar::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3.5' y='8' width='17' height='4' rx='1'/%3E%3Cpath d='M5 12v8h14v-8M12 8v12M12 8c-1.5-3.5-5.5-3.5-5.5-1S10 8 12 8zm0 0c1.5-3.5 5.5-3.5 5.5-1S14 8 12 8z'/%3E%3C/svg%3E");
}

.btn-rifar::after {
  position: absolute;
  right: 26px;
  top: 50%;
  width: 22px;
  height: 22px;
  margin-top: -11px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12h14M13 6l6 6-6 6'/%3E%3C/svg%3E");
  transition: transform 0.2s ease;
}

.btn-rifar:hover {
  transform: translateY(-2px);
  filter: brightness(1.05);
  box-shadow: 0 16px 34px rgba(111, 159, 40, 0.45);
}

.btn-rifar:hover::after { transform: translateX(4px); }

.btn-rifar:disabled::after { display: none; }

@keyframes pulso {
  50% { opacity: 0.42; }
}

@keyframes aparecer {
  from { transform: scale(0.9); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@keyframes sacudir {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-4deg); }
  75% { transform: rotate(4deg); }
}

@keyframes saltar {
  0%, 100% { transform: translateY(0); }
  40% { transform: translateY(-12px) scale(1.04); }
}

/* Controles administrativos — separados del sorteo */

.controles-admin {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  margin-bottom: 16px;
  padding: 20px;
}

.interruptor {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin: 0;
  color: var(--text);
  cursor: pointer;
}

.interruptor input {
  position: relative;
  flex: 0 0 auto;
  width: 52px;
  height: 30px;
  margin: 0;
  border-radius: 999px;
  background: #c9cbd6;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.15);
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  transition: background 0.2s ease;
}

.interruptor input::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.22);
  transition: transform 0.2s ease;
}

.interruptor input:checked { background: #6f9f28; }

.interruptor input:checked::before { transform: translateX(22px); }

.interruptor input:disabled { opacity: 0.6; cursor: wait; }

.interruptor-texto strong {
  display: block;
  color: var(--brand-primary-dark);
}

.interruptor-texto small {
  display: block;
  margin-top: 4px;
  color: #5a5a72;
  font-size: 0.85rem;
  font-weight: 400;
  line-height: 1.4;
}

.acciones-admin {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.acciones-admin .btn {
  gap: 10px;
  min-height: 52px;
  font-size: 0.85rem;
}

.acciones-admin .btn svg {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
}

.btn-secundario {
  background: #ffffff;
  color: var(--brand-primary);
  border: 1.5px solid var(--brand-primary);
}

.btn-secundario:hover {
  background: #f0f0fa;
  transform: translateY(-1px);
}

.borrar { position: relative; }

.borrar summary {
  list-style: none;
}

.borrar summary::-webkit-details-marker { display: none; }

.btn-peligro-suave {
  background: #fdecec;
  color: #b42318;
  border: 1.5px solid #f2b8b5;
}

.btn-peligro-suave:hover,
.borrar[open] .btn-peligro-suave {
  background: #fbdcdc;
  border-color: #e58e89;
}

.zona-peligro {
  margin-top: 10px;
  padding: 16px;
  border: 1px solid #f2b8b5;
  border-radius: 16px;
  background: #fff7f7;
  box-shadow: 0 14px 34px rgba(120, 20, 20, 0.12);
}

.zona-peligro h2 {
  margin: 0 0 6px;
  color: #8d1c1c;
  font-size: 1rem;
}

.zona-peligro p {
  margin: 0 0 12px;
  color: #6b3434;
  font-size: 0.92rem;
}

.check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 0 0 8px;
  font-weight: 700;
  cursor: pointer;
}

.check input {
  width: 1.25rem;
  height: 1.25rem;
  margin-top: 2px;
  flex: 0 0 auto;
  accent-color: #b42318;
}

.check-peligro { color: #7a1f1f; font-size: 0.92rem; }

.btn-peligro {
  margin-top: 6px;
  background: #b42318;
  color: #ffffff;
}

.btn-peligro:hover { background: #912018; }

/* Último ganador */

.ultimo-ganador {
  padding: 18px 20px 20px;
}

.ultimo-ganador h2 {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 14px;
  color: var(--brand-primary-dark);
  font-size: 1.1rem;
}

.ultimo-ganador h2 .stat-icono {
  width: 40px;
  height: 40px;
}

.ultimo-ganador h2 .stat-icono svg {
  width: 22px;
  height: 22px;
}

.ultimo-ganador-caja {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 22px 16px;
  border: 1.5px dashed #d6d8e4;
  border-radius: 14px;
  background: #f8f9fc;
  color: #7a7a92;
  font-size: 0.9rem;
  text-align: center;
}

.ultimo-ganador-caja.con-ganador {
  border: 1.5px solid rgba(157, 195, 59, 0.7);
  background: var(--brand-secondary-light);
  animation: aparecer 0.45s ease;
}

.ultimo-ganador-caja.con-ganador strong {
  color: var(--brand-primary);
  font-size: 1.3rem;
  overflow-wrap: anywhere;
}

.ultimo-ganador-caja.con-ganador span {
  color: #46661a;
  font-weight: 700;
  letter-spacing: 0.05em;
}

#aviso-sorteo { margin-bottom: 16px; }

.confeti-capa {
  position: fixed;
  inset: 0;
  z-index: 30;
  overflow: hidden;
  pointer-events: none;
}

.confeti {
  position: absolute;
  top: -16px;
  width: 10px;
  height: 16px;
  border-radius: 2px;
  animation-name: caer;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
}

@keyframes caer {
  to { transform: translateY(105vh) rotate(420deg); opacity: 0.15; }
}

.oculto-visual {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (min-width: 520px) {
  .estadisticas { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 640px) {
  .tarjeta { padding: 36px 32px 32px; }
  .marca-logo img,
  .logo-institucional { max-width: 260px; }
  .logo-rifas { max-width: 260px; }
}

@media (min-width: 820px) {
  .pagina-sorteo { padding-top: 28px; }

  .fecha-evento {
    position: absolute;
    top: 64px;
    right: 0;
    margin: 0;
  }

  .hero-sorteo {
    grid-template-columns: auto 1fr auto;
    align-items: center;
    justify-items: stretch;
    gap: 28px;
    padding: 26px 30px;
    text-align: left;
  }

  .ilustracion {
    padding-right: 28px;
    border-right: 1px solid rgba(50, 50, 125, 0.1);
  }

  .ilustracion .regalo { width: 190px; }

  .zona-boton { width: 250px; }

  .controles-admin {
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 24px;
  }

  .acciones-admin {
    grid-template-columns: auto auto;
    padding-left: 24px;
    border-left: 1px solid rgba(50, 50, 125, 0.1);
  }

  .acciones-admin .btn {
    width: auto;
    min-width: 190px;
  }

  .borrar[open] .zona-peligro {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    z-index: 20;
    width: 340px;
    margin-top: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sorteando #nombre-ganador,
  .celebrando #nombre-ganador,
  .regalo,
  .ultimo-ganador-caja,
  .confeti { animation: none !important; }

  .btn,
  .stat,
  input[type="text"],
  input[type="tel"] {
    transition: none;
  }

  .btn-principal:hover,
  .btn-rifar:hover,
  .stat:hover {
    transform: none;
  }
}
