* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: none;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #1ea8ff;
  color: #ffffff;
}

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

.hidden {
  display: none !important;
}

/* Biome Toast */
.biome-toast {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%) translateY(-90px);
  background: linear-gradient(135deg, #247828, #144d1a);
  border: 2.5px solid #b6ff4d;
  border-radius: 16px;
  padding: 8px 22px;
  text-align: center;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
  z-index: 25;
  pointer-events: none;
}

.biome-toast.show {
  animation: toastSlide 3.2s ease forwards;
}

@keyframes toastSlide {
  0% { transform: translateX(-50%) translateY(-90px); opacity: 0; }
  14% { transform: translateX(-50%) translateY(0); opacity: 1; }
  82% { transform: translateX(-50%) translateY(0); opacity: 1; }
  100% { transform: translateX(-50%) translateY(-90px); opacity: 0; }
}

.toast-title {
  font-weight: 900;
  font-size: 0.98rem;
  letter-spacing: 0.08em;
  color: #eeff66;
}

.toast-sub {
  font-size: 0.76rem;
  color: #d6ffc2;
}

/* Power-up & Ability Callout Popup Banner */
.powerup-popup {
  position: fixed;
  top: 26%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.5);
  opacity: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  background: linear-gradient(135deg, rgba(20, 68, 32, 0.95), rgba(10, 38, 22, 0.96));
  border: 3px solid var(--pop-color, #ffe24a);
  border-radius: 22px;
  padding: 12px 24px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.55), 0 0 28px var(--pop-color, rgba(255, 226, 74, 0.6));
  z-index: 28;
  pointer-events: none;
  max-width: 92vw;
}

.powerup-popup.show {
  animation: powerPop 2.55s cubic-bezier(0.2, 0.9, 0.3, 1) forwards;
}

@keyframes powerPop {
  0%   { transform: translate(-50%, -40%) scale(0.45); opacity: 0; }
  12%  { transform: translate(-50%, -50%) scale(1.08); opacity: 1; }
  20%  { transform: translate(-50%, -50%) scale(1.0); opacity: 1; }
  82%  { transform: translate(-50%, -50%) scale(1.0); opacity: 1; }
  100% { transform: translate(-50%, -70%) scale(0.85); opacity: 0; }
}

.popup-icon {
  font-size: 2.3rem;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.4));
}

.popup-title {
  font-weight: 900;
  font-size: clamp(1rem, 3.2vw, 1.35rem);
  letter-spacing: 0.05em;
  color: var(--pop-color, #ffe24a);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.6);
}

.popup-desc {
  font-size: clamp(0.76rem, 2.3vw, 0.92rem);
  font-weight: 700;
  color: #ffffff;
  margin-top: 2px;
}

/* In-game HUD */
.hud {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  z-index: 20;
  pointer-events: none;
}

.hud-left {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.hud-stat {
  background: rgba(16, 54, 24, 0.78);
  border: 2px solid #96f24b;
  backdrop-filter: blur(6px);
  padding: 6px 12px;
  border-radius: 12px;
  min-width: 82px;
}

.hud-stat .lbl {
  display: block;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #bcff8c;
}

.hud-stat .val {
  font-size: 1.25rem;
  font-weight: 900;
  color: #ffffff;
}

.hud-stat .val.gold {
  color: #ffdd3c;
}

.hud-right {
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: flex-end;
}

.hud-biome-tag {
  background: rgba(16, 54, 24, 0.82);
  border: 2px solid #96f24b;
  padding: 5px 12px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.8rem;
  color: #eeff66;
}

.hud-powerups {
  font-weight: 800;
  font-size: 0.88rem;
  color: #fff666;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7);
}

.hud-controls-hint {
  font-size: 0.72rem;
  color: #ffffff;
  background: rgba(0, 0, 0, 0.42);
  padding: 3px 10px;
  border-radius: 8px;
}

/* On-Screen Touch Gamepad for Phone & Tablet */
.touch-controls {
  position: fixed;
  left: max(16px, env(safe-area-inset-left));
  right: max(16px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  z-index: 24;
  pointer-events: none;
}

.touch-pad-left, .touch-pad-right {
  display: flex;
  gap: 10px;
  pointer-events: auto;
}

.tbtn {
  width: 66px;
  height: 66px;
  border-radius: 18px;
  border: 3px solid rgba(255, 255, 255, 0.85);
  background: linear-gradient(180deg, rgba(64, 196, 54, 0.85), rgba(26, 118, 28, 0.88));
  color: #ffffff;
  font-size: 1.55rem;
  font-weight: 900;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.38);
  transition: transform 0.08s ease;
}

.tbtn span {
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  margin-top: -2px;
}

.tbtn-jump {
  background: linear-gradient(180deg, rgba(255, 196, 38, 0.9), rgba(224, 112, 16, 0.92));
}

.tbtn-slide {
  background: linear-gradient(180deg, rgba(46, 178, 255, 0.9), rgba(18, 104, 212, 0.92));
}

.tbtn:active {
  transform: scale(0.91);
}

/* Subway Surfers Style Menu Layout: Top Logo + Open Center Stage + Bottom Dock */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  pointer-events: none;
}

.menu-layout {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: max(12px, env(safe-area-inset-top)) 14px max(12px, env(safe-area-inset-bottom));
}

.top-stage-banner {
  text-align: center;
  pointer-events: auto;
}

.logo-plaque {
  display: inline-block;
  background: linear-gradient(180deg, #ffdd38 0%, #ff8814 100%);
  border: 4px solid #ffffff;
  border-radius: 22px;
  padding: 6px 26px 8px;
  box-shadow: 0 8px 0 #8a3c00, 0 14px 28px rgba(0, 0, 0, 0.45);
  transform: rotate(-1.5deg);
}

.logo-main {
  font-size: clamp(1.65rem, 4.5vw, 2.75rem);
  font-weight: 900;
  letter-spacing: 0.04em;
  color: #154d14;
  text-shadow: 0 2px 0 #fff7b2;
  line-height: 1.05;
}

.logo-ribbon {
  display: inline-block;
  background: #143642;
  color: #fff275;
  font-weight: 900;
  font-size: clamp(0.66rem, 1.8vw, 0.85rem);
  letter-spacing: 0.12em;
  padding: 3px 12px;
  border-radius: 99px;
  margin-top: 2px;
}

.stage-prompt {
  margin-top: 10px;
  background: rgba(14, 42, 22, 0.82);
  border: 2px solid #a8ff52;
  color: #ffffff;
  font-weight: 800;
  font-size: clamp(0.7rem, 2vw, 0.86rem);
  letter-spacing: 0.08em;
  padding: 4px 14px;
  border-radius: 999px;
  display: inline-block;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

/* Bottom Dock */
.bottom-stage-dock {
  width: min(880px, 96vw);
  background: linear-gradient(180deg, rgba(16, 48, 26, 0.86), rgba(10, 32, 18, 0.94));
  border: 2.5px solid #9ef54c;
  border-radius: 20px;
  padding: 10px 14px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  pointer-events: auto;
}

.selected-hero-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(174, 245, 108, 0.3);
}

.sel-name {
  font-weight: 900;
  font-size: 1.15rem;
  color: #ffe24a;
  margin-right: 8px;
}

.sel-species {
  font-size: 0.8rem;
  font-weight: 700;
  color: #caff9e;
}

.sel-perk {
  font-size: 0.78rem;
  font-weight: 700;
  color: #ffffff;
  background: rgba(94, 204, 44, 0.28);
  padding: 3px 10px;
  border-radius: 99px;
}

/* 3D Hero Selector Pills */
.char-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}

.hero-tab {
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 12px;
  padding: 6px 8px;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: all 0.15s ease;
}

.hero-tab .hero-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--badge, #ffbe2e);
  margin-bottom: 2px;
}

.hero-tab strong {
  font-size: 0.88rem;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.hero-tab small {
  font-size: 0.65rem;
  color: #d8f5c6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.hero-tab:hover {
  background: rgba(255, 255, 255, 0.2);
}

.hero-tab.active {
  background: linear-gradient(180deg, #ffdd38, #ff9214);
  border-color: #ffffff;
  color: #1a1004;
  transform: translateY(-2px);
  box-shadow: 0 5px 14px rgba(255, 178, 24, 0.5);
}

.hero-tab.active small {
  color: #362204;
  font-weight: 700;
}

/* Biome Bar */
.biome-bar, .obs-showcase-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 9px;
  justify-content: center;
}

.biome-pill, .obs-pill {
  background: rgba(255, 255, 255, 0.1);
  border: 1.5px solid rgba(255, 255, 255, 0.24);
  color: #f0ffdf;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
}

.biome-pill.active {
  background: #84f238;
  color: #0b240c;
  border-color: #ffffff;
}

/* Action Buttons */
.menu-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-primary {
  flex: 1;
  min-width: 170px;
  background: linear-gradient(180deg, #98ff38 0%, #3dc414 100%);
  color: #082406;
  font-weight: 900;
  font-size: 1.05rem;
  letter-spacing: 0.05em;
  border: 2.5px solid #ffffff;
  border-radius: 14px;
  padding: 10px 18px;
  cursor: pointer;
  box-shadow: 0 5px 0 #1c6b08, 0 8px 18px rgba(72, 224, 28, 0.45);
}

.btn-primary:active {
  transform: translateY(3px);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  border: 1.5px solid rgba(200, 255, 150, 0.55);
  border-radius: 12px;
  padding: 9px 13px;
  font-weight: 800;
  font-size: 0.8rem;
  cursor: pointer;
}

/* Free-cam Inspector Studio */
.freecam-banner {
  position: fixed;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: min(980px, 95vw);
  background: rgba(14, 42, 22, 0.92);
  border: 2px solid #9ef54c;
  border-radius: 16px;
  padding: 10px 16px;
  z-index: 35;
}

.freecam-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  gap: 10px;
}

.freecam-header span {
  display: block;
  font-size: 0.76rem;
  color: #caff9e;
}

/* Gameover */
.gameover-layout {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 26, 14, 0.55);
  pointer-events: auto;
}

.gameover-panel {
  width: min(460px, 92vw);
  background: linear-gradient(165deg, rgba(20, 58, 30, 0.96), rgba(10, 32, 18, 0.98));
  border: 3px solid #9ef54c;
  border-radius: 22px;
  padding: 22px;
  text-align: center;
  box-shadow: 0 20px 55px rgba(0, 0, 0, 0.65);
}

.go-reason {
  color: #ffd066;
  margin: 6px 0 14px;
  font-weight: 700;
}

.go-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.go-stats div {
  background: rgba(255, 255, 255, 0.09);
  padding: 10px;
  border-radius: 12px;
}

.go-stats span {
  display: block;
  font-size: 0.7rem;
  color: #bcff8c;
  font-weight: 700;
}

.go-stats strong {
  font-size: 1.4rem;
  color: #ffe24a;
}

/* Mobile Portrait Adjustments */
@media (max-width: 640px) {
  .hud-controls-hint { display: none; }
  .char-tabs { gap: 5px; }
  .hero-tab small { display: none; }
  .biome-pill { font-size: 0.66rem; padding: 3px 8px; }
  .tbtn { width: 58px; height: 58px; font-size: 1.35rem; }
}
