/* twin.css — the /twin page: a full-viewport, app-like surface.
   Chat and voice each own the whole page; a slim top bar holds
   back link, identity, and the mode switch. */

/* lock the app to the exact viewport: a 100% chain from the root beats
   dvh quirks with zoom, scrollbars, and browser chrome */
html.twin-root { height: 100%; overflow: hidden; }
body.twin-app {
  height: 100%; display: flex; flex-direction: column;
  overflow: hidden; overscroll-behavior: none;
}
/* the hidden attribute must always win — .btn/.voice-live set display and would
   otherwise override the UA's [hidden]{display:none} (author styles beat UA) */
.twin-app [hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.twin-top {
  flex: 0 0 auto; display: flex; align-items: center; gap: 16px;
  padding: 12px clamp(16px, 3.5vw, 28px);
  border-bottom: 1px solid var(--line); background: var(--bg);
}
.tt-back {
  flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 50%;
  color: var(--muted); border: 1px solid var(--line-strong); background: var(--surface);
  transition: color .2s, border-color .2s, transform .18s var(--ease);
}
.tt-back:hover { color: var(--accent); border-color: var(--accent); transform: translateX(-2px); }
.tt-back svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tt-id { display: flex; align-items: center; gap: 11px; min-width: 0; margin-right: auto; }
.tt-avatar { position: relative; flex: 0 0 auto; }
.tt-avatar img {
  display: block; width: 40px; height: 40px; border-radius: 50%;
  object-fit: cover; object-position: top;
  border: 2px solid var(--surface); box-shadow: var(--shadow-sm);
}
.tt-dot {
  position: absolute; right: -1px; bottom: 0; width: 10px; height: 10px;
  border-radius: 50%; background: var(--rose); border: 2px solid var(--bg);
}
.tt-name { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.tt-name strong { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; }
.tt-name span { font-size: 12px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* segmented control */
.twin-seg {
  position: relative; display: inline-flex; flex: 0 0 auto; padding: 3px;
  background: var(--fog); border: 1px solid var(--line-strong); border-radius: var(--radius-pill);
}
.twin-seg .seg-thumb {
  position: absolute; top: 3px; left: 0; height: calc(100% - 6px); width: 10px;
  background: var(--ink); border-radius: var(--radius-pill);
  transition: transform .32s var(--ease), width .32s var(--ease);
}
.twin-seg button {
  position: relative; z-index: 1; display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 18px; border: 0; background: transparent; border-radius: var(--radius-pill);
  font-family: var(--font); font-size: 14px; font-weight: 600; letter-spacing: -0.01em;
  color: var(--muted); cursor: pointer; transition: color .25s;
}
.twin-seg button.is-active { color: var(--cream); }
.twin-seg button svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Panes ---------- */
.twin-body { flex: 1; min-height: 0; display: flex; }
/* padding: 0 overrides layout.css's `section { padding: var(--section-gap) 0 }` —
   these panes fill the app viewport, so the marketing-page rhythm doesn't apply */
.twin-pane { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 0; }
.twin-pane[hidden] { display: none; }

/* ---------- Chat ---------- */
.chat-scroll {
  flex: 1; min-height: 0; overflow-y: auto; scroll-behavior: smooth;
  display: flex; flex-direction: column; overscroll-behavior: contain;
}
.chat-col {
  width: 100%; max-width: 720px; margin: 0 auto;
  padding: clamp(20px, 4vh, 36px) 20px 20px;
}
.msg { display: flex; gap: 10px; margin-top: 18px; align-items: flex-end; }
.msg:first-child { margin-top: 0; }
@keyframes msgIn { from { opacity: 0; transform: translateY(10px); } }
.msg { animation: msgIn .35s var(--ease) backwards; }
.msg .m-avatar {
  width: 28px; height: 28px; border-radius: 50%; object-fit: cover; object-position: top;
  flex: 0 0 auto; border: 2px solid var(--surface); box-shadow: var(--shadow-sm);
}
.msg .bubble {
  max-width: 78%; padding: 12px 17px; border-radius: 18px;
  font-size: 15.5px; line-height: 1.55; color: var(--text);
  background: var(--surface); border: 1px solid var(--line);
  border-bottom-left-radius: 6px; overflow-wrap: anywhere;
}
.msg .bubble p + p { margin-top: 8px; }
.msg .bubble ul { margin: 6px 0 2px 18px; }
.msg .bubble li { margin-top: 3px; }
.msg .bubble code {
  font-size: 13.5px; background: rgba(34,34,59,.07); padding: 1px 6px; border-radius: 6px;
}
.msg.user { justify-content: flex-end; }
.msg.user .bubble {
  background: var(--ink); color: var(--cream); border-color: var(--ink);
  border-radius: 18px; border-bottom-right-radius: 6px;
}
.msg .bubble.is-error { background: #f7e8e6; border-color: #e5c5bf; color: #7c3b31; }

/* typing indicator */
.typing { display: inline-flex; gap: 5px; padding: 6px 2px; }
.typing i {
  width: 7px; height: 7px; border-radius: 50%; background: var(--mauve);
  animation: typingBlink 1.2s infinite both;
}
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes typingBlink { 0%, 70%, 100% { opacity: .3; transform: none; } 35% { opacity: 1; transform: translateY(-3px); } }

/* starter suggestions — sit right above the composer */
.chat-starters {
  display: flex; flex-wrap: wrap; gap: 8px;
  max-width: 720px; margin: 0 auto 12px;
}
.chat-starters .chip {
  cursor: pointer; border: 1px solid var(--line-strong); background: var(--surface);
  font-family: var(--font); animation: msgIn .35s var(--ease) backwards;
}
.chat-starters .chip:nth-child(2) { animation-delay: .06s; }
.chat-starters .chip:nth-child(3) { animation-delay: .12s; }

/* composer — pinned to the bottom of the pane */
.composer-bar {
  flex: 0 0 auto; border-top: 1px solid var(--line); background: var(--bg);
  padding: 12px 20px calc(10px + env(safe-area-inset-bottom));
}
.chat-composer { display: flex; align-items: flex-end; gap: 10px; max-width: 720px; margin: 0 auto; }
.chat-composer textarea {
  flex: 1; resize: none; border: 1px solid var(--line-strong); background: var(--surface);
  border-radius: 22px; padding: 11px 18px; font-family: var(--font); font-size: 15.5px;
  line-height: 1.5; color: var(--text); max-height: 130px; outline: none;
  transition: border-color .2s, box-shadow .25s var(--ease);
}
.chat-composer textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(74,78,105,.08); }
.chat-composer textarea::placeholder { color: var(--faint); }
.chat-send {
  flex: 0 0 auto; width: 44px; height: 44px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--ink); color: var(--cream); display: inline-flex; align-items: center; justify-content: center;
  transition: transform .18s var(--ease), opacity .2s, box-shadow .25s var(--ease);
}
.chat-send:hover { transform: translateY(-2px); box-shadow: 0 10px 22px -8px rgba(34,34,59,.5); }
.chat-send:disabled { opacity: .45; cursor: default; transform: none; box-shadow: none; }
.chat-send svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.twin-note { max-width: 720px; margin: 8px auto 0; text-align: center; font-size: 12.5px; color: var(--faint); }
.twin-note a { color: var(--muted); }

/* ---------- Voice ---------- */
#pane-voice { position: relative; align-items: center; justify-content: center; text-align: center; overflow: hidden; }
#pane-voice::before {
  content: ""; position: absolute; top: 8%; left: 50%; transform: translateX(-50%);
  width: min(640px, 90vw); height: min(640px, 90vw); pointer-events: none;
  background: radial-gradient(circle, var(--warm-wash) 0%, rgba(246,227,216,0) 62%);
}
.voice-stage { position: relative; z-index: 1; width: 100%; max-width: 620px; padding: 24px 20px calc(24px + env(safe-area-inset-bottom)); }
.orb-wrap { position: relative; width: 232px; height: 232px; margin: 0 auto; }
.orb {
  position: absolute; inset: 0; margin: auto; width: 184px; height: 184px;
  border-radius: 50%; overflow: hidden; border: 4px solid var(--surface);
  box-shadow: var(--shadow); transition: transform .3s var(--ease);
  animation: orbIdle 5s var(--ease) infinite;
}
@keyframes orbIdle { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.025); } }
.orb img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.ring { position: absolute; inset: 20px; border-radius: 50%; border: 2px solid var(--rose); opacity: 0; pointer-events: none; }

.voice-stage.is-connecting .orb { animation: orbBreathe 1.5s var(--ease) infinite; }
.voice-stage.is-listening .ring { animation: ripple 2.4s var(--ease) infinite; }
.voice-stage.is-listening .ring:nth-child(2) { animation-delay: 1.2s; }
.voice-stage.is-speaking .ring { border-color: var(--slate); animation: ripple 1.2s linear infinite; }
.voice-stage.is-speaking .ring:nth-child(2) { animation-delay: .6s; }
.voice-stage.is-speaking .orb { animation: none; transform: scale(1.05); }
.voice-stage.is-listening .orb { animation: none; }
@keyframes ripple { 0% { transform: scale(.86); opacity: .75; } 100% { transform: scale(1.22); opacity: 0; } }
@keyframes orbBreathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(.95); } }

/* live pill — the "this call is on" signal, same presence vocabulary as .tt-dot */
.voice-live {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 22px;
  padding: 5px 14px; border-radius: var(--radius-pill);
  background: var(--surface); border: 1px solid var(--line-strong);
  font-size: 13px; font-weight: 600; color: var(--muted);
}
.voice-live .live-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--rose);
  animation: livePulse 1.8s var(--ease) infinite;
}
.voice-live .live-time { color: var(--faint); font-variant-numeric: tabular-nums; }
@keyframes livePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(201,173,167,.55); }
  50% { box-shadow: 0 0 0 5px rgba(201,173,167,0); }
}

.voice-status { margin-top: 24px; font-size: 16.5px; color: var(--muted); min-height: 26px; }
.voice-live:not([hidden]) + .voice-status { margin-top: 12px; }
.voice-status.is-error { color: #7c3b31; }
.voice-transcript {
  max-width: 480px; margin: 12px auto 0; min-height: 48px; max-height: 22vh; overflow-y: auto;
  font-size: 14.5px; line-height: 1.6; color: var(--faint); text-align: left;
}
.voice-transcript .vt-line { margin-top: 6px; }
.voice-transcript .vt-line strong { color: var(--muted); font-weight: 600; }
.voice-actions { margin-top: 26px; display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* in-call controls — round mute + hang-up, like every phone call ever */
.call-controls { display: flex; gap: 30px; justify-content: center; }
.call-btn {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  border: 0; background: transparent; padding: 0; cursor: pointer;
  font-family: var(--font); font-size: 12.5px; font-weight: 600; color: var(--muted);
}
.call-btn .cb-ico {
  display: grid; place-items: center; width: 56px; height: 56px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--line-strong); color: var(--text);
  transition: transform .18s var(--ease), background .2s, border-color .2s, color .2s;
}
.call-btn:hover .cb-ico { transform: translateY(-2px); border-color: var(--accent); }
.call-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.call-btn .ico-mic-off { display: none; }
.call-btn.is-muted .cb-ico { background: var(--ink); border-color: var(--ink); color: var(--cream); }
.call-btn.is-muted .ico-mic { display: none; }
.call-btn.is-muted .ico-mic-off { display: block; }
.call-end .cb-ico { background: #a6412f; border-color: #a6412f; color: #fff; }
.call-end .cb-ico svg { fill: currentColor; stroke: none; transform: rotate(135deg); }
.call-end:hover .cb-ico { background: #8e3626; border-color: #8e3626; }
.call-end:hover { color: #8e3626; }

/* muted call: keep the live pill, quiet the listening ripples */
.voice-stage.is-muted .ring { animation: none; opacity: 0; }
.voice-stage.is-muted.is-speaking .ring { animation: ripple 1.2s linear infinite; opacity: 1; }

.voice-note { margin-top: 18px; font-size: 12.5px; color: var(--faint); }
.voice-note a { color: var(--muted); }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .twin-top { gap: 10px; padding: 10px 14px; }
  .tt-back { width: 34px; height: 34px; }
  .tt-name span { display: none; }
  .twin-seg button { padding: 8px 13px; }
  .twin-seg button .seg-label { display: none; }
  .msg .bubble { max-width: 86%; }
  .chat-starters { margin-left: 0; }
  .orb-wrap { width: 196px; height: 196px; }
  .orb { width: 156px; height: 156px; }
}

@media (prefers-reduced-motion: reduce) {
  .voice-stage .ring, .voice-stage .orb, .orb { animation: none !important; }
  .voice-live .live-dot { animation: none; }
  .voice-stage.is-listening .ring, .voice-stage.is-speaking .ring { opacity: .5; transform: none; }
  .typing i { animation: none; opacity: .6; }
  .msg, .chat-starters .chip { animation: none; }
}
