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

html, body {
  min-height: 100%;
  background:
    radial-gradient(circle at 30% 15%, rgba(255, 170, 200, 0.16), transparent 45%),
    radial-gradient(circle at 75% 80%, rgba(140, 200, 255, 0.16), transparent 45%),
    linear-gradient(160deg, #1d1a3a 0%, #121126 60%, #0b0a18 100%) fixed;
  color: #fff;
  font-family: 'Segoe UI', Tahoma, sans-serif;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  overflow-x: hidden;
}

body {
  display: flex;
  justify-content: center;
  padding: 24px 12px 40px;
}

#game-shell {
  width: min(400px, 100%, max(140px, calc((100vh - var(--gp-header-h, 80px) - 81px) * 2 / 3)));
  width: min(400px, 100%, max(140px, calc((100dvh - var(--gp-header-h, 80px) - 81px) * 2 / 3)));
}

#hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 18px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-bottom: 0;
  border-radius: 16px 16px 0 0;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-variant-numeric: tabular-nums;
}

#hud > div { display: flex; align-items: baseline; gap: 7px; }
.hud-label { color: #b9b3dc; font-size: 10px; font-weight: 800; letter-spacing: 1.5px; }
#hud strong { color: #9fe8ff; font-size: 19px; }
#hud > div:nth-child(2) strong { color: #ffd38a; }
#hud > div:nth-child(3) strong { color: #ffb3c8; }

#mission-status {
  min-height: 26px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-top: 0;
  color: #d8d3f2;
  font-size: 10px;
  letter-spacing: 0.7px;
  text-align: center;
  text-transform: uppercase;
}

#game-area {
  position: relative;
  width: 100%;
  overflow: hidden;
  touch-action: none;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-top: 0;
  border-radius: 0 0 16px 16px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45), 0 0 60px rgba(255, 170, 200, 0.12);
}

#game-canvas { display: block; width: 100%; height: auto; background: #071017; touch-action: none; }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  align-items: safe center;
  justify-content: center;
  overflow-y: auto;
  background: rgba(16, 14, 40, 0.62);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 10;
}

.overlay.hidden, .hidden { display: none !important; }
.overlay-content { width: min(360px, calc(100% - 32px)); text-align: center; padding: 24px 16px; }
.overlay h1 { background: linear-gradient(180deg, #ffffff, #ffd3e2 45%, #b8c8ff); -webkit-background-clip: text; background-clip: text; color: transparent; font-size: clamp(28px, 8vw, 42px); letter-spacing: 4px; filter: drop-shadow(0 4px 0 rgba(90, 60, 160, 0.55)) drop-shadow(0 0 18px rgba(255, 190, 220, 0.4)); margin-bottom: 12px; }
#overlay-message { color: #e2ddf7; font-size: 16px; margin-bottom: 18px; }

.how-to-play {
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 14px;
  color: #e2ddf7;
  font-size: 13px;
  line-height: 1.8;
  text-align: left;
  margin-bottom: 20px;
}

.how-title { color: #b9b3dc; font-size: 10px; font-weight: 800; letter-spacing: 2px; margin-bottom: 6px; text-transform: uppercase; }

#overlay-button {
  min-width: 150px;
  padding: 13px 30px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, #ffb3c8, #b8c8ff);
  color: #1d1a3a;
  cursor: pointer;
  font: 800 15px 'Segoe UI', sans-serif;
  letter-spacing: 1px;
  text-transform: uppercase;
  box-shadow: 0 6px 0 rgba(90, 60, 160, 0.55), 0 10px 30px rgba(255, 179, 200, 0.35);
  transition: transform 0.2s, box-shadow 0.2s;
}

#overlay-button:hover { transform: translateY(-2px); box-shadow: 0 8px 0 rgba(90, 60, 160, 0.55), 0 14px 34px rgba(184, 200, 255, 0.45); }

#perfect-banner {
  position: absolute;
  top: 42%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #ffffff;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 4px;
  white-space: nowrap;
  pointer-events: none;
  text-shadow: 0 3px 0 rgba(90, 60, 160, 0.6), 0 0 22px rgba(255, 255, 255, 0.7);
  animation: banner-pop 0.45s cubic-bezier(.2, 1.5, .4, 1);
  z-index: 5;
}

@keyframes banner-pop {
  from { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
  to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

#touch-controls { display: none; justify-content: center; padding: 12px 0 0; }
#drop-button {
  width: min(260px, 90%);
  height: 54px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, #ffb3c8, #b8c8ff);
  color: #1d1a3a;
  box-shadow: 0 5px 0 rgba(90, 60, 160, 0.55);
  cursor: pointer;
  font: 800 14px 'Segoe UI', sans-serif;
  letter-spacing: 1px;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

#drop-button:active, #drop-button.pressed { transform: translateY(3px); box-shadow: 0 2px 0 rgba(90, 60, 160, 0.55); }

#highscores {
  list-style: none;
  margin: 18px 0 0;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 14px;
  color: #e2ddf7;
  text-align: center;
  font-size: 13px;
  line-height: 1.8;
}

#highscores::before { content: 'TOP SCORES'; display: block; color: #ffcf5c; font-size: 10px; font-weight: 800; letter-spacing: 2px; margin-bottom: 4px; }
#highscores li:first-child { color: #fff; font-weight: 800; }

@media (pointer: coarse), (max-width: 600px) {
  #touch-controls { display: flex; }
  #game-shell {
    width: min(400px, 100%, max(140px, calc((100vh - var(--gp-header-h, 80px) - 147px) * 2 / 3)));
    width: min(400px, 100%, max(140px, calc((100dvh - var(--gp-header-h, 80px) - 147px) * 2 / 3)));
  }
}

@media (max-height: 760px) {
  .overlay-content { padding: 14px 12px; }
  .overlay h1 { margin-bottom: 6px; }
  #overlay-message { margin-bottom: 10px; }
  .how-to-play { padding: 10px 14px; line-height: 1.6; margin-bottom: 12px; }
}

@media (max-width: 500px) {
  body { padding: 12px 8px 28px; }
  #hud { gap: 5px; padding: 9px 8px; }
  #hud > div { gap: 4px; }
  #hud strong { font-size: 15px; }
  .hud-label { font-size: 8px; letter-spacing: 0.5px; }
}

@media (max-width: 500px), (max-height: 500px) {
  .overlay { position: fixed; top: var(--gp-header-h, 48px); right: 0; bottom: 0; left: 0; z-index: 900; }
}

@media (orientation: landscape) and (max-height: 500px) {
  body { padding-bottom: 8px; }
  #game-shell { width: min(400px, 100%, max(140px, calc((100dvh - var(--gp-header-h, 48px) - 89px) * 2 / 3))); }
  #touch-controls {
    position: fixed;
    left: 0;
    right: 0;
    top: calc(50% + var(--gp-header-h, 48px) / 2);
    transform: translateY(-50%);
    padding: 0 16px;
    gap: 10px;
    pointer-events: none;
    z-index: 50;
  }
  #touch-controls { justify-content: flex-end; }
  #drop-button { pointer-events: auto; width: 150px; }
}

@media (orientation: landscape) and (max-height: 500px) {
  .overlay-content { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 24px; align-items: center; align-content: center; justify-items: center; width: min(780px, calc(100% - 24px)); max-width: none; }
  .overlay-content > * { grid-column: 2; }
  .overlay-content > .how-to-play { grid-column: 1; grid-row: 1 / span 6; margin: 0; max-width: 340px; width: 100%; }
  .overlay h1 { font-size: 30px; }
}

@media (orientation: landscape) and (max-height: 500px) {
  #game-shell {
    width: auto;
    display: grid;
    grid-template-columns: auto auto;
    column-gap: 8px;
    align-items: start;
    justify-content: center;
  }
  #hud {
    grid-column: 1;
    grid-row: 1;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 8px 10px;
    border: 1px solid #28536a;
    border-radius: 12px;
  }
  #mission-status { grid-column: 1; grid-row: 2; max-width: 130px; margin-top: 6px; border: 1px solid #28536a; border-radius: 10px; }
  #game-area {
    grid-column: 2;
    grid-row: 1 / span 3;
    width: max(150px, calc((100vh - var(--gp-header-h, 48px) - 12px) * 2 / 3));
    width: max(150px, calc((100dvh - var(--gp-header-h, 48px) - 12px) * 2 / 3));
    border-top: 1px solid #28536a;
    border-radius: 12px;
  }
  #highscores { grid-column: 1 / -1; }
}

@media (pointer: coarse) and (min-width: 700px) and (min-height: 700px) {
  #game-shell {
    width: min(540px, 100%, max(140px, calc((100vh - var(--gp-header-h, 80px) - 147px) * 2 / 3)));
    width: min(540px, 100%, max(140px, calc((100dvh - var(--gp-header-h, 80px) - 147px) * 2 / 3)));
  }
}

[data-theme="light"] html,
[data-theme="light"] body { background: var(--gp-page-grad) fixed; color: var(--gp-ink); }
[data-theme="light"] #hud, [data-theme="light"] #mission-status, [data-theme="light"] #highscores { background: var(--gp-surface); color: var(--gp-ink); box-shadow: inset 0 0 0 1px var(--gp-line), var(--gp-shadow); }
[data-theme="light"] .hud-label, [data-theme="light"] .how-title { color: var(--gp-ink-3); }
[data-theme="light"] #hud strong { color: #0a84b8; }
[data-theme="light"] #hud > div:nth-child(2) strong, [data-theme="light"] #highscores::before { color: #b7791f; }
[data-theme="light"] #hud > div:nth-child(3) strong { color: #15803d; }
[data-theme="light"] #mission-status, [data-theme="light"] #highscores { color: var(--gp-ink-2); }
[data-theme="light"] #highscores li:first-child { color: var(--gp-ink); }
[data-theme="light"] .overlay { background: var(--gp-overlay); }
[data-theme="light"] .overlay h1 { background: linear-gradient(180deg, #7c3aed, #db2777); -webkit-background-clip: text; background-clip: text; filter: none; }
[data-theme="light"] #overlay-message { color: var(--gp-ink-2); }
[data-theme="light"] .how-to-play { background: rgba(31, 27, 69, 0.05); border-color: var(--gp-line); color: var(--gp-ink-2); }
[data-theme="light"] #drop-button { color: #1d1a3a; }

.gp-btn-music.off { opacity: .4; }
