/* ============================================================
 * RANA LEOPARDO — Corn Island Adventure
 * style.css
 * ------------------------------------------------------------
 * Tema pastel Caribe: HUD, menús, overlays, botones y estilos
 * responsive (optimizado para móvil).
 * ============================================================ */

/* Los atributos `hidden` deben ganar SIEMPRE. Si una clase como
 * .overlay, .menu o .hud define `display: flex`, anula el
 * `display: none` del atributo hidden del navegador y las ventanas
 * modales se ven desde el arranque (bug: "ventana de victoria al
 * entrar"). Esta regla global lo garantiza. */
[hidden] {
  display: none !important;
}

:root {
  --coral: #ff8c94;
  --coral-dark: #f26a75;
  --sky: #7fc8ee;
  --sky-dark: #4fa8d8;
  --sand: #fff6dd;
  --ink: #5b4a52;
  --ink-soft: #8a7b84;
  --card: rgba(255, 255, 255, 0.92);
  --shadow: 0 10px 30px rgba(120, 90, 60, 0.18);
  --radius: 20px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #dff0ff;
  font-family: 'Quicksand', 'Baloo 2', 'Comic Sans MS', 'Segoe UI', sans-serif;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

/* ---------- Canvas ---------- */
#game {
  position: fixed;
  inset: 0;
  display: block;
  touch-action: none;
}

/* ---------- Capa UI ---------- */
#ui-root {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

#ui-root button {
  pointer-events: auto;
}

/* ============================================================
 * HUD
 * ============================================================ */
.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  padding: calc(10px + env(safe-area-inset-top)) 14px calc(10px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.hud-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  pointer-events: auto;
}

.chip {
  background: var(--card);
  border-radius: 999px;
  padding: 6px 14px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.chip-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}

.chip-value {
  font-size: 15px;
  color: var(--ink);
}

.hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.score-box {
  background: var(--card);
  border-radius: 999px;
  padding: 6px 18px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 17px;
  color: var(--ink);
}

.score-icon {
  color: #ffb03a;
  font-size: 14px;
}

.stars {
  display: flex;
  gap: 4px;
}

.star {
  font-size: 26px;
  color: rgba(120, 110, 100, 0.35);
  transition: transform 0.25s ease, color 0.25s ease;
  display: inline-block;
}

.star.earned {
  color: #ffb03a;
  text-shadow: 0 2px 8px rgba(255, 176, 58, 0.5);
  animation: starPop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Objetivo de estrellas del nivel (p.ej. ★ 1200 ★★ 1800 ★★★ 2400) */
.hud-goal {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.55);
  border-radius: 999px;
  padding: 2px 10px;
  white-space: nowrap;
  max-width: min(58vw, 240px);
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Récord del nivel (best score persistido en localStorage) */
.hud-best {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #b8860b;
  background: rgba(255, 244, 214, 0.85);
  border-radius: 999px;
  padding: 2px 10px;
  white-space: nowrap;
  box-shadow: inset 0 0 0 1px rgba(184, 134, 11, 0.25);
}

@keyframes starPop {
  0% { transform: scale(0) rotate(-40deg); }
  70% { transform: scale(1.35) rotate(8deg); }
  100% { transform: scale(1) rotate(0); }
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.frogs-left {
  display: flex;
  gap: 2px;
  background: var(--card);
  border-radius: 999px;
  padding: 5px 10px;
  box-shadow: var(--shadow);
}

.frog-icon {
  display: block;
  filter: drop-shadow(0 2px 2px rgba(80, 60, 30, 0.25));
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 19px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
  display: grid;
  place-items: center;
}

.icon-btn:hover { transform: translateY(-2px) scale(1.06); background: #ffffff; }
.icon-btn:active { transform: scale(0.92); }

.hud-bottom {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: auto;
}

/* Nombre del nivel: aparece destacado al entrar y se oculta a los ~3 s
 * (la clase .hide lo desvanece; el motor lo añade con un temporizador).
 * Se coloca BAJO la fila del HUD para no tapar estrellas/puntaje. */
.hud-name {
  position: absolute;
  top: calc(118px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: rgba(255, 255, 255, 0.85);
  padding: 5px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 800;
  color: var(--ink);
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(120, 90, 60, 0.16);
  transition: opacity 0.6s ease, transform 0.6s ease;
  pointer-events: none;
  z-index: 2;
}

.hud-name.hide {
  opacity: 0;
  transform: translateX(-50%) translateY(-8px);
}

/* ============================================================
 * Botones
 * ============================================================ */
.btn {
  border: none;
  border-radius: 999px;
  padding: 10px 22px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease, filter 0.16s ease;
  box-shadow: 0 6px 16px rgba(90, 70, 50, 0.18);
}

.btn:hover { transform: translateY(-3px); filter: brightness(1.05); }
.btn:active { transform: translateY(0) scale(0.96); }
.btn:disabled { opacity: 0.45; transform: none; cursor: default; }

.btn-primary {
  background: linear-gradient(180deg, #ffa07a, var(--coral));
  color: #fff;
  text-shadow: 0 1px 2px rgba(140, 50, 40, 0.3);
}

.btn-primary:hover { box-shadow: 0 10px 22px rgba(255, 120, 100, 0.4); }

.btn-ghost {
  background: var(--card);
  color: var(--ink);
}

.btn-ghost:hover { background: #ffffff; }

.btn-big {
  font-size: 19px;
  padding: 14px 44px;
  letter-spacing: 0.04em;
}

/* ============================================================
 * Menú principal
 * ============================================================ */
.menu {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  background: linear-gradient(180deg, rgba(255, 219, 233, 0.55), rgba(223, 240, 255, 0.35) 60%, rgba(255, 246, 221, 0.45));
  text-align: center;
}

.menu-hero {
  animation: frogBounce 2.4s ease-in-out infinite;
  filter: drop-shadow(0 14px 18px rgba(80, 60, 30, 0.25));
}

@keyframes frogBounce {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-16px) rotate(3deg); }
}

.menu-title {
  font-size: clamp(34px, 7vw, 58px);
  font-weight: 900;
  color: var(--ink);
  line-height: 1.05;
  text-shadow: 0 3px 0 #ffffff, 0 6px 18px rgba(120, 90, 60, 0.25);
}

.menu-title span {
  color: var(--coral);
}

.menu-subtitle {
  font-size: clamp(13px, 2.6vw, 17px);
  color: var(--ink-soft);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.level-select {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  max-width: 460px;
  width: 100%;
  margin-top: 6px;
}

.level-card {
  border: none;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  padding: 10px 8px;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.level-card:hover { transform: translateY(-4px) scale(1.03); box-shadow: 0 14px 26px rgba(120, 90, 60, 0.22); }
.level-card:active { transform: scale(0.95); }

.level-card.locked {
  opacity: 0.55;
  cursor: default;
  filter: grayscale(0.5);
}

.level-card.locked:hover { transform: none; }

.level-num {
  font-size: 22px;
  font-weight: 900;
  color: var(--sky-dark);
}

.level-name {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ink-soft);
}

.level-stars-mini {
  font-size: 13px;
  color: #ffb03a;
  letter-spacing: 1px;
}

/* Mejor puntaje por nivel en el selector */
.level-best {
  font-size: 11px;
  font-weight: 800;
  color: #b8860b;
  letter-spacing: 0.02em;
  min-height: 13px;
}

.menu-toggles {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.menu-hint {
  font-size: 12.5px;
  color: var(--ink-soft);
  font-weight: 600;
  margin-top: 4px;
}

/* ============================================================
 * Overlay (victoria / derrota)
 * ============================================================ */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(60, 40, 70, 0.35);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fadeIn 0.35s ease;
  pointer-events: auto;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.overlay-card {
  background: var(--card);
  border-radius: 28px;
  box-shadow: 0 20px 50px rgba(80, 50, 40, 0.3);
  padding: 30px 36px;
  text-align: center;
  max-width: 400px;
  width: calc(100% - 40px);
  animation: cardIn 0.5s cubic-bezier(0.34, 1.4, 0.64, 1);
}

@keyframes cardIn {
  from { transform: translateY(40px) scale(0.9); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.overlay-title {
  font-size: 34px;
  font-weight: 900;
  color: var(--ink);
  margin-bottom: 8px;
}

.overlay.win .overlay-title { color: #3f9e4d; }
.overlay.lose .overlay-title { color: var(--coral-dark); }

.overlay-stars {
  font-size: 46px;
  letter-spacing: 6px;
  margin: 10px 0;
  min-height: 54px;
}

.star.big {
  font-size: 46px;
  animation: none;
}

.star.big.earned {
  animation: starBigPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  animation-delay: calc(var(--i, 0) * 0.18s);
}

@keyframes starBigPop {
  0% { transform: scale(0) rotate(-90deg); opacity: 0; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.overlay-score {
  font-size: 17px;
  font-weight: 800;
  color: var(--ink-soft);
  margin-bottom: 10px;
}

/* Información extra en overlays (p.ej. enemigos restantes al perder) */
.overlay-info {
  font-size: 14px;
  font-weight: 700;
  color: var(--coral-dark);
  margin-bottom: 16px;
}

/* Récord de puntuación en la victoria */
.overlay-record {
  font-size: 15px;
  font-weight: 800;
  color: #b8860b;
  margin-bottom: 16px;
  min-height: 18px;
}

.overlay-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

/* ============================================================
 * Toast + hint de rotación
 * ============================================================ */
.toast {
  position: absolute;
  bottom: calc(90px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(255, 255, 255, 0.95);
  color: var(--ink);
  font-weight: 700;
  font-size: 14px;
  padding: 10px 20px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Aviso de rotación NO bloqueante: pastilla flotante que no
 * intercepta clics (pointer-events: none) y se auto-oculta. */
.rotate-hint {
  position: absolute;
  bottom: calc(76px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(14px);
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.94);
  border: 2px solid rgba(255, 140, 148, 0.35);
  border-radius: 999px;
  box-shadow: var(--shadow);
  padding: 8px 18px;
  z-index: 30;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  white-space: nowrap;
  transition: opacity 0.4s ease, transform 0.4s ease, visibility 0s linear 0.4s;
}

.rotate-hint.show {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.rotate-icon {
  font-size: 22px;
  animation: rotateHint 1.6s ease-in-out infinite;
}

@keyframes rotateHint {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(90deg); }
}

.rotate-hint p {
  font-size: 13px;
  font-weight: 800;
  color: var(--ink);
}

/* ============================================================
 * Responsive
 * ============================================================ */
@media (max-width: 720px) {
  .chip-value { font-size: 13px; }
  .chip { padding: 5px 11px; }
  .score-box { font-size: 14px; padding: 5px 13px; }
  .star { font-size: 21px; }
  .icon-btn { width: 38px; height: 38px; font-size: 16px; }
  .btn { padding: 8px 16px; font-size: 13.5px; }
  .hud-name { top: calc(96px + env(safe-area-inset-top)); font-size: 12.5px; }
  .overlay-card { padding: 22px 20px; }
  .overlay-title { font-size: 27px; }
  .star.big { font-size: 38px; }
  .overlay-stars { font-size: 38px; }
  .level-card { padding: 8px 4px; }
  .level-num { font-size: 18px; }
}

@media (max-height: 560px) {
  .menu-hero { display: none; }
  .menu { gap: 8px; }
  .level-select { grid-template-columns: repeat(6, 1fr); max-width: 640px; }
  .menu-hint { display: none; }
}
