/* «Parla con Graphorum» (voice.js): conversazione a voce. A tutto schermo sul telefono, un pannello al centro sul
   computer. Un cerchio grande che respira con la tua voce (ascolto) e con la sua (lettura), lo stato in una parola,
   in basso Muto · Testo · Fine. Colori dai token della pagina (--accent, --surface, --ink…): tema chiaro/scuro incluso. */
.vx { position: fixed; inset: 0; z-index: 85; display: grid; place-items: center;
  background: color-mix(in srgb, var(--ground, #0e1018) 60%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.vx.hidden { display: none; }
body.vx-on { overflow: hidden; }
body.vx-on .toast { z-index: 87; }
.vx-panel { --orb: 11rem; position: relative; width: min(27rem, calc(100vw - 32px)); height: min(40rem, calc(100dvh - 32px)); overflow: hidden;
  display: grid; grid-template-rows: auto 1fr auto auto; gap: .4rem; padding: 1rem 1rem 1.3rem;
  color: var(--ink, #12141c); border-radius: var(--radius); box-shadow: var(--shadow-lift, 0 18px 50px rgba(0, 0, 0, .25));
  background: radial-gradient(120% 70% at 50% 36%, color-mix(in srgb, var(--accent, #2f6bff) 10%, var(--surface, #fff)), var(--surface, #fff) 70%); }
.vx-head { display: flex; align-items: center; gap: .4rem; min-height: 2.6rem; }
.vx-title { flex: 1; font-weight: 600; font-size: var(--fs-md); color: var(--muted, #6b7080); letter-spacing: .01em; }
.vx-icon { display: inline-grid; place-items: center; width: 2.6rem; height: 2.6rem; border: 0; border-radius: var(--radius);
  background: transparent; color: var(--muted, #6b7080); cursor: pointer; }
.vx-icon:hover { background: var(--surface-2, #f1f2f6); color: var(--ink, #12141c); }
.vx-icon svg { width: var(--ic-md); height: var(--ic-md); }
.vx-icon.hidden { display: none; }

/* il cerchio */
.vx-stage { display: grid; place-content: center; justify-items: center; gap: .35rem; min-height: 0; }
.vx-orb { position: relative; width: var(--orb); height: var(--orb); margin: 1.2rem 0 2.6rem; min-height: 0; padding: 0; border: 0; border-radius: 50%;
  background: transparent; cursor: pointer; touch-action: manipulation; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
.vx .vx-orb:hover, .vx .vx-orb:active, .vx .vx-btn:hover, .vx .vx-btn:active { box-shadow: none; transform: none; border: 0; background: transparent; }
.vx-state, .vx-hint { position: relative; z-index: 1; }
.vx-orb:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent, #2f6bff) 55%, transparent); outline-offset: 10px; }
.vx-core, .vx-halo { position: absolute; border-radius: 50%; pointer-events: none; }
.vx-core { inset: 0; transform: scale(calc(1 + var(--lvl, 0) * .16)); transition: transform 90ms linear, background .4s, border-radius .6s;
  background: radial-gradient(circle at 34% 28%, color-mix(in srgb, var(--accent, #2f6bff) 45%, #fff) 0%, var(--accent, #2f6bff) 52%,
    color-mix(in srgb, var(--accent, #2f6bff) 72%, #000) 100%);
  box-shadow: 0 18px 50px -12px color-mix(in srgb, var(--accent, #2f6bff) 65%, transparent), inset 0 -10px 30px rgba(0, 0, 0, .12); }
.vx-halo { inset: -7%; background: color-mix(in srgb, var(--accent, #2f6bff) 20%, transparent);
  transform: scale(calc(1 + var(--lvl, 0) * .22)); transition: transform 110ms linear, opacity .3s; }
.vx-halo2 { inset: -14%; background: color-mix(in srgb, var(--accent, #2f6bff) 9%, transparent); transform: scale(calc(1 + var(--lvl, 0) * .3)); }
.vx[data-state="tap"] .vx-halo, .vx[data-state="tap"] .vx-core { animation: vx-breathe 2.6s ease-in-out infinite; }
.vx[data-state="sending"] .vx-core, .vx[data-state="thinking"] .vx-core { animation: vx-morph 2.4s ease-in-out infinite; }
.vx[data-state="sending"] .vx-halo, .vx[data-state="thinking"] .vx-halo { animation: vx-breathe 1.6s ease-in-out infinite; }
.vx[data-state="speaking"] .vx-core { background: radial-gradient(circle at 34% 28%, color-mix(in srgb, var(--accent, #2f6bff) 30%, #fff) 0%,
    color-mix(in srgb, var(--accent, #2f6bff) 85%, var(--c-ai, #7457e8)) 55%, color-mix(in srgb, var(--accent, #2f6bff) 60%, #000) 100%); }
.vx[data-state="muted"] .vx-core { background: radial-gradient(circle at 34% 28%, var(--surface-3, #e6e8ee), var(--line-strong, #c9ccd6));
  box-shadow: none; transform: none; }
.vx[data-state="muted"] .vx-halo { opacity: 0; }
@keyframes vx-breathe { 50% { transform: scale(1.08); opacity: .7; } }
@keyframes vx-morph { 0%, 100% { border-radius: 50%; transform: scale(.96); } 33% { border-radius: var(--radius); transform: scale(1.02); }
  66% { border-radius: var(--radius); transform: scale(.98); } }
.vx-state { margin: 0; font-size: var(--fs-2xl); font-weight: 600; text-align: center; min-height: 1.3em; letter-spacing: -.01em; }
.vx[data-state="tap"] .vx-state { font-size: var(--fs-4xl); }
.vx-hint { margin: 0; font-size: var(--fs-base); color: var(--muted, #6b7080); text-align: center; min-height: 1.3em; max-width: 22rem; }

/* «Testo»: quello che hai detto e la risposta */
.vx-say { display: none; gap: .5rem; align-content: end; max-height: 30dvh; overflow: auto; padding: .2rem .1rem; }
.vx.vx-subs .vx-say { display: grid; }
.vx.vx-subs:has(.vx-say p:not(:empty)) .vx-panel { --orb: 8rem; }
.vx-say p { margin: 0; line-height: 1.45; overflow-wrap: anywhere; }
.vx-say p:empty { display: none; }
.vx-you { justify-self: end; max-width: 88%; padding: .5rem .8rem; border-radius: var(--radius);
  background: var(--user-bubble, var(--surface-2, #f1f2f6)); color: var(--ink, #12141c); }
.vx-bot { color: var(--ink-2, var(--ink, #12141c)); font-size: var(--fs-md); white-space: pre-line; }

/* capito male: la frase incerta in grigio, «Ripeti» e «Sì, intendevo questo». Sempre visibile (anche senza «Testo») */
.vx-unsure { display: grid; gap: .55rem; justify-items: center; text-align: center; padding: .85rem 1rem .95rem;
  border-radius: var(--radius); border: 1px dashed color-mix(in srgb, var(--warn, #a8690a) 45%, var(--line, #e3e5ec));
  background: color-mix(in srgb, var(--amber, #f5b941) 7%, var(--surface, #fff)); animation: vx-in .22s ease-out; }
.vx-unsure.hidden { display: none; }
.vx-unsure p { margin: 0; }
.vx-unsure-k { display: inline-flex; align-items: center; gap: .45rem; font-size: var(--fs-sm); font-weight: 600;
  letter-spacing: .01em; color: var(--warn, #a8690a); }
.vx-unsure-dot { width: .5rem; height: .5rem; border-radius: 50%; background: var(--amber, #f5b941);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--amber, #f5b941) 25%, transparent); }
.vx-unsure-text { max-width: 100%; max-height: 6.2em; overflow: auto; font-size: var(--fs-lg); line-height: 1.45; font-style: italic;
  color: var(--muted, #6b7080); overflow-wrap: anywhere; }
.vx-unsure-btns { display: flex; flex-wrap: wrap; justify-content: center; gap: .5rem; margin-top: .15rem; }
.vx-unsure-btns .vx-chip { min-width: 7.5rem; }
.vx.vx-has-unsure .vx-panel { --orb: 7.5rem; }
.vx.vx-has-unsure .vx-orb { margin: .6rem 0 1.4rem; }
@keyframes vx-in { from { opacity: 0; transform: translateY(6px); } }

/* Muto · Testo · Fine */
.vx-ctrl { display: flex; justify-content: center; gap: clamp(1.2rem, 8vw, 2.4rem); padding-top: .4rem; }
.vx-btn { display: grid; justify-items: center; gap: .35rem; padding: 0; min-height: 0; border: 0; background: transparent; cursor: pointer;
  font: inherit; font-size: var(--fs-xs); font-weight: 500; color: var(--muted, #6b7080); -webkit-tap-highlight-color: transparent; }
.vx-bi { display: grid; place-items: center; width: 3.7rem; height: 3.7rem; border-radius: 50%; transition: background .2s, transform .1s;
  background: var(--surface-2, #f1f2f6); color: var(--ink, #12141c); border: 1px solid var(--line, #e3e5ec); }
.vx-bi svg { width: var(--ic-lg); height: var(--ic-lg); }
.vx-btn:active .vx-bi { transform: scale(.94); }
.vx-btn:focus-visible { outline: none; }
.vx-btn:focus-visible .vx-bi { outline: 3px solid color-mix(in srgb, var(--accent, #2f6bff) 55%, transparent); outline-offset: 3px; }
.vx-btn[aria-pressed="true"] .vx-bi { background: var(--ink, #12141c); color: var(--surface, #fff); border-color: var(--ink, #12141c); }
.vx-btn[aria-pressed="true"] { color: var(--ink, #12141c); }
.vx-end .vx-bi { background: var(--danger, #d6343f); color: #fff; border-color: var(--danger, #d6343f); }

/* impostazioni (capo) */
.vx-chip { min-height: 2.6rem; padding: .45rem 1rem; border-radius: var(--radius); cursor: pointer; font: inherit; font-weight: 500;
  border: 1px solid var(--line-strong, var(--line, #d8dbe4)); background: var(--surface, #fff); color: var(--ink, #12141c); }
.vx-primary { background: var(--accent, #2f6bff); border-color: var(--accent, #2f6bff); color: var(--accent-ink, #fff); }
.vx-settings { position: absolute; inset: 0; z-index: 2; display: grid; align-content: start; gap: .7rem; padding: 1rem 1.1rem 1.2rem;
  overflow: auto; background: var(--surface, #fff); border-radius: inherit; }
.vx-settings.hidden { display: none; }
.vx-settings h3 { margin: 0 0 .2rem; font-size: var(--fs-lg); }
.vx-row { display: flex; align-items: center; gap: .6rem; min-height: 2.4rem; }
.vx-row input { width: 1.2rem; height: 1.2rem; accent-color: var(--accent, #2f6bff); }
.vx-field { display: grid; gap: .3rem; font-size: var(--fs-md); }
.vx-field select, .vx-field input[type=range] { width: 100%; min-height: 2.5rem; font: inherit; accent-color: var(--accent, #2f6bff); }
.vx-field select { padding: .4rem .6rem; border-radius: var(--radius); border: 1px solid var(--line-strong, #d8dbe4);
  background: var(--surface-2, #f6f7fa); color: var(--ink, #12141c); }
/* la voce con «Ascolta» accanto: tendina e pulsante sulla stessa riga, alla stessa altezza */
.vx-voice { display: flex; gap: .5rem; align-items: stretch; min-width: 0; }
.vx-voice select { flex: 1 1 auto; min-width: 0; }
.vx-voice select, .vx-voice .vx-chip { min-height: 2.6rem; }
.vx-voice .vx-chip { flex: none; }
.vx-voice .vx-chip[aria-pressed="true"] { border-color: var(--accent, #2f6bff); color: var(--accent, #2f6bff); }
.vx-voice-note { color: var(--muted, #6b7080); font-size: var(--fs-sm); line-height: 1.4; }
.vx-settings .vx-sub { margin: .5rem 0 -.1rem; padding-top: .8rem; border-top: 1px solid var(--line, #e3e5ec); }
.vx-set { display: grid; gap: .45rem; margin: 0; padding: 0; border: 0; min-width: 0; font-size: var(--fs-md); }
.vx-set legend { padding: 0; margin-bottom: .45rem; font-size: var(--fs-md); font-weight: 400; color: inherit; }
.vx-set small { color: var(--muted, #6b7080); font-size: var(--fs-sm); line-height: 1.4; }
.vx-langs { display: flex; flex-wrap: wrap; gap: .4rem; }
.vx-lang { position: relative; display: inline-flex; cursor: pointer; }
.vx-lang input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.vx-lang span { display: inline-flex; align-items: center; gap: .3rem; min-height: 2.3rem; padding: .35rem .8rem .35rem .65rem;
  border-radius: var(--radius); border: 1px solid var(--line-strong, #d8dbe4); background: var(--surface, #fff); color: var(--ink-2, #3a3f4d);
  font-size: var(--fs-base); font-weight: 500; transition: background .15s, border-color .15s, color .15s; user-select: none; }
.vx-lang svg { width: 0; height: .95rem; opacity: 0; transition: width .15s, opacity .15s; }
.vx-lang input:checked + span { background: var(--accent-soft, #eef0ff); border-color: var(--accent, #2f6bff); color: var(--ink, #12141c); }
.vx-lang input:checked + span svg { width: var(--ic-xs); opacity: 1; color: var(--accent, #2f6bff); }
.vx-lang input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--accent, #2f6bff) 45%, transparent); outline-offset: 2px; }
.vx-lang:hover span { border-color: var(--accent, #2f6bff); }
.vx-warn { margin: 0; padding: .6rem .75rem; border-radius: var(--radius); font-size: var(--fs-sm); line-height: 1.45;
  background: color-mix(in srgb, var(--amber, #f5b941) 14%, var(--surface, #fff)); color: var(--ink, #12141c);
  border: 1px solid color-mix(in srgb, var(--amber, #f5b941) 45%, transparent); }
.vx-warn.hidden { display: none; }
.vx-warn b { color: var(--warn, #a8690a); }
.vx-status { margin: 0; font-size: var(--fs-sm); color: var(--ink-2, #3a3f4d); line-height: 1.45; }
.vx-status small { display: block; margin-top: .3rem; color: var(--muted, #6b7080); }
.vx-btns { display: flex; justify-content: flex-end; gap: .5rem; }

/* dove si apre: accanto al microfono della chat, nella chat veloce, «Parla» nella barra in basso */
.vx-talk.hidden, .vx-qc.hidden { display: none; }
.composer .vx-talk { background: var(--accent-soft, #eef0ff); color: var(--accent, #2f6bff); border-radius: var(--radius); }
.vx-talk svg, .vx-qc svg { width: var(--ic-md); height: var(--ic-md); }
.qc-bar .vx-qc { flex: none; width: 2.6rem; height: 2.6rem; border-radius: var(--radius); color: #2F6BFF;
  background: color-mix(in srgb, #2F6BFF 12%, transparent); }
/* «Chiedi» tenuto premuto (extra): senza il menu del telefono */
.bottombar [data-qc] { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }

@media (max-width: 640px) {
  .vx { place-items: stretch; background: var(--surface, #fff); backdrop-filter: none; -webkit-backdrop-filter: none; }
  .vx-panel { --orb: min(13rem, 56vw); width: 100%; height: 100dvh; border-radius: 0; box-shadow: none;
    padding: calc(.6rem + env(safe-area-inset-top, 0px)) 16px calc(1.4rem + env(safe-area-inset-bottom, 0px)); }
  .vx.vx-subs:has(.vx-say p:not(:empty)) .vx-panel { --orb: min(9.5rem, 42vw); }
  .vx-say { max-height: 34dvh; }
}
@media (prefers-reduced-motion: reduce) {
  .vx-core, .vx-halo { animation: none !important; transition: none; }
}

/* «Parla» sul telefono: tondo, in basso a destra sopra la barra; sul computer c'è nella barra delle domande */
.vx-fab { display: none; }
@media (max-width: 860px) {
  .vx-fab:not(.hidden) { display: grid; place-items: center; pointer-events: auto; width: 3.2rem; height: 3.2rem; padding: 0; border: 0;
    border-radius: var(--radius); color: #fff; background: linear-gradient(135deg, #2F6BFF, #38BDF8);
    box-shadow: 0 10px 24px -8px rgba(47, 107, 255, .6), 0 2px 6px rgba(0, 0, 0, .15); }
  .vx-fab svg { width: var(--ic-lg); height: var(--ic-lg); color: #fff; }
  .vx-fab:active { transform: scale(.94); }
  body.pop-open .vx-fab, body.qc-on .vx-fab, body.nav-open .vx-fab { display: none !important; }
}
