:root {
    --bg-color: #0d1b2a;
    --grid-bg: #1b263b;
    --cell-empty: #415a77;
    --primary: #e0e1dd;
    --accent: #ff4d6d;
    /* Festive Red */
    --gold: #ffd60a;
    --snow: #ffffff;
    --glass: rgba(255, 255, 255, 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

body {
    background-color: var(--bg-color);
    font-family: 'Outfit', sans-serif;
    color: var(--primary);
    overflow: hidden;
    height: 100vh;
    display: flex;
    justify-content: center;
    background:
        radial-gradient(circle at 50% 100%, #1a3c5a 0%, #050a10 80%),
        url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M50 10 L60 40 L90 40 L65 60 L75 90 L50 70 L25 90 L35 60 L10 40 L40 40 Z' fill='rgba(255,214,10,0.05)'/%3E%3C/svg%3E");
    background-blend-mode: overlay;
}

.ornament {
    position: fixed;
    pointer-events: none;
    z-index: 5;
    opacity: 0.6;
}

.ornament-tl {
    top: -20px;
    left: -20px;
    width: 150px;
    height: 150px;
    background: radial-gradient(circle, var(--accent) 0%, transparent 70%);
    filter: blur(20px);
}

.ornament-tr {
    top: -20px;
    right: -20px;
    width: 150px;
    height: 150px;
    background: radial-gradient(circle, var(--gold) 0%, transparent 70%);
    filter: blur(20px);
}

.snow-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    background-image: url("data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='2' cy='2' r='1' fill='rgba(255,255,255,0.2)'/%3E%3C/svg%3E");
    opacity: 0.5;
    animation: snowFall 20s linear infinite;
}

@keyframes snowFall {
    from {
        background-position: 0 0;
    }

    to {
        background-position: 0 500px;
    }
}

.game-container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 500px;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 20px;
    gap: 20px;
}

.game-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.back-btn {
    align-self: flex-start;
    color: var(--primary);
    text-decoration: none;
    opacity: 0.7;
    font-size: 0.9rem;
}

.game-title {
    font-weight: 900;
    font-size: 2rem;
    text-transform: uppercase;
    text-shadow: 0 0 10px var(--accent);
    letter-spacing: 2px;
    background: linear-gradient(to right, var(--gold), #ff9900);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.score-board {
    display: flex;
    gap: 20px;
}

.score-box {
    background: var(--glass);
    padding: 10px 20px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 100px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.score-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    opacity: 0.7;
}

.score-value {
    font-size: 1.5rem;
    font-weight: 900;
    color: var(--gold);
}

.game-area {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    max-height: 50vh;
    /* restrict height */
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    grid-template-rows: repeat(10, 1fr);
    gap: 2px;
    background: var(--grid-bg);
    padding: 5px;
    border-radius: 8px;
    /* Aspect ratio hack using safe CSS */
    width: 100%;
    aspect-ratio: 1/1;
    max-width: 400px;
    max-height: 400px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

.grid-cell {
    background: var(--cell-empty);
    border-radius: 2px;
    transition: background-color 0.2s;
    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
}

.grid-container.shake {
    animation: shake 0.4s ease-in-out;
}

@keyframes shake {

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

    10%,
    30%,
    50%,
    70%,
    90% {
        transform: translateX(-5px);
    }

    20%,
    40%,
    60%,
    80% {
        transform: translateX(5px);
    }
}

.grid-cell.filled {
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.pieces-container {
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: 120px;
    gap: 10px;
}

.piece-draggable {
    touch-action: none;
    /* Crucial for custom drag */
    cursor: grab;
    transition: transform 0.1s;
}

.piece-draggable:active {
    cursor: grabbing;
    transform: scale(1.1);
}

/* Blocks styling */
.block {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    background: var(--color);
    box-shadow:
        inset 0 0 8px rgba(255, 255, 255, 0.4),
        inset 0 0 4px rgba(0, 0, 0, 0.3),
        0 2px 4px rgba(0, 0, 0, 0.3);
    position: relative;
    overflow: hidden;
}

.block::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transform: rotate(45deg);
    animation: glitter 3s infinite linear;
}

@keyframes glitter {
    0% {
        transform: translate(-100%, -100%) rotate(45deg);
    }

    100% {
        transform: translate(100%, 100%) rotate(45deg);
    }
}

/* Modal */
.game-over-modal {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    backdrop-filter: blur(5px);
    transition: opacity 0.3s;
}

.game-over-modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: #1e293b;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.modal-content h2 {
    font-size: 2.5rem;
    color: var(--accent);
}

.restart-btn {
    background: var(--gold);
    color: #000;
    border: none;
    padding: 15px 30px;
    border-radius: 99px;
    font-weight: 900;
    font-size: 1.2rem;
    cursor: pointer;
    text-transform: uppercase;
}

.exit-btn {
    color: var(--primary);
    text-decoration: none;
    font-size: 0.9rem;
    opacity: 0.7;
}

/* Block Colors (Festive) */
.c-red {
    background: #ef233c;
    --color: #ef233c;
}

.c-green {
    background: #38b000;
    --color: #38b000;
}

.c-blue {
    background: #4cc9f0;
    --color: #4cc9f0;
}

.c-gold {
    background: #ffbe0b;
    --color: #ffbe0b;
}

.c-purple {
    background: #7209b7;
    --color: #7209b7;
}

/* Combo Feedback */
.combo-text {
    position: fixed;
    pointer-events: none;
    z-index: 200;
    font-size: 2.5rem;
    font-weight: 900;
    color: var(--gold);
    text-shadow: 0 0 20px rgba(255, 214, 10, 0.8), 0 0 40px rgba(255, 214, 10, 0.4);
    text-transform: uppercase;
    white-space: nowrap;
    animation: comboPop 1s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    transform-origin: center;
}

@keyframes comboPop {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.5) rotate(-10deg);
    }

    20% {
        opacity: 1;
        transform: translate(-50%, -60%) scale(1.2) rotate(5deg);
    }

    80% {
        opacity: 1;
        transform: translate(-50%, -70%) scale(1) rotate(0deg);
    }

    100% {
        opacity: 0;
        transform: translate(-50%, -80%) scale(0.8);
    }
}