/**
 * Listening Practice Widget - Styles
 * 
 * Clean, modern, therapeutic design.
 * Mobile-first, accessible, audio-focused.
 * 
 * @package Aphasia_Exercises
 * @since 1.0.1
 * 
 * FIXES:
 * - v1.0.1: Fixed image sizing to fill grid boxes, fixed progress bar visibility
 */

/* =========================================================================
   1. BASE CONTAINER
   ========================================================================= */

.listening-practice-root {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: #1f2937;
    max-width: 800px;
    margin: 0 auto;
    padding: 16px;
}

.listening-practice-container {
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    padding: 24px;
    min-height: 400px;
}

/* =========================================================================
   2. HEADER
   ========================================================================= */

.listening-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid #f3f4f6;
    position: relative;
}

.title-area {
    display: flex;
    align-items: center;
    gap: 10px;
}

.exercise-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: #1f2937;
    margin: 0;
}

.settings-toggle {
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 10px;
    font-size: 1.2rem;
    cursor: pointer;
    transition: 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.settings-toggle:hover {
    background: #e5e7eb;
    border-color: #d1d5db;
}

.settings-toggle.open {
    background: #3b82f6;
    border-color: #3b82f6;
    color: white;
}

/* =========================================================================
   3. SETTINGS PANEL
   ========================================================================= */

.settings-panel {
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 100;
    background: #f9fafb;
    border-radius: 12px;
    padding: 16px;
    margin-top: 8px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15);
    animation: dropdownFadeIn 0.2s ease;
    min-width: 240px;
}

@keyframes dropdownFadeIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.setting-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.setting-row:last-child {
    margin-bottom: 0;
}

.setting-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #4b5563;
    min-width: 70px;
    flex-shrink: 0;
}

.setting-select-wrapper {
    flex: 1;
}

.setting-select {
    width: 100%;
    padding: 10px 36px 10px 14px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    background: #f8fafc;
    color: #1f2937;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 44px;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6,9 12,15 18,9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
}

.setting-select:hover {
    border-color: #cbd5e1;
    background-color: #f1f5f9;
}

.setting-select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

/* =========================================================================
   4. PROGRESS BAR
   ========================================================================= */

.progress-bar-container {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: #f3f4f6;
    border-radius: 9999px;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.06);
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #8b5cf6, #3b82f6);
    border-radius: 9999px;
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 0.8rem;
    font-weight: 600;
    color: #374151;
    white-space: nowrap;
}

.score-text {
    font-size: 0.75rem;
    color: #6b7280;
    white-space: nowrap;
}

.streak-badge {
    font-size: 0.85rem;
    font-weight: 600;
    color: #ea580c;
    background: #fff7ed;
    padding: 2px 8px;
    border-radius: 9999px;
    animation: streakPop 0.3s ease;
}

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

/* =========================================================================
   5. AUDIO PLAYER SECTION
   ========================================================================= */

.audio-player-section {
    background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
    border-radius: 16px;
    padding: 32px 24px;
    text-align: center;
    margin-bottom: 24px;
}

.play-audio-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 16px 40px;
    background: white !important;
    border: none;
    border-radius: 9999px;
    font-size: 1.1rem;
    font-weight: 600;
    color: #6366f1 !important;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    margin-bottom: 16px;
}

.play-audio-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px -2px rgba(0, 0, 0, 0.15);
}

.play-audio-btn:disabled {
    opacity: 0.8;
    cursor: not-allowed;
}

.play-audio-btn.playing {
    background: #f0fdf4;
    color: #16a34a;
}

.play-icon {
    font-size: 1.3rem;
}

.audio-controls {
    display: flex;
    justify-content: center;
    gap: 12px;
}

.audio-control-btn {
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.2) !important;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 9999px;
    color: rgb(0, 0, 0) !important;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.audio-control-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.6);
}

.audio-control-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.audio-control-btn.locked {
    opacity: 0.7;
    cursor: pointer;
}

.audio-control-btn.locked:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* =========================================================================
   6. PROMPT
   ========================================================================= */

.listening-prompt {
    font-size: 1.1rem;
    font-weight: 500;
    color: #374151;
    text-align: center;
    margin: 0 0 20px 0;
}

/* =========================================================================
   7. IMAGE CHOICES GRID - FIXED FOR FULL-SIZE IMAGES
   ========================================================================= */

.choices-grid {
    display: grid;
    gap: 12px;
    margin-bottom: 20px;
    border-radius: 12px;
    background-color: transparent;
}

/* 2 choices - side by side */
.choices-grid.choices-2 {
    grid-template-columns: repeat(2, 1fr);
}

/* 3 choices - 2 top, 1 bottom centered */
.choices-grid.choices-3 {
    grid-template-columns: repeat(2, 1fr);
}

.choices-grid.choices-3 .choice-item:nth-child(3) {
    grid-column: 1 / -1;
    max-width: 50%;
    justify-self: center;
}

/* 4 choices - 2x2 grid */
.choices-grid.choices-4 {
    grid-template-columns: repeat(2, 1fr);
}

.choice-item {
    aspect-ratio: 1;
    background: #f9fafb !important;
    border: 3px solid #e5e7eb;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
    position: relative;
}

.choice-item:hover:not(:disabled) {
    border-color: #8b5cf6;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.2);
}

.choice-item:focus {
    outline: none;
    border-color: #8b5cf6;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.2);
}

.choice-item:disabled {
    cursor: not-allowed;
}

.choice-item.selected {
    border-color: #3b82f6;
    border-width: 4px;
}

.choice-item.correct {
    border-color: #22c55e;
    border-width: 4px;
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
}

.choice-item.incorrect {
    border-color: #ef4444;
    border-width: 4px;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
}

.choice-image {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
}

/* =========================================================================
   8. FEEDBACK OVERLAY
   ========================================================================= */

.feedback-overlay {
    text-align: center;
    padding: 20px;
    border-radius: 12px;
    margin-top: 16px;
    animation: fadeInUp 0.3s ease;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.feedback-overlay.correct {
    background: #f0fdf4;
    border: 2px solid #22c55e;
}

.feedback-overlay.incorrect {
    background: #fef2f2;
    border: 2px solid #ef4444;
}

.feedback-message {
    display: block;
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.feedback-overlay.correct .feedback-message {
    color: #16a34a;
}

.feedback-overlay.incorrect .feedback-message {
    color: #dc2626;
}

.correct-answer {
    display: block;
    font-size: 1rem;
    color: #4b5563;
    margin-bottom: 12px;
}

.hear-answer-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    background: #8b5cf6;
    border: none;
    border-radius: 9999px;
    color: white;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s ease;
}

.hear-answer-btn:hover:not(:disabled) {
    background: #7c3aed;
}

.hear-answer-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* =========================================================================
   9. LOADING & ERROR STATES
   ========================================================================= */

.listening-loading,
.listening-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    text-align: center;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e5e7eb;
    border-top-color: #8b5cf6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 12px;
}

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

.listening-error p {
    color: #ef4444;
    margin-bottom: 16px;
}

.retry-btn {
    padding: 12px 24px;
    background: #8b5cf6;
    border: none;
    border-radius: 9999px;
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s ease;
}

.retry-btn:hover {
    background: #7c3aed;
}

/* =========================================================================
   10. COMPLETE SCREEN
   ========================================================================= */

.listening-complete-screen {
    text-align: center;
    padding: 20px 0;
}

.celebration {
    font-size: 3.5rem;
    margin-bottom: 12px;
    animation: bounce 0.5s ease;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
}

.listening-complete-screen h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1f2937;
    margin: 0 0 24px 0;
}

.session-stats {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin-bottom: 24px;
}

.stat {
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 2.25rem;
    font-weight: 700;
    color: #8b5cf6;
}

.stat-label {
    font-size: 0.8rem;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.encouragement {
    font-size: 1.1rem;
    color: #4b5563;
    margin-bottom: 28px;
}

.upgrade-cta {
    background: #fffbeb;
    border: 1px solid #fcd34d;
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 24px;
}

.upgrade-cta p {
    font-size: 0.9rem;
    color: #92400e;
    margin: 0 0 14px 0;
}

.upgrade-btn {
    display: inline-block;
    padding: 12px 28px;
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
    font-weight: 600;
    text-decoration: none;
    border-radius: 9999px;
    transition: 0.2s ease;
}

.upgrade-btn:hover {
    transform: translateY(-1px);
}

.restart-btn {
    padding: 14px 36px;
    background: #8b5cf6;
    border: none;
    border-radius: 9999px;
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s ease;
}

.restart-btn:hover {
    background: #7c3aed;
}

/* =========================================================================
   11. LOGIN PROMPT
   ========================================================================= */

.login-prompt-overlay {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 24px;
    min-height: 350px;
}

.login-prompt-icon {
    font-size: 3.5rem;
    margin-bottom: 16px;
    animation: gentleBounce 2s ease-in-out infinite;
}

@keyframes gentleBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.login-prompt-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1f2937;
    margin: 0 0 12px 0;
}

.login-prompt-description {
    font-size: 1rem;
    color: #4b5563;
    max-width: 320px;
    margin: 0 0 20px 0;
    line-height: 1.5;
}

.login-prompt-benefits {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px 20px;
    margin-bottom: 28px;
}

.login-prompt-benefits span {
    font-size: 0.9rem;
    color: #16a34a;
    font-weight: 500;
}

.login-prompt-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 280px;
}

.login-prompt-btn {
    display: block;
    padding: 14px 28px;
    border-radius: 9999px;
    font-size: 1rem;
    font-weight: 600;
    text-decoration: none;
    text-align: center;
    transition: all 0.2s ease;
}

.login-prompt-btn.primary {
    background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
    color: white;
    box-shadow: 0 4px 6px -1px rgba(139, 92, 246, 0.3);
}

.login-prompt-btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px -2px rgba(139, 92, 246, 0.4);
}

.login-prompt-btn.secondary {
    background: white;
    color: #4b5563;
    border: 2px solid #e5e7eb;
    font-size: 0.9rem;
    padding: 12px 24px;
}

.login-prompt-btn.secondary:hover {
    border-color: #8b5cf6;
    color: #8b5cf6;
}

/* =========================================================================
   12. RESPONSIVE - MOBILE OPTIMIZED
   ========================================================================= */

@media (max-width: 500px) {
    .listening-practice-root {
        padding: 8px;
    }
    
    .listening-practice-container {
        padding: 16px;
        border-radius: 12px;
    }
    
    .exercise-title {
        font-size: 1.1rem;
    }
    
    /* Progress bar mobile */
    .progress-bar-container {
        gap: 8px;
    }
    
    .audio-player-section {
        padding: 24px 16px;
        border-radius: 12px;
    }
    
    .play-audio-btn {
        padding: 14px 28px;
        font-size: 1rem;
        width: 100%;
        justify-content: center;
    }
    
    .audio-controls {
        flex-direction: column;
        gap: 8px;
    }
    
    .audio-control-btn {
        width: 100%;
        padding: 12px 20px;
    }
    
    /* Larger touch targets for images on mobile */
    .choices-grid {
        gap: 10px;
    }
    
    .choice-item {
        border-radius: 10px;
        border-width: 4px;
    }
    
    .choice-item.selected,
    .choice-item.correct,
    .choice-item.incorrect {
        border-width: 5px;
    }
    
    .choice-image {
        border-radius: 6px;
    }
    
    .listening-prompt {
        font-size: 1rem;
        margin-bottom: 16px;
    }
    
    .feedback-overlay {
        padding: 16px;
    }
    
    .session-stats {
        gap: 24px;
    }
    
    .stat-value {
        font-size: 1.75rem;
    }
    
    .setting-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .settings-panel {
        min-width: 220px;
        right: -10px;
    }
}

/* Extra small screens */
@media (max-width: 360px) {
    .listening-practice-container {
        padding: 12px;
    }
    
    .choices-grid {
        gap: 8px;
    }
    
    .play-audio-btn {
        padding: 12px 20px;
        font-size: 0.95rem;
    }
}

/* =========================================================================
   13. ACCESSIBILITY
   ========================================================================= */

.settings-toggle:focus,
.play-audio-btn:focus,
.audio-control-btn:focus,
.choice-item:focus,
.hear-answer-btn:focus,
.retry-btn:focus,
.restart-btn:focus,
.setting-select:focus {
    outline: 3px solid #8b5cf6;
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .loading-spinner,
    .celebration,
    .streak-badge,
    .login-prompt-icon {
        animation: none;
    }
    
    .choice-item:hover,
    .play-audio-btn:hover,
    .restart-btn:hover {
        transform: none;
    }
}

/* =========================================================================
   14. ELEMENTOR PREVIEW
   ========================================================================= */

.listening-practice-preview {
    padding: 20px;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid #e5e7eb;
}

.preview-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
}

.preview-badge {
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 9999px;
}

.preview-settings {
    background: #f9fafb;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
}

.preview-settings p {
    margin: 4px 0;
    font-size: 0.9rem;
    color: #4b5563;
}

.preview-exercise {
    text-align: center;
}

.preview-audio-player {
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 20px;
}

.preview-play-btn {
    background: white;
    border: none;
    padding: 12px 24px;
    border-radius: 9999px;
    font-size: 1rem;
    font-weight: 600;
    color: #6366f1;
    cursor: default;
}

.preview-prompt {
    font-size: 1rem;
    color: #374151;
    margin-bottom: 16px;
}

.preview-choices-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    max-width: 400px;
    margin: 0 auto;
}

.preview-choice {
    aspect-ratio: 1;
    background: #f3f4f6;
    border: 2px dashed #d1d5db;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    color: #6b7280;
}