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

:root {
  --primary: #F4652B;
  --yellow: #F1E50E;
  --black: #1C1C1B;
  --white: #F8F8F8;
  --shadow: #555759;
  --grass: #7AA11A;
  --olive: #565824;
  --devil: #E64A2E;
  --beige: #EBDB9F;
  --brown: #522C21;
  --bg: #1C1C1B;
  --panel: #EBDB9F;
  --field: #7AA11A;
  --line: rgba(248,248,248,.74);
  --orange: var(--primary);
  --green: var(--grass);
  --red: var(--devil);
  --blue: #555759;
  --text: #EBDB9F;
}
* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; min-height: 100%; background: radial-gradient(circle at top, #522C21, var(--bg)); color: var(--text); font-family: system-ui, -apple-system, Segoe UI, sans-serif; overflow: hidden; overscroll-behavior: none; -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; min-height: 100dvh; min-height: var(--app-height, 100vh); position: fixed; inset: 0; touch-action: none; -webkit-user-select: none; user-select: none; }
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(28,28,27,.38), rgba(28,28,27,.70)),
    url("../../assets/img/IMG_1372.webp") center / min(76vw, 760px) auto no-repeat;
  filter: grayscale(1);
  opacity: .88;
}
button { font: inherit; cursor: pointer; border: 0; }
.shell { position: relative; z-index: 1; width: 100vw; height: 100vh; height: 100dvh; height: var(--app-height, 100vh); display: grid; place-items: center; padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); }
.hidden { display: none !important; }
.panel { width: min(560px, 94vw); max-height: calc(var(--app-height, 100vh) - 24px); overflow: auto; overscroll-behavior: contain; background: rgba(244,101,43,.92); border: 2px solid var(--black); border-radius: 16px; padding: 24px; text-align: center; box-shadow: 0 14px 0 rgba(82,44,33,.82), 0 22px 60px rgba(0,0,0,.42); color: var(--black); scrollbar-color: var(--yellow) rgba(28,28,27,.18); }
.eyebrow { color: var(--primary); margin: 0 0 8px; text-transform: uppercase; letter-spacing: .14em; font-size: .78rem; font-weight: 900; }
.eyebrow { display: none; }
.menu-art { display: block; width: min(78%, 260px); max-height: 28vh; height: auto; object-fit: contain; margin: 4px auto 12px; border: 0; border-radius: 0; box-shadow: none; background: transparent; }
h1 { margin: 0; font-size: clamp(2.35rem, 8vw, 4.6rem); line-height: .88; color: var(--black); text-shadow: 3px 3px 0 var(--yellow), 5px 5px 0 var(--beige); }
h2 { margin: 0 0 10px; font-size: 3rem; color: var(--yellow); }
.tagline { font-size: 1.15rem; opacity: .98; color: var(--yellow); font-weight: 1000; text-shadow: 2px 2px 0 rgba(28,28,27,.55); }
.menu-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
.primary-btn, .ghost-btn { padding: 14px 24px; border-radius: 999px; font-weight: 900; text-transform: uppercase; letter-spacing: .06em; }
.primary-btn { background: var(--primary); color: var(--beige); box-shadow: 0 8px 0 var(--brown); }
#playBtn { background: var(--yellow); color: var(--black); box-shadow: 0 8px 0 #9f8f00; }
#howBtn { background: var(--grass); color: var(--black); box-shadow: 0 8px 0 var(--olive); }
.ghost-btn { background: var(--yellow); color: var(--black); border: 2px solid var(--black); text-decoration: none; display: inline-block; }
.how { margin-top: 16px; text-align: left; background: rgba(241,229,14,.24); padding: 12px 14px; border-radius: 12px; border: 1px solid rgba(28,28,27,.18); max-height: min(260px, 36vh); overflow-y: auto; overscroll-behavior: contain; scrollbar-color: var(--primary) rgba(28,28,27,.18); }
.how p { margin: 6px 0; line-height: 1.28; }
.game-panel { position: relative; width: min(1200px, calc(100vw - 20px)); aspect-ratio: 16 / 9; max-height: calc(var(--app-height, 100vh) - 20px); }
canvas { width: 100%; height: 100%; display: block; border-radius: 18px; background: #555759; box-shadow: 0 18px 60px rgba(0,0,0,.5); border: 3px solid var(--black); touch-action: none; }
.hud { position: absolute; z-index: 5; top: 10px; left: 50%; transform: translateX(-50%); width: min(700px, calc(100% - 24px)); display: grid; grid-template-columns: 2.4fr 1.15fr .78fr .86fr; gap: 7px; pointer-events: none; align-items: stretch; }
.hud div { background: rgba(20,20,19,.58); border: 1px solid rgba(248,248,248,.18); border-radius: 8px; padding: 6px 9px; text-align: center; backdrop-filter: blur(6px); box-shadow: 0 8px 18px rgba(0,0,0,.18); }
.hud span { display: block; font-size: .58rem; text-transform: uppercase; color: rgba(235,219,159,.76); font-weight: 850; letter-spacing: .08em; }
.hud strong { display: block; font-size: 1.12rem; line-height: 1; color: rgba(248,248,248,.92); }
.hud .scoreboard { background: rgba(28,28,27,.88); border: 2px solid var(--yellow); box-shadow: 0 0 22px rgba(241,229,14,.20), inset 0 -3px 0 rgba(244,101,43,.36); }
.hud .scoreboard span { color: rgba(241,229,14,.9); }
.hud .scoreboard strong { font-size: clamp(2.35rem, 5.2vw, 4.4rem); letter-spacing: .04em; color: var(--yellow); text-shadow: 3px 3px 0 var(--black), 0 0 18px rgba(241,229,14,.20); }
.hud .timebox { background: rgba(28,28,27,.70); border-color: rgba(241,229,14,.48); }
.hud .timebox strong { font-size: clamp(1.5rem, 2.7vw, 2.35rem); color: var(--yellow); }
.hud .timebox strong.danger-time {
  color: #ff2b2b;
  text-shadow: 0 0 14px rgba(255,43,43,.85), 3px 3px 0 #000;
  animation: dangerPulse .55s infinite alternate;
}
@keyframes dangerPulse { from { transform: scale(1); } to { transform: scale(1.12); } }

.message { position: absolute; z-index: 6; left: 50%; top: 50%; transform: translate(-50%, -50%); background: rgba(28,28,27,.84); color: var(--yellow); border: 2px solid var(--yellow); border-radius: 14px; padding: 14px 24px; font-size: clamp(1.4rem, 5vw, 3rem); font-weight: 1000; text-align: center; text-shadow: 3px 3px 0 var(--black); white-space: nowrap; animation: pop .18s ease-out; }
.message.message--purple {
  background: rgba(45, 23, 63, .94);
  color: #F8F8F8;
  border-color: #C08CFF;
  box-shadow: 0 0 36px rgba(192,140,255,.72), 0 0 0 4px rgba(110,53,183,.45);
  text-shadow: 3px 3px 0 #2D173F;
}
@keyframes pop { from { transform: translate(-50%, -50%) scale(.75); opacity: .4; } }
.touch-controls { display: none; position: absolute; inset: 0; pointer-events: none; z-index: 7; }
.touch-buttons { position: absolute; right: 22px; bottom: 22px; display: flex; gap: 12px; pointer-events: auto; }
.round-btn { width: 70px; height: 70px; border-radius: 50%; color: #111; font-size: 1.7rem; font-weight: 900; background: var(--orange); box-shadow: 0 7px 0 #913b00; }
.round-btn.shoot { background: var(--green); box-shadow: 0 7px 0 #087333; }
.final-score { font-size: clamp(2.4rem, 9vw, 4.8rem); font-weight: 1000; color: var(--yellow); text-shadow: 3px 3px 0 #000; margin: 12px 0 4px; }
.final-detail { font-size: 1.05rem; opacity: .92; margin-top: 0; }
.record { opacity: .9; }

.game-panel.ajolote-mode canvas { filter: saturate(1.18) contrast(1.06) hue-rotate(18deg); }
.game-panel.ajolote-mode .hud div { background: rgba(45, 23, 63, .84); border-color: rgba(192,140,255,.78); box-shadow: 0 0 18px rgba(192,140,255,.28); }
.game-panel.ajolote-mode .hud strong { color: var(--yellow); }
.game-panel.ajolote-mode .message { border-color: #C08CFF; box-shadow: 0 0 32px rgba(192,140,255,.42); }

.rotate-hint { display: none; }

@media (pointer: coarse), (max-width: 760px) {
  .shell { padding: 0; background: #05050a; }
  .panel { padding: 18px; }
  .menu-art { width: min(60%, 210px); max-height: 22vh; margin-bottom: 8px; }
  h1 { font-size: clamp(2rem, 8vw, 3.8rem); }
  .tagline { font-size: 1rem; margin: 8px 0; }
  .menu-actions { margin-top: 14px; gap: 10px; }
  .primary-btn, .ghost-btn { padding: 12px 18px; }
  .how { max-height: min(220px, 34vh); font-size: .9rem; }
  .game-panel {
    width: min(100vw, calc(var(--app-height, 100vh) * 1.7778));
    height: min(var(--app-height, 100vh), calc(100vw * .5625));
    aspect-ratio: 16 / 9;
    max-height: none;
  }
  canvas { width: 100%; height: 100%; border-radius: 0; }
  .hud { top: max(7px, env(safe-area-inset-top)); grid-template-columns: 1.55fr .78fr .54fr .62fr; gap: 5px; }
  .hud div { padding: 5px 4px; border-radius: 8px; }
  .hud strong { font-size: .88rem; }
  .hud .scoreboard strong { font-size: 2rem; }
  .hud .timebox strong { font-size: 1.28rem; }
  .hud span { font-size: .5rem; }
  .touch-controls { display: block; }
}

@media (pointer: coarse) and (orientation: portrait) {
  html, body {
    overflow: hidden;
    width: 100%;
    height: 100%;
    min-height: 100%;
    background: #050505;
  }

  .shell {
    display: block;
    overflow: hidden;
    position: fixed;
    inset: 0;
    padding: 0;
  }

  .shell > section {
    position: fixed;
    left: 50%;
    top: 50%;
    margin: 0;
    translate: -50% -50%;
    transform: rotate(90deg);
    transform-origin: center center;
    box-sizing: border-box;
  }

  .panel {
    width: calc(100vh - var(--mobile-safe-top) - var(--mobile-safe-bottom) - 22px);
    max-width: calc(100vh - var(--mobile-safe-top) - var(--mobile-safe-bottom) - 22px);
    max-height: calc(100vw - var(--mobile-safe-left) - var(--mobile-safe-right) - 16px);
    overflow: auto;
    padding: clamp(12px, 3vw, 18px);
    border-radius: 18px;
  }

  .menu-art {
    width: min(50%, 190px);
    max-height: 18vw;
    margin: 2px auto 8px;
  }

  h1 {
    font-size: clamp(1.9rem, 8vh, 3.5rem);
  }

  h2 {
    font-size: clamp(2rem, 8vh, 3rem);
  }

  .tagline,
  .final-detail,
  .record {
    margin-block: 6px;
  }

  .menu-actions {
    margin-top: 10px;
  }

  .how {
    max-height: min(26vw, 190px);
    overflow: auto;
    padding: 10px 12px;
    font-size: clamp(.78rem, 2.6vw, .92rem);
  }

  .game-panel {
    width: calc(100vh - var(--mobile-safe-top) - var(--mobile-safe-bottom) - 22px);
    height: calc(100vw - var(--mobile-safe-left) - var(--mobile-safe-right) - 16px);
    max-width: calc(100vh - var(--mobile-safe-top) - var(--mobile-safe-bottom) - 22px);
    max-height: calc(100vw - var(--mobile-safe-left) - var(--mobile-safe-right) - 16px);
  }

  canvas,
  .hud,
  .touch-controls,
  .message {
    opacity: 1;
    pointer-events: auto;
  }

  .touch-controls {
    bottom: max(14px, env(safe-area-inset-left, 0px));
    left: max(14px, env(safe-area-inset-bottom, 0px));
    right: max(14px, env(safe-area-inset-top, 0px));
    box-sizing: border-box;
  }

  .rotate-hint {
    display: none !important;
  }
}

@media (max-width: 520px) {
  .hud { width: calc(100% - 14px); grid-template-columns: 1.6fr .72fr .48fr .55fr; }
  .hud div { padding: 5px 3px; }
  .hud .scoreboard strong { font-size: 1.8rem; }
  .hud .timebox strong { font-size: 1.15rem; }
  .touch-buttons { right: max(14px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); gap: 10px; }
  .round-btn { width: 62px; height: 62px; font-size: 1.45rem; }
}

@supports (height: 100svh) {
  body, .shell { min-height: 100svh; height: 100svh; }
}



@media (pointer: coarse) and (orientation: landscape) {
  html, body {
    overflow: hidden;
    background: #050505;
  }

  .game-panel {
    width: calc(100vw - var(--mobile-safe-left) - var(--mobile-safe-right) - 16px);
    height: calc(100vh - var(--mobile-safe-top) - var(--mobile-safe-bottom) - 16px);
    max-width: calc(100vw - var(--mobile-safe-left) - var(--mobile-safe-right) - 16px);
    max-height: calc(100vh - var(--mobile-safe-top) - var(--mobile-safe-bottom) - 16px);
    margin: auto;
    box-sizing: border-box;
  }

  .touch-controls {
    bottom: max(14px, env(safe-area-inset-bottom, 0px));
    left: max(14px, env(safe-area-inset-left, 0px));
    right: max(14px, env(safe-area-inset-right, 0px));
    box-sizing: border-box;
  }
}



/* Dynamic joystick Safari/mobile fix */
.dynamic-joystick {
  position: fixed;
  width: 112px;
  height: 112px;
  margin-left: -56px;
  margin-top: -56px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.42);
  background: rgba(0, 0, 0, 0.28);
  box-shadow: 0 0 22px rgba(255, 140, 0, 0.22);
  z-index: 9999;
  display: none;
  pointer-events: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.dynamic-joystick.active {
  display: block;
}

.dynamic-joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin-left: -23px;
  margin-top: -23px;
  border-radius: 999px;
  background: rgba(255, 132, 0, 0.86);
  border: 2px solid rgba(255, 255, 255, 0.72);
  box-shadow: 0 0 18px rgba(255, 132, 0, 0.45);
  transform: translate(0px, 0px);
}

@media (pointer: coarse) {
  .joystick,
  .joystick-base,
  .joystick-stick,
  #joystick,
  #joystickBase,
  #joystickStick {
    opacity: 0 !important;
    pointer-events: none !important;
  }

  body {
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    overscroll-behavior: none;
  }
}
