/* General Styles & Reset */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #0b0f19;
  font-family: 'Outfit', sans-serif;
  color: #f3f4f6;
  position: relative;
}

/* Common Overlay Backdrop */
.modal-backdrop, .game-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: rgba(11, 15, 25, 0.85);
  backdrop-filter: blur(10px);
  transition: opacity 0.3s ease;
}

.hidden {
  display: none !important;
}

/* Play Cover Styles */
#play-cover {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 200;
  background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
  overflow: hidden;
}

.cover-bg {
  position: absolute;
  width: 100%;
  height: 100%;
  background: linear-gradient(0deg, #10b981 0%, transparent 60%);
  opacity: 0.15;
  bottom: 0;
  left: 0;
  z-index: 1;
}

.cover-content {
  position: relative;
  z-index: 10;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  max-width: 90%;
}

.cover-logo {
  animation: floatLogo 4s ease-in-out infinite;
}

.logo-bird {
  font-size: 4rem;
  display: inline-block;
  animation: flapLogo 0.6s ease-in-out infinite alternate;
}

.cover-logo h1 {
  font-size: 3.5rem;
  font-weight: 900;
  letter-spacing: 2px;
  background: linear-gradient(to right, #fbbf24, #f59e0b, #d97706);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-top: 0.5rem;
  text-shadow: 0 4px 12px rgba(245, 158, 11, 0.2);
}

.cover-tagline {
  font-size: 1.1rem;
  color: #94a3b8;
  margin-top: 0.25rem;
}

.best-score-display {
  font-size: 1.25rem;
  font-weight: 700;
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.3);
  padding: 0.5rem 1.5rem;
  border-radius: 9999px;
  color: #fbbf24;
  margin-bottom: 0.5rem;
}

.main-buttons {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  max-width: 280px;
}

.play-cover-btn {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #ffffff;
  border: none;
  padding: 1rem 2rem;
  font-size: 1.25rem;
  font-weight: 700;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
  transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
  width: 100%;
}

.play-cover-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
}

.play-cover-btn:active {
  transform: translateY(1px);
}

.play-cover-btn.sec-play {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

.play-cover-btn.sec-play:hover {
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
}

.ui-btn-sm {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #e2e8f0;
  padding: 0.5rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, border 0.2s;
}

.ui-btn-sm:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
}

/* Background pipes anim on cover */
.cover-bird-anim {
  position: absolute;
  top: 40%;
  left: 20%;
  font-size: 2.5rem;
  z-index: 2;
  animation: floatBird 2.5s ease-in-out infinite alternate;
}

/* Game Container & Canvas */
#game-container {
  width: 100%;
  height: 100%;
  position: relative;
  background-color: #1e293b;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* HUD styles */
#hud-overlay {
  position: absolute;
  top: 1rem;
  left: 1rem;
  right: 1rem;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  z-index: 50;
}

#hud-left, #hud-right {
  display: flex;
  gap: 0.75rem;
}

.hud-badge {
  background: rgba(15, 23, 42, 0.75);
  border: 1.5px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
  padding: 0.5rem 1rem;
  border-radius: 12px;
  font-weight: 700;
  font-size: 1.1rem;
  color: #fff;
  display: flex;
  align-items: center;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

#hud-level {
  color: #fbbf24;
}

#hud-timer {
  color: #f87171;
}

#hud-best {
  color: #60a5fa;
}

/* Controls Layer overlay buttons */
#ui-layer {
  position: absolute;
  top: 4.5rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 60;
}

.ui-btn {
  background: rgba(15, 23, 42, 0.75);
  border: 1.5px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  backdrop-filter: blur(8px);
  transition: transform 0.2s, background-color 0.2s;
}

.ui-btn:hover {
  transform: scale(1.05);
  background-color: rgba(15, 23, 42, 0.9);
}

/* Start Screen Overlay */
#overlay-start {
  background-color: rgba(15, 23, 42, 0.5);
  pointer-events: none;
}

.tap-hint {
  font-size: 1.5rem;
  font-weight: 800;
  color: #fff;
  text-align: center;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  animation: pulse 1.5s infinite alternate;
}

.key-hints {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
  justify-content: center;
}

.key-hints span {
  background: rgba(0, 0, 0, 0.4);
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  font-size: 0.85rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #cbd5e1;
}

/* Game Over Card */
.gameover-card {
  background: rgba(30, 41, 59, 0.95);
  border: 2px solid rgba(239, 68, 68, 0.3);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  border-radius: 20px;
  padding: 1.75rem;
  width: 90%;
  max-width: 380px;
  max-height: 95vh;
  overflow-y: auto;
  text-align: center;
  animation: slideUp 0.3s ease-out;
}

.gameover-icon {
  font-size: 2.5rem;
  margin-bottom: 0.25rem;
  animation: shake 0.5s ease-in-out;
}

.gameover-title {
  font-size: 1.75rem;
  font-weight: 900;
  color: #ef4444;
  letter-spacing: 1px;
  margin-bottom: 1rem;
}

.gameover-stats {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  background: rgba(15, 23, 42, 0.5);
  border-radius: 12px;
  padding: 0.85rem 1.1rem;
  margin-bottom: 1.25rem;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.stat-row {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
  font-size: 0.95rem;
}

.stat-row span:first-child {
  color: #94a3b8;
}

.stat-row span:last-child {
  color: #fff;
}

.go-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

@media (max-height: 520px) {
  .gameover-card {
    padding: 1rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: center;
    max-width: 520px;
    gap: 1rem;
  }
  .gameover-icon {
    display: none;
  }
  .gameover-title {
    grid-column: 1 / span 2;
    margin-bottom: 0.25rem;
    font-size: 1.5rem;
  }
  .gameover-stats {
    margin-bottom: 0;
    padding: 0.6rem 0.9rem;
    gap: 0.4rem;
  }
  .go-buttons {
    flex-direction: row;
    gap: 0.5rem;
  }
  .go-buttons .play-cover-btn {
    padding: 0.65rem 1rem;
    font-size: 0.95rem;
  }
}

/* Level Up overlay banner */
#overlay-levelup {
  background-color: transparent;
  pointer-events: none;
}

.levelup-card {
  text-align: center;
  animation: levelUpAnim 1.8s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.levelup-icon {
  font-size: 4rem;
}

.levelup-text {
  font-size: 2.5rem;
  font-weight: 900;
  color: #fbbf24;
  text-shadow: 0 4px 10px rgba(245, 158, 11, 0.5);
}

.levelup-num {
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
  margin-top: 0.25rem;
}

/* Mobile Virtual Controller */
#virtual-controller {
  position: absolute;
  bottom: 15px;
  left: 15px;
  width: auto;
  display: flex;
  justify-content: flex-start;
  z-index: 80;
  pointer-events: none; /* Let clicks pass through, but button itself enables pointer-events */
}

.flap-btn {
  pointer-events: auto;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: radial-gradient(circle at center, rgba(16, 185, 129, 0.85) 0%, rgba(5, 150, 105, 0.85) 100%);
  border: 3px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), inset 0 4px 10px rgba(255, 255, 255, 0.2);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s, border-color 0.2s;
  backdrop-filter: blur(5px);
}

.flap-btn:hover {
  border-color: rgba(255, 255, 255, 0.6);
}

.flap-btn:active {
  transform: scale(0.92);
  background: radial-gradient(circle at center, rgba(5, 150, 105, 0.9) 0%, rgba(4, 120, 87, 0.9) 100%);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.flap-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.flap-label {
  display: none;
}

/* Modals */
.settings-card {
  background: #1e293b;
  border: 1.5px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  width: 90%;
  max-width: 440px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
  animation: slideUp 0.3s ease-out;
  overflow: hidden;
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  background: rgba(15, 23, 42, 0.4);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.settings-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 1.2rem;
  cursor: pointer;
  transition: color 0.2s;
}

.modal-close-btn:hover {
  color: #fff;
}

.settings-body {
  padding: 1.5rem;
}

.save-status-box {
  background: rgba(15, 23, 42, 0.4);
  border-radius: 12px;
  padding: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.05);
  margin-bottom: 1.25rem;
}

.save-status-box h3 {
  font-size: 1rem;
  color: #94a3b8;
  margin-bottom: 0.5rem;
  font-weight: 600;
}

.save-status-box p {
  font-size: 0.95rem;
  color: #e2e8f0;
  margin-bottom: 0.75rem;
}

.pri-btn, .sec-btn {
  width: 100%;
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.95rem;
  transition: background-color 0.2s, transform 0.1s;
  border: none;
}

.pri-btn {
  background: #10b981;
  color: #fff;
}

.pri-btn:hover {
  background: #059669;
}

.pri-btn:active {
  transform: translateY(1px);
}

.sec-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #e2e8f0;
}

.sec-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.modal-divider {
  border: 0;
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  margin: 1.25rem 0;
}

.save-file-actions h3 {
  font-size: 1rem;
  color: #94a3b8;
  margin-bottom: 0.75rem;
  font-weight: 600;
}

.action-buttons-row {
  display: flex;
  gap: 0.75rem;
}

.file-label {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.hidden-input {
  display: none !important;
}

/* Ad Overlay Modal */
#ad-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  background-color: rgba(11, 15, 25, 0.95);
}

.ad-modal {
  width: 90%;
  max-width: 640px;
  height: 80vh;
  max-height: 480px;
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

@media (max-height: 520px) {
  .ad-modal {
    height: 95vh;
    max-height: 95vh;
    border-radius: 8px;
  }
  .ad-header {
    padding: 0.4rem 1rem !important;
  }
}

.ad-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
  background: rgba(15, 23, 42, 0.5);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.ad-badge {
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: #fbbf24;
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

.ad-close-btn {
  background: #e2e8f0;
  color: #0f172a;
  border: none;
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s;
}

.ad-close-btn:disabled {
  background: rgba(255, 255, 255, 0.1);
  color: #64748b;
  cursor: not-allowed;
}

.ad-body {
  flex-grow: 1;
  background: #000;
}

.ad-body iframe {
  width: 100%;
  height: 100%;
  border: none;
}

/* Animations */
@keyframes floatLogo {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

@keyframes flapLogo {
  0% { transform: rotate(-5deg) scaleY(1); }
  100% { transform: rotate(5deg) scaleY(0.9); }
}

@keyframes floatBird {
  0% { transform: translateY(-15px) rotate(-10deg); }
  100% { transform: translateY(15px) rotate(10deg); }
}

@keyframes pulse {
  0% { opacity: 0.6; transform: scale(0.98); }
  100% { opacity: 1; transform: scale(1.02); }
}

@keyframes slideUp {
  0% { transform: translateY(30px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}

@keyframes levelUpAnim {
  0% { transform: scale(0) rotate(-15deg); opacity: 0; }
  50% { transform: scale(1.2) rotate(5deg); opacity: 1; }
  75% { transform: scale(0.95) rotate(-2deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 0; visibility: hidden; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px) rotate(-3deg); }
  50% { transform: translateX(6px) rotate(2deg); }
  75% { transform: translateX(-4px) rotate(-1deg); }
}

/* Media Queries for Orientation and Sizing */
@media (max-width: 768px) {
  .logo-bird { font-size: 2.8rem; }
  .cover-logo h1 { font-size: 2.2rem; }
  .cover-tagline { font-size: 0.9rem; }
  .play-cover-btn { padding: 0.8rem 1.4rem; font-size: 1.05rem; }
  .settings-card { width: 95%; margin: 10px; }
  
  /* Scale HUD badges down slightly on smaller mobile viewports */
  .hud-badge {
    padding: 0.4rem 0.75rem;
    font-size: 0.9rem;
    border-radius: 8px;
  }
}

/* Ensure the virtual controller displays on all mobile-sized devices, or devices using touch (coarse pointer) */
@media (max-width: 1024px), (pointer: coarse) {
  #virtual-controller {
    display: flex !important;
  }
}

@media (min-width: 1025px) and (pointer: fine) {
  #virtual-controller {
    display: none !important;
  }
}
