:root {
    --primary-color: #ffb703;
    --secondary-color: #fb8500;
    --bg-sky: #1777d9;
    --bg-sand: #faedcd;
    --board-border: #6f4e37;
    --board-bg: #d4a373;
    --text-color: #fff;
    --shadow-color: rgba(0, 0, 0, 0.3);
}

* {
    box-sizing: border-box;
    user-select: none;
    margin: 0;
    padding: 0;
    font-family: 'Comic Sans MS', 'Chalkboard SE', 'Marker Felt', sans-serif;
}

body {
    background: linear-gradient(to bottom, var(--bg-sky) 0%, var(--bg-sky) 60%, var(--bg-sand) 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* --- PRELOADER --- */
#preloader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-sky);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: opacity 0.5s ease;
}

.loader-title {
    font-size: 2.5rem;
    color: white;
    text-shadow: 3px 3px 0px var(--secondary-color);
    margin-bottom: 20px;
    animation: bounce 1s infinite alternate;
}

.loader-bar-container {
    width: 250px;
    height: 25px;
    background: white;
    border-radius: 12px;
    padding: 3px;
    border: 3px solid var(--board-border);
}

.loader-bar {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    border-radius: 8px;
    transition: width 0.1s linear;
}

/* --- GAME UI --- */
#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 500px;
    padding: 20px;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.header-info {
    font-size: 2.2rem;
    font-weight: bold;
    color: #fff;
    text-shadow: 3px 3px 0 #000, -1px -1px 0 var(--secondary-color), 1px -1px 0 var(--secondary-color), -1px 1px 0 var(--secondary-color);
    margin-bottom: 10px;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-right: 5%;
}

.level-indicator {
    font-size: 1.2rem;
    background: #0c387f;
    color: #fff;
    padding: 8px 15px;
    border-radius: 20px;
    margin-bottom: 15px;
    box-shadow: 0 4px 6px var(--shadow-color);
    font-weight: bold;
    border: 2px solid #6bc5fb;
    margin-left: 5%;
}

/* --- THE PUZZLE FRAME & BOARD --- */
.puzzle-frame {
    background: var(--board-border);
    padding: 15px;
    border-radius: 24px;
    box-shadow: 0 12px 24px var(--shadow-color), inset 0 4px 10px rgba(0, 0, 0, 0.5);
    border: 6px solid #4a3325;
}

#puzzle-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 2px;
    width: 360px;
    height: 360px;
    background: #222;
    border-radius: 12px;
    overflow: hidden;
}

@media (max-width: 400px) {
    #puzzle-board {
        width: 300px;
        height: 300px;
    }

    .puzzle-frame {
        padding: 10px;
    }
}

#time-display {
    font-size: 1.2rem;
    background: #0c387f;
    color: #fff;
    padding: 8px 15px;
    border-radius: 20px;
    margin-bottom: 15px;
    box-shadow: 0 4px 6px var(--shadow-color);
    font-weight: bold;
    border: 2px solid #6bc5fb;
}

.puzzle-piece {
    position: relative;
    width: 100%;
    height: 100%;
    cursor: pointer;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    background-size: 360px 360px;
}

/* Orientation marker: rotates WITH the tile so you can always tell
           by eye whether a piece is truly at 0deg, even on flat/gradient art */
.puzzle-piece::before {
    content: '';
    position: absolute;
    top: 4px;
    left: 4px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 12px 12px 0 0;
    border-color: rgba(255, 255, 255, 0.9) transparent transparent transparent;
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.4));
    z-index: 2;
    pointer-events: none;
}

@media (max-width: 400px) {
    .puzzle-piece {
        background-size: 300px 300px;
    }
}

.puzzle-piece:active {
    filter: brightness(0.9);
}

.footer-info {
    margin-top: 15px;
}

/* --- MODALS & DIALOGS --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 500;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 24px;
    width: 90%;
    max-width: 400px;
    text-align: center;
    border: 6px solid var(--primary-color);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    transform: scale(0.8);
    animation: popIn 0.3s forwards cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-title {
    font-size: 2rem;
    color: var(--secondary-color);
    margin-bottom: 15px;
}

.modal-body {
    font-size: 1.1rem;
    color: #444;
    line-height: 1.6;
    margin-bottom: 25px;
}

.btn {
    background: linear-gradient(to bottom, var(--primary-color), var(--secondary-color));
    color: white;
    border: none;
    padding: 12px 30px;
    font-size: 1.3rem;
    font-weight: bold;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 5px 0px #b56000;
    transition: all 0.1s;
}

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

.hidden {
    display: none !important;
}

/* --- ANIMATIONS --- */
@keyframes bounce {
    from {
        transform: translateY(0);
    }

    to {
        transform: translateY(-10px);
    }
}

@keyframes popIn {
    to {
        transform: scale(1);
    }
}

.victory-glow {
    animation: glow 1s infinite alternate;
}

@keyframes glow {
    from {
        box-shadow: 0 0 10px #fff, 0 0 20px var(--primary-color);
    }

    to {
        box-shadow: 0 0 20px #fff, 0 0 40px var(--secondary-color);
    }
}

.top-part {
    display: flex;
    width: 70%;
}