:root {
  --bg: #070b14;
  --fg: #f8fafc;
  --panel: rgba(15, 23, 42, 0.72);
  --glass: rgba(255, 255, 255, 0.07);
  --outline: rgba(255, 255, 255, 0.18);
  --accent: #fbbf24;
  --accent-orange: #f97316;
  --cyan: #38bdf8;
  --emerald: #22c55e;
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  overflow: hidden;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  outline: none;
  display: block;
}

#overlay2D {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 4;
}

/* ---------- INTRO MODAL ---------- */
#intro {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 20;
  background: radial-gradient(1200px 750px at 50% 18%, rgba(34, 197, 94, 0.16), rgba(7, 11, 20, 0.75) 60%, rgba(3, 6, 12, 0.92));
  backdrop-filter: blur(6px);
  padding: 16px;
  overflow-y: auto;
}

#introCard {
  width: min(860px, 95vw);
  background: linear-gradient(165deg, rgba(22, 34, 56, 0.88), rgba(10, 16, 28, 0.94));
  border: 1px solid rgba(251, 191, 36, 0.28);
  border-radius: 22px;
  padding: 26px 28px;
  text-align: center;
  box-shadow: 0 28px 100px rgba(0, 0, 0, 0.75), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.badge-top {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(251, 191, 36, 0.15);
  border: 1px solid rgba(251, 191, 36, 0.4);
  color: #fde047;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.title {
  font-weight: 900;
  letter-spacing: 0.03em;
  margin: 0 0 6px;
  font-size: clamp(34px, 6vw, 58px);
  background: linear-gradient(95deg, #fde047 0%, #fb923c 48%, #38bdf8 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 18px rgba(251, 191, 36, 0.22));
}

.subtitle {
  opacity: 0.92;
  margin: 0 0 18px;
  font-size: clamp(14px, 2.2vw, 18px);
  color: #cbd5e1;
}

.grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  text-align: left;
  margin: 12px 0 16px;
}

.glass {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 14px;
  padding: 12px 14px;
  line-height: 1.55;
  font-size: 13.5px;
  color: #e2e8f0;
}

.glass strong {
  color: #fde047;
  font-size: 14px;
}

kbd {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(15, 23, 42, 0.85);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.5);
  font-weight: 800;
  font-size: 11.5px;
  color: #f8fafc;
}

.settings-row {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  text-align: left;
  margin-bottom: 18px;
}

.radio-group {
  display: flex;
  gap: 12px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.radio-group label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}

.btn-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 8px;
}

.btn {
  cursor: pointer;
  border: none;
  border-radius: 12px;
  padding: 13px 22px;
  font-weight: 900;
  font-size: 15px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

.btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.08);
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  background: linear-gradient(90deg, #facc15, #f97316);
  color: #090d16;
  box-shadow: 0 8px 24px rgba(249, 115, 22, 0.35);
}

.btn.secondary {
  background: rgba(255, 255, 255, 0.08);
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

/* ---------- TOP HEALTH & SPECIALS BARS ---------- */
.barWrap {
  position: fixed;
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  z-index: 6;
  display: none;
  width: min(580px, 90vw);
  height: 22px;
  border-radius: 999px;
  background: rgba(10, 15, 28, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.24);
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
}

.barFill {
  height: 100%;
  width: 100%;
  transition: width 0.08s ease-out;
}

#energyFill {
  background: linear-gradient(90deg, #22c55e, #4ade80, #16a34a);
}

.hp-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11.5px;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  pointer-events: none;
}

#specialsRow {
  position: fixed;
  left: 50%;
  top: 38px;
  transform: translateX(-50%);
  display: none;
  gap: 8px;
  z-index: 6;
  width: min(580px, 92vw);
  justify-content: center;
}

.smallBar {
  flex: 1;
  min-width: 110px;
  height: 20px;
  border-radius: 999px;
  background: rgba(10, 15, 28, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.2);
  overflow: hidden;
  position: relative;
  cursor: pointer;
}

.blueFill {
  background: linear-gradient(90deg, #f97316, #facc15);
}

.cyanFill {
  background: linear-gradient(90deg, #0284c7, #38bdf8);
}

.purpleFill {
  background: linear-gradient(90deg, #9333ea, #c084fc);
}

.redFill {
  background: linear-gradient(90deg, #dc2626, #fb7185);
}

.tag {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  font-weight: 800;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  white-space: nowrap;
}

@keyframes readyPulse {
  0%,
  100% {
    box-shadow: 0 0 0 rgba(250, 204, 21, 0);
    border-color: rgba(255, 255, 255, 0.25);
  }
  50% {
    box-shadow: 0 0 14px rgba(250, 204, 21, 0.75);
    border-color: rgba(250, 204, 21, 0.9);
  }
}

.smallBar.ready {
  animation: readyPulse 1.2s ease-in-out infinite;
}

/* ---------- LEFT HUD & TOP-RIGHT QUICK CONTROLS ---------- */
#hud {
  position: fixed;
  left: 12px;
  top: 72px;
  display: none;
  flex-direction: column;
  gap: 7px;
  z-index: 5;
}

.pill {
  background: rgba(10, 15, 28, 0.68);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 11px;
  padding: 6px 12px;
  font-weight: 800;
  font-size: 13.5px;
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.pill span {
  color: #fde047;
}

#comboPill {
  background: linear-gradient(90deg, rgba(234, 88, 12, 0.85), rgba(202, 138, 4, 0.85));
  border-color: #fde047;
  transform-origin: left center;
  transition: transform 0.1s ease;
}

#topRightControls {
  position: fixed;
  right: 12px;
  top: 72px;
  display: none;
  flex-direction: column;
  gap: 6px;
  z-index: 6;
}

.icon-btn {
  background: rgba(10, 15, 28, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #f8fafc;
  border-radius: 10px;
  padding: 6px 11px;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  backdrop-filter: blur(6px);
  text-align: right;
}

.icon-btn:hover {
  border-color: #fde047;
  color: #fde047;
}

/* ---------- LEVEL COMPLETE / PERK MODAL ---------- */
#msg {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  z-index: 15;
  background: rgba(4, 8, 16, 0.72);
  backdrop-filter: blur(5px);
  padding: 16px;
}

#card {
  background: linear-gradient(165deg, #131e36, #0b1120);
  border: 1px solid rgba(251, 191, 36, 0.35);
  border-radius: 20px;
  padding: 22px 24px;
  text-align: center;
  width: min(620px, 94vw);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.75);
}

.perk-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin: 14px 0 18px;
}

.perk-card {
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  padding: 12px 10px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.perk-card:hover,
.perk-card.selected {
  border-color: #facc15;
  background: rgba(250, 204, 21, 0.12);
  transform: translateY(-2px);
}

.perk-icon {
  font-size: 26px;
  margin-bottom: 4px;
}

.perk-name {
  font-weight: 900;
  font-size: 13.5px;
  color: #fde047;
  margin-bottom: 4px;
}

.perk-desc {
  font-size: 11.5px;
  color: #cbd5e1;
  line-height: 1.35;
}

/* ---------- MOBILE CONTROLS ---------- */
#joystick {
  position: fixed;
  left: 16px;
  bottom: 18px;
  width: 124px;
  height: 124px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.07);
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  touch-action: none;
  display: none;
  z-index: 6;
}

#stick {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: rgba(250, 204, 21, 0.35);
  border: 2px solid rgba(250, 204, 21, 0.8);
}

#punchBtn {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 96px;
  height: 96px;
  border-radius: 999px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  background: radial-gradient(circle at 30% 30%, #ffd400, #ff7a00);
  color: #000;
  font-weight: 900;
  font-size: 15px;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 6;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

@media (max-width: 900px) {
  .mobileShow {
    display: flex !important;
  }
  #specialsRow {
    flex-wrap: wrap;
    top: 36px;
  }
  #hud {
    top: 92px;
  }
}
