:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

.pt-safe {
  padding-top: calc(10px + var(--safe-top));
}
.pb-safe {
  padding-bottom: calc(12px + var(--safe-bottom));
}
.mt-safe {
  margin-top: var(--safe-top);
}

* {
  -webkit-tap-highlight-color: transparent;
  box-sizing: border-box;
}

body {
  font-family: 'Press Start 2P', monospace;
  background-color: #000000;
  color: #fff;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  margin: 0;
  padding: 0;
}

.font-arcade {
  font-family: 'Press Start 2P', monospace;
}

/* Fullscreen Canvas & Screen Rendering */
#game-wrapper {
  background-color: #000000;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  position: fixed;
  inset: 0;
}

#screen-container {
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
  background-color: #000000;
}

.game-screen {
  image-rendering: -moz-crisp-edges;
  image-rendering: -webkit-crisp-edges;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background-color: #5c94fc;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Scanline / Arcade Ambient Effect */
.crt-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.15) 50%), 
              linear-gradient(90deg, rgba(255, 0, 0, 0.015), rgba(0, 255, 0, 0.01), rgba(0, 0, 255, 0.015));
  background-size: 100% 3px, 4px 100%;
  pointer-events: none;
  z-index: 10;
  opacity: 0.55;
}

/* Top Action Buttons (Sound & Pause) */
.btn-top-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.85);
  border: 1.5px solid rgba(255, 255, 255, 0.25);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s ease;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #fff;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.7);
  touch-action: manipulation;
}
.btn-top-icon:active {
  transform: scale(0.92);
  background: rgba(30, 41, 59, 0.95);
  border-color: rgba(250, 204, 21, 0.9);
}

/* ========================================================
   FLOATING ERGONOMIC ON-SCREEN THUMB CONTROLS
   ======================================================== */
#touch-controls {
  padding-left: calc(12px + var(--safe-left));
  padding-right: calc(12px + var(--safe-right));
  padding-bottom: calc(10px + var(--safe-bottom));
  pointer-events: none;
}

/* --- D-PAD CONTROLLER (LEFT THUMB) --- */
#dpad-zone {
  touch-action: none;
  -webkit-touch-callout: none;
}

.dpad-cluster {
  width: 164px;
  height: 164px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  background: radial-gradient(circle at center, rgba(30, 41, 59, 0.82) 0%, rgba(15, 23, 42, 0.94) 85%);
  border: 2.5px solid rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  padding: 6px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.85), inset 0 2px 4px rgba(255, 255, 255, 0.25), 0 0 16px rgba(56, 189, 248, 0.25);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.dpad-btn-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.dpad-btn-center {
  width: 44px;
  height: 44px;
  background: rgba(15, 23, 42, 0.95);
  border-radius: 10px;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.95);
}

.dpad-btn {
  width: 54px;
  height: 54px;
  background: linear-gradient(145deg, #334155, #1e293b);
  border: 1.5px solid rgba(148, 163, 184, 0.5);
  color: #f8fafc;
  font-size: 19px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.7), inset 0 1px 2px rgba(255, 255, 255, 0.35);
  transition: transform 0.06s ease, background 0.06s ease, border-color 0.06s ease, box-shadow 0.06s ease;
  touch-action: none;
  cursor: pointer;
}

.dpad-btn-up {
  border-radius: 18px 18px 6px 6px;
}
.dpad-btn-down {
  border-radius: 6px 6px 18px 18px;
}
.dpad-btn-left {
  border-radius: 18px 6px 6px 18px;
}
.dpad-btn-right {
  border-radius: 6px 18px 18px 6px;
}

.dpad-btn:active, .dpad-btn.active {
  background: linear-gradient(145deg, #0284c7, #0369a1) !important;
  border-color: #38bdf8 !important;
  color: #ffffff !important;
  transform: scale(0.92);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.95), 0 0 20px rgba(56, 189, 248, 0.9) !important;
}

/* --- ACTION BUTTONS (RIGHT THUMB) --- */
#action-zone {
  background: radial-gradient(circle at center, rgba(30, 41, 59, 0.8) 0%, rgba(15, 23, 42, 0.94) 85%);
  border: 2.5px solid rgba(255, 255, 255, 0.25);
  border-radius: 46px;
  padding: 10px 14px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.85), inset 0 2px 4px rgba(255, 255, 255, 0.25), 0 0 16px rgba(239, 68, 68, 0.25);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  touch-action: none;
  -webkit-touch-callout: none;
}

.floating-circle-btn {
  width: 66px;
  height: 66px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Press Start 2P', monospace;
  font-size: 19px;
  font-weight: bold;
  border-width: 3.5px;
  text-shadow: 0 2px 3px #000;
  transition: transform 0.06s ease, box-shadow 0.06s ease, filter 0.06s ease;
  touch-action: none;
  cursor: pointer;
}

/* Button B: Run / Fireball */
.btn-b {
  background: radial-gradient(circle at 35% 35%, #f59e0b, #d97706 70%, #b45309 100%);
  border-color: #fef08a;
  color: #fff;
  box-shadow: 0 6px 0 #78350f, 0 8px 18px rgba(0, 0, 0, 0.75), inset 0 2px 4px rgba(255, 255, 255, 0.6);
}
.btn-b:active, .btn-b.active {
  transform: translateY(4px) scale(0.93);
  box-shadow: 0 2px 0 #78350f, 0 2px 6px rgba(0, 0, 0, 0.95), 0 0 22px rgba(245, 158, 11, 0.95);
  filter: brightness(1.25);
}

/* Button A: Jump */
.btn-a {
  background: radial-gradient(circle at 35% 35%, #ef4444, #dc2626 70%, #991b1b 100%);
  border-color: #fee2e2;
  color: #fff;
  box-shadow: 0 6px 0 #7f1d1d, 0 8px 18px rgba(0, 0, 0, 0.75), inset 0 2px 4px rgba(255, 255, 255, 0.6);
}
.btn-a:active, .btn-a.active {
  transform: translateY(4px) scale(0.93);
  box-shadow: 0 2px 0 #7f1d1d, 0 2px 6px rgba(0, 0, 0, 0.95), 0 0 22px rgba(239, 68, 68, 0.95);
  filter: brightness(1.25);
}

/* Button B+A: Dash Jump Combo */
.btn-combo {
  width: 52px;
  height: 52px;
  font-size: 11px;
  background: radial-gradient(circle at 35% 35%, #8b5cf6, #6d28d9 70%, #4c1d95 100%);
  border-color: #ede9fe;
  color: #fff;
  box-shadow: 0 5px 0 #3b0764, 0 7px 14px rgba(0, 0, 0, 0.75), inset 0 2px 3px rgba(255, 255, 255, 0.6);
}
.btn-combo:active, .btn-combo.active {
  transform: translateY(3px) scale(0.92);
  box-shadow: 0 2px 0 #3b0764, 0 2px 5px rgba(0, 0, 0, 0.95), 0 0 20px rgba(139, 92, 246, 0.95);
  filter: brightness(1.3);
}

.floating-btn-label {
  font-size: 8px;
  color: #cbd5e1;
  font-weight: 800;
  font-family: sans-serif;
  margin-top: 5px;
  text-shadow: 0 2px 4px #000, 0 0 6px #000;
  letter-spacing: 0.06em;
}

/* Screen Overlays & Modals */
.screen-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(3, 7, 18, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.screen-overlay.hidden {
  display: none !important;
}

/* Responsive adjustment for small phones */
@media (max-width: 420px) {
  .dpad-cluster {
    width: 144px;
    height: 144px;
    padding: 5px;
  }
  .dpad-btn {
    width: 46px;
    height: 46px;
    font-size: 16px;
  }
  .dpad-btn-center {
    width: 38px;
    height: 38px;
  }
  .floating-circle-btn {
    width: 56px;
    height: 56px;
    font-size: 16px;
  }
  .btn-combo {
    width: 44px;
    height: 44px;
    font-size: 9px;
  }
  #action-zone {
    padding: 8px 10px;
    gap: 8px;
  }
}

/* Mini Pixel-art previews */
.sprite-hero {
  width: 24px;
  height: 28px;
  background: #ff2222;
  border: 2px solid #000;
  box-shadow: 0 8px 0 #0022cc, inset 0 6px 0 #ffcca0;
  border-radius: 4px;
}
.sprite-mush {
  width: 24px;
  height: 24px;
  background: #ff2222;
  border: 2px solid #000;
  border-radius: 12px 12px 6px 6px;
  box-shadow: inset 4px 4px 0 #ffffff, inset -4px -4px 0 #000000;
}
.sprite-flower {
  width: 24px;
  height: 24px;
  background: #f59e0b;
  border: 2px solid #000;
  border-radius: 50%;
  box-shadow: inset 0 0 0 4px #ef4444, inset 0 0 0 8px #ffffff;
}
.sprite-enemy {
  width: 24px;
  height: 22px;
  background: #92400e;
  border: 2px solid #000;
  border-radius: 12px 12px 4px 4px;
  box-shadow: inset 0 -6px 0 #1e293b;
}

.text-stroke {
  text-shadow: 
    -2px -2px 0 #000,  
     2px -2px 0 #000,
    -2px  2px 0 #000,
     2px  2px 0 #000,
     0px  4px 0 #000;
}

/* Animations */
@keyframes coin-spin {
  0%, 100% { transform: scaleX(1); }
  50% { transform: scaleX(0.2); }
}
.coin-icon {
  animation: coin-spin 0.8s infinite ease-in-out;
}