:root {
  --cielo1: #9fd4f2;
  --cielo2: #d9f0fb;
  --tinta: #e8f4ff;
  --tenue: #8fb4d6;
  --panel: rgba(8, 20, 40, 0.82);
  --borde: rgba(140, 200, 255, 0.28);
  --acento: #4de3ff;
  --oro: #ffd166;
  --t-miss: #5b6b82;
  --t-plancton: #8fa3c4;
  --t-listillo: #ff9f43;
  --t-banco: #4de3ff;
  --t-rara: #ff5252;
  --t-abisal: #9d7bff;
  --t-joya: #ffd166;
  --pixel: "Press Start 2P", ui-monospace, monospace;
  color-scheme: dark;
  --mono: "VT323", ui-monospace, "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: #0a1a30;
  color: var(--tinta);
  font-family: var(--mono);
  font-size: 22px;
  -webkit-font-smoothing: none;
  user-select: none;
}
button { font-family: inherit; cursor: pointer; }
.oculto { display: none !important; }

/* ---------- Escena ---------- */
#escena { position: fixed; inset: 0; overflow: hidden; }
#mundo { position: absolute; left: 0; right: 0; top: 0; will-change: transform; }
#cielo {
  position: absolute; left: 0; right: 0; top: 0; height: 1200px;
  background: linear-gradient(var(--cielo1), var(--cielo2));
  overflow: hidden;
}
.sol {
  position: absolute; right: 12%; bottom: 300px; width: 90px; height: 90px;
  background: #ffe28a; box-shadow: 0 0 0 8px #fff1b8, 0 0 60px 20px rgba(255, 230, 140, .6);
  image-rendering: pixelated;
  clip-path: polygon(30% 0, 70% 0, 70% 10%, 90% 10%, 90% 30%, 100% 30%, 100% 70%, 90% 70%, 90% 90%, 70% 90%, 70% 100%, 30% 100%, 30% 90%, 10% 90%, 10% 70%, 0 70%, 0 30%, 10% 30%, 10% 10%, 30% 10%);
}
.nube {
  position: absolute; height: 28px; background: #fff;
  box-shadow: 16px -16px 0 #fff, 48px -16px 0 #fff, 32px -28px 0 #fff;
  animation: deriva 60s linear infinite;
}
.n1 { width: 110px; bottom: 260px; left: 8%; }
.n2 { width: 80px; bottom: 330px; left: 55%; animation-duration: 80s; }
.n3 { width: 130px; bottom: 160px; left: 75%; animation-duration: 95s; opacity: .85; }
@keyframes deriva { from { transform: translateX(0); } to { transform: translateX(-30vw); } }

#agua { position: absolute; left: 0; right: 0; }
#agua::before { /* oleaje en la superficie */
  content: ""; position: absolute; left: 0; right: 0; top: -10px; height: 12px;
  background: repeating-linear-gradient(90deg, #6fc3ec 0 24px, transparent 24px 48px);
  animation: ola 3s linear infinite;
}
@keyframes ola { to { background-position: 48px 0; } }

#marcas { position: absolute; left: 0; right: 0; top: 0; pointer-events: none; transition: opacity .8s; }
body.portada #marcas { opacity: 0; }
#mascota-wrap { transition: top 1s ease; }
body.portada .pantalla { justify-content: flex-start; padding-top: 12vh; }
.marca {
  position: absolute; font-family: var(--mono); font-size: 20px; letter-spacing: 1px;
  color: rgba(220, 240, 255, .55); white-space: nowrap; transition: color .6s, opacity .6s;
}
.marca.izq { left: 4%; }
.marca.der { right: 4%; text-align: right; }
.marca.zona { color: rgba(255, 255, 255, .8); font-size: 24px; letter-spacing: 3px; }
.marca.pasada { color: rgba(255, 255, 255, .95); text-shadow: 0 0 8px rgba(120, 220, 255, .6); }
.regla {
  position: absolute; right: 0; width: 18px; border-top: 2px solid rgba(220, 240, 255, .35);
}
.regla.larga { width: 36px; border-top-color: rgba(220, 240, 255, .6); }
.regla-num { position: absolute; right: 42px; font-size: 16px; color: rgba(220, 240, 255, .5); transform: translateY(-50%); }
.huella {
  position: absolute; left: 50%; width: 10px; height: 10px; margin-left: -5px; border-radius: 0;
  transform: rotate(45deg); box-shadow: 0 0 10px currentColor; background: currentColor;
}
.huella-et {
  position: absolute; left: calc(50% + 18px); font-size: 18px; transform: translateY(-50%);
  white-space: nowrap; text-shadow: 0 0 6px rgba(0, 0, 0, .8);
}
#fondo-fosa {
  position: absolute; left: 0; right: 0; height: 300px;
  background:
    linear-gradient(transparent 0 30px, #0b0d14 30px),
    repeating-linear-gradient(90deg, #151a26 0 40px, #0e121b 40px 80px);
  clip-path: polygon(0 40%, 6% 20%, 12% 35%, 20% 10%, 28% 30%, 36% 18%, 44% 0, 52% 22%, 60% 12%, 70% 30%, 78% 8%, 86% 26%, 94% 14%, 100% 30%, 100% 100%, 0 100%);
}

#nieve { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

#mascota-wrap {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%);
  pointer-events: auto; cursor: pointer; z-index: 3;
}
#mascota { width: 96px; height: 64px; transition: filter .8s; }
#mascota svg { width: 100%; height: 100%; image-rendering: pixelated; display: block; }
#mascota.brilla { filter: drop-shadow(0 0 10px rgba(120, 230, 255, .85)); }
#mascota.dorada { filter: drop-shadow(0 0 16px rgba(255, 209, 102, 1)); }
#mascota.flota { animation: flota 2.4s ease-in-out infinite; }
#mascota.rueda { animation: rueda .9s ease-in-out; }
#mascota.triste { animation: triste 1.6s ease-in-out; }
#mascota.celebra { animation: celebra .7s ease-in-out 3; }
@keyframes flota { 50% { transform: translateY(-6px); } }
@keyframes rueda { to { transform: rotate(360deg); } }
@keyframes triste { 30% { transform: translateY(8px) rotate(-8deg); } 60% { transform: translateY(4px) rotate(6deg); } }
@keyframes celebra { 50% { transform: translateY(-16px) scale(1.1); } }
#blub {
  position: absolute; left: 70%; top: -26px; font-size: 20px; color: #fff; opacity: 0;
  pointer-events: none; text-shadow: 0 0 6px rgba(0, 0, 0, .6);
}
#blub.ver { animation: blub 1s ease-out; }
@keyframes blub { 0% { opacity: 0; transform: translateY(6px); } 20% { opacity: 1; } 100% { opacity: 0; transform: translateY(-22px); } }
.burbuja {
  position: absolute; width: 8px; height: 8px; border: 2px solid rgba(220, 245, 255, .8);
  border-radius: 50%; pointer-events: none; animation: sube 1.6s ease-in forwards;
}
@keyframes sube { to { transform: translate(var(--dx, 0), -120px); opacity: 0; } }

#destello { position: absolute; inset: 0; pointer-events: none; opacity: 0; }
#destello.flash { animation: flash .6s ease-out; }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- Barra ---------- */
#barra {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 10px;
}
.barra-der { display: flex; flex-direction: column; gap: 6px; }
.icono {
  width: 40px; height: 40px; font-size: 20px; line-height: 1;
  background: rgba(10, 30, 55, .55); color: var(--tinta);
  border: 2px solid var(--borde); border-radius: 0;
}
.icono:hover { background: rgba(30, 70, 110, .75); }
#hud {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 22px; flex-wrap: wrap;
  background: rgba(5, 15, 30, .55); border: 2px solid var(--borde); padding: 6px 14px;
}
.hud-bloque { display: flex; flex-direction: column; align-items: center; line-height: 1; }
.hud-et { font-size: 15px; color: var(--tenue); letter-spacing: 2px; }
#hud-prof, #hud-puntos { font-size: 30px; color: var(--acento); font-variant-numeric: tabular-nums; }
#hud-puntos { color: var(--oro); }
#hud-dots { display: flex; gap: 5px; }
.dot { width: 14px; height: 14px; border: 2px solid rgba(220, 240, 255, .5); }
.dot.actual { border-color: #fff; animation: parpadeo 1s steps(2) infinite; }
@keyframes parpadeo { 50% { border-color: transparent; } }

/* ---------- Inicio ---------- */
.pantalla {
  position: fixed; inset: 0; z-index: 5;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 80px 16px 24px; text-align: center;
}
.titulo {
  font-family: var(--pixel); font-size: clamp(38px, 10vw, 84px); margin: 0;
  color: #fff; letter-spacing: 6px;
  text-shadow: 4px 4px 0 #ff5d8f, 8px 8px 0 #1d4f8a;
}
.subtitulo { font-size: clamp(20px, 3vw, 26px); color: #1d4f8a; margin: 18px 0 6px; letter-spacing: 3px; }
.lema { color: #1d4f8a; margin: 4px 0 30px; font-size: 22px; }
.btn-principal {
  font-family: var(--pixel); font-size: clamp(12px, 2.6vw, 16px); padding: 16px 22px;
  background: #ff5d8f; color: #fff; border: 0; box-shadow: 0 6px 0 #a3264f, 0 0 0 3px #fff inset;
  letter-spacing: 1px; transition: transform .08s;
}
.btn-principal:hover { transform: translateY(-2px); }
.btn-principal:active { transform: translateY(4px); box-shadow: 0 2px 0 #a3264f, 0 0 0 3px #fff inset; }
.btn-principal.peq { font-size: 12px; padding: 12px 16px; margin-top: 12px; }
.detalle { color: #23466e; margin: 14px 0 22px; min-height: 1em; font-size: 20px; }
.enlaces { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; max-width: 620px; }
.btn-sec {
  font-size: 19px; letter-spacing: 2px; padding: 6px 14px;
  background: rgba(255, 255, 255, .55); color: #1d4f8a; border: 2px solid #1d4f8a;
}
.btn-sec:hover { background: #fff; }
.btn-link { background: none; border: 0; color: var(--tenue); font-size: 18px; text-decoration: underline; margin-top: 8px; }

/* ---------- Juego ---------- */
#juego {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; justify-content: center; padding: 0 16px calc(18px + env(safe-area-inset-bottom, 0px));
}
#tarjeta {
  width: 100%; max-width: 620px; background: var(--panel); border: 2px solid var(--borde);
  padding: 14px 18px 12px; text-align: center; box-shadow: 0 10px 40px rgba(0, 0, 0, .45);
  backdrop-filter: blur(3px);
}
#ronda-et { font-size: 17px; color: var(--tenue); letter-spacing: 3px; }
#consigna { font-size: clamp(24px, 4.6vw, 32px); line-height: 1.1; margin: 6px 0 10px; color: #fff; }
#temporizador { position: relative; height: 14px; background: rgba(255, 255, 255, .08); border: 2px solid var(--borde); margin-bottom: 10px; }
#temporizador-barra { height: 100%; width: 100%; background: var(--acento); transform-origin: left; }
#temporizador-barra.urgente { background: var(--t-rara); }
#temporizador-num { position: absolute; right: 6px; top: -22px; font-size: 18px; color: var(--tenue); }
#form-respuesta { display: flex; gap: 8px; }
#respuesta {
  flex: 1; min-width: 0; font-family: var(--mono); font-size: 26px; padding: 6px 10px;
  background: #06101f; color: #fff; border: 2px solid var(--acento); outline: none; border-radius: 0;
  user-select: text;
}
#respuesta:focus { box-shadow: 0 0 0 3px rgba(77, 227, 255, .25); }
#respuesta.temblor { animation: temblor .35s; border-color: var(--t-rara); }
@keyframes temblor { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
#btn-enviar {
  font-family: var(--pixel); font-size: 11px; padding: 0 14px; background: var(--acento); color: #04223a; border: 0;
}
#btn-enviar:disabled, #respuesta:disabled { opacity: .5; }
#mensaje { min-height: 24px; margin-top: 8px; font-size: 20px; color: var(--t-listillo); }
#estado-juez { font-size: 16px; color: var(--tenue); margin-top: 2px; }
#form-respuesta.oculto ~ #estado-juez { display: none; }
#resultado-ronda { margin-top: 4px; }
#rr-cabecera { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 30px; }
#rr-nivel { font-size: 26px; letter-spacing: 2px; }
#rr-pts { font-size: 26px; color: var(--oro); }
#rr-respuesta { font-size: 24px; color: #fff; margin-top: 2px; }
#rr-texto { font-size: 19px; color: var(--tenue); }

/* ---------- Modal ---------- */
#modal {
  position: fixed; inset: 0; z-index: 20; background: rgba(2, 8, 18, .72);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
#modal-caja {
  position: relative; width: 100%; max-width: 640px; max-height: 92vh; overflow: auto;
  background: #0b1a30; border: 2px solid var(--borde); padding: 22px 20px 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6); user-select: text;
}
#modal-cerrar { position: absolute; right: 10px; top: 10px; width: 34px; height: 34px; font-size: 16px; }
#modal h2 { font-size: 30px; margin: 0 0 14px; color: #fff; letter-spacing: 2px; padding-right: 40px; line-height: 1.1; font-weight: normal; }
#modal h3 { font-size: 22px; margin: 18px 0 6px; color: var(--acento); letter-spacing: 2px; font-weight: normal; }
#modal p { margin: 6px 0; line-height: 1.15; }
.niveles { display: grid; gap: 4px; margin: 8px 0; }
.nivel-fila { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 8px; padding: 4px 6px; border-bottom: 1px solid rgba(255, 255, 255, .06); }
.nivel-fila .pts { color: var(--oro); }
.nivel-fila small { display: block; color: var(--tenue); font-size: 17px; }

.res-cabecera { text-align: center; }
.res-prof { font-size: 54px; color: var(--acento); line-height: 1; }
.res-pts { font-size: 26px; color: var(--oro); }
.res-veredicto { font-size: 22px; margin: 6px 0 4px; }
.res-emojis { font-size: 30px; letter-spacing: 4px; margin: 8px 0; }
.res-lista { margin: 10px 0; }
.res-fila { display: grid; grid-template-columns: 22px 30px 1fr auto; gap: 8px; align-items: start; padding: 6px 4px; border-bottom: 1px solid rgba(255, 255, 255, .07); }
.res-fila .num { color: var(--tenue); }
.res-fila .cons { color: var(--tenue); font-size: 17px; }
.res-fila .resp { color: #fff; }
.res-fila .pts { color: var(--oro); }
.acciones { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 16px; }
.btn-modal {
  font-size: 20px; letter-spacing: 1px; padding: 8px 14px; background: rgba(77, 227, 255, .12);
  color: var(--tinta); border: 2px solid var(--acento);
}
.btn-modal:hover { background: rgba(77, 227, 255, .25); }
.btn-modal.fuerte { background: #ff5d8f; border-color: #ff5d8f; color: #fff; }
.btn-modal.peligro { border-color: var(--t-rara); color: var(--t-rara); background: transparent; }

details.revelar { border: 1px solid rgba(255, 255, 255, .1); margin: 6px 0; padding: 4px 10px; }
details.revelar summary { cursor: pointer; color: #fff; }
.rev-grupo { margin: 6px 0; font-size: 18px; line-height: 1.2; }
.rev-grupo b { font-weight: normal; }
.rev-grupo .tuya { background: rgba(255, 255, 255, .18); padding: 0 3px; }

.archivo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.archivo-dia {
  padding: 8px 4px; text-align: center; background: rgba(255, 255, 255, .05); color: var(--tinta);
  border: 2px solid var(--borde); font-size: 18px; line-height: 1.1;
}
.archivo-dia:hover { border-color: var(--acento); }
.archivo-dia span { display: block; font-size: 15px; color: var(--tenue); }
.archivo-dia.hecho span { color: var(--oro); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; }
.stat b { display: block; font-size: 34px; color: var(--acento); font-weight: normal; line-height: 1; }
.stat span { font-size: 15px; color: var(--tenue); letter-spacing: 1px; }
.barras { display: grid; gap: 4px; margin-top: 6px; }
.barra-fila { display: grid; grid-template-columns: 150px 1fr 34px; gap: 8px; align-items: center; font-size: 18px; }
.barra-fila .relleno { height: 14px; min-width: 2px; }
.mascotas { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.masc {
  background: rgba(255, 255, 255, .04); border: 2px solid var(--borde); padding: 8px 4px; text-align: center;
  color: var(--tinta); font-size: 17px; line-height: 1.1;
}
.masc .svgw { width: 72px; height: 48px; margin: 0 auto 4px; }
.masc .svgw svg { width: 100%; height: 100%; image-rendering: pixelated; }
.masc.bloq { opacity: .45; cursor: not-allowed; }
.masc.bloq .svgw { filter: brightness(0); }
.masc.elegida { border-color: var(--oro); background: rgba(255, 209, 102, .1); }

.opciones { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
.opcion { font-size: 19px; padding: 4px 12px; background: transparent; color: var(--tinta); border: 2px solid var(--borde); }
.opcion.activa { border-color: var(--acento); background: rgba(77, 227, 255, .15); }

#aviso {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 30;
  background: #fff; color: #0b1a30; padding: 8px 16px; font-size: 20px; border: 2px solid #0b1a30;
}

@media (max-width: 560px) {
  body { font-size: 20px; }
  #hud { gap: 10px; padding: 4px 8px; }
  #hud-prof, #hud-puntos { font-size: 24px; }
  .dot { width: 10px; height: 10px; }
  #mascota-wrap { top: 34%; }
  #btn-enviar { font-size: 9px; padding: 0 8px; }
  .barra-fila { grid-template-columns: 110px 1fr 28px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .marca { font-size: 16px; }
  .marca.zona { font-size: 19px; }
}
