:root {
    --theme-bg-1: #071512;
    --theme-bg-2: #102b24;
    --theme-surface: #10221e;
    --theme-card-a: #2b735d;
    --theme-card-b: #123b31;
    --theme-accent: #67e0b3;
    --theme-ink: #f2fff9;
    --reward: #f4b95f;
    --danger: #ff7c78;
    --surface-0: #08100f;
    --surface-1: var(--theme-surface);
    --surface-2: color-mix(in srgb, var(--theme-surface) 80%, white 7%);
    --surface-3: color-mix(in srgb, var(--theme-surface) 68%, white 12%);
    --line: color-mix(in srgb, var(--theme-accent) 18%, white 9%);
    --line-strong: color-mix(in srgb, var(--theme-accent) 42%, white 8%);
    --text: var(--theme-ink);
    --muted: color-mix(in srgb, var(--theme-ink) 62%, transparent);
    --faint: color-mix(in srgb, var(--theme-ink) 40%, transparent);
    --accent: var(--theme-accent);
    --accent-ink: #071512;
    --shadow-sm: 0 8px 20px rgba(0, 0, 0, .22);
    --shadow-md: 0 18px 48px rgba(0, 0, 0, .34);
    --shadow-glow: 0 0 26px color-mix(in srgb, var(--theme-accent) 22%, transparent);
    --radius-sm: 6px;
    --radius: 8px;
    --content: min(1380px, calc(100% - 40px));
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--theme-bg-1);
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background-color: var(--theme-bg-1);
    font-family: "Nunito", sans-serif;
    font-size: 16px;
    line-height: 1.45;
    overflow-x: hidden;
    transition: background-color .35s ease, color .25s ease;
}

body::before {
    position: fixed;
    z-index: -2;
    inset: 0;
    content: "";
    background-image:
        linear-gradient(color-mix(in srgb, var(--theme-accent) 4%, transparent) 1px, transparent 1px),
        linear-gradient(90deg, color-mix(in srgb, var(--theme-accent) 4%, transparent) 1px, transparent 1px),
        linear-gradient(145deg, var(--theme-bg-1), var(--theme-bg-2));
    background-size: 34px 34px, 34px 34px, 100% 100%;
    transition: background-image .35s ease;
}

button,
input {
    font: inherit;
}

button,
a,
input,
.memory-card,
.theme-card,
.shop-card,
.theme-chip {
    -webkit-tap-highlight-color: transparent;
}

.game-wrapper,
.memory-card,
.card-inner,
.card-back,
.card-front,
.action-btn,
.mode-btn,
.theme-chip {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

button {
    color: inherit;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
.memory-card:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
}

button:disabled {
    cursor: default;
}

/* Application chrome */
header {
    position: relative;
    z-index: 10;
    width: var(--content);
    min-height: 76px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--line);
}

.brand-lockup {
    display: flex;
    align-items: center;
    gap: 13px;
}

.brand-emblem {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    color: var(--accent);
    background: color-mix(in srgb, var(--theme-accent) 11%, var(--surface-1));
    box-shadow: inset 0 0 18px color-mix(in srgb, var(--theme-accent) 8%, transparent);
    font-size: 18px;
}

.brand-copy {
    display: grid;
    gap: 0;
}

.main-title {
    margin: 0;
    color: var(--text);
    font-size: clamp(27px, 2.2vw, 35px);
    font-weight: 900;
    line-height: .95;
    letter-spacing: 0;
}

.main-title .accent {
    color: var(--accent);
}

.tag-line {
    margin: 7px 0 0;
    color: var(--muted);
    font-size: 9px;
    font-weight: 800;
    line-height: 1;
    letter-spacing: 2.4px;
    text-transform: uppercase;
}

.menu,
#user-panel {
    display: flex;
    align-items: center;
}

.btn-login,
.btn-logout {
    min-height: 44px;
    padding: 0 15px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    color: var(--text);
    background: var(--surface-2);
    box-shadow: var(--shadow-sm);
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
    transition: border-color .18s ease, color .18s ease, transform .18s ease, background .18s ease;
}

.btn-login:hover,
.btn-logout:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--surface-3);
    transform: translateY(-1px);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-photo {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
}

.user-info {
    color: var(--text);
    font-size: 13px;
    font-weight: 800;
}

.logout-form {
    margin: 0;
}

main {
    width: 100%;
}

.p_1_m {
    position: relative;
    width: 100%;
    min-height: calc(100vh - 150px);
}

.game-design,
.main-background,
.bottom-right-bush,
.bottom-left-bush {
    display: none;
}

.game-wrapper {
    position: relative;
    z-index: 1;
    width: var(--content);
    margin: 0 auto;
    padding: 18px 0 20px;
}

/* Command console */
.controls-wrapper {
    width: 100%;
    padding: 12px;
    display: grid;
    grid-template-columns: minmax(460px, 1.4fr) minmax(390px, 1fr) auto;
    align-items: center;
    gap: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--surface-1) 91%, black 9%);
    box-shadow: var(--shadow-sm);
}

.main-actions {
    min-width: 0;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
}

.action-btn {
    position: relative;
    min-width: 0;
    min-height: 46px;
    padding: 0 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--text);
    background: var(--surface-2);
    font-size: 14px;
    font-weight: 800;
    line-height: 1.1;
    letter-spacing: 0;
    cursor: pointer;
    overflow: hidden;
    box-shadow: inset 0 1px rgba(255, 255, 255, .05), 0 6px 12px rgba(0, 0, 0, .18);
    transition: transform .16s ease, border-color .16s ease, background .16s ease, box-shadow .16s ease, color .16s ease;
}

.action-btn::before {
    position: absolute;
    inset: 0;
    content: "";
    pointer-events: none;
    background: linear-gradient(180deg, rgba(255, 255, 255, .07), transparent 48%);
}

.action-btn > * {
    position: relative;
}

.action-btn i {
    width: 24px;
    height: 24px;
    display: grid;
    place-items: center;
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, currentColor 10%, transparent);
    font-size: 12px;
}

.action-btn:hover {
    z-index: 1;
    border-color: var(--line-strong);
    background: var(--surface-3);
    box-shadow: var(--shadow-sm), var(--shadow-glow);
    transform: translateY(-2px);
}

.action-btn:active {
    transform: translateY(0) scale(.98);
}

.surprise-btn {
    border-color: color-mix(in srgb, var(--reward) 46%, transparent);
    color: #171107;
    background: linear-gradient(135deg, #f6c76f, #db9341);
}

.surprise-btn:hover {
    border-color: #ffd98c;
    color: #171107;
    background: linear-gradient(135deg, #ffd887, #eaa14b);
    box-shadow: 0 10px 24px rgba(220, 151, 63, .25);
}

.browse-btn {
    border-color: color-mix(in srgb, var(--accent) 38%, transparent);
    background: color-mix(in srgb, var(--accent) 12%, var(--surface-2));
}

.browse-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.shop-btn {
    border-color: color-mix(in srgb, var(--accent) 42%, transparent);
    color: var(--accent-ink);
    background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 92%, white 8%), color-mix(in srgb, var(--accent) 70%, #0b2a25 30%));
}

.shop-btn:hover {
    border-color: var(--accent);
    color: var(--accent-ink);
    filter: brightness(1.08);
}

.hint-btn.is-locked {
    border-style: dashed;
    color: var(--muted);
    background: color-mix(in srgb, var(--surface-2) 86%, transparent);
}

.hint-btn.hint-used {
    opacity: .55;
}

.lock-badge {
    color: var(--danger);
    font-size: 10px;
}

.mode-buttons {
    min-width: 390px;
    min-height: 52px;
    padding: 4px;
    display: grid;
    grid-template-columns: repeat(5, minmax(62px, 1fr));
    gap: 3px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--theme-bg-1) 72%, black 28%);
}

.mode-btn {
    min-height: 44px;
    padding: 0 7px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--muted);
    background: transparent;
    font-size: 12px;
    font-weight: 800;
    cursor: pointer;
    transition: color .16s ease, background .16s ease, border-color .16s ease, box-shadow .16s ease;
}

.mode-btn:hover {
    color: var(--text);
    background: var(--surface-2);
}

.mode-btn.active {
    border-color: color-mix(in srgb, var(--accent) 60%, transparent);
    color: var(--accent-ink);
    background: var(--accent);
    box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 22%, transparent);
}

.mode-btn.is-locked {
    color: var(--faint);
}

.mode-btn.is-locked i {
    margin-left: 3px;
    color: var(--danger);
    font-size: 9px;
}

.visual-theme-strip {
    min-height: 46px;
    display: flex;
    align-items: stretch;
    gap: 5px;
}

.theme-chip {
    min-width: 72px;
    min-height: 46px;
    padding: 5px 8px;
    display: grid;
    grid-template-columns: 20px 1fr;
    align-items: center;
    gap: 7px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--muted);
    background: var(--surface-2);
    font-size: 11px;
    font-weight: 800;
    cursor: pointer;
    transition: border-color .16s ease, background .16s ease, color .16s ease, transform .16s ease;
}

.theme-chip:hover {
    border-color: var(--line-strong);
    color: var(--text);
    transform: translateY(-1px);
}

.theme-chip.active {
    border-color: var(--accent);
    color: var(--text);
    background: color-mix(in srgb, var(--accent) 13%, var(--surface-2));
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 22%, transparent), var(--shadow-glow);
}

.theme-chip.is-locked {
    opacity: .58;
}

.theme-swatch {
    width: 20px;
    height: 28px;
    display: block;
    border: 1px solid rgba(255, 255, 255, .24);
    border-radius: 5px;
    background: linear-gradient(145deg, var(--swatch-a), var(--swatch-b));
    box-shadow: inset 0 1px rgba(255, 255, 255, .22);
}

.premium-badge {
    grid-column: 2;
    margin-top: -7px;
    color: var(--danger);
    font-size: 8px;
    font-weight: 900;
}

/* Game stage */
.board-wrapper {
    position: relative;
    width: 100%;
    min-height: 360px;
    margin-top: 14px;
    padding: 18px 20px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background:
        linear-gradient(90deg, color-mix(in srgb, var(--theme-accent) 3%, transparent) 1px, transparent 1px),
        linear-gradient(color-mix(in srgb, var(--theme-accent) 3%, transparent) 1px, transparent 1px),
        color-mix(in srgb, var(--surface-1) 92%, black 8%);
    background-size: 24px 24px, 24px 24px, auto;
    box-shadow: var(--shadow-md), inset 0 1px rgba(255, 255, 255, .04);
    overflow: hidden;
}

.board-wrapper::before {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 2px;
    content: "";
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    opacity: .75;
}

.board-header {
    min-height: 62px;
    padding-bottom: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    border-bottom: 1px solid var(--line);
}

.board-title-group {
    min-width: 180px;
}

.board-kicker {
    display: flex;
    align-items: center;
    gap: 7px;
    color: var(--accent);
    font-size: 10px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 1.4px;
}

.category-title {
    margin: 4px 0 0;
    color: var(--text);
    font-size: clamp(22px, 2vw, 30px);
    font-weight: 900;
    line-height: 1.05;
    letter-spacing: 0;
}

.board-utility,
.game-stats {
    display: flex;
    align-items: center;
    gap: 8px;
}

.stat-box {
    min-width: 76px;
    min-height: 46px;
    padding: 6px 11px;
    display: grid;
    align-content: center;
    gap: 1px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--surface-2) 75%, transparent);
}

.stat-box .label {
    color: var(--faint);
    font-size: 9px;
    font-weight: 800;
    line-height: 1;
    text-transform: uppercase;
    letter-spacing: .8px;
}

.stat-box .value {
    color: var(--text);
    font-size: 15px;
    font-variant-numeric: tabular-nums;
    font-weight: 900;
    line-height: 1.1;
}

.mode-stat {
    min-width: 90px;
}

.reset-btn {
    min-width: 106px;
    border-color: var(--line-strong);
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 11%, var(--surface-2));
}

.welcome-msg {
    min-height: 260px;
    display: grid;
    place-items: center;
    color: var(--muted);
    font-size: 15px;
    font-weight: 700;
}

.grid-container {
    --card-size: clamp(62px, 4.1vw, 78px);
    position: relative;
    width: max-content;
    max-width: 100%;
    margin: 18px auto;
    display: none;
    grid-template-columns: repeat(var(--cols), var(--card-size));
    grid-auto-rows: var(--card-size);
    justify-content: center;
    gap: 9px;
    perspective: 1200px;
}

.memory-card {
    position: relative;
    width: var(--card-size);
    height: var(--card-size);
    border-radius: var(--radius);
    cursor: pointer;
    perspective: 800px;
    transition: transform .2s ease, filter .2s ease, opacity .35s ease;
}

.memory-card:hover {
    z-index: 2;
    transform: translateY(-3px);
    filter: brightness(1.08);
}

.memory-card:active {
    transform: translateY(-1px) scale(.97);
}

.card-inner {
    position: absolute;
    inset: 0;
    transform-style: preserve-3d;
    transition: transform .5s cubic-bezier(.2, .75, .25, 1);
}

.memory-card.flipped .card-inner,
.memory-card.matched .card-inner,
.memory-card.hint-peek .card-inner {
    transform: rotateY(180deg);
}

.card-back,
.card-front {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    border: 1px solid color-mix(in srgb, var(--accent) 30%, white 12%);
    border-radius: var(--radius);
    backface-visibility: hidden;
    overflow: hidden;
}

.card-back {
    color: color-mix(in srgb, var(--theme-ink) 88%, var(--accent) 12%);
    background:
        linear-gradient(135deg, rgba(255, 255, 255, .1), transparent 38%),
        linear-gradient(145deg, var(--theme-card-a), var(--theme-card-b));
    box-shadow:
        inset 0 0 0 3px color-mix(in srgb, var(--theme-card-b) 70%, transparent),
        inset 0 1px rgba(255, 255, 255, .18),
        0 7px 15px rgba(0, 0, 0, .33),
        0 0 15px color-mix(in srgb, var(--accent) 12%, transparent);
}

.card-back::before {
    position: absolute;
    inset: 7px;
    content: "";
    border: 1px solid color-mix(in srgb, var(--theme-ink) 22%, transparent);
    border-radius: 5px;
    background-image:
        linear-gradient(45deg, color-mix(in srgb, var(--theme-ink) 4%, transparent) 25%, transparent 25%),
        linear-gradient(-45deg, color-mix(in srgb, var(--theme-ink) 4%, transparent) 25%, transparent 25%);
    background-size: 8px 8px;
}

.card-back::after {
    position: relative;
    content: "?";
    font-family: "Nunito", sans-serif;
    font-size: clamp(28px, 2.1vw, 38px);
    font-weight: 900;
    line-height: 1;
    text-shadow: 0 3px 8px rgba(0, 0, 0, .28), 0 0 18px color-mix(in srgb, var(--accent) 36%, transparent);
}

.card-front {
    padding: 8px;
    transform: rotateY(180deg);
    border-color: color-mix(in srgb, var(--accent) 54%, white 10%);
    background: color-mix(in srgb, var(--theme-ink) 94%, var(--accent) 6%);
    box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent), 0 7px 18px rgba(0, 0, 0, .3);
}

.card-front img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
}

.memory-card.matched {
    filter: saturate(.78) brightness(.82);
    pointer-events: none;
}

.memory-card.matched .card-front {
    border-color: var(--accent);
    box-shadow: 0 0 20px color-mix(in srgb, var(--accent) 35%, transparent);
}

.board-footer {
    min-height: 32px;
    padding-top: 11px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    border-top: 1px solid var(--line);
    color: var(--faint);
    font-size: 11px;
    font-weight: 800;
}

.icon-stats {
    display: flex;
    align-items: center;
    gap: 18px;
}

.icon-stats > span,
.board-tip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.icon-stats i,
.board-tip i {
    color: var(--accent);
}

/* Modal system */
.modal-overlay {
    position: fixed;
    z-index: 1000;
    inset: 0;
    padding: 24px;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(2, 7, 8, .78);
    backdrop-filter: blur(8px);
}

.modal-overlay.active {
    display: flex;
    animation: modal-fade .18s ease both;
}

.modal-content {
    position: relative;
    width: min(900px, 100%);
    max-height: min(760px, calc(100vh - 48px));
    padding: 26px;
    overflow-y: auto;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    color: var(--text);
    background:
        linear-gradient(135deg, color-mix(in srgb, var(--theme-accent) 4%, transparent), transparent 42%),
        var(--surface-1);
    box-shadow: 0 28px 80px rgba(0, 0, 0, .56), inset 0 1px rgba(255, 255, 255, .05);
    scrollbar-color: var(--accent) transparent;
    animation: modal-rise .24s cubic-bezier(.2, .75, .25, 1) both;
}

.close-modal-btn {
    position: absolute;
    z-index: 3;
    top: 12px;
    right: 14px;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    color: var(--muted);
    background: transparent;
    box-shadow: none;
    font-size: 30px;
    font-weight: 500;
    line-height: 1;
    cursor: pointer;
    transition: color .16s ease, opacity .16s ease;
}

.close-modal-btn:hover {
    color: var(--text);
}

.gallery-header,
.shop-header {
    padding-right: 42px;
}

.gallery-header h2,
.shop-header h2,
.checkout-title,
.victory-modal h2,
.legal-body h2 {
    margin: 0;
    color: var(--text);
    font-size: clamp(24px, 3vw, 34px);
    font-weight: 900;
    line-height: 1.1;
    letter-spacing: 0;
}

.shop-kicker {
    display: block;
    margin-bottom: 7px;
    color: var(--accent);
    font-size: 10px;
    font-weight: 900;
    letter-spacing: 1.5px;
    text-transform: uppercase;
}

.shop-header p,
.checkout-benefit,
.legal-body p {
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
    line-height: 1.65;
}

.search-box {
    margin-top: 18px;
}

.search-box input,
.discount-row input {
    width: 100%;
    min-height: 46px;
    padding: 0 13px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--text);
    background: color-mix(in srgb, var(--theme-bg-1) 68%, black 32%);
    font-size: 14px;
    font-weight: 700;
    transition: border-color .16s ease, box-shadow .16s ease;
}

.search-box input::placeholder,
.discount-row input::placeholder {
    color: var(--faint);
}

.search-box input:focus,
.discount-row input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent);
}

.gallery-list {
    max-height: 520px;
    margin-top: 18px;
    padding-right: 4px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    overflow-y: auto;
}

.theme-card {
    min-width: 0;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-2);
    cursor: pointer;
    transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}

.theme-card:hover {
    border-color: var(--line-strong);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.theme-card h3 {
    margin: 12px 0 10px;
    font-size: 15px;
    font-weight: 900;
}

.preview-stack {
    position: relative;
    height: 102px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.preview-img {
    position: relative;
    width: 72px;
    height: 72px;
    margin: 0 -17px;
    padding: 5px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--theme-ink) 92%, var(--accent) 8%);
    object-fit: contain;
    box-shadow: var(--shadow-sm);
}

.img-small {
    z-index: 1;
    transform: rotate(-8deg) translateY(8px);
}

.img-medium {
    z-index: 2;
}

.img-large {
    z-index: 1;
    transform: rotate(8deg) translateY(8px);
}

.theme-lock {
    position: absolute;
    z-index: 4;
    top: 5px;
    right: 5px;
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: var(--radius-sm);
    color: #170b0b;
    background: var(--danger);
    font-size: 11px;
}

.btn-stylish {
    width: 100%;
    min-height: 40px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    background: color-mix(in srgb, var(--accent) 12%, var(--surface-3));
    font-weight: 800;
    cursor: pointer;
}

.btn-stylish:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.price-info {
    margin-left: 4px;
    color: var(--reward);
}

.shop-grid {
    margin-top: 22px;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.shop-card {
    min-height: 254px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-2);
}

.shop-card:hover {
    border-color: var(--line-strong);
}

.shop-card.is-unlocked {
    border-color: color-mix(in srgb, var(--accent) 36%, transparent);
}

.shop-card-icon {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 10%, transparent);
    font-size: 17px;
}

.shop-card-copy h3 {
    margin: 13px 0 5px;
    color: var(--text);
    font-size: 15px;
    font-weight: 900;
}

.shop-card-copy p {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.55;
}

.shop-card-foot {
    margin-top: auto;
    padding-top: 14px;
    display: grid;
    gap: 8px;
}

.shop-card-foot > span {
    color: var(--reward);
    font-size: 17px;
    font-weight: 900;
}

.shop-card-foot button,
.discount-row button {
    min-height: 44px;
    padding: 0 10px;
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    color: var(--accent-ink);
    background: var(--accent);
    font-size: 11px;
    font-weight: 900;
    cursor: pointer;
    transition: filter .16s ease, transform .16s ease;
}

.shop-card-foot button:hover,
.discount-row button:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

.shop-card-foot button:disabled {
    border-color: var(--line);
    color: var(--muted);
    background: var(--surface-3);
    filter: none;
    transform: none;
}

.discount-form {
    margin-top: 16px;
    padding: 15px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--theme-bg-1) 54%, transparent);
}

.discount-form label {
    display: block;
    margin-bottom: 7px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
}

.discount-row {
    display: grid;
    grid-template-columns: 1fr 110px;
    gap: 8px;
}

.discount-message {
    min-height: 18px;
    margin-top: 6px;
    font-size: 11px;
    font-weight: 800;
}

.discount-message.is-success {
    color: var(--accent);
}

.discount-message.is-error {
    color: var(--danger);
}

.modal-actions {
    margin-top: 18px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

.modal-actions .action-btn {
    min-width: 132px;
}

.checkout-card {
    width: min(450px, 100%);
    text-align: center;
}

.checkout-icon {
    width: 64px;
    height: 64px;
    margin: 6px auto 17px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 10%, var(--surface-2));
    box-shadow: var(--shadow-glow);
    font-size: 25px;
}

.checkout-price {
    width: max-content;
    margin: 14px auto 0;
    padding: 7px 12px;
    border: 1px solid color-mix(in srgb, var(--reward) 52%, transparent);
    border-radius: var(--radius-sm);
    color: var(--reward);
    background: color-mix(in srgb, var(--reward) 9%, transparent);
    font-size: 20px;
    font-weight: 900;
}

.checkout-primary,
.retry-btn {
    border-color: var(--accent);
    color: var(--accent-ink);
    background: var(--accent);
}

.victory-modal .modal-content {
    width: min(580px, 100%);
    text-align: center;
}

.victory-modal h2 i {
    color: var(--reward);
}

.star-rating {
    margin: 20px 0;
    color: var(--reward);
    font-size: 35px;
}

.star {
    display: inline-block;
    animation: star-in .36s ease both;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.stat-item {
    padding: 14px;
    display: grid;
    gap: 4px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-2);
}

.stat-item .label {
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
}

.stat-item .value {
    color: var(--accent);
    font-size: 25px;
    font-weight: 900;
}

.legal-content {
    width: min(650px, 100%);
}

.legal-body a {
    color: var(--accent);
}

.no_case {
    grid-column: 1 / -1;
    padding: 40px;
    color: var(--muted);
    text-align: center;
}

/* Footer */
footer {
    width: 100%;
    border-top: 1px solid var(--line);
}

.footer {
    width: var(--content);
    min-height: 66px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    color: var(--faint);
    font-size: 11px;
    font-weight: 600;
}

.footer > div span {
    color: var(--muted);
    font-weight: 800;
}

.footer-links {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 4px 16px;
}

.footer-link,
.footer-links a {
    min-height: 44px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    border: 0;
    color: var(--muted);
    background: transparent;
    font-size: 11px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: color .16s ease;
}

.footer-link:hover,
.footer-links a:hover {
    color: var(--accent);
}

@keyframes modal-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modal-rise {
    from { opacity: 0; transform: translateY(12px) scale(.985); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes star-in {
    from { opacity: 0; transform: translateY(8px) scale(.7); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 1180px) {
    .controls-wrapper {
        grid-template-columns: 1fr 1fr;
    }

    .visual-theme-strip {
        grid-column: 1 / -1;
        justify-content: center;
    }

    .theme-chip {
        min-width: 112px;
    }
}

@media (max-width: 820px) {
    :root {
        --content: min(100% - 24px, 720px);
    }

    header {
        min-height: 68px;
    }

    .brand-emblem {
        width: 38px;
        height: 38px;
    }

    .tag-line {
        font-size: 8px;
        letter-spacing: 1.7px;
    }

    .game-wrapper {
        padding-top: 12px;
    }

    .controls-wrapper {
        grid-template-columns: 1fr;
    }

    .main-actions,
    .mode-buttons,
    .visual-theme-strip {
        grid-column: 1;
    }

    .visual-theme-strip {
        justify-content: stretch;
        overflow-x: auto;
        padding: 0 24px 5px 0;
        scroll-padding-inline: 0 24px;
        scrollbar-width: thin;
        scrollbar-color: var(--accent) color-mix(in srgb, var(--surface-2) 70%, transparent);
        mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 24px), transparent 100%);
    }

    .theme-chip {
        min-width: 104px;
        flex: 1 0 104px;
    }

    .board-header {
        align-items: flex-start;
    }

    .board-utility {
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .mode-stat {
        display: none;
    }

    .shop-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .gallery-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .footer {
        padding: 14px 0;
        flex-direction: column;
        justify-content: center;
        text-align: center;
    }

    .footer-links {
        justify-content: center;
    }
}

@media (max-width: 560px) {
    :root {
        --content: calc(100% - 20px);
    }

    header {
        min-height: 64px;
    }

    .brand-emblem {
        width: 34px;
        height: 34px;
        font-size: 14px;
    }

    .main-title {
        font-size: 25px;
    }

    .tag-line {
        display: none;
    }

    .btn-login {
        width: 44px;
        min-width: 44px;
        padding: 0;
    }

    .btn-login span,
    .user-info {
        display: none;
    }

    .game-wrapper {
        padding-bottom: 12px;
    }

    .controls-wrapper {
        padding: 9px;
        gap: 9px;
    }

    .main-actions {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .action-btn {
        min-height: 44px;
        padding: 0 9px;
        font-size: 12px;
    }

    .mode-buttons {
        min-width: 0;
        overflow-x: auto;
        grid-template-columns: repeat(5, minmax(66px, 1fr));
        padding-right: 24px;
        scroll-padding-inline: 4px 24px;
        scrollbar-width: thin;
        scrollbar-color: var(--accent) color-mix(in srgb, var(--surface-2) 70%, transparent);
        box-shadow: inset -14px 0 12px -12px var(--accent);
    }

    .mode-btn {
        font-size: 11px;
    }

    .board-wrapper {
        min-height: 330px;
        padding: 14px 10px 10px;
    }

    .board-header {
        min-height: 58px;
        align-items: stretch;
        flex-direction: column;
        gap: 8px;
    }

    .board-kicker {
        font-size: 8px;
        letter-spacing: .8px;
    }

    .category-title {
        max-width: 100%;
        font-size: 19px;
    }

    .board-utility {
        width: 100%;
        flex-wrap: nowrap;
        justify-content: space-between;
    }

    .game-stats {
        flex: 1;
        gap: 5px;
    }

    .stat-box {
        min-width: 0;
        flex: 1;
        min-height: 42px;
        padding: 5px 7px;
    }

    .stat-box .value {
        font-size: 13px;
    }

    .reset-btn {
        width: 44px;
        min-width: 44px;
        padding: 0;
    }

    .reset-btn span {
        display: none;
    }

    .grid-container {
        --card-size: min(18vw, 70px);
        margin: 14px auto;
        gap: 7px;
    }

    .card-back::after {
        font-size: 28px;
    }

    .card-front {
        padding: 6px;
    }

    .board-footer {
        font-size: 9px;
    }

    .icon-stats {
        gap: 9px;
    }

    .board-tip {
        display: none;
    }

    .modal-overlay {
        padding: 10px;
        align-items: flex-end;
    }

    .modal-content {
        width: 100%;
        max-height: calc(100vh - 20px);
        padding: 22px 16px 18px;
    }

    .gallery-list,
    .shop-grid {
        grid-template-columns: 1fr;
    }

    .shop-card {
        min-height: 220px;
    }

    .discount-row {
        grid-template-columns: 1fr 90px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* Keep the game stage comfortably framed when mobile play begins. */
@media (max-width: 760px) {
    .board-wrapper { scroll-margin-top: 16px; }
    .game-wrapper { padding-bottom: 60px; }
}

/* Keep the reward hierarchy above the later Night and generic button cascade. */
body[data-theme="night"] .victory-modal h2,
body[data-theme="night"] .victory-modal .victory-copy,
body[data-theme="night"] .victory-modal .victory-eyebrow {
    color: #f4f1e7;
}

body[data-theme="night"] .victory-modal .victory-eyebrow { color: #b9c8dc; }

.victory-modal .victory-actions .retry-btn,
body[data-theme="night"] .victory-modal .victory-actions .retry-btn {
    border-color: var(--accent);
    color: var(--accent-ink);
    background: var(--accent);
    box-shadow: 0 4px 0 color-mix(in srgb, var(--accent) 68%, #111d31), 0 10px 18px color-mix(in srgb, var(--accent) 25%, transparent);
}

.victory-modal .victory-actions .retry-btn:hover,
body[data-theme="night"] .victory-modal .victory-actions .retry-btn:hover {
    border-color: var(--accent);
    color: var(--accent-ink);
    background: color-mix(in srgb, var(--accent) 86%, white);
}

.victory-modal .victory-actions .surprise-btn,
body[data-theme="night"] .victory-modal .victory-actions .surprise-btn,
.victory-modal .victory-actions .browse-btn,
body[data-theme="night"] .victory-modal .victory-actions .browse-btn {
    border-color: var(--line);
    color: var(--text);
    background: transparent;
    box-shadow: none;
}

.victory-modal .victory-actions .surprise-btn:hover,
body[data-theme="night"] .victory-modal .victory-actions .surprise-btn:hover {
    border-color: color-mix(in srgb, var(--reward) 60%, var(--line));
    color: var(--reward);
    background: color-mix(in srgb, var(--reward) 10%, var(--theme-surface));
}

/* Night colors are explicit here because this is the terminal victory cascade. */
body[data-theme="night"] .victory-modal .victory-actions .retry-btn,
body[data-theme="night"] .victory-modal .victory-actions .retry-btn:hover {
    border-color: #9bc8ef;
    color: #0b1829;
    background: #9bc8ef;
    box-shadow: 0 4px 0 #557da5, 0 12px 22px rgba(120, 168, 214, .28);
}

body[data-theme="night"] .victory-modal .victory-actions .surprise-btn,
body[data-theme="night"] .victory-modal .victory-actions .browse-btn {
    border-color: #4f6d91;
    color: #e8f0fa;
    background: transparent;
    box-shadow: none;
}

body[data-theme="night"] .victory-modal .victory-actions .surprise-btn:hover {
    border-color: #d3a863;
    color: #f3d8a3;
    background: rgba(211, 168, 99, .10);
}

body[data-theme="night"] .victory-modal .victory-actions .browse-btn:hover {
    border-color: #9bc8ef;
    color: #e8f0fa;
    background: rgba(155, 200, 239, .10);
}

/* Final action hierarchy for the Focus Trail reward moment. */
.victory-modal .victory-actions .next-challenge-btn {
    grid-column: 1 / -1;
    border-color: var(--accent);
    color: var(--accent-ink);
    background: var(--accent);
    box-shadow: 0 4px 0 color-mix(in srgb, var(--accent) 70%, #203529), 0 10px 18px color-mix(in srgb, var(--accent) 22%, transparent);
}
.victory-modal .victory-actions .retry-btn {
    grid-column: auto;
    border-color: var(--line);
    color: var(--text);
    background: transparent;
    box-shadow: none;
}
body[data-theme="night"] .victory-modal .victory-actions .next-challenge-btn,
body[data-theme="night"] .victory-modal .victory-actions .next-challenge-btn:hover {
    border-color: #9bc8ef;
    color: #0b1829;
    background: #9bc8ef;
    box-shadow: 0 4px 0 #557da5, 0 12px 22px rgba(120, 168, 214, .28);
}
body[data-theme="night"] .victory-modal .victory-actions .retry-btn,
body[data-theme="night"] .victory-modal .victory-actions .retry-btn:hover {
    border-color: #4f6d91;
    color: #e8f0fa;
    background: transparent;
    box-shadow: none;
}

/* Final Focus Trail cascade. */
.victory-modal .victory-actions .next-challenge-btn {
    grid-column: 1 / -1;
    border-color: var(--accent);
    color: var(--accent-ink);
    background: var(--accent);
    box-shadow: 0 4px 0 color-mix(in srgb, var(--accent) 70%, #203529), 0 10px 18px color-mix(in srgb, var(--accent) 22%, transparent);
}
.victory-modal .victory-actions .retry-btn {
    grid-column: auto;
    border-color: var(--line);
    color: var(--text);
    background: transparent;
    box-shadow: none;
}
body[data-theme="night"] .victory-modal .victory-actions .next-challenge-btn,
body[data-theme="night"] .victory-modal .victory-actions .next-challenge-btn:hover {
    border-color: #9bc8ef;
    color: #0b1829;
    background: #9bc8ef;
    box-shadow: 0 4px 0 #557da5, 0 12px 22px rgba(120, 168, 214, .28);
}
body[data-theme="night"] .victory-modal .victory-actions .retry-btn,
body[data-theme="night"] .victory-modal .victory-actions .retry-btn:hover {
    border-color: #4f6d91;
    color: #e8f0fa;
    background: transparent;
    box-shadow: none;
}

/* Focus Trail: a small continuation cue within the reward moment. */
.focus-trail {
    width: min(320px, 100%);
    margin: 14px auto 0;
    padding: 12px 14px;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 12px;
    align-items: center;
    border: 1px solid color-mix(in srgb, var(--accent) 26%, var(--line));
    border-radius: 14px;
    background: color-mix(in srgb, var(--theme-bg-2) 20%, var(--theme-surface));
}

.focus-trail-copy { display: grid; gap: 1px; white-space: nowrap; }
.focus-trail-copy span { color: var(--muted); font-size: 11px; font-weight: 900; }
.focus-trail-copy strong { color: var(--text); font-size: 17px; line-height: 1.15; }
.focus-trail-copy small { color: var(--accent); font-size: 11px; font-weight: 800; }
.focus-trail-segments { display: grid; grid-template-columns: repeat(10, 1fr); gap: 3px; align-items: center; }
.focus-trail-segments span { height: 8px; border-radius: 999px; background: color-mix(in srgb, var(--line) 66%, transparent); }
.focus-trail-segments span.is-complete { background: var(--accent); box-shadow: 0 2px 5px color-mix(in srgb, var(--accent) 35%, transparent); }

.victory-actions .next-challenge-btn {
    grid-column: 1 / -1;
    border-color: var(--accent);
    color: var(--accent-ink);
    background: var(--accent);
    box-shadow: 0 4px 0 color-mix(in srgb, var(--accent) 70%, #203529), 0 10px 18px color-mix(in srgb, var(--accent) 22%, transparent);
}
.victory-actions .next-challenge-btn:hover { color: var(--accent-ink); background: color-mix(in srgb, var(--accent) 88%, white); }
.victory-actions .retry-btn { grid-column: auto; color: var(--text); background: transparent; box-shadow: none; }

body[data-theme="night"] .focus-trail { border-color: #405879; background: #1b2a43; }
body[data-theme="night"] .focus-trail-copy strong { color: #f4f1e7; }
body[data-theme="night"] .focus-trail-copy span { color: #b9c8dc; }
body[data-theme="night"] .focus-trail-copy small { color: #9bc8ef; }
body[data-theme="night"] .focus-trail-segments span { background: #344d6d; }
body[data-theme="night"] .focus-trail-segments span.is-complete { background: #9bc8ef; }
body[data-theme="night"] .victory-modal .victory-actions .next-challenge-btn,
body[data-theme="night"] .victory-modal .victory-actions .next-challenge-btn:hover {
    border-color: #9bc8ef;
    color: #0b1829;
    background: #9bc8ef;
    box-shadow: 0 4px 0 #557da5, 0 12px 22px rgba(120, 168, 214, .28);
}
body[data-theme="night"] .victory-modal .victory-actions .retry-btn,
body[data-theme="night"] .victory-modal .victory-actions .browse-btn {
    border-color: #4f6d91;
    color: #e8f0fa;
    background: transparent;
    box-shadow: none;
}

@media (max-width: 420px) {
    .focus-trail { grid-template-columns: 1fr; gap: 9px; padding: 11px 12px; }
    .focus-trail-copy { grid-template-columns: 1fr auto; align-items: center; }
    .focus-trail-copy small { grid-column: 1 / -1; }
}

/* Category gallery: fixed header and a single, intentional results scroller. */
.theme-modal .modal-content {
    width: min(1100px, 100%);
    height: min(808px, calc(100dvh - 48px));
    max-height: min(808px, calc(100dvh - 48px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.theme-modal .gallery-header {
    flex: 0 0 auto;
}

.theme-modal .gallery-list {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    margin-top: 14px;
    padding: 2px 9px 4px 0;
    align-content: start;
    overscroll-behavior: contain;
    scrollbar-color: var(--accent) transparent;
    scrollbar-width: thin;
}

.theme-modal .gallery-list::-webkit-scrollbar {
    width: 8px;
}

.theme-modal .gallery-list::-webkit-scrollbar-thumb {
    border: 2px solid transparent;
    border-radius: 999px;
    background: var(--accent);
    background-clip: padding-box;
}

.theme-modal .theme-card {
    padding: 12px;
}

.theme-modal .preview-stack {
    height: 84px;
}

.theme-modal .preview-img {
    width: 64px;
    height: 64px;
    margin: 0 -15px;
}

.theme-modal .theme-card h3 {
    margin: 8px 0;
}

@media (max-width: 560px) {
    .theme-modal {
        align-items: center;
    }

    .theme-modal .modal-content {
        height: calc(100dvh - 20px);
        max-height: calc(100dvh - 20px);
        padding: 20px 14px 14px;
    }

    .theme-modal .gallery-list {
        margin-top: 12px;
        padding-right: 6px;
        gap: 10px;
    }

    .theme-modal .theme-card {
        padding: 11px;
    }

    .theme-modal .preview-stack {
        height: 78px;
    }
}

/* Night needs explicit reward controls: these colors cannot inherit a light-theme ink token. */
body[data-theme="night"] .victory-modal .victory-actions .retry-btn,
body[data-theme="night"] .victory-modal .victory-actions .retry-btn:hover {
    border-color: #9bc8ef;
    color: #0b1829;
    background: #9bc8ef;
    box-shadow: 0 4px 0 #557da5, 0 12px 22px rgba(120, 168, 214, .28);
}

body[data-theme="night"] .victory-modal .victory-actions .surprise-btn,
body[data-theme="night"] .victory-modal .victory-actions .browse-btn {
    border-color: #4f6d91;
    color: #e8f0fa;
    background: transparent;
}

body[data-theme="night"] .victory-modal .victory-actions .surprise-btn:hover {
    border-color: #d3a863;
    color: #f3d8a3;
    background: rgba(211, 168, 99, .10);
}

body[data-theme="night"] .victory-modal .victory-actions .browse-btn:hover {
    border-color: #9bc8ef;
    color: #e8f0fa;
    background: rgba(155, 200, 239, .10);
}

/* Victory modal: a compact reward moment, intentionally isolated from generic modal rules. */
.victory-modal .victory-content {
    width: min(540px, calc(100% - 28px));
    padding: 26px 28px 24px;
    overflow: hidden;
    border: 1px solid color-mix(in srgb, var(--accent) 24%, var(--line));
    border-radius: 22px;
    background: linear-gradient(145deg, color-mix(in srgb, var(--theme-surface) 92%, white), var(--theme-surface));
    box-shadow: 0 26px 64px rgba(30, 25, 18, .22);
}

.victory-modal .close-modal-btn {
    top: 14px;
    right: 14px;
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border: 1px solid transparent;
    border-radius: 50%;
    color: var(--muted);
    background: transparent;
    font-size: 30px;
    line-height: 1;
}

.victory-modal .close-modal-btn:hover,
.victory-modal .close-modal-btn:focus-visible {
    border-color: var(--line);
    color: var(--text);
    background: color-mix(in srgb, var(--theme-bg-2) 45%, var(--theme-surface));
}

.victory-hero {
    display: grid;
    justify-items: center;
    text-align: center;
}

.victory-mark {
    width: 54px;
    height: 54px;
    display: grid;
    place-items: center;
    margin-bottom: 9px;
    border: 1px solid color-mix(in srgb, var(--reward) 38%, var(--line));
    border-radius: 18px;
    color: var(--reward);
    background: color-mix(in srgb, var(--reward) 13%, var(--theme-surface));
    box-shadow: 0 8px 20px color-mix(in srgb, var(--reward) 17%, transparent);
    font-size: 24px;
}

.victory-eyebrow {
    margin: 0 0 3px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
}

.victory-modal h2 {
    margin: 0;
    font-size: clamp(26px, 5vw, 33px);
}

.victory-modal h2 i { display: none; }

.victory-modal .star-rating {
    margin: 10px 0 0;
    color: var(--reward);
    font-size: 29px;
    line-height: 1;
    letter-spacing: 3px;
}

.victory-stats {
    width: min(260px, 100%);
    margin: 20px auto 0;
    grid-template-columns: 1fr;
}

.victory-stats .stat-item {
    min-height: 76px;
    padding: 11px 18px 12px;
    border-color: color-mix(in srgb, var(--accent) 28%, var(--line));
    border-radius: 15px;
    background: color-mix(in srgb, var(--theme-bg-2) 28%, var(--theme-surface));
}

.victory-stats .stat-item .label { font-size: 11px; }
.victory-stats .stat-item .value { color: var(--accent); font-size: 31px; line-height: 1; }

.victory-actions {
    margin-top: 20px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
}

.victory-actions .action-btn {
    min-width: 0;
    min-height: 46px;
    padding: 0 12px;
    font-size: 13px;
}

.victory-actions .retry-btn {
    grid-column: 1 / -1;
    color: var(--accent-ink);
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 4px 0 color-mix(in srgb, var(--accent) 70%, #203529), 0 10px 18px color-mix(in srgb, var(--accent) 22%, transparent);
}

.victory-actions .retry-btn:hover { color: var(--accent-ink); background: color-mix(in srgb, var(--accent) 88%, white); }
.victory-actions .surprise-btn { color: var(--text); background: transparent; }
.victory-actions .surprise-btn:hover { color: var(--reward); background: color-mix(in srgb, var(--reward) 10%, var(--theme-surface)); }

body[data-theme="night"] .victory-modal .victory-content {
    border-color: #405879;
    background: linear-gradient(145deg, #192941, #111d31);
    box-shadow: 0 26px 64px rgba(0, 0, 0, .48);
}

body[data-theme="night"] .victory-modal .close-modal-btn:hover,
body[data-theme="night"] .victory-modal .close-modal-btn:focus-visible,
body[data-theme="night"] .victory-stats .stat-item { background: #1b2a43; }

@media (max-width: 420px) {
    .victory-modal .victory-content { padding: 24px 16px 18px; border-radius: 18px; }
    .victory-mark { width: 48px; height: 48px; margin-bottom: 7px; border-radius: 15px; font-size: 21px; }
    .victory-modal .star-rating { font-size: 25px; letter-spacing: 1px; }
    .victory-stats { margin-top: 17px; }
    .victory-actions { margin-top: 17px; gap: 7px; }
    .victory-actions .action-btn { min-height: 44px; padding: 0 7px; font-size: 12px; }
}

/* Night: a restrained moonlit palette with deliberate contrast at every layer. */
body[data-theme="night"] header,
body[data-theme="night"] footer {
    background: rgba(8, 14, 29, .8);
}

body[data-theme="night"] .brand-emblem,
body[data-theme="night"] .btn-login,
body[data-theme="night"] .btn-logout,
body[data-theme="night"] .action-btn:not(.surprise-btn):not(.shop-btn):not(.reset-btn) {
    background: #182740;
    border-color: #405b7d;
    color: #edf2f4;
}

body[data-theme="night"] .btn-login:hover,
body[data-theme="night"] .btn-logout:hover,
body[data-theme="night"] .action-btn:not(.surprise-btn):not(.shop-btn):not(.reset-btn):hover {
    background: #203452;
    border-color: #78a8d6;
    color: #f4f1e7;
}

body[data-theme="night"] .surprise-btn {
    background: #c99954;
    border-color: #e1bb7b;
    color: #161b26;
}

body[data-theme="night"] .surprise-btn:hover {
    background: #d8ad69;
    color: #101725;
}

body[data-theme="night"] .mode-buttons {
    background: #0c1628;
    border-color: #3a5274;
    box-shadow: inset 0 1px rgba(184, 208, 236, .08);
}

body[data-theme="night"] .mode-btn {
    color: #b7c8db;
}

body[data-theme="night"] .mode-btn:hover {
    background: #172640;
    color: #f4f1e7;
}

body[data-theme="night"] .mode-btn.active {
    background: #78a8d6;
    color: #0c1a2d;
    box-shadow: 0 3px 9px rgba(81, 137, 190, .3);
}

body[data-theme="night"] .mode-btn.is-locked i {
    color: #d3a863;
}

body[data-theme="night"] .board-header,
body[data-theme="night"] .board-footer {
    border-color: #354b6b;
}

body[data-theme="night"] .stat-box,
body[data-theme="night"] .board-actions {
    background: #1a2a44;
    border-color: #405879;
}

body[data-theme="night"] .stat-box .label,
body[data-theme="night"] .board-kicker,
body[data-theme="night"] .board-footer,
body[data-theme="night"] .board-tip,
body[data-theme="night"] .footer,
body[data-theme="night"] .footer > div span,
body[data-theme="night"] .footer-link,
body[data-theme="night"] .footer-links a {
    color: #acbbcf;
}

body[data-theme="night"] .card-back {
    border-color: #6f94c1;
    background: linear-gradient(145deg, #2e476f, #14213a);
    box-shadow: inset 0 0 0 3px rgba(8, 16, 31, .42), inset 0 1px rgba(220, 234, 247, .18), 0 10px 18px rgba(0, 0, 0, .28);
}

body[data-theme="night"] .card-back::before {
    border-color: rgba(202, 220, 238, .44);
}

body[data-theme="night"] .card-back::after {
    color: #f5f0df;
    text-shadow: 0 2px 0 #17243b, 0 0 12px rgba(200, 219, 239, .24);
}

body[data-theme="night"] .card-front {
    background: #edf1ef;
    border-color: #7e9abe;
}

body[data-theme="night"] .reset-btn,
body[data-theme="night"] .shop-btn {
    background: #4f789e;
    border-color: #83afda;
    color: #f7f3e8;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}

/* Tabletop memory-game refresh */
:root {
    --radius-sm: 10px;
    --radius: 16px;
    --shadow-sm: 0 8px 18px rgba(55, 42, 28, .09);
    --shadow-md: 0 22px 50px rgba(55, 42, 28, .14);
    --shadow-glow: 0 12px 28px color-mix(in srgb, var(--theme-accent) 15%, transparent);
    --surface-0: var(--theme-bg-1);
    --surface-1: var(--theme-surface);
    --surface-2: color-mix(in srgb, var(--theme-surface) 90%, var(--theme-bg-2));
    --surface-3: color-mix(in srgb, var(--theme-surface) 78%, var(--theme-bg-2));
    --line: var(--theme-line, color-mix(in srgb, var(--theme-accent) 22%, white));
    --line-strong: color-mix(in srgb, var(--theme-accent) 60%, var(--theme-line, white));
    --text: var(--theme-ink);
    --muted: var(--theme-muted, color-mix(in srgb, var(--theme-ink) 65%, transparent));
    --faint: color-mix(in srgb, var(--theme-muted, var(--theme-ink)) 72%, transparent);
    --accent: var(--theme-accent);
    --accent-ink: #fffdf8;
    --reward: var(--theme-reward, #c8874b);
}

html { background: var(--theme-bg-1); }

body {
    background: linear-gradient(135deg, var(--theme-bg-1), var(--theme-bg-2));
}

body::before {
    background:
        radial-gradient(circle at 12% 8%, color-mix(in srgb, white 42%, transparent), transparent 22%),
        radial-gradient(circle at 88% 86%, color-mix(in srgb, var(--theme-accent) 12%, transparent), transparent 26%);
    opacity: .75;
}

body[data-theme="paper"]::before {
    background: radial-gradient(circle at 18% 2%, rgba(255,255,255,.66), transparent 29%), repeating-linear-gradient(0deg, rgba(111,80,39,.025) 0 1px, transparent 1px 5px);
    opacity: 1;
}

body[data-theme="night"]::before {
    background: radial-gradient(circle at 13% 0%, rgba(104,145,193,.16), transparent 29%), radial-gradient(circle at 84% 76%, rgba(44,83,133,.12), transparent 34%);
    opacity: 1;
}

body[data-theme="candy"]::before {
    background: radial-gradient(circle at 10% 5%, rgba(255,255,255,.62), transparent 27%), radial-gradient(circle at 90% 80%, rgba(195,81,119,.18), transparent 30%);
    opacity: 1;
}

header {
    min-height: 78px;
    border-bottom: 1px solid color-mix(in srgb, var(--theme-line, var(--line)) 75%, transparent);
}

.brand-lockup { gap: 11px; }

.brand-emblem {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    color: var(--accent);
    background: color-mix(in srgb, var(--theme-surface) 88%, var(--theme-bg-2));
    box-shadow: none;
}

.main-title { font-size: clamp(28px, 2.1vw, 34px); }
.tag-line { margin-top: 5px; color: var(--muted); font-size: 9px; font-weight: 700; letter-spacing: 1.4px; }

.btn-login, .btn-logout {
    border-color: var(--line);
    border-radius: 12px;
    color: var(--text);
    background: color-mix(in srgb, var(--theme-surface) 78%, var(--theme-bg-2));
    box-shadow: none;
    font-weight: 800;
}

.game-wrapper { padding-top: 20px; padding-bottom: 34px; }

.controls-wrapper {
    padding: 0;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 18px;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}

.main-actions {
    grid-template-columns: repeat(4, max-content);
    gap: 8px;
}

.action-btn {
    min-height: 44px;
    padding: 0 14px;
    border-color: var(--line);
    border-radius: 12px;
    color: var(--text);
    background: color-mix(in srgb, var(--theme-surface) 84%, var(--theme-bg-2));
    box-shadow: 0 3px 0 color-mix(in srgb, var(--theme-line, var(--line)) 85%, transparent), 0 7px 14px rgba(57, 44, 30, .06);
    font-size: 13px;
    font-weight: 800;
    overflow: visible;
}

.action-btn::before { display: none; }
.action-btn i { width: auto; height: auto; background: transparent; font-size: 14px; }
.action-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--theme-surface); box-shadow: 0 3px 0 color-mix(in srgb, var(--accent) 54%, transparent), 0 10px 18px rgba(57,44,30,.10); transform: translateY(-2px); }

.surprise-btn { border-color: color-mix(in srgb, var(--reward) 70%, var(--line)); color: #fffdf8; background: var(--reward); }
.surprise-btn:hover { border-color: var(--reward); color: #fffdf8; background: color-mix(in srgb, var(--reward) 88%, white); box-shadow: 0 3px 0 color-mix(in srgb, var(--reward) 75%, #5e3b21), 0 10px 18px rgba(57,44,30,.12); }
.browse-btn { background: color-mix(in srgb, var(--theme-surface) 80%, var(--theme-bg-2)); }
.shop-btn { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); color: var(--accent-ink); background: var(--accent); }
.shop-btn:hover { color: var(--accent-ink); background: color-mix(in srgb, var(--accent) 88%, black); }
.appearance-btn { min-width: 44px; padding-inline: 12px; }

.mode-buttons {
    min-width: 490px;
    min-height: 46px;
    padding: 3px;
    gap: 2px;
    border-color: var(--line);
    border-radius: 13px;
    background: color-mix(in srgb, var(--theme-surface) 72%, var(--theme-bg-2));
    box-shadow: inset 0 1px rgba(255,255,255,.5);
}

.mode-btn { min-height: 38px; border-radius: 10px; color: var(--muted); font-weight: 800; }
.mode-btn:hover { color: var(--text); background: color-mix(in srgb, var(--theme-bg-2) 44%, var(--theme-surface)); }
.mode-btn.active { border-color: transparent; color: var(--accent-ink); background: var(--accent); box-shadow: 0 3px 8px color-mix(in srgb, var(--accent) 26%, transparent); }
.mode-btn.is-locked i { color: var(--reward); }

.visual-theme-strip {
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.appearance-content { width: min(560px, 100%); }
.appearance-header { margin-bottom: 18px; padding-right: 26px; }
.appearance-header > span { color: var(--accent); font-size: 12px; font-weight: 900; }
.appearance-header h2 { margin: 3px 0 5px; font-size: 28px; line-height: 1.15; }
.appearance-header p { margin: 0; color: var(--muted); font-size: 14px; }

.theme-chip {
    min-width: 0;
    min-height: 78px;
    padding: 12px;
    grid-template-columns: 34px 1fr;
    gap: 10px;
    border-color: var(--line);
    border-radius: 12px;
    color: var(--text);
    background: var(--surface-2);
    font-size: 13px;
    text-align: left;
}
.theme-chip.active { border-color: var(--accent); color: var(--text); background: color-mix(in srgb, var(--accent) 10%, var(--theme-surface)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 13%, transparent); }
.theme-swatch { width: 34px; height: 50px; border-radius: 9px; }
.premium-badge { margin-top: -12px; color: var(--reward); }

.board-wrapper {
    min-height: 0;
    margin-top: 22px;
    padding: 22px clamp(16px, 3vw, 42px) 16px;
    border-color: color-mix(in srgb, var(--theme-line, var(--line)) 88%, white);
    border-radius: 20px;
    background: var(--theme-surface);
    box-shadow: var(--shadow-md);
    overflow: visible;
}

.board-wrapper::before { display: none; }

body[data-theme="garden"] .board-wrapper { background: linear-gradient(135deg, #fffdf8, #f4f8ef); }
body[data-theme="paper"] .board-wrapper { background: linear-gradient(135deg, #fffaf0, #f5e9d1); }
body[data-theme="night"] .board-wrapper { border-color: #3a4f70; background: linear-gradient(145deg, #192941, #111d31); color: #f4f1e7; box-shadow: 0 24px 54px rgba(0,0,0,.34); }
body[data-theme="candy"] .board-wrapper { background: linear-gradient(135deg, #fffafa, #fff1f0); }
body[data-theme="night"] .board-wrapper .category-title, body[data-theme="night"] .board-wrapper .stat-box .value { color: #f4f1e7; }
body[data-theme="night"] .board-wrapper .stat-box, body[data-theme="night"] .board-wrapper .board-actions { background: #1b2a43; border-color: #405879; }

.board-header { min-height: 58px; padding-bottom: 15px; gap: 14px; border-bottom-color: var(--line); }
.board-kicker { color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .2px; text-transform: none; }
.category-title { margin-top: 4px; font-family: "Quicksand", "Nunito", sans-serif; font-size: clamp(25px, 2.1vw, 34px); }
.board-utility, .game-stats { gap: 7px; }
.stat-box { min-width: 72px; min-height: 44px; border-color: var(--line); border-radius: 10px; background: color-mix(in srgb, var(--theme-bg-2) 26%, var(--theme-surface)); }
.stat-box .label { color: var(--muted); font-size: 9px; letter-spacing: .5px; }
.stat-box .value { color: var(--text); }

.welcome-msg { min-height: 300px; color: var(--muted); }
.grid-container { --card-size: clamp(86px, 6vw, 108px); margin: 28px auto 22px; gap: 12px; perspective: 1000px; }
.memory-card { border-radius: 14px; }
.memory-card:hover { transform: translateY(-4px) rotate(-.5deg); filter: none; }
.card-back, .card-front { border-radius: 14px; }
.card-back { border-color: color-mix(in srgb, var(--theme-card-a) 68%, white); background: linear-gradient(145deg, var(--theme-card-a), var(--theme-card-b)); box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--theme-card-b) 54%, transparent), inset 0 1px rgba(255,255,255,.32), 0 8px 14px rgba(55,42,28,.18); }
.card-back::before { inset: 8px; border-color: color-mix(in srgb, white 35%, transparent); background: none; }
.card-back::after { font-size: clamp(36px, 3vw, 48px); text-shadow: 0 2px 0 rgba(0,0,0,.13); }
.card-front { border-color: color-mix(in srgb, var(--theme-card-a) 44%, white); background: #fffdf8; box-shadow: 0 8px 14px rgba(55,42,28,.16); }
.memory-card.matched .card-front { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 27%, transparent), 0 8px 14px rgba(55,42,28,.14); }
.grid-container.is-previewing .memory-card { cursor: default; }
.grid-container.is-previewing .memory-card:hover { transform: none; }

@media (prefers-reduced-motion: reduce) {
    .card-inner { transition-duration: .16s; }
}

.board-actions {
    min-height: 58px;
    margin: 0 auto;
    padding: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: color-mix(in srgb, var(--theme-bg-2) 28%, var(--theme-surface));
}
.board-actions .action-btn { min-width: 116px; }
.hint-btn.is-locked { border-style: solid; color: var(--muted); background: color-mix(in srgb, var(--theme-surface) 76%, var(--theme-bg-2)); }
.hint-btn.hint-used { opacity: .52; }
.reset-btn { border-color: color-mix(in srgb, var(--accent) 48%, var(--line)); color: var(--accent-ink); background: var(--accent); }
.reset-btn:hover { color: var(--accent-ink); background: color-mix(in srgb, var(--accent) 86%, black); }

.board-footer { min-height: 42px; padding-top: 13px; border-top: 0; color: var(--muted); font-size: 11px; font-weight: 700; }
.board-tip { color: var(--muted); }

footer { border-top-color: color-mix(in srgb, var(--theme-line, var(--line)) 72%, transparent); background: color-mix(in srgb, var(--theme-surface) 30%, transparent); }
.footer { min-height: 76px; color: var(--muted); font-size: 12px; font-weight: 600; }
.footer > div span, .footer-link, .footer-links a { color: var(--muted); font-weight: 700; }

@media (max-width: 1180px) {
    .controls-wrapper { grid-template-columns: 1fr; gap: 12px; }
    .main-actions { justify-content: center; }
    .mode-buttons { min-width: 0; width: min(100%, 680px); margin: 0 auto; }
}

@media (max-width: 820px) {
    :root { --content: min(100% - 24px, 720px); }
    header { min-height: 70px; }
    .main-actions { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
    .main-actions .action-btn { padding: 0 8px; font-size: 12px; }
    .main-actions .action-btn span { display: none; }
    .main-actions .appearance-btn { min-width: 44px; }
    .mode-buttons { min-width: 0; }
    .board-wrapper { margin-top: 18px; }
    .grid-container { --card-size: min(17.5vw, 88px); gap: 9px; }
}

@media (max-width: 560px) {
    :root { --content: calc(100% - 20px); }
    .brand-emblem { width: 36px; height: 36px; }
    .main-title { font-size: 28px; }
    .tag-line { display: none; }
    .btn-login { width: 44px; min-width: 44px; padding: 0; }
    .btn-login span { display: none; }
    .game-wrapper { padding-top: 14px; }
    .controls-wrapper, .main-actions, .board-wrapper, .board-utility { min-width: 0; width: 100%; }
    .main-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .main-actions .action-btn { min-height: 46px; padding: 0 8px; font-size: 12px; white-space: nowrap; }
    .main-actions .action-btn span { display: inline; }
    .mode-buttons { overflow-x: auto; grid-template-columns: repeat(5, minmax(70px, 1fr)); }
    .mode-btn { min-height: 40px; }
    .board-wrapper { padding: 17px 10px 11px; border-radius: 16px; }
    .board-header { align-items: flex-start; flex-direction: column; }
    .board-utility { width: 100%; justify-content: stretch; }
    .game-stats { width: 100%; }
    .stat-box { min-width: 0; flex: 1; }
    .mode-stat { display: grid; }
    .grid-container { --card-size: min(19.5vw, 80px); margin: 22px auto 18px; gap: 7px; }
    .card-back::after { font-size: 34px; }
    .board-actions { min-height: 56px; }
    .board-actions .action-btn { flex: 1; min-width: 0; }
    .board-footer { min-height: 34px; font-size: 10px; }
    .board-tip { display: none; }
    .appearance-content { padding: 22px 16px 18px; }
    .visual-theme-strip { grid-template-columns: 1fr; }
    .theme-chip { min-height: 64px; }
    .theme-swatch { height: 38px; }
}

/* Final Night victory controls: retained after every shared control rule. */
body[data-theme="night"] .victory-modal .victory-actions .retry-btn,
body[data-theme="night"] .victory-modal .victory-actions .retry-btn:hover {
    border-color: #9bc8ef;
    color: #0b1829;
    background: #9bc8ef;
    box-shadow: 0 4px 0 #557da5, 0 12px 22px rgba(120, 168, 214, .28);
}

body[data-theme="night"] .victory-modal .victory-actions .surprise-btn,
body[data-theme="night"] .victory-modal .victory-actions .browse-btn {
    border-color: #4f6d91;
    color: #e8f0fa;
    background: transparent;
    box-shadow: none;
}

body[data-theme="night"] .victory-modal .victory-actions .surprise-btn:hover {
    border-color: #d3a863;
    color: #f3d8a3;
    background: rgba(211, 168, 99, .10);
}

body[data-theme="night"] .victory-modal .victory-actions .browse-btn:hover {
    border-color: #9bc8ef;
    color: #e8f0fa;
    background: rgba(155, 200, 239, .10);
}

/* Final victory cascade: must remain after all shared Night/button rules. */
body[data-theme="night"] .victory-modal h2,
body[data-theme="night"] .victory-modal .victory-copy,
body[data-theme="night"] .victory-modal .victory-eyebrow {
    color: #f4f1e7;
}

body[data-theme="night"] .victory-modal .victory-eyebrow { color: #b9c8dc; }

.victory-modal .victory-actions .retry-btn {
    border-color: var(--accent);
    color: var(--accent-ink);
    background: var(--accent);
}

.victory-modal .victory-actions .surprise-btn,
.victory-modal .victory-actions .browse-btn {
    border-color: var(--line);
    color: var(--text);
    background: transparent;
    box-shadow: none;
}

/* Explicit Night values prevent light-theme text and generic action rules leaking in. */
body[data-theme="night"] .victory-modal .victory-actions .retry-btn,
body[data-theme="night"] .victory-modal .victory-actions .retry-btn:hover {
    border-color: #9bc8ef;
    color: #0b1829;
    background: #9bc8ef;
    box-shadow: 0 4px 0 #557da5, 0 12px 22px rgba(120, 168, 214, .28);
}

body[data-theme="night"] .victory-modal .victory-actions .surprise-btn,
body[data-theme="night"] .victory-modal .victory-actions .browse-btn {
    border-color: #4f6d91;
    color: #e8f0fa;
    background: transparent;
    box-shadow: none;
}

body[data-theme="night"] .victory-modal .victory-actions .surprise-btn:hover {
    border-color: #d3a863;
    color: #f3d8a3;
    background: rgba(211, 168, 99, .10);
}

body[data-theme="night"] .victory-modal .victory-actions .browse-btn:hover {
    border-color: #9bc8ef;
    color: #e8f0fa;
    background: rgba(155, 200, 239, .10);
}

/* Focus Trail action hierarchy. Kept terminal so it always wins the modal cascade. */
.victory-modal .victory-actions .action-btn { min-height: 48px; box-sizing: border-box; }
.victory-modal .victory-actions .next-challenge-btn { grid-column: 1 / -1; border-color: var(--accent); color: var(--accent-ink); background: var(--accent); box-shadow: 0 4px 0 color-mix(in srgb, var(--accent) 70%, #203529), 0 10px 18px color-mix(in srgb, var(--accent) 22%, transparent); }
.victory-modal .victory-actions .retry-btn { grid-column: auto; border-color: var(--line); color: var(--text); background: transparent; box-shadow: none; }
body[data-theme="night"] .victory-modal .victory-actions .next-challenge-btn, body[data-theme="night"] .victory-modal .victory-actions .next-challenge-btn:hover { border-color: #9bc8ef !important; color: #0b1829 !important; background: #9bc8ef !important; box-shadow: 0 4px 0 #557da5, 0 12px 22px rgba(120, 168, 214, .28) !important; }
body[data-theme="night"] .victory-modal .victory-actions .retry-btn, body[data-theme="night"] .victory-modal .victory-actions .retry-btn:hover { border-color: #4f6d91 !important; color: #e8f0fa !important; background: transparent !important; box-shadow: none !important; }
