/* ==========================================================
   Fun! — the falling-notes game (see js/game.js)
   ========================================================== */

.game {
  --lane-gap: .6rem;
  max-width: 34rem;
  margin: 0 auto;
}

.game-intro {
  margin: 0 auto 1.25rem;
  text-align: center;
}

/* ---------- scoreboard ---------- */
.game-hud {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: .5rem 1.1rem;
  margin-bottom: .75rem;
  font-family: var(--font-pencil);
  font-size: 1.6rem;
  line-height: 1;
}
.game-hud b {
  font-family: var(--font-body);
  font-size: 1.15rem;
}
.game-lives {
  letter-spacing: .1em;
  color: var(--ink-pink);
}
.game-lives .spent { opacity: .25; }

/* ---------- board ---------- */
.game-board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--lane-gap);
  height: min(62vh, 30rem);
  padding: var(--lane-gap);
  border: 3px solid var(--ink-pink-dark);
  border-radius: 14px;
  background: var(--sheet);
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
}

.lane {
  position: relative;
  display: flex;
  flex-direction: column;
  border-radius: 10px;
  background: var(--tint);
  cursor: pointer;
}
/* one riso colour per character */
.lane:nth-child(1) { --tint: var(--tint-yellow); --ink: var(--ink-blue); }
.lane:nth-child(2) { --tint: var(--tint-pink); --ink: var(--ink-pink); }
.lane:nth-child(3) { --tint: var(--tint-blue); --ink: var(--ink-pink-dark); }
.lane:nth-child(4) { --tint: #ddf4fb; --ink: #2a9fc4; }
.lane.is-wrong { animation: lane-wrong .3s ease-out; }
@keyframes lane-wrong {
  50% { background: color-mix(in srgb, var(--tint) 45%, #ff2d6f); }
}

/* where the notes fall */
.track {
  position: relative;
  flex: 1;
  overflow: hidden;
  border-radius: 10px 10px 0 0;
}

.tile {
  position: absolute;
  left: 8%;
  width: 84%;
  height: 3.6rem;
  margin-top: -3.6rem; /* starts just above the track */
  border-radius: 8px;
  background: var(--ink);
  box-shadow: inset 0 -4px 0 rgb(0 0 0 / .16);
  will-change: transform;
}
.tile::after {
  content: "";
  position: absolute;
  inset: .55rem .7rem auto;
  height: 3px;
  border-radius: 3px;
  background: rgb(255 255 255 / .55);
}
.tile.is-hit { animation: tile-hit .22s ease-out forwards; }
@keyframes tile-hit {
  to { opacity: 0; transform: translateY(var(--y)) scale(1.35); }
}

/* the character who catches the notes */
.catcher {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  border-top: 3px solid var(--ink-pink-dark);
  border-radius: 0 0 10px 10px;
  background: var(--sheet);
  font: inherit;
  cursor: pointer;
}
/* the 8-bit sprite: a calm one, and a "caught it!" one stacked on top */
.catcher .sprite {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
}
.catcher .sprite img {
  position: absolute;
  inset: 8%;
  width: 84%;
  height: 84%;
  object-fit: contain;
  image-rendering: pixelated;
}
.sprite-hit { opacity: 0; }
.catcher.is-caught .sprite-base { opacity: 0; }
.catcher.is-caught .sprite-hit { opacity: 1; }

.catcher .name {
  display: block;
  padding: .2rem 0 .3rem;
  font-size: .85rem;
  font-weight: 700;
  text-align: center;
}

/* the reaction: squash, spring up, settle */
.catcher.is-caught .sprite { animation: sprite-react .4s ease-out; }
@keyframes sprite-react {
  0% { transform: translateY(0) scale(1, 1); }
  20% { transform: translateY(3px) scale(1.14, .84); }
  55% { transform: translateY(-12px) scale(.9, 1.14); }
  80% { transform: translateY(0) scale(1.04, .96); }
  100% { transform: translateY(0) scale(1, 1); }
}
.catcher.is-caught { animation: catcher-flash .4s ease-out; }
@keyframes catcher-flash {
  0%, 100% { background: var(--sheet); }
  30% { background: color-mix(in srgb, var(--sheet) 55%, var(--tint)); }
}

/* a music note pops out of the character */
.pop-note {
  position: absolute;
  left: 50%;
  top: 4%;
  opacity: 0;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--ink);
  pointer-events: none;
}
.catcher.is-caught .pop-note { animation: note-pop .5s ease-out; }
@keyframes note-pop {
  from { opacity: 1; transform: translate(-50%, 0) scale(.5) rotate(-10deg); }
  to { opacity: 0; transform: translate(-50%, -2.2rem) scale(1.25) rotate(14deg); }
}

@media (prefers-reduced-motion: reduce) {
  .catcher.is-caught .sprite,
  .catcher.is-caught .pop-note,
  .catcher.is-caught { animation: none; }
}

/* ---------- start / paused / game over ---------- */
.game-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: .75rem;
  padding: 1.5rem;
  background: rgb(253 253 251 / .93);
  text-align: center;
}
.game-overlay[hidden] { display: none; }
.game-overlay h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 6vw, 2.4rem);
  font-weight: 400;
  color: var(--ink-pink-dark);
}
.game-overlay p {
  max-width: 22rem;
  margin: 0 auto;
}
.game-keys {
  font-family: var(--font-pencil);
  font-size: 1.4rem;
}
.game-start { justify-self: center; }

.game-note {
  margin: .5rem 0 0;
  color: var(--pencil);
  font-size: .9rem;
  text-align: center;
}

.game-sound {
  display: block;
  margin: .75rem auto 0;
  padding: .35rem 1rem;
  border: 2px solid var(--edge);
  border-radius: 999px;
  background: var(--sheet);
  font: 700 .95rem var(--font-body);
  cursor: pointer;
}

@media (max-width: 40rem) {
  .game-board { height: min(58vh, 26rem); }
  .tile { height: 3rem; margin-top: -3rem; }
  .catcher .name { font-size: .72rem; }
  .pop-note { font-size: 1.1rem; }
  .game-hud { font-size: 1.35rem; }
}
