:root {
  color-scheme: light;
  font-family: "Trebuchet MS", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #8fe5ff;
  color: #223047;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  background:
    radial-gradient(circle at 78% 12%, rgba(255, 245, 158, 0.75), transparent 20%),
    linear-gradient(#83ddff, #dffbff 58%, #fff1d4);
}

.menu-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  overflow: auto;
  touch-action: auto;
}

.menu-card {
  width: min(760px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: clamp(20px, 5vw, 42px);
  border: 4px solid rgba(34, 48, 71, 0.9);
  border-radius: 28px;
  background: linear-gradient(#fff9dc, #ffeeb7);
  box-shadow: 0 22px 0 rgba(91, 71, 54, 0.16), 0 30px 60px rgba(50, 80, 120, 0.22);
}

.eyebrow { margin: 0 0 8px; font-weight: 900; color: #ff8a1e; text-transform: uppercase; letter-spacing: 0.08em; }
.menu-card h1 { margin: 0; font-size: clamp(2rem, 9vw, 4.5rem); line-height: 0.95; }
.menu-subtitle { margin: 14px 0 28px; max-width: 540px; font-size: clamp(1rem, 3vw, 1.25rem); font-weight: 650; color: #4c6075; }
.menu-card h2 { margin: 0 0 12px; font-size: 1.15rem; }
.level-list {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, minmax(92px, 1fr));
  gap: 38px 22px;
  margin: 18px 0 16px;
  padding: 34px 14px 30px;
  border-radius: 26px;
  background:
    radial-gradient(circle at 18% 18%, rgba(255,255,255,0.55), transparent 13%),
    radial-gradient(circle at 78% 28%, rgba(255,243,143,0.65), transparent 15%),
    linear-gradient(#a9edff, #eaffff 58%, #aeea67);
  overflow: hidden;
}

.level-list::before {
  content: "";
  position: absolute;
  inset: 70px 48px 62px;
  border: 12px dotted rgba(255, 159, 28, 0.48);
  border-left-color: transparent;
  border-right-color: transparent;
  border-radius: 50%;
  transform: rotate(-10deg);
}

.level-node {
  position: relative;
  z-index: 1;
  display: grid;
  justify-items: center;
  gap: 5px;
  border: 0;
  background: transparent;
  color: #223047;
  cursor: pointer;
  font-family: inherit;
}

.level-node:nth-child(3n + 2) { transform: translateY(30px); }
.level-node:nth-child(3n) { transform: translateY(-6px); }
.level-node:hover .level-badge { transform: translateY(-3px) scale(1.04); }

.plane-sticker {
  position: absolute;
  top: -20px;
  right: calc(50% - 58px);
  width: 58px;
  height: 42px;
  transform: rotate(-12deg);
  filter: drop-shadow(0 5px 0 rgba(47, 70, 92, 0.18));
}

.plane-sticker::before {
  content: "";
  position: absolute;
  inset: 7px 4px 8px;
  background: linear-gradient(135deg, hsl(var(--plane-hue) 95% 70%), hsl(calc(var(--plane-hue) + 35deg) 95% 50%));
  clip-path: polygon(0 48%, 100% 0, 76% 50%, 100% 100%);
  border-radius: 7px;
}

.plane-sticker::after {
  content: "";
  position: absolute;
  left: 18px;
  top: 14px;
  width: 20px;
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  transform: rotate(-18deg);
}

.level-node:nth-child(2n) .plane-sticker { left: calc(50% - 58px); right: auto; transform: scaleX(-1) rotate(-10deg); }
.level-node:nth-child(3n) .plane-sticker { top: -26px; transform: rotate(18deg); }

.level-badge {
  display: grid;
  place-items: center;
  width: 82px;
  height: 82px;
  border: 5px solid #ffffff;
  border-radius: 50%;
  background: linear-gradient(#54d9ff, #237dff);
  color: #ffffff;
  font-size: 2rem;
  font-weight: 950;
  box-shadow: 0 7px 0 rgba(24, 91, 165, 0.55), 0 13px 24px rgba(50, 80, 120, 0.24);
  transition: transform 0.12s ease;
}

.level-node:nth-child(4n + 2) .level-badge { background: linear-gradient(#ffda64, #ff8a1e); box-shadow: 0 7px 0 rgba(177, 91, 18, 0.55), 0 13px 24px rgba(50, 80, 120, 0.24); }
.level-node:nth-child(4n + 3) .level-badge { background: linear-gradient(#9cff6a, #34bf54); box-shadow: 0 7px 0 rgba(35, 126, 55, 0.55), 0 13px 24px rgba(50, 80, 120, 0.24); }
.level-node:nth-child(4n) .level-badge { background: linear-gradient(#ff9eda, #e651a7); box-shadow: 0 7px 0 rgba(161, 48, 111, 0.55), 0 13px 24px rgba(50, 80, 120, 0.24); }

.level-name {
  max-width: 120px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(255, 249, 220, 0.88);
  font-weight: 950;
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.level-meta {
  color: #60758c;
  font-weight: 850;
  font-size: 0.72rem;
}

.game-shell {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  background: #83ddff;
}

canvas {
  position: absolute;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  display: block;
  object-fit: cover;
  touch-action: none;
  cursor: crosshair;
}

.hud {
  position: absolute;
  z-index: 5;
  pointer-events: none;
}

.hud-top {
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.level-pill {
  justify-self: center;
  max-width: min(560px, 70vw);
  padding: 9px 16px;
  border: 3px solid rgba(34, 48, 71, 0.82);
  border-radius: 999px;
  background: linear-gradient(#fff9dc, #ffeeb7);
  box-shadow: 0 6px 0 rgba(91, 71, 54, 0.14), 0 10px 24px rgba(50, 80, 120, 0.18);
  text-align: center;
}

.level-pill strong { display: block; line-height: 1; font-size: clamp(0.9rem, 2.4vw, 1.2rem); }
.level-pill span { display: block; margin-top: 2px; color: #4c6075; font-weight: 800; font-size: clamp(0.68rem, 1.8vw, 0.9rem); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-button, button {
  pointer-events: auto;
  border: 0;
  border-radius: 18px;
  min-width: 52px;
  min-height: 52px;
  padding: 8px 14px;
  font-size: 1.55rem;
  font-weight: 950;
  color: white;
  background: linear-gradient(#54d9ff, #237dff);
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.55), 0 5px 0 rgba(24, 91, 165, 0.55), 0 10px 22px rgba(50, 80, 120, 0.2);
  cursor: pointer;
}
.icon-button:active, button:active { transform: translateY(3px); box-shadow: inset 0 2px 0 rgba(255,255,255,0.55), 0 2px 0 rgba(24, 91, 165, 0.55); }
#resetButton { background: linear-gradient(#ffcf5a, #ff8a1e); box-shadow: inset 0 2px 0 rgba(255,255,255,0.55), 0 5px 0 rgba(177, 91, 18, 0.62), 0 10px 22px rgba(50, 80, 120, 0.2); }
#menuButton { background: linear-gradient(#8fa0b7, #596579); box-shadow: inset 0 2px 0 rgba(255,255,255,0.45), 0 5px 0 rgba(62, 72, 90, 0.62), 0 10px 22px rgba(50, 80, 120, 0.2); }

.launch-hint {
  position: absolute;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 4;
  max-width: 88vw;
  padding: 9px 14px;
  border-radius: 999px;
  background: rgba(255, 249, 220, 0.86);
  border: 2px solid rgba(223, 180, 106, 0.9);
  color: #40566e;
  font-weight: 900;
  font-size: clamp(0.78rem, 2vw, 0.95rem);
  pointer-events: none;
  text-align: center;
}

@media (orientation: portrait) {
  .game-shell::after {
    content: "Gira el móvil para jugar en horizontal";
    position: absolute;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    padding: 32px;
    background: linear-gradient(#83ddff, #dffbff);
    color: #223047;
    text-align: center;
    font-size: 1.6rem;
    font-weight: 950;
  }
}

@media (max-height: 430px) and (orientation: landscape) {
  .level-pill { padding: 6px 12px; }
  .icon-button { min-width: 44px; min-height: 44px; font-size: 1.25rem; border-radius: 14px; }
  .launch-hint { display: none; }
}
