/* Shared layout for the canvas games (snake, bouncy ball). Builds on theme.css. */
.game { max-width: none; }
.game__hud, .game__stage, .game__help { max-width: 46rem; }
.game__hud { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.75rem; flex-wrap: wrap; }
.game__stat { display: inline-flex; align-items: baseline; gap: 0.35rem; padding: 0.35rem 0.8rem; border-radius: 999px; background: var(--surface); box-shadow: inset 0 0 0 1px var(--stone-200); font-size: 0.85rem; color: var(--stone-500); }
.game__stat strong { font-size: 1.05rem; color: var(--stone-900); font-variant-numeric: tabular-nums; }
.game__hud .btn { margin-left: auto; }
.game__stage { position: relative; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-card), inset 0 0 0 1px var(--stone-100); background: #1f2433; touch-action: none; user-select: none; }
.game__stage canvas { display: block; width: 100%; height: auto; }
.game__overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.75rem;
  padding: 1rem; text-align: center; color: #fff; background: rgba(20, 24, 36, 0.62); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
}
.game__overlay h2 { margin: 0; color: #fff; font-size: clamp(1.4rem, 4vw, 2rem); }
.game__overlay p { margin: 0; color: rgba(255, 255, 255, 0.82); max-width: 26rem; }
.game__overlay .btn { min-width: 9rem; }
.game__help { margin-top: 0.75rem; font-size: 0.85rem; color: var(--stone-500); }
/* On-screen controls (touch screens only) */
.game { scroll-margin-top: calc(var(--header-h) + 0.5rem); }
@media (max-width: 900px) { .game { scroll-margin-top: 0.5rem; } }  /* the header slides away while scrolling down */
.game.is-playing, .game__pad { touch-action: none; }
.game__pad { display: none; margin-top: 0.75rem; gap: 0.6rem; justify-content: center; max-width: 46rem; }
.game__pad button, .game__track {
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: none;
}
.game__pad button {
  display: grid; place-items: center; width: 4.25rem; height: 3.75rem; margin: 0; padding: 0; border: 0;
  border-radius: 1rem; background: var(--surface); color: var(--stone-700);
  box-shadow: inset 0 0 0 1px var(--stone-200), 0 2px 0 var(--stone-200);
  transition: transform 0.06s, background-color 0.06s;
}
.game__pad button svg.lucide { width: 1.75rem; height: 1.75rem; stroke-width: 2.4; }
.game__pad button:active, .game__pad button.is-pressed {
  background: var(--brand-100); color: var(--brand-700); transform: translateY(2px);
  box-shadow: inset 0 0 0 1px var(--brand-200);
}
.game__pad--dpad { grid-template-columns: repeat(3, 4.5rem); grid-template-rows: repeat(2, 3.75rem); gap: 0.5rem; }
.game__pad--dpad button { width: 100%; height: 100%; }
.game__pad--dpad [data-dir="up"] { grid-column: 2; }
.game__pad--dpad [data-dir="left"] { grid-column: 1; grid-row: 2; }
.game__pad--dpad [data-dir="down"] { grid-column: 2; grid-row: 2; }
.game__pad--dpad [data-dir="right"] { grid-column: 3; grid-row: 2; }
.game__pad--strip { align-items: stretch; }
.game__track {
  flex: 1; display: grid; place-items: center; min-height: 3.75rem; border-radius: 1rem;
  background: repeating-linear-gradient(90deg, transparent 0 14px, rgba(228, 130, 51, 0.12) 14px 16px), var(--surface);
  box-shadow: inset 0 0 0 1px var(--stone-200); color: var(--stone-400);
}
.game__track svg.lucide { width: 1.75rem; height: 1.75rem; }
.game__track.is-dragging { background-color: var(--brand-50); color: var(--brand-600); box-shadow: inset 0 0 0 2px var(--brand-300); }
@media (pointer: coarse) {
  .game__pad { display: flex; }
  .game__pad--dpad { display: grid; }
  .game__help { font-size: 0.8rem; text-align: center; }
  .game__overlay { cursor: pointer; }
}
@media (max-width: 640px) {
  .game__hud { margin-bottom: 0.5rem; }
  .game__stat { padding: 0.3rem 0.65rem; }
  .game__stage { border-radius: var(--radius-sm); }
}
/* Phones held sideways: keep the whole board on screen instead of letting it run past the bottom. */
@media (orientation: landscape) and (max-height: 600px) {
  .game__stage { width: fit-content; max-width: 100%; }
  .game__stage canvas { width: auto; max-width: 100%; max-height: calc(100vh - 2rem); max-height: calc(100svh - 2rem); margin: 0 auto; }
}
/* Phones held upright: board + controls fit in one screen below the header. */
@media (pointer: coarse) and (max-width: 640px) and (orientation: portrait) {
  .game { --controls-h: 4.5rem; }
  .game:has(.game__pad--dpad) { --controls-h: 8.75rem; }
  .game__stage { width: fit-content; max-width: 100%; margin-inline: auto; }
  .game__stage canvas {
    width: auto; max-width: 100%; margin: 0 auto;
    max-height: calc(100vh - var(--header-h) - var(--controls-h) - 4.5rem);
    max-height: calc(100svh - var(--header-h) - var(--controls-h) - 4.5rem);
  }
}

/* ---------- Segmented control (difficulty) ---------- */
/* .segmented (difficulty buttons) lives in theme.css */

/* ---------- Pair matching ---------- */
.pair-wrap { position: relative; max-width: 46rem; border-radius: var(--radius); overflow: hidden; }
.pair-board {
  --cols: 6;
  display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 0.5rem;
  padding: 0.75rem; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-card), inset 0 0 0 1px var(--stone-100);
}
.pair-board[data-level="easy"] { max-width: 26rem; }
.pair-board[data-level="normal"] { max-width: 34rem; }
.pair-wrap:has(.pair-board[data-level="easy"]) { max-width: 26rem; }
.pair-wrap:has(.pair-board[data-level="normal"]) { max-width: 34rem; }
.pair-board .pair-card, .pair-board .pair-card:hover, .pair-board .pair-card:active {
  aspect-ratio: 1; min-height: 0; margin: 0; padding: 0; border: 0; background: none; cursor: pointer;
  perspective: 600px; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  font-size: clamp(1rem, calc(min(100vw - 3rem, 44rem) / var(--cols) * 0.45), 2.4rem);
}
.pair-card__inner { position: relative; display: block; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform 0.3s; }
.pair-card.is-open .pair-card__inner, .pair-card.is-matched .pair-card__inner { transform: rotateY(180deg); }
.pair-card__back, .pair-card__front {
  position: absolute; inset: 0; display: grid; place-items: center; border-radius: var(--radius-sm);
  -webkit-backface-visibility: hidden; backface-visibility: hidden;
}
.pair-card__back {
  background: linear-gradient(135deg, var(--brand-300), var(--brand-500));
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.12);
}
.pair-card__back::after { content: "?"; color: rgba(255, 255, 255, 0.75); font-weight: 700; font-size: 0.8em; }
.pair-card__front { transform: rotateY(180deg); background: var(--brand-50); box-shadow: inset 0 0 0 2px var(--brand-200); }
.pair-card.is-matched .pair-card__front { background: var(--ok-bg, #ecfdf5); box-shadow: inset 0 0 0 2px #86efac; }
.pair-card:focus-visible { outline: 3px solid var(--brand-300); outline-offset: 2px; border-radius: var(--radius-sm); }
@media (hover: hover) { .pair-card:not(.is-open):not(.is-matched):hover .pair-card__back { filter: brightness(1.06); } }
@media (max-width: 640px) {
  .pair-board { gap: 0.35rem; padding: 0.5rem; }
  .segmented { display: flex; }
  .segmented button { flex: 1; }
}

/* ---------- Catch the button ---------- */
.catch-arena {
  position: relative; overflow: hidden; max-width: 46rem; height: min(60vh, 28rem);
  border-radius: var(--radius); touch-action: none; user-select: none; -webkit-user-select: none;
  background: radial-gradient(circle at 30% 20%, var(--surface), var(--brand-50) 70%);
  box-shadow: var(--shadow-card), inset 0 0 0 1px var(--brand-100);
}
.catch-arena .catch-btn, .catch-arena .catch-btn:hover, .catch-arena .catch-btn:active {
  position: absolute; left: 0; top: 0; margin: 0; padding: 0.75rem 1.25rem; border: 0; border-radius: 999px;
  background: #22c55e; color: #fff; font: inherit; font-weight: 700; white-space: nowrap; cursor: pointer;
  box-shadow: 0 4px 0 #15803d, 0 8px 16px rgba(21, 128, 61, 0.25); will-change: transform;
  -webkit-tap-highlight-color: transparent; touch-action: none;
}
.catch-arena .catch-btn.is-squash { animation: catch-squash 0.25s ease; }
@keyframes catch-squash { 40% { scale: 1.15 0.85; } 70% { scale: 0.95 1.05; } }
.catch-spark {
  position: absolute; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%; pointer-events: none;
  animation: catch-spark 0.7s ease-out forwards;
}
@keyframes catch-spark { to { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.3); } }
@media (pointer: coarse) {
  .catch-arena .catch-btn { padding: 0.9rem 1.4rem; font-size: 1.05rem; }
}
@media (max-width: 640px) {
  .catch-arena { height: calc(100svh - 9rem); max-height: 34rem; min-height: 20rem; border-radius: var(--radius-sm); }
}

/* Wider screens (tablets, desktops): the game column is centred instead of hugging the left edge */
.game > .game__hud, .game > .game__stage, .game > .game__pad, .game > .game__help,
.game > .pair-wrap, .game > .catch-arena, .game > .segmented { margin-left: auto; margin-right: auto; }
.game > .segmented { display: flex; width: fit-content; }
.game > .game__help { text-align: center; }
.game:has(.pair-board[data-level="easy"]) .game__hud { max-width: 26rem; }
.game:has(.pair-board[data-level="normal"]) .game__hud { max-width: 34rem; }
@media (max-width: 640px) { .game > .segmented { width: auto; } }
