/* WATERPOLO (polo.html). Primero el celular acostado (844 × 390): todo lo
   demás se abre desde ahí. Mismo aire que el juego de rugby: tinta azul
   petróleo, Barlow, píldoras translúcidas. */
:root {
  --tinta: #06222f;
  --espuma: #e8f7fc;
  --agua: #6fd3ef;
  --panel: rgba(6, 34, 47, 0.78);
  --amarillo: #ffd21f;
  --blanco: #f1f5f8;
  --azul: #2a66cf;
  --rojo: #e5352b;
  --verde: #2fbf71;
  --fuente: 'Barlow', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --cond: 'Barlow Condensed', 'Barlow', system-ui, sans-serif;
  --sl: env(safe-area-inset-left, 0px);
  --sr: env(safe-area-inset-right, 0px);
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #0b3a50; color: var(--espuma);
  font-family: var(--fuente); -webkit-font-smoothing: antialiased;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none; touch-action: none;
}
[hidden] { display: none !important; }
button { font-family: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
#juego { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

/* ------------------------------------------------------------------ HUD */
/* Por ENCIMA de la capa táctil (6): si no, pausa y sonido quedan debajo y el
   dedo no llega. No estorba: nada del HUD recibe toques salvo esos dos botones. */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 7; }
#arriba {
  position: absolute; top: calc(6px + var(--st)); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
}
#marcador {
  display: flex; align-items: stretch; background: var(--panel); border-radius: 12px; overflow: hidden;
  box-shadow: 0 4px 18px rgba(0, 0, 0, .25); backdrop-filter: blur(6px);
}
#marcador .eq { display: flex; align-items: center; gap: 7px; padding: 5px 11px; font: 800 13px var(--cond); letter-spacing: .07em; }
#marcador .eq b { font: 800 26px/1 var(--cond); min-width: 16px; text-align: center; font-variant-numeric: tabular-nums; }
#marcador .gorro { width: 13px; height: 13px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .85); }
#marcador .blanco .gorro { background: var(--blanco); border-color: #9fb6c2; }
#marcador .azul .gorro { background: var(--azul); }
#marcador .centro {
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2px 12px;
  background: rgba(0, 0, 0, .28); min-width: 76px;
}
#reloj { font: 800 22px/1 var(--cond); font-variant-numeric: tabular-nums; }
#periodo { font-size: 10px; opacity: .75; letter-spacing: .04em; white-space: nowrap; }
#marcador.gol-blanco .blanco b, #marcador.gol-azul .azul b { animation: salta .7s ease; color: var(--amarillo); }
@keyframes salta { 30% { transform: scale(1.7); } }

/* Reloj de posesión: siempre a la vista, y enorme cuando quedan 5 s. */
#posesion {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 54px; height: 46px; border-radius: 12px; background: var(--panel);
  border: 2px solid rgba(255, 255, 255, .25); transform-origin: top center;
  transition: transform .2s, background .2s, border-color .2s; backdrop-filter: blur(6px);
}
#posesion b { font: 800 24px/1 var(--cond); font-variant-numeric: tabular-nums; }
#posesion small { font: 700 7.5px var(--fuente); letter-spacing: .08em; opacity: .8; }
#posesion.blanco { border-color: var(--blanco); }
#posesion.azul { border-color: #6f9fef; }
#posesion.urge { transform: scale(1.45); background: #b3261e; border-color: #fff; animation: late .5s infinite alternate; }
#posesion.parado b { opacity: .45; }
@keyframes late { to { background: #e5352b; } }

#estado {
  position: absolute; top: calc(60px + var(--st)); left: 50%; transform: translateX(-50%);
  padding: 3px 12px; border-radius: 99px; background: rgba(6, 34, 47, .6); font: 700 12px var(--fuente);
  white-space: nowrap; transition: background .2s, color .2s;
}
#estado.mio { background: var(--amarillo); color: var(--tinta); }
#estado.rival { background: rgba(42, 102, 207, .85); }

#aviso {
  position: absolute; left: 50%; top: 30%; transform: translate(-50%, -50%) scale(.9);
  text-align: center; opacity: 0; transition: opacity .25s, transform .25s; width: min(92vw, 560px);
  text-shadow: 0 2px 14px rgba(0, 0, 0, .55);
}
#aviso.ver { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#aviso strong { display: block; font: 800 42px/1 var(--cond); letter-spacing: .02em; text-transform: uppercase; }
#aviso span { display: inline-block; margin-top: 6px; padding: 4px 12px; border-radius: 10px; background: rgba(6, 34, 47, .72); font: 600 14px/1.3 var(--fuente); text-shadow: none; }
#aviso span:empty { display: none; }
#aviso.gol strong { font-size: 68px; color: var(--amarillo); }
#aviso.malo strong { color: #ffb0a8; }

#coach {
  position: absolute; left: 50%; bottom: calc(18px + var(--sb)); transform: translate(-50%, 12px);
  max-width: min(46vw, 430px); padding: 8px 14px; border-radius: 12px; background: rgba(255, 210, 31, .96); color: var(--tinta);
  font: 700 13.5px/1.3 var(--fuente); text-align: center; opacity: 0; transition: opacity .3s, transform .3s;
  box-shadow: 0 6px 22px rgba(0, 0, 0, .3);
}
#coach.ver { opacity: 1; transform: translate(-50%, 0); }

#barras { position: absolute; left: calc(14px + var(--sl)); top: calc(10px + var(--st)); width: 132px; display: grid; gap: 5px; margin-left: 52px; }
.barra { position: relative; height: 9px; border-radius: 99px; background: rgba(6, 34, 47, .6); overflow: hidden; border: 1px solid rgba(255, 255, 255, .22); }
.barra i { position: absolute; inset: 0; transform-origin: left center; border-radius: 99px; }
.barra.fuerza i { background: linear-gradient(90deg, #2fbf71, #9fe870); }
.barra.fuerza.poca i { background: #e5352b; }
.barra.agarre { height: 16px; opacity: 0; transition: opacity .2s; }
.barra.agarre.ver { opacity: 1; }
.barra.agarre i { background: var(--amarillo); }
.barra.agarre.peligro i { background: var(--rojo); }
.barra.agarre span { position: absolute; inset: 0; z-index: 1; display: grid; place-items: center; font: 800 9.5px var(--fuente); letter-spacing: .05em; color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, .7); white-space: nowrap; }

/* Carga del tiro: barra vertical junto al botón, con la zona buena marcada. */
#potencia {
  position: absolute; right: calc(214px + var(--sr)); bottom: calc(34px + var(--sb)); width: 16px; height: 118px; border-radius: 8px;
  background: rgba(6, 34, 47, .75); border: 2px solid rgba(255, 255, 255, .6); overflow: hidden; opacity: 0; transition: opacity .12s;
}
#potencia.ver { opacity: 1; }
#potencia i { position: absolute; left: 0; right: 0; bottom: 0; height: 100%; transform-origin: bottom; background: linear-gradient(0deg, #2fbf71, #ffd21f 70%, #e5352b 96%); }
#potencia em { position: absolute; left: -2px; right: -2px; bottom: 87%; height: 2px; background: #fff; }

#flecha { position: absolute; left: 0; top: 0; width: 38px; height: 38px; margin: -19px; opacity: 0; transition: opacity .2s; }
#flecha.ver { opacity: 1; }
#flecha svg { width: 100%; height: 100%; fill: var(--amarillo); stroke: var(--tinta); stroke-width: 2; filter: drop-shadow(0 2px 4px rgba(0, 0, 0, .5)); }

#teclas { position: absolute; left: 50%; bottom: 4px; transform: translateX(-50%); margin: 0; padding: 4px 12px; border-radius: 10px; background: rgba(6, 34, 47, .55); font-size: 12px; white-space: nowrap; opacity: .9; }
#teclas b { color: var(--amarillo); }
.tactil #teclas { display: none; }
body:not(.tactil) #coach { bottom: 38px; }

.redondo {
  position: absolute; top: calc(8px + var(--st)); width: 44px; height: 44px; border-radius: 50%; border: 0; pointer-events: auto;
  background: var(--panel); display: grid; place-items: center; cursor: pointer;
}
.redondo svg { width: 22px; height: 22px; fill: currentColor; }
#btn-pausa { left: calc(10px + var(--sl)); }
#btn-sonido { right: calc(10px + var(--sr)); }
#btn-sonido.mudo .ondas { display: none; }
#btn-sonido.mudo { opacity: .6; }

/* -------------------------------------------------------------- táctil */
#tactil { position: fixed; inset: 0; z-index: 6; touch-action: none; }
body:not(.tactil) #tactil { display: none; }
#stick {
  position: absolute; left: 110px; top: 70%; width: 116px; height: 116px; margin: -58px; border-radius: 50%;
  background: rgba(232, 247, 252, .10); border: 2px solid rgba(232, 247, 252, .38); opacity: .55; transition: opacity .15s;
  pointer-events: none;
}
#stick.on { opacity: 1; }
#perilla { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px; border-radius: 50%; background: rgba(232, 247, 252, .85); box-shadow: 0 3px 10px rgba(0, 0, 0, .35); }
.btn {
  position: absolute; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .85); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  font: 800 15px/1 var(--cond); letter-spacing: .05em; color: #fff; touch-action: none;
  box-shadow: 0 5px 16px rgba(0, 0, 0, .35); transition: transform .06s, background .15s, opacity .15s;
}
.btn.abajo { transform: scale(.92); filter: brightness(1.25); }
.btn small { font: 700 10px var(--fuente); letter-spacing: 0; opacity: .95; }
#btn-a { right: calc(18px + var(--sr)); bottom: calc(22px + var(--sb)); width: 92px; height: 92px; font-size: 19px; background: rgba(42, 102, 207, .92); }
#btn-b { right: calc(118px + var(--sr)); bottom: calc(52px + var(--sb)); width: 84px; height: 84px; font-size: 18px; background: rgba(47, 191, 113, .92); }
#btn-sprint { right: calc(34px + var(--sr)); bottom: calc(126px + var(--sb)); width: 64px; height: 64px; font-size: 13px; background: rgba(6, 34, 47, .72); }
#btn-a.pase, #btn-a.globo { background: rgba(42, 102, 207, .94); }
#btn-a.globo { border-style: dashed; }
#btn-a.quitar { background: rgba(229, 53, 43, .94); }
#btn-a.pedir { background: rgba(241, 245, 248, .95); color: var(--tinta); border-color: var(--tinta); }
#btn-a.balon { background: rgba(6, 34, 47, .7); }
#btn-a.espera, #btn-b.espera { background: rgba(6, 34, 47, .45); opacity: .5; }
#btn-b.tiro { background: rgba(47, 191, 113, .95); }
#btn-b.tiro.atiro { box-shadow: 0 0 0 5px rgba(255, 210, 31, .85), 0 5px 16px rgba(0, 0, 0, .35); }
#btn-b.cambiar { background: rgba(6, 34, 47, .72); font-size: 14px; }
#btn-b.pasa { background: rgba(120, 130, 140, .8); }

/* --------------------------------------------------------------- capas */
.capa {
  position: fixed; inset: 0; z-index: 20; display: flex; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: calc(10px + var(--st)) calc(14px + var(--sr)) calc(10px + var(--sb)) calc(14px + var(--sl));
  touch-action: pan-y;
}
#portada { background: linear-gradient(90deg, rgba(4, 26, 38, .93) 0%, rgba(4, 26, 38, .78) 48%, rgba(4, 26, 38, .30) 100%); }
/* El centrado va con margin:auto en el hijo: con align-items:center lo que
   desborda por arriba queda inalcanzable con el dedo. */
.lobby { margin: auto; width: min(100%, 980px); display: grid; grid-template-columns: 1.15fr 1fr; gap: 22px; align-items: center; }
.marca { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; color: var(--espuma); margin-bottom: 6px; }
.marca b { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: var(--espuma); color: var(--tinta); font: 800 13px var(--cond); }
.marca span { font: 700 13px/1.1 var(--fuente); }
.marca small { display: block; font-weight: 400; opacity: .7; font-size: 10.5px; }
.kicker { margin: 0; font: 700 12px var(--fuente); letter-spacing: .16em; text-transform: uppercase; color: var(--amarillo); }
.heroe h1 { margin: 0; font: 800 clamp(44px, 9vw, 86px)/.92 var(--cond); text-transform: uppercase; letter-spacing: .01em; }
.gancho { margin: 6px 0 10px; font-size: clamp(14px, 1.9vw, 17px); line-height: 1.35; max-width: 34em; opacity: .95; }
.opciones { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; font-size: 13px; }
.opciones label { display: inline-flex; align-items: center; gap: 7px; font-weight: 600; }
.opciones select {
  min-height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid rgba(232, 247, 252, .4);
  background: rgba(6, 34, 47, .8); color: var(--espuma); font: 700 15px var(--fuente);
}
.ficha { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 99px; background: rgba(232, 247, 252, .12); font-weight: 600; }
.ficha i { width: 12px; height: 12px; border-radius: 50%; background: var(--blanco); }
.cta {
  display: block; width: 100%; max-width: 420px; min-height: 58px; border: 0; border-radius: 14px; cursor: pointer;
  background: var(--amarillo); color: var(--tinta); font: 800 26px var(--cond); letter-spacing: .06em;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35); transition: transform .08s;
}
.cta:active { transform: scale(.98); }
.cta:disabled { background: rgba(232, 247, 252, .25); color: var(--espuma); font-size: 18px; cursor: default; }
.como { background: rgba(6, 34, 47, .72); border: 1px solid rgba(232, 247, 252, .16); border-radius: 16px; padding: 14px 16px; backdrop-filter: blur(6px); }
.como h2 { margin: 0 0 6px; font: 800 20px var(--cond); text-transform: uppercase; letter-spacing: .05em; color: var(--agua); }
.como ol { margin: 0; padding: 0; list-style: none; counter-reset: paso; display: grid; gap: 8px; }
.como li { counter-increment: paso; position: relative; padding-left: 34px; font-size: 14px; line-height: 1.32; }
.como li::before { content: counter(paso); position: absolute; left: 0; top: 0; width: 24px; height: 24px; border-radius: 50%; background: var(--amarillo); color: var(--tinta); display: grid; place-items: center; font: 800 14px var(--cond); }
.como li b { color: #fff; }
.otros { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; margin-top: 12px; font-size: 12.5px; }
.otros > span { opacity: .7; width: 100%; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.otros a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px; border-radius: 10px; background: rgba(232, 247, 252, .12); color: var(--espuma); text-decoration: none; font-weight: 700; }
.otros a.tienda { background: none; text-decoration: underline; font-weight: 600; opacity: .85; padding: 0 6px; }

#tarjeta { background: rgba(4, 26, 38, .72); backdrop-filter: blur(3px); }
.carta { margin: auto; width: min(100%, 520px); background: rgba(6, 34, 47, .94); border: 1px solid rgba(232, 247, 252, .18); border-radius: 18px; padding: 16px 20px; text-align: center; box-shadow: 0 18px 50px rgba(0, 0, 0, .45); }
.carta h2 { margin: 2px 0 0; font: 800 44px/1 var(--cond); text-transform: uppercase; }
.carta .resultado { margin: 4px 0 0; font: 800 34px/1 var(--cond); font-variant-numeric: tabular-nums; color: var(--amarillo); }
.carta .resultado:empty, .carta .sub:empty, .carta .cifras:empty { display: none; }
.carta .sub { margin: 6px 0 0; font-size: 14px; opacity: .9; }
.cifras { list-style: none; margin: 10px 0 0; padding: 0; display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.cifras li { background: rgba(232, 247, 252, .09); border-radius: 10px; padding: 6px 2px; font-size: 10.5px; line-height: 1.15; }
.cifras b { display: block; font: 800 24px/1 var(--cond); color: #fff; }
.carta .cta { margin: 12px auto 0; }
.enlace { display: block; margin: 4px auto 0; min-height: 44px; padding: 0 16px; background: none; border: 0; text-decoration: underline; font-size: 14px; cursor: pointer; opacity: .9; }
.carta .otros { justify-content: center; margin-top: 4px; }

/* ---------------------------------------------------------- orientación */
#gira {
  position: fixed; inset: 0; z-index: 40; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  background: #06222f; text-align: center; padding: 24px;
}
#gira svg { width: 84px; height: 84px; color: var(--amarillo); animation: gira 2.4s ease-in-out infinite; }
#gira b { font: 800 30px var(--cond); text-transform: uppercase; }
#gira span { opacity: .8; }
@keyframes gira { 0%, 20% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
/* Solo en el celular y solo durante el partido: la portada sí cabe en vertical. */
@media (orientation: portrait) and (pointer: coarse) {
  body.jugando #gira { display: flex; }
}

/* Vertical o ventana estrecha: la portada en una columna. */
@media (max-aspect-ratio: 1/1), (max-width: 620px) {
  .lobby { grid-template-columns: 1fr; gap: 12px; }
  #portada { background: rgba(4, 26, 38, .86); }
  .cifras { grid-template-columns: repeat(3, 1fr); }
}
/* Celular acostado: poca altura. Todo más prieto. */
@media (max-height: 460px) {
  .marca { display: none; }
  .heroe h1 { font-size: clamp(40px, 13vh, 62px); }
  .gancho { font-size: 13.5px; margin: 4px 0 8px; }
  .opciones { margin-bottom: 8px; }
  .cta { min-height: 52px; font-size: 24px; }
  .como { padding: 10px 14px; }
  .como li { font-size: 13px; }
  .otros { margin-top: 8px; }
  .carta { padding: 10px 16px; width: min(100%, 600px); }
  .carta h2 { font-size: 34px; }
  .carta .resultado { font-size: 28px; }
  .cifras { margin-top: 6px; }
  .cifras b { font-size: 20px; }
  .carta .cta { margin-top: 8px; min-height: 48px; }
  .carta .otros a { min-height: 36px; }
  #aviso { top: 34%; }
  #aviso strong { font-size: 34px; }
  #aviso.gol strong { font-size: 54px; }
  #coach { max-width: 40vw; font-size: 12.5px; bottom: calc(8px + var(--sb)); }
}
@media (min-width: 1000px) and (min-height: 600px) {
  #marcador .eq { font-size: 16px; padding: 7px 16px; }
  #marcador .eq b { font-size: 34px; }
  #reloj { font-size: 28px; }
  #posesion { width: 66px; height: 58px; }
  #posesion b { font-size: 31px; }
  #posesion small { font-size: 9px; }
  #estado { top: 78px; font-size: 14px; }
  #aviso strong { font-size: 60px; }
  #aviso.gol strong { font-size: 110px; }
  #aviso span { font-size: 17px; }
  #coach { font-size: 16px; max-width: 520px; }
  #barras { width: 200px; }
  .barra { height: 11px; }
  #potencia { right: auto; left: 50%; margin-left: 150px; bottom: 90px; }
}
@media (prefers-reduced-motion: reduce) {
  #posesion.urge, #gira svg { animation: none; }
}
