* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #7ec8e3;
  font-family: 'Baloo 2', 'Comic Sans MS', system-ui, sans-serif;
  overscroll-behavior: none;
}

#app {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  align-items: flex-start;
  gap: 10px;
  pointer-events: none;
  z-index: 10;
}
#hud.hidden { display: none; }

.hud-panel {
  background: rgba(30, 25, 60, 0.45);
  border: 2px solid rgba(255,255,255,0.4);
  border-radius: 16px;
  padding: 6px 14px;
  color: #fff;
  backdrop-filter: blur(3px);
}

#score-box { text-align: left; }
#score-label {
  font-size: clamp(10px, 1.6vw, 14px);
  letter-spacing: 2px;
  opacity: 0.85;
}
#score-value {
  font-size: clamp(20px, 4vw, 30px);
  font-weight: 800;
  line-height: 1;
}

#lives-hearts {
  font-size: clamp(18px, 3.4vw, 26px);
  line-height: 1;
  display: flex;
  gap: 4px;
}

/* ---------- Level display (bottom-left) ---------- */
#level-display {
  position: fixed;
  left: 12px;
  left: calc(12px + env(safe-area-inset-left, 0px));
  bottom: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  font-weight: 700;
  font-size: clamp(14px, 2.6vw, 20px);
  z-index: 10;
}
#level-display.hidden { display: none; }

/* ---------- Exit / home button (top-right) ---------- */
#exit-btn {
  position: fixed;
  top: 12px;
  top: calc(12px + env(safe-area-inset-top, 0px));
  right: 12px;
  right: calc(12px + env(safe-area-inset-right, 0px));
  z-index: 35;
  font-family: inherit;
  font-weight: 700;
  font-size: clamp(12px, 2vw, 15px);
  color: #fff;
  background: rgba(60, 90, 60, 0.75);
  border: 2px solid rgba(255,255,255,0.4);
  border-radius: 14px;
  padding: 6px 16px;
  cursor: pointer;
}
#exit-btn.hidden { display: none; }

/* ---------- Toast ---------- */
#toast {
  position: absolute;
  top: 14%;
  left: 50%;
  transform: translate(-50%, 0);
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255,255,255,0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  border: 1px solid rgba(255,255,255,0.7);
  border-radius: 20px;
  padding: 10px 22px 10px 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  z-index: 20;
  transition: opacity 0.25s ease, transform 0.25s ease;
  opacity: 1;
}
#toast.hidden {
  opacity: 0;
  transform: translate(-50%, -20px);
  pointer-events: none;
}
#toast-icon { font-size: clamp(22px, 4vw, 32px); }
#toast-text {
  font-weight: 700;
  font-size: clamp(14px, 2.6vw, 22px);
  color: #1c1c34;
  text-shadow: 0 1px 3px rgba(255,255,255,0.6);
  max-width: 60vw;
}

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(20, 15, 45, 0.68);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  text-align: center;
  color: #fff;
  padding: 16px;
}
.overlay.hidden { display: none; }

.panel {
  max-width: 520px;
  background: rgba(40, 30, 75, 0.92);
  border: 3px solid rgba(255,255,255,0.3);
  border-radius: 26px;
  padding: clamp(18px, 4vw, 36px);
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}

.panel h1 {
  margin: 0 0 6px;
  font-size: clamp(24px, 5.6vw, 38px);
}
.panel h2 {
  margin: 0 0 14px;
  font-weight: 500;
  opacity: 0.85;
  font-size: clamp(14px, 3vw, 20px);
}
.panel p {
  font-size: clamp(14px, 2.6vw, 18px);
  line-height: 1.4;
}
.panel .hint {
  opacity: 0.7;
  font-size: clamp(12px, 2.2vw, 15px);
}
.panel .hint.hidden { display: none; }

.big-btn {
  font-family: inherit;
  font-size: clamp(18px, 3.6vw, 26px);
  font-weight: 700;
  color: #2b2b45;
  background: linear-gradient(#a6e3a1, #6bcf7f);
  border: none;
  border-radius: 999px;
  padding: 12px 38px;
  margin: 10px 0;
  box-shadow: 0 5px 0 #3f9a52, 0 8px 18px rgba(0,0,0,0.35);
  cursor: pointer;
  display: inline-block;
}
.big-btn:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #3f9a52, 0 3px 10px rgba(0,0,0,0.35);
}

.home-link {
  display: block;
  margin-top: 14px;
  color: rgba(255,255,255,0.65);
  font-size: clamp(12px, 2.2vw, 15px);
  text-decoration: none;
}
.home-link:active { color: rgba(255,255,255,0.95); }

@media (orientation: portrait) and (max-aspect-ratio: 1/1) {
  #rotate-screen.show-portrait-warning {
    display: flex;
  }
}
