:root {
    --blue: #4ca5ff;
    --yellow: #ffd84e;
    --purple: #9a7dff;
    --green: #37c783;
    --pink: #ff74a3;
    --ink: #254468;
    --panel: #fff6c5;
    --panel-2: #f4eeff;
    --border: #ffffff;
    --tile: #95d8ff;
    --tile-2: #bfa7ff;
    --tile-hl: #ffd84e;
    --tile-ok: #45cf89;
    --tile-bad: #ff667f;
    --shadow: 0 12px 0 rgba(47, 75, 112, 0.12), 0 18px 28px rgba(19, 38, 64, 0.16);
    --grid-size: 4;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    font-family: 'Baloo 2', sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at 14% 18%, rgba(255, 255, 255, 0.85), transparent 38%),
        radial-gradient(circle at 80% 20%, rgba(255, 236, 125, 0.52), transparent 34%),
        radial-gradient(circle at 85% 82%, rgba(160, 130, 255, 0.48), transparent 38%),
        linear-gradient(150deg, #4ca5ff 0%, #5ac9ff 30%, #85dd7b 65%, #ffd84e 100%);
    cursor: auto;
}

.game-topbar {
    position: fixed;
    top: 10px;
    left: 0;
    width: 100%;
    padding: 0 14px;
    z-index: 20;
    pointer-events: none;
}

.topbar-actions {
    max-width: 980px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    pointer-events: auto;
}

.profile-icon {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    text-decoration: none;
    color: #ffffff;
    background: linear-gradient(160deg, #2b8bff, #5868ff);
    border: 3px solid var(--border);
    box-shadow: 0 8px 0 rgba(53, 84, 129, 0.22);
    font-size: 1rem;
}

.today-menu {
    position: relative;
}

.today-game-open {
    border: 3px solid var(--border);
    background: linear-gradient(165deg, #ffffff, #e9f7ff);
    color: #2c5773;
    border-radius: 999px;
    padding: 8px 15px;
    font-family: 'Fredoka', sans-serif;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 8px 0 rgba(67, 104, 146, 0.16);
}

.today-menu-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 10px);
    min-width: 215px;
    border: 3px solid var(--border);
    border-radius: 14px;
    background: #fffdf2;
    box-shadow: 0 16px 24px rgba(31, 60, 95, 0.16);
    display: none;
    overflow: hidden;
    z-index: 14;
}

.today-menu.open .today-menu-dropdown {
    display: block;
}

.today-menu-dropdown a {
    display: block;
    text-decoration: none;
    color: #315c78;
    font-family: 'Fredoka', sans-serif;
    font-size: 0.86rem;
    font-weight: 600;
    padding: 11px 13px;
    border-bottom: 1px solid #d8ecfb;
}

.today-menu-dropdown a:last-child {
    border-bottom: 0;
}

.today-menu-dropdown a:hover {
    background: #ebf7ff;
}

.memory-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px 14px;
    position: relative;
    overflow: visible;
}

.shape {
    position: absolute;
    border-radius: 50%;
    filter: blur(0.3px);
    opacity: 0.68;
    pointer-events: none;
}

.shape-a {
    width: 120px;
    height: 120px;
    left: 4vw;
    top: 20vh;
    background: rgba(255, 255, 255, 0.42);
}

.shape-b {
    width: 180px;
    height: 180px;
    right: 4vw;
    top: 30vh;
    background: rgba(255, 118, 163, 0.33);
}

.shape-c {
    width: 130px;
    height: 130px;
    left: 17vw;
    bottom: 6vh;
    background: rgba(158, 126, 255, 0.32);
}

.memory-card {
    --tile-size-max: 88px;
    --grid-gap: 11px;
    --grid-pad: 10px;
    --tile-size: clamp(46px, 9.2vh, var(--tile-size-max));
    --board-size: calc(
        (var(--grid-size) * var(--tile-size))
        + ((var(--grid-size) - 1) * var(--grid-gap))
        + (var(--grid-pad) * 2)
    );
    width: fit-content;
    max-width: 100%;
    min-width: min(calc(var(--board-size) + 40px), calc(100vw - 20px));
    border: 4px solid var(--border);
    border-radius: 28px;
    background:
        radial-gradient(circle at 12% 12%, rgba(255, 255, 255, 0.72), transparent 30%),
        linear-gradient(170deg, var(--panel), var(--panel-2));
    box-shadow: var(--shadow);
    padding: 18px 16px 16px;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.memory-card.reward-pop {
    animation: reward-pop 0.65s ease;
}

.memory-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.memory-top h1 {
    margin: 0;
    font-family: 'Fredoka', sans-serif;
    font-size: clamp(1.45rem, 3vw, 1.9rem);
    color: #255176;
    text-shadow: 0 2px 0 rgba(255, 255, 255, 0.7);
}

.memory-stats {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.hud-pill {
    margin: 0;
    border: 3px solid var(--border);
    border-radius: 999px;
    padding: 5px 10px;
    font-family: 'Fredoka', sans-serif;
    font-size: 0.84rem;
    font-weight: 700;
    box-shadow: 0 5px 0 rgba(49, 84, 117, 0.14);
}

.level-pill {
    background: #9ed2ff;
}

.score-pill {
    background: #ffe27a;
}

.score-pill.gain {
    animation: score-pill-gain 0.5s ease;
}

.star-pill {
    background: #d8bcff;
}

.achievement-strip {
    margin-top: 10px;
    text-align: center;
    font-size: 1.15rem;
    color: #ff5f93;
    letter-spacing: 0.35em;
    text-shadow: 0 0 14px rgba(255, 210, 93, 0.75);
}

.achievement-strip i {
    animation: star-float 2.6s ease-in-out infinite;
}

.achievement-strip i:nth-child(2) {
    animation-delay: 0.2s;
}

.achievement-strip i:nth-child(3) {
    animation-delay: 0.4s;
}

.memory-message {
    margin: 10px 0 8px;
    min-height: 1.5em;
    text-align: center;
    font-family: 'Fredoka', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    color: #295675;
}

.memory-message.good {
    color: #159a63;
}

.memory-message.bad {
    color: #d44260;
}

.dedication-line {
    margin: 8px 0 2px;
    text-align: center;
    font-family: 'Fredoka', sans-serif;
    font-size: 0.95rem;
    font-weight: 700;
    color: #8b3ca9;
}

.reward-banner {
    margin: 0 auto 10px;
    width: fit-content;
    max-width: 100%;
    padding: 5px 12px;
    border-radius: 999px;
    border: 3px solid #ffffff;
    background: linear-gradient(150deg, #ffd84e, #ffb43d);
    color: #6a3c05;
    font-family: 'Fredoka', sans-serif;
    font-size: 0.88rem;
    font-weight: 700;
    box-shadow: 0 6px 0 rgba(130, 86, 9, 0.2);
    opacity: 0;
    transform: translateY(8px) scale(0.95);
    pointer-events: none;
}

.reward-banner.show {
    animation: reward-banner 1.25s ease;
}

.grid-board {
    margin: 8px auto 12px;
    width: fit-content;
    height: auto;
    max-width: 100%;
    display: grid;
    gap: var(--grid-gap);
    padding: var(--grid-pad);
    border-radius: 20px;
    border: 4px solid #ffffff;
    background: linear-gradient(160deg, rgba(96, 151, 255, 0.35), rgba(158, 126, 255, 0.33));
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.4);
    align-self: center;
}

.grid-board.grid-enter {
    animation: grid-enter 0.4s ease;
}

.grid-board.shake {
    animation: grid-shake 0.35s ease;
}

.tile {
    border: 3px solid var(--border);
    border-radius: 14px;
    background: linear-gradient(160deg, var(--tile), var(--tile-2));
    box-shadow: 0 4px 0 rgba(34, 69, 105, 0.18);
    width: var(--tile-size);
    aspect-ratio: 1 / 1;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
    position: relative;
    display: grid;
    place-items: center;
}

.tile:not(:disabled):hover {
    transform: translateY(-3px);
    box-shadow: 0 7px 0 rgba(34, 69, 105, 0.18);
}

.tile.pop {
    animation: tile-pop 0.18s ease;
}

.tile.pattern {
    background: linear-gradient(155deg, var(--tile-hl), #ffbf2f);
    box-shadow: 0 0 0 3px rgba(255, 248, 218, 0.9), 0 0 24px rgba(255, 212, 54, 0.82);
    animation: tile-bounce 0.55s ease infinite;
}

.tile.selected {
    filter: brightness(1.04);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.9), 0 6px 0 rgba(34, 69, 105, 0.18);
}

.tile.correct {
    background: linear-gradient(160deg, var(--tile-ok), #1fae6f);
}

.tile.wrong {
    background: linear-gradient(160deg, var(--tile-bad), #ed3f61);
}

.tile-emoji {
    font-size: clamp(0.72rem, calc(var(--tile-size) * 0.42), 1.25rem);
    line-height: 1;
    opacity: 0;
    transform: scale(0.7);
    transition: opacity 0.15s ease, transform 0.15s ease;
    filter: drop-shadow(0 2px 0 rgba(255, 255, 255, 0.45));
    user-select: none;
    pointer-events: none;
}

.tile.pattern .tile-emoji,
.tile.selected .tile-emoji,
.tile.correct .tile-emoji,
.tile.wrong .tile-emoji {
    opacity: 1;
    transform: scale(1);
}

.tile:disabled {
    cursor: default;
}

.fx-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    border-radius: 3px;
    animation: confetti-fall 0.85s ease-out forwards;
}

.memory-actions {
    margin-top: 14px;
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.memory-actions button {
    border: 3px solid var(--border);
    border-radius: 999px;
    color: #ffffff;
    padding: 9px 16px;
    font-family: 'Fredoka', sans-serif;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 8px 0 rgba(35, 59, 94, 0.2);
}

#start-btn {
    background: linear-gradient(165deg, #4678ff, #4bc4ff);
}

.memory-actions button.alt {
    background: linear-gradient(165deg, #36cc83, #2ca671);
}

.memory-actions button.music {
    background: linear-gradient(165deg, #ff7dac, #ab6bff);
}

.memory-actions button:active {
    transform: translateY(2px);
}

.final-surprise {
    position: fixed;
    inset: 0;
    background: rgba(35, 30, 62, 0.5);
    display: none;
    place-items: center;
    z-index: 30;
    padding: 14px;
}

.final-surprise.open {
    display: grid;
}

.final-card {
    width: min(540px, 100%);
    border-radius: 24px;
    border: 4px solid #ffffff;
    background: linear-gradient(160deg, #ffd6e8, #e6d8ff);
    padding: 20px 16px;
    text-align: center;
    box-shadow: 0 16px 28px rgba(39, 24, 75, 0.24);
    animation: reward-pop 0.45s ease;
}

.final-card h2 {
    margin: 0 0 8px;
    font-family: 'Fredoka', sans-serif;
    color: #4e2e8e;
}

.final-card p {
    margin: 0 0 14px;
    font-family: 'Fredoka', sans-serif;
    color: #5d3a85;
}

.final-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.final-actions button {
    border: 3px solid #ffffff;
    border-radius: 999px;
    padding: 9px 15px;
    color: #ffffff;
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 7px 0 rgba(45, 31, 84, 0.2);
}

a,
button,
[role="button"] {
    cursor: pointer;
}

body.fancy-cursor-enabled,
body.fancy-cursor-enabled * {
    cursor: none !important;
}

.magic-cursor-heart,
.magic-cursor-ring,
.magic-star-trail {
    position: fixed;
    left: 0;
    top: 0;
    pointer-events: none;
    z-index: 9999;
}

.magic-cursor-heart {
    font-size: 13px;
    transform: translate(-100px, -100px);
    will-change: transform;
    filter: drop-shadow(0 0 6px rgba(255, 58, 95, 0.55));
}

.magic-cursor-ring {
    width: 26px;
    height: 26px;
    border: 2px solid rgba(255, 74, 108, 0.95);
    border-radius: 50%;
    transform: translate(-100px, -100px);
    will-change: transform;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.38), 0 0 16px rgba(255, 76, 115, 0.35);
    transition: transform 0.08s linear, opacity 0.2s ease;
}

.magic-cursor-ring.active {
    border-width: 3px;
    opacity: 0.8;
}

.magic-star-trail {
    font-size: 12px;
    line-height: 1;
    opacity: 0.95;
    animation: star-trail-fade 620ms ease-out forwards;
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.85);
    will-change: transform, opacity;
}

.score-float-text,
.score-float-heart {
    position: fixed;
    left: 0;
    top: 0;
    pointer-events: none;
    z-index: 10002;
    transform: translate(-50%, -50%);
    will-change: transform, opacity;
}

.score-float-text {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.08rem;
    font-weight: 700;
    color: #d23455;
    text-shadow: 0 1px 0 #fff, 0 0 10px rgba(255, 74, 108, 0.35);
    animation: score-text-pop 0.92s ease forwards;
}

.score-float-heart {
    font-size: 1.2rem;
    color: #ff4c6c;
    text-shadow: 0 0 12px rgba(255, 118, 150, 0.62);
    animation: score-heart-rise 1.2s ease-out forwards;
}

@keyframes star-trail-fade {
    0% {
        opacity: 0.95;
        transform: translate(-50%, -50%) scale(1) rotate(0deg);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, calc(-50% - 24px)) scale(0.35) rotate(18deg);
    }
}

@keyframes score-pill-gain {
    0% { transform: scale(1); }
    45% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

@keyframes score-text-pop {
    0% {
        opacity: 0;
        transform: translate(-50%, -30%) scale(0.8);
    }
    20% {
        opacity: 1;
        transform: translate(-50%, -75%) scale(1.05);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -130%) scale(0.95);
    }
}

@keyframes score-heart-rise {
    0% {
        opacity: 0.95;
        transform: translate(calc(-50% + 0px), calc(-50% + 2px)) scale(0.7);
    }
    100% {
        opacity: 0;
        transform: translate(
            calc(-50% + var(--drift-x, 0px)),
            calc(-50% - var(--rise, 42px))
        ) scale(1.05);
    }
}

#yes-btn {
    background: #5f8f62;
}

#ofcourse-btn {
    background: #e4b24a;
    color: #5f3e20;
}

#play-more-btn {
    background: #7fb36a;
    color: #f7f3e8;
}

@keyframes grid-enter {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes tile-pop {
    0% { transform: scale(1); }
    55% { transform: scale(1.11); }
    100% { transform: scale(1); }
}

@keyframes tile-bounce {
    0%, 100% { transform: translateY(0) scale(1); }
    45% { transform: translateY(-4px) scale(1.03); }
}

@keyframes grid-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-5px); }
    40% { transform: translateX(5px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

@keyframes confetti-fall {
    from {
        opacity: 1;
        transform: translate(0, 0) rotate(0deg);
    }
    to {
        opacity: 0;
        transform: translate(var(--dx), var(--dy)) rotate(var(--rot));
    }
}

@keyframes reward-banner {
    0% { opacity: 0; transform: translateY(8px) scale(0.95); }
    20% { opacity: 1; transform: translateY(0) scale(1.03); }
    80% { opacity: 1; transform: translateY(0) scale(1); }
    100% { opacity: 0; transform: translateY(-6px) scale(0.96); }
}

@keyframes reward-pop {
    0% { transform: scale(1); }
    40% { transform: scale(1.02); }
    100% { transform: scale(1); }
}

@keyframes star-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

@media (max-width: 560px) {
    .memory-card {
        --tile-size-max: 76px;
        --grid-gap: 8px;
        --grid-pad: 8px;
        --tile-size: clamp(40px, 8.1vh, var(--tile-size-max));
        border-radius: 22px;
        padding: 14px 12px 14px;
    }

    .grid-board {
        width: fit-content;
        height: auto;
    }

    .tile {
        border-radius: 12px;
    }

    .achievement-strip {
        font-size: 1rem;
    }
}

@media (max-height: 760px) {
    .memory-card {
        --tile-size-max: 72px;
        --grid-gap: 8px;
        --grid-pad: 8px;
        --tile-size: clamp(38px, 7.4vh, var(--tile-size-max));
        padding: 14px 12px 12px;
    }

    .memory-top h1 {
        font-size: clamp(1.2rem, 2.2vw, 1.55rem);
    }

    .achievement-strip {
        margin-top: 7px;
        font-size: 1rem;
    }

    .memory-message {
        margin: 7px 0 6px;
        font-size: 0.92rem;
    }

    .reward-banner {
        margin-bottom: 8px;
        padding: 4px 10px;
    }

    .grid-board {
        margin: 6px auto 10px;
        width: fit-content;
        height: auto;
    }

    .memory-actions {
        margin-top: 10px;
    }

    .memory-actions button {
        padding: 7px 13px;
        font-size: 0.82rem;
    }
}
