@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@700;900&display=swap');

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

:root {
  --neon-green: #00ff88;
  --neon-blue:  #00cfff;
  --neon-gold:  #ffd700;
  --bg:         #07020f;
  --pill-bg:    rgba(255,255,255,0.07);

  /* Single source of truth for canvas display size — used by both canvas and controls */
  --game-size: min(96vw, calc(96vh - 110px));
}

html, body {
  height: 100%;
  width: 100%;
  background: var(--bg);
  color: #fff;
  font-family: 'Nunito', 'Arial Rounded MT Bold', sans-serif;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Prevent pull-to-refresh / scroll on iOS */
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-height: 100dvh; /* dynamic viewport on mobile (handles browser chrome) */
  padding: 4px 0;
}

/* ── HUD ─────────────────────────────────────── */
#hud {
  display: flex;
  gap: 8px;
  align-items: center;
  width: var(--game-size);
  max-width: 520px;
  justify-content: center;
  flex-wrap: wrap;
}

.hud-pill {
  background: var(--pill-bg);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 50px;
  padding: 5px 14px;
  font-size: clamp(10px, 2.5vw, 13px);
  font-weight: 900;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  white-space: nowrap;
}

#hud-level { color: var(--neon-gold);  text-shadow: 0 0 10px var(--neon-gold); }
#hud-balls { color: var(--neon-green); text-shadow: 0 0 10px var(--neon-green); }
#hud-shots { color: var(--neon-blue);  text-shadow: 0 0 10px var(--neon-blue); }

/* ── Canvas ──────────────────────────────────── */
#canvas-wrap {
  position: relative;
  border-radius: 12px;
  box-shadow: 0 0 40px rgba(0,255,136,0.15), 0 0 80px rgba(0,0,0,0.8);
  flex-shrink: 0;
}

#gameCanvas {
  display: block;
  border-radius: 12px;
  cursor: crosshair;
  width:  var(--game-size);
  height: var(--game-size);
  max-width:  520px;
  max-height: 520px;
  /* Critical for mobile: prevent browser scroll/zoom while dragging on canvas */
  touch-action: none;
}

/* ── Controls ────────────────────────────────── */
#controls {
  display: flex;
  align-items: center;
  gap: 8px;
  width: var(--game-size);
  max-width: 520px;
  justify-content: space-between;
}

.ctrl-btn {
  background: rgba(255,255,255,0.08);
  border: 1.5px solid rgba(255,255,255,0.2);
  border-radius: 50px;
  color: #fff;
  font-family: 'Nunito', sans-serif;
  font-weight: 900;
  font-size: clamp(11px, 2.8vw, 13px);
  letter-spacing: 0.5px;
  /* Minimum 44×44 touch target (Apple HIG) */
  min-height: 44px;
  padding: 0 18px;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
  touch-action: manipulation; /* no double-tap zoom on button */
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}
.ctrl-btn:hover  { background: rgba(255,255,255,0.16); border-color: rgba(255,255,255,0.45); }
.ctrl-btn:active { opacity: 0.75; }

#btn-next {
  color: var(--neon-green);
  border-color: var(--neon-green);
  text-shadow: 0 0 8px var(--neon-green);
}

#tip {
  font-size: clamp(9px, 2vw, 11px);
  color: rgba(255,255,255,0.3);
  text-align: center;
  flex: 1;
  min-width: 0; /* allow shrinking */
  line-height: 1.3;
}

/* ── Overlay ─────────────────────────────────── */
#overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7,2,15,0.88);
  backdrop-filter: blur(6px);
  z-index: 100;
  transition: opacity 0.3s;
  padding: 16px;      /* safe margin on narrow screens */
}
#overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.ov-panel {
  background: radial-gradient(ellipse at center, #0d2a18 0%, #050e0a 100%);
  border: 2px solid rgba(0,255,136,0.4);
  border-radius: 20px;
  padding: clamp(20px, 6vw, 40px) clamp(20px, 8vw, 50px);
  text-align: center;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 0 60px rgba(0,255,136,0.2), inset 0 0 40px rgba(0,0,0,0.5);
}

.ov-title {
  font-size: clamp(48px, 14vw, 72px);
  font-weight: 900;
  background: linear-gradient(135deg, #ffd700, #ff8c00, #ffd700);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 16px rgba(255,200,0,0.6));
  line-height: 1;
  margin-bottom: 8px;
}

.ov-sub {
  font-size: clamp(11px, 3vw, 14px);
  color: rgba(255,255,255,0.55);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 28px;
  line-height: 1.5;
}

.ov-btn {
  background: linear-gradient(135deg, #00cc66, #009944);
  border: none;
  border-radius: 50px;
  color: #fff;
  font-family: 'Nunito', sans-serif;
  font-weight: 900;
  font-size: clamp(15px, 4vw, 18px);
  letter-spacing: 2px;
  /* Large touch target */
  min-height: 52px;
  padding: 0 clamp(28px, 8vw, 48px);
  cursor: pointer;
  box-shadow: 0 0 30px rgba(0,255,136,0.4), 0 4px 20px rgba(0,0,0,0.5);
  transition: all 0.2s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  width: 100%;
}
.ov-btn:active { opacity: 0.8; transform: scale(0.97); }

/* ── Safe area insets (notch / home bar on iOS) ── */
@supports (padding: env(safe-area-inset-bottom)) {
  #app {
    padding-bottom: max(4px, env(safe-area-inset-bottom));
    padding-left:   max(0px, env(safe-area-inset-left));
    padding-right:  max(0px, env(safe-area-inset-right));
  }
}
