  :root {
    --bg: #f4f2eb;
    --bg-glow: rgba(61, 107, 84, 0.07);
    --surface: #fffefb;
    --border: #e2ded3;
    --text: #211f1b;
    --muted: #857f74;
    --accent: #35664c;
    --accent-2: #4d8a68;
    --accent-soft: #e3ede6;
    --user-bubble: linear-gradient(135deg, #3f7458 0%, #2c5540 100%);
    --user-text: #f2f7f3;
    --error: #b3423f;
    --error-bg: #fbeeed;
    --code-bg: #efece3;
    --shadow: 0 1px 2px rgba(35, 30, 18, 0.05), 0 10px 30px rgba(35, 30, 18, 0.07);
    --shadow-pop: 0 2px 6px rgba(35, 30, 18, 0.08), 0 16px 48px rgba(35, 30, 18, 0.14);
  }
  @media (prefers-color-scheme: dark) {
    :root {
      --bg: #101216;
      --bg-glow: rgba(127, 181, 154, 0.05);
      --surface: #1a1d23;
      --border: #2b2f37;
      --text: #e8e9eb;
      --muted: #8b8f97;
      --accent: #82ba9d;
      --accent-2: #5d9578;
      --accent-soft: #202b25;
      --user-bubble: linear-gradient(135deg, #30604a 0%, #234534 100%);
      --user-text: #e9f1ec;
      --error: #e08886;
      --error-bg: #2e2022;
      --code-bg: #252932;
      --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 10px 30px rgba(0, 0, 0, 0.3);
      --shadow-pop: 0 2px 6px rgba(0, 0, 0, 0.4), 0 16px 48px rgba(0, 0, 0, 0.5);
    }
  }

  * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
  }
  ::-webkit-scrollbar { width: 8px; height: 8px; }
  ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  html { height: 100%; }
  /* dvh : suit la barre d'URL mobile ; le vh précédent sert de repli. */
  body { height: 100vh; height: 100dvh; }
  body {
    /* Halo vert très diffus en tête de page : de la profondeur sans bruit. */
    background:
      radial-gradient(90rem 40rem at 50% -18rem, var(--bg-glow), transparent 60%),
      var(--bg);
    color: var(--text);
    font: 15.5px/1.65 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
  }

  header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 680px;
    width: 100%;
    margin: 0 auto;
    padding: 1rem 1.25rem 0.5rem;
  }
  .wordmark {
    font-size: 1.05rem;
    font-weight: 650;
    letter-spacing: 0.01em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }
  .wordmark::before {
    content: "";
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-2), var(--accent));
    box-shadow: 0 0 0 3px var(--accent-soft);
  }
  .wordmark #version {
    font-size: 0.72rem;
    font-weight: 400;
    color: var(--muted);
  }
  .header-button {
    background: none;
    border: none;
    color: var(--muted);
    font: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    padding: 0.3rem 0.55rem;
    border-radius: 999px;
    transition: color 0.15s, background 0.15s;
  }
  /* Sur écran étroit, les libellés du header cèdent la place aux icônes. */
  @media (max-width: 480px) {
    .header-button .hb-label { display: none; }
    .header-button { font-size: 1rem; }
  }
  @media (hover: hover) {
    .header-button:hover { color: var(--text); background: var(--accent-soft); }
  }

  /* --- Canvas: the central surface showing the current exchange. --- */
  #canvas {
    flex: 1;
    overflow-y: auto;
    scroll-behavior: smooth;
  }
  #canvas-inner {
    max-width: 680px;
    margin: 0 auto;
    padding: 1.25rem 1.25rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.4rem;
  }
  #exchange { display: contents; }
  body:not(.has-messages) #exchange { display: none; }

  #canvas-rich { width: 100%; }
  .canvas-frame {
    width: 100%;
    height: 58vh;
    height: 58dvh;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: var(--shadow);
  }

  /* Mini-lecteur persistant : la musique vit hors du canvas (reconstruit à
     chaque échange) et survit donc à l'envoi de nouveaux messages. */
  #audio-dock { padding: 0 1.25rem 0.5rem; }
  #audio-dock .dock-inner {
    max-width: 680px;
    margin: 0 auto;
    position: relative;
  }
  #audio-dock .audio-player { padding: 0.7rem 1rem; gap: 0.5rem; }
  #audio-dock .tracks { max-height: 8.5rem; overflow-y: auto; }
  #audio-dock .dock-close {
    position: absolute;
    top: 0.45rem;
    right: 0.55rem;
  }

  /* Audio player canvas view */
  .audio-player {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1rem;
    box-shadow: var(--shadow);
  }
  .audio-player .now-playing {
    display: flex;
    align-items: center;
    gap: 0.9rem;
  }
  .audio-player .art {
    flex-shrink: 0;
    width: 84px;
    height: 84px;
    border-radius: 12px;
    background: var(--accent-soft);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
  }
  .audio-player .art img { width: 100%; height: 100%; object-fit: cover; }
  .audio-player.loading .art { animation: pulse 1.3s ease-in-out infinite; }
  .audio-player .meta .title { font-weight: 650; font-size: 1.05rem; }
  .audio-player .meta .artist { color: var(--muted); font-size: 0.9rem; }
  .audio-player audio { width: 100%; }
  .audio-player .tracks {
    display: flex;
    flex-direction: column;
    border-top: 1px solid var(--border);
    padding-top: 0.5rem;
    max-height: 30vh;
    max-height: 30dvh;
    overflow-y: auto;
  }
  .audio-player .tracks button {
    text-align: left;
    background: none;
    border: none;
    color: var(--text);
    font: inherit;
    font-size: 0.88rem;
    padding: 0.35rem 0.5rem;
    border-radius: 8px;
    cursor: pointer;
  }
  @media (hover: hover) {
    .audio-player .tracks button:hover { background: var(--accent-soft); }
  }
  .audio-player .tracks button.active { color: var(--accent); font-weight: 650; }

  /* Lecteur Deezer (vue deezer_player) : le widget officiel dans une iframe,
     même carte et même dock que le lecteur Ampache. */
  .deezer-frame {
    width: 100%;
    height: 160px;
    border: 0;
    border-radius: 12px;
    display: block;
  }

  /* --- Volet d'activité : chaîne d'appels, raisonnement, chrono. --- */
  .activity {
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    font-size: 0.82rem;
    box-shadow: var(--shadow);
    animation: rise 0.25s ease both;
  }
  .activity summary {
    cursor: pointer;
    padding: 0.45rem 0.85rem;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    list-style: none;
    user-select: none;
  }
  .activity summary::-webkit-details-marker { display: none; }
  .activity summary::before {
    content: "▸";
    font-size: 0.7rem;
    transition: transform 0.15s;
  }
  .activity[open] summary::before { transform: rotate(90deg); }
  .activity.running .activity-title { animation: pulse 1.3s ease-in-out infinite; }
  .activity-tokens {
    margin-left: auto;
    font-variant-numeric: tabular-nums;
    color: var(--muted);
    font-size: 0.78rem;
  }
  .activity-tokens.warn { color: var(--accent); }
  .activity-time {
    font-variant-numeric: tabular-nums;
    color: var(--muted);
  }
  /* Pilules d'action (copier, écouter, renvoyer, pouces…) : une seule
     définition partagée — les blocs spécifiques ne gardent que leurs écarts. */
  .activity-copy, .user-tools button, .msg.bot .copy-button,
  .msg.bot .speak-button, .msg.bot .rate-button {
    background: none;
    border: 1px solid var(--border);
    color: var(--muted);
    font: inherit;
    font-size: 0.72rem;
    cursor: pointer;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    transition: color 0.15s, border-color 0.15s, background 0.15s, opacity 0.15s;
  }
  @media (hover: hover) {
    .activity-copy:hover, .user-tools button:hover,
    .msg.bot .copy-button:hover, .msg.bot .speak-button:hover {
      color: var(--text);
      border-color: var(--accent);
      background: var(--accent-soft);
    }
  }
  .activity-copy::before { content: "⧉ "; }
  .activity-copy.copied { color: var(--accent); border-color: var(--accent); }
  .activity-copy.copied::before { content: "✓ "; }
  .activity-log {
    border-top: 1px solid var(--border);
    padding: 0.55rem 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 38vh;
    max-height: 38dvh;
    overflow-y: auto;
  }
  .act-entry .act-label { color: var(--text); }
  .act-entry.status .act-label { color: var(--accent); }
  .act-entry .act-when {
    color: var(--muted);
    font-size: 0.72rem;
    margin-left: 0.4rem;
    font-variant-numeric: tabular-nums;
  }
  .act-entry pre {
    margin-top: 0.25rem;
    background: var(--code-bg);
    border-radius: 8px;
    padding: 0.35rem 0.55rem;
    font: 0.72rem/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    max-height: 9rem;
    overflow-y: auto;
    color: var(--muted);
  }
  .act-entry.reasoning pre { font-style: italic; }

  #empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    color: var(--muted);
    padding-bottom: 15vh;
    user-select: none;
  }
  /* Écran verrouillé : masque tout sauf lui-même et les dialogs d'auth. */
  #lock-screen { display: none; }
  body.locked > :not(#lock-screen):not(dialog) { display: none; }
  body.locked #lock-screen {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: var(--muted);
  }

  #empty-state::before,
  #lock-screen::before {
    content: "";
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-2), var(--accent));
    box-shadow: 0 0 0 6px var(--accent-soft);
    margin-bottom: 1rem;
    animation: breathe 3.2s ease-in-out infinite;
  }
  @keyframes breathe {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 6px var(--accent-soft); }
    50%      { transform: scale(1.12); box-shadow: 0 0 0 10px var(--accent-soft); }
  }
  #empty-state .big,
  #lock-screen .big {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.015em;
    color: var(--text);
  }
  body.has-messages #empty-state { display: none; }

  .msg { animation: rise 0.25s ease both; }
  @keyframes rise {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
  }

  .msg.user {
    align-self: flex-end;
    max-width: 82%;
    background: var(--user-bubble);
    color: var(--user-text);
    padding: 0.65rem 1.05rem;
    border-radius: 20px 20px 6px 20px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    box-shadow: 0 2px 10px rgba(35, 70, 50, 0.18);
  }

  /* --- Outils sous le message envoyé : copier / renvoyer, toujours visibles. --- */
  .user-wrap {
    align-self: flex-end;
    max-width: 82%;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.3rem;
  }
  .user-wrap .msg.user { max-width: 100%; align-self: auto; }
  .user-tools { display: flex; gap: 0.35rem; }

  .msg.bot {
    align-self: flex-start;
    max-width: 100%;
    width: 100%;
    overflow-wrap: anywhere;
  }
  .msg.bot .label {
    font-size: 0.72rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent);
    margin-bottom: 0.35rem;
  }
  .msg.bot .body p { margin: 0 0 0.7em; }
  .msg.bot .body p:last-child { margin-bottom: 0; }
  .msg.bot .body ul, .msg.bot .body ol { margin: 0 0 0.7em 1.4em; }
  .msg.bot .body li { margin-bottom: 0.25em; }
  .msg.bot .body code {
    background: var(--code-bg);
    border-radius: 5px;
    padding: 0.1em 0.4em;
    font-size: 0.88em;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  }
  .msg.bot .body a { color: var(--accent); }
  .msg.bot .body pre {
    background: var(--code-bg);
    border-radius: 8px;
    padding: 0.6em 0.8em;
    margin: 0 0 0.7em;
    overflow-x: auto;
  }
  .msg.bot .body pre code { background: none; padding: 0; font-size: 0.85em; }
  .msg.bot .body h4, .msg.bot .body h5, .msg.bot .body h6 {
    font-size: 1em;
    margin: 0.9em 0 0.4em;
  }
  .msg.bot .body h4:first-child { margin-top: 0; }
  /* Formules larges : défilement local, pas de débordement de la bulle. */
  .msg.bot .body .katex-display { overflow-x: auto; overflow-y: hidden; padding: 2px 0; }

  .msg.bot .copy-button {
    margin-top: 0.55rem;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
  }
  .msg.bot .sources {
    margin-top: 0.7rem;
    border-top: 1px solid var(--border);
    padding-top: 0.6rem;
  }
  .sources-title {
    font-size: 0.72rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin-bottom: 0.45rem;
  }
  .sources-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
  }
  .sources-list a {
    display: flex;
    align-items: baseline;
    gap: 0.55rem;
    text-decoration: none;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.4rem 0.6rem;
    transition: border-color 0.15s, background 0.15s;
  }
  @media (hover: hover) {
    .sources-list a:hover { border-color: var(--accent); background: var(--accent-soft); }
  }
  .sources-list .src-index {
    flex-shrink: 0;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    font-size: 0.78rem;
  }
  .sources-list .src-meta { display: flex; flex-direction: column; min-width: 0; }
  .sources-list .src-name {
    font-size: 0.86rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .sources-list .src-host { font-size: 0.72rem; color: var(--muted); }

  .msg.bot button + .speak-button { margin-left: 0.4rem; }

  .msg.bot .speak-button {
    margin-top: 0.55rem;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
  }
  .msg.bot .speak-button::before { content: "🔊"; font-size: 0.85em; }
  .msg.bot .speak-button.loading::before { content: "⏳"; }
  .msg.bot .speak-button.playing::before { content: "⏹"; }
  .msg.bot .speak-button.playing { color: var(--accent); border-color: var(--accent); }

  /* --- Évaluation de la réponse : pouces enregistrés dans chat_exchanges. --- */
  .msg.bot .rate-button {
    margin-top: 0.55rem;
    margin-left: 0.4rem;
    display: inline-flex;
    align-items: center;
    filter: grayscale(1);
    opacity: 0.75;
  }
  @media (hover: hover) {
    .msg.bot .rate-button:hover {
      color: var(--text);
      border-color: var(--muted);
      filter: none;
      opacity: 1;
    }
  }
  .msg.bot .rate-button.active {
    color: var(--accent);
    border-color: var(--accent);
    filter: none;
    opacity: 1;
  }

  .msg.bot .copy-button::before { content: "⧉"; font-size: 0.85em; }
  .msg.bot .copy-button.copied {
    color: var(--accent);
    border-color: var(--accent);
  }
  .msg.bot .copy-button.copied::before { content: "✓"; }

  .msg.error .body {
    background: var(--error-bg);
    color: var(--error);
    border-radius: 12px;
    padding: 0.6rem 0.9rem;
    font-size: 0.9rem;
  }

  .msg.pending .body:empty::after {
    content: "•••";
    letter-spacing: 0.25em;
    color: var(--muted);
    animation: pulse 1.3s ease-in-out infinite;
  }
  @keyframes pulse {
    0%, 100% { opacity: 0.25; }
    50%      { opacity: 1; }
  }
  .status-text {
    color: var(--muted);
    font-size: 0.9rem;
    animation: pulse 1.3s ease-in-out infinite;
  }
  .msg .body .interrupted {
    color: var(--muted);
    font-size: 0.8rem;
  }
  .msg .body .canvas-note {
    color: var(--muted);
    font-size: 0.8rem;
    font-style: italic;
  }

  /* --- History: past exchanges in a slide-in side panel. --- */
  #history-panel {
    position: fixed;
    top: 0;
    right: 0;
    height: 100%;
    width: min(92vw, 420px);
    background: var(--surface);
    border-left: 1px solid var(--border);
    border-radius: 18px 0 0 18px;
    box-shadow: var(--shadow-pop);
    transform: translateX(100%);
    transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.3, 1);
    display: flex;
    flex-direction: column;
    z-index: 30;
  }
  body.history-open #history-panel { transform: none; }
  .history-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.9rem 1.1rem 0.6rem;
    border-bottom: 1px solid var(--border);
  }
  .history-head h2 { font-size: 0.9rem; font-weight: 650; }
  #history-scroll {
    flex: 1;
    overflow-y: auto;
  }
  #thread {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    padding: 1.1rem;
  }
  #thread:empty::after {
    content: "Aucun échange pour l'instant.";
    color: var(--muted);
    font-size: 0.85rem;
  }
  #history-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 8, 0.35);
    backdrop-filter: blur(2px);
    z-index: 20;
    display: none;
  }
  body.history-open #history-backdrop { display: block; }

  /* --- Notifications : alertes émises par pepi, cloche + panneau latéral. --- */
  #alerts-button { position: relative; }
  #alerts-badge {
    position: absolute;
    top: -0.15rem;
    right: -0.15rem;
    min-width: 1.05rem;
    padding: 0 0.25rem;
    height: 1.05rem;
    line-height: 1.05rem;
    border-radius: 999px;
    background: #dc2626;
    color: #fff;
    font-size: 0.62rem;
    font-weight: 650;
    text-align: center;
  }
  #alerts-panel {
    position: fixed;
    top: 0;
    right: 0;
    height: 100%;
    width: min(92vw, 420px);
    background: var(--surface);
    border-left: 1px solid var(--border);
    border-radius: 18px 0 0 18px;
    box-shadow: var(--shadow-pop);
    transform: translateX(100%);
    transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.3, 1);
    display: flex;
    flex-direction: column;
    z-index: 30;
  }
  body.alerts-open #alerts-panel { transform: none; }
  #alerts-scroll { flex: 1; overflow-y: auto; }
  #alerts-list {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    padding: 1.1rem;
  }
  #alerts-list:empty::after {
    content: "Aucune notification pour l'instant.";
    color: var(--muted);
    font-size: 0.85rem;
  }
  .alert-item {
    border: 1px solid var(--border);
    border-left: 3px solid var(--border);
    border-radius: 12px;
    padding: 0.65rem 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
  }
  .alert-item.unread { border-left-color: var(--accent); }
  .alert-item.warning { border-left-color: #d97706; }
  .alert-item.error { border-left-color: #dc2626; }
  .alert-title { font-size: 0.88rem; font-weight: 650; }
  .alert-body {
    font-size: 0.82rem;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    max-height: 40vh;
    max-height: 40dvh;
    overflow-y: auto;
  }
  .alert-meta { font-size: 0.72rem; color: var(--muted); }
  #alerts-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 8, 0.35);
    backdrop-filter: blur(2px);
    z-index: 20;
    display: none;
  }
  body.alerts-open #alerts-backdrop { display: block; }

  /* Bouton « aller en bas » : n'existe que décroché du bas ; s'accentue
     quand une carte de confirmation attend hors écran. */
  #jump-bottom {
    position: fixed;
    right: 1rem;
    bottom: calc(7rem + env(safe-area-inset-bottom));
    width: 44px;
    height: 44px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    color: var(--text);
    font-size: 1.15rem;
    box-shadow: var(--shadow-pop);
    cursor: pointer;
    z-index: 15;
  }
  #jump-bottom.has-pending {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
  }
  #jump-bottom.has-pending::after {
    content: "⏸";
    position: absolute;
    top: -0.4rem;
    right: -0.3rem;
    font-size: 0.75rem;
  }

  #composer {
    padding: 0.5rem 1.25rem calc(1.1rem + env(safe-area-inset-bottom));
  }
  /* Deux lignes : zone de texte pleine largeur au-dessus, boutons dessous —
     sur mobile, quatre boutons sur la même ligne étranglaient la saisie. */
  #chat-form {
    max-width: 680px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.3rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 26px;
    padding: 0.6rem 0.6rem 0.5rem 1rem;
    box-shadow: var(--shadow);
    transition: border-color 0.15s, box-shadow 0.2s;
  }
  #composer-buttons {
    display: flex;
    align-items: center;
    gap: 0.35rem;
  }
  #composer-buttons #send { margin-left: auto; }
  #chat-form:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow);
  }
  #input {
    flex: 1;
    min-width: 0; /* autorise le rétrécissement : sans ça, les boutons débordent */
    resize: none;
    border: none;
    background: none;
    color: var(--text);
    font: inherit;
    /* < 16px, iOS Safari zoome au focus et ne revient pas : jamais moins. */
    font-size: 16px;
    line-height: 1.5;
    padding: 0.35rem 0;
    max-height: 9rem;
    outline: none;
  }
  #input::placeholder { color: var(--muted); }
  #send {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-2), var(--accent));
    color: #fff;
    font-size: 1.05rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(35, 70, 50, 0.3);
    transition: opacity 0.15s, transform 0.1s, background 0.2s;
  }
  @media (hover: hover) {
    #send:hover { transform: scale(1.06); }
  }
  #send:disabled { opacity: 0.35; cursor: default; transform: none; }
  /* En cours de run, le même bouton devient STOP : rouge, sans ambiguïté
     avec l'envoi (qui reste vert). */
  #send.running { background: var(--error); color: #fff; }

  /* Pastille modèle+raisonnement (#engine) : ouvre la feuille de sélection
     maison (styles du panneau dans app-engine.css). */
  .chip-face {
    height: 36px;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    border: 1px solid var(--border);
    border-radius: 18px;
    color: var(--muted);
    font-size: 0.9rem;
    padding: 0 0.65rem;
    white-space: nowrap;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
  }
  .chip-face .chip-label {
    font-size: 0.72rem;
    max-width: 9rem;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .chip-face.boosted { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
  /* Écran étroit : icône seule — le nom complet vit dans le menu natif. */
  @media (max-width: 480px) {
    .chip-face .chip-label { display: none; }
    .chip-face { padding: 0; width: 40px; justify-content: center; }
  }

  #mic {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: none;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.15s, background 0.15s, transform 0.1s;
  }
  @media (hover: hover) {
    #mic:hover { border-color: var(--accent); background: var(--accent-soft); }
  }
  #mic.recording {
    border-color: var(--error);
    background: var(--error-bg);
    animation: pulse 1.3s ease-in-out infinite;
  }
  #mic.busy { animation: pulse 1.3s ease-in-out infinite; cursor: default; }

  dialog {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 1.5rem;
    width: min(90vw, 380px);
    box-shadow: var(--shadow-pop);
    margin: auto;
  }
  dialog::backdrop { background: rgba(10, 10, 8, 0.45); backdrop-filter: blur(2px); }
  dialog h2 { font-size: 1rem; font-weight: 650; margin-bottom: 0.3rem; }
  dialog p { font-size: 0.85rem; color: var(--muted); margin-bottom: 1rem; }
  dialog input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font: inherit;
    /* < 16px, iOS Safari zoome au focus et ne revient pas : jamais moins. */
    font-size: 16px;
    padding: 0.55rem 0.8rem;
    margin-bottom: 1rem;
    outline: none;
  }
  dialog input:focus { border-color: var(--accent); }
  dialog button {
    width: 100%;
    background: var(--accent);
    color: var(--surface);
    border: none;
    border-radius: 10px;
    padding: 0.55rem 1rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
  }
  dialog .link-button {
    background: none;
    color: var(--accent);
    font-weight: 500;
    font-size: 0.82rem;
    margin-top: 0.5rem;
    padding: 0.25rem;
  }
  #twofa-hint.error { color: var(--error); }

  #logs-dialog { width: min(94vw, 860px); }
  .logs-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.6rem;
  }
  .logs-head h2 { margin: 0; }
  .logs-actions { display: flex; gap: 0.4rem; }
  .logs-actions button { width: auto; padding: 0.35rem 0.8rem; font-size: 0.8rem; font-weight: 600; }
  .logs-actions button.secondary { background: var(--accent-soft); color: var(--accent); }
  #logs-meta { font-size: 0.75rem; color: var(--muted); margin-bottom: 0.5rem; }
  #logs-output {
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.7rem 0.9rem;
    max-height: 62vh;
    max-height: 62dvh;
    overflow: auto;
    font: 0.72rem/1.55 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
  }

  /* --- Tactile : retour visuel à l'appui, les :hover ci-dessus étant
     réservés aux vrais pointeurs via @media (hover: hover). --- */
  .header-button:active, .user-tools button:active, .activity-copy:active,
  .msg.bot .copy-button:active, .msg.bot .speak-button:active,
  .msg.bot .rate-button:active, .audio-player .tracks button:active,
  #attachment-chip button:active, dialog .link-button:active {
    color: var(--text);
    border-color: var(--accent);
    background: var(--accent-soft);
  }
  .sources-list a:active, #engine:active,
  #mic:active, #attach:active {
    border-color: var(--accent);
    background: var(--accent-soft);
  }
  #send:active:not(:disabled) { transform: scale(0.92); }
  .pending-card button:active:not(:disabled) { transform: scale(0.96); }

  /* --- Écrans tactiles : cibles ≥ 44px (Confirmer/Annuler d'écritures
     irréversibles en premier), sans grossir le rendu desktop. --- */
  @media (pointer: coarse) {
    /* Clavier logiciel ouvert, un dialog centré passe derrière : l'ancrer
       dans le tiers haut de l'écran. */
    dialog { margin-top: 8dvh; margin-bottom: auto; }
    .pending-card .pa-buttons { gap: 0.75rem; }
    .pending-card button { min-height: 44px; padding: 0.5rem 1.2rem; }
    #send, #mic, #attach { width: 44px; height: 44px; }
    .chip-face { height: 44px; border-radius: 22px; }
    @media (max-width: 480px) {
      .chip-face { width: 44px; }
    }
    .header-button { min-height: 44px; padding: 0.55rem 0.6rem; }
    .user-tools button, .activity-copy, .msg.bot .copy-button,
    .msg.bot .speak-button, .msg.bot .rate-button {
      min-height: 36px;
      padding: 0.4rem 0.7rem;
    }
    #attachment-chip button { min-width: 40px; min-height: 40px; }
    .audio-player .tracks button { padding: 0.55rem 0.5rem; }
    dialog .link-button { min-height: 44px; }
  }
