/**
 * Puzzle Activity Styles
 *
 * @package Crowdaa_Challenges_Calendar
 * @since 4.12.126
 */

/* ========== CONTAINER ========== */

.puzzle-container {
    padding: 20px;
    max-width: 600px;
    margin: 0 auto;
}

/* ========== HEADER ========== */

.puzzle-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    padding: 12px 16px;
    border-radius: 12px;
    margin-bottom: 16px;
}

.puzzle-info {
    display: flex;
    gap: 16px;
    font-size: 13px;
    color: #92400e;
}

.puzzle-grid-info,
.puzzle-moves-count {
    display: flex;
    align-items: center;
    gap: 6px;
}

.puzzle-grid-info svg,
.puzzle-moves-count svg {
    flex-shrink: 0;
}

.puzzle-timer {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 18px;
    font-weight: 700;
    color: #92400e;
}

.puzzle-timer.has-limit {
    color: #f59e0b;
}

.puzzle-timer.warning {
    color: #ef4444;
    animation: pulse 1s ease infinite;
}

.puzzle-time-limit {
    font-size: 14px;
    font-weight: 400;
    opacity: 0.7;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ========== HINT ========== */

.puzzle-hint {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fff7ed;
    border: 1px solid #fed7aa;
    padding: 12px 16px;
    border-radius: 10px;
    margin-bottom: 16px;
    font-size: 14px;
    color: #c2410c;
}

.puzzle-hint svg {
    flex-shrink: 0;
    color: #f59e0b;
}

/* ========== PREVIEW TOGGLE ========== */

.puzzle-preview-toggle {
    margin-bottom: 16px;
    text-align: center;
}

.puzzle-preview-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: white;
    border: 2px solid #fcd34d;
    padding: 10px 20px;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 500;
    color: #92400e;
    cursor: pointer;
    transition: all 0.2s ease;
}

.puzzle-preview-btn:hover {
    background: #fef3c7;
    border-color: #f59e0b;
}

.puzzle-preview-btn.active {
    background: #f59e0b;
    border-color: #f59e0b;
    color: white;
}

.puzzle-preview-image {
    margin-top: 12px;
    padding: 12px;
    background: white;
    border: 2px solid #fcd34d;
    border-radius: 12px;
}

.puzzle-preview-image img {
    max-width: 200px;
    max-height: 200px;
    border-radius: 8px;
    margin: 0 auto;
    display: block;
}

/* ========== GAME AREA ========== */

.puzzle-game-area {
    background: white;
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.puzzle-board {
    display: grid;
    grid-template-columns: repeat(var(--grid-size, 3), 1fr);
    gap: 4px;
    aspect-ratio: 1;
    background: #e5e7eb;
    border-radius: 12px;
    padding: 4px;
    touch-action: none;
}

/* ========== PIECES ========== */

.puzzle-piece {
    position: relative;
    aspect-ratio: 1;
    /* background-size et background-position sont définis inline par JS */
    /* NE PAS mettre de valeurs par défaut ici, elles écraseraient le JS */
    border-radius: 6px;
    cursor: grab;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    overflow: hidden;
}

.puzzle-piece:active {
    cursor: grabbing;
}

.puzzle-piece.dragging {
    transform: scale(1.05);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
    z-index: 100;
    opacity: 0.9;
}

.puzzle-piece.drag-over {
    transform: scale(0.95);
    box-shadow: inset 0 0 0 3px #f59e0b;
}

.puzzle-piece.correct {
    box-shadow: inset 0 0 0 3px #22c55e;
}

.puzzle-piece-number {
    position: absolute;
    top: 4px;
    left: 4px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    pointer-events: none;
}

/* ========== ACTIONS ========== */

.puzzle-actions {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 16px;
}

.puzzle-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: 25px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
}

.puzzle-btn-primary {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
}

.puzzle-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(245, 158, 11, 0.4);
}

.puzzle-btn-primary:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.puzzle-btn-secondary {
    background: white;
    border: 2px solid #fcd34d;
    color: #92400e;
}

.puzzle-btn-secondary:hover {
    background: #fef3c7;
    border-color: #f59e0b;
}

/* ========== POTENTIAL POINTS ========== */

.puzzle-potential-points {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    padding: 12px 20px;
    border-radius: 12px;
    color: #92400e;
    font-size: 14px;
}

.puzzle-potential-points svg {
    color: #f59e0b;
}

/* ========== RESULT MESSAGE ========== */

.puzzle-result-message {
    text-align: center;
    padding: 20px;
    border-radius: 12px;
    margin-top: 16px;
}

.puzzle-result-message.success {
    background: linear-gradient(135deg, #dcfce7, #bbf7d0);
    color: #166534;
}

.puzzle-result-message.timeout {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    color: #92400e;
}

/* ========== RESULTS (COMPLETED) ========== */

.puzzle-completed {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
}

/* Spécificité maximale pour écraser .results-icon */
.puzzle-container.puzzle-completed .results-header {
    margin-bottom: 24px;
    text-align: center;
}

.puzzle-container.puzzle-completed .results-header h3 {
    font-size: 22px;
    font-weight: 700;
    color: #1f2937;
    margin: 0;
}

/* Triple sélecteur pour écraser tous les contextes */
.puzzle-container .results-icon,
.puzzle-container .puzzle-results-icon,
.crowdaa-modal .puzzle-container .results-icon,
.crowdaa-modal .puzzle-container .puzzle-results-icon,
.quiz-completed-results .puzzle-container .results-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    border-radius: 50%;
    margin-bottom: 16px;
    color: white;
    font-size: 0;
    animation: none;
}

.puzzle-container .results-icon svg,
.puzzle-container .puzzle-results-icon svg,
.crowdaa-modal .puzzle-container .results-icon svg {
    width: 48px;
    height: 48px;
    stroke: white;
}

/* Image complétée */
.puzzle-completed-image {
    margin-bottom: 24px;
    text-align: center;
}

.puzzle-completed-image img {
    max-width: 280px;
    max-height: 280px;
    border-radius: 16px;
    border: 4px solid #f59e0b;
    box-shadow: 0 8px 24px rgba(245, 158, 11, 0.3);
}

/* Stats */
.puzzle-results-stats {
    display: flex;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.puzzle-container .result-card {
    background: white;
    padding: 16px 24px;
    border-radius: 12px;
    text-align: center;
    min-width: 100px;
    border: 2px solid #fcd34d;
}

.puzzle-container .result-card .result-icon {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 8px auto;
}

.puzzle-container .result-card .result-icon svg {
    width: 22px;
    height: 22px;
    stroke: #f59e0b;
}

.puzzle-container .result-card .result-value {
    font-size: 24px;
    font-weight: 700;
    color: #f59e0b;
}

.puzzle-container .result-card .result-label {
    font-size: 12px;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.puzzle-container .result-card.result-card-points {
    border-color: #22c55e;
}

.puzzle-container .result-card.result-card-points .result-icon {
    background: linear-gradient(135deg, #dcfce7, #bbf7d0);
}

.puzzle-container .result-card.result-card-points .result-icon svg {
    stroke: #22c55e;
}

.puzzle-container .result-card.result-card-points .result-value {
    color: #22c55e;
}

/* Bouton classement */
.puzzle-leaderboard-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
    border: none;
    padding: 14px 28px;
    border-radius: 25px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.puzzle-leaderboard-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(245, 158, 11, 0.4);
}

/* ========== MODAL CONTEXT ========== */

.crowdaa-modal .puzzle-container .result-card .result-icon {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    font-size: 0;
}

.crowdaa-modal .puzzle-container .result-card .result-icon svg {
    width: 22px;
    height: 22px;
    stroke: #f59e0b;
}

/* ========== RESPONSIVE ========== */

@media (max-width: 480px) {
    .puzzle-container {
        padding: 16px;
    }

    .puzzle-header {
        flex-direction: column;
        gap: 12px;
        text-align: center;
    }

    .puzzle-info {
        justify-content: center;
    }

    .puzzle-actions {
        flex-direction: column;
    }

    .puzzle-btn {
        width: 100%;
        justify-content: center;
    }

    .puzzle-results-stats {
        gap: 12px;
    }

    .puzzle-container .result-card {
        padding: 12px 16px;
        min-width: 80px;
    }

    .puzzle-container .result-card .result-value {
        font-size: 20px;
    }

    .puzzle-completed-image img {
        max-width: 200px;
    }
}

/* ========== ANIMATIONS ========== */

@keyframes celebrate {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.puzzle-container.completed .puzzle-completed-image img {
    animation: celebrate 0.5s ease;
}

/* Loading state */
.puzzle-board.loading {
    opacity: 0.5;
    pointer-events: none;
}

.puzzle-board.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border: 4px solid #fcd34d;
    border-top-color: #f59e0b;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}
