:root {
    --color-bg-top: #EAF7FC; /* pale sky-water */
    --color-bg-deep: #CDEEFB; /* shallow water */
    --color-paper: #FFFFFF; /* card surface */
    --color-navy: #1D3557; /* ink text — matches the JS silhouette fill */
    --color-navy-60: rgba(29, 53, 87, 0.62);
    --color-ocean: #0B6E8C; /* deep accent */
    --color-aqua: #4EA8DE; /* secondary accent — matches JS particle burst color */
    --color-coral: #FF6B6B; /* wrong / warm accent */
    --color-sand: #FFEFD6; /* shadow-column bed */
    --color-gold: #FFD93D; /* stars */
    --radius-lg: 32px;
    --radius-md: 18px;
    --shadow-card: 0 14px 0 rgba(11, 79, 108, 0.10), 0 24px 40px rgba(11, 79, 108, 0.16);
    --font-display: 'Baloo 2', system-ui, sans-serif;
    --font-body: 'Nunito', system-ui, sans-serif;
}
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}
html,
body {
    height: 100%;
    margin: 0;
    overscroll-behavior: none;
}
body {
    font-family: var(--font-body);
    color: var(--color-navy);
    background:
        radial-gradient(circle at 15% 10%, rgba(255, 255, 255, 0.7) 0, transparent 40%),
        linear-gradient(180deg, var(--color-bg-top) 0%, var(--color-bg-deep) 100%);
    background-attachment: fixed;
    overflow: hidden;
    position: fixed;
    inset: 0;
    -webkit-user-select: none;
    user-select: none;
}

/* gentle wave band along the bottom of the viewport */
body::after {
    content: '';
    position: fixed;
    left: -10%;
    right: -10%;
    bottom: -6%;
    height: 22%;
    z-index: 0;
    pointer-events: none;
    background:
        radial-gradient(ellipse at 10% 100%, rgba(255, 255, 255, 0.55) 0 40%, transparent 41%) 0 0/20% 100% repeat-x,
        var(--color-ocean);
    opacity: 0.10;
    border-radius: 50% 50% 0 0 / 100% 100% 0 0;
}

#bg-canvas {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
}

#fx-canvas {
    position: fixed;
    inset: 0;
    z-index: 40;
    pointer-events: none;
}

h1,
h2,
h3,
.display {
    font-family: var(--font-display);
    margin: 0;
}

button {
    font-family: var(--font-body);
    border: none;
    cursor: pointer;
    -webkit-appearance: none;
    background: none;
}

button:focus-visible,
.match-card:focus-visible {
    outline: 3px solid var(--color-ocean);
    outline-offset: 3px;
}

.btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1rem, 2.4vw, 1.2rem);
    color: #fff;
    padding: 16px 34px;
    border-radius: 999px;
    background: var(--btn-color, var(--color-ocean));
    box-shadow: 0 6px 0 var(--btn-shadow, #094D63), 0 14px 24px rgba(11, 79, 108, 0.22);
    transition: transform .08s ease, box-shadow .08s ease;
}

.btn:active {
    transform: translateY(6px);
    box-shadow: 0 0 0 var(--btn-shadow, #094D63), 0 6px 12px rgba(11, 79, 108, 0.2);
}

.btn.coral {
    --btn-color: var(--color-coral);
    --btn-shadow: #D94F4F;
}

.btn.ghost {
    color: var(--color-navy);
    background: var(--color-paper);
    box-shadow: 0 6px 0 #D9EDF6, 0 14px 24px rgba(11, 79, 108, 0.1);
}

.btn.ghost:active {
    box-shadow: 0 0 0 #D9EDF6, 0 6px 12px rgba(11, 79, 108, 0.08);
}

.icon-btn {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    background: var(--color-paper);
    color: var(--color-navy);
    box-shadow: 0 5px 0 #D9EDF6, 0 10px 18px rgba(11, 79, 108, 0.16);
    transition: transform .08s ease;
}

.icon-btn:active {
    transform: translateY(4px);
    box-shadow: 0 1px 0 #D9EDF6;
}

.screen {
    display: none;
}

.screen.active {
    display: flex;
}

.screen {
    position: fixed;
    inset: 0;
    z-index: 10;
    flex-direction: column;
    align-items: center;
    padding: 20px 18px 26px;
    overflow-y: auto;
}

.topbar {
    width: 100%;
    max-width: 760px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.brand-mini {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-display);
    font-weight: 700;
    color: #033378;
    font-size: 1.95rem;
}

/* ---------- Preloader ---------- */
#preloader-screen {
    justify-content: center;
    align-items: center;
    text-align: center;
    z-index: 60;
}

.loader-wave {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    background: radial-gradient(circle at 32% 30%, #fff, var(--color-aqua) 65%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.2rem;
    box-shadow: 0 10px 0 rgba(11, 79, 108, 0.10), 0 20px 34px rgba(11, 79, 108, 0.2);
    animation: bob 1.6s ease-in-out infinite;
    margin-bottom: 20px;
}

@keyframes bob {

    0%,
    100% {
        transform: translateY(0) rotate(-4deg);
    }

    50% {
        transform: translateY(-10px) rotate(4deg);
    }
}

.loader-title {
    font-size: clamp(1.5rem, 5vw, 2.1rem);
    margin-bottom: 6px;
}

.loader-sub {
    color: var(--color-navy-60);
    font-weight: 700;
    margin-bottom: 22px;
}

.load-track {
    width: 220px;
    height: 16px;
    border-radius: 999px;
    background: #D9EDF6;
    box-shadow: inset 0 2px 4px rgba(11, 79, 108, 0.18);
    overflow: hidden;
    margin: 0 auto;
}

#load-progress {
    height: 100%;
    width: 0%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--color-ocean), var(--color-aqua));
    transition: width .25s ease;
}

#loading-status-text {
    margin-top: 12px;
    font-weight: 800;
    color: var(--color-navy-60);
    font-size: 0.9rem;
    letter-spacing: 0.4px;
}

#btn-start-loading {
    display: none;
    margin-top: 18px;
}

/* ---------- Home ---------- */
#home-screen {
    justify-content: center;
    align-items: center;
    text-align: center;
}

.home-audio {
    position: absolute;
    top: 22px;
    right: 22px;
}

.home-badge {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 0.85rem;
    color: #fff;
    background: var(--color-ocean);
    padding: 6px 16px;
    border-radius: 999px;
    margin-bottom: 16px;
    box-shadow: 0 4px 0 #094D63;
}

.home-title {
    font-size: clamp(2rem, 7vw, 3rem);
    line-height: 1.05;
}

.home-title em {
    font-style: normal;
    color: var(--color-coral);
}

.home-sub {
    margin-top: 10px;
    color: var(--color-navy-60);
    font-weight: 700;
    max-width: 360px;
}

.home-scene {
    font-size: 2.4rem;
    margin: 22px 0 26px;
    display: flex;
    gap: 12px;
}

.home-scene span {
    display: inline-block;
    animation: swim 2.4s ease-in-out infinite;
}

.home-scene span:nth-child(2) {
    animation-delay: .2s;
}

.home-scene span:nth-child(3) {
    animation-delay: .4s;
}

.home-scene span:nth-child(4) {
    animation-delay: .6s;
}

@keyframes swim {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-9px) rotate(-4deg);
    }
}

.home-actions {
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: min(320px, 80vw);
}

.home-levels-hint {
    margin-top: 18px;
    font-weight: 800;
    color: var(--color-navy-60);
    font-size: 0.85rem;
    display: flex;
    gap: 8px;
    align-items: center;
}

.home-levels-hint .dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    display: inline-block;
}

/* ---------- Game ---------- */
#game-screen {
    justify-content: flex-start;
    align-items: center;
}

.hud {
    width: 100%;
    max-width: 520px;
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-top: 2px;
    flex-wrap: wrap;
}

.hud-pill {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--color-navy);
    background: var(--color-paper);
    padding: 8px 14px;
    border-radius: 999px;
    box-shadow: 0 4px 0 #D9EDF6;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.hud-pill.lvl-easy {
    background: #DFF7E3;
    color: #1B7A3D;
    box-shadow: 0 4px 0 #BDE9C6;
}

.hud-pill.lvl-medium {
    background: #FFF1D6;
    color: #B5651D;
    box-shadow: 0 4px 0 #F5DBA8;
}

.hud-pill.lvl-hard {
    background: #FFE1E1;
    color: #C23B3B;
    box-shadow: 0 4px 0 #F6C2C2;
}

.hud-pill.lvl-expert {
    background: #EDE1FA;
    color: #6B3FA0;
    box-shadow: 0 4px 0 #D6C2EF;
}

.hud-pill.lvl-master {
    background: #26324A;
    color: #EAF7FC;
    box-shadow: 0 4px 0 #16203380;
}

#instruction-text {
    margin-top: 14px;
    font-family: var(--font-display);
    font-weight: 600;
    text-align: center;
    font-size: clamp(1.02rem, 3.6vw, 1.3rem);
    min-height: 1.5em;
}

.timer-wrap {
    width: 100%;
    max-width: 520px;
    margin-top: 2px;
    display: none;
}

.timer-track {
    width: 100%;
    height: 12px;
    border-radius: 999px;
    background: #D9EDF6;
    box-shadow: inset 0 2px 4px rgba(11, 79, 108, 0.18);
    overflow: hidden;
}

#timer-fill {
    height: 100%;
    width: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--color-gold), var(--color-coral));
    transition: width .12s linear;
}

.board {
    width: 100%;
    max-width: 520px;
    margin-top: 10px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 10px;
    align-items: start;
}

.board-col {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.board-col-head {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--color-navy-60);
    margin-bottom: 2px;
}

.board-divider {
    width: 2px;
    align-self: stretch;
    margin: 34px 0 6px;
    background: repeating-linear-gradient(180deg, rgba(11, 79, 108, 0.25) 0 8px, transparent 8px 16px);
    border-radius: 2px;
}

#animals-column {
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: linear-gradient(180deg, rgba(78, 168, 222, 0.14), rgba(78, 168, 222, 0.05));
    border-radius: var(--radius-md);
    padding: 10px;
}

#shadows-column {
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: linear-gradient(180deg, rgba(255, 239, 214, 0.9), rgba(255, 239, 214, 0.55));
    border-radius: var(--radius-md);
    padding: 10px;
}

.match-card {
    background: var(--color-paper);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    height: 72px;
    font-size: 2.2rem;
    box-shadow: 0 5px 0 #D9EDF6, 0 10px 16px rgba(11, 79, 108, 0.14);
    border: 3px solid transparent;
    cursor: pointer;
    transition: transform .12s ease, border-color .12s ease, opacity .25s ease;
    animation: cardIn .35s ease backwards;
}

.match-card.compact {
    height: 58px;
    font-size: 1.8rem;
}

.match-card.tiny {
    height: 46px;
    font-size: 1.4rem;
}

.match-card:nth-child(2) {
    animation-delay: .06s;
}

.match-card:nth-child(3) {
    animation-delay: .12s;
}

.match-card:nth-child(4) {
    animation-delay: .18s;
}

.match-card:nth-child(5) {
    animation-delay: .24s;
}

@keyframes cardIn {
    from {
        transform: scale(0.7);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.match-card:active {
    transform: scale(0.94);
}

.match-card.selected {
    border-color: var(--color-aqua);
    box-shadow: 0 0 0 4px rgba(78, 168, 222, 0.28), 0 10px 16px rgba(11, 79, 108, 0.14);
    transform: translateY(-3px);
}

.match-card.matched {
    opacity: 0.35;
    border-color: transparent;
    cursor: default;
    pointer-events: none;
    box-shadow: none;
}

.match-card.shake {
    animation: shakeCard .4s ease;
    border-color: var(--color-coral);
}

@keyframes shakeCard {

    0%,
    100% {
        transform: translateX(0);
    }

    20% {
        transform: translateX(-8px);
    }

    40% {
        transform: translateX(8px);
    }

    60% {
        transform: translateX(-5px);
    }

    80% {
        transform: translateX(5px);
    }
}

.shadow-card {
    background: var(--color-sand);
}

.shadow-card canvas {
    width: 56px;
    height: 56px;
    image-rendering: auto;
    filter: drop-shadow(0 3px 3px rgba(29, 53, 87, 0.25));
}

.match-card.compact canvas {
    width: 44px;
    height: 44px;
}

.match-card.tiny canvas {
    width: 34px;
    height: 34px;
}

/* ---------- Result ---------- */
#result-screen {
    justify-content: center;
    align-items: center;
    text-align: center;
}

.result-card {
    background: var(--color-paper);
    border-radius: var(--radius-lg);
    padding: 36px 30px;
    box-shadow: var(--shadow-card);
    width: min(360px, 84vw);
}

.result-badge {
    font-size: 3.4rem;
    margin-bottom: 6px;
}

.result-title {
    font-size: clamp(1.5rem, 5vw, 1.9rem);
}

.stars-row {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 18px 0 8px;
}

.star {
    font-size: 2.4rem;
    color: #D9EDF6;
    transition: transform .3s ease, color .3s ease;
    display: inline-block;
}

.star.earned {
    color: var(--color-gold);
    transform: scale(1.18) rotate(-6deg);
    filter: drop-shadow(0 4px 6px rgba(255, 217, 61, 0.5));
}

#result-score-text {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--color-navy-60);
    margin-bottom: 22px;
}

.result-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

@media (max-width:400px) {
    .btn {
        padding: 14px 26px;
    }

    .icon-btn {
        width: 46px;
        height: 46px;
    }

    .match-card {
        height: 64px;
        font-size: 1.9rem;
    }

    .match-card.compact {
        height: 52px;
        font-size: 1.6rem;
    }

    .match-card.tiny {
        height: 42px;
        font-size: 1.25rem;
    }

    .shadow-card canvas {
        width: 48px;
        height: 48px;
    }

    .match-card.compact canvas {
        width: 38px;
        height: 38px;
    }

    .match-card.tiny canvas {
        width: 30px;
        height: 30px;
    }
}

.logo {
    border-radius: 50px;
    box-shadow: 0 2px 0 #b8b8b8, 0 5px 0 #8c8c8c, 0 8px 0 #5f5f5f, 0 12px 20px rgba(0, 0, 0, 0.45);
    transition: all 0.25s ease;
}