/* ==========================================================================
   Voix — direction : cabine de radio la nuit.
   Fond pétrole encre, texte parchemin, une seule couleur vive à la fois :
   celle de la persona active. Tout l'affichage tourne autour du halo.
   ========================================================================== */

:root {
    --encre:      #0E1A1F;
    --encre-haut: #142329;
    --surface:    #1A2B31;
    --parchemin:  #EFE6D6;
    --brume:      #86A0A6;
    --accent:     #E9A13B;

    --pad: 20px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);

    --display: 'Bricolage Grotesque', 'Trebuchet MS', sans-serif;
    --body: 'Instrument Sans', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

/* Une règle de classe l'emporte sur l'attribut hidden : sans ce !important,
   .gate, .sheet et .composer restent affichés malgré element.hidden = true. */
[hidden] { display: none !important; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--encre);
    color: var(--parchemin);
    font-family: var(--body);
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
}

body {
    /* Lueur d'ambiance : le fond respire avec la persona. */
    background-image: radial-gradient(120% 60% at 50% 12%,
        color-mix(in oklab, var(--accent) 14%, transparent), transparent 70%);
}

button, input { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; touch-action: manipulation; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }

.eyebrow {
    font-size: 0.7rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--brume);
    margin: 0;
}

/* ---------- Écran d'entrée ---------- */
.gate {
    position: fixed;
    inset: 0;
    padding: calc(var(--safe-top) + 48px) var(--pad) calc(var(--safe-bottom) + 24px);
    display: flex;
    flex-direction: column;
    gap: 18px;
    overflow-y: auto;
    background: var(--encre);
    z-index: 30;
}

.gate-title {
    font-family: var(--display);
    font-weight: 700;
    font-size: clamp(2rem, 9vw, 2.8rem);
    line-height: 1.05;
    letter-spacing: -0.02em;
    margin: 0 0 8px;
}

.gate-list { display: flex; flex-direction: column; gap: 12px; }

.gate-card {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 18px 16px;
    text-align: left;
    background: var(--encre-haut);
    border: 1px solid rgba(239, 230, 214, 0.08);
    border-radius: 18px;
    transition: transform 0.18s ease, border-color 0.18s ease;
}

.gate-card:active { transform: scale(0.985); }
.gate-card[aria-current="true"] { border-color: var(--card-accent); }

.gate-card .avatar {
    flex: 0 0 auto;
    width: 42px; height: 42px;
    border-radius: 50%;
    background: var(--card-accent);
    color: var(--encre);
    display: grid;
    place-items: center;
    font-family: var(--display);
    font-weight: 700;
    font-size: 1.1rem;
}

.gate-card .card-body { min-width: 0; }

.gate-card .name {
    display: block;
    font-family: var(--display);
    font-weight: 500;
    font-size: 1.15rem;
}

.gate-card .tagline { display: block; font-size: 0.85rem; color: var(--brume); margin-top: 2px; }
.gate-card .voice { margin-left: auto; font-size: 0.72rem; color: var(--brume); letter-spacing: 0.06em; }

.gate-foot { margin-top: auto; font-size: 0.8rem; color: var(--brume); }
.gate-list-compact .gate-card { padding: 14px; }

/* ---------- Écran principal ---------- */
.app {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    padding: calc(var(--safe-top) + 10px) var(--pad) calc(var(--safe-bottom) + 12px);
}

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

.chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    font-size: 0.82rem;
    color: var(--parchemin);
    background: rgba(239, 230, 214, 0.06);
    border-radius: 999px;
}

.chip-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }

.chip-agent {
    font-size: 0.75rem;
    color: var(--brume);
    max-width: 42vw;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.chip-icon { margin-left: auto; padding: 9px 12px; color: var(--brume); }

.stage {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 26px;
    min-height: 0;
}

.state { transition: color 0.3s ease; }

/* ---------- Le halo : bouton unique, quatre états ---------- */
.halo {
    position: relative;
    width: min(62vw, 260px);
    aspect-ratio: 1;
    display: grid;
    place-items: center;
}

.ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 1px solid color-mix(in oklab, var(--accent) 55%, transparent);
    /* --level est écrit par le JS à chaque frame (0 → 1). */
    transform: scale(calc(0.62 + var(--level, 0) * 0.30));
    transition: opacity 0.4s ease;
    will-change: transform;
}

.ring-1 { opacity: 0.9; }
.ring-2 { opacity: 0.45; transform: scale(calc(0.72 + var(--level, 0) * 0.42)); }
.ring-3 { opacity: 0.18; transform: scale(calc(0.84 + var(--level, 0) * 0.56)); }

.core {
    position: relative;
    width: 42%;
    aspect-ratio: 1;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--accent);
    color: var(--encre);
    box-shadow: 0 0 40px color-mix(in oklab, var(--accent) 45%, transparent);
    transform: scale(calc(1 + var(--level, 0) * 0.08));
}

.core svg { width: 44%; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.icon-stop { display: none; fill: currentColor; stroke: none; }

.halo[data-state="idle"] .core { animation: souffle 4.5s ease-in-out infinite; }
.halo[data-state="thinking"] .ring-1 { border-style: dashed; animation: tourne 2.4s linear infinite; }
.halo[data-state="thinking"] .core { opacity: 0.7; }
.halo[data-state="speaking"] .icon-mic { display: none; }
.halo[data-state="speaking"] .icon-stop { display: block; }
.halo[data-state="listening"] .ring { border-width: 2px; }

@keyframes souffle {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.045); }
}

@keyframes tourne { to { transform: rotate(360deg) scale(0.75); } }

/* ---------- Onde d'écoute ----------
   Signal principal du « c'est à toi de parler » : visible uniquement pendant
   l'écoute, animée par le niveau réel du micro. Un halo qui pulse tout seul ne
   dit pas si la voix est captée ; ces barres, si. */
.wave {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    height: 30px;
    opacity: 0;
    transition: opacity 0.25s ease;
    pointer-events: none;
}

.wave.on { opacity: 1; }

.wave span {
    width: 3px;
    height: 100%;
    border-radius: 2px;
    background: var(--accent);
    transform: scaleY(var(--h, 0.06));
    transform-origin: center;
}

@media (prefers-reduced-motion: reduce) {
    .wave span { transform: scaleY(0.4); }
}

/* ---------- Dernière réplique ---------- */
.live {
    margin: 0;
    max-width: 34ch;
    min-height: 4.5em;
    text-align: center;
    font-family: var(--display);
    font-weight: 500;
    font-size: clamp(1.05rem, 4.6vw, 1.35rem);
    line-height: 1.45;
    letter-spacing: -0.01em;
    text-wrap: balance;
}

.live.user { color: var(--brume); font-family: var(--body); font-size: 1rem; }

/* Chrono : sert à comparer les agents entre eux. */
.stats {
    margin: 0;
    min-height: 1.1em;
    font-size: 0.72rem;
    letter-spacing: 0.04em;
    color: var(--brume);
    opacity: 0.75;
    text-align: center;
}

/* ---------- Liste des agents ---------- */
.sheet-note { margin: 0; font-size: 0.8rem; line-height: 1.45; color: var(--brume); }

.agent-list { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }

.agent-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 16px;
    text-align: left;
    background: var(--surface);
    border: 1px solid transparent;
    border-radius: 14px;
}

.agent-row:disabled { opacity: 0.4; }
.agent-row[aria-current="true"] { border-color: var(--accent); }
.agent-main { flex: 1; min-width: 0; }
.agent-label { display: block; font-family: var(--display); font-weight: 500; font-size: 1rem; }

.agent-meta {
    display: block;
    margin-top: 2px;
    font-size: 0.75rem;
    color: var(--brume);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.agent-tick { color: var(--accent); opacity: 0; }
.agent-row[aria-current="true"] .agent-tick { opacity: 1; }

/* ---------- Barre du bas ---------- */
.dock { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }

.dock-btn {
    padding: 9px 11px;
    font-size: 0.75rem;
    white-space: nowrap;
    color: var(--brume);
    border-radius: 999px;
}

.dock-btn:disabled { opacity: 0.35; }
.dock-btn:active { background: rgba(239, 230, 214, 0.07); }

.dock-btn.on {
    color: var(--encre);
    background: var(--accent);
    font-weight: 600;
}

/* ---------- Saisie clavier ---------- */
.composer { display: flex; gap: 8px; padding-top: 12px; }

.composer input {
    flex: 1;
    padding: 14px 16px;
    font-size: 16px;              /* < 16px = zoom automatique sur iOS */
    background: var(--surface);
    border: 1px solid rgba(239, 230, 214, 0.1);
    border-radius: 14px;
}

.composer input::placeholder { color: var(--brume); }

.composer-send {
    width: 50px;
    border-radius: 14px;
    background: var(--accent);
    color: var(--encre);
    font-size: 1.2rem;
}

/* ---------- Feuilles ---------- */
.sheet {
    position: fixed;
    inset: auto 0 0 0;
    max-height: 82dvh;
    padding: 16px var(--pad) calc(var(--safe-bottom) + 20px);
    background: var(--encre-haut);
    border-top: 1px solid rgba(239, 230, 214, 0.1);
    border-radius: 22px 22px 0 0;
    box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    gap: 14px;
    z-index: 20;
    animation: monte 0.25s cubic-bezier(0.2, 0.9, 0.3, 1);
}

@keyframes monte { from { transform: translateY(100%); } }

.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.thread { overflow-y: auto; display: flex; flex-direction: column; gap: 14px; padding-bottom: 8px; }

.turn { max-width: 90%; font-size: 0.95rem; line-height: 1.5; }
.turn.assistant { color: var(--parchemin); }
.turn.user { align-self: flex-end; color: var(--brume); text-align: right; }
.turn .who { display: block; font-size: 0.66rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--brume); margin-bottom: 3px; }

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(var(--safe-bottom) + 26px);
    transform: translateX(-50%);
    max-width: 88vw;
    margin: 0;
    padding: 11px 16px;
    font-size: 0.85rem;
    background: var(--surface);
    border: 1px solid rgba(239, 230, 214, 0.12);
    border-radius: 999px;
    z-index: 40;
}

/* ---------- Écrans larges ---------- */
@media (min-width: 720px) {
    .app, .gate { max-width: 560px; margin: 0 auto; }
    .sheet { max-width: 560px; left: 50%; right: auto; width: 100%; transform: translateX(-50%); }
    @keyframes monte { from { transform: translate(-50%, 100%); } }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
