#memory-game { width: min(760px, calc(100vw - 32px)); max-width: none; max-height: calc(100dvh - 32px); padding: 0; border: 1px solid var(--line); border-radius: 28px; background: var(--paper); color: var(--ink); box-shadow: 0 24px 100px #102d4659; overscroll-behavior: contain; scrollbar-width: thin }
#memory-game::backdrop { background: #102d4678; backdrop-filter: blur(6px) }
.memory-shell { padding: 28px }
.memory-header { position: sticky; top: 0; z-index: 3; background: var(--paper); padding: 8px 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px }
.memory-eyebrow { color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase }
#memory-title { margin: 6px 0 0; font-size: clamp(25px, 4vw, 36px); letter-spacing: -.045em; line-height: 1.1 }
.memory-close { display: grid; place-items: center; width: 48px; height: 48px; flex: 0 0 auto; padding: 0; border: 0; border-radius: 15px; background: var(--soft); color: var(--ink); font-size: 30px }
#memory-intro { margin: 14px 0 20px; font-size: 15px; line-height: 1.5; color: var(--muted) }
.memory-options { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px }
.memory-options fieldset { border: 0; margin: 0; padding: 0; min-width: 0 }
.memory-options legend { margin-bottom: 8px; color: var(--muted); font-size: 13px; font-weight: 800 }
.memory-levels { display: flex; gap: 6px }
.memory-levels button, .memory-restart { min-height: 48px; border: 1px solid var(--line); border-radius: 12px; background: var(--soft); color: var(--ink); padding: 8px 14px; font-size: 14px; font-weight: 800 }
.memory-levels [aria-pressed=true] { background: #287f6e; color: white; border-color: #287f6e; box-shadow: 0 3px 0 #1d6258 }
.memory-restart { background: transparent; font-size: 13px }
.memory-restart > span { font-size: 21px; vertical-align: middle }
.memory-level-hint { color: var(--muted); font-size: 11px; margin: 10px 0 16px }
.memory-stats { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--muted) }
.memory-stats i { font-style: normal }
.memory-stats b { color: var(--ink); font-size: 19px; margin-right: 4px; font-variant-numeric: tabular-nums }
#memory-progress { display: block; width: 100%; height: 7px; margin: 12px 0 20px; border: 0; border-radius: 9px; overflow: hidden; accent-color: #287f6e; background: var(--soft) }
#memory-progress::-webkit-progress-bar { background: var(--soft) }
#memory-progress::-webkit-progress-value { background: #287f6e; border-radius: 9px }
#memory-progress::-moz-progress-bar { background: #287f6e; border-radius: 9px }
#memory-board { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px }
.memory-card { position: relative; display: grid; aspect-ratio: 1.05; min-width: 0; min-height: 64px; padding: 0; border: 2px solid #b9d9d2; border-radius: 18px; background: #e6f1eb; box-shadow: 0 4px 0 #b9d0c7; color: #245e59; overflow: hidden; transition: transform .18s, border-color .18s, background .18s }
.memory-card:hover:not([aria-disabled=true]) { border-color: #287f6e; transform: translateY(-2px) }
.memory-card:active:not([aria-disabled=true]) { transform: translateY(2px) }
.memory-back, .memory-face { grid-area: 1 / 1; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none }
.memory-back { align-self: stretch; position: relative; background: radial-gradient(circle at 24% 22%, #fff9 0 3px, transparent 4px), radial-gradient(circle at 80% 74%, #fff9 0 3px, transparent 4px), linear-gradient(145deg, #e0efea, #c5e0d5); border: 5px solid #ffffff78; border-radius: 15px }
.memory-back::before { content: ''; position: absolute; inset: 12px; border: 1px dashed #6da49666; border-radius: 50%; transform: rotate(-25deg) }
.memory-back-plane { font-size: clamp(30px, 5vw, 50px); line-height: 1; transform: rotate(-20deg); color: #427d73; z-index: 1 }
.memory-cloud { width: 34%; height: 8px; margin-top: 8px; background: #ffffffa8; border-radius: 100% }
.memory-face { visibility: hidden; width: 100%; padding: 4px 4px 8px; background: #fffef9 }
.memory-face svg { width: 100%; max-height: 108px; flex: 1; min-height: 0 }
.memory-name { font-size: 12px; font-weight: 800; line-height: 1.2; text-align: center; min-height: 2.4em; display: flex; align-items: center; justify-content: center }
.memory-card.is-up .memory-face { visibility: visible }
.memory-card.is-up .memory-back { visibility: hidden }
.memory-card.is-preview .memory-back { visibility: hidden }
.memory-card.is-preview .memory-face { visibility: visible }
.memory-save-note { color: var(--muted); font-size: 12px; line-height: 1.5; margin: -8px 0 18px }
#memory-fact { padding: 12px 16px; border-radius: 14px; background: var(--soft); color: var(--ink); font-size: 14px; line-height: 1.5 }
#memory-best { font-size: 13px }
#memory-board[data-pairs="2"] { grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 430px; margin-inline: auto }
.memory-options { flex-wrap: wrap }
.memory-levels { flex-wrap: wrap }
.memory-card.is-matched { border-color: #287f6e; box-shadow: 0 4px 0 #287f6e; cursor: default }
.memory-card.is-matched .memory-face { background: #edf7ee }
.memory-check { display: none; position: absolute; top: 5px; right: 5px; border-radius: 50%; width: 22px; height: 22px; background: #287f6e; color: white; font-size: 14px; font-weight: 900; place-items: center }
.memory-card.is-matched .memory-check { display: grid }
#memory-status { min-height: 1.5em; margin: 20px 0 0; text-align: center; color: var(--accent); font-size: 15px; font-weight: 700 }
#memory-win { margin-top: 18px; padding: 22px; border: 1px solid #e8d7a6; border-radius: 20px; background: #fff5d8; color: #72551b; text-align: center }
#memory-win[hidden] { display: none }
.memory-medal { display: inline-grid; place-items: center; width: 56px; height: 56px; border-radius: 50%; background: #f5ce67; color: #8c6715; font-size: 38px }
#memory-win h3 { margin: 12px 0 6px; font-size: 25px; letter-spacing: -.03em }
#memory-win p { font-size: 15px; line-height: 1.5; margin: 0 0 16px }
#memory-win button { margin-inline: auto; min-height: 48px }
#memory-empty { grid-column: 1 / -1 }
body.memory-playing #moment, body.memory-playing #notice { visibility: hidden }
@media (prefers-reduced-motion: no-preference) {
  .memory-card.is-matched .memory-check { animation: memory-pop .3s ease-out }
  @keyframes memory-pop { from { transform: scale(.2) } to { transform: scale(1) } }
}
@media (max-width: 760px) {
  #actions #back { flex: 0 0 auto } #actions #back .label { display: none }
  #actions #memory-open { flex: 0 0 auto } #actions #memory-open .label { display: inline }
  #memory-game { width: calc(100vw - 20px); max-height: calc(100dvh - 20px); border-radius: 22px }
  .memory-shell { padding: 18px }
  .memory-eyebrow { font-size: 9px; letter-spacing: .04em }
  #memory-intro { font-size: 14px; margin-bottom: 16px }
  .memory-options { flex-wrap: wrap; gap: 10px }
  .memory-options fieldset { flex: 1 } .memory-levels button { flex: 1; padding: 8px 10px }
  .memory-restart { width: 100%; min-height: 48px }
  .memory-level-hint { margin-bottom: 12px }
  .memory-stats { font-size: 11px; gap: 8px } .memory-stats b { font-size: 18px }
  #memory-board { gap: 9px }
  .memory-card { border-radius: 12px; aspect-ratio: .72 }
  .memory-back { border-width: 3px; border-radius: 9px } .memory-back::before { inset: 5px }
  .memory-face { padding: 2px 2px 4px } .memory-name { font-size: 10px; min-height: 3.6em }
  .memory-check { width: 18px; height: 18px; font-size: 11px; top: 3px; right: 3px }
  #memory-status { font-size: 14px; margin-top: 16px }
}
@media (max-width: 350px) { #actions #book .label { display: none } .memory-shell { padding: 14px } #memory-board { gap: 7px } }
#memory-game { font-family: "Trebuchet MS", system-ui, sans-serif }
@media (max-width: 760px) {
  .memory-options fieldset { flex-basis: 100% }
  .memory-options > .memory-restart { width: calc(50% - 5px); font-size: 12px; padding: 8px }
  #memory-board[data-pairs="2"] .memory-card { aspect-ratio: 1.15 }
  #memory-board[data-pairs="2"] .memory-name { min-height: 2.4em }
}
body.night .memory-face { background: #e4efe9; color: #163c45 }
body.night .memory-card.is-matched .memory-face { background: #c7e6d2 }
