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

body {
  background: #111;
  font-family: 'Fredoka', sans-serif;
}

#game-viewport {
  height: 100vh;
  height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  background: #111;
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  max-width: calc(100vh * 575 / 1024);
  max-height: calc(100vw * 1024 / 575);
  aspect-ratio: 575 / 1024;
  background: linear-gradient(160deg, #7cb85c 0%, #5a9e4b 55%, #468a3f 100%); /* Grass field */
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.8);
}

#game-center-wrap {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  height: 100%;
  width: 100%;
  pointer-events: none;
  z-index: 30;
  display: flex;
  flex-direction: column;
}

@media (min-aspect-ratio: 1/1) {
  #game-container {
    max-width: 100vw;
    max-height: 100vh;
    aspect-ratio: 2972 / 1672;
  }
  #game-center-wrap {
    width: calc(100% * 575 / 1024 * 1672 / 2972);
  }
}

/* Enable pointer events on active elements */
#game-center-wrap .hud-btn,
#game-center-wrap .game-btn,
#game-center-wrap .gameover:not(.hidden) {
  pointer-events: auto;
}

/* Buttons inside hidden overlays must never swallow battlefield gestures */
#game-center-wrap .gameover.hidden,
#game-center-wrap .gameover.hidden * {
  pointer-events: none !important;
}

/* Header Area */
#header-area {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px 5px 20px;
  pointer-events: auto;
  position: relative;
  z-index: 40;
}

#level-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 30px;
  padding: 6px 18px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

#level-chip .level-label {
  font-size: 15px;
  font-weight: 700;
  color: #d7ffc9;
  letter-spacing: 1px;
  text-transform: uppercase;
}

#level-val {
  font-size: 24px;
  color: #ffe066;
  font-family: 'Fredoka One', cursive;
  text-shadow: 0 2px 4px rgba(0,0,0,0.4);
}

.hud-btn {
  background: none;
  border: none;
  cursor: pointer;
  outline: none;
  transition: transform 0.1s;
}
.hud-btn:active {
  transform: scale(0.85);
}

/* Faction power balance bar */
#power-bar-container {
  padding: 6px 20px 0 20px;
  pointer-events: none;
}

#power-bar {
  position: relative;
  display: flex;
  width: 100%;
  height: 16px;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.35);
  box-shadow: inset 0 2px 5px rgba(0,0,0,0.4);
  border: 2px solid rgba(255,255,255,0.25);
}

#power-bar .power-seg {
  height: 100%;
  transition: width 0.5s ease-out;
}

/* Game canvas fills everything below the HUD */
#game-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  pointer-events: auto;
}

/* Tutorial hint */
#hint-banner {
  position: absolute;
  left: 50%;
  bottom: 4%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.55);
  border: 2px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  padding: 10px 22px;
  border-radius: 30px;
  white-space: nowrap;
  z-index: 45;
  pointer-events: none;
  animation: hintPulse 1.6s ease-in-out infinite;
  transition: opacity 0.4s;
}
#hint-banner.hidden { opacity: 0; }

@keyframes hintPulse {
  0%, 100% { transform: translateX(-50%) scale(1); }
  50%      { transform: translateX(-50%) scale(1.06); }
}

/* Overlays */
.gameover {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: opacity .3s;
  pointer-events: auto;
}
.gameover.hidden {
  opacity: 0;
  pointer-events: none;
}

.gameover-card {
  width: 78%;
  background: #1d2b1a;
  border: 5px solid #ffb300;
  border-radius: 24px;
  padding: 36px 20px;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0,0,0,.7);
  animation: popIn .35s cubic-bezier(.175,.885,.32,1.275);
}

.gameover-title {
  font-family: 'Fredoka One', cursive;
  font-size: 36px;
  color: #ffb300;
  margin-bottom: 10px;
  text-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.gameover-score-text {
  font-size: 22px;
  color: #fff;
  margin-bottom: 26px;
}

.game-btn {
  font-family: 'Fredoka One', cursive;
  font-size: 22px;
  color: #fff;
  background: linear-gradient(180deg, #ffb300, #ff8800);
  border: none;
  border-radius: 28px;
  padding: 11px 36px;
  cursor: pointer;
  box-shadow: 0 6px 0 #b37400, 0 8px 16px rgba(0,0,0,.3);
  transition: transform .1s, box-shadow .1s;
  outline: none;
}
.game-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #b37400;
}

@keyframes popIn {
  from { transform: scale(.65); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}
