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

:root {
  --sky: #4ec0ca;
  --gold: #f5c518;
  --pipe: #73bf2e;
  --btn-bg: #f5c518;
  --btn-hover: #e6b800;
  --text-dark: #1a1a1a;
  --overlay: rgba(0,0,0,0.55);
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #000;
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: 'Segoe UI', system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

#game-wrapper {
  position: relative;
  width: 480px;
  height: 640px;
  max-width: 100vw;
  max-height: 100vh;
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

/* ── Screens ── */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  pointer-events: none;
}
.screen.active, .screen.visible { pointer-events: all; }
.hidden { display: none !important; }

/* ── Start Screen ── */
#screen-start {
  gap: 24px;
  background: transparent;
}
.logo-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.logo-bird {
  width: 60px; height: 48px;
  background: #f5c518;
  border-radius: 50% 50% 40% 40%;
  border: 3px solid #1a1a1a;
  position: relative;
  box-shadow: 0 4px 0 #c8960c;
  animation: bobble 1s ease-in-out infinite alternate;
}
.logo-bird::before {
  content: '';
  position: absolute;
  right: -14px; top: 14px;
  width: 16px; height: 10px;
  background: #f08c00;
  border-radius: 0 8px 8px 0;
  border: 2px solid #1a1a1a;
}
.logo-bird::after {
  content: '';
  position: absolute;
  left: 10px; top: 10px;
  width: 10px; height: 10px;
  background: #fff;
  border-radius: 50%;
  border: 2px solid #1a1a1a;
}
@keyframes bobble { from { transform: translateY(0); } to { transform: translateY(-12px); } }

.game-title {
  font-size: 2.8rem;
  font-weight: 900;
  color: #fff;
  text-shadow: 3px 3px 0 #1a1a1a, -1px -1px 0 #1a1a1a, 1px -1px 0 #1a1a1a, -1px 1px 0 #1a1a1a;
  letter-spacing: 2px;
}
.start-prompt {
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 2px 2px 0 #1a1a1a;
  background: rgba(0,0,0,0.35);
  padding: 10px 28px;
  border-radius: 24px;
  border: 2px solid rgba(255,255,255,0.3);
}
.tap-anim { animation: pulse 1.1s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: 1; } to { opacity: 0.4; } }

.controls-hint {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  color: rgba(255,255,255,0.75);
  text-shadow: 1px 1px 0 #000;
}

/* ── HUD ── */
#hud {
  justify-content: flex-start;
  align-items: center;
  padding: 16px 20px 0;
  flex-direction: row;
  justify-content: space-between;
}
#score-display {
  font-size: 3rem;
  font-weight: 900;
  color: #fff;
  text-shadow: 3px 3px 0 #1a1a1a;
  line-height: 1;
}
#btn-pause {
  background: rgba(0,0,0,0.4);
  border: 2px solid rgba(255,255,255,0.4);
  color: #fff;
  border-radius: 8px;
  font-size: 1.1rem;
  padding: 6px 12px;
  cursor: pointer;
  letter-spacing: 3px;
  transition: background 0.15s;
}
#btn-pause:hover { background: rgba(0,0,0,0.65); }

/* ── Overlay boxes ── */
.overlay-box {
  background: linear-gradient(160deg, #fffbe6 0%, #fff8d0 100%);
  border: 4px solid #1a1a1a;
  border-radius: 20px;
  padding: 28px 36px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  min-width: 280px;
  box-shadow: 0 8px 0 #1a1a1a, 0 12px 30px rgba(0,0,0,0.4);
}
.overlay-box h2 {
  font-size: 2rem;
  font-weight: 900;
  color: #1a1a1a;
  letter-spacing: 2px;
}
.over-title {
  color: #d62b2b !important;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.15);
}

/* ── Score rows ── */
.score-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  font-size: 1.1rem;
  font-weight: 700;
  color: #333;
  background: rgba(0,0,0,0.06);
  border-radius: 10px;
  padding: 8px 16px;
}
.score-row span:last-child {
  font-size: 1.5rem;
  color: #1a1a1a;
}

/* ── Name entry ── */
.name-entry {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
}
.name-entry label {
  font-size: 0.88rem;
  color: #555;
  font-weight: 600;
}
.name-entry input {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid #1a1a1a;
  border-radius: 10px;
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
  outline: none;
  background: #fff;
  color: #1a1a1a;
  transition: border-color 0.15s;
}
.name-entry input:focus { border-color: var(--gold); }

/* ── Buttons ── */
.btn-main {
  width: 100%;
  padding: 12px 0;
  background: var(--btn-bg);
  border: 3px solid #1a1a1a;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 900;
  color: #1a1a1a;
  cursor: pointer;
  letter-spacing: 1px;
  box-shadow: 0 4px 0 #1a1a1a;
  transition: transform 0.1s, box-shadow 0.1s, background 0.1s;
}
.btn-main:hover { background: var(--btn-hover); }
.btn-main:active { transform: translateY(3px); box-shadow: 0 1px 0 #1a1a1a; }

.btn-sub {
  background: transparent;
  border: none;
  font-size: 0.9rem;
  font-weight: 700;
  color: #555;
  cursor: pointer;
  text-decoration: underline;
  padding: 4px 0;
}
.btn-sub:hover { color: #1a1a1a; }

/* ── Leaderboard ── */
.leaderboard-box { min-width: 320px; }

#lb-list {
  list-style: none;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
}
#lb-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0,0,0,0.06);
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 700;
  color: #1a1a1a;
}
#lb-list li .rank {
  font-size: 0.95rem;
  color: #888;
  min-width: 26px;
}
#lb-list li .lb-name {
  flex: 1;
  font-size: 1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#lb-list li .lb-score {
  font-size: 1.1rem;
  font-weight: 900;
}
#lb-list li:nth-child(1) { background: linear-gradient(90deg, #ffe06680, transparent); }
#lb-list li:nth-child(2) { background: linear-gradient(90deg, #e8e8e880, transparent); }
#lb-list li:nth-child(3) { background: linear-gradient(90deg, #cd7f3280, transparent); }
#lb-list li.current-entry { outline: 2px solid var(--gold); }

/* ── Paused screen ── */
#screen-pause { background: var(--overlay); }

/* ── Responsive scaling ── */
@media (max-height: 640px) {
  #game-wrapper { height: 100vh; width: calc(100vh * 0.75); }
}
@media (max-width: 480px) {
  #game-wrapper { width: 100vw; height: calc(100vw * 1.333); }
}
