.memory-stats:has(#memory-score-slot:not([hidden])) { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.memory-nav .memory-wallet-button { gap: 5px; font-size: .85rem; border-color: #9b704c; }
.memory-wallet-button span { color: var(--memory-gold); font-size: 1.05rem; }
.memory-wallet-button b { font-variant-numeric: tabular-nums; }
.memory-wallet-button b:empty { display: none; }
.memory-menu-link {
    min-height: 42px;
    min-width: 0;
    padding: 5px 12px;
    border: 1px solid var(--memory-border);
    border-radius: 8px;
    color: var(--memory-text);
    background: var(--memory-panel);
}
.memory-challenge-menu > :is(button, a) { display: flex; width: 100%; margin-block: 7px; }
#memory-wallet-balance { color: var(--memory-gold); font-variant-numeric: tabular-nums; }
.memory-style-picker { display: grid; grid-template-columns: 38px minmax(0, 1fr) 38px; gap: 8px; align-items: center; margin-block: 9px 6px; }
#memory-style-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: clamp(68px, 19dvh, 130px);
    border: 1px solid var(--style-edge, var(--memory-border));
    border-radius: 11px;
    background: radial-gradient(ellipse, var(--style-light, #6c437f), var(--style-panel, #422951));
}
#memory-style-preview span {
    display: grid;
    width: clamp(36px, 13vw, 78px);
    aspect-ratio: 1.18;
    place-items: center;
    border: 1px solid var(--style-edge, #e0b078);
    border-radius: 7px;
    background: radial-gradient(ellipse, var(--style-light, #6c437f), var(--style-dark, #422951));
    box-shadow: 0 3px 12px #120c19a0;
    color: var(--style-mark, var(--memory-gold));
    font-size: 1.35rem;
}
.memory-wallet-actions, #memory-rescue-panel { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; }
.memory-wallet-actions form { margin: 0; }
#memory-wallet-status, #memory-rescue-status { min-height: 1.2em; font-size: .82rem; margin-block: 4px 6px; }
#memory-rescue-status { flex-basis: 100%; margin: 0; }
#memory-rescue-status:empty { display: none; }
#memory-rescue-panel { margin-block: 12px 0; }

[data-preview-style="classic"] {
    --style-panel: #422951;
    --style-light: #6c437f;
    --style-dark: #422951;
    --style-edge: #c596b8;
    --style-mark: #f3bf75;
}
:is([data-memory-style="aurora"], [data-preview-style="aurora"]) {
    --style-panel: #101331;
    --style-light: #734dd0;
    --style-dark: #1e2659;
    --style-edge: #a59cff;
    --style-mark: #dbd6ff;
}
:is([data-memory-style="sunset"], [data-preview-style="sunset"]) {
    --style-panel: #392032;
    --style-light: #aa4f62;
    --style-dark: #5d2541;
    --style-edge: #ffba93;
    --style-mark: #ffdab7;
}
:is([data-memory-style="jade"], [data-preview-style="jade"]) {
    --style-panel: #112e33;
    --style-light: #258579;
    --style-dark: #114c4b;
    --style-edge: #8bdccb;
    --style-mark: #c4ffdf;
}
.memory-page[data-memory-style]:not([data-memory-style="classic"]) .memory-workbench {
    background: radial-gradient(ellipse at top, var(--style-light), transparent 85%), var(--style-panel);
}
.memory-page[data-memory-style]:not([data-memory-style="classic"]) .memory-card-back {
    border-color: var(--style-edge);
    color: var(--style-mark);
    background: repeating-linear-gradient(135deg, transparent 0 5px, #fff3d412 5px 6px),
        radial-gradient(ellipse, var(--style-light), var(--style-dark) 75%);
}
.memory-card[data-shift] :is(.memory-card-back, .memory-card-front) { outline: 2px solid #ffda86; outline-offset: -3px; box-shadow: inset 0 0 17px #ffd577a1; }
.memory-card[data-shift="moving"] .memory-card-surface { animation: memory-slide 280ms ease-out; }
.memory-card[data-state="matched"] { --shift-angle: 180deg; }
@keyframes memory-slide {
    35% { transform: translateX(var(--shift-offset, 14%)) rotateY(var(--shift-angle, 0deg)); opacity: .45; }
    100% { transform: translateX(0) rotateY(var(--shift-angle, 0deg)); opacity: 1; }
}
[dir="rtl"] .memory-board { --shift-offset: -14%; }
.memory-combo-flare { color: var(--memory-gold); font-weight: 700; }
.memory-weekly { grid-template-rows: minmax(0, 1fr); grid-template-areas: "intro board"; }
.memory-weekly .memory-intro { align-self: center; }
.memory-weekly .memory-workbench { min-height: 0; }
.memory-weekly .memory-message { margin-inline: 3px; }
.weekly-reward { color: var(--memory-gold); font-size: .9rem; line-height: 1.45; }
.weekly-actions { justify-content: center; flex-wrap: wrap; }
.weekly-actions:empty, .weekly-actions:not(:has(:is(a, button):not([hidden]))) { display: none; }
#weekly-welcome {
    width: min(60%, 230px, 47dvh);
    display: grid;
    aspect-ratio: 1.25;
    grid-template: repeat(2, minmax(0, 1fr))/repeat(2, minmax(0, 1fr));
    gap: 6px;
}
#weekly-welcome span {
    display: grid;
    place-items: center;
    border: 1px solid #ab8069;
    border-radius: 8px;
    background: radial-gradient(#6c437f, #422951);
    color: #f3bf75;
    font-size: clamp(1rem, 4dvh, 2.3rem);
}
@media (max-width: 720px) {
    .memory-nav { gap: 5px; }
    .memory-nav-actions { gap: 4px; }
    .memory-nav :is(a, button) { padding-inline: 7px; }
    .memory-nav-actions button { min-width: 36px; }
    .memory-help { column-gap: 5px; }
    .memory-help .memory-action { padding-inline: 5px; }
    .memory-stats:has(#memory-score-slot:not([hidden])) span { font-size: clamp(.67rem, 2.4vw, .79rem); }
    .memory-weekly { grid-template-rows: auto minmax(0, 1fr); grid-template-areas: "intro" "board"; }
}
@media (min-width: 721px) {
    .memory-layout:not(.memory-weekly) { grid-template-rows: auto auto minmax(0, 1fr); }
}
@media (min-width: 721px) and (max-height: 610px) {
    .memory-layout:not(.memory-weekly) .memory-intro p { display: none; }
    .memory-help { gap: 3px 8px; }
    .memory-help :is(a, button) { min-height: 34px; font-size: .77rem; }
}
@media (orientation: landscape) and (max-height: 500px) {
    .memory-weekly { grid-template-rows: minmax(0, 1fr); grid-template-areas: "intro board"; }
    .memory-weekly .memory-intro { align-self: start; padding-block: 8px; }
    .memory-wallet-actions .memory-menu-link, #memory-rescue-panel .memory-menu-link { min-height: 36px; }
}
@media (orientation: landscape) and (max-height: 370px) {
    .memory-help { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px; }
    .memory-help :is(a, button) { min-height: 29px; line-height: 1.1; white-space: normal; }
    .memory-intro h1, [dir="rtl"] .memory-intro h1 { font-size: clamp(1rem, 3vw, 1.5rem); }
    .memory-settings :is(button, #game-hearts-hud) { min-height: 31px; padding-block: 3px; }
}
@media (prefers-reduced-motion: reduce) {
    .memory-card[data-shift="moving"] .memory-card-surface { animation: none; }
}
