/* ===== Puzzle Overlay ===== */
.puzzle-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.puzzle-overlay.active {
    display: flex;
}

.puzzle-modal {
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.95) 0%, rgba(10, 14, 39, 0.98) 100%);
    border: 2px solid rgba(99, 102, 241, 0.3);
    border-radius: 24px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7), 0 0 80px rgba(99, 102, 241, 0.3);
    overflow: hidden;
    animation: slideUp 0.4s ease;
}

.puzzle-header {
    padding: 2rem;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.2) 0%, transparent 100%);
    border-bottom: 1px solid rgba(99, 102, 241, 0.2);
    text-align: center;
}

.puzzle-header h2 {
    font-size: 2rem;
    color: #fff;
    margin-bottom: 0.5rem;
}

.puzzle-desc {
    color: #9ca3af;
    font-size: 1rem;
}

.puzzle-content {
    padding: 2rem;
    overflow-y: auto;
    max-height: calc(90vh - 150px);
}

/* Common Puzzle Styles */
.puzzle-progress {
    margin-bottom: 2rem;
    text-align: center;
}

.progress-bar {
    width: 100%;
    height: 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 0.75rem;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #10b981 0%, #6366f1 100%);
    transition: width 0.4s ease;
    border-radius: 6px;
}

.progress-text {
    font-size: 1.1rem;
    color: #fff;
    font-weight: 600;
}

.hint {
    color: #9ca3af;
    font-style: italic;
    margin-top: 1rem;
}

/* ===== Reconstruction Puzzle ===== */
.reconstruction-puzzle {
    width: 100%;
}

.puzzle-main {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.reconstruction-area {
    position: relative;
    width: 100%;
    max-width: 500px;
    height: 500px;
    margin: 0 auto;
    background: rgba(99, 102, 241, 0.08);
    border: 3px solid rgba(99, 102, 241, 0.3);
    border-radius: 20px;
    padding: 1rem;
}

.guitar-outline {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}

.drop-zones {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.drop-zone {
    position: absolute;
    border: 3px dashed rgba(167, 139, 250, 0.8);
    border-radius: 8px;
    background: rgba(167, 139, 250, 0.2);
    transition: all 0.3s ease;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: rgba(167, 139, 250, 0.6);
    font-weight: 700;
}

.zone-number {
    pointer-events: none;
}

.drop-zone.drag-over {
    background: rgba(16, 185, 129, 0.2);
    border-color: #10b981;
    transform: scale(1.05);
}

.pieces-tray {
    padding: 2rem;
    background: rgba(255, 255, 255, 0.08);
    border: 2px solid rgba(99, 102, 241, 0.3);
    border-radius: 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    justify-content: center;
    align-items: center;
    min-height: 180px;
}

.hint {
    width: 100%;
    text-align: center;
    color: #a78bfa !important;
    font-size: 1.1rem !important;
    margin-bottom: 1rem !important;
}

.puzzle-piece {
    cursor: grab;
    transition: all 0.3s ease;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
    border: 3px solid rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.piece-label {
    color: white;
    font-size: 1.5rem;
    font-weight: 700;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    pointer-events: none;
}

.puzzle-piece:hover {
    transform: scale(1.15) rotate(0deg) !important;
    box-shadow: 0 10px 20px rgba(99, 102, 241, 0.6);
    border-color: #6366f1;
}

.puzzle-piece.dragging {
    opacity: 0.7;
    cursor: grabbing;
    transform: scale(1.1) !important;
}

.puzzle-piece.placed {
    cursor: default;
    box-shadow: 0 0 25px rgba(16, 185, 129, 0.8);
    border-color: #10b981;
}

.puzzle-piece.placed .piece-label {
    color: #10b981;
}

.puzzle-piece.shake {
    animation: shake 0.5s ease;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-10px);
    }

    75% {
        transform: translateX(10px);
    }
}

/* ===== Rhythm Puzzle ===== */
.rhythm-puzzle {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
}

.rhythm-progress p {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.rhythm-hint {
    font-size: 1rem !important;
    color: #9ca3af !important;
    font-weight: 400 !important;
}

.rhythm-display {
    margin: 2rem 0;
    padding: 3rem;
    background: rgba(99, 102, 241, 0.1);
    border-radius: 16px;
    text-align: center;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sequence-indicator {
    font-size: 3rem;
    animation: pulse 1.5s ease-in-out infinite;
}

.watching-text,
.playing-text,
.success-text,
.fail-text {
    font-size: 1.5rem;
    font-weight: 600;
}

.success-text {
    color: #10b981;
}

.fail-text {
    color: #ef4444;
}

.rhythm-notes {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
    margin: 2rem 0;
}

.note-button {
    width: 100px;
    height: 100px;
    border: none;
    border-radius: 16px;
    font-size: 1.25rem;
    font-weight: 700;
    color: white;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.note-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.2);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.note-button:hover::before {
    opacity: 1;
}

.note-button:active {
    transform: scale(0.95);
}

.note-button.playing {
    transform: scale(1.2);
    box-shadow: 0 0 40px currentColor;
    animation: noteGlow 0.6s ease;
}

.note-button.clicked {
    animation: notePress 0.2s ease;
}

@keyframes noteGlow {

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

    50% {
        transform: scale(1.2);
    }
}

@keyframes notePress {

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

    50% {
        transform: scale(0.9);
    }
}

.note-name {
    font-size: 1rem;
}

.rhythm-controls {
    margin-top: 2rem;
    text-align: center;
}

.btn-secondary {
    padding: 0.75rem 2rem;
    background: rgba(99, 102, 241, 0.2);
    color: white;
    border: 2px solid #6366f1;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-secondary:hover {
    background: rgba(99, 102, 241, 0.4);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.btn-secondary:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* ===== Memory Card Puzzle ===== */
.memory-puzzle {
    width: 100%;
    max-width: 700px;
    margin: 0 auto;
}

.memory-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-top: 2rem;
}

.memory-card {
    aspect-ratio: 1;
    cursor: pointer;
    perspective: 1000px;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.6s;
    transform-style: preserve-3d;
}

.memory-card.flipped .card-inner {
    transform: rotateY(180deg);
}

.memory-card.matched .card-inner {
    transform: rotateY(180deg) scale(1.05);
}

.card-front,
.card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.card-front {
    background: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%);
    color: white;
}

.card-back {
    background: linear-gradient(135deg, #10b981 0%, #34d399 100%);
    transform: rotateY(180deg);
}

.memory-card.matched .card-back {
    animation: cardSuccess 0.6s ease;
}

.memory-card.celebrate {
    animation: celebrate 0.6s ease;
}

@keyframes cardSuccess {

    0%,
    100% {
        transform: rotateY(180deg) scale(1);
    }

    50% {
        transform: rotateY(180deg) scale(1.2);
    }
}

@keyframes celebrate {

    0%,
    100% {
        transform: translateY(0);
    }

    25% {
        transform: translateY(-20px) rotate(-10deg);
    }

    75% {
        transform: translateY(-10px) rotate(10deg);
    }
}

/* Puzzle Completion */
.puzzle-complete {
    text-align: center;
    padding: 3rem;
}

.success-icon {
    font-size: 5rem;
    margin-bottom: 1rem;
    animation: successBounce 1s ease;
}

@keyframes successBounce {

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

    50% {
        transform: scale(1.3);
    }
}

.puzzle-complete h2 {
    font-size: 2.5rem;
    color: #10b981;
    margin-bottom: 1rem;
}

.puzzle-complete p {
    font-size: 1.25rem;
    color: #9ca3af;
}

/* Responsive */
@media (max-width: 768px) {
    .puzzle-modal {
        width: 95%;
        max-height: 95vh;
    }

    .memory-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.75rem;
    }

    .note-button {
        width: 70px;
        height: 70px;
    }

    .reconstruction-area {
        max-width: 100%;
    }
}