:root {
  color: #31575d;
  background: #e9f8f5;
  font-family: ui-rounded, "Nunito", "Avenir Next", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 12% 7%, #fffdf3 0 5%, transparent 21%),
    radial-gradient(circle at 88% 88%, #bce8e0 0 7%, transparent 26%),
    #e9f8f5;
}

.game-shell {
  width: min(100%, 680px);
  height: 100svh;
  padding: clamp(22px, 5vw, 42px) clamp(16px, 4vw, 32px) 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.hud {
  position: relative;
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-actions, .game-controls { display: flex; align-items: center; gap: 9px; }

.selected-option {
  position: absolute;
  left: 50%;
  margin: 0;
  transform: translateX(-50%);
  color: #31575d;
  font-size: .86rem;
  font-weight: 900;
  white-space: nowrap;
}

.menu-wrap { position: relative; }

.menu-button {
  display: grid;
  width: 40px;
  height: 40px;
  padding: 10px;
  place-content: center;
  gap: 4px;
  border-radius: 50%;
  color: #568285;
  background: #fffdf9;
  box-shadow: 0 5px 0 #d4e6e1;
}

.menu-button span {
  display: block;
  width: 16px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
}

.game-menu {
  position: absolute;
  z-index: 4;
  top: calc(100% + 10px);
  left: 0;
  min-width: 150px;
  padding: 7px;
  border-radius: 16px;
  background: #fffdf9;
  box-shadow: 0 12px 28px rgba(34, 83, 85, .2);
}

.game-menu[hidden] { display: none; }

.game-menu button {
  width: 100%;
  padding: 10px 12px;
  text-align: left;
  color: #31575d;
  background: transparent;
  box-shadow: none;
}

.game-menu button:hover, .game-menu button:focus-visible { background: #e9f8f5; }

.run-counters { display: flex; align-items: center; gap: 12px; }

.metric-stack { display: grid; justify-items: end; }

.level-progress {
  margin: -2px 0 0;
  color: #ef8c78;
  font-size: clamp(1.35rem, 3.8vw, 2rem);
  font-weight: 900;
  line-height: 1;
}

.level-progress[hidden] { display: none; }

.run-counters.is-level .timer { font-size: clamp(1.5rem, 4.2vw, 2.2rem); }

.header-high-score {
  margin: 0;
  color: #6b8e8d;
  font-size: .72rem;
  font-weight: 800;
  white-space: nowrap;
}

.hud-label {
  margin: 0 0 2px;
  color: #70999a;
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .16em;
}

.timer {
  margin: 0;
  color: #285e65;
  font-size: clamp(2.4rem, 8vw, 4.1rem);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -.07em;
}

.restart-button {
  color: #568285;
  background: #fffdf9;
  box-shadow: 0 5px 0 #d4e6e1;
}

.game-field {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  border: 8px solid #fffdf9;
  border-bottom: 0;
  border-radius: 34px 34px 0 0;
  background: linear-gradient(160deg, #bfe8e5, #e6faf4 66%, #c6ede5);
  box-shadow: 0 20px 45px rgba(73, 137, 135, .19), inset 0 0 0 1px rgba(66, 138, 132, .11);
}

canvas { width: 100%; height: 100%; display: block; touch-action: none; }

.game-over {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(39, 86, 91, .26);
  backdrop-filter: blur(4px);
}

.game-over[hidden] { display: none; }

.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti[hidden] { display: none; }

.confetti-piece {
  position: absolute;
  top: -18px;
  width: 9px;
  height: 16px;
  border-radius: 3px;
  background: var(--color);
  animation: confetti-fall 1.7s var(--delay) ease-in infinite;
}

@keyframes confetti-fall {
  from { transform: translateY(-18px) rotate(0deg); }
  to { transform: translate(var(--drift), 590px) rotate(540deg); }
}

.countdown {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: grid;
  width: 92px;
  height: 92px;
  place-items: center;
  border: 5px solid #fffdf9;
  border-radius: 50%;
  color: #285e65;
  background: rgba(255, 248, 223, .92);
  box-shadow: 0 12px 28px rgba(48, 103, 103, .19);
  font-size: 3rem;
  font-weight: 900;
}

.countdown[hidden] { display: none; }

.game-over-card {
  width: min(100%, 300px);
  padding: 28px 24px;
  border-radius: 26px;
  text-align: center;
  background: #fffdf9;
  box-shadow: 0 18px 38px rgba(34, 83, 85, .24);
}

.game-over-metres {
  margin: 4px 0 2px;
  color: #e77c6e;
  font-size: 3.3rem;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -.08em;
}

.high-score { margin: 0 0 22px; color: #6b8e8d; font-size: .82rem; font-weight: 800; }

button {
  border: 0;
  border-radius: 100px;
  padding: 11px 20px;
  color: #fff;
  background: #ef8c78;
  box-shadow: 0 5px 0 #cf6f63;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

button:focus-visible { outline: 3px solid #285e65; outline-offset: 3px; }

button:disabled {
  color: #9aafae;
  background: #e4edeb;
  box-shadow: 0 5px 0 #cddbd7;
  cursor: not-allowed;
}

.next-level-button { display: block; width: 100%; margin-top: 16px; }
.next-level-button[hidden] { display: none; }

@media (max-width: 480px) {
  .game-shell { padding-inline: 12px; }
  .game-field { border-radius: 28px 28px 0 0; border-width: 6px; }
}
