body {
  margin: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  color: #fff;
  background: radial-gradient(circle at top, #4b4960, #222128 72%);
  font-family: system-ui, sans-serif;
}

.flappy-game {
  width: min(96vw, 760px);
  margin: 6px auto;
}

.flappy-heading {
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.flappy-heading h1 {
  margin: 0;
  padding: 6px 20px;
  border-radius: 11px;
  background: #a000a0;
  font-size: clamp(1.55rem, 6vw, 2.4rem);
}

.desktop-modes,
.mobile-modes {
  display: flex;
  gap: 7px;
}

.desktop-modes {
  display: none;
}

.desktop-modes button,
.mobile-modes button {
  min-height: 46px;
  padding: 7px 12px;
  border: 3px solid #d7eff2;
  border-radius: 12px;
  color: #fff;
  background: #38445f;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
}

.desktop-modes button[aria-pressed="true"],
.mobile-modes button[aria-pressed="true"] {
  color: #102e33;
  background: #58e5ee;
  border-color: #fff;
}

#game-container {
  position: relative;
  width: min(96vw, 680px);
  height: min(760px, calc(100svh - var(--gamez-control-height) - 128px - env(safe-area-inset-bottom)));
  min-height: 0;
  margin: 0 auto;
  overflow: hidden;
  border: 4px solid #a000a0;
  border-radius: 18px;
  background:
    radial-gradient(circle at 20% 18%, rgba(255,255,255,.85) 0 18px, transparent 19px),
    radial-gradient(circle at 28% 18%, rgba(255,255,255,.72) 0 27px, transparent 28px),
    linear-gradient(#6dd8e4 0 74%, #82cf6a 74% 78%, #b2864b 78%);
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.4);
  outline: none;
  touch-action: none;
  user-select: none;
}

#game-container:focus-visible {
  border-color: #fff;
  box-shadow: 0 0 0 4px #29d8e4, 0 16px 50px rgba(0, 0, 0, 0.4);
}

#bird {
  --bird-angle: 0deg;
  position: absolute;
  z-index: 5;
  width: 42px;
  height: 42px;
  left: 52px;
  top: 45%;
  border: 2px solid rgba(255,255,255,.85);
  border-radius: 50%;
  background: url("./img/flappy-bird-png.png") center / cover;
  transform: rotate(var(--bird-angle));
  transform-origin: center;
  will-change: top, transform;
}

#bird.is-crashing {
  filter: saturate(1.5) drop-shadow(0 0 9px #ff3737);
}

#bird.is-nested {
  z-index: 7;
  filter: drop-shadow(0 2px 4px rgba(56, 29, 5, .45));
  transition: left 180ms ease-out, top 180ms ease-out;
}

.finish-nest {
  position: absolute;
  z-index: 6;
  width: 96px;
  height: 96px;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 4px 4px rgba(73, 30, 4, .42));
  will-change: left;
}

.finish-nest.is-home {
  animation: nest-celebrate 520ms ease-out both;
}

@keyframes nest-celebrate {
  45% { transform: scale(1.13) rotate(-3deg); }
  72% { transform: scale(.97) rotate(2deg); }
  100% { transform: scale(1) rotate(0); }
}

.pipe {
  position: absolute;
  z-index: 2;
  width: 62px;
  border: 4px solid #145c29;
  background: linear-gradient(90deg, #18692d, #66df6e 42%, #21913b 68%, #125424);
  box-shadow: inset 7px 0 0 rgba(255,255,255,.13);
}

.top-pipe {
  top: 0;
  border-radius: 0 0 10px 10px;
}

.bottom-pipe {
  bottom: 0;
  border-radius: 10px 10px 0 0;
}

.score {
  position: absolute;
  z-index: 8;
  top: 10px;
  right: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  color: #fff;
  background: rgba(20, 28, 56, 0.76);
  font-size: 1.35rem;
  font-weight: 1000;
}

.flap-button {
  position: absolute;
  z-index: 12;
  left: 50%;
  bottom: 18px;
  width: 86px;
  height: 86px;
  display: none;
  place-items: center;
  border: 4px solid #fff;
  border-radius: 50%;
  color: #102e33;
  background: #58e5ee;
  box-shadow: 0 8px 0 #268b95, 0 14px 28px rgba(0, 0, 0, .3);
  font-size: 3rem;
  font-weight: 1000;
  line-height: 1;
  transform: translateX(-50%);
  touch-action: manipulation;
}

.flap-button:active {
  box-shadow: 0 3px 0 #268b95, 0 8px 18px rgba(0, 0, 0, .3);
  transform: translate(-50%, 5px);
}

.game-message {
  position: absolute;
  z-index: 10;
  inset: 50% auto auto 50%;
  width: min(84%, 320px);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border: 3px solid #fff;
  border-radius: 16px;
  color: #fff;
  background: rgba(25, 20, 48, 0.9);
  text-align: center;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.game-message strong { font-size: 1.5rem; }
.game-message.is-hidden { display: none; }

.control-help {
  width: min(92vw, 560px);
  margin: 8px auto 0;
  display: flex;
  justify-content: center;
  gap: 8px 18px;
  flex-wrap: wrap;
  color: #fff;
  text-align: center;
  font-size: 0.9rem;
}

.danger-keys { color: #ffb7be; }

@media (pointer: coarse), (max-width: 640px) {
  .control-help > span:first-child { display: none; }
  .mobile-modes button {
    padding-inline: 8px;
    font-size: .82rem;
  }
  .flap-button.is-visible { display: grid; }
  .danger-keys { display: none; }
}

@media (min-width: 641px) and (pointer: fine) {
  .mobile-modes { display: none; }
  .desktop-modes { display: flex; }
  #game-container.is-mouse-mode { cursor: ns-resize; }
}

@media (max-height: 680px) {
  #game-container { height: min(61svh, 520px); }
  .control-help { margin-top: 4px; }
}
