.memory-page {
  min-height: 100dvh;
  background: radial-gradient(ellipse at 4% 12%, #e6f6ff, transparent 42%),
    radial-gradient(ellipse at 98% 50%, #f5eaff, transparent 42%), #f9fcff;
}
.memory-main { padding: 23px 0 28px; }
.memory-intro {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 17px;
}
.memory-intro h1 { margin: 2px 0 5px; font-size: clamp(2.35rem, 5.2vw, 3.9rem); line-height: 1.03; letter-spacing: -.065em; }
.memory-lead { color: #4b526b; font-size: .94rem; }
.memory-tools { display: flex; align-items: center; gap: 7px; flex: none; }
.memory-soft, .memory-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 7px 12px;
  border: 1px solid #d9cbef;
  border-radius: 10px;
  color: #4f3285;
  background: #f7f0ff;
  font-size: .82rem;
  font-weight: 800;
  white-space: nowrap;
}
.memory-soft:hover { background: #eee1fb; }
.memory-soft .icon { width: 18px; height: 18px; }
.help-mark {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  color: #fff;
  background: #6b49ad;
}
.sound-off, .sound-control[aria-pressed="true"] .sound-waves { display: none; }
.sound-control[aria-pressed="true"] .sound-off { display: block; }
.shrink-icon, .memory-layout:is(:fullscreen, .is-expanded) .expand-icon { display: none; }
.memory-layout:is(:fullscreen, .is-expanded) .shrink-icon { display: block; }
.memory-primary { border-color: #ccdf8e; background: #e8ffa8; color: #293716; }
.memory-primary:hover { background: #f0ffcb; }
.memory-layout {
  display: grid;
  grid-template-columns: clamp(221px, 23vw, 268px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.club-panel, .memory-cabinet {
  min-width: 0;
  border: 1px solid #d8e4ed;
  border-radius: 21px;
  background: #fff;
  box-shadow: 0 8px 25px #446a9212;
}
.club-panel { align-self: start; padding: 13px; }
.club-guide {
  position: relative;
  display: grid;
  align-items: center;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 6px;
  min-height: 84px;
  padding: 5px 8px 5px 0;
  overflow: hidden;
  border: 1px solid #e4d6f7;
  border-radius: 14px;
  background: linear-gradient(120deg, #efe3ff, #ffe8ee 70%, #fff3d4);
  color: #432962;
}
.club-characters { position: relative; align-self: stretch; }
.club-characters img { position: absolute; bottom: 0; max-width: none; height: auto; filter: drop-shadow(0 3px 3px #664b691c); }
.club-characters .club-maya { width: auto; height: 100%; max-height: 74px; right: -1px; }
.club-paxa { width: 57px; left: 1px; }
.club-guide .eyebrow { font-size: .61rem; }
.club-guide h2 { font-size: 1.13rem; line-height: 1.14; letter-spacing: -.035em; }
.memory-field { display: grid; gap: 4px; min-width: 0; margin: 11px 0; }
.memory-field label, label.memory-field, .player-settings legend, .board-dimensions legend { color: #4e386b; font-size: .76rem; font-weight: 800; }
.player-settings, .board-dimensions { min-inline-size: 0; margin: 10px 0; padding: 0; border: 0; }
.player-settings legend, .board-dimensions legend { margin-bottom: 4px; padding: 0; }
.dimension-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.dimension-controls .memory-field { margin: 0; }
#dimension-note { margin-top: 4px; color: #5e5471; font-size: .72rem; }
.player-options { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.player-options label { position: relative; cursor: pointer; }
.player-options input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.player-options span {
  display: grid;
  place-items: center;
  min-height: 44px;
  padding: 4px;
  border: 1px solid #ded3ef;
  border-radius: 9px;
  background: #faf6ff;
  color: #4e386b;
  font-size: .78rem;
  font-weight: 800;
}
.player-options :checked + span { border-color: #9477c6; background: #efe4ff; color: #3c265f; }
.player-options :focus-visible + span { outline: 3px solid #7651cc; outline-offset: 2px; }
.memory-field select {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 5px 8px;
  border: 1px solid #ded3ef;
  border-radius: 9px;
  background: #faf6ff;
  color: #3c2954;
  font: 750 .82rem Manrope, system-ui, sans-serif;
}
#round-settings .memory-primary { width: 100%; }
.pending-note { margin-top: 7px; color: #654719; font-size: .74rem; }
.setup-rule { margin: 8px 0; color: #4c556f; font-size: .75rem; }
.club-tip { margin-top: 12px; padding: 9px 10px; border-radius: 10px; background: #edf7ff; color: #325272; font-size: .81rem; }
.club-tip p { margin-top: 2px; font-size: .78rem; }
.memory-cabinet {
  display: grid;
  min-width: 0;
  padding: 13px;
  background: linear-gradient(142deg, #fff, #f6fbff 64%, #f7f1ff);
}
.board-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.board-label { color: #5c458e; font-size: .68rem; }
.board-top h2 { margin-top: 2px; font-size: clamp(1.18rem, 2.7vw, 1.9rem); line-height: 1.1; letter-spacing: -.05em; }
.memory-stats { display: flex; align-items: stretch; gap: 6px; margin: 0; text-align: center; }
.memory-stats div { flex: 1; min-width: 74px; padding: 5px 9px; border: 1px solid #d5e7f4; border-radius: 10px; background: #edf7ff; }
.memory-stats .matched-stat { border-color: #c6e3d7; background: #e9f8f1; }
.memory-stats .best-stat { min-width: 94px; border-color: #ecd7a8; background: #fff5df; }
.memory-stats dt { color: #465770; font-size: .67rem; font-weight: 800; }
.memory-stats dd { margin: 0; color: #273b57; font-size: 1.14rem; font-weight: 800; line-height: 1.25; font-variant-numeric: tabular-nums; }
.memory-stats .heart-stat { background: #fff0f1; border-color: #edc7cd; }
.heart-stat dd { color: #8b3041; }
.memory-stats .player-a { background: #fff2dd; border-color: #ebd2a9; }
.memory-stats .player-b { background: #e8f4ff; border-color: #bedcf3; }
.memory-stats .player-stat { display: flex; align-items: center; gap: 7px; min-width: 99px; text-align: left; }
.player-stat dt { display: flex; align-items: center; gap: 4px; flex: 1; white-space: nowrap; }
.player-stat dt img { width: 24px; height: 32px; object-fit: contain; }
.player-stat dt small { display: block; font-size: .61rem; font-weight: 750; line-height: 1.15; }
.player-a dd { color: #784b22; }
.player-b dd { color: #255990; }
.memory-stats [data-low="true"] dd { color: #9b3342; }
.memory-stats .player-a[data-active="true"] { border-color: #a97741; box-shadow: inset 0 -2px #b98149; }
.memory-stats .player-b[data-active="true"] { border-color: #386b9b; box-shadow: inset 0 -2px #4a80b1; }
.turn-tag {
  display: inline-block;
  margin-top: 5px;
  padding: 2px 9px;
  border-radius: 99px;
  background: #f1eaff;
  color: #5c458e;
  font-size: .73rem;
  font-weight: 800;
}
.turn-tag[data-player="a"] { background: #fff2dd; color: #784b22; }
.turn-tag[data-player="b"] { background: #e8f4ff; color: #255990; }
.memory-progress { height: 6px; margin: 10px 0; overflow: hidden; border-radius: 99px; background: #e4e9f3; }
.memory-progress > div { width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #55b5a3, #a0cf6d); transition: width .22s ease; }
.board-shell {
  container-type: inline-size;
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: clamp(6px, 1.1vw, 13px);
  border: 1px solid #dfd6f0;
  border-radius: 15px;
  background: radial-gradient(circle at 20% 17%, #f9edff, transparent 56%),
    radial-gradient(circle at 91% 86%, #e8fbf0, transparent 57%), #edf3ff;
}
.memory-board {
  --gap: clamp(5px, 1cqw, 10px);
  --row-min: clamp(32px, calc(103px - 9px * var(--density, 4)), 86px);
  --row-max: clamp(61px, calc(208px - 18.5px * var(--density, 4)), 176px);
  --cell-width: calc((100cqw - (var(--columns, 4) - 1) * var(--gap)) / var(--columns, 4));
  --cell-height: clamp(var(--row-min, 54px), calc(var(--cell-width) * var(--row-ratio, .66)), var(--row-max, 110px));
  display: grid;
  grid-template-columns: repeat(var(--columns, 4), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows, 4), var(--cell-height));
  gap: var(--gap);
  width: 100%;
}
.memory-board[data-size="2x2"] { --row-min: 88px; --row-ratio: .68; --row-max: 176px; }
.memory-board[data-size="2x4"] { --row-min: 62px; --row-ratio: .75; --row-max: 132px; }
.memory-board[data-size="3x3"] { --row-min: 64px; --row-ratio: .76; --row-max: 132px; }
.memory-board[data-size="4x4"] { --row-min: 54px; --row-ratio: .66; --row-max: 110px; }
.memory-board[data-size="4x6"] { --row-min: 44px; --row-ratio: .72; --row-max: 99px; }
.memory-board[data-size="5x5"] { --row-min: 46px; --row-ratio: .69; --row-max: 94px; }
.memory-board[data-size="6x6"] { --row-min: 40px; --row-ratio: .7; --row-max: 82px; }
.memory-board[data-size="7x7"] { --row-min: 35px; --row-ratio: .7; --row-max: 70px; }
.memory-board[data-size="8x8"] { --row-min: 32px; --row-ratio: .72; --row-max: 61px; }
.memory-board[data-dense="true"] { --gap: clamp(3px, .8cqw, 8px); }
.pause-cover {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: inherit;
  background: #edf3ff;
  text-align: center;
}
.pause-cover h3 { margin: 3px 0 8px; }
.board-shell:has(.pause-cover:not([hidden])) .memory-board { visibility: hidden; }
.club-tile {
  container-type: inline-size;
  display: grid;
  place-items: center;
  border: 1px solid #ead9aa;
  border-radius: 12px;
  background: linear-gradient(145deg, #fff9e5, #f9edd5);
  color: #8c6933;
  font-size: clamp(1rem, 4vw, 2.6rem);
}
.memory-card {
  position: relative;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 15px;
  background: transparent;
  color: #442977;
  perspective: 620px;
  container-type: inline-size;
  -webkit-tap-highlight-color: transparent;
}
.memory-card:focus-visible { outline: 3px solid #613fb3; outline-offset: 2px; z-index: 1; }
.memory-card[aria-disabled="true"] { cursor: default; }
.card-turn, .card-back, .card-face { position: absolute; inset: 0; border-radius: inherit; }
.card-turn { transform-style: preserve-3d; transition: transform .26s cubic-bezier(.2,.72,.24,1); }
.memory-card[data-state="down"]:hover .card-turn { transform: translateY(-2px); }
.memory-card:is([data-state="revealed"], [data-state="matched"]) .card-turn { transform: rotateY(180deg); }
.card-back, .card-face {
  display: grid;
  place-items: center;
  backface-visibility: hidden;
  overflow: hidden;
  border: 1px solid #c3aae9;
  box-shadow: 0 3px 0 #c6b4e2, 0 4px 8px #57458420;
}
.card-back {
  border-color: #d2b3ec;
  background:
    radial-gradient(circle at 4px 4px, #ffffff57 0 2px, transparent 2.5px) 0 0 / 17px 17px,
    radial-gradient(circle at 4px 4px, #ffffff42 0 2px, transparent 2.5px) 8px 8px / 17px 17px,
    linear-gradient(148deg, #f1ddff 5%, #e6c9fa 63%, #efdafa);
  box-shadow: inset 0 0 0 2px #fff9, 0 3px 0 #c4a7e0, 0 4px 8px #57458418;
  color: #723ca8;
  font-weight: 800;
  line-height: 1;
}
.card-back > span { font-size: clamp(.9rem, min(34cqw, 63cqh), 3.2rem); }
.card-back, .card-face { container-type: size; }
.card-face {
  transform: rotateY(180deg);
  padding: clamp(1px, 3cqw, 5px);
  background: #fff;
  color: #41305f;
  font-weight: 800;
  line-height: 1;
}
.memory-card[data-kind="number"] .card-face { color: #234b71; font-size: clamp(1.22rem, 34cqw, 3.45rem); }
.memory-board[data-dense="true"] .memory-card[data-kind="number"] .card-face { font-size: clamp(.85rem, 31cqw, 1.65rem); }
.memory-card[data-kind="word"] .card-face {
  font-size: clamp(.5rem, 15cqw, 1.64rem);
  text-align: center;
  overflow-wrap: anywhere;
}
.tile-picture {
  display: block;
  width: min(100cqw, 100cqh);
  aspect-ratio: 1;
  border-radius: 5px;
  background-repeat: no-repeat;
  background-size: 500% 1000%;
}
.memory-card[data-kind="picture"] .card-face { padding: 2px; }
.card-face .word-workbook-image {
  width: min(100cqw, 100cqh);
  height: min(100cqw, 100cqh);
  object-fit: contain;
}
.memory-board:is([data-theme="anatomy"], [data-theme="anatomy-words"]) .word-workbook-image { mix-blend-mode: multiply; }
.card-face.card-captioned {
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 2px;
}
.card-captioned :is(.tile-picture, .word-workbook-image) { width: min(100cqw, 65cqh); }
.card-captioned .word-workbook-image { height: min(100cqw, 65cqh); }
.card-captioned .quantity { width: min(80cqw, 56cqh, 78px); }
.card-caption {
  display: -webkit-box;
  max-width: 100%;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow-wrap: anywhere;
  text-align: center;
  font-size: clamp(.45rem, min(13cqw, 23cqh), .82rem);
  line-height: 1.07;
}
.quantity { display: grid; grid-template-columns: repeat(var(--dot-columns), minmax(0, 1fr)); gap: clamp(.5px, 2cqw, 4px); width: min(83cqw, 72cqh, 78px); }
.quantity i { width: 100%; max-width: 17px; justify-self: center; aspect-ratio: 1; border-radius: 50%; background: #3b9786; }
.memory-card[data-state="matched"] .card-face { border-color: #8cc5ab; background: #ecfbf2; box-shadow: 0 3px 0 #b6dfcc; }
.memory-card[data-state="matched"] .card-face::after {
  content: "✓";
  position: absolute;
  top: 4px;
  right: 5px;
  color: #2c7550;
  font-size: clamp(.65rem, 13cqw, .9rem);
}
.memory-card[data-owner="a"] .card-face { border-color: #cd9e65; background: #fff1db; box-shadow: 0 3px 0 #ebd4ad; }
.memory-card[data-owner="b"] .card-face { border-color: #75a8d4; background: #eaf5ff; box-shadow: 0 3px 0 #bfdcf4; }
.memory-card[data-owner="a"] .card-face::after { content: "A"; color: #784b22; }
.memory-card[data-owner="b"] .card-face::after { content: "B"; color: #255990; }
.memory-toolbar { display: flex; align-items: stretch; justify-content: space-between; gap: 8px; margin-top: 7px; min-width: 0; }
.memory-display-controls { display: flex; align-items: center; gap: 5px; flex: none; }
.memory-display-controls .memory-soft:disabled { opacity: .56; cursor: default; }
.round-status {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 43px;
  padding: 6px 9px;
  border-radius: 9px;
  background: #f1eaff;
  color: #47366c;
  font-size: .83rem;
  font-weight: 700;
}
.round-status p { line-height: 1.3; }
.round-status[data-tone="match"], .round-status[data-tone="complete"] { background: #e5f8ed; color: #24573a; }
.round-status[data-tone="miss"] { background: #fff0d8; color: #66451e; }
.status-mark { display: grid; place-items: center; flex: 0 0 23px; height: 23px; border-radius: 50%; background: #ffffffb8; }
.memory-finish {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: inherit;
  background: #f3f7ffe3;
  padding: 8px;
}
.finish-card {
  display: grid;
  grid-template-columns: 65px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border: 1px solid #dce8b4;
  border-radius: 12px;
  background: linear-gradient(120deg, #f0ffe2, #fff6db);
  color: #334732;
}
.memory-finish .eyebrow { color: #496342; font-size: .64rem; }
.memory-finish h3 { font-size: 1.16rem; letter-spacing: -.03em; }
.memory-finish p:not(.eyebrow) { font-size: .78rem; }
.memory-finish img { width: 65px; height: auto; }
.memory-local { margin-top: 9px; color: var(--muted); font-size: .72rem; }
.memory-help li { margin: 7px 0; color: #352653; }
.memory-help ol { padding-inline-start: 23px; }

.memory-layout:is(:fullscreen, .is-expanded) {
  display: block;
  width: 100%;
  height: 100%;
  overflow: clip;
  background: #f6fbff;
}
.memory-layout.is-expanded { position: fixed; inset: 0; z-index: 100; }
html:has(.memory-layout.is-expanded) { overflow: hidden; }
.memory-page:has(.memory-layout:is(:fullscreen, .is-expanded)) :is(.site-header, .skip, .memory-intro, .memory-local) { visibility: hidden; }
.memory-layout:is(:fullscreen, .is-expanded) .club-panel { display: none; }
.memory-layout:is(:fullscreen, .is-expanded) .memory-cabinet {
  height: 100%;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
.memory-layout:is(:fullscreen, .is-expanded) .memory-board {
  height: 100%;
  grid-template-rows: repeat(var(--rows, 4), minmax(0, 1fr));
}
.memory-layout:is(:fullscreen, .is-expanded) .memory-display-controls .memory-soft {
  min-width: 44px;
  padding-inline: 7px;
  background: #ffffffb8;
  color: #293e5f;
}
.memory-layout:is(:fullscreen, .is-expanded) .memory-display-controls span { display: none; }

@media (max-width: 760px) {
  .memory-main { width: calc(100% - 20px); padding-block: 12px 18px; }
  .memory-layout { grid-template-columns: minmax(0, 1fr); gap: 9px; }
  .memory-intro { align-items: flex-start; margin-bottom: 9px; gap: 8px; }
  .memory-intro h1 { font-size: clamp(1.85rem, 8.6vw, 3rem); }
  .memory-lead { font-size: .81rem; }
  .memory-tools { gap: 4px; }
  .memory-tools .memory-soft { min-width: 44px; padding-inline: 7px; }
  .memory-tools .help-control span:last-child { display: none; }
  .club-panel, .memory-cabinet { padding: 8px; border-radius: 14px; }
  .club-guide { grid-template-columns: 58px 1fr; min-height: 50px; gap: 5px; }
  .club-characters .club-maya { max-height: 42px; right: 0; }
  .club-paxa { width: 38px; }
  .club-guide h2 { font-size: .99rem; }
  #round-settings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px 7px; margin-top: 5px; }
  .memory-field { margin: 0; }
  .memory-field select { padding-inline: 4px; font-size: .72rem; }
  #round-settings :is(.memory-primary, .pending-note, .player-settings, .board-dimensions, .setup-rule) { grid-column: 1 / -1; margin: 0; }
  .club-tip { display: flex; flex-wrap: wrap; align-items: baseline; gap: 1px 5px; padding: 5px 7px; margin-top: 6px; }
  .club-tip b, .club-tip p { margin: 0; font-size: .69rem; }
  .board-top { align-items: stretch; flex-direction: column; gap: 6px; }
  .board-top > div { display: flex; flex-wrap: wrap; align-items: center; gap: 3px 6px; }
  .board-top h2 { flex-basis: 100%; }
  .memory-layout:is(:fullscreen, .is-expanded) .board-top h2 {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
  .turn-tag { margin-top: 0; }
  .memory-stats div, .memory-stats .player-stat, .memory-stats .best-stat { min-width: 0; padding-inline: 4px; }
  .memory-stats .player-stat { justify-content: space-around; gap: 3px; }
  .player-stat dt { flex: none; }
  .player-stat dt img { width: 18px; height: 27px; }
  .board-shell { padding: 5px; }
  .memory-display-controls .memory-soft { min-width: 44px; padding-inline: 5px; }
  .memory-display-controls .memory-soft span { display: none; }
  .memory-toolbar { align-items: stretch; gap: 4px; }
  .round-status { font-size: .73rem; gap: 4px; }
  .status-mark { display: none; }
  .memory-card { border-radius: 10px; }
  .finish-card { grid-template-columns: 43px minmax(0, 1fr); }
  .memory-finish img { width: 43px; }
  .memory-finish button { grid-column: 1 / -1; }
}
@media (max-height: 505px) and (min-width: 520px) {
  .memory-layout:is(:fullscreen, .is-expanded) .memory-cabinet {
    grid-template-columns: minmax(0, 1fr) 204px;
    grid-template-rows: auto auto minmax(0, 1fr);
    column-gap: 9px;
  }
  .memory-layout:is(:fullscreen, .is-expanded) .board-shell { grid-area: 1 / 1 / -1 / 2; }
  .memory-layout:is(:fullscreen, .is-expanded) .board-top { grid-area: 1 / 2; align-items: stretch; flex-direction: column; }
  .memory-layout:is(:fullscreen, .is-expanded) .memory-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .memory-layout:is(:fullscreen, .is-expanded) .memory-stats > div { min-width: 0; }
  .memory-layout:is(:fullscreen, .is-expanded) .memory-progress { grid-area: 2 / 2; }
  .memory-layout:is(:fullscreen, .is-expanded) .memory-toolbar { grid-area: 3 / 2; flex-direction: column; align-items: stretch; margin-top: 0; }
  .memory-layout:is(:fullscreen, .is-expanded) .memory-display-controls { justify-content: flex-end; }
  .memory-layout:is(:fullscreen, .is-expanded) .round-status { flex: 0 1 auto; }
}
@media (prefers-reduced-motion: reduce) {
  .card-turn, .memory-progress > div { transition: none; }
  .memory-card[data-state="down"]:hover .card-turn { transform: none; }
}
