/* Arcade games: Flappy Popcorn, Popcorn Dash (canvas, reuse .game-shell/.game-frame/.overlay from games.css)
   and Snack 2048 (DOM board). Load after games.css. */
#flappy,
#dash {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 2/3;
  touch-action: none;
  background: var(--ink);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
#flappy:focus,
#dash:focus {
  outline: none;
}
#flappy:focus-visible,
#dash:focus-visible {
  outline: 3px solid var(--yellow);
  outline-offset: -3px;
}

/* ---------- Snack 2048 ---------- */
.s2-wrap {
  width: min(460px, 100%);
  margin-inline: auto;
}
.s2-top {
  display: flex;
  align-items: stretch;
  gap: 10px;
  margin-bottom: 14px;
}
.s2-box {
  flex: 1;
  display: grid;
  justify-items: center;
  align-content: center;
  padding: 8px 10px;
  border-radius: 16px;
  background: var(--navy-2);
  border: 3px solid var(--purple);
  min-width: 0;
}
.s2-box span {
  font-family: var(--label);
  font-weight: 800;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--cyan);
}
.s2-box b {
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.7rem;
  line-height: 1.1;
  color: #fff;
}
.s2-box.best b {
  color: var(--yellow);
}
.s2-top .btn {
  flex: 0 0 auto;
  padding-inline: 1em;
  font-size: 1.05rem;
}

.s2-board {
  --gap: clamp(7px, 2.4vw, 12px);
  position: relative;
  width: min(460px, 100%);
  margin-inline: auto;
  aspect-ratio: 1;
  padding: var(--gap);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: var(--gap);
  border-radius: 24px;
  background: linear-gradient(160deg, #170a5c, var(--ink));
  border: 4px solid var(--pink);
  box-shadow:
    0 0 0 5px var(--navy),
    0 0 0 8px var(--cyan),
    0 0 60px rgba(248, 89, 241, 0.35);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  container-type: inline-size;
  outline: none;
}
.s2-board:focus-visible {
  box-shadow:
    0 0 0 5px var(--navy),
    0 0 0 8px var(--yellow),
    0 0 60px rgba(248, 192, 0, 0.4);
}
.s2-cell {
  border-radius: 14px;
  background: rgba(122, 116, 171, 0.16);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.35);
}
.s2-tiles {
  position: absolute;
  inset: var(--gap);
  pointer-events: none;
}
.s2-tile {
  position: absolute;
  left: 0;
  top: 0;
  width: calc((100% - 3 * var(--gap)) / 4);
  height: calc((100% - 3 * var(--gap)) / 4);
  transform: translate(calc(var(--c) * (100% + var(--gap))), calc(var(--r) * (100% + var(--gap))));
  transition: transform 0.12s ease-in-out;
  will-change: transform;
  z-index: 1;
}
.s2-in {
  width: 100%;
  height: 100%;
  border-radius: 14px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 2px;
  text-align: center;
  padding: 4px;
  background: var(--bg);
  color: var(--fg, #0a043a);
  box-shadow:
    0 4px 0 var(--sh, rgba(0, 0, 0, 0.35)),
    inset 0 2px 0 rgba(255, 255, 255, 0.35);
}
.s2-e {
  font-size: 2rem;
  font-size: 9.4cqw;
  line-height: 1.05;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.25));
}
.s2-n {
  font-family: var(--label);
  font-weight: 800;
  font-size: 0.66rem;
  font-size: max(9px, 2.55cqw);
  line-height: 1.05;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  max-width: 100%;
}
.s2-l1 {
  --bg: #fff4c9;
  --sh: #d9b85a;
}
.s2-l2 {
  --bg: #ffe38a;
  --sh: #d7a400;
}
.s2-l3 {
  --bg: #ffc200;
  --sh: #a87c00;
}
.s2-l4 {
  --bg: #ffb0fb;
  --sh: #c95cc3;
}
.s2-l5 {
  --bg: #f85af1;
  --fg: #fff;
  --sh: #9c1c96;
}
.s2-l6 {
  --bg: #c53fc0;
  --fg: #fff;
  --sh: #6a0f63;
}
.s2-l7 {
  --bg: #8fe6ff;
  --sh: #2a9cc4;
}
.s2-l8 {
  --bg: #00c5ff;
  --sh: #00769b;
}
.s2-l9 {
  --bg: #00076a;
  --fg: #ffc200;
  --sh: #ffc200;
}
.s2-l9 .s2-in {
  border: 3px solid #ffc200;
  box-shadow:
    0 4px 0 #a87c00,
    0 0 22px rgba(255, 194, 0, 0.55);
}
.s2-l10 {
  --bg: linear-gradient(145deg, #f85af1, #00c5ff);
  --fg: #fff;
  --sh: #0a043a;
}
.s2-l10 .s2-in {
  box-shadow:
    0 4px 0 #0a043a,
    0 0 24px rgba(248, 90, 241, 0.6);
}
.s2-l11 {
  --bg: linear-gradient(145deg, #fff1a8, #ffc200 45%, #f0a000);
  --sh: #8a5a00;
}
.s2-l11 .s2-in {
  box-shadow:
    0 4px 0 #8a5a00,
    0 0 30px rgba(255, 194, 0, 0.8);
}
.s2-new .s2-in {
  animation: s2in 0.2s ease-out 0.08s both;
}
.s2-merged {
  z-index: 2;
}
.s2-merged .s2-in {
  animation: s2merge 0.22s ease-out;
}
@keyframes s2in {
  from {
    transform: scale(0);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}
@keyframes s2merge {
  0% {
    transform: scale(0.8);
  }
  55% {
    transform: scale(1.18);
  }
  100% {
    transform: scale(1);
  }
}
.s2-bump {
  animation: s2bump 0.22s;
}
@keyframes s2bump {
  25% {
    translate: -5px 0;
  }
  75% {
    translate: 5px 0;
  }
}
.s2-banner {
  position: absolute;
  inset: 0;
  z-index: 5;
  border-radius: 20px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  padding: 20px;
  text-align: center;
  background: radial-gradient(ellipse at center, rgba(14, 5, 76, 0.9), rgba(5, 2, 32, 0.95));
  animation: s2fade 0.3s ease-out;
}
.s2-banner[hidden] {
  display: none;
}
.s2-banner h3 {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(1.8rem, 7vw, 2.6rem);
  line-height: 1.05;
  color: var(--yellow);
  text-shadow: 0 0 22px rgba(248, 192, 0, 0.5);
}
.s2-banner p {
  max-width: 28ch;
  color: #dcd8f7;
}
.s2-banner .row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
@keyframes s2fade {
  from {
    opacity: 0;
  }
}
.s2-msg {
  min-height: 2.8em;
  margin-top: 16px;
  text-align: center;
  font-family: var(--label);
  font-weight: 700;
  font-size: 0.92rem;
  color: #dcd8f7;
}
.s2-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.s2-ladder {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 18px;
  padding: 0;
  list-style: none;
}
.s2-ladder li {
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: var(--label);
  font-weight: 700;
  font-size: 0.74rem;
  color: #cfcbef;
  padding: 4px 9px 4px 6px;
  border-radius: 999px;
  background: rgba(122, 116, 171, 0.16);
}
.s2-ladder li span {
  font-size: 1rem;
}
.s2-ladder li.win {
  background: rgba(255, 194, 0, 0.18);
  color: var(--yellow);
}
@media (prefers-reduced-motion: reduce) {
  .s2-tile {
    transition: none;
  }
  .s2-in,
  .s2-bump,
  .s2-banner {
    animation: none !important;
  }
}
.s2-ladder li {
  font-size: 0.8rem;
}

/* Flappy Popcorn character picker */
.fp-chars {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  max-width: 400px;
}
.fp-char {
  display: grid;
  justify-items: center;
  gap: 2px;
  width: 78px;
  padding: 6px 2px 5px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  color: #dcd8f7;
  font: 700 0.68rem/1.1 var(--label);
  cursor: pointer;
  transition:
    border-color 0.2s,
    background 0.2s,
    transform 0.2s;
}
.fp-char img {
  width: 44px;
  height: 52px;
  object-fit: contain;
  animation: fp-bob 1.1s ease-in-out infinite;
  animation-delay: var(--d, 0s);
}
.fp-char:hover {
  transform: translateY(-2px);
  border-color: var(--cyan);
}
.fp-char.on {
  border-color: var(--yellow);
  background: rgba(255, 194, 0, 0.16);
  color: #fff;
}
.fp-char.on img {
  animation: fp-dance 0.6s ease-in-out infinite;
}
.fp-chars.small .fp-char {
  width: 50px;
}
.fp-chars.small .fp-char span {
  display: none;
}
.fp-chars.small .fp-char img {
  width: 34px;
  height: 40px;
}
@keyframes fp-bob {
  50% {
    transform: translateY(-5px) rotate(-3deg);
  }
}
@keyframes fp-dance {
  0%,
  100% {
    transform: translateY(0) rotate(-7deg) scale(1.08);
  }
  50% {
    transform: translateY(-7px) rotate(7deg) scale(1.14);
  }
}
@media (prefers-reduced-motion: reduce) {
  .fp-char img,
  .fp-char.on img {
    animation: none;
  }
}
#fp-start {
  gap: 10px;
}
@media (max-width: 420px) {
  .fp-char {
    width: 64px;
  }
  .fp-char img {
    width: 36px;
    height: 44px;
  }
  #fp-start p {
    font-size: 0.85rem;
  }
}
