/* Visitor overlay for the web runtime -- the design language of the desktop overlay v2
   (core/ui/client_overlay_v2.py, docs/ui_mockups/overlay_v2_mockup.html): squircle glass, muted gold / silver /
   bronze, serif for the character's words, no saturated colour. */
.tpo {
  --gold: #c7a86a; --gold-bright: #d8bd86; --gold-line: rgba(199,168,106,.42); --gold-line-2: rgba(199,168,106,.22);
  --silver: #c4c2bb; --bronze: #9c7b54; --text: #e9e1d2; --text-dim: #9a9285;
  --ink: rgba(17,15,12,.55); --ink-strong: rgba(14,13,11,.82); --ink-bubble: rgba(20,18,15,.52); --hair: rgba(255,255,255,.07);
  --shadow: 0 10px 34px rgba(0,0,0,.55); --serif: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  --sans: 'Inter', 'Segoe UI', system-ui, sans-serif; --mic: 88px; --edge: 24px;
  position: fixed; inset: 0; pointer-events: none; z-index: 20; font-family: var(--sans); color: var(--text);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
}
.tpo * { box-sizing: border-box; }
.tpo .sq {
  pointer-events: auto; border-radius: 22px; background: var(--ink); border: 1px solid var(--gold-line-2);
  backdrop-filter: blur(9px) saturate(.9); -webkit-backdrop-filter: blur(9px) saturate(.9);
  display: flex; align-items: center; justify-content: center; color: var(--silver); cursor: pointer;
  box-shadow: var(--shadow); transition: transform .18s ease, border-color .25s, color .25s, background .25s, box-shadow .25s;
  touch-action: none; -webkit-touch-callout: none; outline: none;
}
.tpo .sq:hover { border-color: var(--gold-line); }
.tpo .sq:focus-visible { border-color: var(--gold-bright); }

/* ── mic / system button ─────────────────────────────────────────────── */
.tpo .mic-wrap { position: absolute; left: var(--edge); bottom: var(--edge); width: calc(var(--mic) + 76px); height: calc(var(--mic) + 76px);
  margin: -38px; }
.tpo .mic-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.tpo .mic { position: absolute; left: 38px; top: 38px; width: var(--mic); height: var(--mic); border-radius: 50%; }
.tpo .mic svg { width: 40px; height: 40px; }
.tpo .mic:active { transform: scale(.96); }
.tpo .mic[data-state="off"], .tpo .mic[data-state="muted"] { color: var(--text-dim); }
.tpo .mic[data-state="open"] { color: var(--silver); border-color: rgba(196,194,187,.35); }
.tpo .mic[data-state="listening"] { color: var(--silver); border-color: rgba(196,194,187,.6); box-shadow: 0 0 0 3px rgba(196,194,187,.08), var(--shadow); }
.tpo .mic[data-state="thinking"] { color: var(--gold); border-color: var(--gold-line); box-shadow: 0 0 0 3px rgba(199,168,106,.08), var(--shadow); }
.tpo .mic[data-state="speaking"] { color: var(--gold-bright); border-color: rgba(216,189,134,.55); box-shadow: 0 0 0 3px rgba(199,168,106,.12), var(--shadow); }
.tpo .mic[data-state="offline"] { color: var(--bronze); }
.tpo .mic.held { color: var(--gold-bright); border-color: var(--gold-bright); background: linear-gradient(180deg, rgba(199,168,106,.18), var(--ink)); }
.tpo .mic[data-state="thinking"] svg circle { animation: tpo-dot 1.2s ease-in-out infinite; }
.tpo .mic[data-state="thinking"] svg circle:nth-child(2) { animation-delay: .15s; }
.tpo .mic[data-state="thinking"] svg circle:nth-child(3) { animation-delay: .3s; }
@keyframes tpo-dot { 0%, 100% { opacity: .35; } 40% { opacity: 1; } }
.tpo .hint { position: absolute; left: calc(var(--edge) + var(--mic) + 46px); bottom: calc(var(--edge) + var(--mic) / 2 - 9px);
  font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--text-dim); white-space: nowrap;
  text-shadow: 0 1px 6px rgba(0,0,0,.9); transition: opacity .4s; }
.tpo .hint.gone { opacity: 0; }

/* ── chat toggle + panel ─────────────────────────────────────────────── */
.tpo .chat-btn { position: absolute; right: var(--edge); bottom: calc(var(--edge) + (var(--mic) - 60px) / 2); width: 60px; height: 60px; border-radius: 18px; }
.tpo .chat-btn svg { width: 26px; height: 26px; }
.tpo .chat-btn.on { color: var(--gold-bright); border-color: var(--gold-line); background: linear-gradient(180deg, rgba(199,168,106,.16), var(--ink)); }
.tpo .chat-btn .dot { position: absolute; top: 9px; right: 9px; width: 7px; height: 7px; border-radius: 50%; background: var(--gold);
  opacity: 0; transition: opacity .3s; }
.tpo .chat-btn.unread .dot { opacity: 1; }

.tpo .chat { position: absolute; right: var(--edge); bottom: calc(var(--edge) + var(--mic) + 18px); width: min(420px, calc(100vw - 2 * var(--edge)));
  max-height: min(62vh, 640px); display: flex; flex-direction: column; gap: 10px;
  opacity: 0; transform: translateY(10px); transition: opacity .28s ease, transform .28s ease; pointer-events: none; }
.tpo.chat-open .chat { opacity: 1; transform: none; }
.tpo.chat-open .chat .log, .tpo.chat-open .chat form { pointer-events: auto; }
.tpo .log { overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 2px 2px 4px; scrollbar-width: thin;
  scrollbar-color: var(--gold-line-2) transparent; user-select: text; -webkit-user-select: text;
  mask-image: linear-gradient(to bottom, transparent 0, #000 28px); -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 28px); }
.tpo .bubble { max-width: 88%; padding: 11px 15px; border-radius: 15px; background: var(--ink-bubble);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); line-height: 1.45; font-size: 15px; font-weight: 300;
  box-shadow: 0 6px 20px rgba(0,0,0,.3); white-space: pre-wrap; overflow-wrap: anywhere; }
.tpo .bubble.ai { align-self: flex-start; border-left: 2px solid var(--gold-line); font-family: var(--serif); font-size: 18px; color: var(--text); }
.tpo .bubble.user { align-self: flex-end; border-right: 2px solid rgba(196,194,187,.35); color: #d8d4cb; }
.tpo .bubble.sys { align-self: center; font-size: 11px; letter-spacing: .1em; color: var(--text-dim); background: transparent; box-shadow: none;
  backdrop-filter: none; padding: 2px 8px; }
.tpo .bubble .who { display: block; font-family: var(--sans); font-weight: 500; font-size: 10px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--text-dim); margin-bottom: 4px; }
.tpo .bubble.pending::after { content: '▍'; color: var(--gold); animation: tpo-dot 1s steps(2) infinite; margin-left: 2px; }
.tpo form { display: flex; gap: 8px; align-items: center; padding: 6px 6px 6px 16px; border-radius: 18px; background: var(--ink-strong);
  border: 1px solid var(--gold-line-2); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: var(--shadow); }
.tpo form:focus-within { border-color: var(--gold-line); }
.tpo input { flex: 1; min-width: 0; background: transparent; border: 0; outline: none; color: var(--text); font: 300 16px var(--sans);
  padding: 9px 0; user-select: text; -webkit-user-select: text; }
.tpo input::placeholder { color: var(--text-dim); }
.tpo .send { width: 40px; height: 40px; border-radius: 13px; box-shadow: none; flex: none; }
.tpo .send svg { width: 20px; height: 20px; }
.tpo .send:disabled { opacity: .35; cursor: default; }

/* ── loading line (the poster is up; the avatar is still on its way) ──── */
.tpo .loading { position: absolute; left: 50%; top: 18px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 7px;
  font-size: 10.5px; letter-spacing: .2em; text-transform: uppercase; color: var(--text-dim); text-shadow: 0 1px 6px rgba(0,0,0,.9);
  transition: opacity .6s; }
.tpo .loading.done { opacity: 0; }
.tpo .loading .bar { width: 120px; height: 2px; background: rgba(255,255,255,.1); border-radius: 2px; overflow: hidden; }
.tpo .loading .bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--bronze), var(--gold)); transition: width .25s; }

.tpo .toast { position: absolute; left: 50%; bottom: calc(var(--edge) + var(--mic) + 22px); transform: translate(-50%, 6px); max-width: calc(100vw - 40px);
  padding: 9px 14px; border-radius: 12px; background: var(--ink-strong); border: 1px solid var(--gold-line-2); font-size: 13px; color: var(--text);
  opacity: 0; transition: opacity .3s, transform .3s; text-align: center; }
.tpo .toast.on { opacity: 1; transform: translate(-50%, 0); }

/* phones: mic centred at the thumb, chat as a sheet above it */
@media (max-width: 640px) {
  .tpo { --mic: 76px; --edge: 18px; }
  .tpo .mic-wrap { left: 50%; margin-left: calc(-1 * (var(--mic) + 76px) / 2); }
  .tpo .hint { left: 50%; transform: translateX(-50%); bottom: calc(var(--edge) + var(--mic) + 26px); }
  .tpo .chat { left: 12px; right: 12px; width: auto; bottom: calc(var(--edge) + var(--mic) + 20px); max-height: 40vh; }
  .tpo .bubble { padding: 9px 13px; font-size: 14px; background: rgba(20,18,15,.62); }
  .tpo.chat-open .hint { opacity: 0; }
  .tpo .bubble.ai { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) { .tpo * { transition: none !important; animation: none !important; } }
