:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --filled-gradient: linear-gradient(45deg, #ff6b6b, #feca57);
    --piece-block-gradient: linear-gradient(45deg, #4ecdc4, #44a08d);
    --grid-cell-size-mobile: 35px; /* Default for mobile */
    --piece-block-size-mobile: 20px; /* Default for mobile */
}

body {
    margin: 0;
    padding: 0;
    background: var(--primary-gradient);
    font-family: 'Arial', sans-serif;
    color: white;
    overflow-x: hidden;
    min-height: 100vh;
    display: flex; /* Use flexbox for vertical centering if content is small */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    user-select: none; /* Prevent text selection */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.game-container {
    max-width: 500px;
    width: 100%; /* Ensure it takes full width on small screens */
    margin: 20px auto; /* Add vertical margin */
    padding: 20px;
    text-align: center;
    box-sizing: border-box; /* Include padding in width calculation */
}

.header {
    margin-bottom: 20px;
}

h1 {
    font-size: 2.5em; /* Responsive font size */
    margin-top: 0;
}

.score {
    font-size: 1.5em;
    font-weight: bold;
    margin-bottom: 10px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    background: rgba(255,255,255,0.1);
    padding: 10px;
    border-radius: 10px;
    margin: 0 auto 30px;
    width: fit-content; /* Adjusts to content size */
    box-shadow: 0 5px 15px rgba(0,0,0,0.3); /* Add a subtle shadow */
}

.cell {
    width: var(--grid-cell-size-mobile);
    height: var(--grid-cell-size-mobile);
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 4px;
    transition: background 0.2s ease, border 0.2s ease, box-shadow 0.2s ease;
}

.cell.filled {
    background: var(--filled-gradient);
    border: 1px solid #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.cell.preview { /* Keep preview for future use/visual debugging */
    background: rgba(255,255,255,0.5);
    border: 2px dashed #fff;
}

.cell.valid-drop {
    background: rgba(76, 217, 100, 0.6);
    border: 2px solid #4cd964;
}

.cell.invalid-drop {
    background: rgba(255, 107, 107, 0.6);
    border: 2px solid #ff6b6b;
}

.pieces-container {
    display: flex;
    justify-content: center; /* Center pieces horizontally */
    gap: 15px; /* Increased gap for better spacing */
    margin-bottom: 20px;
    flex-wrap: wrap; /* Allow pieces to wrap on smaller screens */
    min-height: 80px;
}

.piece {
    display: grid;
    gap: 2px;
    padding: 10px;
    background: rgba(255,255,255,0.1);
    border-radius: 8px;
    cursor: grab;
    transition: all 0.3s ease;
    border: 2px solid transparent;
    position: relative; /* For potential positioning of elements within */
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.piece:not(.dragging):hover { /* Apply hover only when not dragging */
    transform: scale(1.05);
    background: rgba(255,255,255,0.2);
    border: 2px solid rgba(255,255,255,0.5);
    box-shadow: 0 5px 15px rgba(0,0,0,0.4);
}

.piece.dragging {
    opacity: 0.8;
    transform: scale(1.1) rotate(5deg);
    cursor: grabbing;
    z-index: 1000;
    position: fixed; /* Keep it fixed during drag */
    pointer-events: none; /* Allow events to pass through to elements below */
    background: rgba(255,255,255,0.3);
    border: 2px solid #fff;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.piece.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(50%);
}

.piece-block {
    width: var(--piece-block-size-mobile);
    height: var(--piece-block-size-mobile);
    background: var(--piece-block-gradient);
    border-radius: 3px;
    border: 1px solid rgba(255,255,255,0.3);
}

/* Drag ghost uses the same styles as .piece.dragging */
.drag-ghost {
    position: fixed;
    pointer-events: none;
    z-index: 999;
    opacity: 0.8;
    transform: scale(1.2);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5); /* Ensure it has shadow */
}

/* Game Over Overlay */
.game-over-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.85); /* Slightly darker overlay */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000; /* Higher z-index to ensure it's on top */
    opacity: 0; /* Initially hidden */
    visibility: hidden; /* Hide from screen readers when not visible */
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.game-over-overlay.show {
    opacity: 1;
    visibility: visible;
}

.game-over-content {
    background: var(--primary-gradient);
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    border: 2px solid rgba(255,255,255,0.3);
    box-shadow: 0 10px 30px rgba(0,0,0,0.6);
    transform: translateY(20px); /* Small animation on show */
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.game-over-overlay.show .game-over-content {
    transform: translateY(0);
    opacity: 1;
}

.restart-btn {
    background: var(--filled-gradient);
    border: none;
    padding: 15px 30px;
    border-radius: 25px;
    color: white;
    font-size: 1.1em;
    font-weight: bold;
    cursor: pointer;
    margin-top: 25px; /* Increased margin */
    transition: all 0.3s ease;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

.restart-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 7px 20px rgba(0,0,0,0.4);
}

.combo-text {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2.5em; /* Larger for impact */
    font-weight: bold;
    color: #feca57;
    text-shadow: 2px 2px 6px rgba(0,0,0,0.6), 0 0 10px #feca57; /* Enhanced shadow */
    animation: comboAnimation 1.2s ease-out forwards; /* 'forwards' keeps final state */
    pointer-events: none;
    z-index: 1000;
    white-space: nowrap; /* Prevent text wrapping */
}

@keyframes comboAnimation {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
    30% { opacity: 1; transform: translate(-50%, -50%) scale(1.3); }
    70% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
}

/* --- Media Queries Optimized --- */

/* 1. Pentru telefoane mici (landscape) și ecrane mai înguste de 767px */
@media (max-width: 767px) {
    .game-container {
        padding: 15px;
    }

    h1 {
        font-size: 2em;
    }

    .score {
        font-size: 1.3em;
    }

    .cell {
        --grid-cell-size-mobile: 32px; /* Slightly smaller cells */
        width: var(--grid-cell-size-mobile);
        height: var(--grid-cell-size-mobile);
    }

    .piece-block {
        --piece-block-size-mobile: 18px; /* Slightly smaller piece blocks */
        width: var(--piece-block-size-mobile);
        height: var(--piece-block-size-mobile);
    }

    .grid {
        padding: 8px;
        margin-bottom: 20px;
    }

    .pieces-container {
        gap: 10px;
    }

    .piece {
        padding: 8px;
    }

    .game-over-content {
        padding: 30px;
    }

    .restart-btn {
        padding: 12px 25px;
        font-size: 1em;
    }

    .combo-text {
        font-size: 2em;
    }
}

/* Pentru tablete și ecrane medii (768px - 1024px) */
@media (min-width: 768px) {
    body {
        font-size: 18px; /* Base font size for tablets */
    }

    h1 {
        font-size: 3em;
    }

    .score {
        font-size: 1.8em;
    }

    .cell {
        width: 40px; /* Larger cells for tablets */
        height: 40px;
    }

    .piece-block {
        width: 22px; /* Larger piece blocks */
        height: 22px;
    }

    .grid {
        padding: 12px;
    }

    .piece {
        padding: 12px;
    }
}

/* Pentru desktopuri (1025px și mai mari) */
@media (min-width: 1025px) {
    body {
        font-size: 20px; /* Base font size for desktops */
    }

    h1 {
        font-size: 3.5em;
    }

    .score {
        font-size: 2em;
    }

    .cell {
        width: 45px; /* Even larger cells for desktops */
        height: 45px;
    }

    .piece-block {
        width: 25px; /* Even larger piece blocks */
        height: 25px;
    }

    .grid {
        padding: 15px;
    }

    .piece {
        padding: 15px;
    }
}

/* Touch device optimizations: Remove hover effects for touchscreens */
@media (hover: none) {
    .piece:not(.dragging):hover {
        transform: none;
        background: rgba(255,255,255,0.1);
        border: 2px solid transparent;
        box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    }
}

