/* ── Reset & Base ── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  background: radial-gradient(circle at 50% 0%, #22345c 0%, #0c1222 65%) fixed, #0c1222;
  font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

/* ── Game Wrapper ── */
#game-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

/* ── HUD Bar ── */
#hud {
  width: min(400px, 100vw, max(150px, calc((100vh - var(--gp-header-h, 80px) - 66px) * 2 / 3)));
  width: min(400px, 100vw, max(150px, calc((100dvh - var(--gp-header-h, 80px) - 66px) * 2 / 3)));
  flex-shrink: 0;
  background: linear-gradient(180deg, rgba(28,42,74,0.96), rgba(20,30,56,0.96));
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border-radius: 16px 16px 0 0;
  border: 1px solid rgba(255,255,255,0.1);
  border-bottom: none;
}

#hud-score-label {
  color: #9fb4d8;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
}

#hud-score {
  color: #ffffff;
  font-size: 28px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 14px rgba(95, 184, 255, 0.45);
}

/* ── Canvas Container ── */
#canvas-container {
  position: relative;
  width: min(400px, 100vw, max(150px, calc((100vh - var(--gp-header-h, 80px) - 66px) * 2 / 3)));
  width: min(400px, 100vw, max(150px, calc((100dvh - var(--gp-header-h, 80px) - 66px) * 2 / 3)));
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.1);
  border-top: none;
  border-radius: 0 0 16px 16px;
  overflow: hidden;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55), 0 0 90px rgba(95, 184, 255, 0.12);
}

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

/* ── Overlays ── */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  align-items: safe center;
  justify-content: center;
  overflow-y: auto;
  background: linear-gradient(180deg, rgba(14, 26, 54, 0.62), rgba(10, 18, 40, 0.78));
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 10;
  transition: opacity 0.3s ease;
}

.overlay.hidden {
  display: none;
  opacity: 0;
}

.overlay-content {
  text-align: center;
  color: #ffffff;
  padding: 30px;
}

/* ── Start Screen ── */
.game-title {
  font-size: 42px;
  font-weight: 900;
  background: linear-gradient(135deg, #8ff5a8, #5fb8ff 55%, #c9a0ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 30px;
  text-shadow: none;
  filter: drop-shadow(0 4px 14px rgba(95, 184, 255, 0.4));
}

.start-doodler {
  width: 42px;
  height: 42px;
  background: radial-gradient(circle at 35% 30%, #c2f8cf, #52d283 55%, #22985a);
  border-radius: 48% 48% 46% 46%;
  margin: 0 auto 30px;
  position: relative;
  box-shadow: 0 6px 20px rgba(82, 210, 131, 0.45);
  animation: bob 1.2s ease-in-out infinite;
}

.start-doodler::before {
  content: '';
  position: absolute;
  width: 24px;
  height: 13px;
  top: 9px;
  left: 10px;
  background:
    radial-gradient(circle at 7px 7px, #1b1f2a 2.4px, transparent 2.9px),
    radial-gradient(circle at 19px 7px, #1b1f2a 2.4px, transparent 2.9px),
    radial-gradient(4.6px 6px at 6px 6.5px, #ffffff 92%, transparent 100%),
    radial-gradient(4.6px 6px at 18px 6.5px, #ffffff 92%, transparent 100%);
}

.start-doodler::after {
  content: '';
  position: absolute;
  width: 12px;
  height: 8px;
  background: #3cc26f;
  border-radius: 4px;
  top: 19px;
  right: -9px;
}

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-16px); }
}

.how-to {
  max-width: 340px;
  text-align: left;
  margin: 16px 0;
  padding: 14px 18px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.7;
  color: #dbe6f6;
}

.how-to-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #a9bcdd;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.start-hint {
  font-size: 20px;
  font-weight: 600;
  color: #ffffff;
  margin-bottom: 8px;
  animation: pulse 2s ease-in-out infinite;
}

.start-controls {
  font-size: 13px;
  color: #a9bcdd;
  letter-spacing: 1px;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Game Over Screen ── */
.gameover-title {
  font-size: 36px;
  font-weight: 900;
  color: #ff6b7d;
  margin-bottom: 24px;
  text-shadow: 0 4px 24px rgba(255, 90, 110, 0.45);
}

#final-score-box {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 16px 40px;
  margin-bottom: 24px;
  display: inline-block;
}

.final-score-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 3px;
  color: #7a7aaa;
  margin-bottom: 4px;
}

#final-score {
  font-size: 48px;
  font-weight: 900;
  color: #ffd700;
  text-shadow: 0 0 20px rgba(255, 215, 0, 0.4);
}

/* ── High Score Board ── */
#highscore-board {
  margin-bottom: 24px;
}

#highscore-board h3 {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #7a7aaa;
  text-transform: uppercase;
  margin-bottom: 10px;
}

#highscore-list {
  list-style: none;
  padding: 0;
}

#highscore-list li {
  font-size: 16px;
  font-weight: 600;
  color: #ccccee;
  padding: 4px 0;
  font-variant-numeric: tabular-nums;
}

#highscore-list li:first-child {
  color: #ffd700;
}

#highscore-list li:nth-child(2) {
  color: #c0c0d0;
}

#highscore-list li:nth-child(3) {
  color: #cd7f32;
}

#highscore-list li .rank {
  display: inline-block;
  width: 28px;
  text-align: right;
  margin-right: 10px;
  color: #5a5a8a;
  font-size: 13px;
}

#tilt-toggle {
  margin: 4px 0 14px;
  padding: 9px 18px;
  min-height: 40px;
  border: 1px solid rgba(255,255,255,0.28);
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  color: #e8f0fb;
  font: 700 13px 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  letter-spacing: 0.5px;
  cursor: pointer;
}

#tilt-toggle.on {
  background: rgba(127, 240, 154, 0.2);
  border-color: #7ff09a;
  color: #c9ffd6;
}

#tilt-toggle.hidden {
  display: none;
}

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

/* ── HUD Milestone ── */
#hud-milestone {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-left: 12px;
  padding: 2px 10px;
  border-radius: 10px;
  background: rgba(255,255,255,0.06);
  transition: color 0.3s, background 0.3s;
  min-width: 0;
}
#hud-milestone:empty {
  display: none;
}

/* ── Play Again Button ── */
#play-again-btn {
  background: linear-gradient(135deg, #8ff5a8, #5fb8ff);
  color: #0c1830;
  border: none;
  padding: 14px 48px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 1px;
  border-radius: 50px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 6px 22px rgba(95, 184, 255, 0.4);
  text-transform: uppercase;
}

#play-again-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(95, 184, 255, 0.6);
}

#play-again-btn:active {
  transform: translateY(0);
}

/* ── Mobile Responsive ── */
@media (max-width: 420px) {
  #hud {
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  #canvas-container {
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  .game-title {
    font-size: 32px;
  }

  .gameover-title {
    font-size: 28px;
  }

  #final-score {
    font-size: 36px;
  }
}

@media (max-height: 760px) {
  .overlay-content { padding: 16px 20px; }
  .game-title, .gameover-title { margin-bottom: 14px; }
  .start-doodler { margin-bottom: 14px; }
  #final-score-box, #highscore-board { margin-bottom: 14px; }
}

@media (max-height: 640px) {
  .start-controls, .start-doodler { display: none; }
  .how-to { margin: 8px 0; padding: 10px 14px; font-size: 12px; line-height: 1.5; }
}

@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; border-radius: 0; }
}

@media (orientation: landscape) and (max-height: 500px) {
  #start-overlay .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; }
  #start-overlay .overlay-content > * { grid-column: 2; }
  #start-overlay .overlay-content > .how-to { grid-column: 1; grid-row: 1 / span 6; margin: 0; max-width: 340px; width: 100%; }
  .game-title { font-size: 30px; margin-bottom: 8px; }
}

@media (pointer: coarse) and (min-width: 700px) and (min-height: 700px) {
  #hud, #canvas-container {
    width: min(540px, 100vw, max(150px, calc((100vh - var(--gp-header-h, 80px) - 66px) * 2 / 3)));
    width: min(540px, 100vw, max(150px, calc((100dvh - var(--gp-header-h, 80px) - 66px) * 2 / 3)));
  }
}

[data-theme="light"] html,
[data-theme="light"] body { background: var(--gp-page-grad) fixed; color: var(--gp-ink); }
[data-theme="light"] #hud { background: var(--gp-surface); box-shadow: inset 0 0 0 1px var(--gp-line); }
[data-theme="light"] #hud-score-label { color: var(--gp-ink-3); }
[data-theme="light"] #hud-score { color: var(--gp-ink); text-shadow: none; }
[data-theme="light"] #canvas-container { border-color: var(--gp-line); box-shadow: var(--gp-shadow); }
[data-theme="light"] .overlay { background: linear-gradient(180deg, rgba(250, 248, 255, 0.8), rgba(244, 242, 251, 0.9)); }
[data-theme="light"] .overlay-content, [data-theme="light"] .start-hint { color: var(--gp-ink); }
[data-theme="light"] .how-to { background: rgba(31, 27, 69, 0.05); border-color: var(--gp-line); color: var(--gp-ink-2); }
[data-theme="light"] .how-to-title, [data-theme="light"] .start-controls { color: var(--gp-ink-3); }
[data-theme="light"] .gameover-title { color: #e11d48; text-shadow: none; }
[data-theme="light"] #final-score-box { background: var(--gp-surface); border-color: var(--gp-line); }
[data-theme="light"] .final-score-label { color: var(--gp-ink-3); }
[data-theme="light"] #final-score, [data-theme="light"] #highscore-list li:first-child { color: #b7791f; text-shadow: none; }
[data-theme="light"] #highscore-board h3 { color: var(--gp-ink-3); }
[data-theme="light"] #highscore-list li { color: var(--gp-ink-2); }
[data-theme="light"] #highscore-list li .rank { color: var(--gp-ink-3); }
[data-theme="light"] #tilt-toggle { background: var(--gp-surface); color: var(--gp-ink-2); border-color: var(--gp-line); box-shadow: 0 3px 10px rgba(31, 27, 69, 0.08); }
[data-theme="light"] #tilt-toggle.on { color: #15803d; border-color: #22c55e; background: #ecfdf3; }
[data-theme="light"] .game-title { background: linear-gradient(135deg, #16a34a, #0284c7 55%, #7c3aed); -webkit-background-clip: text; background-clip: text; }
[data-theme="light"] #hud-milestone { filter: brightness(0.72) saturate(1.3); }
