body {
    font-family: 'Courier New', Courier, monospace;
    background-color: #1a1a1a;
    color: #fff;
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
    /* Prevent scrolling during drag */
    touch-action: none;
    /* Important for touch drag */
}

.game-container {
    text-align: center;
    width: 100%;
    height: 100vh;
    padding: 10px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

h1 {
    margin: 5px 0;
    color: #fff;
    font-size: 2rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-weight: bold;
}

p {
    margin: 0 0 10px 0;
    color: #aaa;
    font-size: 0.9rem;
}

.back-link {
    position: absolute;
    top: 20px;
    left: 20px;
    color: #888;
    text-decoration: none;
    font-size: 1rem;
    transition: all 0.2s;
    z-index: 100;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.back-link:hover {
    color: #fff;
    text-decoration: line-through;
}

.controls-container {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    z-index: 100;
}

.new-puzzle-btn {
    background: transparent;
    border: 1px solid #333;
    color: #888;
    padding: 10px 20px;
    cursor: pointer;
    font-family: inherit;
    font-size: 1rem;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.new-puzzle-btn:hover {
    color: #000;
    border-color: #fff;
    background: #fff;
}

.easy-mode-label {
    color: #888;
    font-size: 0.8rem;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.easy-mode-label:hover {
    color: #fff;
}

.game-area {
    position: relative;
    width: 100%;
    flex: 1;
    overflow: hidden;
}

.pieces-container {
    display: none;
}

.board {
    border: 2px solid #666;
    position: absolute;
    background-color: #000;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 5;
}

.puzzle-piece {
    cursor: grab;
    position: absolute;
    transition: transform 0.1s, box-shadow 0.1s;
    user-select: none;
    z-index: 20;
    touch-action: none;
    /* Prevent scrolling while dragging piece */
    box-sizing: border-box;
}

/* Dragging State Optimization */
body.dragging .youtube-player {
    opacity: 0.2; /* Dim player to save resources and indicate non-interactive */
    pointer-events: none !important; /* Ensure events pass through to game area */
    transition: opacity 0.2s;
}

body.dragging .puzzle-piece {
    cursor: grabbing;
}

/* Hardware Acceleration Hints */
.game-area {
    transform: translateZ(0);
    will-change: transform;
}

.puzzle-piece {
    will-change: left, top, transform;
}


/* Easy Mode Styles */
@keyframes greenFlash {
    0% {
        border: 2px solid transparent;
        box-shadow: 0 0 0 transparent;
    }

    20% {
        border: 2px solid #00ff00;
        box-shadow: 0 0 15px #00ff00;
    }

    80% {
        border: 2px solid #00ff00;
        box-shadow: 0 0 15px #00ff00;
    }

    100% {
        border: 2px solid transparent;
        box-shadow: 0 0 0 transparent;
    }
}

.puzzle-piece.correct-placement {
    animation: greenFlash 1.5s ease-out;
    z-index: 15;
    /* Lower z-index so it doesn't block others too much, but still visible */
}

.puzzle-piece.locked {
    cursor: default;
    pointer-events: none;
    /* Make it unclickable/undraggable */
}

/* Winner Overlay */
.winner-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, rgba(50, 0, 0, 0.9) 0%, rgba(0, 0, 0, 1) 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.5s;
}

.winner-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.winner-content {
    text-align: center;
    z-index: 1001;
    position: relative;
    border: 5px solid #800000;
    padding: 40px;
    background-color: rgba(0, 0, 0, 0.8);
    box-shadow: 0 0 50px #ff0000;
}

.winner-content h2 {
    font-family: 'Courier New', Courier, monospace;
    font-size: 5rem;
    color: #ff0000;
    text-transform: uppercase;
    letter-spacing: 10px;
    text-shadow: 4px 4px 0px #000, -2px -2px 0px #330000;
    margin: 0 0 30px 0;
    animation: shake 0.5s infinite;
    border-bottom: 2px solid #ff0000;
    padding-bottom: 20px;
}

.winner-content button {
    padding: 20px 40px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.5rem;
    font-weight: bold;
    background: #000;
    border: 3px solid #ff0000;
    color: #ff0000;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.winner-content button:hover {
    background: #ff0000;
    color: #000;
    box-shadow: 0 0 20px #ff0000;
    transform: scale(1.1) rotate(-2deg);
}

#fireworks {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

@keyframes shake {
    0% {
        transform: translate(1px, 1px) rotate(0deg);
    }

    10% {
        transform: translate(-1px, -2px) rotate(-1deg);
    }

    20% {
        transform: translate(-3px, 0px) rotate(1deg);
    }

    30% {
        transform: translate(3px, 2px) rotate(0deg);
    }

    40% {
        transform: translate(1px, -1px) rotate(1deg);
    }

    50% {
        transform: translate(-1px, 2px) rotate(-1deg);
    }

    60% {
        transform: translate(-3px, 1px) rotate(0deg);
    }

    70% {
        transform: translate(3px, 1px) rotate(-1deg);
    }

    80% {
        transform: translate(-1px, -1px) rotate(1deg);
    }

    90% {
        transform: translate(1px, 2px) rotate(0deg);
    }

    100% {
        transform: translate(1px, -2px) rotate(-1deg);
    }
}

/* Dragging State Optimization */
body.dragging .youtube-player {
    opacity: 0.2; /* Dim player to save resources and indicate non-interactive */
    pointer-events: none !important; /* Ensure events pass through to game area */
    transition: opacity 0.2s;
}

body.dragging .puzzle-piece {
    cursor: grabbing;
}

/* Hardware Acceleration Hints */
.game-area {
    transform: translateZ(0);
    will-change: transform;
}

.puzzle-piece {
    will-change: left, top, transform;
}

/* YouTube Player */
.youtube-player {
    position: fixed;
    bottom: 0;
    right: 0;
    width: 205px;
    height: 205px;
    z-index: 100;
    border-top: 2px solid #333;
    border-left: 2px solid #333;
    background-color: #000;
    transition: transform 0.3s ease;
}

.youtube-player.closed {
    transform: translateY(100%);
    /* Slide down to hide */
    display: none;
    /* Or just hide it */
}

.youtube-player iframe {
    width: 100%;
    height: 100%;
    border: none;
}

.close-player-btn {
    position: absolute;
    top: -44px;
    right: 0;
    background: #000;
    border: 2px solid #333;
    border-bottom: none;
    color: #fff;
    width: 44px;
    height: 44px;
    cursor: pointer;
    font-size: 1.5rem;
    line-height: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    /* Ensure it's on top of everything */
    touch-action: manipulation;
}

.close-player-btn:hover {
    background: #333;
}

/* Mobile Adaptation */
@media (max-width: 768px) {

    /* Hide non-essential elements to maximize game space */
    .back-link,
    .new-puzzle-btn,
    h1,
    p,
    .youtube-player,
    .close-player-btn {
        display: none !important;
    }

    .game-container {
        padding: 0;
        /* Minimal padding */
    }

    .controls-container {
        position: relative;
        top: 0;
        right: 0;
        width: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 10px 0;
        background-color: #1a1a1a;
        /* Match body bg */
        z-index: 100;
    }

    .easy-mode-label {
        font-size: 1rem;
        color: #fff;
    }

    .winner-content {
        padding: 20px;
        width: 90%;
        box-sizing: border-box;
    }

    .winner-content h2 {
        font-size: 2.5rem;
    }
}