:root {
  color-scheme: light dark;
  /* Vertical room to leave for the hint line under the game. */
  --chrome: 56px;
}

html, body {
  margin: 0;
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 100vh;
  min-height: 100dvh; /* dvh accounts for mobile browser chrome */
  background: #111;
  font-family: system-ui, sans-serif;
  color: #ccc;
  /* Stop mobile browsers hijacking taps with scroll/zoom gestures. */
  touch-action: manipulation;
  overscroll-behavior: none; /* no pull-to-refresh from rapid tapping */
  user-select: none; /* rapid taps shouldn't select text */
  -webkit-tap-highlight-color: transparent; /* no blue flash on every flap */
}

#stage {
  /* Internal canvas resolution is a fixed 288x512, scaled up with CSS. Fill the
     viewport rather than pinning to 288px, which left the game as a small box
     adrift on a phone. Bounded by height so it can never overflow, and capped
     at 576px (a crisp 2x) so it doesn't get silly on a desktop monitor. */
  position: relative; /* anchors the gear + settings overlay */
  aspect-ratio: 288 / 512;
  width: min(100vw, 576px, calc((100vh - var(--chrome)) * 288 / 512));
  width: min(100vw, 576px, calc((100dvh - var(--chrome)) * 288 / 512));
}

@media (max-width: 520px) {
  :root {
    --chrome: 8px;
  }

  /* The title screen already says TAP TO FLAP — the hint is just stealing
     height from the game on a phone. */
  #hint {
    display: none;
  }
}

/* Our overlays set display, which would otherwise beat the UA's [hidden]. */
[hidden] {
  display: none !important;
}

/* ---- settings + donate ---- */
#gear,
#board {
  position: absolute;
  top: 6px;
  /* 44px is the minimum comfortable touch target (Apple HIG / Material). */
  width: 44px;
  height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 22px;
  line-height: 1;
  color: #fff;
  background: rgba(0, 0, 0, 0.45);
  border: 2px solid #fff;
  border-radius: 4px;
  cursor: pointer;
}

#gear {
  right: 6px;
}

#board {
  left: 6px;
}

/* Bottom stack: the labels are too wide to share the top row with the gear. */
#bottombar {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#coffee,
#share {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  /* 11px keeps the whole control >=44px tall (min touch target) */
  padding: 11px 14px;
  background: rgba(0, 0, 0, 0.55);
  border: 2px solid #fff;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  /* Fixed width so the button doesn't jump when the label swaps to COPIED! */
  min-width: 212px;
  box-sizing: border-box;
}

#coffee img,
#share img {
  display: block;
  height: 18px;
  image-rendering: pixelated; /* it's pixel art — never smooth it */
}

#coffee span,
#share span {
  font-size: 19px;
  line-height: 1;
}

/* Share is the primary action on game-over — give it the accent. */
#share {
  background: rgba(245, 152, 42, 0.9);
  border-color: #000;
}

#share:hover {
  background: #ffc23d;
}

#gear:hover,
#board:hover,
#coffee:hover {
  background: rgba(0, 0, 0, 0.8);
}

/* Coffee button scaled 1.5x — a bigger donation ask on the main screen. Applies
   to #coffee only (the share button keeps its size). Must sit AFTER the shared
   #coffee,#share rules to win on equal specificity. */
#coffee {
  padding: 16px 21px;               /* 11×14 → ~1.5× */
}
#coffee img {
  height: 27px;                     /* 18 → 1.5× (bmc.png is 184×18, so ~276px wide) */
}
#coffee span {
  font-size: 28px;                  /* 19 → 1.5× */
}
/* The label is intrinsically wide; at full 1.5x it's ~354px, which overflows
   phones under ~360px. Scale it back a touch there so nothing clips. */
@media (max-width: 360px) {
  #coffee { padding: 12px 14px; }
  #coffee img { height: 22px; }
  #coffee span { font-size: 22px; }
}

#settings,
#leaderboard,
#nameprompt {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  background: rgba(0, 0, 0, 0.6);
}

#panel,
.panel {
  width: 100%;
  max-width: 220px;
  padding: 14px;
  /* Same palette as the game art: sea, gold, orange. */
  background: #123850;
  border: 3px solid #fff;
  box-shadow: 0 0 0 3px #000;
  color: #fff;
  font: 700 12px/1.4 system-ui, sans-serif;
  letter-spacing: 1px;
  text-transform: uppercase;
}

#panel h2,
.panel h2 {
  margin: 0 0 12px;
  font-size: 14px;
  text-align: center;
  color: #ffc23d;
}

#panel .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

/* ---- leaderboard ---- */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
}

.tab {
  flex: 1;
  padding: 6px 2px;
  font: inherit;
  font-size: 10px;
  color: #fff;
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid rgba(255, 255, 255, 0.35);
  cursor: pointer;
}

.tab.on {
  color: #000;
  background: #f5982a;
  border-color: #000;
}

#boardlist {
  margin: 0 0 8px;
  padding: 0;
  list-style: none;
  /* 10 rows always fit, but never let a long board push the panel off-screen. */
  max-height: 190px;
  overflow-y: auto;
}

#boardlist li {
  display: flex;
  gap: 6px;
  align-items: baseline;
  padding: 3px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 11px;
}

#boardlist .rank {
  width: 18px;
  color: #ffc23d;
}

#boardlist .who {
  flex: 1;
  /* Free-text names: never let one blow out the panel. */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-transform: none;
}

#boardlist .pts {
  color: #ffc23d;
}

#boardlist li.me {
  background: rgba(245, 152, 42, 0.22);
}

#boardmsg,
.panel .sub {
  margin: 0 0 10px;
  font-size: 10px;
  text-align: center;
  opacity: 0.75;
  text-transform: none;
}

#nameinput {
  width: 100%;
  padding: 8px;
  margin-bottom: 10px;
  font: 700 13px system-ui, sans-serif;
  color: #000;
  background: #fff;
  border: 2px solid #000;
  box-sizing: border-box;
}

.row2 {
  display: flex;
  gap: 6px;
}

.row2 button {
  flex: 1;
}

.panel .ghost {
  color: #fff;
  background: rgba(0, 0, 0, 0.35);
  border-color: #fff;
}

#vol {
  width: 100%;
  margin: 0 0 14px;
  accent-color: #f5982a;
}

#snd,
#voice,
#music,
#sfx,
#checkpoint {
  width: 18px;
  height: 18px;
  accent-color: #f5982a;
}

/* Category toggles read as sub-options of the master Sound switch. */
#panel .row.sub {
  padding-left: 12px;
  margin-bottom: 4px;
}

#panel .row.sub label {
  font-size: 10px;
  color: #cfe0ea;
}

#close,
#boardclose,
#namesave,
#nameskip {
  width: 100%;
  margin-top: 8px;
  padding: 8px;
  font: inherit;
  color: #000;
  background: #f5982a;
  border: 2px solid #000;
  cursor: pointer;
}

#close:hover,
#boardclose:hover,
#namesave:hover,
#nameskip:hover {
  background: #ffc23d;
}

#game {
  width: 100%;
  height: 100%;
  display: block;
  /* Keep the pixel art crisp when scaled up. */
  image-rendering: pixelated;
  background: #4ec0ca; /* classic Flappy Bird sky, shown before art loads */
  cursor: pointer;
}

#hint {
  margin: 0;
  font-size: 14px;
  opacity: 0.6;
}
