:root{
  --frame-w: 1000px;
  --frame-h: 760px;
  --accent: #35ffa0;
  --panel: rgba(0,0,0,0.55);
  --panel-strong: rgba(0,0,0,0.75);
  --text: #e9ffee;
  --desktop-offset: 19.6vh; /* desktop vertical position */

  /* mobile viewport height (with modern fallbacks) */
  --app-h: 100vh;

  /* fixed site header height on mobile */
  --site-header-h: 56px;

  /* tiny right inset to avoid clipping near rounded corners/notches */
  --mobile-right-gutter: 10px;

  /* PUSH HUD + CANVAS DOWN on mobile (increase to go lower) */
  --mobile-top-offset: 92px;  /* try 84–108px to taste */
}
@supports (height: 100svh){ :root{ --app-h: 100svh; } }
@supports (height: 100dvh){ :root{ --app-h: 100dvh; } }

* { box-sizing: border-box; }
html, body { height: 100%; }
html, body { overscroll-behavior-y: none; touch-action: manipulation; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  color: var(--text);
  font-family: system-ui, Segoe UI, Roboto, Inter, Arial, sans-serif;
  background: #000;
  overflow: hidden;
}

/* Background video */
.bg-video{
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  filter: saturate(1.2) contrast(1.05) brightness(0.7);
  z-index: -2;
}
.bg-overlay{
  position: fixed; inset: 0;
  background:
    radial-gradient(60% 60% at 50% 30%, rgba(0,255,170,0.10), transparent 60%),
    linear-gradient(to bottom, rgba(0,0,0,0.35), rgba(0,0,0,0.65));
  z-index: -1;
}

/* Hide video bg on phones only */
@media (max-width: 900px){
  .bg-video, .bg-overlay { display: none !important; }
}

/* Page wrapper */
.page-offset{
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 0 10px;
}
@media (min-width: 901px){
  .page-offset{ align-content: start; padding-top: var(--desktop-offset); }
}

/* MOBILE: below fixed header + extra offset; keep full-screen height */
@media (max-width: 900px){
  .page-offset{
    height: calc(var(--app-h) - var(--site-header-h) - var(--mobile-top-offset));
    min-height: 0;
    padding: calc(var(--site-header-h) + var(--mobile-top-offset)) 0 0 0;
    display: grid;
    place-items: center;
  }
}

/* Game shell */
.game-shell{
  width: min(100vw, var(--frame-w));
  height: min(100vh, var(--frame-h));
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto;  /* HUD / stage / footer */
  gap: 10px;
  padding: 10px;
  background: var(--panel);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(53,255,160,0.25);
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.45), inset 0 0 80px rgba(53,255,160,0.10);
}
@media (min-width: 901px){
  .game-shell{
    transform: scale(.9) scaleY(.94) scaleX(1.140);
    transform-origin: top center;
  }
}

/* MOBILE: shell fills available area; keep grid; add bigger row gap for HUD clearance */
@media (max-width: 900px){
  .game-shell{
    width: 100vw;
    height: 100%;
    border-radius: 0;
    border: none;
    background: var(--panel-strong);
    padding: calc(env(safe-area-inset-top,0px) + 6px)
             calc(env(safe-area-inset-right,0px) + 8px)
             calc(env(safe-area-inset-bottom,0px) + 6px)
             calc(env(safe-area-inset-left,0px) + 8px);
    gap: 12px; /* ↑ ensures HUD never overlaps the canvas */
    display: grid;
    grid-template-rows: auto minmax(0,1fr) auto; /* prevent overflow pushing under HUD */
    align-content: stretch;
  }
}

/* HUD */
.hud{
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(0,0,0,0.45);
  border: 1px solid rgba(53,255,160,0.2);
  z-index: 1; /* always above stage visuals */
}
.hud .title { color: var(--accent); font-weight: 700; letter-spacing: 0.5px; }
.hud-center { display: flex; gap: 16px; justify-content: center; }
.hud-right { display: flex; justify-content: end; }
.music-controls{
  display: inline-flex; gap: 6px; align-items: center;
  background: rgba(0,0,0,0.35);
  padding: 4px 6px; border-radius: 8px;
  border: 1px solid rgba(53,255,160,0.15);
}
.music-controls button{
  cursor: pointer; border: 1px solid rgba(53,255,160,0.25);
  background: rgba(0,0,0,0.5); color: var(--text);
  padding: 4px 6px; border-radius: 6px;
}
.music-controls input[type="range"]{ width: 80px; }

/* Stage */
.game-stage{
  position: relative;
  display: grid;
  place-items: center;
  padding: 8px;
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(0,0,0,0.35), rgba(0,0,0,0.65));
  border: 1px solid rgba(53,255,160,0.2);
}

/* MOBILE: full-bleed canvas inside the stage, centered; safe right inset */
@media (max-width: 900px){
  .game-stage{
    padding: 8px; /* tiny visual breathing room below the HUD */
    padding-inline-end: calc(var(--mobile-right-gutter) + env(safe-area-inset-right, 0px));
    padding-inline-start: calc(env(safe-area-inset-left, 0px));
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 0;
  }
}

#game{
  width: 100%;
  height: auto;               /* desktop default keeps intrinsic 900x600 ratio */
  max-height: 100%;
  image-rendering: pixelated;
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.45), inset 0 0 40px rgba(53,255,160,0.08);
  background: transparent;
  touch-action: none;
}

/* MOBILE: stretch to fill BOTH dimensions of the stage (matches phone aspect) */
@media (max-width: 900px){
  #game{
    width: 100%;
    height: 100%;   /* fill height as well */
    max-width: 100%;
    max-height: 100%;
    margin: 0;
  }
}

/* Touch controls (fallback only) */
.touch-controls{
  position: absolute; inset-inline: 0; bottom: 8px;
  display: none; gap: 10px; justify-content: center;
}
.touch-controls .ctl{
  font-size: 22px;
  width: 72px; height: 56px;
  border-radius: 10px;
  border: 1px solid rgba(53,255,160,0.35);
  background: rgba(0,0,0,0.55);
  color: var(--text); backdrop-filter: blur(6px);
}
@media (max-width: 900px) { .touch-controls{ display: flex; } }

/* Game Over Overlay */
.gameover-overlay{
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(0,0,0,0.55);
  border-radius: 10px;
}
.gameover-overlay[hidden]{ display: none !important; }
.gameover-overlay .panel{
  background: rgba(0,0,0,0.75);
  border: 1px solid rgba(53,255,160,0.35);
  border-radius: 12px;
  padding: 18px 20px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5), inset 0 0 40px rgba(53,255,160,0.08);
}
.gameover-overlay h2{ margin: 0 0 8px; color: var(--accent); }
.gameover-overlay .btn{
  margin-top: 10px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid rgba(53,255,160,0.5);
  background: rgba(0,0,0,0.6);
  color: var(--text);
  cursor: pointer;
}
.gameover-overlay .btn:hover{ filter: brightness(1.1); }

/* NEW: Paused badge */
.paused-badge{
  position:absolute; top:10px; right:10px;
  background: rgba(0,0,0,0.6);
  border:1px solid rgba(53,255,160,0.4);
  padding:4px 8px; border-radius:8px;
  font-weight:700; color:var(--accent);
}

/* NEW: High Scores modal */
.modal{ position:absolute; inset:0; display:grid; place-items:center; background: rgba(0,0,0,0.55); border-radius:10px; }
.modal[hidden]{ display:none !important; }
.modal-panel{
  width:min(90vw, 520px);
  background: rgba(0,0,0,0.78);
  border:1px solid rgba(53,255,160,0.35);
  border-radius:12px; padding:16px 18px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.55), inset 0 0 40px rgba(53,255,160,0.08);
}
.modal-panel h3{ margin:0 0 10px; color:var(--accent); }
.hs-list{ margin:0; padding-left:20px; max-height:50vh; overflow:auto; }
.modal-actions{ display:flex; justify-content:end; margin-top:12px; }
.modal .btn{
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid rgba(53,255,160,0.5);
  background: rgba(0,0,0,0.6);
  color: var(--text);
  cursor: pointer;
}
