/* ── 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% 20%, #2f63b0 0%, #183a75 45%, #0c1d40 100%) fixed;
  font-family: 'Nunito', '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, #46c0ff 0%, #2a9be6 100%);
  padding: 8px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border-radius: 16px 16px 0 0;
  border: 3px solid #1d3b66;
  border-bottom: none;
}

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

#hud-score {
  color: #ffffff;
  font-size: 28px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  -webkit-text-stroke: 2px #1d3b66;
  paint-order: stroke fill;
  text-shadow: 0 3px 0 #1d3b66;
}

#hud-score.bump { animation: score-bump 0.3s ease-out; }

@keyframes score-bump {
  40% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

/* ── 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: 3px solid #1d3b66;
  border-top: none;
  border-radius: 0 0 16px 16px;
  overflow: hidden;
  box-shadow: 0 8px 0 rgba(10, 25, 55, 0.6), 0 20px 50px rgba(0, 0, 0, 0.35);
}

#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: rgba(20, 60, 110, 0.32);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 10;
  transition: opacity 0.3s ease;
}

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

.overlay-content {
  text-align: center;
  color: #22324f;
  padding: 22px 22px 20px;
  margin: 12px;
  max-width: 360px;
  background: #ffffff;
  border: 3px solid #1d3b66;
  border-radius: 22px;
  box-shadow: 0 6px 0 #1d3b66, 0 18px 40px rgba(10, 30, 70, 0.35);
}

/* ── Start Screen ── */
.game-title {
  font-size: 42px;
  font-weight: 900;
  color: #ffcf1f;
  -webkit-text-stroke: 3px #1d3b66;
  paint-order: stroke fill;
  text-shadow: 0 4px 0 #1d3b66;
  margin-bottom: 18px;
  letter-spacing: 1px;
}

.start-bird {
  width: 52px;
  height: 40px;
  background: radial-gradient(circle at 35% 30%, #fff27a, #ffcf1f 55%, #e39b00);
  border: 3px solid #1d3b66;
  border-radius: 50%;
  margin: 0 auto 18px;
  position: relative;
  animation: bob 1.2s ease-in-out infinite;
}

.start-bird::before {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  top: 4px;
  right: 6px;
  background: radial-gradient(circle at 62% 50%, #1c1430 0 3px, #ffffff 3.5px);
  border: 2px solid #1d3b66;
}

.start-bird::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 9px;
  background: #ff8a3d;
  border: 2px solid #1d3b66;
  border-radius: 0 9px 9px 0;
  top: 18px;
  right: -14px;
}

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

.how-to {
  max-width: 340px;
  text-align: left;
  margin: 16px 0;
  padding: 12px 16px;
  background: #eaf7ff;
  border: 2px solid #bfe3ff;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.6;
  color: #2b3a5c;
}

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

.start-hint {
  font-size: 20px;
  font-weight: 900;
  color: #1d3b66;
  margin-bottom: 6px;
  animation: pulse 2s ease-in-out infinite;
}

.start-controls {
  font-size: 12px;
  color: #5a7bb0;
  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: #ff6b6b;
  -webkit-text-stroke: 3px #1d3b66;
  paint-order: stroke fill;
  text-shadow: 0 4px 0 #1d3b66;
  margin-bottom: 16px;
}

#final-score-box {
  background: #fff7e0;
  border: 2px solid #ffd98a;
  border-radius: 16px;
  padding: 12px 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  text-align: left;
}

.final-meta { font-size: 12px; color: #6a5a3a; margin-top: 2px; }
.final-meta strong { color: #22324f; }

.medal {
  position: relative;
  flex-shrink: 0;
  width: 66px;
  height: 66px;
  border-radius: 50%;
  border: 3px solid #1d3b66;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.15), 0 3px 0 #1d3b66;
}
.medal span { position: absolute; bottom: -18px; font-size: 10px; font-weight: 900; letter-spacing: 1px; text-transform: uppercase; color: #22324f; white-space: nowrap; }
.medal.none { background: #eef2f7; border-style: dashed; box-shadow: none; }
.medal.bronze { background: radial-gradient(circle at 35% 30%, #ffe0bd, #e09a55 55%, #9a5b22); }
.medal.silver { background: radial-gradient(circle at 35% 30%, #ffffff, #cfd6e0 55%, #8a95a6); }
.medal.gold { background: radial-gradient(circle at 35% 30%, #fff6c2, #ffcc33 55%, #c98a00); }
.medal.platinum { background: radial-gradient(circle at 35% 30%, #ffffff, #c8ecff 50%, #7fb3d6); }
.medal:not(.none)::before { content: '\2605'; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -54%); font-size: 30px; color: rgba(255, 255, 255, 0.9); text-shadow: 0 2px 0 rgba(0, 0, 0, 0.2); }
.medal.new-best::after { content: 'NEW'; position: absolute; top: -8px; right: -12px; padding: 2px 6px; border-radius: 999px; background: #ff5f6d; color: #fff; font-size: 10px; font-weight: 900; border: 2px solid #1d3b66; }
.final-score-main { min-width: 0; }

.final-score-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 3px;
  color: #b07a1f;
  margin-bottom: 2px;
}

#final-score {
  font-size: 40px;
  line-height: 1;
  font-weight: 900;
  color: #22324f;
}

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

#highscore-board h3 {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 2px;
  color: #5a7bb0;
  text-transform: uppercase;
  margin-bottom: 10px;
}

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

#highscore-list li {
  font-size: 15px;
  font-weight: 800;
  color: #2b3a5c;
  padding: 3px 0;
  font-variant-numeric: tabular-nums;
}

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

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

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

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

/* ── 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: #ffffff;
  border: 2px solid #1d3b66;
  transition: color 0.3s, background 0.3s;
  min-width: 0;
}
#hud-milestone:empty {
  display: none;
}

/* ── Mode Selector ── */
#mode-selector {
  margin: 12px 0 14px;
  text-align: center;
}

.mode-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 2px;
  color: #5a7bb0;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.mode-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 12px;
}

.mode-btn {
  background: #ffffff;
  color: #1d3b66;
  border: 2px solid #1d3b66;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 800;
  border-radius: 20px;
  box-shadow: 0 3px 0 #1d3b66;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  letter-spacing: 0.5px;
}

.mode-btn:hover {
  transform: translateY(-1px);
}

.mode-btn.active {
  color: #ffffff;
  background: #4f7cff;
}

.mode-btn[data-mode="classic"].active {
  background: #3ccf5c;
}

.mode-btn[data-mode="reverse"].active {
  background: #ff9a3d;
}

.mode-btn[data-mode="night"].active {
  background: #5b5bd6;
}

.skin-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 10px;
}

#skin-picker { display: flex; gap: 8px; }

.skin-btn {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid #1d3b66;
  background: radial-gradient(circle at 35% 30%, var(--skin-light), var(--skin) 60%);
  cursor: pointer;
  box-shadow: 0 3px 0 #1d3b66;
  transition: transform 0.15s;
}
.skin-btn::after { content: ''; position: absolute; top: 8px; right: 7px; width: 7px; height: 7px; border-radius: 50%; background: radial-gradient(circle at 60% 50%, #1c1430 0 2px, #fff 2.5px); }
.skin-btn:hover { transform: translateY(-2px); }
.skin-btn.active { outline: 3px solid #ffcf1f; outline-offset: 2px; }
.skin-btn.locked { filter: grayscale(0.85) brightness(0.9); cursor: not-allowed; }
.skin-btn.locked::after { display: none; }
.skin-btn span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 900; color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); }

.coin-bank { display: inline-flex; align-items: center; gap: 5px; font-size: 14px; font-weight: 900; color: #22324f; }
.coin-bank i { width: 16px; height: 16px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff7b0, #ffd23d 55%, #c98a00); border: 2px solid #a86f00; }

/* ── Ghost Toggle ── */
.ghost-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  color: #4a5f86;
}

.ghost-toggle input[type="checkbox"] {
  accent-color: #4f7cff;
  width: 14px;
  height: 14px;
  cursor: pointer;
}

.ghost-toggle-label {
  user-select: none;
  letter-spacing: 0.5px;
}

/* ── Play Again Button ── */
#play-again-btn {
  background: linear-gradient(180deg, #5fe07a, #2fb24f);
  color: #ffffff;
  border: 3px solid #1d3b66;
  padding: 12px 44px;
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 1px;
  border-radius: 50px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 5px 0 #1d3b66;
  text-transform: uppercase;
  -webkit-text-stroke: 1px #1d3b66;
  paint-order: stroke fill;
}

#play-again-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 7px 0 #1d3b66;
}

#play-again-btn:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #1d3b66;
}

/* ── 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;
  }

  .overlay-content {
    padding: 16px 14px;
  }

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

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

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

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

@media (max-height: 700px) {
  #mode-selector { margin: 8px 0 8px; }
  .start-controls, .start-bird { display: none; }
  .how-to { margin: 8px 0; padding: 8px 12px; font-size: 12px; line-height: 1.45; }
  .game-title { font-size: 34px; }
}

@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) {
  .ghost-toggle { min-height: 36px; padding: 0 8px; }
  .ghost-toggle input[type="checkbox"] { width: 18px; height: 18px; }
}

@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: radial-gradient(circle at 50% 20%, #d9f3ff 0%, #bfe6ff 45%, #a6d8ff 100%) fixed; color: var(--gp-ink); }
[data-theme="light"] .overlay { background: rgba(120, 190, 255, 0.25); }
[data-theme="light"] #hud-milestone { filter: none; }

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