/*
 * Pasapalabra para tótem. CSS escrito a mano y compatible con el Chrome 98 del tótem:
 * nada de @layer, color-mix, oklch, anidamiento ni media queries de rango.
 *
 * Los colores son variables («tokens»). Cada marca redefine las suyas en un bloque
 * html[data-marca="…"] (ver al final de la sección de marcas). La marca se elige en js/config.js.
 */

@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('../fuentes/outfit-latin.woff2') format('woff2');
}

@font-face {
  font-family: 'Ubuntu';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fuentes/ubuntu-400-latin.woff2') format('woff2');
}

@font-face {
  font-family: 'Ubuntu';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../fuentes/ubuntu-500-latin.woff2') format('woff2');
}

@font-face {
  font-family: 'Ubuntu';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fuentes/ubuntu-700-latin.woff2') format('woff2');
}

/* ---------- Escala (igual para todas las marcas) ---------- */

:root {
  /*
   * Escala pensada para un tótem vertical 9:16: --u es el 1 % del ancho del tótem.
   * En una pantalla apaisada manda el alto, así nada se sale.
   */
  --u: min(1vw, 0.5625vh);
  /*
   * Margen de seguridad a los lados: el marco del tótem (o el recorte de la pantalla)
   * puede comerse los bordes. Cabecera, rosco y panel lo respetan.
   */
  --margen: calc(7 * var(--u));

  --texto-xs: calc(2 * var(--u));
  --texto-sm: calc(2.6 * var(--u));
  --texto-md: calc(3.4 * var(--u));
  --texto-lg: calc(4.2 * var(--u));
  --texto-xl: calc(6.5 * var(--u));
  --texto-2xl: calc(11 * var(--u));
}

/* ---------- Marcas ---------- */

/* Konery (por defecto): noche, cian y azul. */
:root {
  --fuente: 'Outfit', system-ui, sans-serif;
  --fondo: #080914;
  --texto: #ffffff;
  --titulo: #4ceeeb;
  --titulo-sombra: 0 2px 6px rgba(0, 0, 0, 0.4);
  --destacado: #4ceeeb;            /* pista de la letra, números grandes */

  --brillo-1: rgba(65, 86, 222, 0.55);
  --brillo-2: rgba(76, 238, 235, 0.26);
  --brillo-3: rgba(27, 20, 117, 0.85);
  --velo-arriba: rgba(8, 9, 20, 0.7);
  --velo-medio: rgba(8, 9, 20, 0);
  --velo-abajo: rgba(8, 9, 20, 0.95);

  --boton: #4ceeeb;
  --boton-texto: #080914;
  --boton-sombra: 0 6px 20px rgba(76, 238, 235, 0.25);
  --boton-2: #4156de;              /* «Pasapalabra» */
  --boton-2-texto: #ffffff;

  --tarjeta: rgba(18, 20, 44, 0.9);
  --tarjeta-borde: transparent;
  --tarjeta-sombra: 0 25px 50px rgba(0, 0, 0, 0.5);
  --opcion: rgba(8, 9, 20, 0.6);
  --opcion-borde: rgba(255, 255, 255, 0.7);
  --opcion-texto: #ffffff;

  --pastilla: rgba(8, 9, 20, 0.8);
  --pastilla-borde: rgba(255, 255, 255, 0.12);
  --pastilla-texto: #ffffff;
  --pastilla-destacada: #4ceeeb;
  --pastilla-destacada-texto: #080914;

  --letra: #4156de;
  --letra-borde: #ffffff;
  --letra-texto: #ffffff;
  --letra-pasada: #2b3fb8;
  --letra-pasada-borde: #4ceeeb;
  --letra-actual: #4ceeeb;
  --letra-actual-texto: #080914;
  --letra-ola: #4ceeeb;
  --aro: rgba(76, 238, 235, 0.35);
  --rosco-sombra: drop-shadow(0 2px 6px rgba(8, 9, 20, 0.6));

  --aviso: #fcb900;
  --aviso-texto: #080914;
  /* Verde y rojo, como en el programa */
  --acierto: #1fae5b;
  --fallo: #cf2e2e;
  --destello-acierto: rgba(31, 174, 91, 0.8);
  --destello-fallo: rgba(207, 46, 46, 0.8);
  --repaso: rgba(207, 46, 46, 0.8);
}

/*
 * A3E · Asociación de Empresas de Eficiencia Energética: fondo claro, teal #478084,
 * turquesa #01CBC0, lima #F0FF93, menta #61DAA9 y texto petróleo #002E39 (colores de a3e.es).
 */
html[data-marca="a3e"] {
  --fuente: 'Ubuntu', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --fondo: #f4fffb;
  --texto: #002e39;
  --titulo: #478084;
  --titulo-sombra: none;
  --destacado: #017f78;

  --brillo-1: rgba(1, 203, 192, 0.35);
  --brillo-2: rgba(240, 255, 147, 0.9);
  --brillo-3: rgba(97, 218, 169, 0.5);
  --velo-arriba: rgba(244, 255, 251, 0.75);
  --velo-medio: rgba(244, 255, 251, 0);
  --velo-abajo: rgba(244, 255, 251, 0.92);

  --boton: #01cbc0;
  --boton-texto: #002e39;
  --boton-sombra: 0 6px 20px rgba(1, 203, 192, 0.35);
  --boton-2: #478084;
  --boton-2-texto: #ffffff;

  --tarjeta: rgba(255, 255, 255, 0.94);
  --tarjeta-borde: rgba(71, 128, 132, 0.25);
  --tarjeta-sombra: 0 20px 45px rgba(0, 46, 57, 0.18);
  --opcion: #ffffff;
  --opcion-borde: #478084;
  --opcion-texto: #002e39;

  --pastilla: rgba(255, 255, 255, 0.9);
  --pastilla-borde: rgba(71, 128, 132, 0.35);
  --pastilla-texto: #002e39;
  --pastilla-destacada: #f0ff93;
  --pastilla-destacada-texto: #002e39;

  --letra: #478084;
  --letra-borde: #ffffff;
  --letra-texto: #ffffff;
  --letra-pasada: #69aaae;
  --letra-pasada-borde: #f0ff93;
  --letra-actual: #f0ff93;
  --letra-actual-texto: #002e39;
  --letra-ola: #01cbc0;
  --aro: rgba(71, 128, 132, 0.4);
  --rosco-sombra: drop-shadow(0 3px 6px rgba(0, 46, 57, 0.25));

  --aviso: #e5ff46;
  --aviso-texto: #002e39;
  --acierto: #2dc185;
  --fallo: #d64545;
  --destello-acierto: rgba(45, 193, 133, 0.75);
  --destello-fallo: rgba(214, 69, 69, 0.7);
  --repaso: #d64545;
}

/* ---------- Base ---------- */

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--fondo);
}

body {
  color: var(--texto);
  font-family: var(--fuente);
  -webkit-font-smoothing: antialiased;
}

p,
h1,
h2 {
  margin: 0;
}

.oculto {
  display: none !important;
}

/* ---------- Estructura ---------- */

.juego {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: var(--fondo);
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* En espejo: quien juega se ve como en un espejo. */
  transform: scaleX(-1);
}

/* Fondo sin webcam: tres brillos de la marca que derivan despacio. */
.fondo {
  position: absolute;
  top: -20%;
  left: -20%;
  right: -20%;
  bottom: -20%;
  pointer-events: none;
  background:
    radial-gradient(38% 28% at 28% 26%, var(--brillo-1), transparent 70%),
    radial-gradient(32% 26% at 74% 38%, var(--brillo-2), transparent 70%),
    radial-gradient(55% 40% at 50% 88%, var(--brillo-3), transparent 70%);
  animation: deriva 20s ease-in-out infinite alternate;
}

@keyframes deriva {
  from { transform: translate3d(-4%, -2%, 0) rotate(0deg) }
  to { transform: translate3d(4%, 3%, 0) rotate(10deg) }
}

/* Oscurece (o aclara) arriba y abajo para que se lean marcador y pregunta sobre la imagen. */
.velo {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  background: linear-gradient(to bottom, var(--velo-arriba) 0%, var(--velo-medio) 40%, var(--velo-abajo) 100%);
}

.capa-rosco {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.cabecera {
  position: relative;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: calc(2 * var(--u));
  width: 100%;
  max-width: calc(100 * var(--u));
  margin: 0 auto;
  padding: calc(3 * var(--u)) var(--margen) 0;
}

.logo-caja {
  display: flex;
  align-items: center;
  gap: calc(1.5 * var(--u));
  min-height: calc(5 * var(--u));
}

.logo {
  height: calc(5 * var(--u));
  width: auto;
}

/* Logotipo de texto, para marcas sin imagen. */
.logo-texto {
  font-size: calc(5 * var(--u));
  line-height: 1;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--titulo);
}

.logo-subtexto {
  max-width: calc(26 * var(--u));
  font-size: var(--texto-xs);
  line-height: 1.15;
  font-weight: 500;
  opacity: 0.8;
}

.cartel {
  display: none;
  padding: 0 var(--margen);
}

.hueco {
  flex: 1 1 0;
  min-height: 0;
  /* El rosco llena este hueco: con el margen, sus letras no tocan los bordes. */
  margin: 0 var(--margen);
}

.zona-panel {
  position: relative;
  z-index: 20;
  display: flex;
  justify-content: center;
  width: 100%;
  max-width: calc(100 * var(--u));
  margin: 0 auto;
  padding: 0 var(--margen) calc(3 * var(--u));
}

.marcador {
  display: flex;
  align-items: center;
  gap: calc(1.5 * var(--u));
}

.marcador-abajo {
  display: none;
}

/*
 * Tótem más alto que 9:20: sobra alto, así que se reparte en columna:
 * cartel arriba (se ve de lejos), rosco en medio y el juego abajo, a mano.
 */
@media (max-aspect-ratio: 9/20) {
  .cartel {
    position: relative;
    z-index: 10;
    display: flex;
    flex: 1 1 0;
    min-height: 0;
    flex-direction: column;
    justify-content: center;
    text-align: center;
  }

  .hueco {
    flex: 1.6 1 0;
  }

  .marcador-arriba {
    display: none !important;
  }

  .marcador-abajo {
    position: relative;
    z-index: 10;
    display: flex;
    justify-content: center;
    padding-bottom: calc(3 * var(--u));
  }

  .titulo,
  .lema-espera {
    display: none;
  }
}

/* ---------- Textos ---------- */

.titulo,
.cartel-titulo {
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.025em;
  color: var(--titulo);
  text-shadow: var(--titulo-sombra);
}

.titulo {
  font-size: var(--texto-2xl);
}

.cartel-titulo {
  font-size: calc(12 * var(--u));
}

.lema {
  font-size: var(--texto-xs);
  text-transform: uppercase;
  letter-spacing: 0.3em;
  opacity: 0.6;
  margin-top: calc(1.5 * var(--u));
}

.cartel .lema {
  font-size: var(--texto-sm);
  margin-top: calc(2 * var(--u));
}

.etiqueta {
  font-size: var(--texto-xs);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  opacity: 0.6;
}

/* ---------- Pastillas (marcador y ranking) ---------- */

.pastilla {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: calc(7 * var(--u));
  padding: 0 calc(2.5 * var(--u));
  border-radius: 999px;
  font-size: var(--texto-md);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.pastilla-chica {
  height: calc(5.5 * var(--u));
  padding: 0 calc(2 * var(--u));
  font-size: var(--texto-sm);
}

.pastilla-neutra {
  background: var(--pastilla);
  color: var(--pastilla-texto);
  border: 1px solid var(--pastilla-borde);
}

.pastilla-aviso {
  background: var(--aviso);
  color: var(--aviso-texto);
}

.pastilla-peligro {
  background: var(--fallo);
  color: #fff;
  animation: latir 1s ease-in-out infinite;
}

@keyframes latir {
  50% { opacity: 0.55 }
}

.pastilla-acierto {
  background: var(--acierto);
  color: #fff;
}

.pastilla-fallo {
  background: var(--fallo);
  color: #fff;
}

.pastilla-primaria {
  background: var(--pastilla-destacada);
  color: var(--pastilla-destacada-texto);
}

.mejores {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--u);
}

.mejores-lista {
  display: flex;
  gap: var(--u);
}

/* ---------- Botones ---------- */

.boton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  margin: 0;
  font-family: inherit;
  font-weight: 600;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s ease, background-color 0.2s ease, opacity 0.2s ease;
}

.boton:active:not(:disabled) {
  transform: scale(0.97);
}

.boton:disabled {
  cursor: default;
}

.boton-primario {
  background: var(--boton);
  color: var(--boton-texto);
  border-radius: 999px;
  box-shadow: var(--boton-sombra);
}

.boton-jugar {
  height: calc(11 * var(--u));
  padding: 0 calc(14 * var(--u));
  font-size: var(--texto-lg);
  margin-top: calc(5 * var(--u));
}

.boton-otra {
  height: calc(10 * var(--u));
  padding: 0 calc(12 * var(--u));
  font-size: var(--texto-md);
  margin-top: calc(2 * var(--u));
}

.boton-secundario {
  width: 100%;
  height: calc(10 * var(--u));
  background: var(--boton-2);
  color: var(--boton-2-texto);
  font-size: var(--texto-md);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border-radius: calc(1.5 * var(--u));
}

.boton-fantasma {
  background: transparent;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
}

.esquina {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 30;
  display: flex;
  gap: 4px;
  opacity: 0.4;
}

/* ---------- Espera y cuenta atrás ---------- */

.espera {
  width: 100%;
  text-align: center;
  /* Margen abajo para no pisar el botón del montador de la esquina. */
  padding-bottom: calc(5 * var(--u));
}

.mensaje-espera {
  font-size: var(--texto-lg);
  font-weight: 600;
  margin-top: calc(5 * var(--u));
}

.reglas {
  font-size: var(--texto-sm);
  opacity: 0.7;
  margin-top: calc(2 * var(--u));
}

.privacidad {
  font-size: var(--texto-xs);
  opacity: 0.4;
  margin-top: calc(4 * var(--u));
}

.cuenta {
  text-align: center;
  padding-bottom: calc(10 * var(--u));
}

.preparado {
  font-size: var(--texto-lg);
  opacity: 0.8;
}

.cuenta-numero {
  font-size: calc(40 * var(--u));
  line-height: 1;
  font-weight: 700;
  color: var(--titulo);
  text-shadow: var(--titulo-sombra);
  animation: ping 1s cubic-bezier(0, 0, 0.2, 1) 1;
}

@keyframes ping {
  75%, 100% { transform: scale(2); opacity: 0 }
}

/* ---------- Tarjetas: pregunta y final ---------- */

#pregunta {
  width: 100%;
}

.tarjeta {
  width: 100%;
  background: var(--tarjeta);
  border: 1px solid var(--tarjeta-borde);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-radius: 1rem;
  box-shadow: var(--tarjeta-sombra);
}

.panel-pregunta {
  display: flex;
  flex-direction: column;
  gap: calc(2.5 * var(--u));
  padding: calc(3.5 * var(--u));
  animation: subir 0.3s ease-out both;
}

@keyframes subir {
  from { opacity: 0; transform: translateY(1.5rem) }
  to { opacity: 1; transform: none }
}

/* Si se falla, el panel tiembla. */
.panel-pregunta.temblar {
  animation: temblar 0.45s ease-in-out;
}

@keyframes temblar {
  0%, 100% { transform: translateX(0) }
  20% { transform: translateX(-0.7rem) }
  40% { transform: translateX(0.7rem) }
  60% { transform: translateX(-0.4rem) }
  80% { transform: translateX(0.4rem) }
}

.pregunta-cabeza {
  display: flex;
  align-items: center;
  gap: calc(3 * var(--u));
}

.pregunta-letra {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: calc(13 * var(--u));
  height: calc(13 * var(--u));
  border-radius: 50%;
  background: var(--letra-actual);
  color: var(--letra-actual-texto);
  font-size: var(--texto-xl);
  font-weight: 700;
}

.pista {
  font-size: var(--texto-sm);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--destacado);
}

.enunciado {
  font-size: var(--texto-lg);
  font-weight: 600;
  line-height: 1.375;
}

.opciones {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: calc(2 * var(--u));
}

.opcion {
  min-height: calc(11 * var(--u));
  padding: calc(1.5 * var(--u));
  font-size: var(--texto-md);
  line-height: 1.2;
  text-align: center;
  border-radius: calc(1.5 * var(--u));
  background: var(--opcion);
  color: var(--opcion-texto);
  border: 1px solid var(--opcion-borde);
}

.opcion-correcta {
  background: var(--acierto);
  border-color: var(--acierto);
  color: #fff;
}

.opcion-mal {
  background: var(--fallo);
  border-color: var(--fallo);
  color: #fff;
}

.opcion-apagada {
  opacity: 0.3;
}

.boton-pasar:disabled {
  opacity: 0.5;
}

.final {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: calc(2 * var(--u));
  padding: calc(4 * var(--u));
  animation: entrar 0.5s cubic-bezier(0.18, 1.5, 0.5, 1) both;
}

@keyframes entrar {
  from { opacity: 0; transform: scale(0.85) translateY(2rem) }
  to { opacity: 1; transform: none }
}

.final-titulo {
  font-size: var(--texto-sm);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  opacity: 0.6;
}

.final-puntos {
  font-size: calc(16 * var(--u));
  line-height: 1;
  font-weight: 700;
  color: var(--titulo);
}

.final-detalle {
  font-size: var(--texto-md);
}

.texto-acierto {
  color: var(--acierto);
  font-weight: 700;
}

.texto-fallo {
  color: var(--fallo);
  font-weight: 700;
}

.final-fallos {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(1.2 * var(--u));
  margin: var(--u) 0;
}

.repaso {
  padding: var(--u) calc(2.5 * var(--u));
  border-radius: 999px;
  font-size: var(--texto-sm);
  color: #fff;
  background: var(--repaso);
}

.final-ranking {
  font-size: var(--texto-sm);
  opacity: 0.7;
}

/* ---------- Destello y confeti ---------- */

/* Destello en los bordes de la pantalla al responder: se ve aunque mires la cara y no el panel. */
.destello {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 15;
  pointer-events: none;
  animation: destello 0.8s ease-out forwards;
}

.destello-acierto {
  box-shadow: inset 0 0 140px 40px var(--destello-acierto);
}

.destello-fallo {
  box-shadow: inset 0 0 140px 40px var(--destello-fallo);
}

@keyframes destello {
  from { opacity: 1 }
  to { opacity: 0 }
}

.confeti {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 25;
  overflow: hidden;
  pointer-events: none;
}

.pieza {
  position: absolute;
  top: -8%;
  width: 0.55rem;
  height: 0.95rem;
  border-radius: 1px;
  opacity: 0;
  animation-name: caer;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
}

@keyframes caer {
  0% { transform: translateY(-10vh) rotate(0deg); opacity: 1 }
  100% { transform: translateY(105vh) rotate(720deg); opacity: 0.1 }
}

/* ---------- Rosco ---------- */

.rosco {
  /* La posición y el tamaño los pone dibujo-rosco.js en cada fotograma. */
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  will-change: transform, width;
  filter: var(--rosco-sombra);
}

.rosco svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.rosco-aro {
  fill: none;
  stroke: var(--aro);
  stroke-width: 0.6;
}

.rosco-letra circle {
  fill: var(--letra);
  stroke: var(--letra-borde);
  stroke-width: 0.5;
  transition: fill 0.3s ease;
}

.rosco-letra text {
  fill: var(--letra-texto);
  font-weight: 700;
  font-family: var(--fuente);
  transition: fill 0.3s ease;
}

/* Pasapalabra: sigue pendiente, pero se distingue de las que aún no han salido. */
.rosco-pasada circle {
  fill: var(--letra-pasada);
  stroke: var(--letra-pasada-borde);
}

/* La letra que se resuelve da un salto al cambiar de color. */
.rosco-acierto,
.rosco-fallo {
  transform-box: fill-box;
  transform-origin: center;
  animation: marcar 0.6s cubic-bezier(0.2, 1.6, 0.5, 1);
}

@keyframes marcar {
  0% { transform: scale(1.25) }
  45% { transform: scale(1.65) }
  100% { transform: scale(1) }
}

.rosco-acierto circle {
  fill: var(--acierto);
}

.rosco-fallo circle {
  fill: var(--fallo);
}

.rosco-acierto text,
.rosco-fallo text {
  fill: #fff;
}

.rosco-actual {
  transform-box: fill-box;
  transform-origin: center;
  animation: latido 1.1s ease-in-out infinite;
}

.rosco-actual circle {
  fill: var(--letra-actual);
  stroke: var(--letra-borde);
  stroke-width: 0.8;
}

.rosco-actual text {
  fill: var(--letra-actual-texto);
}

@keyframes latido {
  0%, 100% { transform: scale(1.12) }
  50% { transform: scale(1.32) }
}

/* Pantalla de espera sin cámara: una ola de color da la vuelta al rosco. */
.rosco-atraer .rosco-letra circle {
  animation: ola 3s ease-in-out infinite;
  animation-delay: var(--retardo);
}

@keyframes ola {
  0%, 30%, 100% { fill: var(--letra) }
  8% { fill: var(--letra-ola) }
}

/* ---------- Menos movimiento ---------- */

@media (prefers-reduced-motion: reduce) {
  .fondo,
  .panel-pregunta,
  .panel-pregunta.temblar,
  .final,
  .rosco-acierto,
  .rosco-fallo,
  .rosco-atraer .rosco-letra circle {
    animation: none;
  }

  .rosco-actual {
    animation: none;
    transform: scale(1.25);
  }

  .destello {
    animation-duration: 0.01s;
  }

  .pieza {
    display: none;
  }
}
