#memory-board :where(p, span, ul) { color: inherit; font: inherit; text-align: inherit; }
#memory-game { scroll-margin-top: 16px; }
#memory-game .memory-instructions {
    margin: 0 8px;
    text-align: center;
    font: bold 16px/1.5 Arial, Helvetica, sans-serif;
    color: #ffff99;
}
#memory-game .memory-instructions span { font-size: 14px; }

#memory-board,
#memory-board * { box-sizing: border-box; }
#memory-board {
    width: calc(100% - 24px);
    max-width: 660px;
    margin: 20px auto 28px;
    padding: 22px;
    border: 1px solid #d5e1ec;
    border-radius: 22px;
    background: #fffaf0;
    color: #193b59;
    box-shadow: 0 8px 22px rgba(43, 24, 24, .14);
    font: 15px/1.45 Arial, Helvetica, sans-serif;
    text-align: center;
}
#memory-board .memory-controls {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
}
#memory-board .memory-controls .memory-choose-level { margin: 0; padding: 0; }
#memory-board #memory-choose-theme > summary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 9px 12px;
    border: 2px solid #24558a;
    border-radius: 10px;
    background: #edf3f9;
    color: #24558a;
    font: bold 14px/1.3 Arial, Helvetica, sans-serif;
    list-style: none;
    cursor: pointer;
}
#memory-board #memory-choose-theme > summary::-webkit-details-marker { display: none; }
#memory-board #memory-choose-theme[open] > summary,
#memory-board #memory-choose-theme > summary:hover { background: #24558a; color: #fff; }
#memory-board summary:focus-visible { outline: 3px solid #c36b00; outline-offset: 4px; }
#memory-board .memory-theme-panel {
    position: absolute;
    z-index: 25;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    max-height: 60vh;
    max-height: min(440px, 60vh);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 10px;
    border: 2px solid #24558a;
    border-radius: 12px;
    background: #fffaf0;
    box-shadow: 0 8px 24px rgba(25, 59, 89, .25);
    text-align: left;
}
#memory-board .memory-theme-header {
    position: sticky;
    top: -10px;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: -10px -10px 8px;
    padding: 8px 10px;
    border-bottom: 1px solid #d5e1ec;
    background: #fffaf0;
}
#memory-board .memory-theme-title { margin: 0; padding: 4px 2px; font-weight: bold; }
#memory-board #memory-close-themes {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    flex-shrink: 0;
    min-width: 96px;
    min-height: 44px;
    padding: 9px 12px;
    border: 2px solid #24558a;
    border-radius: 8px;
    background: #24558a;
    color: #fff;
    font: bold 14px/1.3 Arial, Helvetica, sans-serif;
    cursor: pointer;
}
#memory-board #memory-close-themes:hover { background: #193b59; border-color: #193b59; }
#memory-board .memory-theme-panel { scroll-padding-top: 66px; }
#memory-board .memory-theme-group { border-top: 1px solid #d5e1ec; }
#memory-board .memory-theme-group > summary {
    min-height: 44px;
    padding: 11px 8px;
    color: #193b59;
    font-weight: bold;
    cursor: pointer;
}
#memory-board .memory-theme-group > summary:hover { background: #edf3f9; }
#memory-board .memory-theme-links {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    list-style: none;
    margin: 0;
    padding: 0 4px 8px;
}
#memory-board .memory-theme-links li { margin: 0; padding: 0; }
#memory-board .memory-theme {
    display: block;
    min-height: 44px;
    padding: 10px 8px;
    border: 1px solid transparent;
    border-radius: 8px;
    color: #234c6b;
    font: 14px/1.4 Arial, Helvetica, sans-serif;
    text-decoration: none;
}
#memory-board .memory-theme:hover,
#memory-board .memory-theme[aria-current="page"] { background: #e3edf7; border-color: #24558a; }
#memory-board .memory-theme[aria-current="page"] { font-weight: bold; }
@media (max-width: 480px) {
    #memory-board .memory-theme-links { grid-template-columns: 1fr; }
}
#memory-board .memory-choose-level {
    margin: 0 0 12px;
    color: #193b59;
    font-size: 17px;
    font-weight: bold;
}
#memory-board .memory-levels {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
}
#memory-board .memory-level {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 7px;
    min-height: 88px;
    padding: 10px 4px 8px;
    border: 2px solid #d3dfeb;
    border-radius: 13px;
    background: #fff;
    color: #234c6b;
    font: bold 12px/1.3 Arial, Helvetica, sans-serif;
    text-decoration: none;
}
#memory-board .memory-smiley {
    clip-path: circle(46% at 50% 49%);
    display: block;
    width: 40px;
    height: 40px;
    max-width: none;
    margin: 0;
    padding: 0;
    border: 0;
    object-fit: contain;
}
#memory-board .memory-level[aria-pressed="true"],
#memory-board .memory-level[aria-current="page"] {
    border-color: #24558a;
    background: #24558a;
    color: #fff;
}
#memory-board .memory-level:hover { border-color: #24558a; }
#memory-board .memory-stats {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 36px;
    margin: 20px 0 18px;
    padding: 14px 0;
    border-top: 1px solid #dce4e9;
    border-bottom: 1px solid #dce4e9;
}
#memory-board .memory-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    min-width: 100px;
}
#memory-board .memory-caption { font-size: 12px; color: #52697b; }
#memory-board #memory-pairs { font-size: 22px; line-height: 1.3; }
#memory-board #memory-time {
    min-width: 100px;
    min-height: 44px;
    margin: -5px 0 -8px;
    padding: 4px 10px;
    border: 2px solid transparent;
    border-radius: 9px;
    background: transparent;
    color: #193b59;
    font: bold 22px/1.3 Arial, Helvetica, sans-serif;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
}
#memory-board #memory-time:hover { background: #e8f0f8; }
#memory-board .memory-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, 96px);
    width: 100%;
    max-width: calc(var(--memory-columns) * 108px - 12px);
    justify-content: center;
    gap: 12px;
    margin: 0 auto;
}
#memory-board .memory-card {
    position: relative;
    width: 96px;
    height: 96px;
    margin: 0;
    padding: 6px;
    border: 2px solid #24558a;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 3px 0 #c5d3de;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
#memory-board .memory-card img {
    display: block;
    width: 80px;
    height: 80px;
    max-width: none;
    margin: 0;
    opacity: 0;
    border: 0;
    border-radius: 7px;
    object-fit: contain;
    pointer-events: none;
}
#memory-board .memory-back {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    overflow: hidden;
    border-radius: 11px;
    background: radial-gradient(circle at 15% 18%, rgba(255,255,255,.15) 0 5px, transparent 6px),
                radial-gradient(circle at 85% 82%, rgba(255,255,255,.15) 0 7px, transparent 8px),
                linear-gradient(145deg, #3975af, #24558a);
    color: #fff;
    font: bold 42px/1 Arial, Helvetica, sans-serif;
    pointer-events: none;
}
#memory-board .memory-back::before {
    position: absolute;
    inset: 9px;
    border: 1px solid rgba(255,255,255,.3);
    border-radius: 8px;
    content: "";
}
#memory-board .memory-check {
    position: absolute;
    top: -6px;
    right: -6px;
    display: none;
    place-items: center;
    width: 23px;
    height: 23px;
    border: 2px solid #fffaf0;
    border-radius: 50%;
    background: #237042;
    color: #fff;
    font: bold 14px/1 Arial, Helvetica, sans-serif;
    pointer-events: none;
}
#memory-board .memory-card.is-open img { opacity: 1; }
#memory-board .memory-card.is-open .memory-back { opacity: 0; }
#memory-board .memory-card.is-found {
    border-color: #237042;
    background: #edf7e8;
    box-shadow: 0 3px 0 #c5d8bd;
    cursor: default;
}
#memory-board .memory-card.is-found .memory-check { display: grid; }
#memory-board .memory-card:hover:not(.is-found) {
    border-color: #153b60;
    box-shadow: 0 0 0 2px #bdd9f1, 0 3px 0 #c5d3de;
}
#memory-board button:focus-visible,
#memory-board a:focus-visible {
    outline: 3px solid #c36b00;
    outline-offset: 4px;
}
#memory-board .memory-bottom {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-top: 20px;
}
#memory-board #memory-status {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    margin: 0;
    color: #34546b;
    font-size: 15px;
    font-weight: bold;
}
#memory-board.is-finished #memory-status { color: #237042; }
#memory-board #memory-replay {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    min-width: 155px;
    min-height: 46px;
    padding: 10px 22px;
    border: 2px solid #24558a;
    border-radius: 12px;
    background: #fff;
    color: #24558a;
    font: bold 16px/1.3 Arial, Helvetica, sans-serif;
    cursor: pointer;
}
#memory-board #memory-replay:hover,
#memory-board.is-finished #memory-replay { background: #24558a; color: #fff; }
#memory-board #memory-replay svg { width: 19px; height: 19px; }
@media (prefers-reduced-motion: no-preference) {
    #memory-board .memory-card,
    #memory-board .memory-level,
    #memory-board #memory-replay { transition: background-color .15s, border-color .15s, box-shadow .15s; }
    #memory-board .memory-back,
    #memory-board .memory-card img { transition: opacity .12s; }
}
@media (max-width: 680px) {
    #memory-board { width: calc(100% - 12px); padding: 16px 10px; border-radius: 17px; }
    #memory-board .memory-levels { gap: 5px; }
    #memory-board .memory-level { min-height: 91px; padding: 8px 2px; font-size: 11px; }
    #memory-board .memory-grid { grid-template-columns: repeat(3, 88px); gap: 8px; }
    #memory-board .memory-card { width: 88px; height: 88px; padding: 2px; border-radius: 12px; }
    #memory-board .memory-back { border-radius: 9px; }
    #memory-board .memory-stats { margin-top: 16px; gap: 22px; }
}
/* Levels 4 and 5 fit four columns on wider phones while keeping 80 px pictures. */
@media (min-width: 390px) and (max-width: 680px) {
    #memory-board[data-pairs="8"],
    #memory-board[data-pairs="10"] {
        width: calc(100% - 8px);
        padding-left: 4px;
        padding-right: 4px;
    }
    #memory-board[data-pairs="8"] .memory-grid,
    #memory-board[data-pairs="10"] .memory-grid {
        grid-template-columns: repeat(auto-fit, 84px);
        max-width: 354px;
        gap: 6px;
    }
    #memory-board[data-pairs="8"] .memory-card,
    #memory-board[data-pairs="10"] .memory-card {
        width: 84px;
        height: 84px;
        padding: 0;
    }
}
@media (max-width: 340px) {
    #memory-board { width: 100%; padding-left: 8px; padding-right: 8px; }
    #memory-board .memory-grid { gap: 6px; }
    #memory-board .memory-level { font-size: 10px; }
}
@media (max-width: 300px) {
    #memory-board .memory-grid { grid-template-columns: repeat(2, 88px); }
    #memory-board .memory-levels { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

#memory-board[data-mode="numbers"] .memory-levels { grid-template-columns: repeat(3, minmax(0, 1fr)); }
#memory-board button.memory-level { cursor: pointer; margin: 0; }
#memory-board .memory-letter {
    display: block;
    font: bold 50px/1 Arial, Helvetica, sans-serif;
    color: #193b59;
    text-align: center;
}
#memory-board #memory-sound {
    min-height: 44px;
    padding: 6px 16px;
    border: 1px solid #24558a;
    border-radius: 8px;
    background: white;
    color: #24558a;
    font: bold 14px/1.4 Arial, Helvetica, sans-serif;
    cursor: pointer;
}
#memory-board #memory-sound[aria-pressed="true"] { background: #24558a; color: white; }
