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

:root{
  --bg1:#0b0e1a;
  --bg2:#161b2e;
  --accent:#4fd1ff;
  --accent2:#ff4f9a;
  --gold:#ffd24f;
  --text:#eaf2ff;
}

html, body{
  height: 100%;
  background: radial-gradient(1200px 800px at 50% -10%, #1c2340 0%, var(--bg1) 55%, #05060c 100%);
  color: var(--text);
  font-family: 'Segoe UI', Tahoma, Verdana, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app{
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  padding: 10px;
  gap: 8px;
}

#hud{
  width: min(100%, var(--stage-w, 800px));
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 8px 14px;
  background: rgba(20,24,44,0.75);
  border: 1px solid rgba(79,209,255,0.25);
  border-radius: 12px;
  font-size: 14px;
  letter-spacing: .3px;
  backdrop-filter: blur(6px);
}

.hud-item{ white-space: nowrap; opacity: .95; }
.hud-item span{ color: var(--accent); font-weight: 700; }
#lives span{ color: var(--accent2); letter-spacing: 2px; }

.icon-btn{
  margin-left: auto;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.15);
  color: var(--text);
  border-radius: 8px;
  width: 34px; height: 30px;
  cursor: pointer;
  font-size: 15px;
  transition: transform .12s ease, background .2s ease;
}
.icon-btn:hover{ background: rgba(255,255,255,0.14); transform: translateY(-1px); }
#pauseBtn{ margin-left: 6px; }

#stage{
  position: relative;
  flex: 1;
  width: 100%;
  max-width: 1280px;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#playfield{
  position: relative;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid rgba(79,209,255,0.25);
  box-shadow: 0 20px 60px rgba(0,0,0,0.55), inset 0 0 80px rgba(79,209,255,0.04);
}

canvas{
  display: block;
  width: 100%;
  height: 100%;
  background: #05070f;
  touch-action: none;
}

.overlay{
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  background: rgba(5,7,15,0.86);
  backdrop-filter: blur(3px);
  padding: 24px;
  animation: fadeIn .25s ease;
}
.hidden{ display: none !important; }

@keyframes fadeIn{ from{ opacity:0; } to{ opacity:1; } }

.title{
  font-size: clamp(32px, 7vw, 54px);
  letter-spacing: 2px;
  font-weight: 800;
  text-shadow: 0 0 22px rgba(79,209,255,0.55);
}
.title span{ color: var(--accent); }

.subtitle{ opacity: .75; font-size: 14px; margin-bottom: 8px; }

.btn{
  min-width: 220px;
  padding: 12px 22px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  transition: transform .12s ease, background .2s ease, box-shadow .2s ease;
}
.btn:hover{ transform: translateY(-2px); background: rgba(255,255,255,0.12); }
.btn.primary{
  background: linear-gradient(135deg, var(--accent), #2a7dff);
  border: none;
  color: #05070f;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(79,209,255,0.35);
}
.btn.primary:hover{ box-shadow: 0 10px 30px rgba(79,209,255,0.5); }

.btn.fs-btn{
  min-width: 0;
  padding: 8px 18px;
  font-size: 14px;
  opacity: .85;
}
#continueBtn{ display: none; }

/* Level select grid */
.level-grid{
  display: grid;
  grid-template-columns: repeat(5, 58px);
  gap: 10px;
  padding: 8px;
  max-width: 100%;
}
.level-btn{
  width: 58px; height: 58px;
  border-radius: 10px;
  border: 1px solid rgba(79,209,255,0.3);
  background: rgba(79,209,255,0.08);
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .12s ease, background .2s ease, box-shadow .2s ease;
}
.level-btn:hover{ background: rgba(79,209,255,0.2); transform: translateY(-2px); box-shadow: 0 6px 18px rgba(79,209,255,0.25); }
.level-btn.locked{
  opacity: .35;
  cursor: not-allowed;
  background: rgba(255,255,255,0.04);
  border-color: rgba(255,255,255,0.12);
}
.level-btn.locked:hover{ transform: none; background: rgba(255,255,255,0.04); box-shadow: none; }
#levelSelectOverlay h2{ margin-bottom: 6px; }

.footer-note{ margin-top: 18px; font-size: 12px; opacity: .55; max-width: 420px; }

.howto-list{ list-style: none; text-align: left; max-width: 480px; }
.howto-list li{ margin: 8px 0; font-size: 15px; line-height: 1.4; }

.big-stat{ font-size: 22px; color: var(--gold); font-weight: 700; }
.danger{ color: var(--accent2); font-size: 30px; }
.win{ font-size: 28px; color: var(--gold); text-shadow: 0 0 24px rgba(255,210,79,0.6); }

#toast{
  position: absolute;
  top: 14px; left: 50%;
  transform: translateX(-50%);
  background: rgba(20,24,44,0.9);
  border: 1px solid rgba(79,209,255,0.4);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  pointer-events: none;
  animation: toastPop .28s ease;
  z-index: 20;
}
@keyframes toastPop{
  from{ opacity: 0; transform: translateX(-50%) translateY(-10px); }
  to{ opacity: 1; transform: translateX(-50%) translateY(0); }
}

#touchZone{ display: none; }

/* ---------- Responsive: small screens / portrait ---------- */
@media (max-width: 620px){
  #app{ padding: 6px; gap: 6px; }
  #hud{ font-size: 11px; gap: 8px; padding: 6px 10px; flex-wrap: wrap; justify-content: center; }
  .icon-btn{ width: 30px; height: 27px; font-size: 13px; }
  .btn{ min-width: 170px; font-size: 14px; padding: 10px 16px; }
  .subtitle{ font-size: 12px; }
  .howto-list li{ font-size: 13px; }
  .footer-note{ font-size: 11px; }
  .level-grid{ grid-template-columns: repeat(4, 48px); gap: 8px; }
  .level-btn{ width: 48px; height: 48px; font-size: 16px; }
}

/* Landscape phones (short height): compact HUD & overlays */
@media (max-height: 500px){
  #app{ padding: 4px; gap: 4px; }
  #hud{ padding: 3px 10px; font-size: 12px; gap: 12px; }
  .overlay{ padding: 12px; gap: 8px; }
  .btn{ min-width: 160px; padding: 8px 16px; font-size: 14px; }
}
