* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  touch-action: none;
}

#render-canvas {
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
}

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  font-family: "Segoe UI", Arial, sans-serif;
  color: #fff;
}

#character-select {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.75);
  font-family: "Segoe UI", Arial, sans-serif;
  color: #fff;
  z-index: 10;
}
#character-select.hidden {
  display: none;
}
#character-select .card {
  background: #101025;
  border: 2px solid #66ccff;
  border-radius: 16px;
  padding: 28px 36px;
  text-align: center;
  box-shadow: 0 0 40px rgba(102, 204, 255, 0.35);
  max-width: 420px;
}
#character-select h2 {
  color: #66ccff;
  font-size: 24px;
  margin-bottom: 10px;
}
#character-select p {
  font-size: 13px;
  color: #ccc;
  margin-bottom: 20px;
}
#persona-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
}
.persona-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  cursor: pointer;
  color: #ddd;
  font: inherit;
  font-size: 12px;
}
.persona-swatch {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.4);
  transition: border-color 0.15s, transform 0.1s;
}
.persona-btn:hover .persona-swatch {
  border-color: #fff;
  transform: scale(1.08);
}
.persona-btn:active .persona-swatch {
  transform: scale(0.95);
}

#loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 20px;
  background: rgba(0, 0, 0, 0.6);
  padding: 16px 24px;
  border-radius: 10px;
}
#loading.hidden {
  display: none;
}

#info {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  background: rgba(0, 0, 0, 0.55);
  padding: 8px 16px;
  border-radius: 20px;
  white-space: nowrap;
}

#level-info {
  position: absolute;
  top: 16px;
  left: 16px;
  font-size: 14px;
  font-weight: 600;
  background: rgba(0, 0, 0, 0.55);
  padding: 8px 14px;
  border-radius: 8px;
}
#level-info.hidden {
  display: none;
}

#lives-info {
  position: absolute;
  top: 16px;
  right: 16px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 2px;
  background: rgba(0, 0, 0, 0.55);
  padding: 8px 14px;
  border-radius: 8px;
}
#lives-info.hidden {
  display: none;
}

#rings-info {
  position: absolute;
  top: 56px;
  right: 16px;
  font-size: 15px;
  font-weight: 600;
  background: rgba(0, 0, 0, 0.55);
  padding: 8px 14px;
  border-radius: 8px;
  color: #7fe8ff;
}
#rings-info.hidden {
  display: none;
}

#level-complete,
#game-over {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
}
#level-complete.hidden,
#game-over.hidden {
  display: none;
}
#level-complete .card,
#game-over .card {
  pointer-events: auto;
  background: #101025;
  border: 2px solid #ffcc55;
  border-radius: 16px;
  padding: 28px 36px;
  text-align: center;
  box-shadow: 0 0 40px rgba(255, 204, 85, 0.35);
}
#level-complete h2,
#game-over h2 {
  color: #ffcc55;
  font-size: 26px;
  margin-bottom: 10px;
}
#level-complete p,
#game-over p {
  font-size: 14px;
  color: #ddd;
  margin-bottom: 18px;
}
#level-complete button,
#game-over button {
  font: inherit;
  font-weight: 700;
  font-size: 16px;
  color: #1a1400;
  background: linear-gradient(180deg, #ffdd55, #ffaa00);
  border: none;
  border-radius: 8px;
  padding: 10px 22px;
  cursor: pointer;
  box-shadow: 0 4px 0 #a06e00;
}
#level-complete button:active,
#game-over button:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #a06e00;
}

/* Game-over uses a red accent instead of gold to read as distinct/worse
   than a level-complete moment, even at a glance. */
.game-over-card {
  border-color: #ff5566 !important;
  box-shadow: 0 0 40px rgba(255, 85, 102, 0.35) !important;
}
#game-over h2 {
  color: #ff5566;
}

/* Touch controls — only ever created (touchControls.js) on a touch-capable
   device, so no media query is needed here to hide these on desktop.
   Styled to match the rest of the HUD's neon-glass accent palette (cyan
   #66ccff / gold #ffcc55) instead of the old flat dark circles, and padded
   for iOS/Android safe areas so notches/home-indicators never clip a
   control zone. */
#touch-controls {
  position: absolute;
  inset: 0;
}

#touch-joystick-zone {
  position: absolute;
  left: max(20px, env(safe-area-inset-left));
  bottom: max(20px, env(safe-area-inset-bottom));
  width: 136px;
  height: 136px;
  pointer-events: auto;
  touch-action: none;
}
#touch-joystick-base {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(102, 204, 255, 0.16), rgba(10, 14, 28, 0.35) 70%);
  border: 1.5px solid rgba(102, 204, 255, 0.4);
  backdrop-filter: blur(6px);
  box-shadow:
    0 0 22px rgba(102, 204, 255, 0.18),
    inset 0 0 18px rgba(0, 0, 0, 0.35);
  transition: border-color 0.15s, box-shadow 0.15s;
}
#touch-joystick-zone.active #touch-joystick-base {
  border-color: rgba(102, 204, 255, 0.8);
  box-shadow:
    0 0 30px rgba(102, 204, 255, 0.35),
    inset 0 0 18px rgba(0, 0, 0, 0.35);
}
#touch-joystick-ring {
  position: absolute;
  inset: 14px;
  border-radius: 50%;
  border: 1px dashed rgba(255, 255, 255, 0.18);
  pointer-events: none;
}
#touch-joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  margin-left: -27px;
  margin-top: -27px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffffff, #bfe9ff 60%, #66ccff 100%);
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4), 0 0 14px rgba(102, 204, 255, 0.5);
  transform: translate(-50%, -50%);
  transition: box-shadow 0.15s, transform 0.08s ease-out;
}
#touch-joystick-knob.active {
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.45), 0 0 26px rgba(102, 204, 255, 0.85);
}

#touch-action-zone {
  position: absolute;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  gap: 16px;
}
#touch-action-zone button {
  pointer-events: auto;
  touch-action: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  font: inherit;
  font-weight: 700;
  color: #fff;
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.1), rgba(10, 14, 28, 0.55) 75%);
  border: 1.5px solid rgba(255, 255, 255, 0.35);
  border-radius: 50%;
  backdrop-filter: blur(6px);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.08s ease-out, box-shadow 0.15s, border-color 0.15s, background 0.15s;
}
#touch-action-zone button:active,
#touch-action-zone button.active {
  transform: scale(0.92);
}
.touch-btn-icon {
  font-size: 1.3em;
  line-height: 1;
}
.touch-btn-label {
  font-size: 10px;
  letter-spacing: 0.5px;
  opacity: 0.85;
}
#touch-run-btn {
  width: 60px;
  height: 60px;
  margin-bottom: 14px;
  border-color: rgba(102, 204, 255, 0.5);
  box-shadow: 0 0 14px rgba(102, 204, 255, 0.2);
}
#touch-run-btn.active {
  background: radial-gradient(circle at 35% 30%, rgba(102, 204, 255, 0.5), rgba(102, 204, 255, 0.25));
  border-color: #66ccff;
  box-shadow: 0 0 22px rgba(102, 204, 255, 0.65);
}
#touch-jump-btn {
  width: 86px;
  height: 86px;
  border-color: rgba(255, 204, 85, 0.6);
  box-shadow: 0 0 18px rgba(255, 204, 85, 0.28), 0 4px 0 rgba(160, 110, 0, 0.4);
  animation: jump-btn-pulse 2.4s ease-in-out infinite;
}
#touch-jump-btn .touch-btn-icon {
  font-size: 1.6em;
}
#touch-jump-btn.active {
  background: radial-gradient(circle at 35% 30%, rgba(255, 221, 85, 0.65), rgba(255, 170, 0, 0.35));
  border-color: #ffcc55;
  box-shadow: 0 0 30px rgba(255, 204, 85, 0.8);
  animation: none;
}
@keyframes jump-btn-pulse {
  0%, 100% { box-shadow: 0 0 18px rgba(255, 204, 85, 0.28), 0 4px 0 rgba(160, 110, 0, 0.4); }
  50% { box-shadow: 0 0 28px rgba(255, 204, 85, 0.55), 0 4px 0 rgba(160, 110, 0, 0.4); }
}
