/* The games (js/games/), played: a game's play area, Back, the chrome
   line, the end-of-round card and each game's own board. The Apps
   launcher that opens them is apps.css; loaded after it. */

/* A game: the play area between the key bar and the player, 1280 x 544.
   The three board games share one composition, three columns on the same
   two lines (20 px inside the play area's top and foot): the panel (the
   name on Back's line, the score, the best, how to play, New game at the
   foot), the board, 504 px square, and what the hands use or the eye
   counts (the arrow pad; Memory's pairs found). */
.game {
  position: absolute;
  inset: var(--safe-top) 0 var(--safe-bottom);
  overflow: hidden;
  --panel-w: 288px;
  --stage: 504px;
  --stage-x: calc(var(--edge) + var(--panel-w) + var(--s4));
  --stage-inset: 20px; /* (544 - 504) / 2 */
  /* A game's own art, the same in either theme, as Marv's is: a screen
     that is off, and the wells of 2048's tray in it. */
  --screen: #14130f;
  --screen-well: #090806;
}

.game-body { position: absolute; inset: 0; }

/* ---- The games' pictures (js/games/art.js) ----
   One set with the Apps tiles' (apps.css, .tile-art): the same palette,
   the same round ink line, here 3 units on a 64 grid. */
.game-art {
  display: block;
  fill: none;
  stroke: var(--art-ink);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.game-art .p { fill: var(--art-paper); }
.game-art .s { fill: var(--art-steel); }
.game-art .a { fill: var(--art-amber); }
.game-art .r { fill: var(--art-red); }
.game-art .g { fill: var(--art-green); }
.game-art .b { fill: var(--art-blue); }
.game-art .k { fill: var(--art-ink); }
.game-art .n { stroke: none; }
.game-art .l { fill: none; }

/* Back: the shared round button (style.css, Shared controls). */

/* The game's name: an app's heading, on the back button's line. A name
   of two words takes two lines there, the button's own height. */
.game-title {
  position: absolute;
  left: calc(var(--edge) + 80px + var(--s2));
  top: var(--s3);
  width: calc(var(--panel-w) - 80px - var(--s2));
  height: 80px;
  margin: 0;
  display: flex;
  align-items: center;
  font-size: var(--fs-title);
  font-weight: var(--fw-semibold);
  line-height: 1;
  z-index: 2;
}

/* The panel, on the content edge under Back. */
.game-hud {
  position: absolute;
  left: var(--edge);
  top: calc(var(--s3) + 80px + var(--s2));
  width: var(--panel-w);
  pointer-events: none;
  z-index: 2;
}

/* The score: the biggest thing beside the board, read from across the
   kitchen. Four figures fit the panel at the numeral size; a longer
   score is set smaller, never under the headline size. */
.game-score { position: relative; }
.game-score b {
  display: block;
  width: max-content;
  font-size: var(--fs-numeral);
  font-weight: var(--fw-semibold);
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  transform-origin: 0 60%;
}
.game-score b[data-len="5"] { font-size: 96px; line-height: 120px; }
.game-score b[data-len="6"] { font-size: 80px; line-height: 120px; }
.game-score b[data-len="7"], .game-score b[data-len="8"] { font-size: var(--fs-headline); line-height: 120px; }
/* What it counts, under it. */
.game-unit { display: block; font-size: var(--fs-label); line-height: 1.2; color: var(--text-2); }

/* The best so far, with its star: hollow until this round beats it,
   then filled, amber, and the words say so. */
.game-best {
  display: flex;
  align-items: center;
  gap: var(--s1);
  margin-top: var(--s2);
  font-size: var(--fs-body);
  line-height: 1.2;
  color: var(--text-2);
}
.game-star { flex: none; width: 28px; height: 28px; }
.game-star path { fill: none; }
.game .game-best.beat { color: var(--accent-mark); font-weight: var(--fw-semibold); }
.game-best.beat .game-star path { fill: currentColor; }

/* How to play, under the best until the round's first move. */
.game-howto {
  margin: var(--s3) 0 0;
  font-size: var(--fs-label);
  line-height: 1.35;
  color: var(--text-2);
  transition: opacity var(--dur-1) var(--ease);
}
.game-howto:empty { display: none; }
.game-howto.gone { opacity: 0; }

/* A score going up: the number pops amber and settles; what it gained
   rises from the end of the line under it. */
.game-score b.bump { animation: score-bump 320ms var(--ease-pop); }
.game-flappy .game-score b { transform-origin: 50% 60%; }

@keyframes score-bump {
  35% { scale: 1.1; color: var(--score-pop); }
}

.game-gain {
  position: absolute;
  right: 0;
  bottom: 0;
  font-size: var(--fs-body);
  font-style: normal;
  font-weight: var(--fw-bold);
  line-height: 1;
  color: var(--accent-mark);
  white-space: nowrap;
  pointer-events: none;
  animation: gain-rise 800ms var(--ease) forwards;
}

@keyframes gain-rise {
  from { translate: 0 8px; opacity: 0; }
  20% { opacity: 1; }
  to { translate: 0 -20px; opacity: 0; }
}

/* Flappy Marv's world takes the whole play area, so its panel is only
   the count, top centre in the sky, with the best under it. */
.game-flappy .game-hud {
  left: 50%;
  top: var(--s1);
  width: auto;
  transform: translateX(-50%);
  text-align: center;
  text-shadow: var(--shadow-text);
}
/* The count is words over a picture, so it sits on the picture's shade
   as a caption does: a soft fall-off, no edge, the pipes still seen
   through it; a tight halo keeps the numeral whole over a silver pipe. */
.game-flappy .game-hud::before {
  content: "";
  position: absolute;
  inset: -16px -96px -24px;
  z-index: -1;
  background: radial-gradient(closest-side, rgba(var(--shade-rgb), 0.5) 40%, rgba(var(--shade-rgb), 0.3) 70%, transparent);
  pointer-events: none;
}
.game-flappy .game-score b { text-shadow: 0 0 3px rgba(var(--shade-rgb), 0.7), var(--photo-shadow-text); }
.game-flappy .game-title, .game-flappy .game-unit { display: none; }
/* Marv's Face is built on the same frame and hides the panel itself
   (face.js); the name goes with it: his Face is his own art, unlabelled. */
.game-face .game-title { display: none; }
.game-flappy .game-score b { margin: 0 auto; }
.game-flappy .game-best { justify-content: center; margin-top: 0; color: var(--text); }

/* Flappy's sky is 544 px tall: the strip under it (the tray's) carries
   on its counter-top ground instead of ending in black. */
.games:has(> .game-flappy) {
  background: linear-gradient(to bottom, var(--bg) 0, var(--bg) 600px, #8b5a32 600px, #6e4526 720px);
}
/* ... and dims with it under the end-of-round card's veil. */
.games:has(> .game-flappy .game-card:not([hidden])) {
  background: linear-gradient(to bottom, var(--bg) 0, var(--bg) 600px, #382414 600px, #2c1c0f 720px);
}
/* The running score sits over the card's top edge; the card says the
   score, so the count steps aside while it shows. */
.game-flappy .game-hud { transition: opacity var(--dur-1) var(--ease); }
.game-flappy:has(.game-card:not([hidden])) .game-hud { opacity: 0; }

/* New game: the panel's foot, on the board's bottom line. */
.games .game-new {
  position: absolute;
  left: var(--edge);
  bottom: var(--stage-inset);
}

/* ---- The board of a game played on a screen (2048, Snake) ----
   A screen in a steel frame edged in Marv's ink, as his Face is a screen
   in its plate: the same object in either theme, dark because it is a
   screen, not because the shell is. 476 px of picture in a 504 px frame. */
.game-screen {
  position: absolute;
  left: var(--stage-x);
  top: var(--stage-inset);
  width: var(--stage);
  height: var(--stage);
  box-sizing: border-box;
  padding: 10px;
  border: var(--art-line) solid var(--art-ink);
  border-radius: var(--r-l);
  background: var(--art-steel);
  box-shadow: 0 12px 32px rgba(var(--shade-rgb), calc(0.45 * var(--shadow-a)));
}
.game-screen > :first-child {
  position: relative;
  display: block;
  width: 476px;
  height: 476px;
  border-radius: 14px;
  background: var(--screen);
  /* The screen's own edge, where the glass meets the frame. */
  box-shadow: 0 0 0 3px var(--art-ink);
}

/* A hint over a game's picture, waiting for the first move: a paper
   label with the one ink edge, the same on every game and in either
   theme (what it lies on does not change with the theme either). Still:
   it can wait a long time, and nothing should pulse that long. */
.game-hint {
  position: absolute;
  left: 50%;
  top: 64%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: var(--s1);
  height: var(--touch);
  padding: 0 var(--s3);
  border: var(--art-line) solid var(--art-ink);
  border-radius: var(--r-pill);
  background: var(--paper);
  color: var(--text-on-light);
  font-size: var(--fs-body);
  font-weight: var(--fw-semibold);
  white-space: nowrap;
  pointer-events: none;
  box-shadow: var(--shadow-float);
}
.game-hint[hidden] { display: none; }
.game-pause { display: none; width: 32px; height: 32px; margin-left: -4px; }
.game-hint.paused .game-pause { display: block; }

.snake-hint { top: auto; bottom: var(--s5); }
/* The fruit is in the bottom rows (js/games/snake.js): the hint goes as
   far in from the board's top edge as it otherwise is from its bottom. */
.snake-hint.top { top: var(--s5); bottom: auto; }

/* Arrow pad: a cross of big buttons, right of the board, on the right
   content edge as the panel is on the left one, its arrows the key
   bar's. Pressed, a button is the shared one pressed. */
.arrow-pad {
  position: absolute;
  right: var(--edge);
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  grid-template: repeat(3, 104px) / repeat(3, 104px);
  gap: var(--s1);
}

.games .arrow { width: auto; height: auto; padding: 0; border-radius: var(--r-l); }
.arrow .icon { width: 56px; height: 56px; }
.arrow-up { grid-area: 1 / 2; }
.arrow-left { grid-area: 2 / 1; }
.arrow-right { grid-area: 2 / 3; }
.arrow-down { grid-area: 3 / 2; }

/* ---- End of a round ----
   The confirm card's manners (style.css, .confirm-card): a card over the
   veil with the stronger line and the one shadow, a picture, a headline,
   a line, and the one main action, full size. */
.game-card {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--veil-game);
  z-index: 4;
}
/* The veil carried on over the foot strip under the game (--veil-game-foot:
   only a light theme has anything to dim there). Flappy's strip is its
   own ground, which dims itself (above). */
.games:has(> .game:not(.game-flappy) .game-card:not([hidden]))::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--safe-bottom);
  background: var(--veil-game-foot);
  pointer-events: none;
}

.game-card-box {
  width: 680px;
  box-sizing: border-box;
  padding: var(--s4) var(--s6) var(--s5);
  border-radius: var(--r-xl);
  text-align: center;
  border-color: var(--line-strong); /* a card over the veil: the stronger line, the one shadow */
  box-shadow: var(--shadow-float);
  animation: card-in 260ms var(--ease-pop);
}

/* The game's own picture, as on its tile in Apps. */
.game-card-art { display: grid; place-items: center; margin-bottom: var(--s1); }
.game-card-art:empty { display: none; }
.game-card-art > svg { width: 112px; height: 112px; }

.game-card h2 { margin: 0; font-size: var(--fs-headline); font-weight: var(--fw-semibold); line-height: 1.1; }
.game-card p { margin: var(--s1) 0 0; font-size: var(--fs-body); line-height: 1.3; color: var(--text); }
/* The best so far (or the one just beaten), a step quieter, with the
   best's star. */
.game-card .game-card-best {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s1);
  font-size: var(--fs-label);
  color: var(--text-2);
}
.game-card .game-card-best[hidden] { display: none; }
.game-card-best .game-star { width: 24px; height: 24px; }

.games .game-play { min-width: 320px; margin-top: var(--s3); }

/* A new best is a prize: the rosette pinned over the card's top edge
   (half on, half off, turning in as it lands), the card in the selected
   ring, the headline amber, the star beside the beaten best filled. The
   card sits lower to leave the rosette its room. */
.game-card.best { padding-top: 56px; box-sizing: border-box; }
.game-card.best .game-card-box {
  padding-top: 0;
  border-color: transparent;
  outline: var(--ring);
  outline-offset: calc(var(--ring-width) / -2);
}
.game-card.best .game-card-art {
  margin-top: -68px;
  animation: star-in 520ms var(--ease-pop) 120ms backwards;
}
.game-card.best .game-card-art > svg { width: 148px; height: 148px; }
.game-card.best h2 { color: var(--accent-mark); }
.game-card.best .game-star path { fill: currentColor; }

@keyframes star-in { from { transform: scale(0.2) rotate(-90deg); opacity: 0; } }

@keyframes card-in { from { transform: scale(0.8); opacity: 0; } }

/* New best: a banner and a burst of confetti, in the picture set's
   colours. */
.celebrate {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 5;
}

/* The banner ("You made 2048!"): an amber plate with the ink edge and
   ink words, so it reads on the board and on the page beside it alike. */
.game .celebrate .celebrate-ribbon {
  position: absolute;
  left: 50%;
  top: 20%;
  transform: translateX(-50%) rotate(-3deg);
  padding: var(--s1) var(--s4);
  border: var(--art-line) solid var(--art-ink);
  border-radius: var(--r-m);
  background: var(--accent);
  color: var(--text-on-accent);
  font-size: var(--fs-headline);
  font-weight: var(--fw-bold);
  line-height: 1.2;
  white-space: nowrap;
  text-shadow: none;
  box-shadow: var(--shadow-float);
  animation: ribbon 2.4s ease forwards;
}

.celebrate i {
  position: absolute;
  top: -24px;
  width: 14px;
  height: 20px;
  border-radius: 3px;
  animation: confetti linear forwards;
}

@keyframes ribbon {
  0% { scale: 0.3; opacity: 0; }
  12% { scale: 1.12; opacity: 1; }
  20%, 80% { scale: 1; opacity: 1; }
  100% { scale: 1; opacity: 0; }
}

@keyframes confetti {
  to { transform: translate(var(--drift), 600px) rotate(var(--spin)); opacity: 0.6; }
}

/* Flappy Marv and Snake draw on canvas. */
.flappy-canvas { position: absolute; inset: 0; display: block; }

/* 2048: tiles slide by transform; spawn and pop use scale. The screen
   shows a tray of sunken wells; a tile is a block on it, coloured from
   the ramp in g2048.js (--tile, --tile-ink). */
.board-2048 i, .tile {
  position: absolute;
  left: 0;
  top: 0;
  width: 104px;
  height: 104px;
  border-radius: var(--r-s);
}

.board-2048 i { background: var(--screen-well); }

.tile {
  display: grid;
  place-items: center;
  font-size: 56px;
  font-weight: var(--fw-bold);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--tile-ink);
  background: var(--tile);
  /* A block with a foot: one flat face, a darker lip under it. */
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.2);
  padding-bottom: 6px;
  box-sizing: border-box;
  transition: transform 110ms ease-out;
}

/* A merge: a ring of light bursts off the tile as it pops. */
.tile::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: 0 0 0 4px var(--accent-strong);
  opacity: 0;
  pointer-events: none;
}

.tile.spawn { animation: tile-spawn 200ms var(--ease-pop) 90ms backwards; }
.tile.pop { animation: tile-pop 220ms var(--ease-pop); }
.tile.pop::after { animation: tile-ring 380ms var(--ease) forwards; }

@keyframes tile-spawn { from { scale: 0.3; opacity: 0; } }
@keyframes tile-pop { 45% { scale: 1.18; } }
@keyframes tile-ring {
  from { opacity: 0.9; scale: 1; }
  to { opacity: 0; scale: 1.3; }
}

.tile[data-len="3"] { font-size: 46px; }
.tile[data-len="4"] { font-size: 38px; }
.tile[data-len="5"], .tile[data-len="6"] { font-size: 30px; }
/* 2048 and beyond glow gold (a screen's light: the game's own art). */
.tile.glow { box-shadow: inset 0 -6px 0 rgba(160, 100, 20, 0.25), 0 0 28px rgba(255, 181, 71, 0.7); }

/* Memory match: cards on the bench, turned over in 3D. A card is the
   picture set's: steel-backed with Marv's hard hat, paper-faced with a
   food, each inside the one ink edge, so it is the same card on either
   ground. */
.memory-grid {
  position: absolute;
  left: var(--stage-x);
  top: var(--stage-inset);
  display: grid;
  grid-template-columns: repeat(4, 117px);
  gap: 12px;
}

.games .mcard { position: relative; width: 117px; height: 117px; perspective: 700px; }
.games .mcard.focus { outline: var(--ring); outline-offset: 5px; border-radius: var(--r-m); }

.mcard-in {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 320ms var(--ease);
}

/* Turning up, the card lifts toward you on the way over. */
.mcard.up .mcard-in { transform: rotateY(180deg); animation: mcard-lift 320ms var(--ease); }

@keyframes mcard-lift { 50% { scale: 1.08; } }

.mcard-back, .mcard-face {
  position: absolute;
  inset: 0;
  box-sizing: border-box;
  border: var(--art-line) solid var(--art-ink);
  border-radius: var(--r-m);
  backface-visibility: hidden;
  display: grid;
  place-items: center;
  /* A card's thickness: a hard foot, no blur. */
  box-shadow: 0 4px 0 rgba(var(--shade-rgb), calc(0.45 * var(--shadow-a)));
}

.mcard-back { background: var(--art-steel); }
.mcard-back svg { width: 80px; height: 80px; }

.mcard-face { background: var(--art-paper); transform: rotateY(180deg); }
.mcard-face svg { width: 88px; height: 88px; }

/* A pair found: a tick badge on the corner (shape, not just colour), and
   the card settles a step darker, as paper held down, so what's left
   stands out. */
.mcard-tick {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 38px;
  height: 38px;
  box-sizing: border-box;
  border: 3px solid var(--art-ink);
  border-radius: 50%;
  display: none;
  place-items: center;
  background: var(--art-green);
  color: var(--art-ink);
}

.mcard-tick svg { width: 22px; height: 22px; }
.mcard.done .mcard-tick { display: grid; animation: tick-in 300ms var(--ease-pop) 260ms backwards; }
.mcard.done .mcard-face { background: var(--paper-press); }
.mcard.done { animation: matched 380ms var(--ease) 200ms; }
/* Not a pair: both shake their heads once they've turned. */
.mcard.miss { animation: miss 360ms var(--ease) 260ms; }

@keyframes matched { 50% { scale: 1.1; } }
@keyframes tick-in { from { scale: 0; } }
@keyframes miss {
  20% { translate: -8px 0; }
  45% { translate: 7px 0; }
  70% { translate: -4px 0; }
  85% { translate: 2px 0; }
}

/* The pairs found so far, right of the cards where the other games have
   their arrows: how many of the eight, and a round socket for each,
   hollow until its pair is found (a hollow outline is "nothing here
   yet"), then the food on a paper token. Round, so never taken for a
   card to turn. */
.memory-found {
  position: absolute;
  right: var(--edge);
  top: var(--stage-inset);
  width: 328px;
  height: var(--stage);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end; /* on the board's bottom line, so it starts under the timer pill */
  gap: var(--s3);
  pointer-events: none;
}
.memory-found p { margin: 0; font-size: var(--fs-body); line-height: 1.2; color: var(--text-2); }
.memory-found b { color: var(--text); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; }
.memory-slots { display: grid; grid-template-columns: repeat(2, 80px); gap: 12px var(--s3); }
.memory-slots i {
  width: 80px;
  height: 80px;
  box-sizing: border-box;
  border: var(--edge-w) solid var(--control-off-edge);
  border-radius: 50%;
  display: grid;
  place-items: center;
}
.memory-slots i.in {
  border: var(--art-line) solid var(--art-ink);
  background: var(--art-paper);
  animation: tick-in 300ms var(--ease-pop) 320ms backwards;
}
.memory-slots svg { width: 54px; height: 54px; }

@media (prefers-reduced-motion: reduce) {
  .game-card-box, .game-card.best .game-card-art, .memory-slots i.in, .mcard.done .mcard-tick { animation: none; }
}
