:root {
    --primary: #4f46e5;
    --primary-light: #818cf8;
    --bg-dark: #0f172a;
    --bg-gradient: radial-gradient(circle at 10% 20%, #1e1b4b 0%, #0f172a 100%);
    --glass-bg: rgba(30, 41, 59, 0.6);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --eco-color: #a6e3a1;
    --role-a: #818cf8;
    --role-b: #f472b6;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg-gradient);
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 20px;
    overflow: auto;
    -webkit-user-select: none;
    user-select: none;
}

/* Formes d'arrière-plan abstraites */
.bg-shape {
    position: fixed;
    filter: blur(80px);
    z-index: -1;
    border-radius: 50%;
    animation: float 10s infinite alternate ease-in-out;
}
.shape-1 {
    width: 300px; height: 300px;
    background: rgba(99, 102, 241, 0.3);
    top: 10%; left: 15%;
}
.shape-2 {
    width: 400px; height: 400px;
    background: rgba(192, 132, 252, 0.2);
    bottom: 10%; right: 10%;
}

@keyframes float {
    0% { transform: translateY(0px) scale(1); }
    100% { transform: translateY(-30px) scale(1.05); }
}

/* ========== ÉCRAN D'ACCUEIL (Sélection du rôle) ========== */
#welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3rem;
    min-height: 80vh;
    animation: fadeIn 0.6s ease-out;
}

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

.welcome-title {
    text-align: center;
}

.welcome-title h1 {
    font-size: 2.8rem;
    font-weight: 800;
    background: linear-gradient(135deg, #f8fafc, #cbd5e1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
}

.welcome-title p {
    color: var(--text-muted);
    font-size: 1.2rem;
    font-weight: 300;
}

.role-buttons {
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
    justify-content: center;
}

.role-btn {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: 2px solid var(--glass-border);
    border-radius: 24px;
    padding: 3rem 4rem;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    text-align: center;
    min-width: 220px;
    box-shadow: 0 15px 40px -10px rgba(0, 0, 0, 0.5);
}

.role-btn:hover {
    transform: translateY(-8px) scale(1.03);
    box-shadow: 0 25px 50px -15px rgba(0, 0, 0, 0.6);
}

.role-btn.role-a:hover {
    border-color: var(--role-a);
    box-shadow: 0 25px 50px -15px rgba(129, 140, 248, 0.4);
}

.role-btn.role-b:hover {
    border-color: var(--role-b);
    box-shadow: 0 25px 50px -15px rgba(244, 114, 182, 0.4);
}

.role-btn .role-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    display: block;
}

.role-btn .role-label {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
    display: block;
}

.role-btn .role-sub {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    display: block;
}

/* ========== ÉCRAN DE TRADUCTION ========== */
#translation-screen {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    width: 100%;
    max-width: 800px;
    animation: slideUp 0.6s ease-out;
}

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

/* Header barre */
.tete-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.8rem 10px;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.4);
}

.tete-header .header-left {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.tete-header .role-badge {
    padding: 6px 14px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 0.9rem;
}

.tete-header .role-badge.badge-a {
    background: rgba(129, 140, 248, 0.2);
    color: var(--role-a);
    border: 1px solid rgba(129, 140, 248, 0.3);
}

.tete-header .role-badge.badge-b {
    background: rgba(244, 114, 182, 0.2);
    color: var(--role-b);
    border: 1px solid rgba(244, 114, 182, 0.3);
}

.peer-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
    color: var(--text-muted);
    padding: 6px 14px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-weight: 700;
}

.peer-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ef4444;
    transition: background 0.3s ease;
}

.peer-dot.online {
    background: var(--eco-color);
    box-shadow: 0 0 8px rgba(166, 227, 161, 0.6);
    animation: pulse-green 2s infinite;
}

@keyframes pulse-green {
    0%, 100% { box-shadow: 0 0 4px rgba(166, 227, 161, 0.4); }
    50% { box-shadow: 0 0 12px rgba(166, 227, 161, 0.8); }
}

/* Sélecteur de langue (drapeaux cible) */
.lang-bar {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
    justify-content: center;
    padding: 0.8rem 1rem;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    width: 100%;
}

.lang-bar label {
    cursor: pointer;
    font-size: 2.2rem;
    opacity: 0.4;
    transition: all 0.3s ease;
    filter: grayscale(0.5);
}

.lang-bar label:hover {
    opacity: 0.8;
    transform: scale(1.1);
}

.lang-bar label.active {
    opacity: 1;
    filter: drop-shadow(0 0 12px rgba(79, 70, 229, 0.9)) grayscale(0);
    transform: scale(1.15);
}

.lang-bar input[type="radio"] { display: none; }

/* ========== Zone de chat ========== */
.chat-container {
    width: 100%;
    background: rgba(15, 23, 42, 0.6);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 300px;
    max-height: 55vh;
    overflow: hidden;
    box-shadow: inset 0 2px 15px rgba(0, 0, 0, 0.2);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

/* Bulles de chat */
.chat-bubble {
    max-width: 85%;
    padding: 0.8rem 1.2rem;
    border-radius: 18px;
    font-size: 1.05rem;
    line-height: 1.5;
    animation: bubbleIn 0.3s ease-out;
    word-wrap: break-word;
}

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

.chat-bubble.from-peer {
    align-self: flex-start;
    background: rgba(129, 140, 248, 0.15);
    border: 1px solid rgba(129, 140, 248, 0.2);
    border-bottom-left-radius: 4px;
}

.chat-bubble.from-me {
    align-self: flex-end;
    background: rgba(244, 114, 182, 0.15);
    border: 1px solid rgba(244, 114, 182, 0.2);
    border-bottom-right-radius: 4px;
}

.chat-bubble .bubble-original {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    font-style: italic;
}

.chat-bubble .bubble-translation {
    color: var(--text-main);
    font-weight: 500;
}

.chat-bubble .bubble-meta {
    font-size: 0.75rem;
    color: rgba(148, 163, 184, 0.6);
    margin-top: 4px;
    text-align: right;
}

/* Indicateur de traduction en cours */
.typing-indicator {
    display: none;
    align-self: flex-start;
    padding: 0.6rem 1.2rem;
    background: rgba(129, 140, 248, 0.1);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 0 1rem;
}

.typing-indicator.visible { display: flex; align-items: center; }

.typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* ========== Label "Parlez..." ========== */
.speak-label {
    display: none;
    text-align: center;
    padding: 0.5rem 1rem;
    color: #a6e3a1;
    font-size: 1.1rem;
    font-weight: 600;
    animation: fadeInPulse 0.3s ease-out;
}

.speak-label.visible {
    display: block;
}

@keyframes fadeInPulse {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

/* ========== Barre du bas : Micro PTT + Statut ========== */
.chat-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(0, 0, 0, 0.2);
}

.controls-text {
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 2px;
}

.ptt-hint {
    font-size: 0.75rem;
    color: rgba(148, 163, 184, 0.5);
    font-weight: 400;
}

/* ========== BOUTON MICRO GÉANT (PTT) ========== */
.mic-btn {
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.3), rgba(30, 41, 59, 0.8));
    color: var(--primary-light);
    border: 3px solid rgba(129, 140, 248, 0.3);
    border-radius: 50%;
    width: 80px;
    height: 80px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 20px rgba(79, 70, 229, 0.2);
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
}

.mic-btn:hover {
    transform: scale(1.08);
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.5), rgba(30, 41, 59, 0.9));
    box-shadow: 0 8px 30px rgba(79, 70, 229, 0.4);
    border-color: rgba(129, 140, 248, 0.5);
}

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

/* État RECORDING : gros bouton rouge pulsant */
.mic-btn.recording {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    border-color: #ef4444;
    transform: scale(1.1);
    animation: pulse-record 1.2s infinite ease-in-out;
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5),
                0 8px 30px rgba(239, 68, 68, 0.3);
}

@keyframes pulse-record {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6),
                    0 8px 30px rgba(239, 68, 68, 0.3);
        transform: scale(1.1);
    }
    50% {
        box-shadow: 0 0 0 18px rgba(239, 68, 68, 0),
                    0 8px 30px rgba(239, 68, 68, 0.5);
        transform: scale(1.15);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0),
                    0 8px 30px rgba(239, 68, 68, 0.3);
        transform: scale(1.1);
    }
}

.status-text {
    color: var(--text-muted);
    font-size: 1rem;
    font-weight: 600;
}

/* Lien retour */
.back-link {
    position: fixed;
    top: 20px;
    left: 20px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--text-main);
    padding: 8px 16px;
    border-radius: 12px;
    text-decoration: none;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    z-index: 100;
    font-family: 'Outfit', sans-serif;
    font-size: 0.9rem;
}

.back-link:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ========== RESPONSIVE MOBILE-FIRST ========== */
@media (max-width: 768px) {
    body {
        padding: 5px;
        padding-bottom: 0;
        justify-content: flex-start;
    }

    .welcome-title h1 { font-size: 2rem; }

    .role-buttons { gap: 1rem; }

    .role-btn {
        padding: 2rem 2.5rem;
        min-width: 160px;
    }

    .role-btn .role-icon { font-size: 3rem; }
    .role-btn .role-label { font-size: 1.2rem; }

    #translation-screen {
        gap: 0.3rem;
        height: 100vh;
        height: 100dvh;
    }

    .tete-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        padding: 0.6rem 10px;
    }

    .lang-bar {
        padding: 0.3rem 0.2rem;
        gap: min(0.2rem, 1vw);
        flex-wrap: nowrap;
        justify-content: space-between;
    }
    .lang-bar label { font-size: min(1.6rem, 7.5vw); }

    .chat-container {
        max-height: none;
        flex: 1;
        min-height: 250px;
        border-radius: 12px;
    }

    .chat-bubble { max-width: 95%; padding: 0.6rem 1rem; font-size: 1rem; }

    /* Bouton micro plus petit sur mobile pour dégager la vue */
    .mic-btn {
        width: 64px;
        height: 64px;
    }

    .mic-btn .material-symbols-outlined {
        font-size: 2.2rem !important;
    }

    .chat-controls {
        padding: 0.5rem 0.8rem;
        gap: 0.5rem;
    }

    .controls-text .status-text { font-size: 0.85rem; }
    .controls-text .ptt-hint { font-size: 0.7rem; }

    .back-link { display: none; }
}
