/* ============================================================
   Memory Match — game-only styles (linked from games/memory.html)
   Uses site tokens from styles.css
   ============================================================ */

.memory-game {
  position: relative;
}

.memory-help {
  margin: 0 0 14px;
  font-size: 18px;
  color: var(--muted);
  text-align: center;
  line-height: 1.4;
}

/* ---- difficulty selector ---- */
.memory-difficulty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.memory-difficulty-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.memory-difficulty-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.memory-diff-btn {
  margin-top: 0 !important;
  font-size: 7px !important;
  padding: 8px 10px !important;
  background: linear-gradient(180deg, #fff 0%, var(--pink-soft) 100%);
}

.memory-diff-btn.is-active,
.memory-diff-btn[aria-pressed="true"] {
  background: linear-gradient(180deg, var(--lavender) 0%, var(--pink) 100%);
  box-shadow: inset 1px 1px 0 var(--border-dark), 1px 1px 0 var(--shadow);
  color: var(--text-dark);
}

.memory-diff-btn:hover {
  background: linear-gradient(180deg, var(--pink-soft) 0%, var(--lavender) 100%);
}

.memory-diff-btn.is-active:hover {
  background: linear-gradient(180deg, var(--lavender) 0%, var(--pink) 100%);
}

/* ---- HUD ---- */
.memory-hud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 14px;
}

.memory-stat {
  min-width: 72px;
  padding: 6px 10px;
  text-align: center;
  background: var(--bg-window);
  border: 2px solid var(--border);
  box-shadow: 2px 2px 0 var(--shadow);
}

.memory-stat-label {
  display: block;
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: var(--muted);
  margin-bottom: 4px;
}

.memory-stat-value {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: var(--text-dark);
}

.memory-stat-best .memory-stat-value {
  font-size: 8px;
}

/* ---- board shell: keep overflow visible so last-row cards/shadows aren't clipped ---- */
.memory-board-scroll {
  width: 100%;
  max-width: 100%;
  margin: 0 auto 12px;
  overflow: visible;
  display: flex;
  justify-content: center;
  padding: 2px 4px 10px;
  border: 2px dashed transparent;
  box-sizing: border-box;
}

.memory-board-scroll.is-scrollable {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border-color: var(--pink-soft);
  background: rgba(255, 250, 253, 0.45);
  padding: 6px 6px 12px;
  box-shadow: inset 0 0 0 1px var(--pink-soft);
}

/* ---- board ---- */
.memory-board {
  display: grid;
  gap: 10px;
  margin: 0 auto;
  /* avoid perspective clipping transformed card faces */
  perspective: none;
  padding-bottom: 2px;
  box-sizing: border-box;
}

.memory-board.size-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  max-width: 420px;
  width: 100%;
  gap: 10px;
  /* room for 2px drop shadow under last row */
  padding-bottom: 6px;
}

.memory-board.size-8 {
  grid-template-columns: repeat(8, minmax(0, 1fr));
  max-width: 560px;
  width: 100%;
  gap: 6px;
  padding-bottom: 4px;
}

.memory-board.size-16,
.memory-board.size-32 {
  /* Explicit cell tracks so tiny cards can't collapse/overlap */
  width: max-content;
  height: max-content;
  max-width: none;
  min-width: 0;
  aspect-ratio: auto;
  perspective: none;
  padding-bottom: 4px;
}

.memory-board.size-16 {
  grid-template-columns: repeat(16, var(--memory-cell-size, 40px));
  grid-template-rows: repeat(16, var(--memory-cell-size, 40px));
  gap: 3px;
}

.memory-board.size-32 {
  grid-template-columns: repeat(32, var(--memory-cell-size, 20px));
  grid-template-rows: repeat(32, var(--memory-cell-size, 20px));
  gap: 1px;
}

/* Compact chrome so Hard boards get more room */
.memory-game.is-compact .memory-help {
  display: none;
}

.memory-game.is-compact .memory-difficulty {
  margin-bottom: 8px;
}

.memory-game.is-compact .memory-hud {
  margin-bottom: 8px;
  gap: 6px;
}

.memory-game.is-compact .memory-stat {
  min-width: 58px;
  padding: 4px 6px;
}

.memory-game.is-compact .memory-actions {
  margin-top: 2px;
}

.memory-card {
  aspect-ratio: 1 / 1;
  width: 100%;
  height: auto;
  min-height: 0;
  padding: 0;
  border: 2px solid var(--border);
  background: transparent;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--shadow);
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  min-width: 0;
  overflow: visible;
  position: relative;
}

.memory-board.size-8 .memory-card {
  border-width: 1px;
  box-shadow: 1px 1px 0 var(--shadow);
}

.memory-board.size-16 .memory-card,
.memory-board.size-32 .memory-card {
  /* Fill the fixed grid track; kill inherited 20px font min-size blowout */
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  border-width: 1px;
  box-shadow: none;
  overflow: hidden;
  font-size: 0;
  line-height: 0;
  min-width: 0;
  min-height: 0;
}

.memory-card:focus-visible {
  outline: 2px dashed var(--pink-deep);
  outline-offset: 3px;
}

.memory-board.size-16 .memory-card:focus-visible,
.memory-board.size-32 .memory-card:focus-visible {
  outline-offset: 1px;
  outline-width: 1px;
}

.memory-card:disabled {
  cursor: default;
}

.memory-card-inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.35s ease;
}

/* Lightweight flip for large boards (less GPU cost) */
.memory-board.size-16 .memory-card-inner,
.memory-board.size-32 .memory-card-inner {
  position: absolute;
  inset: 0;
  transform-style: flat;
  transition: opacity 0.12s ease, transform 0.12s ease;
}

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

.memory-board.size-16 .memory-card.is-flipped .memory-card-inner,
.memory-board.size-16 .memory-card.is-matched .memory-card-inner,
.memory-board.size-32 .memory-card.is-flipped .memory-card-inner,
.memory-board.size-32 .memory-card.is-matched .memory-card-inner {
  transform: none;
}

.memory-card-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  font-size: clamp(22px, 7vw, 36px);
  line-height: 1;
  overflow: hidden;
}

.memory-board.size-8 .memory-card-face {
  font-size: clamp(12px, 2.4vw, 20px);
}

.memory-board.size-16 .memory-card-face {
  font-size: clamp(16px, 2.8cqi, 28px);
  backface-visibility: visible;
  -webkit-backface-visibility: visible;
}

.memory-board.size-16 .memory-face-emoji {
  font-size: 1em;
  line-height: 1;
}

.memory-board.size-32 .memory-card-face {
  font-size: clamp(9px, 2.1cqi, 14px);
  backface-visibility: visible;
  -webkit-backface-visibility: visible;
}

.memory-board.size-16,
.memory-board.size-32 {
  container-type: inline-size;
}

.memory-card-back {
  background: linear-gradient(160deg, var(--lavender) 0%, var(--pink) 55%, var(--pink-deep) 100%);
  color: var(--white);
  text-shadow: 1px 1px 0 var(--border-dark);
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(14px, 4vw, 20px);
}

.memory-board.size-8 .memory-card-back {
  font-size: clamp(9px, 2vw, 14px);
}

.memory-board.size-16 .memory-card-back {
  font-size: clamp(5px, 1cqi, 9px);
}

.memory-board.size-32 .memory-card-back {
  font-size: clamp(8px, 1.8cqi, 12px);
  text-shadow: none;
}

.memory-card-front {
  background: var(--cream);
  transform: rotateY(180deg);
  border: 1px solid var(--pink-soft);
}

/* Large boards: hide back when flipped instead of 3D rotate */
.memory-board.size-16 .memory-card-front,
.memory-board.size-32 .memory-card-front {
  transform: none;
  opacity: 0;
  pointer-events: none;
}

.memory-board.size-16 .memory-card.is-flipped .memory-card-back,
.memory-board.size-16 .memory-card.is-matched .memory-card-back,
.memory-board.size-32 .memory-card.is-flipped .memory-card-back,
.memory-board.size-32 .memory-card.is-matched .memory-card-back {
  opacity: 0;
  pointer-events: none;
}

.memory-board.size-16 .memory-card.is-flipped .memory-card-front,
.memory-board.size-16 .memory-card.is-matched .memory-card-front,
.memory-board.size-32 .memory-card.is-flipped .memory-card-front,
.memory-board.size-32 .memory-card.is-matched .memory-card-front {
  opacity: 1;
}

.memory-face-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  max-width: 100%;
  padding: 1px 2px;
  border-radius: 3px;
  line-height: 1;
  font-weight: 600;
}

.memory-face-emoji {
  flex-shrink: 0;
}

.memory-face-tag {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.45em;
  letter-spacing: -0.02em;
  opacity: 0.95;
}

.memory-board.size-4 .memory-face-tag,
.memory-board.size-8 .memory-face-tag {
  font-size: 0.38em;
}

.memory-board.size-16 .memory-face-tag,
.memory-board.size-32 .memory-face-tag {
  font-size: 0.55em;
}

.memory-board.size-32 .memory-face-chip {
  flex-direction: column;
  justify-content: center;
  gap: 0;
  padding: 1px 0;
  width: 100%;
  height: 100%;
}

.memory-board.size-32 .memory-face-emoji {
  font-size: 1.05em;
  line-height: 1;
}

.memory-board.size-32 .memory-face-tag {
  display: block;
  font-size: 0.72em;
  letter-spacing: 0;
  line-height: 1;
  margin-top: 1px;
}

.memory-game.is-extreme .memory-difficulty-btns {
  gap: 4px;
}

.memory-game.is-extreme .memory-diff-btn {
  font-size: 6px !important;
  padding: 6px 7px !important;
}

.memory-card.is-matched {
  box-shadow: 2px 2px 0 #6aaa90;
  border-color: #6aaa90;
}

.memory-board.size-8 .memory-card.is-matched,
.memory-board.size-16 .memory-card.is-matched,
.memory-board.size-32 .memory-card.is-matched {
  box-shadow: none;
}

.memory-card.is-matched .memory-card-front {
  background: #eefaf4;
}

.memory-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  align-items: center;
  margin-top: 4px;
}

.memory-actions .btn {
  margin-top: 0;
  text-decoration: none;
  display: inline-block;
}

.memory-back-btn {
  font-size: 8px !important;
}

.memory-win {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(243, 238, 252, 0.82);
  z-index: 5;
  padding: 16px;
}

.memory-win[hidden] {
  display: none !important;
}

.memory-win-inner {
  max-width: 320px;
  width: 100%;
  text-align: center;
  padding: 18px 16px;
  background: var(--bg-window);
  border: 2px solid var(--border);
  box-shadow: 4px 4px 0 var(--shadow);
}

.memory-win-title {
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  margin: 0 0 10px;
  color: var(--text-dark);
}

.memory-win-msg {
  margin: 0 0 14px;
  font-size: 18px;
  color: var(--muted);
}

@media (max-width: 420px) {
  .memory-board.size-4 {
    gap: 6px;
    max-width: 100%;
  }

  .memory-stat {
    min-width: 64px;
    padding: 5px 8px;
  }

  .memory-diff-btn {
    font-size: 6px !important;
    padding: 7px 8px !important;
  }
}


/* Hard: image-only faces (no letter tags) */
.memory-board.size-16 .memory-face-tag,
.memory-board.size-32 .memory-face-tag {
  display: none !important;
}

.memory-face-chip.is-image-only {
  width: 100%;
  height: 100%;
  border-radius: 4px;
  border: 1px solid rgba(155, 77, 138, 0.35);
  box-sizing: border-box;
}

.memory-board.size-16 .memory-face-chip.is-image-only {
  border-radius: 3px;
}

.memory-board.size-32 .memory-face-chip.is-image-only {
  border-radius: 2px;
  border-width: 1px;
}

.memory-board.size-16 .memory-face-emoji {
  font-size: 1.25em;
  line-height: 1;
}

.memory-board.size-32 .memory-face-emoji {
  font-size: 1.2em;
  line-height: 1;
}


.memory-face-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  line-height: 0;
}

.memory-face-icon svg {
  width: 86%;
  height: 86%;
  display: block;
}

.memory-board.size-32 .memory-face-icon svg {
  width: 92%;
  height: 92%;
}


/* Site chrome otherwise clips the last card row + shadows */
.os-body.memory-game {
  overflow: visible;
  padding-bottom: 20px;
}
