:root {
  color-scheme: dark;
  --ink: #eef7ff;
  --muted: #91a6bc;
  --bg: #07111f;
  --surface: #0c1a2b;
  --surface-strong: #10243a;
  --line: rgba(174, 208, 235, 0.14);
  --blue: #52a8ff;
  --green: #42e6b4;
  --red: #ff6f7d;
  --amber: #ffc55c;
  --radius: 1.25rem;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  min-width: 20rem;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 85% -10%, rgba(82, 168, 255, 0.18), transparent 34rem),
    radial-gradient(circle at -10% 72%, rgba(66, 230, 180, 0.09), transparent 28rem),
    var(--bg);
  color: var(--ink);
}

button, select { font: inherit; }
button, select, summary { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }

.app-shell { min-height: 100dvh; }

.topbar {
  height: 4.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 78rem;
  margin: auto;
  padding: 0 1rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--ink);
  text-decoration: none;
  font-weight: 760;
  letter-spacing: -0.02em;
}

.brand-mark {
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  border-radius: 0.7rem;
  background: var(--green);
  color: #04130f;
  font-size: 0.9rem;
  font-weight: 900;
}

.topbar-actions { display: flex; align-items: center; gap: 0.7rem; }
.network-status { color: var(--green); font-size: 0.8rem; }
.network-status::before { content: ""; display: inline-block; width: 0.4rem; height: 0.4rem; margin-right: 0.35rem; border-radius: 50%; background: currentColor; vertical-align: 0.08rem; }
.network-status.offline { color: var(--red); }

.workspace {
  width: min(100% - 1rem, 78rem);
  margin: 0 auto;
  padding: 0 0 calc(1rem + env(safe-area-inset-bottom));
  display: grid;
  gap: 0.75rem;
}

.avatar-panel, .conversation-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(12, 26, 43, 0.9);
  box-shadow: 0 1.4rem 4rem rgba(0, 0, 0, 0.22);
  overflow: hidden;
}

.panel-heading {
  min-height: 5rem;
  padding: 1rem 1.1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
}
.panel-heading.compact { min-height: auto; }
.eyebrow { margin: 0 0 0.18rem; color: var(--green); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.11em; text-transform: uppercase; }
h1, h2 { margin: 0; font-size: clamp(1.05rem, 4vw, 1.35rem); line-height: 1.15; letter-spacing: -0.025em; }

.status-pill {
  flex: 0 0 auto;
  padding: 0.45rem 0.68rem;
  border-radius: 999px;
  border: 1px solid rgba(66, 230, 180, 0.24);
  background: rgba(66, 230, 180, 0.08);
  color: var(--green);
  font-size: 0.76rem;
  font-weight: 750;
}
.status-pill[data-tone="busy"] { color: var(--blue); border-color: rgba(82, 168, 255, 0.26); background: rgba(82, 168, 255, 0.08); }
.status-pill[data-tone="recording"] { color: #fff; border-color: var(--red); background: rgba(255, 77, 94, 0.72); }
.status-pill[data-tone="error"] { color: var(--amber); border-color: rgba(255, 197, 92, 0.3); background: rgba(255, 197, 92, 0.08); }

.avatar-stage {
  position: relative;
  height: clamp(18rem, 47dvh, 35rem);
  background: radial-gradient(circle at 50% 30%, #f7fbff 0, #e6eff5 62%, #cddbe5 100%);
  isolation: isolate;
}
.avatar-mount { width: 100%; height: 100%; }
.avatar-mount iframe { width: 100%; height: 100%; display: block; border: 0; }
.avatar-loading, .avatar-fallback {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 0.65rem;
  padding: 2rem;
  text-align: center;
  color: #26394b;
  background: linear-gradient(150deg, rgba(247, 251, 255, 0.97), rgba(225, 238, 247, 0.97));
}
.avatar-loading[hidden], .avatar-fallback[hidden] { display: none; }
.avatar-fallback span { max-width: 19rem; font-size: 0.9rem; color: #526a7d; }
.loading-orbit { width: 2.5rem; height: 2.5rem; border: 0.2rem solid rgba(7, 17, 31, 0.12); border-top-color: #1172c9; border-radius: 50%; animation: spin 0.85s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.avatar-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  padding: 0.85rem;
  border-top: 1px solid var(--line);
}
.avatar-controls label { display: grid; gap: 0.3rem; color: var(--muted); font-size: 0.72rem; }
select { min-height: 2.7rem; padding: 0 0.7rem; border: 1px solid var(--line); border-radius: 0.75rem; background: var(--surface-strong); color: var(--ink); }
.toggle-control, .icon-button { min-height: 2.7rem; align-content: center; }
.toggle-control { display: flex !important; grid-column: span 1; align-items: center; gap: 0.5rem !important; padding: 0 0.7rem; border: 1px solid var(--line); border-radius: 0.75rem; background: var(--surface-strong); color: var(--ink) !important; font-size: 0.85rem !important; }
.toggle-control input { accent-color: var(--green); width: 1.1rem; height: 1.1rem; }

.conversation-panel { display: flex; flex-direction: column; }
.transcript-stack { display: grid; gap: 0.75rem; padding: 0.9rem; }
.language-card { min-height: 7.2rem; padding: 0.95rem; border: 1px solid var(--line); border-radius: 1rem; background: rgba(5, 14, 25, 0.42); }
.translation-card { border-color: rgba(66, 230, 180, 0.22); background: linear-gradient(145deg, rgba(66, 230, 180, 0.07), rgba(5, 14, 25, 0.44)); }
.language-label { display: flex; align-items: center; gap: 0.45rem; color: var(--muted); font-size: 0.75rem; font-weight: 700; }
.language-label span { display: inline-grid; place-items: center; min-width: 1.75rem; height: 1.35rem; padding: 0 0.3rem; border-radius: 0.38rem; background: rgba(82, 168, 255, 0.13); color: var(--blue); font-size: 0.65rem; }
.translation-card .language-label span { color: var(--green); background: rgba(66, 230, 180, 0.1); }
.transcript-text { margin: 0.75rem 0 0; font-size: clamp(1rem, 4.3vw, 1.35rem); line-height: 1.45; overflow-wrap: anywhere; }
.transcript-text.placeholder { color: #708499; font-size: 0.95rem; }
.transcript-text.partial { color: #bfd6e8; }

.notice { margin: 0 0.9rem; padding: 0.75rem 0.85rem; border: 1px solid rgba(255, 197, 92, 0.28); border-radius: 0.8rem; background: rgba(255, 197, 92, 0.08); color: #ffe0a4; font-size: 0.84rem; }

.speech-control { margin-top: auto; display: grid; justify-items: center; gap: 0.7rem; padding: 1rem 1rem 1.2rem; border-top: 1px solid var(--line); }
.mic-button { width: min(100%, 23rem); min-height: 4.5rem; display: flex; align-items: center; justify-content: center; gap: 0.75rem; border: 0; border-radius: 1.15rem; background: var(--green); color: #04130f; font-weight: 850; font-size: 1rem; box-shadow: 0 0.8rem 2.2rem rgba(66, 230, 180, 0.16); cursor: pointer; transition: transform 120ms ease, background 160ms ease; }
.mic-button:active { transform: scale(0.985); }
.mic-button:disabled { opacity: 0.55; cursor: wait; }
.mic-button[aria-pressed="true"] { background: var(--red); color: white; box-shadow: 0 0.8rem 2.2rem rgba(255, 111, 125, 0.18); }
.mic-symbol { width: 1.05rem; height: 1.45rem; border: 0.15rem solid currentColor; border-radius: 0.7rem; position: relative; }
.mic-symbol::before { content: ""; position: absolute; left: 50%; top: 100%; width: 0.95rem; height: 0.55rem; border: 0.15rem solid currentColor; border-top: 0; border-radius: 0 0 0.7rem 0.7rem; transform: translateX(-50%); }
.mic-symbol::after { content: ""; position: absolute; left: 50%; top: calc(100% + 0.48rem); width: 0.15rem; height: 0.38rem; background: currentColor; transform: translateX(-50%); }
.speech-control p { margin: 0; color: var(--muted); font-size: 0.78rem; text-align: center; }
.level-meter { height: 1rem; display: flex; align-items: center; gap: 0.2rem; opacity: 0.25; }
.level-meter i { width: 0.18rem; height: 0.25rem; border-radius: 1rem; background: var(--green); transition: height 80ms linear; }
body[data-recording="true"] .level-meter { opacity: 1; }

.privacy-note { margin: 0 0.9rem 0.9rem; color: var(--muted); font-size: 0.78rem; }
.privacy-note summary { cursor: pointer; }
.privacy-note p { margin: 0.5rem 0 0; line-height: 1.5; }

.quiet-button, .icon-button { border: 1px solid var(--line); border-radius: 0.7rem; background: rgba(255,255,255,0.035); color: var(--ink); min-height: 2.5rem; padding: 0 0.75rem; font-size: 0.8rem; cursor: pointer; }
.avatar-fallback .quiet-button { color: #163752; border-color: rgba(22, 55, 82, 0.24); background: white; }
button:disabled { opacity: 0.45; cursor: default; }
button:focus-visible, select:focus-visible, summary:focus-visible { outline: 0.18rem solid var(--blue); outline-offset: 0.15rem; }

@media (min-width: 52rem) {
  .topbar { height: 5rem; padding-inline: 1.5rem; }
  .workspace { width: min(100% - 3rem, 78rem); grid-template-columns: minmax(24rem, 0.95fr) minmax(25rem, 1.05fr); gap: 1rem; padding-bottom: 1.5rem; }
  .avatar-stage { height: min(62dvh, 38rem); }
  .conversation-panel { min-height: calc(100dvh - 6.5rem); }
  .avatar-controls { grid-template-columns: 1fr 1fr auto auto; align-items: end; }
  .language-card { min-height: 9rem; }
  .speech-control { padding-block: 1.3rem 1.5rem; }
}

@media (max-width: 51.99rem) {
  body { padding-bottom: calc(7.4rem + env(safe-area-inset-bottom)); }
  .speech-control {
    position: fixed;
    z-index: 20;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 0.65rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(174, 208, 235, 0.2);
    background: rgba(7, 17, 31, 0.94);
    box-shadow: 0 -1rem 2.6rem rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(1rem);
  }
  .speech-control .level-meter { position: absolute; top: 0.25rem; }
  .mic-button { min-height: 4.1rem; }
}

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