/* Fly! — a game about a housefly with poor life choices. */

/* `hidden` is only a UA stylesheet rule: any author `display` below would beat
   it. Pin it once, here, so toggling the attribute always works. */
[hidden] { display: none !important; }

* { box-sizing: border-box; }

:root {
  --ink: #f3ead8;
  --dim: #9a9382;
  --accent: #ffd34d;
  --danger: #ff6b5e;
  --panel: rgba(14, 16, 22, 0.86);
}

html, body { height: 100%; }

body {
  margin: 0;
  background: #0b0d12 radial-gradient(120% 90% at 50% 0%, #1b2030 0%, #0b0d12 70%);
  color: var(--ink);
  font: 400 16px/1.5 ui-rounded, "Avenir Next", "Segoe UI", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

/* The stage letterboxes inside the viewport, so viewport units would size the
   HUD against a box the stage does not occupy. `container-type: size` makes
   cqh/cqw resolve against the stage itself. */
#stage {
  position: relative;
  width: min(100%, calc((100dvh - 60px) * 16 / 9));
  aspect-ratio: 16 / 9;
  container-type: size;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.06);
  touch-action: none;
  cursor: crosshair;
}

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

/* ---------- HUD ---------- */

.hud {
  position: absolute;
  inset: 0 0 auto 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2.6cqh 3cqh;
  font-size: clamp(9px, 3.4cqh, 19px);
  letter-spacing: 0.09em;
  pointer-events: none;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.55);
}

.hud-left, .hud-right { display: flex; align-items: center; gap: 0.7em; }

.hud-label { color: var(--dim); font-size: 0.72em; }
.hud-value { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 3.2em; }
.hud-left .hud-value { color: var(--accent); }
.hud-right .hud-value { text-align: right; }

.icon-btn {
  pointer-events: auto;
  appearance: none;
  border: 0;
  background: rgba(255, 255, 255, 0.1);
  color: var(--ink);
  font: inherit;
  font-size: 0.8em;
  line-height: 1;
  padding: 0.45em 0.6em;
  border-radius: 0.5em;
  cursor: pointer;
  min-width: 2.2em;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.2); }
.icon-btn.off { color: var(--dim); opacity: 0.6; }

/* ---------- sugar rush meter ---------- */

.rush-bar {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 15cqh;
  width: 34cqw;
  height: 1.6cqh;
  min-height: 5px;
  border-radius: 99px;
  background: rgba(0, 0, 0, 0.45);
  box-shadow: 0 0 0 1px rgba(255, 211, 77, 0.35);
  overflow: hidden;
}
.rush-bar i {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ffe89a, var(--accent));
  transform-origin: left center;
}

/* ---------- overlays ---------- */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2.2cqh;
  padding: 4cqh;
  text-align: center;
  background: var(--panel);
  backdrop-filter: blur(3px);
  font-size: clamp(10px, 3.6cqh, 20px);
}

.overlay h1 {
  margin: 0;
  font-size: clamp(28px, 17cqh, 108px);
  line-height: 0.9;
  letter-spacing: 0.06em;
  font-weight: 800;
  color: var(--accent);
  text-shadow: 0 6px 0 rgba(0, 0, 0, 0.35);
}
.overlay h1 .excl { color: var(--danger); }

.overlay h2 {
  margin: 0;
  font-size: clamp(20px, 10cqh, 60px);
  line-height: 1;
  font-weight: 800;
  color: var(--ink);
}
#over h2 { color: var(--danger); }

.tag { margin: 0; color: var(--dim); font-size: 0.95em; }
.fine { margin: 0; color: var(--dim); font-size: 0.75em; }
.score-line { margin: 0; font-size: 1.15em; }
.score-line b { color: var(--accent); font-variant-numeric: tabular-nums; }
.best-line { margin: 0; color: var(--dim); font-size: 0.85em; }
.best-line.new { color: var(--accent); font-weight: 700; }

.keys {
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--dim);
  font-size: 0.8em;
  line-height: 1.9;
}
.keys b { color: var(--ink); font-weight: 700; }

.big-btn {
  appearance: none;
  border: 0;
  border-radius: 99px;
  padding: 0.7em 1.8em;
  font: inherit;
  font-size: 1em;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #22190a;
  background: linear-gradient(180deg, #ffe07a, var(--accent));
  box-shadow: 0 4px 0 #b8912a;
  cursor: pointer;
}
.big-btn:hover { filter: brightness(1.06); }
.big-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #b8912a; }

/* ---------- misc ---------- */

.rotate-note {
  margin: 0;
  text-align: center;
  font-size: 12px;
  color: var(--dim);
  display: none;
}

/* A short stage cannot hold the key list; the overlay keeps only what a player
   needs to press the button. Container query, because the decision is about the
   stage's box and not the viewport's. */
@container (max-height: 300px) {
  .overlay { gap: 1.6cqh; }
  .keys, .fine { display: none; }
}

.credits { font-size: 12px; color: #5d6270; }
.credits a { color: #7d8496; text-decoration: none; }
.credits a:hover { color: var(--ink); }

/* Media queries still read the viewport — that is the right box for a decision
   about the device rather than about the stage. */
@media (orientation: portrait) and (pointer: coarse) {
  .rotate-note { display: block; }
  .credits { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .rush-bar i { transition: none; }
}
