:root {
    --bg-color: #f7f4ed;
    --bg-pattern: #ede8db;
    --text-color: #3d3226;
    --text-light: #6b5e4f;
    --tile-bg: #fffef9;
    --tile-shadow: #d9ceb5;
    --tile-shadow-dark: #c4b89a;
    --grid-gap: 6px;
    --accent: #e8875b;
    --accent-soft: #f4a886;
    --hint-bg: #5b8c7a;
    --hint-bg-dark: #4a7263;
    --win-gold: #f0c040;
    --color-0: #c7c7f5;
    --shadow-0: #a5a5d8;
    --color-1: #ffcf9e;
    --shadow-1: #e0a66b;
    --color-2: #fff3a8;
    --shadow-2: #e0d47a;
    --color-3: #a8ecc8;
    --shadow-3: #7cc9a0;
    --color-4: #ffb8d0;
    --shadow-4: #e090aa;
    --color-5: #b8e8f8;
    --shadow-5: #8cc8d8;
    --color-6: #e8d5f5;
    --shadow-6: #c4a8d8;
    --color-7: #f5d5c8;
    --shadow-7: #d8a898;
    --color-active: rgba(232, 135, 91, 0.25);
}

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

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    background-image:
        radial-gradient(ellipse at 20% 20%, rgba(232, 135, 91, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(91, 140, 122, 0.06) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(0, 0, 0, 0.015) 0%, transparent 70%);
    font-family: 'Nunito', sans-serif;
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    letter-spacing: -0.01em;
}

/* Subtle dot pattern overlay */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    opacity: 0.25;
    background-image: radial-gradient(circle, var(--bg-pattern) 1px, transparent 1px);
    background-size: 24px 24px;
}

#preloader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-color);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.5s ease;
    gap: 18px;
}

#preloader .logo-text {
    font-size: 2.4rem;
    font-weight: 900;
    color: var(--text-color);
    letter-spacing: -0.02em;
    animation: pulse-logo 1.8s ease-in-out infinite;
}

@keyframes pulse-logo {

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

    50% {
        opacity: 1;
        transform: scale(1.04);
    }
}

.spinner-ring {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 5px solid var(--tile-shadow);
    border-top-color: var(--accent);
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    100% {
        transform: rotate(360deg);
    }
}

header {
    position: relative;
    z-index: 2;
    width: 100%;
    max-width: 520px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px 6px;
}

.level-badge {
    background: var(--tile-bg);
    border: 2px solid var(--tile-shadow);
    border-radius: 28px;
    padding: 8px 18px;
    font-size: 1rem;
    font-weight: 800;
    color: var(--text-color);
    box-shadow: 0 3px 0 var(--tile-shadow);
    letter-spacing: 0.01em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.level-badge .level-num {
    background: var(--accent);
    color: #fff;
    border-radius: 50%;
    width: 26px;
    height: 26px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.85rem;
    font-weight: 900;
}

.icons {
    display: flex;
    gap: 10px;
}

.icon-btn {
    background: var(--tile-bg);
    border: 2px solid var(--tile-shadow);
    border-radius: 50%;
    width: 42px;
    height: 42px;
    font-size: 1.2rem;
    color: var(--text-color);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s;
    box-shadow: 0 3px 0 var(--tile-shadow);
    position: relative;
}

.icon-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 0 var(--tile-shadow);
}

.icon-btn:active {
    transform: translateY(3px);
    box-shadow: 0 0px 0 var(--tile-shadow);
}

main {
    position: relative;
    z-index: 2;
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    padding: 8px;
}

#grid-container {
    position: relative;
    display: grid;
    gap: var(--grid-gap);
    padding: 12px;
    touch-action: none;
    background: rgba(255, 255, 255, 0.35);
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.06), 0 2px 8px rgba(0, 0, 0, 0.04);
    border: 2px solid rgba(0, 0, 0, 0.04);
}

.cell {
    width: 68px;
    height: 68px;
    background-color: var(--tile-bg);
    border-radius: 12px;
    box-shadow: 0 3px 0 var(--tile-shadow), 0 1px 4px rgba(0, 0, 0, 0.04);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--text-color);
    transition: transform 0.1s, box-shadow 0.1s, background-color 0.2s;
    cursor: pointer;
    position: relative;
    z-index: 1;
}

.cell:active {
    transform: scale(0.95);
    box-shadow: 0 1px 0 var(--tile-shadow);
}

.cell.hint-glow {
    animation: hintPulse 0.7s ease-in-out 3;
    background-color: #fff3cd !important;
    box-shadow: 0 3px 0 #e0c870, 0 0 20px rgba(240, 192, 64, 0.5) !important;
}

@keyframes hintPulse {

    0%,
    100% {
        box-shadow: 0 3px 0 #e0c870, 0 0 8px rgba(240, 192, 64, 0.3);
    }

    50% {
        box-shadow: 0 3px 0 #e0c870, 0 0 24px rgba(240, 192, 64, 0.7);
        transform: scale(1.06);
    }
}

@media (max-width: 420px) {
    .cell {
        width: 50px;
        height: 50px;
        font-size: 1.3rem;
        border-radius: 10px;
    }

    #grid-container {
        gap: 4px;
        padding: 8px;
        border-radius: 16px;
    }

    .cell {
        box-shadow: 0 2px 0 var(--tile-shadow);
    }
}

@media (max-width: 340px) {
    .cell {
        width: 40px;
        height: 40px;
        font-size: 1.1rem;
        border-radius: 8px;
    }

    #grid-container {
        gap: 3px;
        padding: 6px;
    }
}

.rectangle {
    position: absolute;
    border-radius: 12px;
    pointer-events: none;
    z-index: 10;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--text-color);
    animation: popIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transition: box-shadow 0.15s;
    cursor: pointer;
    letter-spacing: -0.01em;
}

@media (max-width: 420px) {
    .rectangle {
        font-size: 1.3rem;
        border-radius: 10px;
    }
}

@keyframes popIn {
    0% {
        transform: scale(0.75);
        opacity: 0;
    }

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

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

.rect-temp {
    background-color: var(--color-active);
    z-index: 5;
    box-shadow: none;
    border: 3px dashed var(--accent);
    border-radius: 14px;
    animation: none;
}

.color-0 {
    background-color: var(--color-0);
    box-shadow: 0 4px 0 var(--shadow-0), 0 2px 8px rgba(0, 0, 0, 0.06);
}

.color-1 {
    background-color: var(--color-1);
    box-shadow: 0 4px 0 var(--shadow-1), 0 2px 8px rgba(0, 0, 0, 0.06);
}

.color-2 {
    background-color: var(--color-2);
    box-shadow: 0 4px 0 var(--shadow-2), 0 2px 8px rgba(0, 0, 0, 0.06);
}

.color-3 {
    background-color: var(--color-3);
    box-shadow: 0 4px 0 var(--shadow-3), 0 2px 8px rgba(0, 0, 0, 0.06);
}

.color-4 {
    background-color: var(--color-4);
    box-shadow: 0 4px 0 var(--shadow-4), 0 2px 8px rgba(0, 0, 0, 0.06);
}

.color-5 {
    background-color: var(--color-5);
    box-shadow: 0 4px 0 var(--shadow-5), 0 2px 8px rgba(0, 0, 0, 0.06);
}

.color-6 {
    background-color: var(--color-6);
    box-shadow: 0 4px 0 var(--shadow-6), 0 2px 8px rgba(0, 0, 0, 0.06);
}

.color-7 {
    background-color: var(--color-7);
    box-shadow: 0 4px 0 var(--shadow-7), 0 2px 8px rgba(0, 0, 0, 0.06);
}

.rectangle:not(.rect-temp):hover {
    filter: brightness(0.94);
    box-shadow: 0 5px 0 rgba(0, 0, 0, 0.18), 0 3px 12px rgba(0, 0, 0, 0.1);
    transform: scale(1.015);
    z-index: 15;
}

footer {
    position: relative;
    z-index: 2;
    padding: 14px 30px 24px;
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}

.hint-btn {
    background: var(--hint-bg);
    border: none;
    border-radius: 30px;
    padding: 11px 22px;
    font-size: 1.05rem;
    font-weight: 700;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 0 var(--hint-bg-dark);
    transition: all 0.15s;
    font-family: 'Nunito', sans-serif;
    letter-spacing: 0.01em;
}

.hint-btn:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 var(--hint-bg-dark);
}

.hint-btn:disabled {
    opacity: 0.5;
    pointer-events: none;
    filter: grayscale(30%);
}

.hint-count {
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
    border-radius: 50%;
    width: 26px;
    height: 26px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.85rem;
    font-weight: 900;
}

.reset-btn {
    background: var(--tile-bg);
    border: 2px solid var(--tile-shadow);
    border-radius: 30px;
    padding: 11px 18px;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-color);
    cursor: pointer;
    box-shadow: 0 4px 0 var(--tile-shadow);
    transition: all 0.15s;
    font-family: 'Nunito', sans-serif;
}

.reset-btn:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 var(--tile-shadow);
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(30, 20, 15, 0.55);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: #fffef9;
    width: 90%;
    max-width: 420px;
    border-radius: 24px;
    padding: 32px 28px 24px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(0, 0, 0, 0.05);
    transform: translateY(30px);
    transition: transform 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal h2 {
    margin-top: 0;
    font-size: 1.6rem;
    font-weight: 900;
    letter-spacing: -0.02em;
}

.modal p {
    line-height: 1.6;
    margin-bottom: 20px;
    color: var(--text-light);
    font-size: 0.95rem;
}

.modal .emoji-icon {
    font-size: 3rem;
    display: block;
    margin-bottom: 8px;
}

.btn {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 13px 28px;
    border-radius: 16px;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    font-family: 'Nunito', sans-serif;
    width: 100%;
    box-shadow: 0 4px 0 #c96d3e;
    transition: all 0.15s;
    letter-spacing: 0.01em;
}

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

.btn-secondary {
    background: var(--tile-bg);
    color: var(--text-color);
    border: 2px solid var(--tile-shadow);
    box-shadow: 0 4px 0 var(--tile-shadow);
    margin-top: 8px;
}

.btn-secondary:active {
    box-shadow: 0 0 0 var(--tile-shadow);
}

/* Confetti */
.confetti-piece {
    position: fixed;
    z-index: 2000;
    pointer-events: none;
    animation: confettiFall 1.8s ease-in forwards;
}

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

    60% {
        opacity: 1;
    }

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