:root {
  --bg: #0b0f14;
  --bg-elevated: #111722;
  --border: #1e2732;
  --text: #e6edf3;
  --text-muted: #8b98a5;
  --accent: #22d3ee;
  --accent-dim: #0891b2;
  --dirt: #4a3222;
  --dirt-dark: #2e1e14;
  --hit: #f59e0b;
  --danger: #f87171;
  --radius: 10px;
  --hud-block: 7rem;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Topbar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 480px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 0;
}

.topbar__title {
  font-size: 1.4rem;
  margin: 0;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.mute-toggle,
.bug-report-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 2.5rem;
  height: 2.5rem;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text);
  text-decoration: none;
  transition: filter 120ms ease-out;
}

.mute-toggle:hover,
.bug-report-link:hover {
  filter: brightness(1.3);
}

.mute-toggle:active,
.bug-report-link:active {
  filter: brightness(0.85);
}

.mute-toggle[aria-pressed="true"] {
  opacity: 0.5;
}

/* Tooltip: reuses the button's own aria-label as its text, so it can never
   drift out of sync with what's announced to screen readers. */
.mute-toggle::after,
.bug-report-link::after {
  content: attr(aria-label);
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 400;
  white-space: nowrap;
  padding: 0.3rem 0.6rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease-out;
  z-index: 10;
}

.mute-toggle:hover::after,
.mute-toggle:focus-visible::after,
.bug-report-link:hover::after,
.bug-report-link:focus-visible::after {
  opacity: 1;
}

/* Game page footer */

.site-footer {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 1.25rem 1.25rem;
  text-align: center;
  font-size: 0.85rem;
}

.site-footer a {
  color: var(--text-muted);
}

.site-footer a:hover {
  color: var(--accent);
}

/* About page: a short document in a centred column, as wide as a comfortable
   line. */

.about {
  max-width: 40rem;
  margin: 0 auto;
  padding: 2rem 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
}

.about__title {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: -0.02em;
}

.about__lead {
  margin: 0.5rem 0 0;
  color: var(--text-muted);
}

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

.about__heading {
  margin: 0;
  font-size: 1.05rem;
}

.about__section p {
  margin: 0;
  color: var(--text-muted);
}

.about__section strong {
  color: var(--text);
}

.about__section .muted {
  font-size: 0.9rem;
}

.about a {
  color: var(--accent);
}

.about__credit {
  font-size: 0.9rem;
}

/* The one section asking something of the reader, so it gets the only frame. */
.about__section--call {
  padding: 1rem 1.25rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
}

.about__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.about__back {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem 1rem;
  text-decoration: none;
}

.about__back:hover {
  filter: brightness(1.3);
}

.about__version {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Stage */

.stage {
  max-width: 480px;
  margin: 0 auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.hud {
  display: flex;
  gap: 1.5rem;
}

.hud__stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 4.5rem;
}

.hud__label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.hud__value {
  font-size: 1.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.hud__mode {
  margin: -0.5rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  min-height: 1.2em;
}

/* Playing: the page is locked to one screen (no scroll, no double-tap or pinch
   zoom) and focused on the round. Everything it doesn't need hides (the queue,
   the leaderboard, the title and the bug button; the mute toggle stays), and
   the HUD and board sit in the middle of the screen, the board being the
   largest square that fits under the HUD, so a phone never has to scroll
   mid-round. setPlaying in js/main.js runs the switch as a view transition, so
   the hidden parts fade and the named elements below glide to their new place. */

body.is-playing {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body.is-playing .topbar,
body.is-playing .stage {
  width: 100%;
  /* Not on the whole page: a dialog opened mid-round (bug report) still has
     to scroll and zoom its own text box. */
  touch-action: none;
  /* Rapid taps and long presses would otherwise select text and flash Chrome's
     blue tap highlight over the holes. */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* The topbar leaves the flow so the stage is the whole screen and its middle is
   the screen's middle. */
body.is-playing .topbar {
  position: absolute;
  inset: 0 0 auto;
  margin: 0 auto;
}

body.is-playing .stage {
  flex: 1;
  min-height: 0;
  justify-content: center;
  /* The board is sized from the stage (cqw/cqh), not from what's left over. */
  container-type: size;
}

body.is-playing .queue-panel,
body.is-playing .leaderboard,
body.is-playing .site-footer {
  display: none;
}

body.is-playing .topbar__title,
body.is-playing .bug-report-link {
  visibility: hidden;
}

/* The elements that glide rather than fade: each needs its own name. */
.mute-toggle {
  view-transition-name: mute;
}

.hud {
  view-transition-name: hud;
}

.hud__mode {
  view-transition-name: mode;
}

.board {
  view-transition-name: board;
}

::view-transition-group(*) {
  animation-duration: 700ms;
  animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation: none !important;
  }
}

/* Ready, steady, go: over the middle of the board before a round starts. The
   page is locked to one screen then, so fixed is the middle of what's seen. */

.countdown {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  font-size: clamp(2.5rem, 14vw, 4.5rem);
  font-weight: 800;
  color: var(--accent);
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.7);
  pointer-events: none;
}

/* hidden alone isn't enough: the display above would win. */
.countdown[hidden],
body:not(.is-playing) .countdown {
  display: none;
}

/* One word's whole second (COUNTDOWN_WORD_MS in js/main.js): it pops in, holds,
   then fades and grows over the last stretch so it's gone when the next one
   arrives. */
.countdown--pop {
  animation: countdown-word 1000ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes countdown-word {
  0% {
    opacity: 0;
    transform: scale(0.6);
  }
  20% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1);
    animation-timing-function: linear;
  }
  100% {
    opacity: 0;
    transform: scale(1.15);
  }
}

.countdown--go {
  color: var(--hit);
}

@media (prefers-reduced-motion: reduce) {
  .countdown--pop {
    animation: none;
  }
}

/* Board */

.board-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
  /* Not stretch (the board keeps its own square shape), and top-aligned so it
     doesn't jump when a turn starts. */
  align-items: flex-start;
}

/* --hud-block is the HUD and the mode label with their gaps, a little over. */
body.is-playing .board {
  width: min(100cqw, 100cqh - var(--hud-block));
}

.board {
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(0.5rem, 2vw, 1rem);
  background: var(--dirt);
  border-radius: calc(var(--radius) * 2);
  padding: clamp(0.75rem, 3vw, 1.5rem);
}

.hole {
  position: relative;
  /* A hole is a <button> (so it can be focused and pressed from the keyboard);
     this strips the browser's button look. */
  appearance: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  border-radius: 50%;
  background: var(--dirt-dark);
  box-shadow: inset 0 6px 12px rgba(0, 0, 0, 0.6);
  overflow: hidden;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.mole {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translate(-50%, 100%);
  font-size: clamp(2rem, 8vw, 3rem);
  transition: transform 160ms ease-out;
  user-select: none;
  -webkit-user-select: none;
}

.hole.is-up .mole {
  transform: translate(-50%, 0%);
}

.hole.is-hit .mole {
  animation: hit-squash 220ms ease-out;
}

@keyframes hit-squash {
  0% {
    transform: translate(-50%, 0%) scale(1);
  }
  40% {
    transform: translate(-50%, 10%) scale(1.15, 0.8);
  }
  100% {
    transform: translate(-50%, 100%) scale(1);
  }
}

.whack-burst {
  position: absolute;
  pointer-events: none;
  font-size: 1.75rem;
  transform: translate(-50%, -50%);
  animation: whack-pop 320ms ease-out forwards;
  z-index: 5;
}

@keyframes whack-pop {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.6) rotate(-10deg);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -140%) scale(1.3) rotate(10deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .mole,
  .hole.is-hit .mole,
  .whack-burst {
    animation: none !important;
    transition: none !important;
  }
}

.board--readonly {
  pointer-events: none;
  opacity: 0.75;
}

.board--readonly .hole {
  cursor: default;
}

/* Start button */

.start-btn {
  background: var(--accent);
  color: #06222a;
  border: none;
  border-radius: var(--radius);
  padding: 0.75rem 2rem;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: filter 120ms ease-out;
}

.start-btn:not(:disabled):hover {
  filter: brightness(1.1);
}

.start-btn:not(:disabled):active {
  filter: brightness(0.9);
}

.start-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

/* Queue panel */

.queue-panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}

.queue-panel__status {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.queue-panel__list {
  width: 100%;
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.queue-panel__empty {
  color: var(--text-muted);
}

/* Leaderboard */

.leaderboard {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

.leaderboard__title {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  color: var(--text-muted);
}

.leaderboard__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.leaderboard__list li {
  display: flex;
  justify-content: space-between;
  font-variant-numeric: tabular-nums;
}

.leaderboard__empty {
  color: var(--text-muted);
}

.leaderboard__rank {
  color: var(--text-muted);
  margin-right: 0.5rem;
}

/* Shared dialog chrome (game-over, bug-report) */

.dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--text);
  padding: 1.5rem;
  width: min(340px, 90vw);
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.dialog h2 {
  margin: 0;
  font-size: 1.15rem;
}

.dialog__form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.dialog__secondary {
  background: transparent;
  border: none;
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 120ms ease-out;
}

.dialog__secondary:hover {
  color: var(--text);
}

.dialog__primary {
  background: var(--accent);
  color: #06222a;
  border: none;
  border-radius: var(--radius);
  padding: 0.5rem 1.25rem;
  font-weight: 700;
  cursor: pointer;
  transition: filter 120ms ease-out;
}

.dialog__primary:not(:disabled):hover {
  filter: brightness(1.1);
}

.dialog__primary:not(:disabled):active {
  filter: brightness(0.9);
}

.dialog__primary:disabled {
  opacity: 0.6;
  cursor: default;
}

/* Game over dialog */

.game-over__score {
  margin: 0;
  color: var(--text-muted);
}

.game-over__label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.game-over__input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
  color: var(--text);
  font-size: 1rem;
  transition: border-color 120ms ease-out;
}

.game-over__input:focus {
  outline: none;
  border-color: var(--accent);
}

.game-over__input::placeholder {
  color: var(--text-muted);
}

/* Bug report dialog */

.bug-report__label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.bug-report__textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
  min-height: 6rem;
  transition: border-color 120ms ease-out;
}

.bug-report__textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.bug-report__textarea::placeholder {
  color: var(--text-muted);
}

.bug-report__status {
  margin: 0;
  color: var(--danger);
  font-size: 0.85rem;
}
