:root {
  --ink: #072734;
  --panel: rgba(3, 28, 39, .88);
  --cream: #fff8e7;
  --gold: #ffd45c;
  --line: rgba(255,255,255,.22);
}

* { box-sizing: border-box; }
html, body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: #031f2b;
}
body {
  color: var(--cream);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}
button { font: inherit; }

#app {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  min-height: 100svh;
  overflow: hidden;
  isolation: isolate;
  background: #071f29;
}
#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: #071f29;
}

.topbar {
  position: absolute;
  z-index: 20;
  top: max(8px, env(safe-area-inset-top));
  left: max(8px, env(safe-area-inset-left));
  right: max(8px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}
.brand,
.toolbar > button,
.metric,
.scene-badge {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(10,52,69,.72), rgba(2,33,46,.56));
  backdrop-filter: blur(12px) saturate(1.15);
}
.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 9px;
  border-radius: 13px;
}
.brand-icon { font-size: 20px; }
.brand strong {
  display: block;
  white-space: nowrap;
  font-size: 9px;
  letter-spacing: .10em;
}
.brand small {
  display: block;
  margin-top: 3px;
  white-space: nowrap;
  font-size: 6px;
  letter-spacing: .14em;
  opacity: .75;
}
.toolbar {
  display: flex;
  align-items: center;
  gap: 5px;
  pointer-events: auto;
}
.toolbar button {
  color: white;
  cursor: pointer;
}
.round-button {
  width: 34px;
  height: 34px;
  border-radius: 50%;
}
.pill-button {
  min-width: 74px;
  height: 34px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 8px;
  font-weight: 900;
  letter-spacing: .07em;
}

.hud {
  position: absolute;
  z-index: 12;
  top: max(54px, calc(env(safe-area-inset-top) + 48px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 7px;
  pointer-events: none;
}
.metric {
  min-width: 67px;
  padding: 6px 9px 7px;
  border-radius: 12px;
  text-align: center;
}
.metric span {
  display: block;
  font-size: 7px;
  font-weight: 900;
  letter-spacing: .15em;
  opacity: .75;
}
.metric strong {
  display: block;
  margin-top: 1px;
  font-size: 21px;
  line-height: 1;
}
.metric:last-child strong { color: var(--gold); }

.scene-badge {
  position: absolute;
  z-index: 12;
  top: max(96px, calc(env(safe-area-inset-top) + 90px));
  left: 50%;
  transform: translateX(-50%);
  width: min(88vw, 300px);
  padding: 7px 10px 8px;
  border-radius: 15px;
  text-align: center;
  pointer-events: none;
}
.scene-badge span,
.scene-badge small {
  display: block;
  font-size: 7px;
  letter-spacing: .18em;
  opacity: .74;
}
.scene-badge strong {
  display: block;
  margin: 2px 0;
  font-size: 12px;
}

.panel {
  position: absolute;
  z-index: 30;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(94vw, 620px);
  max-height: min(88dvh, 760px);
  overflow: auto;
  padding: 18px 14px 16px;
  border: 1px solid rgba(255,255,255,.27);
  border-radius: 21px;
  background: radial-gradient(circle at 50% 0%, rgba(72,157,96,.24), transparent 38%), radial-gradient(circle at 50% 120%, rgba(255,212,92,.08), transparent 36%), var(--panel);
  text-align: center;
}
.panel.compact { width: min(91vw, 430px); }
.panel h1 {
  margin: 8px auto 8px;
  max-width: 560px;
  font-size: clamp(24px, 8vw, 38px);
  line-height: 1;
  letter-spacing: -.045em;
}
.panel h2 {
  margin: 9px 0 12px;
  font-size: clamp(27px, 7vw, 38px);
  line-height: 1;
}
.eyebrow {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 999px;
  color: #173029;
  background: var(--gold);
  font-size: 8px;
  font-weight: 950;
  letter-spacing: .14em;
}
.lead {
  margin: 0 auto 12px;
  max-width: 540px;
  color: rgba(255,248,231,.78);
  font-size: 11px;
  line-height: 1.4;
}
.species-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 9px;
  margin: 13px 0;
}
.species-card {
  min-width: 0;
  display: grid;
  grid-template-columns: 92px 1fr;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 17px;
  color: white;
  background: rgba(255,255,255,.06);
  text-align: left;
  cursor: pointer;
}
.species-card.selected {
  border-color: var(--gold);
  background: rgba(255,212,92,.13);
}
.sprite-stage {
  display: grid;
  place-items: center;
  height: 78px;
  overflow: hidden;
  border-radius: 12px;
  background: rgba(255,255,255,.045);
}
.sprite-stage img {
  display: block;
  max-width: 98%;
  max-height: 72px;
  object-fit: contain;
  image-rendering: auto;
  filter: none;
}
.species-card strong {
  display: block;
  margin-top: 0;
  font-size: 14px;
}
.species-card small {
  display: block;
  margin-top: 3px;
  color: rgba(255,255,255,.65);
  font-size: 10px;
}
.primary-button,
.secondary-button {
  width: 100%;
  min-height: 46px;
  border-radius: 14px;
  cursor: pointer;
  font-weight: 950;
  letter-spacing: .06em;
}
.primary-button {
  border: 0;
  color: #102d30;
  background: linear-gradient(#ffe37d,#ffc83f);
}
.primary-button:disabled { opacity: .55; cursor: wait; }
.secondary-button {
  margin-top: 9px;
  border: 1px solid rgba(255,255,255,.2);
  color: white;
  background: rgba(255,255,255,.07);
}
.load-status {
  min-height: 17px;
  margin-top: 11px;
  color: rgba(255,255,255,.73);
  font-size: 10px;
}
.controls-help {
  margin-top: 5px;
  color: rgba(255,255,255,.48);
  font-size: 9px;
}
.results {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin: 15px 0;
}
.results div {
  padding: 11px;
  border-radius: 15px;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.12);
}
.results span { display: block; font-size: 8px; letter-spacing: .15em; opacity: .65; }
.results strong { display: block; margin-top: 4px; font-size: 29px; color: var(--gold); }

.municipal-ad {
  position: absolute;
  z-index: 10;
  left: max(8px, env(safe-area-inset-left));
  bottom: max(8px, env(safe-area-inset-bottom));
  min-width: 126px;
  padding: 6px 8px;
  border-radius: 9px;
  color: #17343b;
  background: rgba(255,249,226,.92);
  border-top: 5px solid #f4cd58;
  pointer-events: none;
}
.municipal-ad span,
.municipal-ad strong { display: block; text-align: center; }
.municipal-ad span { font-size: 7px; font-weight: 800; letter-spacing: .11em; }
.municipal-ad strong { margin-top: 1px; font-size: 11px; }
.error-toast {
  position: absolute;
  z-index: 50;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  max-width: 90vw;
  padding: 10px 14px;
  border-radius: 12px;
  background: #7a2323;
  color: white;
  font-size: 12px;
}
.hidden { display: none !important; }

@media (min-width: 700px) {
  .topbar { top: max(12px, env(safe-area-inset-top)); left: max(14px, env(safe-area-inset-left)); right: max(14px, env(safe-area-inset-right)); }
  .brand { gap: 10px; padding: 9px 13px; border-radius: 16px; }
  .brand-icon { font-size: 25px; }
  .brand strong { font-size: 12px; letter-spacing: .13em; }
  .brand small { font-size: 8px; letter-spacing: .18em; }
  .toolbar { gap: 8px; }
  .round-button { width: 43px; height: 43px; }
  .pill-button { min-width: 142px; height: 43px; padding: 0 16px; font-size: 11px; }
  .hud { top: max(78px, calc(env(safe-area-inset-top) + 70px)); gap: 10px; }
  .metric { min-width: 86px; padding: 8px 14px 9px; border-radius: 14px; }
  .metric strong { font-size: 27px; }
  .scene-badge { top: max(137px, calc(env(safe-area-inset-top) + 128px)); width: min(86vw, 355px); padding: 9px 14px 10px; border-radius: 18px; }
  .scene-badge strong { font-size: 15px; }
  .panel { padding: 27px; border-radius: 28px; }
  .species-grid { grid-template-columns: 1fr 1fr; gap: 12px; margin: 17px 0; }
  .species-card { display: block; padding: 12px 12px 15px; text-align: center; }
  .sprite-stage { height: 145px; }
  .sprite-stage img { max-height: 132px; }
  .species-card strong { margin-top: 9px; font-size: 16px; }
  .species-card small { font-size: 11px; }
  .lead { font-size: 13px; margin-bottom: 18px; }
  .primary-button, .secondary-button { min-height: 51px; }
  .municipal-ad { min-width: 170px; padding: 9px 15px; border-top-width: 7px; left: max(14px, env(safe-area-inset-left)); bottom: max(13px, env(safe-area-inset-bottom)); }
  .municipal-ad span { font-size: 9px; }
  .municipal-ad strong { font-size: 13px; }
}

@media (max-height: 620px) and (orientation: landscape) {
  .panel { width: min(86vw, 760px); padding: 15px 18px 13px; }
  .panel h1 { font-size: 28px; }
  .lead { margin-bottom: 8px; font-size: 10px; }
  .species-grid { margin: 8px 0; }
  .sprite-stage { height: 78px; }
  .sprite-stage img { max-height: 72px; }
  .controls-help { display: none; }
}

@supports not (height: 100dvh) {
  #app { height: 100vh; }
}


.scene-badge.scene-change {
  animation: sceneReveal .62s cubic-bezier(.2,.8,.2,1);
}
@keyframes sceneReveal {
  0% { opacity: .22; transform: translateX(-50%) translateY(8px) scale(.96); }
  55% { opacity: 1; transform: translateX(-50%) translateY(-2px) scale(1.015); }
  100% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .scene-badge.scene-change { animation: none; }
}

/* Game12 v13: HUD móvil, zonas de cinco niveles y transición de ruta */
.topbar,
.brand,
.scene-badge,
.hud,
.toolbar button {
  transition: opacity .22s ease, transform .22s ease, top .22s ease, left .22s ease, width .22s ease;
}

body.is-playing .topbar {
  left: auto;
  width: auto;
  justify-content: flex-end;
}
body.is-playing .brand,
body.is-playing #speciesBtn,
body.is-playing #soundBtn,
body.is-playing #fullscreenBtn {
  display: none;
}
body.is-playing .hud {
  top: max(9px, env(safe-area-inset-top));
}
body.is-playing .metric {
  min-width: 58px;
  padding: 5px 8px 6px;
  background: rgba(2, 28, 39, .54);
}
body.is-playing .metric strong { font-size: 19px; }
body.is-playing .metric span { font-size: 6px; }
body.is-playing .scene-badge {
  top: max(9px, env(safe-area-inset-top));
  left: max(8px, env(safe-area-inset-left));
  transform: none;
  width: auto;
  min-width: 132px;
  max-width: 42vw;
  padding: 6px 9px 7px;
  border-radius: 12px;
  text-align: left;
  background: rgba(2, 28, 39, .54);
}
body.is-playing .scene-badge span { display: none; }
body.is-playing .scene-badge strong {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 10px;
  margin: 0 0 2px;
}
body.is-playing .scene-badge small {
  font-size: 7px;
  color: var(--gold);
  opacity: .92;
}
body.is-playing .round-button {
  width: 36px;
  height: 36px;
  background: rgba(2, 28, 39, .62);
}

.zone-intro {
  position: absolute;
  z-index: 24;
  top: 24%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(78vw, 390px);
  padding: 10px 14px 11px;
  border: 1px solid rgba(255,255,255,.26);
  border-radius: 20px;
  color: var(--cream);
  background: linear-gradient(135deg, rgba(2, 25, 35, .86), rgba(4, 51, 60, .72));
  backdrop-filter: blur(12px) saturate(1.15);
  text-align: center;
  pointer-events: none;
  animation: zoneIntro 1.25s cubic-bezier(.2,.8,.2,1) both;
}
.zone-intro span,
.zone-intro small {
  display: block;
  font-size: 8px;
  font-weight: 900;
  letter-spacing: .18em;
  color: var(--gold);
}
.zone-intro strong {
  display: block;
  margin: 5px 0 4px;
  font-size: clamp(21px, 7vw, 38px);
  line-height: .98;
  letter-spacing: -.035em;
  text-wrap: balance;
}
@keyframes zoneIntro {
  0% { opacity: 0; transform: translate(-50%, -45%) scale(.94); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.015); }
  72% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -55%) scale(.985); }
}

.restart-hint {
  display: block;
  margin-top: 12px;
  color: rgba(255,255,255,.52);
  font-size: 9px;
}

body.is-playing .scene-badge.scene-change {
  animation: playingBadge .5s cubic-bezier(.2,.8,.2,1);
}
@keyframes playingBadge {
  0% { opacity: .2; transform: translateY(5px) scale(.96); }
  60% { opacity: 1; transform: translateY(-1px) scale(1.02); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@media (min-width: 700px) {
  .zone-intro { top: 46%; width: min(72vw, 440px); padding: 14px 18px 15px; }
  body.is-playing .scene-badge {
    left: max(14px, env(safe-area-inset-left));
    min-width: 180px;
    padding: 8px 12px 9px;
  }
  body.is-playing .scene-badge strong { font-size: 13px; }
  body.is-playing .scene-badge small { font-size: 8px; }
  body.is-playing .hud { top: max(12px, env(safe-area-inset-top)); }
  body.is-playing .metric { min-width: 74px; padding: 7px 12px 8px; }
  body.is-playing .metric strong { font-size: 24px; }
  body.is-playing .round-button { width: 42px; height: 42px; }
}

@media (prefers-reduced-motion: reduce) {
  .zone-intro { animation-duration: .01ms; }
  body.is-playing .scene-badge.scene-change { animation: none; }
}

#app::after { content:''; position:absolute; inset:0; pointer-events:none; background: radial-gradient(circle at 50% -8%, rgba(255,255,255,.09), transparent 30%), linear-gradient(180deg, rgba(255,255,255,.02), rgba(255,255,255,0)); z-index:1; mix-blend-mode: screen; }


.power-badge,
.phrase-toast {
  position: absolute;
  z-index: 22;
  border: 1px solid rgba(255,255,255,.24);
  background: linear-gradient(180deg, rgba(10,52,69,.80), rgba(2,33,46,.66));
  backdrop-filter: blur(12px) saturate(1.15);
  color: var(--cream);
  pointer-events: none;
}
.power-badge {
  top: max(142px, calc(env(safe-area-inset-top) + 138px));
  right: max(8px, env(safe-area-inset-right));
  min-width: 122px;
  max-width: 40vw;
  padding: 7px 10px 8px;
  border-radius: 14px;
  text-align: right;
}
.power-badge span,
.power-badge small {
  display: block;
  font-size: 7px;
  letter-spacing: .16em;
  opacity: .76;
}
.power-badge strong {
  display: block;
  margin: 2px 0;
  color: var(--gold);
  font-size: 10px;
  line-height: 1.1;
}
.phrase-toast {
  left: 50%;
  bottom: max(12px, calc(env(safe-area-inset-bottom) + 12px));
  transform: translateX(-50%);
  max-width: min(90vw, 560px);
  padding: 10px 14px;
  border-radius: 999px;
  text-align: center;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .01em;
  box-shadow: 0 10px 24px rgba(0,0,0,.18);
}
body.is-playing .power-badge {
  top: max(9px, env(safe-area-inset-top));
  right: max(52px, calc(env(safe-area-inset-right) + 46px));
  background: rgba(2, 28, 39, .56);
}
body.is-playing .phrase-toast {
  bottom: max(8px, calc(env(safe-area-inset-bottom) + 8px));
  font-size: 10px;
  padding: 8px 12px;
}
@media (min-width: 700px) {
  .power-badge {
    top: max(186px, calc(env(safe-area-inset-top) + 174px));
    min-width: 154px;
    max-width: 250px;
    padding: 9px 13px 10px;
  }
  .power-badge strong { font-size: 13px; }
  .phrase-toast { font-size: 13px; }
  body.is-playing .power-badge {
    top: max(12px, env(safe-area-inset-top));
    right: max(58px, calc(env(safe-area-inset-right) + 50px));
  }
}
