/* =============================================
 * IAW Speaking Modülü - Modern UI Revizyonu v2.0
 * ============================================= */

/* --- 1. Ana Konteyner (Sahne) --- */
#iaw-speaking-app {
    max-width: 800px;
    margin: 40px auto;
    background: #ffffff;
    border-radius: 24px;
    /* Daha modern, geniş yuvarlak köşeler */
    box-shadow: 0 12px 40px -12px rgba(0, 0, 0, 0.1);
    /* Derinlik hissi veren yumuşak gölge */
    padding: 40px;
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    position: relative;
    overflow: hidden;
    /* Taşmaları gizle */
}

@media (min-width: 993px) {
    #iaw-speaking-app {
        margin-left: max(350px, calc(50% - 285px)) !important;
        margin-right: auto !important;
    }
}

@media (max-width: 992px) {
    #iaw-speaking-app {
        margin-left: auto !important;
        margin-right: auto !important;
    }
}

/* Sonuç Ekranı - Ana Container'dan bağımsız */
#iaw-speaking-results-screen {
    width: 100%;
    max-width: 1200px;
    margin: 40px auto;
    padding: 0;
    /* İsteğe bağlı: Sonuç ekranı da kutu içinde olsun isterseniz: */
    /*
    background: #ffffff;
    border-radius: 24px;
    box-shadow: 0 12px 40px -12px rgba(0, 0, 0, 0.1);
    padding: 40px; 
    */
}

@media (min-width: 993px) {
    #iaw-speaking-results-screen {
        margin-left: max(350px, calc(50% - 485px)) !important;
        margin-right: auto !important;
    }
}

@media (max-width: 992px) {
    #iaw-speaking-results-screen {
        margin-left: auto !important;
        margin-right: auto !important;
    }
}

/* JS ile kesin gizleme */
.iaw-force-hidden {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    overflow: hidden !important;
}

/* Mobil uyumluluk için kenar boşluklarını daralt */
@media (max-width: 768px) {
    #iaw-speaking-app {
        padding: 25px;
        margin: 20px auto;
        border-radius: 16px;
    }
}

/* --- 2. Başlıklar ve Metinler --- */
#iaw-speaking-app h3 {
    font-size: 1.8rem;
    font-weight: 700;
    color: #1a202c;
    text-align: center;
    margin-bottom: 25px;
    letter-spacing: -0.02em;
}

#iaw-speaking-app p.iaw-description {
    font-size: 1.1rem;
    color: #4a5568;
    text-align: center;
    line-height: 1.6;
    max-width: 600px;
    margin: 0 auto 35px auto;
}

/* --- 3. Examiner Prompt (Soru Alanı) - HERO SECTION --- */
.iaw-examiner-prompt-box {
    background: transparent;
    /* Arka planı kaldırdık */
    border: none;
    /* Kenarlığı kaldırdık */
    padding: 20px 0;
    margin-bottom: 40px;
    text-align: center;
}

#iaw-examiner-avatar {
    width: 70px;
    height: 70px;
    margin: 0 auto 15px auto;
    background: #ebf8ff;
    /* Çok açık mavi */
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

#iaw-examiner-prompt {
    font-size: 1.5rem;
    /* Yazıyı büyüttük */
    font-weight: 600;
    color: #2d3748;
    line-height: 1.4;
}

/* --- 4. Kontrol Alanı (Butonlar ve Durum) --- */
.iaw-speaking-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-top: 30px;
}

/* Durum Metni */
#iaw-recording-status {
    margin-bottom: 25px;
    font-size: 1.1rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 15px;
}

.status-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: #cbd5e0;
    /* Varsayılan gri */
    transition: all 0.3s ease;
}

/* Duruma göre renkler */
.status-listening .status-indicator {
    background-color: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
}

/* Kayıt: Kırmızı */
.status-speaking .status-indicator {
    background-color: #3b82f6;
}

/* Okuyor: Mavi */

/* KAYIT BUTONU - Modernleştirilmiş */
.iaw-record-button {
    width: 80px;
    /* Daha büyük, dairesel buton */
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    /* Modern mavi gradyan */
    border: none;
    color: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 10px 20px -10px rgba(37, 99, 235, 0.5);
    /* Buton gölgesi */
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
}

.iaw-record-button:hover:not(:disabled) {
    transform: translateY(-3px) scale(1.02);
    /* Hafif yukarı kalkma efekti */
    box-shadow: 0 15px 30px -10px rgba(37, 99, 235, 0.6);
}

.iaw-record-button:active:not(:disabled) {
    transform: translateY(1px) scale(0.98);
}

.iaw-record-button:disabled {
    background: #e2e8f0;
    color: #a0aec0;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.iaw-record-button svg {
    width: 32px;
    height: 32px;
    margin-bottom: 4px;
    fill: currentColor;
}

.iaw-record-button span {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* --- Record Button (Green Design) --- */
#iaw-record-wrapper {
    position: relative;
    width: 80px;
    /* Reduced from 200 */
    height: 80px;
    /* Reduced from 200 */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
}

#iaw-record-btn {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: none;
    /* Dark Grey Background - Ready state */
    background: #374151;
    color: white;
    /* White Icon */
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
    box-shadow: 0 4px 6px -1px rgba(55, 65, 81, 0.1), 0 2px 4px -1px rgba(55, 65, 81, 0.06);
    padding: 0;
}

#iaw-record-btn:hover {
    transform: scale(1.05);
    background: #1f2937;
    box-shadow: 0 10px 15px -3px rgba(55, 65, 81, 0.2);
}

#iaw-record-btn svg {
    width: 32px;
    height: 32px;
    stroke: currentColor;
    stroke-width: 2.5;
}

#iaw-record-btn:disabled {
    background: #9ca3af;
    /* Disabled Grey */
    opacity: 0.5;
    cursor: not-allowed;
    filter: none;
    box-shadow: none;
}

/* Recording State - Transparent bg to see canvas */
#iaw-record-btn.recording {
    background: transparent;
    /* Let canvas show through */
    color: #ef4444;
    /* Red Icon */
    box-shadow: none;
    /* remove pulse, let canvas do the work */
    animation: none;
}

@keyframes iaw-pulse-recording {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
    }

    70% {
        box-shadow: 0 0 0 15px rgba(239, 68, 68, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

/* Canvas Positioning */
#iaw-mic-visualizer {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 1;
}

#iaw-record-text {
    margin-top: 20px;
    font-size: 1rem;
    font-weight: 600;
    color: #64748b;
    text-align: center;
    position: absolute;
    bottom: 20px;
    width: 100%;
}

/* =============================================
 * PREMIUM AI BUBBLE - LOGIC FIXED (v2)
 * ============================================= */

:root {
    /* --- MAVİ PALET (VARSAYILAN, KONUŞMA & BEKLEME) --- */
    --iaw-blue-primary: #3b82f6;
    --iaw-blue-secondary: #8b5cf6;
    --iaw-blue-accent: #06b6d4;

    /* --- KIRMIZI PALET (SADECE VE SADECE DİNLERKEN) --- */
    --iaw-red-primary: #ef4444;
    --iaw-red-secondary: #dc2626;
    --iaw-red-accent: #f87171;
}

#iaw-audio-wave {
    /* 1. VARSAYILAN AYARLAR (MAVİ) */
    --current-primary: var(--iaw-blue-primary);
    --current-secondary: var(--iaw-blue-secondary);
    --current-accent: var(--iaw-blue-accent);

    /* Varsayılan Mavi Gölge */
    --current-shadow: rgba(59, 130, 246, 0.25);

    background: transparent;
    border: none !important;
    padding: 0 !important;
    margin-left: 25px;
    gap: 0 !important;

    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 50%;

    position: relative;
    z-index: 10;
    cursor: pointer;

    /* GÖRÜNÜM */
    background: radial-gradient(circle at 35% 35%, rgba(255, 255, 255, 0.25), transparent 25%),
        linear-gradient(135deg, var(--current-primary), var(--current-secondary), var(--current-accent));
    background-size: 200% 200%;

    /* GÖLGE: Artık değişken kullanıyor, böylece kırmızıya tam dönebilir */
    box-shadow:
        inset -4px -4px 10px rgba(0, 0, 0, 0.15),
        inset 4px 4px 10px rgba(255, 255, 255, 0.4),
        0 8px 20px var(--current-shadow);

    /* GEÇİŞLER */
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform, box-shadow, background;
}

/* Eski spanları gizle */
#iaw-audio-wave span {
    display: none !important;
}

/* =============================================
* KRİTİK DÜZELTME: GÜVENLİK KİLİDİ
* ============================================= */

/* Eğer element ACTIVE değilse (yani bekleme/boşta modundaysa),
parent elementte 'status-listening' kalsa bile rengi MAVİ'ye zorla.
Bu, bekleme modundaki kırmızılığı çözer.
*/
#iaw-audio-wave:not(.active) {
    --current-primary: var(--iaw-blue-primary) !important;
    --current-secondary: var(--iaw-blue-secondary) !important;
    --current-accent: var(--iaw-blue-accent) !important;
    --current-shadow: rgba(59, 130, 246, 0.25) !important;
}

/* =============================================
* RENK DEĞİŞİM MANTIĞI (DİNLEME MODU)
* ============================================= */

/* SADECE "status-listening" varsa KIRMIZI olsun. */
#iaw-recording-status.status-listening #iaw-audio-wave {
    --current-primary: var(--iaw-red-primary);
    --current-secondary: var(--iaw-red-secondary);
    --current-accent: var(--iaw-red-accent);
    --current-shadow: rgba(239, 68, 68, 0.6);
    /* Kırmızı Gölge */
}

/* EKSTRA ÖNLEM: Eğer sistem 'processing' (düşünme) moduna geçerse 
ve yanlışlıkla 'listening' class'ı silinmezse, Maviye geri dön. */
#iaw-recording-status.status-processing #iaw-audio-wave,
#iaw-recording-status.status-thinking #iaw-audio-wave {
    --current-primary: var(--iaw-blue-primary) !important;
    --current-secondary: var(--iaw-blue-secondary) !important;
    --current-accent: var(--iaw-blue-accent) !important;
    --current-shadow: rgba(59, 130, 246, 0.25) !important;
}

/* =============================================
* ANIMASYONLAR (BEKLEME - IDLE)
* ============================================= */
@keyframes iaw-gradient-flow {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

@keyframes iaw-idle-float {

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

    50% {
        transform: translateY(-3px) scale(1.02);
    }
}

#iaw-audio-wave:not(.active) {
    /* Animation disabled for static idle state */
    /* animation: iaw-gradient-flow 6s ease infinite, iaw-idle-float 4s ease-in-out infinite; */

    /* Ensure visibility in static state */
    opacity: 1;
    transform: scale(1);
    background-position: 50% 50%;
    box-shadow:
        inset -4px -4px 10px rgba(0, 0, 0, 0.15),
        inset 4px 4px 10px rgba(255, 255, 255, 0.4),
        0 8px 20px var(--current-shadow);
}

#iaw-audio-wave:hover {
    transform: translateY(-2px) scale(1.05);
}

/* =============================================
* AKTİF DURUM (KONUŞMA & DİNLEME)
* ============================================= */

/* Dalga Halkaları */
#iaw-audio-wave::before,
#iaw-audio-wave::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    border-radius: 50%;
    z-index: -1;
    background: transparent;
    border: 1px solid var(--current-primary);
    opacity: 0;
    pointer-events: none;
    transition: all 0.5s ease;
}

@keyframes iaw-pulse-shadow {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 var(--current-primary);
    }

    70% {
        transform: scale(1.05);
        box-shadow: 0 0 0 15px transparent;
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 transparent;
    }
}

@keyframes iaw-ripple-expand {
    0% {
        transform: translate(-50%, -50%) scale(0.8);
        opacity: 0.8;
        border-width: 2px;
    }

    100% {
        transform: translate(-50%, -50%) scale(2.2);
        opacity: 0;
        border-width: 0px;
    }
}

#iaw-audio-wave.active {
    animation: iaw-pulse-shadow 1.5s infinite;
    filter: brightness(1.1);
}

#iaw-audio-wave.active::before {
    animation: iaw-ripple-expand 2s linear infinite;
}

#iaw-audio-wave.active::after {
    animation: iaw-ripple-expand 2s linear infinite 0.8s;
}

#iaw-audio-wave .iaw-orb,
#iaw-audio-wave i {
    color: white;
    transition: all 0.3s ease;
}