/**
 * SpeechAce Tutor LMS - Styles
 * @version 2.1.0
 */

/* ===========================================
   INLINE WORD BUTTON - Nút nhỏ cho từng từ
   =========================================== */

.speechace-word-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    margin: 0 4px;
    background: linear-gradient(135deg, #fff0f3 0%, #ffe4e9 100%);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    vertical-align: middle;
    box-shadow: 0 2px 8px rgba(255, 182, 193, 0.3);
    line-height: 1;
    float: none !important;
}

.speechace-word-btn:hover {
    transform: scale(1.15);
    box-shadow: 0 4px 15px rgba(255, 182, 193, 0.5);
}

.speechace-word-btn:active {
    transform: scale(0.95);
}

.speechace-word-btn .sa-icon {
    font-size: 18px;
    line-height: 1;
}

/* Force inline với từ */
.speechace-word-btn {
    white-space: nowrap;
}

.speechace-word-btn .sa-text {
    font-size: 11px;
    color: white;
    margin-left: 4px;
}

/* Trong bảng */
table .speechace-word-btn {
    margin: 0 4px;
    display: inline-flex !important;
}

/* Đảm bảo luôn inline */
p .speechace-word-btn,
td .speechace-word-btn,
span .speechace-word-btn,
div .speechace-word-btn {
    display: inline-flex !important;
    vertical-align: middle;
}

/* ===========================================
   SENTENCE WRAPPER - Cho câu dài
   =========================================== */

.speechace-sentence-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: linear-gradient(135deg, #f5f7fa 0%, #e8ecf1 100%);
    border-radius: 10px;
    margin: 12px 0;
    border-left: 4px solid #667eea;
}

.speechace-sentence-wrapper .sentence-text {
    flex: 1;
    font-style: italic;
    color: #333;
    font-size: 15px;
    line-height: 1.5;
}

.speechace-sentence-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    background: linear-gradient(135deg, #fff0f3 0%, #ffe4e9 100%);
    color: #333;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
    white-space: nowrap;
    box-shadow: 0 2px 10px rgba(255, 182, 193, 0.3);
}

.speechace-sentence-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(255, 182, 193, 0.5);
}

.speechace-sentence-btn .sa-icon {
    font-size: 18px;
}

.speechace-sentence-btn .sa-label {
    font-size: 13px;
    color: #555;
}

/* ===========================================
   MODAL POPUP
   =========================================== */

.speechace-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.speechace-modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.speechace-modal-content {
    position: relative;
    background: white;
    border-radius: 20px;
    width: 90%;
    max-width: 400px;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.3s ease;
    display: flex;
    flex-direction: column;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.speechace-modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    background: #f0f0f0;
    border: none;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 10;
}

.speechace-modal-close:hover {
    background: #e0e0e0;
    transform: rotate(90deg);
}

/* Modal Header */
.modal-header {
    padding: 20px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    flex-shrink: 0;
}

.modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

/* Modal Body */
.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
    max-height: calc(90vh - 80px);
}

/* Target Display */
.target-display {
    text-align: center;
    margin-bottom: 24px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 12px;
}

.target-word {
    font-size: 28px;
    font-weight: 700;
    color: #1a1a2e;
    margin-bottom: 8px;
    word-break: break-word;
}

.target-ipa {
    font-size: 16px;
    color: #667eea;
    font-family: 'Segoe UI', sans-serif;
}

/* Recording Section */
.recording-section {
    text-align: center;
}

.record-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 20px 40px;
    background: white;
    border: 3px solid #667eea;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 0 auto;
}

.record-btn:hover {
    background: #f5f7ff;
    transform: scale(1.02);
}

.record-btn.recording {
    border-color: #f44336;
    background: #fff5f5;
    animation: recordingPulse 1.5s infinite;
}

@keyframes recordingPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(244, 67, 54, 0.4); }
    50% { box-shadow: 0 0 0 15px rgba(244, 67, 54, 0); }
}

.record-btn .record-icon {
    color: #667eea;
    transition: color 0.3s;
}

.record-btn.recording .record-icon {
    color: #f44336;
}

.record-btn .record-icon .inner-circle {
    transition: all 0.3s;
}

.record-btn.recording .record-icon .inner-circle {
    r: 8;
    fill: #f44336;
}

.record-btn .record-text {
    font-size: 14px;
    color: #666;
    font-weight: 500;
}

/* Audio Visualizer */
.audio-visualizer {
    margin-top: 16px;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 10px;
    display: none;
}

.record-btn.recording + .audio-visualizer {
    display: block;
}

.audio-visualizer canvas {
    width: 100%;
    height: 40px;
}

/* Recording Timer */
.recording-timer {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 12px;
    font-size: 14px;
    color: #f44336;
}

.record-btn.recording ~ .recording-timer {
    display: flex;
}

.timer-dot {
    width: 8px;
    height: 8px;
    background: #f44336;
    border-radius: 50%;
    animation: timerBlink 1s infinite;
}

@keyframes timerBlink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0.3; }
}

/* ===========================================
   RESULTS SECTION
   =========================================== */

.results-section {
    text-align: center;
    animation: fadeIn 0.4s ease;
}

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

/* Score Display */
.score-display {
    margin-bottom: 20px;
}

.main-score {
    position: relative;
    width: 120px;
    height: 120px;
    margin: 0 auto 12px;
}

.score-ring {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.ring-bg {
    fill: none;
    stroke: #e6e6e6;
    stroke-width: 3;
}

.ring-fill {
    fill: none;
    stroke: #667eea;
    stroke-width: 3;
    stroke-linecap: round;
    transition: stroke-dasharray 1s ease;
}

.ring-fill.excellent { stroke: #4CAF50; }
.ring-fill.good { stroke: #FF9800; }
.ring-fill.poor { stroke: #f44336; }

.score-number {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 36px;
    font-weight: 700;
    color: #1a1a2e;
}

.score-label {
    font-size: 14px;
    color: #666;
}

/* Score Details */
.score-details {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 16px;
}

.detail-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #f5f7fa;
    border-radius: 20px;
}

.detail-label {
    font-size: 12px;
    color: #666;
}

.detail-value {
    font-size: 14px;
    font-weight: 600;
    color: #667eea;
}

/* Word Breakdown */
.word-breakdown {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #eee;
    text-align: left;
}

.word-breakdown h4 {
    font-size: 14px;
    color: #333;
    margin-bottom: 12px;
}

.phoneme-display {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.phoneme-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 15px;
    font-size: 13px;
    font-family: monospace;
}

.phoneme-item.good {
    background: #e8f5e9;
    color: #2e7d32;
}

.phoneme-item.average {
    background: #fff3e0;
    color: #e65100;
}

.phoneme-item.poor {
    background: #ffebee;
    color: #c62828;
}

.phoneme-score {
    font-size: 10px;
    opacity: 0.8;
}

/* Feedback Message */
.feedback-message {
    padding: 12px 20px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 500;
    margin: 16px 0;
}

.feedback-message.excellent {
    background: #e8f5e9;
    color: #2e7d32;
}

.feedback-message.good {
    background: #fff3e0;
    color: #e65100;
}

.feedback-message.poor {
    background: #ffebee;
    color: #c62828;
}

/* Try Again Button */
.try-again-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 28px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 8px;
}

.try-again-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

/* ===========================================
   ERROR & LOADING
   =========================================== */

.error-section {
    text-align: center;
    padding: 20px;
}

.error-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.error-message {
    color: #c62828;
    margin-bottom: 16px;
}

.loading-section {
    text-align: center;
    padding: 40px 20px;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #e6e6e6;
    border-top-color: #667eea;
    border-radius: 50%;
    margin: 0 auto 16px;
    animation: spin 1s linear infinite;
}

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

.loading-text {
    color: #666;
    font-size: 14px;
}

/* ===========================================
   PRACTICE WIDGET (Full version)
   =========================================== */

.speechace-practice-widget {
    background: white;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    padding: 24px;
    margin: 24px 0;
    max-width: 500px;
}

.speechace-practice-widget .speechace-header h4 {
    margin: 0 0 16px 0;
    font-size: 18px;
    color: #1a1a2e;
}

.speechace-practice-widget .speechace-target-text {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 20px;
}

.speechace-practice-widget .speechace-target-text label {
    font-size: 12px;
    opacity: 0.9;
    display: block;
    margin-bottom: 8px;
}

.speechace-practice-widget .target-sentence {
    font-size: 20px;
    font-weight: 500;
    margin: 0;
}

.speechace-practice-widget .speechace-record-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 14px 24px;
    background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
    color: white;
    border: none;
    border-radius: 30px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.speechace-practice-widget .speechace-record-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.4);
}

.speechace-practice-widget .speechace-record-btn.recording {
    background: linear-gradient(135deg, #f44336 0%, #d32f2f 100%);
}

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

@media (max-width: 480px) {
    .speechace-modal-content {
        width: 95%;
        max-height: 95vh;
        border-radius: 16px;
    }
    
    .modal-body {
        padding: 16px;
    }
    
    .target-word {
        font-size: 24px;
    }
    
    .main-score {
        width: 100px;
        height: 100px;
    }
    
    .score-number {
        font-size: 28px;
    }
    
    .speechace-sentence-wrapper {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .speechace-sentence-btn {
        align-self: flex-end;
    }
}

/* ===========================================
   TUTOR LMS SPECIFIC
   =========================================== */

.tutor-lesson-content .speechace-word-btn {
    margin: 0 2px;
}

.tutor-course-content-wrap .speechace-practice-widget {
    max-width: 100%;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
    .speechace-modal-content {
        background: #1e1e2e;
    }
    
    .target-display {
        background: #2a2a3e;
    }
    
    .target-word {
        color: #e0e0e0;
    }
    
    .record-btn {
        background: #2a2a3e;
        border-color: #667eea;
    }
    
    .record-btn:hover {
        background: #333346;
    }
}
