:root {
  --bg: #050816;
  --panel: rgba(6, 18, 58, 0.78);
  --panel2: rgba(8, 38, 91, 0.8);
  --line: rgba(127, 242, 255, 0.44);
  --text: #eaffff;
  --muted: rgba(234, 255, 255, 0.76);
  --accent: #49f5ff;
  --accent2: #a7ff3f;
  --danger: #ff3d6e;
  --shadow: 0 22px 80px rgba(0, 0, 0, 0.42);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: #02050f; color: var(--text); }
body { position: fixed; inset: 0; touch-action: none; overscroll-behavior: none; }
button, input, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

#gameShell {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: radial-gradient(circle at 50% 35%, #102d79 0%, #050816 54%, #02030a 100%);
}

#gameCanvas {
  width: 100vw;
  height: 100vh;
  display: block;
  cursor: pointer;
  touch-action: none;
}

.hidden { display: none !important; }

.panel {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 720px);
  max-height: min(88vh, 720px);
  overflow: auto;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: linear-gradient(150deg, var(--panel), rgba(2, 9, 29, 0.76));
  box-shadow: var(--shadow), inset 0 0 38px rgba(66, 229, 255, 0.08);
  backdrop-filter: blur(14px);
  text-align: center;
  z-index: 20;
}

.menu-panel h1 {
  margin: 8px 0 12px;
  font-size: clamp(42px, 8vw, 78px);
  line-height: 0.95;
  letter-spacing: -0.06em;
  text-transform: uppercase;
  text-shadow: 0 0 14px rgba(64, 240, 255, 0.74), 0 7px 0 rgba(0, 0, 0, 0.3);
}

.lead {
  margin: 0 auto 20px;
  max-width: 58ch;
  color: var(--muted);
  font-size: clamp(15px, 2.2vw, 18px);
}

.brand-badge {
  display: inline-flex;
  padding: 7px 13px;
  border: 1px solid rgba(167, 255, 63, 0.45);
  border-radius: 999px;
  color: var(--accent2);
  background: rgba(167, 255, 63, 0.08);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 12px;
}

.name-label {
  display: grid;
  gap: 7px;
  width: min(100%, 360px);
  margin: 0 auto 20px;
  color: var(--muted);
  text-align: left;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.name-label input,
.score-tools select {
  width: 100%;
  border: 1px solid rgba(73, 245, 255, 0.45);
  border-radius: 15px;
  padding: 13px 14px;
  color: var(--text);
  background: rgba(0, 13, 41, 0.65);
  outline: none;
}

.name-label input:focus,
.score-tools select:focus { box-shadow: 0 0 0 4px rgba(73, 245, 255, 0.14); }

.menu-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.primary-btn,
.secondary-btn,
.icon-btn,
.close-btn {
  border: 0;
  border-radius: 18px;
  cursor: pointer;
  font-weight: 900;
  color: #00133a;
  transition: transform 0.15s ease, filter 0.15s ease, opacity 0.15s ease;
}

.primary-btn {
  padding: 15px 28px;
  min-width: 156px;
  background: linear-gradient(180deg, #b9ff4d, #42ef66);
  box-shadow: 0 8px 0 #178d43, 0 0 28px rgba(113, 255, 89, 0.38);
  text-transform: uppercase;
}

.secondary-btn {
  padding: 14px 21px;
  background: linear-gradient(180deg, #78f7ff, #1ec4ff);
  box-shadow: 0 7px 0 #0a72b2, 0 0 24px rgba(73, 245, 255, 0.26);
}

.secondary-btn.small {
  padding: 10px 14px;
  border-radius: 12px;
  box-shadow: 0 5px 0 #0a72b2, 0 0 16px rgba(73, 245, 255, 0.22);
}

.primary-btn:hover,
.secondary-btn:hover,
.icon-btn:hover,
.close-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.primary-btn:active,
.secondary-btn:active,
.icon-btn:active,
.close-btn:active { transform: translateY(3px); box-shadow: none; }

.mini-help { color: var(--muted); font-size: 14px; }

.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.hud-top {
  position: absolute;
  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: 48px 1fr 48px;
  align-items: center;
  gap: 12px;
}

.icon-btn {
  pointer-events: auto;
  width: 48px;
  height: 48px;
  padding: 0;
  color: #dfffff;
  background: rgba(0, 18, 58, 0.45);
  border: 1px solid rgba(151, 241, 255, 0.42);
  box-shadow: 0 0 20px rgba(73, 245, 255, 0.15);
  font-size: 25px;
  line-height: 1;
}

.progress-wrap {
  position: relative;
  height: 28px;
  overflow: hidden;
  border-radius: 999px;
  border: 2px solid rgba(168, 246, 255, 0.55);
  background: rgba(0, 0, 0, 0.38);
  box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.5), 0 0 24px rgba(73, 245, 255, 0.2);
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #5cff65, #b9ff4d, #ffe33c);
  transition: width 0.08s linear;
}

#progressText {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: white;
  font-weight: 950;
  text-shadow: 0 2px 3px rgba(0,0,0,0.65);
}

.attempt-overlay {
  position: absolute;
  left: 50%;
  top: 16%;
  transform: translateX(-50%);
  min-width: 200px;
  text-align: center;
  color: white;
  font-size: clamp(34px, 7vw, 64px);
  font-weight: 950;
  text-transform: uppercase;
  letter-spacing: -0.04em;
  text-shadow: 0 5px 0 rgba(0,0,0,0.4), 0 0 20px rgba(255,255,255,0.35);
  pointer-events: none;
}

.side-panel {
  width: min(94vw, 860px);
  text-align: left;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.panel-head h2,
.pause-panel h2,
.complete-panel h2 { margin: 0; font-size: clamp(30px, 5vw, 44px); }

.close-btn {
  width: 44px;
  height: 44px;
  color: #06123a;
  background: linear-gradient(180deg, #ffffff, #78f7ff);
  box-shadow: 0 5px 0 #0a72b2;
  font-size: 28px;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
}

.level-card {
  position: relative;
  overflow: hidden;
  min-height: 162px;
  border: 1px solid rgba(148, 240, 255, 0.35);
  border-radius: 22px;
  padding: 16px;
  background: linear-gradient(150deg, rgba(16, 67, 136, 0.64), rgba(7, 15, 44, 0.72));
  cursor: pointer;
  box-shadow: inset 0 0 30px rgba(73, 245, 255, 0.08);
}

.level-card.locked { filter: grayscale(0.75); opacity: 0.55; cursor: not-allowed; }
.level-card h3 { margin: 0 0 6px; font-size: 22px; }
.level-card p { margin: 0 0 10px; color: var(--muted); }
.level-card .bar {
  height: 12px;
  border-radius: 999px;
  background: rgba(0,0,0,0.35);
  overflow: hidden;
}
.level-card .fill { height: 100%; background: linear-gradient(90deg, #5cff65, #ffe33c); }
.level-card .tag { display: inline-block; margin-top: 10px; color: var(--accent2); font-weight: 900; }

.score-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin-bottom: 14px;
}

.score-list {
  display: grid;
  gap: 8px;
  color: var(--muted);
}

.score-row {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 11px 12px;
  border: 1px solid rgba(151, 241, 255, 0.18);
  border-radius: 14px;
  background: rgba(0, 12, 39, 0.38);
}
.score-row b { color: white; }
.score-row small { display: block; color: rgba(234,255,255,0.62); }

.pause-panel,
.complete-panel { width: min(90vw, 440px); display: grid; gap: 14px; }
.complete-panel p { margin: 0; color: var(--muted); }
.stars { color: #ffe84d; font-size: 36px; text-shadow: 0 0 15px rgba(255,232,77,0.65); }

@media (max-width: 620px) {
  .panel { padding: 20px; border-radius: 22px; }
  .menu-actions { display: grid; grid-template-columns: 1fr; }
  .primary-btn, .secondary-btn { width: 100%; }
  .hud-top { grid-template-columns: 42px 1fr 42px; gap: 8px; }
  .icon-btn { width: 42px; height: 42px; font-size: 22px; }
  .progress-wrap { height: 25px; }
  .score-tools { grid-template-columns: 1fr; }
}

/* El mensaje ATTEMPT se dibuja dentro del mundo. Ocultamos el duplicado fijo del HUD. */
.attempt-overlay { display: none !important; }

/* El mensaje ATTEMPT se dibuja dentro del mundo. Ocultamos el duplicado fijo del HUD. */
.attempt-overlay { display: none !important; }
