/* Forest Memory & Counting — game-specific styles. Base UI: shared/css/game-base.css */

:root {
  --game-bg: linear-gradient(180deg, #e8f5e9 0%, #c8e6c9 60%, #a5d6a7 100%);
  --game-ink: #1b5e20;
  --game-accent: #2e7d32;
}

.memory-board-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  perspective: 1000px;
}

/*
 * Grid size comes from level data (--cols / --rows set by game.js). Cards keep a
 * 3:4 ratio and shrink to fit both the width and the height of the screen.
 */
.memory-board {
  --gap: 12px;
  --card-w: min(
    150px,
    calc((100vw - 24px - (var(--cols) - 1) * var(--gap)) / var(--cols)),
    calc((100dvh - 150px - (var(--rows) - 1) * var(--gap)) / var(--rows) * 0.75)
  );
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), var(--card-w));
  grid-auto-rows: calc(var(--card-w) * 4 / 3);
  gap: var(--gap);
}

.card-scene {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 0;
  border: none;
  background: transparent;
  font: inherit;
  cursor: pointer;
  perspective: 800px;
  border-radius: 20px;
}

.card-scene:focus-visible {
  outline: 4px solid var(--game-focus);
  outline-offset: 3px;
}

.card-scene[aria-disabled="true"] {
  cursor: default;
}

.card-inner {
  position: absolute;
  inset: 0;
  transition: transform 0.45s cubic-bezier(0.4, 0.2, 0.2, 1);
  transform-style: preserve-3d;
  border-radius: 20px;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.12);
}

.card-scene.is-flipped .card-inner {
  transform: rotateY(180deg);
}

.card-scene.is-matched .card-inner {
  animation: memory-match 0.5s ease;
}

.card-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px;
  border-radius: 20px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.card-back {
  background: linear-gradient(135deg, #43a047 0%, #2e7d32 100%);
  border: 4px solid #ffffff;
  font-size: calc(var(--card-w) * 0.3);
}

.card-front {
  background: #ffffff;
  border: 4px solid #81c784;
  transform: rotateY(180deg);
}

.card-scene.is-matched .card-front {
  border-color: #ffb300;
}

.card-icon {
  font-size: calc(var(--card-w) * 0.34);
  line-height: 1.1;
  text-align: center;
}

.card-icon-quantity {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  font-size: calc(var(--card-w) * 0.2);
  gap: 2px;
}

.card-label {
  font-size: max(0.75rem, calc(var(--card-w) * 0.11));
  font-weight: 700;
  color: #2e7d32;
  text-align: center;
  overflow-wrap: anywhere;
}

.card-digit {
  font-size: calc(var(--card-w) * 0.45);
  font-weight: 900;
  color: #1b5e20;
}

@keyframes memory-match {
  0%, 100% { transform: rotateY(180deg) scale(1); }
  50% { transform: rotateY(180deg) scale(1.12); }
}

@media (max-width: 600px) {
  .memory-board {
    --gap: 8px;
  }
}

/* No 3D flip with reduced motion: cards switch instantly. */
@media (prefers-reduced-motion: reduce) {
  .card-inner {
    transition: none;
  }
}
