/* Incastro Magico - Kanoodle CSS */

:root {
    --bg-color: #f0fdf4;
    --board-bg: #e2e8f0;
    --board-cell: #cbd5e1;
    --grid-gap: 2px;
}

body {
    background-color: var(--bg-color);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.site-footer {
    margin-top: auto;
    width: 100%;
}

.screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    animation: fadeIn 0.3s ease;
}

.hidden {
    display: none !important;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Griglia Selezione Livelli */
.level-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 15px;
    width: 100%;
    max-width: 400px;
    margin-top: 20px;
}

.level-btn {
    aspect-ratio: 1;
    border-radius: 12px;
    font-size: 1.5rem;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: white;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    color: var(--brand);
    border: 2px solid #e2e8f0;
    cursor: pointer;
    transition: all 0.2s;
}

.level-btn:hover:not(:disabled) {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
    border-color: var(--brand);
}

.level-btn:active:not(:disabled) {
    transform: translateY(0) scale(0.95);
}

.level-btn:disabled {
    background-color: #f1f5f9;
    color: #cbd5e1;
    cursor: not-allowed;
    box-shadow: none;
}

.level-btn.completed {
    background-color: #dcfce7;
    border-color: #22c55e;
    color: #166534;
}

.level-btn.completed::after {
    content: '⭐';
    position: absolute;
    font-size: 0.8rem;
    top: 5px;
    right: 5px;
}

/* Area di Gioco */
.game-play-area {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.timer-badge {
    background: #fee2e2;
    color: #ef4444;
    padding: 6px 12px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 1.1rem;
    font-family: monospace;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.timer-badge.warning {
    animation: timerPulse 1s infinite;
}

@keyframes timerPulse {
    50% {
        opacity: 0.5;
        transform: scale(1.05);
    }
}

/* Griglia di Gioco */
.board-container {
    background-color: var(--board-bg);
    padding: 10px;
    border-radius: 12px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
    border: 3px solid #64748b;
}

.kanoodle-board {
    display: grid;
    gap: var(--grid-gap);
    background-color: transparent;
    border-radius: 4px;
    /* Grid template will be set by JS */
}

.board-cell {
    background-color: var(--board-cell);
    border-radius: 20%;
    width: clamp(25px, 8vw, 40px);
    height: clamp(25px, 8vw, 40px);
    box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.4), inset 0 -2px 4px rgba(0, 0, 0, 0.1);
    transition: background-color 0.2s;
    position: relative;
    user-select: none;
}

.board-cell.hint {
    background-color: #e0f2fe;
    opacity: 0.7;
}

.board-cell.hint-invalid {
    background-color: #fee2e2;
    /* Clear red feedback */
    opacity: 0.7;
}

.board-cell.snapped {
    animation: snapPulse 0.3s ease;
}

@keyframes snapPulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
        box-shadow: 0 0 15px var(--brand);
    }

    100% {
        transform: scale(1);
    }
}

/* Palette dei Pezzi */
.piece-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    justify-content: center;
    background-color: white;
    padding: 20px;
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    width: 100%;
    min-height: 150px;
}

/* Singolo Pezzo in Palette */
.palette-piece {
    cursor: grab;
    transition: transform 0.2s;
    touch-action: none;
    position: relative;
}

.palette-piece:active {
    cursor: grabbing;
}

.palette-piece:hover {
    transform: scale(1.05);
}

.palette-piece.selected {
    transform: scale(1.1);
    z-index: 10;
    filter: drop-shadow(0 0 8px rgba(0, 0, 0, 0.3));
}

.palette-piece.used {
    opacity: 0;
    pointer-events: none;
}

.palette-piece.dragging {
    opacity: 0.5;
    pointer-events: none;
}

.dragging-clone {
    opacity: 1 !important;
    pointer-events: none;
    z-index: 2000;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.4));
}

/* Stile Struttura Pezzo */
.piece-grid {
    display: grid;
    gap: var(--grid-gap);
    /* Blocks now receive pointer events to detect grab offset */
}

/* Blocchetto base del pezzo */
.piece-block {
    width: clamp(25px, 8vw, 40px);
    height: clamp(25px, 8vw, 40px);
    border-radius: 20%;
    box-shadow: inset 0 3px 5px rgba(255, 255, 255, 0.6), inset 0 -3px 5px rgba(0, 0, 0, 0.3), 0 2px 4px rgba(0, 0, 0, 0.4);
}

.piece-block.empty {
    background-color: transparent;
    box-shadow: none;
}

/* Controls */
.piece-controls {
    display: flex;
    justify-content: center;
    width: 100%;
}

.control-buttons {
    display: flex;
    gap: 10px;
    opacity: 0.5;
    pointer-events: none;
    transition: opacity 0.3s;
}

.control-buttons.active {
    opacity: 1;
    pointer-events: auto;
}

.btn-sm {
    padding: 8px 12px;
    font-size: 0.9rem;
}

/* Overlay Successo */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}


.overlay-content {
    background: white;
    padding: 40px 30px;
    border-radius: 24px;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    max-width: 90%;
}

.overlay-content h2 {
    color: var(--brand);
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.overlay-content p {
    font-size: 1.2rem;
    color: var(--ink-2);
    margin-bottom: 25px;
}

.overlay-content .btn {
    width: 100%;
}

@keyframes popIn {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}