/* =====================================================================
   Basket Trivial 60" · Mobile-first
   ===================================================================== */
:root {
  /* Colores de categoría (Trivial clásico) */
  --cat-historia: #2a7de1;   /* Azul     */
  --cat-nba:      #f5c400;   /* Amarillo */
  --cat-acb:      #1fa35c;   /* Verde    */
  --cat-reglas:   #e3343d;   /* Rojo     */
  --cat-puntos:   #d6336c;   /* Rojo-rosa (Puntos) */
  --cat-equipos:  #f47b20;   /* Naranja  */

  --bg-1: #0b1730;
  --bg-2: #13254a;
  --linea: rgba(255, 255, 255, .06);
  --tarjeta: #fffaf0;
  --tarjeta-borde: #e8dcc3;
  --tinta: #1b1f2a;
  --tinta-suave: #5d6475;
  --ok: #18a957;
  --ko: #e0313b;
  --dorado: #f5c400;
  --blanco: #ffffff;

  --radio: 22px;
  --sombra: 0 18px 40px rgba(0, 0, 0, .35), 0 2px 0 rgba(255, 255, 255, .6) inset;
  --gutter: 16px;
  --fuente: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --fuente-display: "Bebas Neue", "Arial Narrow", Impact, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--fuente);
  color: var(--blanco);
  background-color: var(--bg-1);
  /* Pista nocturna: degradado + líneas de campo */
  background-image:
    radial-gradient(circle at 50% 120%, transparent 0 34%, var(--linea) 34% 34.6%, transparent 34.6%),
    radial-gradient(ellipse at 50% -10%, #234079 0%, transparent 60%),
    linear-gradient(180deg, var(--bg-2), var(--bg-1));
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button, input, select { font: inherit; }

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

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) var(--gutter) max(16px, env(safe-area-inset-bottom));
}

.pantalla { display: none; }
.pantalla.activa { display: flex; flex-direction: column; animation: entrar .35s ease both; }

@keyframes entrar { from { opacity: 0; transform: translateY(12px); } }

/* ---------- Tarjeta Trivial ---------- */
.tarjeta {
  background: var(--tarjeta);
  color: var(--tinta);
  border-radius: var(--radio);
  border: 1px solid var(--tarjeta-borde);
  box-shadow: var(--sombra);
}

/* ---------- Botones ---------- */
.btn {
  display: block;
  width: 100%;
  min-height: 56px;
  border: 0;
  border-radius: 16px;
  font-weight: 900;
  font-size: 1.1rem;
  letter-spacing: .02em;
  cursor: pointer;
  transition: transform .08s ease, filter .15s ease;
}
.btn:active { transform: scale(.97); }
.btn:focus-visible { outline: 3px solid var(--cat-historia); outline-offset: 3px; }
.btn-principal {
  color: #2b1300;
  background: linear-gradient(180deg, #ff9a3d, var(--cat-equipos));
  box-shadow: 0 6px 0 #b4530c, 0 12px 24px rgba(244, 123, 32, .35);
}
.btn-principal:active { box-shadow: 0 2px 0 #b4530c; transform: translateY(4px); }
.btn-principal[disabled] { filter: grayscale(.6) brightness(.9); cursor: progress; }
.btn-secundario {
  color: var(--tinta);
  background: transparent;
  border: 2px solid var(--tarjeta-borde);
  min-height: 48px;
}

/* ---------- Rueda de quesitos ---------- */
.rueda .quesito { stroke: var(--tarjeta); stroke-width: 2.5; transition: fill-opacity .4s, transform .4s; transform-origin: 60px 60px; }
.rueda .quesito.vacio { fill-opacity: .18; }
.rueda .quesito.lleno { fill-opacity: 1; animation: quesito .5s ease; }
.rueda .borde { fill: none; stroke: var(--tarjeta); stroke-width: 4; }
@keyframes quesito { 50% { transform: scale(1.12); } }

/* =====================================================================
   INICIO
   ===================================================================== */
#pantalla-inicio { gap: 18px; justify-content: center; min-height: calc(100dvh - 28px); }

.inicio-cabecera { text-align: center; }
.logo-rueda { position: relative; width: 120px; height: 120px; margin: 4px auto 8px; }
.logo-rueda .rueda { width: 100%; height: 100%; animation: girar 24s linear infinite; }
.logo-balon { position: absolute; inset: 34px; width: 52px; height: 52px; filter: drop-shadow(0 4px 6px rgba(0,0,0,.4)); }
@keyframes girar { to { transform: rotate(360deg); } }

h1 {
  margin: 0;
  font-family: var(--fuente-display);
  font-weight: 400;
  font-size: clamp(2.8rem, 13vw, 4rem);
  line-height: .95;
  letter-spacing: .03em;
}
h1 span { color: var(--dorado); }
.subtitulo { margin: 6px 0 0; color: #b8c4e0; font-weight: 700; }

.tarjeta-form { padding: 20px; display: flex; flex-direction: column; gap: 8px; }
.tarjeta-form label { font-weight: 800; font-size: .95rem; margin-top: 6px; }
.tarjeta-form input,
.tarjeta-form select {
  width: 100%;
  min-height: 52px;
  padding: 0 14px;
  border-radius: 14px;
  border: 2px solid var(--tarjeta-borde);
  background: #fff;
  color: var(--tinta);
  font-size: 16px; /* evita zoom en iOS */
  font-weight: 700;
}
.tarjeta-form input:focus,
.tarjeta-form select:focus { outline: none; border-color: var(--cat-historia); box-shadow: 0 0 0 3px rgba(42,125,225,.2); }
.tarjeta-form .btn-principal { margin-top: 10px; }
.form-error { min-height: 1.2em; margin: 2px 0 0; color: var(--ko); font-weight: 800; font-size: .9rem; }

.leyenda {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px;
  list-style: none; margin: 0; padding: 0;
}
.leyenda li {
  font-size: .78rem; font-weight: 800;
  padding: 5px 10px 5px 8px;
  border-radius: 999px;
  background: rgba(255,255,255,.08);
  display: flex; align-items: center; gap: 6px;
}
.leyenda li::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--c); }

/* =====================================================================
   JUEGO  (todo cabe en 100dvh: sin scroll)
   ===================================================================== */
#pantalla-juego {
  height: calc(100dvh - max(12px, env(safe-area-inset-top)) - max(16px, env(safe-area-inset-bottom)));
  gap: 10px;
  position: relative;
}

.marcador {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  flex: none;
}
.stat { display: flex; flex-direction: column; align-items: center; }
.stat-num { font-family: var(--fuente-display); font-size: 2.6rem; line-height: 1; }
.stat-label { font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: #b8c4e0; }
.stat-aciertos .stat-num { color: #3ee08a; text-shadow: 0 0 18px rgba(62,224,138,.35); }
.stat-racha .fuego { font-size: 1.4rem; margin-left: 2px; display: inline-block; opacity: .25; transition: opacity .2s, transform .2s; }
.stat-racha.caliente .fuego { opacity: 1; animation: latir .7s ease infinite alternate; }
@keyframes latir { to { transform: scale(1.2) rotate(-6deg); } }

/* Reloj gigante */
.reloj { position: relative; width: clamp(104px, 30vw, 132px); aspect-ratio: 1; }
.reloj svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.reloj circle { fill: none; stroke-width: 8; }
.reloj-fondo { stroke: rgba(255,255,255,.12); fill: rgba(0,0,0,.25) !important; }
.reloj-progreso {
  stroke: var(--dorado);
  stroke-linecap: round;
  stroke-dasharray: 276.46;
  stroke-dashoffset: 0;
  transition: stroke .3s;
}
.reloj-num {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-family: var(--fuente-display);
  font-size: clamp(3.4rem, 16vw, 4.4rem);
  line-height: 1;
  padding-top: .08em;
}
.reloj.urgente .reloj-progreso { stroke: var(--ko); }
.reloj.urgente .reloj-num { color: #ff6b72; animation: pulso 1s ease infinite; }
@keyframes pulso { 0% { transform: scale(1.12); } 100% { transform: scale(1); } }

.puntos-linea {
  flex: none;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 4px;
  font-weight: 800; color: #d7def0;
}
.puntos-linea strong { font-family: var(--fuente-display); font-size: 1.7rem; font-weight: 400; color: var(--blanco); }
.rueda-juego { width: 40px; height: 40px; }

/* Tarjeta de pregunta */
.tarjeta-pregunta {
  flex: 1 1 auto;
  min-height: 0;
  display: flex; flex-direction: column;
  padding: 10px;
  gap: 10px;
  border-top: 8px solid var(--cat, var(--cat-nba));
  transition: border-color .2s;
}
.tarjeta-pregunta.cambio { animation: carta .28s ease; }
@keyframes carta { from { transform: rotateY(-12deg) scale(.97); opacity: .4; } }

.pregunta-imagen {
  position: relative;
  flex: 1 1 140px;
  min-height: 70px;
  max-height: 220px;
  border-radius: 14px;
  overflow: hidden;
  background:
    radial-gradient(circle at 30% 30%, rgba(255,255,255,.35), transparent 60%),
    var(--cat, var(--cat-nba));
}
.pregunta-imagen img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity .25s;
}
.pregunta-imagen img.cargada { opacity: 1; }
.imagen-fallback {
  position: absolute; left: 50%; top: 50%;
  width: 56px; height: 56px; translate: -50% -50%;
  opacity: .9; filter: drop-shadow(0 4px 8px rgba(0,0,0,.3));
}
.pregunta-imagen img.cargada + .imagen-fallback { display: none; }
.pregunta-imagen::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent 55%, rgba(0,0,0,.45));
  pointer-events: none;
}
.chip-categoria {
  position: absolute; left: 10px; bottom: 10px; z-index: 1;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--cat, var(--cat-nba));
  color: var(--chip-tinta, #1b1f2a);
  font-weight: 900; font-size: .78rem; letter-spacing: .08em; text-transform: uppercase;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}

.pregunta-texto {
  flex: none;
  margin: 0;
  padding: 0 4px;
  font-size: clamp(1.05rem, 4.6vw, 1.3rem);
  line-height: 1.25;
  font-weight: 900;
  text-align: center;
  text-wrap: balance;
}

.opciones { flex: none; display: flex; flex-direction: column; gap: 8px; }
.opcion {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  min-height: 58px;
  padding: 8px 14px 8px 8px;
  border-radius: 14px;
  border: 2px solid var(--tarjeta-borde);
  background: #fff;
  color: var(--tinta);
  font-weight: 800;
  font-size: 1.02rem;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--tarjeta-borde);
  transition: transform .08s, background-color .15s, border-color .15s, box-shadow .08s;
  touch-action: manipulation;
}
.opcion:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--tarjeta-borde); }
.opcion:focus-visible { outline: 3px solid var(--cat-historia); outline-offset: 2px; }
.opcion-letra {
  flex: none;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--cat, var(--cat-nba));
  color: var(--chip-tinta, #1b1f2a);
  font-weight: 900;
}
.opcion.correcta { background: var(--ok); border-color: var(--ok); color: #fff; box-shadow: 0 3px 0 #0e7a3d; animation: bien .35s ease; }
.opcion.incorrecta { background: var(--ko); border-color: var(--ko); color: #fff; box-shadow: 0 3px 0 #9d1a22; animation: mal .35s ease; }
.opcion.correcta .opcion-letra,
.opcion.incorrecta .opcion-letra { background: rgba(255,255,255,.25); color: #fff; }
.opciones.bloqueadas .opcion:not(.correcta):not(.incorrecta) { opacity: .55; }
@keyframes bien { 50% { transform: scale(1.03); } }
@keyframes mal { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* Pantalla parpadea brevemente */
#pantalla-juego.flash-ok::before,
#pantalla-juego.flash-ko::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 5;
  animation: flash .45s ease forwards;
}
#pantalla-juego.flash-ok::before { background: radial-gradient(circle, transparent 40%, rgba(24,169,87,.45)); }
#pantalla-juego.flash-ko::before { background: radial-gradient(circle, transparent 40%, rgba(224,49,59,.45)); }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }

.flotante {
  position: absolute; left: 50%; top: 38%;
  translate: -50% 0;
  font-family: var(--fuente-display);
  font-size: 3rem;
  color: #3ee08a;
  text-shadow: 0 3px 0 #0e7a3d, 0 0 20px rgba(0,0,0,.4);
  pointer-events: none;
  opacity: 0;
  z-index: 6;
}
.flotante.ver { animation: subir .8s ease forwards; }
@keyframes subir { 0% { opacity: 0; transform: translateY(10px) scale(.8); } 20% { opacity: 1; transform: none; } 100% { opacity: 0; transform: translateY(-50px); } }

.cuenta-atras {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  background: rgba(11,23,48,.88);
  backdrop-filter: blur(4px);
}
.cuenta-atras[hidden] { display: none; }
.cuenta-atras span {
  font-family: var(--fuente-display);
  font-size: 9rem; color: var(--dorado);
  animation: cuenta .8s ease both;
}
@keyframes cuenta { from { transform: scale(2); opacity: 0; } 60% { transform: scale(1); opacity: 1; } }

/* Pantallas muy bajas (móvil apaisado / SE) */
@media (max-height: 640px) {
  .reloj { width: 92px; }
  .reloj-num { font-size: 3rem; }
  .stat-num { font-size: 2rem; }
  .pregunta-imagen { flex-basis: 80px; max-height: 120px; }
  .opcion { min-height: 50px; }
  .opcion-letra { width: 32px; height: 32px; }
}
@media (max-height: 520px) {
  .pregunta-imagen { display: none; }
}

/* =====================================================================
   FINAL
   ===================================================================== */
#pantalla-final { gap: 14px; padding-bottom: 8px; }

.tarjeta-resultado { padding: 20px 18px 16px; text-align: center; border-top: 8px solid var(--dorado); }
.final-pre { margin: 0; font-weight: 900; color: var(--tinta-suave); }
.final-puntos {
  margin: 0;
  font-family: var(--fuente-display);
  font-weight: 400;
  font-size: 5.2rem;
  line-height: 1;
  color: var(--tinta);
}
.final-puntos small { display: block; font-family: var(--fuente); font-size: .9rem; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; color: var(--tinta-suave); }
.final-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 14px 0 10px; }
.final-stats div { display: flex; flex-direction: column; background: #f3ead6; border-radius: 12px; padding: 8px 2px; }
.final-stats strong { font-family: var(--fuente-display); font-weight: 400; font-size: 1.9rem; line-height: 1.05; }
.final-stats span { font-size: .68rem; font-weight: 800; text-transform: uppercase; color: var(--tinta-suave); }
.final-stats .ok { color: var(--ok); }
.final-stats .ko { color: var(--ko); }
.rueda-final { width: 64px; height: 64px; margin: 4px auto 0; display: block; }
.estado-guardado { margin: 8px 0 0; font-weight: 800; font-size: .92rem; color: var(--tinta-suave); min-height: 1.3em; }
.estado-guardado.ok { color: var(--ok); }
.estado-guardado.ko { color: var(--ko); }

.tarjeta-ranking { padding: 16px 14px; }
.tarjeta-ranking h3 { margin: 0 0 10px; font-family: var(--fuente-display); font-weight: 400; font-size: 1.9rem; letter-spacing: .03em; }
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: #f0e6cf; padding: 4px; border-radius: 12px; margin-bottom: 10px; }
.tab {
  min-height: 42px; border: 0; border-radius: 9px;
  background: transparent; color: var(--tinta-suave);
  font-weight: 900; cursor: pointer;
}
.tab.activa { background: #fff; color: var(--tinta); box-shadow: 0 2px 6px rgba(0,0,0,.1); }
.tab[hidden] { display: none; }

.ranking-lista { list-style: none; margin: 0; padding: 0; counter-reset: pos; }
.ranking-lista li {
  counter-increment: pos;
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 9px 6px;
  border-bottom: 1px dashed var(--tarjeta-borde);
}
.ranking-lista li:last-child { border-bottom: 0; }
.ranking-lista li::before {
  content: counter(pos);
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: #efe5cd; font-weight: 900; font-size: .9rem;
}
.ranking-lista li:nth-child(1)::before { background: #f5c400; }
.ranking-lista li:nth-child(2)::before { background: #cfd6e2; }
.ranking-lista li:nth-child(3)::before { background: #e3a26b; }
.ranking-lista li.yo { background: #fff2c2; border-radius: 10px; }
.rk-nombre { font-weight: 900; line-height: 1.15; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rk-sub { display: block; font-size: .78rem; font-weight: 700; color: var(--tinta-suave); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rk-pts { font-family: var(--fuente-display); font-size: 1.6rem; line-height: 1; text-align: right; }
.rk-pts small { display: block; font-family: var(--fuente); font-size: .68rem; font-weight: 800; color: var(--tinta-suave); }
.rk-info { min-width: 0; }
.ranking-vacio { text-align: center; color: var(--tinta-suave); font-weight: 700; padding: 16px 0; }
.ranking-lista li.ranking-vacio::before { content: none; }
.ranking-lista li.ranking-vacio { display: block; }

.final-botones { display: grid; gap: 10px; }
.final-botones .btn-secundario { color: #fff; border-color: rgba(255,255,255,.25); }

/* =====================================================================
   ESCRITORIO
   ===================================================================== */
@media (min-width: 900px) {
  #app { max-width: 1040px; }
  #pantalla-inicio { max-width: 460px; margin: 0 auto; }
  #pantalla-juego { max-width: 600px; margin: 0 auto; width: 100%; }
  .opcion:hover { border-color: var(--cat, var(--cat-nba)); }
  .btn-principal:hover { filter: brightness(1.06); }
  #pantalla-final.activa {
    display: grid;
    grid-template-columns: 1fr 1.15fr;
    grid-template-rows: auto 1fr;
    align-items: start;
    gap: 18px;
    padding-top: 24px;
  }
  .tarjeta-ranking { grid-row: 1 / span 2; grid-column: 2; }
  .final-botones { grid-column: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
