.memory-hero { padding-block: clamp(2rem,5vw,4rem) 2rem; }
.memory-hero h1 { font-size: clamp(2.7rem,5vw,4.5rem); }
.memory-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.memory-heading h2 { font: clamp(1.8rem,3vw,2.5rem)/1.2 var(--serif); margin: .5rem 0; }
.memory-heading > a { font-size: .8rem; text-underline-offset: 4px; }
.memory-levels { display: flex; gap: .65rem; margin: 1.4rem 0; padding: .8rem; background: #edf1e5; border: 1px solid #d1dbc5; border-radius: 12px; }
.memory-levels a { flex: 1; display: flex; flex-direction: column; gap: .3rem; padding: .8rem 1rem; border-radius: 8px; background: #fffdf6; color: #38503b; border: 1px solid #ced7c2; text-decoration: none; }
.memory-levels strong { font-size: .95rem; }.memory-levels span { font-size: .7rem; }
.memory-levels a[aria-current=true] { background: #315743; border-color: #315743; color: #fff4d7; box-shadow: 0 3px 0 #193827; }
.memory-stats { display: flex; gap: 1.5rem; align-items: center; }
.memory-stats > div { display: flex; flex-direction: column; text-align: center; min-width: 42px; }
.memory-stats strong { color: #f6d68b; font-size: 1.35rem; font-weight: 750; font-variant-numeric: tabular-nums; line-height: 1.4; }
.memory-stats span { font-size: .62rem; color: #dce7d1; }
.memory-view { position: relative; padding: 1rem 1.25rem 1.5rem; background: radial-gradient(ellipse at 50% 0%, #fffaf0, transparent 70%), #e9eedf; }
.memory-level-label { text-align: center; font-size: .72rem; letter-spacing: .07em; color: #748166; margin: 0 0 1rem; }
.memory-cards { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 12px; width: 100%; max-width: 680px; margin: auto; }
.memory-cards[data-difficulty=hard] { grid-template-columns: repeat(6,minmax(0,1fr)); max-width: 940px; }
.maze-page .memory-card { display: block; position: relative; aspect-ratio: .86; min-width: 0; border: 0; border-radius: 12px; padding: 0; background: transparent; perspective: 700px; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.memory-card-inner { position: absolute; inset: 0; display: block; transform-style: preserve-3d; transition: transform .28s ease; }
.memory-card.is-up .memory-card-inner { transform: rotateY(180deg); }
.memory-card-back, .memory-card-face { position: absolute; inset: 0; border-radius: 11px; backface-visibility: hidden; -webkit-backface-visibility: hidden; overflow: hidden; box-shadow: 0 4px 0 #18372b30, 0 7px 15px #264e3015; }
.memory-card-back { display: flex; flex-direction: column; justify-content: center; align-items: center; gap: .6rem; border: 2px solid #b99e57; color: #eed391; background: radial-gradient(circle at 50% 35%,#4b7151,#234b3b 75%); }
.memory-card-back::before { content: ''; position: absolute; inset: 6px; border: 1px solid #d1b56a66; border-radius: 6px; }
.memory-back-emblem { display: block; width: 82%; padding: .4em 0; border-top: 1px solid #e6cc8166; border-bottom: 1px solid #e6cc8166; text-align: center; text-wrap: balance; font: italic clamp(.75rem,2.3vw,1.7rem)/1.15 var(--serif); }
.memory-back-word { font-size: clamp(.35rem,.7vw,.58rem); font-weight: 750; letter-spacing: .12em; }
.memory-card-face { display: flex; flex-direction: column; background: #fff8df; border: 2px solid #d6c79d; transform: rotateY(180deg); }
.memory-card-art { display: block; width: 100%; aspect-ratio: 1; background-image: url('Book/Memory%20Match/storybook-cards.jpg'); background-size: 400% 300%; background-repeat: no-repeat; }
.memory-card-name { display: flex; flex: 1; align-items: center; justify-content: center; font-size: clamp(.5rem,.85vw,.72rem); line-height: 1.1; color: #42513a; padding: 1px 3px; }
.memory-card.is-matched .memory-card-face { border-color: #76965c; box-shadow: 0 0 0 2px #b0c797; }
.memory-card.is-matched { cursor: default; }
.maze-page .memory-card:hover { background: transparent; }
.memory-card:not(.is-up):hover .memory-card-back { border-color: #f5d887; }
.maze-page .memory-card:focus-visible { outline: 3px solid #bd7d25; outline-offset: 4px; }
.memory-saving-note { font-size: .8rem; color: #6b765f; margin: 1.3rem 0 2.5rem; max-width: 800px; line-height: 1.6; }
.memory-view #fireworks { z-index: 3; }
.memory-view .memory-celebration { position: absolute; z-index: 2; top: 50%; left: 50%; transform: translate(-50%,-50%); margin: 0; width: min(90%,420px); background: #fff9eaf7; border: 2px solid #d1af59; box-shadow: 0 12px 50px #21483150; }
.memory-celebration .eyebrow { font-size: .65rem; }.memory-celebration h3 { font-size: clamp(1.8rem,4vw,2.7rem); }
.memory-page .leaderboard-table th:first-child { width: 60px; }.memory-page .leaderboard-table th:nth-child(3), .memory-page .leaderboard-table th:last-child { width: 75px; text-align: right; }
.memory-page .leaderboard-table td:nth-child(3) { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.memory-play.is-expanded .memory-view { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; justify-content: center; }
.memory-play.is-expanded .memory-level-label { margin-bottom: .5rem; flex-shrink: 0; }
.memory-play.is-expanded .memory-cards { margin: 0 auto; flex-shrink: 0; }
.memory-play.is-expanded #game-status { flex-shrink: 0; }
@media(max-width:650px) {
  .memory-levels { padding: .6rem; gap: .45rem; }.memory-levels a { padding: .65rem; }.memory-levels span { font-size: .6rem; }
  .memory-view { padding: .8rem; }.memory-cards { gap: 8px; }.memory-cards[data-difficulty=hard] { grid-template-columns: repeat(4,minmax(0,1fr)); }
  .memory-card-back, .memory-card-face, .maze-page .memory-card { border-radius: 8px; }.memory-card-back { gap: .35rem; }
  .memory-stats { gap: 1rem; margin-left: auto; }.memory-stats strong { font-size: 1.1rem; }
  .memory-page .leaderboard-table th, .memory-page .leaderboard-table td { padding-inline: .65rem; }.memory-page .leaderboard-table th:first-child { width: 45px; }.memory-page .leaderboard-table th:nth-child(3), .memory-page .leaderboard-table th:last-child { width: 57px; }
  .memory-celebration p { font-size: .85rem; }
}
@media(orientation:landscape) and (max-height:600px) { .memory-play.is-expanded { display: flex; }.memory-play.is-expanded .maze-gamebar { flex-wrap: nowrap; padding-block: .4rem; }.memory-play.is-expanded .memory-view { padding: .5rem; }.memory-play.is-expanded .memory-level-label { display: none; } }
@media(prefers-reduced-motion:reduce) { .memory-card-inner { transition: none; } }

.memory-page #player-best { font-size: clamp(1.2rem,2vw,1.7rem); line-height: 1.8; }

/* Keep short leaderboard labels intact at every screen size. */
.memory-page .leaderboard-table th { white-space: nowrap; overflow-wrap: normal; word-break: normal; }
.memory-page .leaderboard-table th:first-child { width: 64px; }
.memory-page .leaderboard-table th:nth-child(3), .memory-page .leaderboard-table th:last-child { width: 80px; }
@media (max-width: 650px) {
  .memory-page .leaderboard-table th, .memory-page .leaderboard-table td { padding-inline: .5rem; }
  .memory-page .leaderboard-table th:first-child { width: 52px; }
  .memory-page .leaderboard-table th:nth-child(3), .memory-page .leaderboard-table th:last-child { width: 64px; }
}