/* ── Game polish: intros, study picker, end screens, Dino v2, Match/Memory touches ── */

/* Shared button row on end screens */
.game-btn-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 6px; }
.game-btn-row .restart-btn, .game-btn-row .leaderboard-btn, .game-btn-row .dino-start-btn { margin: 0; }
.score-end .leaderboard-btn { margin-top: 0; }

/* ── Intro card + study picker ── */
.game-intro {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: 18px 12px 8px; max-width: 520px; margin: 0 auto;
  animation: fadeUp 0.35s var(--ease-out);
}
.game-intro-desc { font-family: var(--font-body); font-size: 14px; color: var(--text-secondary); line-height: 1.6; margin-bottom: 14px; }

.study-picker {
  width: 100%; max-width: 480px; margin: 6px auto 16px;
  padding: 14px; border-radius: 16px;
  background: var(--card-bg); border: 1px solid var(--card-border);
}
.study-picker-title {
  font-family: var(--font-mono); font-size: 11px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-secondary); margin-bottom: 10px;
}
.study-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.study-chip {
  font-family: var(--font-mono); font-size: 12px; font-weight: 600;
  padding: 8px 12px; border-radius: 999px; cursor: pointer;
  border: 1.5px solid var(--card-border); background: var(--body-bg); color: var(--text);
  box-shadow: 0 2px 0 var(--card-border);
  transition: transform 0.14s var(--ease-spring), background 0.18s, color 0.18s, border-color 0.18s, box-shadow 0.14s;
}
.study-chip:hover { transform: translateY(-1px); border-color: var(--blue); }
.study-chip:active { transform: translateY(2px); box-shadow: none; }
.study-chip.on {
  background: var(--blue); border-color: var(--blue); color: #fff;
  box-shadow: 0 2px 0 var(--blue-dark);
  animation: chipPop 0.3s var(--ease-spring);
}
.study-chip.all.on { background: linear-gradient(135deg, var(--blue), var(--purple)); }
@keyframes chipPop { 50% { transform: scale(1.08); } }

/* Typed answers (spelling) inside Dino / Tower / Speedrun / Chess */
.q-spell-row { display: flex; gap: 8px; width: 100%; }
.q-spell-input {
  flex: 1; min-width: 0; padding: 12px 14px; border-radius: 12px;
  border: 1.5px solid var(--card-border); background: var(--card-bg);
  font-family: var(--font-mono); font-size: 15px; color: var(--text); outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.q-spell-input:focus { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(26, 77, 232, 0.12); }
.q-spell-row .next-btn { width: auto; margin: 0; padding: 12px 18px; }
.q-spell-row.correct .q-spell-input { border-color: #22c55e; background: var(--green-bg); color: var(--green-text); }
.q-spell-row.wrong .q-spell-input { border-color: #ef4444; background: var(--red-bg); color: var(--red-text); animation: fxWrong 0.42s; }

/* ── End screens ── */
.end-stars { display: flex; justify-content: center; gap: 6px; margin: -4px 0 6px; }
.end-star {
  font-size: 34px; color: var(--card-border); line-height: 1;
  animation: starIn 0.5s var(--ease-spring) both;
}
.end-star.on { color: #fbbf24; text-shadow: 0 2px 12px rgba(251, 191, 36, 0.55); }
@keyframes starIn { from { transform: scale(0) rotate(-90deg); opacity: 0; } to { transform: none; opacity: 1; } }

.streak-badge {
  display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px;
  background: linear-gradient(135deg, #f97316, #ef4444); color: #fff;
  font-size: 11px; font-weight: 700; animation: chipPop 0.35s var(--ease-spring);
}
.sr-streak {
  font-family: var(--font-mono); font-size: 12px; font-weight: 700; color: #f97316;
  margin-bottom: 4px; animation: chipPop 0.3s var(--ease-spring);
}
.question-card { position: relative; overflow: hidden; }
.question-card::after {
  content: ''; position: absolute; inset: 0 auto 0 0; width: 4px;
  background: linear-gradient(180deg, var(--blue), var(--purple));
}

/* ── Match ── */
.match-tile { box-shadow: 0 3px 0 var(--card-border); }
.match-tile.word { border-left: 4px solid var(--blue); }
.match-tile.selected { box-shadow: 0 3px 0 var(--blue-dark), 0 8px 24px rgba(26, 77, 232, 0.35); }
.match-tile.matched { animation: matchPop 0.45s var(--ease-spring) forwards !important; }
@keyframes matchPop {
  0% { transform: scale(1); opacity: 1; }
  40% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(0.94); opacity: 0.35; }
}


/* ── Speedrun ── */
.sr-word-long { font-family: var(--font-body) !important; font-weight: 600 !important; }

/* ── Dino (Chrome style) ── */
.dino-v2 { min-height: 0; gap: 8px; }
.dino-stage { position: relative; width: 100%; }
.dino-v2 .dino-canvas {
  width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--card-border);
  image-rendering: pixelated; cursor: pointer; display: block;
}
.dino-v2 .dino-quiz-overlay { position: absolute; inset: -8px -4px; min-height: 260px; align-items: flex-start; padding-top: 8px; border-radius: 14px; }
.dino-v2 .dino-gameover { padding: 12px 8px 4px; gap: 10px; }
.dino-v2 .dino-how-grid { margin: 0 auto 4px; }
.dino-v2 .dino-controls { margin-top: 0; }
@media (hover: hover) and (pointer: fine) { .dino-v2 .dino-controls { display: none !important; } }
.dino-quiz-word.long { font-family: var(--font-body); font-size: 17px; font-weight: 600; line-height: 1.4; }
.dino-countdown {
  font-family: var(--font-mono); font-weight: 900; font-size: 64px; color: var(--blue); line-height: 1.1;
  animation: chipPop 0.8s var(--ease-spring) infinite;
}
.dino-beat-msg { font-family: var(--font-body); font-size: 14px; text-align: center; }
.dino-ctrl-btn { box-shadow: 0 4px 0 var(--card-border); transition: transform 0.08s, box-shadow 0.08s; touch-action: none; }
.dino-ctrl-btn:active { transform: translateY(4px) !important; box-shadow: none; }

/* Tower question box: a bit more presence */
.tower-question-box { box-shadow: var(--shadow-lg); border-radius: 16px; animation: modalSlideUp 0.3s var(--ease-spring); }

/* ── Chess ── */
/* Board + piece colours come from the theme (css/themes.css sets them per theme).
   These defaults are the classic wooden board used by the Light theme.
   ("html", not ":root", so any [data-theme] block overrides them.) */
html {
  --board-light: #f0d9b5; --board-dark: #b58863; --board-frame: #6b4a2b;
  --board-last-light: #f6eb72; --board-last-dark: #dcc34b; --board-select: #1a4de8;
  --board-coord: rgba(60, 40, 20, 0.55);
  --piece-white: #ffffff; --piece-white-edge: #000000; --piece-white-glow: 0 0 0 transparent;
  --piece-black: #1f1f1f; --piece-black-edge: rgba(255, 255, 255, 0.6); --piece-black-glow: 0 0 0 transparent;
}
.chess-record { font-family: var(--font-mono); font-size: 12px; color: var(--text-secondary); margin-bottom: 8px; }
.chess-wrap { max-width: 500px; margin: 0 auto; }
.chess-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; gap: 8px; }
.chess-status {
  font-family: var(--font-mono); font-size: 13px; font-weight: 700; padding: 6px 12px; border-radius: 999px;
  background: var(--card-bg); border: 1px solid var(--card-border); transition: background 0.2s, color 0.2s;
}
.chess-status.thinking { animation: thinkPulse 1s ease-in-out infinite; }
.chess-status.danger { background: var(--red-bg); color: var(--red-text); border-color: #ef4444; }
.chess-status.good { background: var(--green-bg); color: var(--green-text); border-color: #22c55e; }
@keyframes thinkPulse { 50% { opacity: 0.55; } }
.chess-stats { font-family: var(--font-mono); font-size: 13px; color: var(--text-secondary); }
.chess-captured { min-height: 26px; font-size: 20px; line-height: 26px; letter-spacing: -2px; padding: 0 2px; }
.chess-board {
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); width: 100%; aspect-ratio: 1;
  border-radius: 10px; overflow: hidden; box-shadow: 0 6px 0 var(--board-frame), 0 14px 30px rgba(0, 0, 0, 0.25);
  border: 3px solid var(--board-frame); user-select: none;
}
.chess-sq {
  position: relative; border: none; padding: 0; margin: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  min-width: 0; min-height: 0; overflow: hidden;
  font-size: clamp(26px, 8.6vw, 46px); line-height: 1;
}
.chess-sq.light { background: var(--board-light); }
.chess-sq.dark { background: var(--board-dark); }
.chess-sq.last.light { background: var(--board-last-light); }
.chess-sq.last.dark { background: var(--board-last-dark); }
.chess-sq.sel { box-shadow: inset 0 0 0 4px var(--board-select); }
.chess-sq.check { background: radial-gradient(circle, #ff3b3b 0%, #e11d1d 45%, transparent 75%) !important; }
.chess-sq.target::after {
  content: ''; width: 28%; height: 28%; border-radius: 50%; background: rgba(20, 30, 60, 0.32);
  position: absolute; animation: chipPop 0.25s var(--ease-spring);
}
.chess-sq.capture::after {
  content: ''; position: absolute; inset: 6%; border-radius: 50%; border: 5px solid rgba(20, 30, 60, 0.32);
}
.chess-sq:hover:not(.sel) { filter: brightness(1.07); }
.chess-coord {
  position: absolute; font-family: var(--font-mono); font-size: 10px; font-weight: 700;
  color: var(--board-coord); pointer-events: none; line-height: 1;
}
.chess-coord.rank { top: 3px; left: 3px; }
.chess-coord.file { bottom: 2px; right: 3px; }
.chess-piece {
  font-family: 'Segoe UI Symbol', 'Apple Symbols', 'DejaVu Sans', 'Noto Sans Symbols 2', sans-serif;
  position: relative; z-index: 1; transition: transform 0.15s var(--ease-spring);
}
.chess-piece.white { color: var(--piece-white); text-shadow: 0 0 1px var(--piece-white-edge), 0 0 1px var(--piece-white-edge), 1px 1px 0 var(--piece-white-edge), -1px -1px 0 var(--piece-white-edge), 1px -1px 0 var(--piece-white-edge), -1px 1px 0 var(--piece-white-edge), 0 3px 4px rgba(0, 0, 0, 0.35), var(--piece-white-glow); }
.chess-piece.black { color: var(--piece-black); text-shadow: 0 0 1px var(--piece-black-edge), 1px 1px 0 var(--piece-black-edge), -1px -1px 0 var(--piece-black-edge), 0 3px 4px rgba(0, 0, 0, 0.35), var(--piece-black-glow); }
.chess-sq.sel .chess-piece { transform: translateY(-4px) scale(1.08); }
.chess-piece.landed { animation: pieceLand 0.3s var(--ease-spring); }
@keyframes pieceLand { 0% { transform: scale(1.25); } 100% { transform: none; } }
.chess-captured .chess-piece { font-size: 20px; }
.chess-q {
  margin-top: 14px; padding: 16px; border-radius: 16px; background: var(--card-bg);
  border: 1px solid var(--card-border); box-shadow: var(--shadow); animation: modalSlideUp 0.3s var(--ease-spring);
}
.chess-q-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.chess-q-head .dino-quiz-badge { margin-bottom: 0; }
.chess-q-move { font-family: var(--font-mono); font-size: 11px; color: var(--text-secondary); }

/* Review controls + move list */
.chess-board-wrap { position: relative; }
.chess-board.reviewing { filter: saturate(0.75); }
.chess-review-banner {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 3;
  background: rgba(15, 15, 25, 0.88); color: #fff; padding: 7px 12px; border-radius: 999px;
  font-family: var(--font-mono); font-size: 12px; white-space: nowrap; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  animation: chipPop 0.3s var(--ease-spring);
}
.chess-review-banner button {
  margin-left: 6px; border: none; border-radius: 999px; padding: 3px 10px; cursor: pointer;
  background: #fbbf24; color: #1a1714; font-family: var(--font-mono); font-size: 11px; font-weight: 700;
}
.chess-nav { display: flex; gap: 6px; justify-content: center; margin: 6px 0; flex-wrap: wrap; }
.chess-nav-btn {
  min-width: 44px; padding: 8px 12px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--card-border); background: var(--card-bg); color: var(--text);
  font-family: var(--font-mono); font-size: 14px; font-weight: 700;
  box-shadow: 0 3px 0 var(--card-border); transition: transform 0.1s, box-shadow 0.1s, opacity 0.2s;
}
.chess-nav-btn:active:not(:disabled) { transform: translateY(3px); box-shadow: none; }
.chess-nav-btn:disabled { opacity: 0.4; cursor: default; }
.chess-nav-btn.undo { background: var(--blue); border-color: var(--blue); color: #fff; box-shadow: 0 3px 0 var(--blue-dark); }
.chess-moves {
  display: flex; flex-wrap: wrap; gap: 4px 10px; max-height: 92px; overflow-y: auto;
  padding: 8px 10px; border-radius: 12px; background: var(--card-bg); border: 1px solid var(--card-border);
  font-family: var(--font-mono); font-size: 13px;
}
.chess-move-pair { display: inline-flex; align-items: center; gap: 2px; }
.chess-move-num { color: var(--text-secondary); margin-right: 2px; }
.chess-ply {
  border: none; background: transparent; color: var(--text); cursor: pointer;
  font-family: var(--font-mono); font-size: 13px; font-weight: 600; padding: 2px 5px; border-radius: 6px;
}
.chess-ply:hover { background: var(--card-border); }
.chess-ply.current { background: var(--blue); color: #fff; }
.chess-ply.pass { color: var(--text-secondary); font-weight: 400; }
.chess-move-empty { color: var(--text-secondary); font-size: 12px; }

/* Chess start screen: computer / friend cards */
.chess-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; width: 100%; max-width: 760px; margin-top: 4px; }
@media (max-width: 680px) { .chess-modes { grid-template-columns: 1fr; } }
.chess-modes.single { grid-template-columns: 1fr; max-width: 420px; }
.chess-mode-card {
  display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center;
  padding: 18px 16px; border-radius: 18px; background: var(--card-bg); border: 1px solid var(--card-border);
  box-shadow: 0 4px 0 var(--card-border);
}
.chess-mode-card h3 { font-family: var(--font-serif); font-size: 20px; margin: 0; }
.chess-mode-card p { font-family: var(--font-body); font-size: 13px; color: var(--text-secondary); line-height: 1.5; margin: 0; }
.chess-mode-card .name-input { width: 100%; }
.chess-mode-card .name-submit-row { width: 100%; }
.chess-mode-label { font-family: var(--font-mono); font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-secondary); }
.chess-color-pick { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.chess-or { font-family: var(--font-mono); font-size: 11px; color: var(--text-secondary); }

/* Player bars above / below the board */
.chess-player { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 30px; padding: 2px 2px; }
.chess-player-name { display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-mono); font-size: 12px; font-weight: 700; }
.chess-dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--text-secondary); }
.chess-dot.w { background: #fff; }
.chess-dot.b { background: #1f1f1f; }
.chess-player .chess-captured { min-height: 0; font-size: 17px; line-height: 1; }

/* Waiting for a friend */
.duel-share { text-align: center; display: flex; flex-direction: column; gap: 10px; }
.duel-share-title { font-family: var(--font-serif); font-size: 18px; font-weight: 700; }
.duel-code { display: flex; justify-content: center; gap: 6px; }
.duel-code span {
  font-family: var(--font-mono); font-weight: 900; font-size: clamp(26px, 7vw, 40px); padding: 2px 10px;
  border-radius: 10px; background: var(--blue); color: #fff; box-shadow: 0 4px 0 var(--blue-dark);
  animation: chipPop 0.4s var(--ease-spring) both;
}
.duel-share-hint { font-family: var(--font-mono); font-size: 12px; color: var(--text-secondary); }
.duel-share .live-dots span { background: var(--blue); }

/* POS questions show the meaning under the word (a word can be a different POS in each sense) */
.q-pos-def {
  font-family: var(--font-body); font-size: 14px; font-weight: 500; line-height: 1.45; color: var(--text-secondary);
  margin: -2px auto 12px; max-width: 46ch; text-align: center;
}
.sr-card .q-pos-def { text-align: left; margin: -10px 0 16px; }

/* Dino: only the intro until "Start Running" */
.dino-idle .dino-stage, .dino-idle .dino-controls { display: none !important; }

/* ── Chess: layout ──
   Wide screens: question / hints in a column left of the board. Small screens: the question
   covers the board (js/games/chess.js moves the panel), and the result goes under the moves. */
#screen-main .tab-content.tab-wide { max-width: 980px; }
.chess-q[hidden], .chess-end[hidden], .chess-hint[hidden] { display: none !important; }
.chess-side { display: none; }
.chess-main { min-width: 0; }
@media (min-width: 940px) {
  .chess-wrap { max-width: none; display: grid; grid-template-columns: 300px minmax(0, 540px); gap: 28px; justify-content: center; align-items: start; }
  .chess-side { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 16px; padding-top: 42px; }
  .chess-side .chess-q, .chess-side .chess-end { margin-top: 0; }
}
.chess-hint, .chess-end {
  padding: 16px; border-radius: 16px; background: var(--card-bg); border: 1px solid var(--card-border);
  font-family: var(--font-body); font-size: 14px; line-height: 1.5; color: var(--text-secondary);
}
.chess-end { margin-top: 14px; animation: modalSlideUp 0.3s var(--ease-spring); }
.chess-hint p { margin: 0 0 8px; } .chess-hint p:last-child { margin-bottom: 0; }
.chess-hint strong { color: var(--text); }
.chess-hint-title { font-family: var(--font-mono); font-size: 11px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--blue); margin-bottom: 8px; }

/* Question on top of the board (small screens) */
.chess-q.on-board {
  position: absolute; inset: 0; z-index: 6; margin: 0; padding: 14px; border-radius: 10px;
  display: flex; flex-direction: column; justify-content: center; overflow-y: auto;
  background: color-mix(in srgb, var(--card-bg) 93%, transparent); backdrop-filter: blur(4px);
  animation: boardQIn 0.28s var(--ease-out);
}
@keyframes boardQIn { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: none; } }
.chess-q.on-board .dino-quiz-word { font-size: 22px; margin-bottom: 4px; }
.chess-q.on-board .dino-quiz-word.long { font-size: 15px; }
.chess-q.on-board .dino-quiz-prompt { margin-bottom: 8px; }
.chess-q.on-board .choice-btn { padding: 9px 12px; font-size: 13px; margin-bottom: 6px; }
.chess-q.on-board .q-pos-def { margin-bottom: 8px; }

/* ── Chess: moving pieces ── */
.chess-anim-layer { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
.chess-float { position: absolute; display: flex; align-items: center; justify-content: center; line-height: 1; will-change: transform; }
.chess-float.moving { transition: transform 0.26s cubic-bezier(0.25, 0.8, 0.25, 1); }
.chess-float.dragging { z-index: 7; filter: drop-shadow(0 10px 10px rgba(0, 0, 0, 0.35)); }
.chess-float.taken { animation: pieceTaken 0.4s ease-out forwards; }
@keyframes pieceTaken { to { transform: scale(0.35) rotate(-25deg); opacity: 0; } }
.chess-sq .chess-piece { touch-action: none; } /* dragging a piece doesn't scroll the page */
.chess-piece.lifted { opacity: 0.25; transform: none !important; }
.chess-sq.drag-over { box-shadow: inset 0 0 0 4px var(--board-select); filter: brightness(1.1); }
.chess-sq.pending { box-shadow: inset 0 0 0 4px var(--board-select); animation: pendingPulse 1.1s ease-in-out infinite; }
@keyframes pendingPulse { 50% { filter: brightness(1.15); } }
.chess-piece.denied { animation: pieceDenied 0.45s ease-in-out; }
@keyframes pieceDenied { 20%, 60% { transform: translateX(-5px) rotate(-6deg); } 40%, 80% { transform: translateX(5px) rotate(6deg); } }
@media (hover: hover) { .chess-sq:hover .chess-piece { transform: translateY(-2px); } }
@media (prefers-reduced-motion: reduce) { .chess-sq.pending { animation: none; } }


/* ── Memory (clean look) ── */
.mem-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 4px 0 10px; }
.mem-stats.end { max-width: 420px; margin: 0 auto 14px; }
.mem-stat { padding: 9px 12px; border-radius: 14px; background: var(--card-bg); border: 1px solid var(--card-border); text-align: left; }
.mem-stat span { display: block; font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-secondary); }
.mem-stat strong { font-family: var(--font-mono); font-size: 18px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.mem-progress { height: 4px; border-radius: 999px; background: var(--card-border); overflow: hidden; margin-bottom: 14px; }
.mem-progress-fill { height: 100%; width: 0; border-radius: 999px; background: var(--blue); transition: width 0.5s var(--ease-out); }


/* Chess: challenge a friend's account */
.chess-friends { display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow-y: auto; }
.chess-friend { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 10px; border-radius: 12px; border: 1px solid var(--card-border); background: var(--bg-secondary, transparent); }
.chess-friend-name { flex: 1; min-width: 0; font-weight: 700; display: flex; flex-direction: column; overflow: hidden; }
.chess-friend-name small { font-family: var(--font-mono); font-size: 10px; font-weight: 500; color: var(--text-secondary); }
.chess-friend-btn { width: auto !important; margin: 0 !important; padding: 8px 14px !important; font-size: 12px !important; }
.chess-friends-empty { font-size: 12px; color: var(--text-secondary); margin: 0; }

/* After a false true/false statement: the correct answer */
.answer-note {
  display: flex; align-items: flex-start; gap: 10px; flex-basis: 100%; grid-column: 1 / -1; box-sizing: border-box; width: 100%;
  margin-top: 10px; padding: 12px 14px; border-radius: 14px; text-align: left; font-size: 15px; line-height: 1.45;
  background: rgba(22, 163, 74, 0.12); border: 1px solid rgba(22, 163, 74, 0.35); color: var(--text, #1c1430);
  animation: pageIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.answer-note .ico { width: 20px; height: 20px; flex: none; color: #16a34a; margin-top: 1px; }
.answer-note strong { color: #16a34a; }
.dino-quiz .answer-note, .tower-q .answer-note { font-size: 14px; }

/* ── Memory (js/games/memory.js) ──
   The flip is a flat squeeze: the back narrows to nothing, then the front widens. No 3D, and nothing
   on a card is faded or bounced, so it stays smooth and never flickers (Safari, slow laptops). */
.mem-board {
  --mem-cols: 3; --mem-gap: 10px; --mem-h: 136px;
  display: flex; flex-wrap: wrap; justify-content: center; gap: var(--mem-gap);
}
@media (min-width: 640px) { .mem-board { --mem-cols: 4; --mem-gap: 12px; --mem-h: 150px; } }
@media (max-width: 380px) { .mem-board { --mem-gap: 8px; --mem-h: 140px; } }
.mem-card {
  position: relative; flex: 0 0 calc((100% - var(--mem-gap) * (var(--mem-cols) - 1)) / var(--mem-cols));
  height: var(--mem-h); padding: 0; margin: 0; border: 0; background: none; color: inherit; font: inherit;
  cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; border-radius: 16px;
}
.mem-card:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }
.mem-face {
  position: absolute; inset: 0; border-radius: 16px; box-sizing: border-box; display: flex; flex-direction: column;
  align-items: center; justify-content: center; overflow: hidden;
  transition: transform 0.13s ease-in, background-color 0.25s, border-color 0.25s, box-shadow 0.25s;
}
/* face down */
.mem-back {
  transform: scaleX(1); transition-delay: 0.13s, 0s, 0s, 0s; transition-timing-function: ease-out;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.16) 1px, transparent 1.6px) 0 0 / 12px 12px, var(--blue);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18);
}
.mem-back-mark { width: 30px; height: 30px; color: rgba(255, 255, 255, 0.6); }
.mem-front {
  transform: scaleX(0); transition-delay: 0s;
  padding: 24px 8px 10px; background: var(--card-bg); border: 1.5px solid var(--card-border); box-shadow: inset 0 -3px 0 var(--card-border);
}
/* face up */
.mem-card.up .mem-back { transform: scaleX(0); transition-delay: 0s, 0s, 0s, 0s; transition-timing-function: ease-in; }
.mem-card.up .mem-front { transform: scaleX(1); transition-delay: 0.13s, 0s, 0s, 0s; transition-timing-function: ease-out; }
@media (hover: hover) {
  .mem-card:not(.up):hover .mem-back { background-color: color-mix(in srgb, var(--blue) 86%, #fff); }
  .mem-card:not(.up):hover .mem-back-mark { color: rgba(255, 255, 255, 0.9); }
}
.mem-kind { position: absolute; top: 8px; left: 10px; font-family: var(--font-mono); font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--blue); }
.mem-text { display: block; width: 100%; color: var(--text); text-align: center; line-height: 1.3; overflow-wrap: normal; word-break: normal; }
.mem-text.wrap-any { overflow-wrap: anywhere; }
.is-word .mem-text { font-family: var(--font-serif); font-weight: 700; line-height: 1.15; }
.is-def .mem-text { font-family: var(--font-body); }
.mem-pos { font-family: var(--font-mono); font-size: 0.6em; font-weight: 400; font-style: normal; color: var(--text-secondary); white-space: nowrap; }
.mem-check { position: absolute; top: 7px; right: 8px; width: 20px; height: 20px; border-radius: 50%; display: none; align-items: center; justify-content: center; background: #16a34a; color: #fff; }
.mem-check .ico { width: 13px; height: 13px; stroke-width: 3; }
/* a pair found */
.mem-card.done { cursor: default; }
.mem-card.done .mem-front { background: color-mix(in srgb, #16a34a 11%, var(--card-bg)); border-color: #16a34a; box-shadow: inset 0 -3px 0 #16a34a; animation: memFound 0.6s ease-out; }
.mem-card.done .mem-check { display: flex; }
.mem-card.done .mem-kind { color: #16a34a; }
@keyframes memFound { 0% { box-shadow: inset 0 -3px 0 #16a34a, 0 0 0 0 rgba(22, 163, 74, 0.55); } 100% { box-shadow: inset 0 -3px 0 #16a34a, 0 0 0 12px rgba(22, 163, 74, 0); } }
/* not a pair */
.mem-card.miss .mem-front { border-color: #ef4444; box-shadow: inset 0 -3px 0 #ef4444; }
.mem-card.miss { animation: memNope 0.32s ease-in-out; }
@keyframes memNope { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.mem-tip { margin: 14px 0 0; text-align: center; font-family: var(--font-mono); font-size: 12px; color: var(--text-secondary); }
@media (prefers-reduced-motion: reduce) {
  .mem-face { transition: none !important; }
  .mem-card.miss, .mem-card.done .mem-front { animation: none; }
}
