
@import url('https://fonts.googleapis.com/css2?family=Fredoka+One&family=Quicksand:wght@400;600;700&display=swap');

:root {
    --ocean-deep: #0b3d5c;
    --ocean-mid: #1a6b8a;
    --ocean-light: #4db8d1;
    --sand: #f5deb3;
    --sand-dark: #d4a853;
    --coral: #ff6b6b;
    --gold: #ffd166;
    --shell: #fff8f0;
    --seafoam: #7ec8a0;
    --bubble: rgba(255, 255, 255, 0.25);
}

* {
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Quicksand', 'Fredoka One', cursive, sans-serif;
    background: #0a1628;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    background: radial-gradient(ellipse at 50% 30%, #1a3a5c 0%, #0a1628 60%, #020810 100%);
}

/* --- AMBIENT BACKGROUND BUBBLES --- */
.ambient-bubbles {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.bubble {
    position: absolute;
    border-radius: 50%;
    background: var(--bubble);
    animation: floatUp linear infinite;
    opacity: 0;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.15);
}

@keyframes floatUp {
    0% {
        transform: translateY(105vh) scale(0);
        opacity: 0;
    }

    10% {
        opacity: 0.7;
    }

    90% {
        opacity: 0.3;
    }

    100% {
        transform: translateY(-15vh) scale(1.3);
        opacity: 0;
    }
}

/* --- PRELOADER --- */
#preloader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(ellipse at 50% 40%, #0f3050 0%, #060e1c 100%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: opacity 0.6s ease, visibility 0.6s ease;
}

#preloader.fade-out {
    opacity: 0;
    visibility: hidden;
}

.preloader-puzzle {
    display: grid;
    grid-template-columns: repeat(3, 45px);
    grid-template-rows: repeat(3, 45px);
    gap: 4px;
    margin-bottom: 30px;
    animation: preloaderPulse 1.8s ease-in-out infinite;
}

.preloader-piece {
    width: 45px;
    height: 45px;
    border-radius: 8px;
    background: linear-gradient(135deg, #ff9a56, #ff6b6b);
    animation: preloaderPiece 1.8s ease-in-out infinite;
    box-shadow: 0 4px 15px rgba(255, 107, 107, 0.5);
}

.preloader-piece:nth-child(1) {
    animation-delay: 0s;
    background: linear-gradient(135deg, #ff9a56, #ff6b6b);
}

.preloader-piece:nth-child(2) {
    animation-delay: 0.15s;
    background: linear-gradient(135deg, #ffd166, #ffaa33);
}

.preloader-piece:nth-child(3) {
    animation-delay: 0.3s;
    background: linear-gradient(135deg, #7ec8a0, #4db8d1);
}

.preloader-piece:nth-child(4) {
    animation-delay: 0.45s;
    background: linear-gradient(135deg, #4db8d1, #1a6b8a);
}

.preloader-piece:nth-child(5) {
    animation-delay: 0.6s;
    background: linear-gradient(135deg, #ffd166, #ff6b6b);
}

.preloader-piece:nth-child(6) {
    animation-delay: 0.75s;
    background: linear-gradient(135deg, #ff9a56, #ffaa33);
}

.preloader-piece:nth-child(7) {
    animation-delay: 0.9s;
    background: linear-gradient(135deg, #7ec8a0, #4db8d1);
}

.preloader-piece:nth-child(8) {
    animation-delay: 1.05s;
    background: linear-gradient(135deg, #ff6b6b, #ff9a56);
}

.preloader-piece:nth-child(9) {
    animation-delay: 1.2s;
    background: linear-gradient(135deg, #4db8d1, #1a6b8a);
}

@keyframes preloaderPiece {

    0%,
    100% {
        transform: scale(1) rotate(0deg);
        opacity: 0.7;
    }

    50% {
        transform: scale(1.2) rotate(10deg);
        opacity: 1;
    }
}

@keyframes preloaderPulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

.preloader-text {
    font-family: 'Fredoka One', cursive;
    font-size: 28px;
    color: #ffd166;
    text-shadow: 0 0 20px rgba(255, 209, 102, 0.7), 0 0 40px rgba(255, 107, 107, 0.5);
    letter-spacing: 2px;
    animation: textGlow 1.5s ease-in-out infinite;
}

.preloader-dots {
    display: flex;
    gap: 8px;
    margin-top: 15px;
}

.preloader-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ffd166;
    animation: dotBounce 1.2s ease-in-out infinite;
}

.preloader-dot:nth-child(1) {
    animation-delay: 0s;
}

.preloader-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.preloader-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes dotBounce {

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

    50% {
        transform: translateY(-20px);
        opacity: 1;
    }
}

@keyframes textGlow {

    0%,
    100% {
        text-shadow: 0 0 20px rgba(255, 209, 102, 0.7), 0 0 40px rgba(255, 107, 107, 0.5);
    }

    50% {
        text-shadow: 0 0 35px rgba(255, 209, 102, 1), 0 0 60px rgba(255, 107, 107, 0.8), 0 0 80px rgba(255, 150, 80, 0.6);
    }
}

/* --- MAIN GAME CONTAINER --- */
#game-container {
    position: relative;
    width: 100%;
    max-width: 450px;
    height: 100vh;
    max-height: 850px;
    background: linear-gradient(180deg,
            rgba(30, 100, 140, 0.9) 0%,
            rgba(60, 170, 200, 0.85) 18%,
            rgba(140, 210, 230, 0.8) 35%,
            rgba(200, 225, 235, 0.85) 50%,
            rgba(245, 222, 179, 0.9) 65%,
            rgba(220, 190, 140, 0.95) 80%,
            rgba(180, 150, 100, 0.95) 100%);
    border-radius: 24px;
    box-shadow:
        0 0 60px rgba(60, 170, 200, 0.4),
        0 0 120px rgba(30, 100, 140, 0.25),
        0 20px 50px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 1;
    border: 3px solid rgba(255, 255, 255, 0.35);
    backdrop-filter: blur(2px);
}

/* --- TOP BAR --- */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    z-index: 20;
    background: rgba(0, 0, 0, 0.15);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.25);
}

.btn {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 22px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.btn:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3), 0 0 20px rgba(255, 255, 255, 0.3);
}

.btn:active {
    transform: scale(0.88);
    transition: transform 0.1s;
}

.level-badge {
    background: linear-gradient(135deg, #ff6b6b, #ff9a56);
    border: 3px solid white;
    border-radius: 30px;
    padding: 8px 22px;
    color: white;
    font-family: 'Fredoka One', cursive;
    font-size: 20px;
    letter-spacing: 2px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
    box-shadow: 0 4px 20px rgba(255, 107, 107, 0.5), 0 0 30px rgba(255, 154, 86, 0.3);
    animation: badgeGlow 2.5s ease-in-out infinite;
}

@keyframes badgeGlow {

    0%,
    100% {
        box-shadow: 0 4px 20px rgba(255, 107, 107, 0.5), 0 0 30px rgba(255, 154, 86, 0.3);
    }

    50% {
        box-shadow: 0 4px 30px rgba(255, 107, 107, 0.8), 0 0 50px rgba(255, 154, 86, 0.6), 0 0 70px rgba(255, 209, 102, 0.4);
    }
}

.score-display {
    background: rgba(0, 0, 0, 0.25);
    border-radius: 20px;
    padding: 6px 16px;
    color: #ffd166;
    font-family: 'Fredoka One', cursive;
    font-size: 18px;
    text-align: center;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border: 2px solid rgba(255, 255, 255, 0.3);
    letter-spacing: 1px;
    transition: all 0.3s ease;
}

.score-display.pulse {
    animation: scorePulse 0.4s ease;
}

@keyframes scorePulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.25);
        color: #fff;
        border-color: #ffd166;
        box-shadow: 0 0 25px rgba(255, 209, 102, 0.7);
    }
}

/* --- GRID AREA --- */
.grid-wrapper {
    width: 300px;
    height: 300px;
    margin: 8px auto;
    position: relative;
    background: rgba(210, 180, 140, 0.5);
    border-radius: 20px;
    border: 4px solid rgba(255, 255, 255, 0.6);
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.3),
        inset 0 0 30px rgba(255, 255, 255, 0.2),
        0 0 0 8px rgba(210, 180, 140, 0.3);
    overflow: hidden;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

#grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    height: 100%;
    gap: 3px;
    padding: 3px;
}

.cell {
    width: 100%;
    height: 100%;
    border-radius: 8px;
    border: 2px solid rgba(255, 255, 255, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 55px;
    color: white;
    text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.5);
    background-size: 300% 300%;
    background-color: rgba(255, 255, 255, 0.15);
    transition: all 0.3s ease;
    cursor: default;
    position: relative;
    overflow: hidden;
}

.cell::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 6px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2) 0%, transparent 50%, rgba(0, 0, 0, 0.1) 100%);
    pointer-events: none;
}

.cell.question {
    background: rgba(255, 255, 255, 0.35) !important;
    animation: questionPulse 1s ease-in-out infinite;
    border: 3px solid #ffd166 !important;
    box-shadow: 0 0 25px rgba(255, 209, 102, 0.7), inset 0 0 20px rgba(255, 209, 102, 0.3);
}

.cell.filled {
    animation: fillPop 0.5s ease;
}

@keyframes questionPulse {

    0%,
    100% {
        box-shadow: 0 0 20px rgba(255, 209, 102, 0.6), inset 0 0 15px rgba(255, 209, 102, 0.2);
        transform: scale(1);
    }

    50% {
        box-shadow: 0 0 40px rgba(255, 209, 102, 1), inset 0 0 30px rgba(255, 209, 102, 0.5), 0 0 60px rgba(255, 154, 86, 0.6);
        transform: scale(1.04);
    }
}

@keyframes fillPop {
    0% {
        transform: scale(0.7);
        opacity: 0.4;
    }

    60% {
        transform: scale(1.1);
        opacity: 1;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* --- FULL IMAGE OVERLAY --- */
#full-image-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    z-index: 10;
    display: none;
    border-radius: 16px;
    box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.3);
}

#memorize-banner {
    position: absolute;
    top: -55px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    text-align: center;
    z-index: 25;
    background: linear-gradient(135deg, #ff6b6b, #ff4757);
    color: white;
    font-family: 'Fredoka One', cursive;
    font-size: 20px;
    padding: 10px 20px;
    border-radius: 30px;
    letter-spacing: 2px;
    border: 3px solid white;
    box-shadow: 0 6px 25px rgba(255, 71, 87, 0.6);
    animation: bannerBounce 0.8s ease-in-out infinite;
}

@keyframes bannerBounce {

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

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

#timer-ring {
    position: absolute;
    bottom: 15px;
    left: 50%;
    transform: translateX(-50%);
    width: 55px;
    height: 55px;
    z-index: 25;
}

#timer-ring .ring-bg {
    fill: none;
    stroke: rgba(255, 255, 255, 0.3);
    stroke-width: 5;
}

#timer-ring .ring-fg {
    fill: none;
    stroke: #ffd166;
    stroke-width: 5;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.9s linear;
    filter: drop-shadow(0 0 6px rgba(255, 209, 102, 0.8));
}

#timer-ring .ring-text {
    fill: white;
    font-family: 'Fredoka One', cursive;
    font-size: 22px;
    text-anchor: middle;
    dominant-baseline: central;
    text-shadow: 0 0 8px rgba(0, 0, 0, 0.6);
}

/* --- FLOATING AREA --- */
#floating-area {
    flex-grow: 1;
    position: relative;
    overflow: hidden;
    margin: 6px 10px;
    border-radius: 20px;
    background: rgba(0, 0, 0, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    box-shadow: inset 0 4px 20px rgba(0, 0, 0, 0.3), 0 4px 15px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    min-height: 140px;
}

#floating-area::before {
    content: 'TAP THE MATCHING PIECE';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'Fredoka One', cursive;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.35);
    letter-spacing: 3px;
    pointer-events: none;
    z-index: 0;
    text-align: center;
}

.floating-piece {
    position: absolute;
    width: 76px;
    height: 76px;
    border: 3px solid white;
    border-radius: 14px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4), 0 0 15px rgba(255, 255, 255, 0.3);
    background-size: 300% 300%;
    cursor: pointer;
    z-index: 5;
    transition: border 0.25s ease, box-shadow 0.25s ease, transform 0.1s ease;
    animation: pieceFloat 3s ease-in-out infinite;
}

.floating-piece:hover {
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5), 0 0 25px rgba(255, 255, 255, 0.5);
    z-index: 8;
}

.floating-piece:active {
    transform: scale(0.9);
}

.floating-piece.wrong-flash {
    border: 4px solid #ff4757 !important;
    box-shadow: 0 0 30px rgba(255, 71, 87, 0.9) !important;
    animation: shake 0.5s ease !important;
}

@keyframes pieceFloat {

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

    50% {
        transform: translateY(-12px);
    }
}

@keyframes shake {

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

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

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

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

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

.piece-ripple {
    position: absolute;
    border-radius: 50%;
    border: 3px solid #ffd166;
    animation: rippleOut 0.6s ease-out forwards;
    pointer-events: none;
    z-index: 20;
}

@keyframes rippleOut {
    0% {
        width: 20px;
        height: 20px;
        opacity: 1;
    }

    100% {
        width: 120px;
        height: 120px;
        opacity: 0;
        margin-left: -50px;
        margin-top: -50px;
    }
}

/* --- OVERLAYS & MODALS --- */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    z-index: 100;
    color: white;
    text-align: center;
    padding: 20px;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border-radius: 24px;
}

.modal-box {
    background: linear-gradient(180deg, #fffef5 0%, #fff8e7 100%);
    color: #3d2b1f;
    padding: 28px 24px;
    border-radius: 24px;
    border: 4px solid #ffd166;
    max-width: 90%;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), 0 0 40px rgba(255, 209, 102, 0.3);
    animation: modalAppear 0.5s ease;
}

@keyframes modalAppear {
    0% {
        transform: scale(0.7) translateY(30px);
        opacity: 0;
    }

    100% {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

.modal-box h1 {
    color: #ff6b6b;
    margin-top: 0;
    font-family: 'Fredoka One', cursive;
    font-size: 28px;
    text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.1);
    letter-spacing: 1px;
}

.modal-box p {
    font-weight: 600;
    margin: 6px 0;
    font-size: 15px;
    color: #5a4030;
}

.modal-btn {
    background: linear-gradient(135deg, #ff9a56, #ff6b6b);
    border: 3px solid white;
    padding: 14px 28px;
    font-size: 20px;
    color: white;
    border-radius: 30px;
    font-family: 'Fredoka One', cursive;
    cursor: pointer;
    box-shadow: 0 6px 0 #c0392b, 0 8px 20px rgba(0, 0, 0, 0.3);
    margin-top: 18px;
    letter-spacing: 2px;
    transition: all 0.15s ease;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.modal-btn:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 #c0392b, 0 4px 10px rgba(0, 0, 0, 0.3);
}

.hidden {
    display: none !important;
}

/* --- CONFETTI --- */
.confetti {
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    z-index: 150;
    pointer-events: none;
    animation: confettiFall linear forwards;
}

@keyframes confettiFall {
    0% {
        transform: translateY(-120px) rotate(0deg) scale(1);
        opacity: 1;
    }

    100% {
        transform: translateY(105vh) rotate(720deg) scale(0.3);
        opacity: 0;
    }
}

/* --- RESPONSIVE --- */
@media (max-width: 400px) {
    .grid-wrapper {
        width: 260px;
        height: 260px;
        border-radius: 16px;
    }

    .cell {
        font-size: 44px;
        border-radius: 6px;
    }

    .floating-piece {
        width: 62px;
        height: 62px;
        border-radius: 10px;
    }

    #floating-area {
        border-radius: 14px;
        min-height: 110px;
    }

    .level-badge {
        font-size: 16px;
        padding: 6px 14px;
    }

    .btn {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }
}
