/* Flappy Bird — Dark theme matching portal */

:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: #16213e;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --text-primary: #eee;
  --text-secondary: #a0a0b8;
  --border: #2a2a4a;
  --success: #4ecca3;
  --warning: #ffc107;
  --gold: #ffd700;
  --bird-yellow: #f8d247;
  --bird-body: #ffd95a;
  --pipe-green: #4caf50;
  --pipe-green-dark: #2e7d32;
  --pipe-cap: #66bb6a;
  --sky-top: #0a0e27;
  --sky-mid: #1a1f4e;
  --sky-bot: #2a3373;
  --ground: #5d4037;
  --ground-grass: #4caf50;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  padding: 0;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 12px 40px;
  gap: 14px;
  min-height: calc(100vh - 120px);
}

/* ---------- HUD ---------- */
.hud {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 480px;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

.hud-stat {
  flex: 1;
  text-align: center;
  min-width: 0;
}

.hud-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 1px;
}

.hud-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.hud-gold { color: var(--gold); }
.medal-name { font-size: 16px; }

.btn-icon {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 18px;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, background 0.15s;
}

.btn-icon:hover { background: var(--border); transform: scale(1.05); }
.btn-icon:active { transform: scale(0.95); }

/* ---------- Canvas ---------- */
.canvas-wrap {
  position: relative;
  width: 100%;
  max-width: 400px;
  aspect-ratio: 400 / 600;
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 60%, var(--sky-bot) 90%, var(--ground) 100%);
  border: 2px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
  touch-action: none;
}

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

/* ---------- Overlay system ---------- */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 14, 39, 0.78);
  backdrop-filter: blur(2px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  z-index: 5;
  animation: fadeIn 0.3s ease-out;
}

.overlay[hidden] { display: none; }

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.overlay-title {
  font-size: 36px;
  font-weight: 900;
  letter-spacing: 2px;
  color: var(--gold);
  text-shadow:
    0 0 12px rgba(255, 215, 0, 0.6),
    0 0 24px rgba(255, 215, 0, 0.3),
    0 3px 0 rgba(0, 0, 0, 0.5);
  margin-bottom: 8px;
}

.overlay-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 18px;
}

.ready-sub {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 10px;
}

/* ---------- Menu ---------- */
.bird-demo {
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 12px 0 18px;
}

.bird {
  width: 38px;
  height: 28px;
  background: var(--bird-body);
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  position: relative;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
  animation: birdIdle 0.9s ease-in-out infinite;
}

.bird::before {
  content: "";
  position: absolute;
  top: 8px;
  right: 4px;
  width: 8px;
  height: 8px;
  background: white;
  border-radius: 50%;
  border: 2px solid #333;
}

.bird::after {
  content: "";
  position: absolute;
  top: 13px;
  right: -1px;
  width: 10px;
  height: 6px;
  background: var(--accent);
  border-radius: 0 50% 50% 0;
  transform: rotate(-5deg);
}

@keyframes birdIdle {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-8px) rotate(3deg); }
}

.best-pill {
  margin-top: 14px;
  padding: 6px 14px;
  background: rgba(255, 215, 0, 0.12);
  border: 1px solid var(--gold);
  color: var(--gold);
  font-weight: 700;
  border-radius: 999px;
  font-size: 14px;
}

.best-pill[hidden] { display: none; }

/* ---------- Buttons ---------- */
.btn {
  padding: 12px 24px;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
  font-family: inherit;
}

.btn-primary {
  background: linear-gradient(180deg, var(--accent-hover), var(--accent));
  color: white;
  box-shadow: 0 4px 0 #b0344a, 0 6px 14px rgba(233, 69, 96, 0.35);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 0 #b0344a, 0 8px 18px rgba(233, 69, 96, 0.45);
}

.btn-primary:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #b0344a;
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover { background: var(--border); }

/* ---------- Get Ready ---------- */
.ready-pulse {
  font-size: 32px;
  font-weight: 900;
  letter-spacing: 2px;
  color: var(--gold);
  text-shadow: 0 0 16px rgba(255, 215, 0, 0.6);
  animation: readyPulse 1s ease-in-out infinite;
}

@keyframes readyPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.08); opacity: 0.7; }
}

/* ---------- Pause ---------- */
.overlay-pause {
  background: rgba(10, 14, 39, 0.85);
}

/* ---------- Game Over ---------- */
.over-title {
  color: var(--accent);
  text-shadow:
    0 0 12px rgba(233, 69, 96, 0.6),
    0 3px 0 rgba(0, 0, 0, 0.5);
}

.score-board {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin: 14px 0 18px;
  padding: 18px 28px;
  background: rgba(15, 15, 26, 0.7);
  border: 1px solid var(--border);
  border-radius: 14px;
  min-width: 220px;
}

.score-row {
  display: flex;
  justify-content: space-between;
  width: 100%;
  gap: 24px;
}

.score-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 1px;
  align-self: center;
}

.score-big {
  font-size: 32px;
  font-weight: 900;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.score-best { color: var(--gold); }

.medal-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}

.medal-circle {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 900;
  color: white;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  border: 3px solid rgba(255, 255, 255, 0.4);
}

.medal-circle.no-medal {
  background: var(--bg-secondary);
  border-color: var(--border);
  color: var(--text-secondary);
}

.medal-circle.bronze {
  background: linear-gradient(135deg, #cd7f32, #8b4513);
}
.medal-circle.silver {
  background: linear-gradient(135deg, #e0e0e0, #909090);
}
.medal-circle.gold {
  background: linear-gradient(135deg, #ffd700, #ff8c00);
}
.medal-circle.platinum {
  background: linear-gradient(135deg, #b9f2ff, #6a5acd);
  border-color: white;
}

.medal-tier {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 1px;
}

.new-pb {
  font-size: 14px;
  font-weight: 900;
  color: var(--gold);
  letter-spacing: 1px;
  text-shadow: 0 0 10px rgba(255, 215, 0, 0.6);
  animation: pbPop 1.2s ease-in-out infinite;
}

@keyframes pbPop {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.tap-restart { margin-top: 8px; font-style: italic; }

/* ---------- Touch hint ---------- */
.touch-hint {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: rgba(255, 255, 255, 0.55);
  pointer-events: none;
  z-index: 2;
  letter-spacing: 1px;
  animation: hintPulse 2s ease-in-out infinite;
}

@keyframes hintPulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

/* ---------- Controls hint ---------- */
.controls-hint {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  justify-content: center;
  font-size: 12px;
  color: var(--text-secondary);
  max-width: 480px;
  width: 100%;
  padding: 0 8px;
}

kbd {
  display: inline-block;
  padding: 2px 6px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: ui-monospace, "SF Mono", monospace;
  font-size: 11px;
  color: var(--text-primary);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
}

/* ---------- Stats modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 14, 39, 0.85);
  backdrop-filter: blur(3px);
  animation: fadeIn 0.25s ease-out;
}

.modal-card {
  position: relative;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
  animation: modalSlide 0.3s ease-out;
}

@keyframes modalSlide {
  from { transform: translateY(20px) scale(0.97); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 22px;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.modal-close:hover {
  background: var(--border);
  color: var(--text-primary);
}

.modal-title {
  margin: 0 0 18px;
  color: var(--text-primary);
  font-size: 22px;
  text-align: center;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}

.stat-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 10px;
  text-align: center;
}

.stat-card.span2 { grid-column: span 2; }

.stat-label {
  font-size: 11px;
  color: var(--text-secondary);
  letter-spacing: 1px;
  margin-bottom: 4px;
  font-weight: 700;
}

.stat-value {
  font-size: 24px;
  font-weight: 900;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.stat-value.gold { color: var(--gold); }

.medals-row {
  display: flex;
  justify-content: space-around;
  gap: 12px;
  padding: 8px 0;
}

.medal-cell {
  font-size: 36px;
  filter: grayscale(1) brightness(0.5);
  opacity: 0.45;
  transition: filter 0.3s, opacity 0.3s, transform 0.2s;
}

.medal-cell.unlocked {
  filter: none;
  opacity: 1;
  animation: medalGlow 2s ease-in-out infinite;
}

.medal-cell:active { transform: scale(1.15); }

@keyframes medalGlow {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.modal-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

/* ---------- Mobile responsive ---------- */
@media (max-width: 480px) {
  .game-container { padding: 12px 8px 28px; }
  .hud { padding: 8px 10px; gap: 8px; }
  .hud-value { font-size: 18px; }
  .medal-name { font-size: 14px; }
  .overlay-title { font-size: 28px; }
  .score-big { font-size: 26px; }
  .controls-hint { font-size: 11px; gap: 8px 12px; }
  .modal-card { padding: 18px; }
}

@media (max-width: 360px) {
  .hud { flex-wrap: wrap; }
  .hud-stat { min-width: 70px; }
  .score-board { min-width: 180px; padding: 14px 20px; }
}

/* ---------- Accessibility ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
