:root { --cyan: #22d3ee; --amber: #fcd34d; --orange: #f97316; --bg: #050b16; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: #e6fbff;
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  touch-action: none; overscroll-behavior: none;
}
#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#gl.off { visibility: hidden; }

.screen {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: calc(16px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right))
    calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left)); text-align: center;
}
.screen.solid { background: radial-gradient(120% 90% at 30% 10%, #0b2530, #050b16 70%); z-index: 20; }
.screen.panel { justify-content: flex-end; pointer-events: none; z-index: 10; }
.card {
  pointer-events: auto; width: min(420px, 100%); padding: 18px; border-radius: 18px; display: flex; flex-direction: column;
  gap: 10px; background: rgba(5, 11, 22, 0.88); border: 1px solid rgba(34, 211, 238, 0.35);
  box-shadow: 0 0 24px rgba(34, 211, 238, 0.15);
}
h1, h2, p { margin: 0; }
h1 { font-size: 40px; letter-spacing: 2px; color: var(--cyan); }
h2 { font-size: 26px; color: var(--amber); }
.small { font-size: 13px; opacity: 0.7; max-width: 340px; }
.logo { width: min(40vmin, 220px); height: auto; border-radius: 22%; box-shadow: 0 0 30px rgba(34, 211, 238, 0.25); }
b { color: var(--amber); }

button {
  font: inherit; font-weight: 600; color: #e6fbff; background: rgba(34, 211, 238, 0.12); border: 1px solid var(--cyan);
  border-radius: 14px; padding: 12px 22px; min-width: 190px; cursor: pointer; touch-action: manipulation;
}
button:active { transform: scale(0.97); }
button.primary { background: linear-gradient(90deg, var(--orange), var(--amber)); color: #1b1203; border: 0; font-size: 18px; }
button.icon { min-width: 0; width: 44px; height: 44px; padding: 0; border-radius: 12px; display: grid; place-items: center; }
.pauseIcon { width: 14px; height: 16px; border-left: 4px solid currentColor; border-right: 4px solid currentColor; display: block; }

#hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
#hud button { pointer-events: auto; }
#hud .bar {
  position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) 0 calc(12px + env(safe-area-inset-left));
}
.chip { background: rgba(5, 11, 22, 0.7); border: 1px solid rgba(34, 211, 238, 0.35); border-radius: 12px; padding: 8px 12px; font-weight: 600; }
.lives { color: #fb7185; letter-spacing: 2px; }
.time { margin-left: auto; font-variant-numeric: tabular-nums; min-width: 72px; text-align: center; color: var(--amber); font-size: 20px; }
.time.warn { color: #fb7185; }
#hud .hint { position: absolute; left: 0; right: 0; top: calc(64px + env(safe-area-inset-top)); text-align: center; color: var(--amber); font-weight: 600; text-shadow: 0 0 8px #000; }
#hud .bottom { position: absolute; left: 0; right: 0; bottom: calc(18px + env(safe-area-inset-bottom)); display: flex; justify-content: center; }

#joy { position: fixed; left: 0; top: 0; width: 112px; height: 112px; margin: -56px 0 0 -56px; border-radius: 50%; z-index: 4;
  border: 2px solid rgba(34, 211, 238, 0.5); background: rgba(34, 211, 238, 0.08); pointer-events: none; }
#joyKnob { position: absolute; left: 50%; top: 50%; width: 48px; height: 48px; margin: -24px 0 0 -24px; border-radius: 50%;
  background: rgba(252, 211, 77, 0.55); }

@media (orientation: landscape) {
  .screen.panel { justify-content: center; align-items: flex-end; }
  .card { width: min(420px, 46vw); }
}

/* Horizontal: el botón y el aviso van a los lados para dejar todo el alto al laberinto. */
@media (orientation: landscape) {
  #hud .bottom { left: auto; right: calc(16px + env(safe-area-inset-right)); width: auto; }
  #hud .hint { left: calc(16px + env(safe-area-inset-left)); right: auto; text-align: left; top: calc(72px + env(safe-area-inset-top)); }
}

/* Vuelo (solo abeja): botones grandes abajo a la derecha */
#flight { position: absolute; right: calc(14px + env(safe-area-inset-right)); bottom: calc(24px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px; z-index: 6; }
#flight .fly { min-width: 0; width: 64px; height: 64px; padding: 0; border-radius: 50%; display: grid; place-items: center;
  background: rgba(5, 11, 22, 0.6); touch-action: none; }
#flight .fly.on { background: rgba(252, 211, 77, 0.35); border-color: var(--amber); }
.arrow { width: 0; height: 0; border-left: 12px solid transparent; border-right: 12px solid transparent; display: block; }
.arrow.up { border-bottom: 16px solid var(--amber); }
.arrow.down { border-top: 16px solid var(--amber); }

/* Selección de personaje */
.screen.select { justify-content: flex-start; gap: 10px; z-index: 20; background: none; }
.select h2 { flex: none; }
.grid { flex: 1 1 auto; min-height: 0; width: min(760px, 100%); overflow-y: auto; overflow-x: hidden; touch-action: pan-y;
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; align-content: start; padding: 4px; overscroll-behavior: contain; }
@media (orientation: landscape) { .grid { grid-template-columns: repeat(3, 1fr); } }
.select .row { flex: none; display: flex; gap: 10px; }
.select .row button { min-width: 130px; }
.card3d { display: flex; flex-direction: column; padding: 0; min-width: 0; background: none; border: 2px solid rgba(34, 211, 238, 0.35);
  border-radius: 16px; overflow: hidden; text-align: center; touch-action: pan-y; }
.card3d .thumb { display: block; flex: none; height: clamp(96px, 17vh, 170px); }
#charGrid { grid-auto-rows: max-content; }
.card3d .info { display: flex; flex-direction: column; gap: 2px; padding: 6px 8px 8px; background: rgba(5, 11, 22, 0.86); }
.card3d .name { font-size: 16px; color: #e6fbff; }
.card3d .desc { font-size: 12px; font-weight: 400; opacity: 0.75; line-height: 1.25; }
.card3d[aria-checked="true"] { border-color: var(--amber); box-shadow: 0 0 18px rgba(252, 211, 77, 0.45); }
.card3d[aria-checked="true"] .name { color: var(--amber); }
button:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }
@media (orientation: landscape) and (max-height: 480px) {
  .card3d { flex-direction: row; align-items: center; text-align: left; }
  .card3d .thumb { width: 46%; height: clamp(84px, 28vh, 130px); }
  .card3d .info { flex: 1; min-width: 0; background: none; }
  .select h2 { font-size: 20px; margin: 0; }
}

/* Silencio */
.mute { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right)); }
.mute .slash { display: none; }
.mute.off .slash { display: block; }
.mute.off .waves { display: none; }

/* Destello al cruzar el portal (sin animación con movimiento reducido) */
#flash { position: fixed; inset: 0; z-index: 8; pointer-events: none; opacity: 0;
  background: radial-gradient(circle at 50% 45%, rgba(255, 244, 214, 0.95), rgba(252, 211, 77, 0.65) 45%, rgba(249, 115, 22, 0.25) 80%); }
#flash.on { animation: flash 0.55s ease-out; }
@keyframes flash { 0% { opacity: 0.95; } 100% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { #flash.on { animation: none; opacity: 0; } }

/* Foco visible y tamaño táctil mínimo de 44 px */
a:focus-visible, select:focus-visible, input:focus-visible, [tabindex]:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }
button, select { min-height: 44px; }
h2[tabindex]:focus { outline: none; }

/* Pantallas con desplazamiento (menú y diálogos): el contenido se centra y, si no cabe, se desplaza completo */
.screen.scroll { justify-content: flex-start; overflow-y: auto; overflow-x: hidden; touch-action: pan-y; overscroll-behavior: contain; }
.screen.scroll.solid { z-index: 30; }
#menu.scroll { z-index: 20; }
.sheet { margin: auto; width: min(420px, 100%); display: flex; flex-direction: column; align-items: center; gap: 14px; }
.menu .brand, .menu .actions { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.pair { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.pair button { min-width: 140px; }
@media (max-width: 360px) { .pair button { min-width: 120px; padding-inline: 14px; } h1 { font-size: 34px; } }
@media (orientation: landscape) and (max-height: 480px) {
  .menu.sheet { width: min(760px, 100%); flex-direction: row; justify-content: center; gap: 36px; }
  .menu .brand { flex: 0 1 auto; gap: 8px; }
  .menu .logo { width: min(34vh, 150px); }
  .menu h1 { font-size: 32px; }
  .menu .actions { gap: 8px; }
}

.closeBtn { position: fixed; top: calc(12px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right)); z-index: 2; }
.closeBtn .x { position: relative; width: 18px; height: 18px; display: block; }
.closeBtn .x::before, .closeBtn .x::after { content: ""; position: absolute; left: 50%; top: 50%; width: 20px; height: 3px; margin: -1.5px 0 0 -10px; background: currentColor; border-radius: 2px; transform: rotate(45deg); }
.closeBtn .x::after { transform: rotate(-45deg); }
.form { padding-top: 40px; padding-bottom: 8px; }
.field { width: 100%; display: flex; flex-direction: column; gap: 6px; text-align: left; }
.field label, .field > span { font-weight: 600; color: var(--amber); }
.field label b { margin-left: 4px; }
select, input[type="range"] { width: 100%; min-height: 44px; font: inherit; color: #e6fbff; background: rgba(34, 211, 238, 0.12); border: 1px solid var(--cyan); border-radius: 12px; padding: 8px 12px; }
select option { background: #0b2530; color: #e6fbff; }
input[type="range"] { padding: 0; background: none; border: 0; accent-color: var(--amber); }
button[role="switch"][aria-checked="true"] { border-color: var(--amber); background: rgba(252, 211, 77, 0.2); }
.steps { margin: 0; padding-left: 1.3em; text-align: left; display: flex; flex-direction: column; gap: 12px; line-height: 1.4; }
.steps li::marker { color: var(--amber); font-weight: 700; }

.about { gap: 12px; }
.appIcon { width: 96px; }
.about h2 { font-size: 30px; }
.stack { display: flex; flex-direction: column; gap: 10px; width: min(300px, 100%); }
.stack button { width: 100%; }
.dev { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 12px; border-radius: 16px;
  background: rgba(5, 11, 22, 0.55); border: 1px solid rgba(34, 211, 238, 0.3); }
.dev h3 { margin: 0 0 4px; font-size: 14px; letter-spacing: 1px; text-transform: uppercase; color: var(--amber); }
.devLogo { width: 64px; height: 64px; border-radius: 14px; }
.devName { font-size: 20px; font-weight: 700; }
.link { color: var(--cyan); min-height: 44px; display: inline-flex; align-items: center; padding: 0 10px; word-break: break-all; }
.selectable { -webkit-user-select: text; user-select: text; }

#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60; max-width: min(90vw, 420px);
  padding: 12px 18px; border-radius: 14px; background: rgba(5, 11, 22, 0.95); border: 1px solid var(--amber); color: #e6fbff; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity 0.2s; }
#toast.on { opacity: 1; }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }

/* Política de privacidad dentro de la app: marco bajo el botón cerrar, respetando las áreas seguras. */
.screen.privacy { padding-top: calc(64px + env(safe-area-inset-top)); z-index: 30; }
.privacy iframe { flex: 1; width: min(680px, 100%); border: 0; border-radius: 12px; background: #050b16; }
#nogl { gap: 18px; }
#nogl p { max-width: 460px; }

/* Menú con progreso: «Nuevo juego» y «Elegir nivel» en pareja; etiqueta de juego completo */
.fullTag, .fullState { font-weight: 600; color: var(--amber); }
.fullState { font-size: 14px; opacity: 0.9; }
.fullState:not(.on) { color: #e6fbff; opacity: 0.7; }
.fullTag.free { color: #e6fbff; opacity: 0.75; }

/* Compra abierta desde el menú: tapa el menú como un diálogo */
.screen.panel.over { z-index: 40; justify-content: center; align-items: center; pointer-events: auto; background: radial-gradient(120% 90% at 30% 10%, #0b2530, #050b16 70%); }
.screen.panel.over .card { width: min(420px, 100%); }

/* Elegir nivel */
.levelGrid { width: 100%; display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.levelGrid button { min-width: 0; padding: 10px 0; font-size: 20px; }
.levelGrid button.cur { border-color: var(--amber); background: rgba(252, 211, 77, 0.2); color: var(--amber); }
.levelGrid button.lock { display: inline-flex; align-items: center; justify-content: center; gap: 4px; border-color: rgba(252, 211, 77, 0.6); color: var(--amber); }
@media (orientation: landscape) { .levelGrid { grid-template-columns: repeat(6, 1fr); } }
@media (orientation: landscape) and (max-height: 480px) {
  #levels .form { padding-top: 8px; gap: 8px; }
  #levels h2 { font-size: 20px; }
  .menu .actions button, .menu .actions .pair button { min-height: 40px; padding-block: 8px; }
  .menu .actions .fullTag { margin: 0; }
}
