/**
 * Thai Pronunciation Trainer - Word Cards
 * Card layout, images, audio buttons, validation badge
 */

/* ============================================
   Word Card - Layout
   ============================================ */

.tpt-word-card {
    background: linear-gradient(145deg, rgba(45, 55, 72, 0.8), rgba(30, 38, 52, 0.8));
    backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 32px;
    transition: all 0.2s ease;
    position: relative;
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 24px;
    align-items: center;
}

/* Validated state - green (lower priority) */
.tpt-word-card.validated {
    background: linear-gradient(145deg, 
        rgba(34, 197, 94, 0.65) 0%,
        rgba(16, 185, 129, 0.6) 50%,
        rgba(5, 150, 105, 0.55) 100%);
    box-shadow: 0 3px 16px rgba(34, 197, 94, 0.25),
                0 0 32px rgba(16, 185, 129, 0.12);
    position: relative;
    overflow: hidden;
    animation: cardPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Needs improvement - orange (higher priority, overrides validated) */
.tpt-word-card.needs-improvement {
    background: linear-gradient(145deg, 
        rgba(255, 149, 0, 0.7) 0%,
        rgba(255, 159, 10, 0.65) 35%,
        rgba(251, 146, 60, 0.6) 100%) !important;
    box-shadow: 0 3px 16px rgba(255, 149, 0, 0.28),
                0 0 32px rgba(255, 159, 10, 0.14) !important;
}

/* Error state - orange rougeâtre (highest priority) */
.tpt-word-card.has-error {
    background: linear-gradient(145deg, 
        rgba(254, 124, 88, 0.45) 0%,
        rgba(251, 101, 66, 0.42) 50%,
        rgba(239, 68, 48, 0.4) 100%) !important;
    box-shadow: 0 3px 16px rgba(251, 101, 66, 0.22),
                0 0 32px rgba(254, 124, 88, 0.1) !important;
}

@keyframes cardPop {
    0% { transform: scale(1); }
    50% { transform: scale(1.03); }
    100% { transform: scale(1); }
}

.tpt-word-card.validated::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(
        45deg,
        transparent 30%,
        rgba(255, 255, 255, 0.06) 50%,
        transparent 70%
    );
    pointer-events: none;
}

/* Animation shine avec durées variées pour effet moins régulier - RALENTI */
.tpt-word-card.validated:nth-child(1)::before { animation: validateShine 7.2s ease-in-out infinite; animation-delay: 0s; }
.tpt-word-card.validated:nth-child(2)::before { animation: validateShine 6.7s ease-in-out infinite; animation-delay: 1.2s; }
.tpt-word-card.validated:nth-child(3)::before { animation: validateShine 7.8s ease-in-out infinite; animation-delay: 2.1s; }
.tpt-word-card.validated:nth-child(4)::before { animation: validateShine 6.3s ease-in-out infinite; animation-delay: 3.5s; }
.tpt-word-card.validated:nth-child(5)::before { animation: validateShine 8.1s ease-in-out infinite; animation-delay: 0.9s; }
.tpt-word-card.validated:nth-child(6)::before { animation: validateShine 7.5s ease-in-out infinite; animation-delay: 2.8s; }
.tpt-word-card.validated:nth-child(7)::before { animation: validateShine 6.9s ease-in-out infinite; animation-delay: 4.2s; }
.tpt-word-card.validated:nth-child(8)::before { animation: validateShine 7.6s ease-in-out infinite; animation-delay: 1.5s; }
.tpt-word-card.validated:nth-child(9)::before { animation: validateShine 8.3s ease-in-out infinite; animation-delay: 3.1s; }
.tpt-word-card.validated:nth-child(10)::before { animation: validateShine 6.5s ease-in-out infinite; animation-delay: 4.7s; }

@keyframes validateShine {
    0% {
        transform: translateX(-100%) translateY(-100%) rotate(45deg);
    }
    100% {
        transform: translateX(100%) translateY(100%) rotate(45deg);
    }
}

/* Needs improvement - orange (higher priority, overrides validated) */
.tpt-word-card.needs-improvement {
    background: linear-gradient(145deg, 
        rgba(255, 149, 0, 0.7) 0%,
        rgba(255, 159, 10, 0.65) 35%,
        rgba(251, 146, 60, 0.6) 100%) !important;
    box-shadow: 0 3px 16px rgba(255, 149, 0, 0.28),
                0 0 32px rgba(255, 159, 10, 0.14) !important;
}

/* Error state - orange rougeâtre (highest priority) */
.tpt-word-card.has-error {
    background: linear-gradient(145deg, 
        rgba(254, 124, 88, 0.45) 0%,
        rgba(251, 101, 66, 0.42) 50%,
        rgba(239, 68, 48, 0.4) 100%) !important;
    box-shadow: 0 3px 16px rgba(251, 101, 66, 0.22),
                0 0 32px rgba(254, 124, 88, 0.1) !important;
}

/* ============================================
   Validation Badge
   ============================================ */

.tpt-validation-badge {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #22c55e, #10b981);
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    animation: tptPopIn 0.3s ease;
    z-index: 10;
    box-shadow: 0 4px 16px rgba(34, 197, 94, 0.6),
                0 0 24px rgba(34, 197, 94, 0.3);
}

@keyframes tptPopIn {
    0% { transform: scale(0); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* Show badge if currently validated OR if ever validated (data attribute) */
.tpt-word-card.validated .tpt-validation-badge,
.tpt-word-card[data-ever-validated="true"] .tpt-validation-badge {
    display: flex;
}

/* ============================================
   Word Image/Emoji
   ============================================ */

.tpt-word-image {
    width: 80px;
    height: 80px;
    border-radius: 8px;
    grid-column: 1;
    display: none;
    background: rgba(59, 130, 246, 0.1);
    align-items: center;
    justify-content: center;
    font-size: 48px;
    transition: background 0.3s ease;
}

.tpt-word-card.validated .tpt-word-image {
    background: rgba(34, 197, 94, 0.15);
}

.tpt-word-card.needs-improvement .tpt-word-image {
    background: rgba(255, 149, 0, 0.15);
}

.tpt-word-card.has-error .tpt-word-image {
    background: rgba(254, 124, 88, 0.15);
}

.tpt-word-image.show {
    display: flex;
}

.tpt-word-image img {
    max-width: 80px;
    height: auto;
    border-radius: 8px;
}

/* ============================================
   Word Info
   ============================================ */

.tpt-word-info {
    grid-column: 2;
}

.tpt-word-french {
    font-size: 18px;
    font-weight: 600;
    color: #93C5FD;
    margin-bottom: 6px;
}

.tpt-word-phonetic {
    font-size: 16px;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 6px;
    font-weight: 600;
    font-family: monospace;
}

.tpt-word-thai {
    font-size: 18px;
    color: #FCA5A5;
    font-weight: 500;
}

/* ============================================
   Audio Buttons
   ============================================ */

.tpt-word-actions {
    grid-column: 3;
    display: flex;
    flex-direction: row;
    gap: 12px;
}

/* Listen-only cards: center the single button */
.tpt-word-card.listen-only .tpt-word-actions {
    justify-content: center;
}

.tpt-audio-btn {
    width: 56px;
    height: 56px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* Listen Button */
.tpt-btn-listen {
    background: linear-gradient(135deg, #60A5FA 0%, #3B82F6 100%);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.tpt-btn-listen:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.5);
}

.tpt-btn-listen:active {
    transform: scale(0.95);
}

.tpt-speaker-icon {
    position: relative;
    z-index: 2;
}

/* Speed Badge */
.tpt-speed-badge {
    position: absolute;
    bottom: -6px;
    right: -6px;
    background: #EF4444;
    color: white;
    font-size: 9px;
    font-weight: 700;
    padding: 3px 7px;
    border-radius: 8px;
    display: none;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    z-index: 3;
}

.tpt-speed-badge.show {
    display: block;
    animation: tptPopIn 0.3s ease;
}

/* Record Button */
.tpt-btn-record {
    background: linear-gradient(135deg, #F87171 0%, #DC2626 100%);
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.4);
}

.tpt-btn-record:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(220, 38, 38, 0.5);
}

.tpt-btn-record:active {
    transform: scale(0.95);
}

.tpt-btn-record:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: scale(1);
}

/* État "preparing" - micro se prépare */
.tpt-btn-record.preparing {
    background: linear-gradient(135deg, #FCA5A5 0%, #F87171 100%);
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.2);
    cursor: wait;
    opacity: 0.6;
    pointer-events: none; /* Empêcher double-clic */
    filter: saturate(0.7); /* Légèrement désaturé */
}

.tpt-btn-record.recording {
    --volume: 0.3; /* Sera mis à jour dynamiquement par JS */
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3),
                0 0 0 calc(var(--volume) * 20px) rgba(220, 38, 38, calc(var(--volume) * 0.4));
    transition: box-shadow 0.1s ease-out;
}

/* Icons */
.tpt-mic-icon {
    position: relative;
    z-index: 2;
}

.tpt-stop-icon {
    display: none;
    position: relative;
    z-index: 2;
}

.tpt-btn-record.recording .tpt-mic-icon {
    display: none;
}

.tpt-btn-record.recording .tpt-stop-icon {
    display: block;
}

/* ============================================
   Audio Waves Animation
   ============================================ */

.tpt-audio-waves {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 3px;
    width: 100%;
    height: 100%;
    position: absolute;
}

.tpt-audio-waves.active {
    display: flex;
}

.tpt-btn-listen.playing .tpt-speaker-icon {
    display: none;
}

.tpt-btn-listen.playing .tpt-audio-waves {
    display: flex;
}

.tpt-wave-bar {
    width: 3px;
    background: white;
    border-radius: 2px;
    animation: tptWave 1s ease-in-out infinite;
}

.tpt-wave-bar:nth-child(1) { height: 8px; animation-delay: 0s; }
.tpt-wave-bar:nth-child(2) { height: 16px; animation-delay: 0.1s; }
.tpt-wave-bar:nth-child(3) { height: 12px; animation-delay: 0.2s; }
.tpt-wave-bar:nth-child(4) { height: 18px; animation-delay: 0.3s; }
.tpt-wave-bar:nth-child(5) { height: 10px; animation-delay: 0.4s; }

@keyframes tptWave {
    0%, 100% { transform: scaleY(1); }
    50% { transform: scaleY(1.4); }
}

/* ============================================
   Analyzing State
   ============================================ */

.tpt-analyzing {
    display: none;
    text-align: center;
    padding: 20px;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.15), rgba(59, 130, 246, 0.15));
    border-radius: 8px;
    grid-column: 1 / -1;
    margin-top: 16px;
}

.tpt-analyzing.show {
    display: block;
}

.tpt-word-card.analyzing .tpt-analyzing {
    display: block;
}

.tpt-analyzing-animation {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
    margin-bottom: 10px;
}

.tpt-analyzing-dot {
    width: 8px;
    height: 8px;
    background: #3b82f6;
    border-radius: 50%;
    animation: tptDotPulse 1.5s ease-in-out infinite;
}

.tpt-analyzing-dot:nth-child(1) { animation-delay: 0s; }
.tpt-analyzing-dot:nth-child(2) { animation-delay: 0.2s; }
.tpt-analyzing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes tptDotPulse {
    0%, 60%, 100% {
        transform: scale(1);
        opacity: 0.5;
    }
    30% {
        transform: scale(1.3);
        opacity: 1;
    }
}

.tpt-analyzing-text {
    color: rgba(255, 255, 255, 0.9);
    font-size: 14px;
    font-weight: 500;
}

/* ============================================
   Feedback - IMPORTANT pour override l'état de la carte
   ============================================ */

.tpt-feedback {
    padding: 20px 28px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    text-align: left;
    display: none;
    animation: tptSlideDown 0.3s ease;
    grid-column: 1 / -1;
    margin-top: 16px;
    align-items: center;
    gap: 16px;
}

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

.tpt-feedback.show {
    display: flex;
}

.tpt-word-card.has-feedback .tpt-feedback {
    display: flex;
}

.tpt-feedback-icon {
    font-size: 36px;
    flex-shrink: 0;
    animation: tptScaleIn 0.4s ease;
}

@keyframes tptScaleIn {
    0% { transform: scale(0); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.tpt-feedback-content {
    flex: 1;
}

.tpt-feedback-title {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 4px;
}

.tpt-feedback-text {
    font-size: 13px;
    opacity: 0.9;
}
.tpt-feedback.improvement .tpt-feedback-text {
    font-family: monospace;
    font-weight: 600;
}

/* Feedback success - toujours vert vif, override état carte */
.tpt-feedback.success {
    background: linear-gradient(135deg, rgba(52, 211, 153, 0.25), rgba(34, 197, 94, 0.25)) !important;
    color: #6ee7b7 !important;
}

/* Feedback improvement - toujours orange/jaune vif, override état carte */
.tpt-feedback.improvement {
    background: linear-gradient(135deg, rgba(252, 211, 77, 0.25), rgba(251, 191, 36, 0.25)) !important;
    color: #fcd34d !important;
}

/* Feedback error - orange rougeâtre, override état carte */
.tpt-feedback.error {
    background: linear-gradient(135deg, rgba(251, 101, 66, 0.25), rgba(239, 68, 48, 0.25)) !important;
    color: #fecaca !important;
}

/* ============================================
   Responsive - Cards
   ============================================ */

@media (max-width: 600px) {
    .tpt-word-card {
        grid-template-columns: auto 1fr;
        grid-template-rows: auto auto;
        text-align: center;
        padding: 24px;
        justify-content: center;
        gap: 16px 20px;
    }
    
    .tpt-word-image {
        grid-column: 1;
        grid-row: 1;
        margin: 0;
        align-self: center;
    }
    
    .tpt-word-info {
        grid-column: 2;
        grid-row: 1;
        text-align: left;
        align-self: center;
    }
    
    .tpt-word-actions {
        grid-column: 1 / -1;
        grid-row: 2;
        justify-content: center;
        margin-top: 8px;
    }
}