:root {
  --bg: #071019;
  --bg-deep: #03070c;
  --panel: rgba(8, 14, 22, 0.78);
  --panel-strong: rgba(11, 18, 28, 0.92);
  --line: rgba(183, 218, 255, 0.16);
  --line-strong: rgba(183, 218, 255, 0.28);
  --text: #edf5ff;
  --muted: #97abc4;
  --accent: #a9c8ff;
  --accent-strong: #ff9db4;
  --shadow: 0 30px 80px rgba(0, 0, 0, 0.42);
  --radius-xl: 32px;
  --radius-lg: 24px;
  --radius-md: 18px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  font-family: "Aptos", "Segoe UI Variable Text", "Trebuchet MS", sans-serif;
  background:
    radial-gradient(circle at top, rgba(110, 153, 255, 0.16), transparent 38%),
    radial-gradient(circle at 82% 16%, rgba(255, 157, 180, 0.1), transparent 24%),
    linear-gradient(180deg, #09121d 0%, #04080d 100%);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    linear-gradient(135deg, rgba(4, 8, 13, 0.16), rgba(4, 8, 13, 0.82)),
    url("./assets/aidoru-room-night.jpg") center center / cover no-repeat;
  opacity: 0.22;
  filter: saturate(0.9) blur(2px);
  transform: scale(1.03);
  pointer-events: none;
}

img {
  display: block;
  max-width: 100%;
}

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(380px, 0.85fr) minmax(560px, 1.15fr);
  gap: 1.5rem;
  width: 100%;
  min-height: 100vh;
  padding: 1.25rem 1.5rem;
  margin: 0 auto;
}

.stage-panel,
.chat-frame {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: linear-gradient(180deg, rgba(9, 16, 26, 0.88), rgba(8, 12, 18, 0.94));
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.stage-panel {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  min-height: calc(100vh - 2.5rem);
  padding: 1.3rem;
}

.stage-backdrop,
.stage-noise {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.stage-backdrop {
  background:
    linear-gradient(180deg, rgba(5, 10, 17, 0.08), rgba(5, 10, 17, 0.76)),
    url("./assets/aidoru-room-night.jpg") center center / cover no-repeat;
  opacity: 0.36;
}

.stage-noise {
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 22px 22px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.12), rgba(0, 0, 0, 0.75));
  opacity: 0.28;
}

.stage-copy,
.avatar-stage,
.chat-frame {
  position: relative;
  z-index: 1;
}

.eyebrow {
  margin: 0 0 0.45rem;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.24em;
  text-transform: uppercase;
}

.stage-copy h1,
.chat-intro h2 {
  margin: 0;
  font-family: "Georgia", "Times New Roman", serif;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.stage-copy h1 {
  max-width: 12ch;
  font-size: clamp(2.35rem, 4.8vw, 4.8rem);
  line-height: 0.94;
}

.chat-intro h2 {
  font-size: clamp(1.65rem, 2.5vw, 2.2rem);
  line-height: 1;
}

.lede,
.chat-note {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.lede {
  max-width: 42rem;
  font-size: 1.02rem;
}

.avatar-stage {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: flex-end;
  gap: 1rem;
  min-height: 32rem;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 2.15rem;
  padding: 0.5rem 0.85rem;
  border: 1px solid rgba(169, 200, 255, 0.18);
  border-radius: 999px;
  background: rgba(10, 18, 27, 0.72);
  color: var(--text);
  font-size: 0.88rem;
  line-height: 1.1;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.status-pill[data-mode="speaking"] {
  border-color: rgba(255, 157, 180, 0.32);
  background: rgba(61, 18, 31, 0.62);
  color: #ffd6df;
}

.status-pill[data-mode="thinking"] {
  border-color: rgba(169, 200, 255, 0.34);
  background: rgba(16, 31, 54, 0.76);
}

.status-pill[data-mode="ready"] {
  border-color: rgba(147, 216, 186, 0.28);
  background: rgba(12, 38, 29, 0.72);
  color: #d7ffec;
}

.status-pill[data-mode="error"] {
  border-color: rgba(255, 154, 154, 0.34);
  background: rgba(58, 20, 20, 0.8);
  color: #ffd4d4;
}

.status-pill-muted {
  color: var(--muted);
}

/* Live streaming-latency pill: TTFT (time-to-first-token) + TTFA
   (time-to-first-audio) for the most recent generation. Most discoverable
   place to surface these numbers so the user can see streaming working. */
.status-pill-latency {
  display: inline-flex !important;
  align-items: center;
  gap: 0.5rem;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(135deg, rgba(16, 32, 56, 0.86), rgba(28, 14, 24, 0.86)) !important;
  border-color: rgba(169, 200, 255, 0.42) !important;
  color: #c5d4ea !important;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.status-pill-latency[hidden] {
  display: none !important;
}
.status-pill-latency[data-state="pending"] {
  border-color: rgba(169, 200, 255, 0.22) !important;
  color: var(--muted) !important;
}
.status-pill-latency[data-state="ttft"] {
  border-color: rgba(169, 200, 255, 0.55) !important;
  color: #d8e7ff !important;
  box-shadow: 0 0 0 3px rgba(169, 200, 255, 0.18);
}
.status-pill-latency[data-state="ttfa-good"] {
  border-color: rgba(147, 216, 186, 0.6) !important;
  color: #d7ffec !important;
  box-shadow: 0 0 0 3px rgba(147, 216, 186, 0.18);
}
.status-pill-latency[data-state="ttfa-slow"] {
  border-color: rgba(255, 157, 180, 0.6) !important;
  color: #ffd6df !important;
  box-shadow: 0 0 0 3px rgba(255, 157, 180, 0.18);
}
.status-pill-latency[data-flash="1"] {
  transform: scale(1.04);
}
.latency-cell {
  display: inline-flex;
  align-items: baseline;
  gap: 0.3rem;
}
.latency-key {
  font-size: 0.62rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}
.status-pill-latency[data-state="ttfa-good"] .latency-key,
.status-pill-latency[data-state="ttfa-slow"] .latency-key {
  color: inherit;
  opacity: 0.78;
}
.latency-val {
  font-size: 0.82rem;
  font-weight: 700;
  min-width: 2.4rem;
  text-align: right;
}
.latency-sep {
  color: var(--muted);
  opacity: 0.55;
}

.avatar-scene {
  position: relative;
  display: flex;
  flex: 1;
  align-items: flex-end;
  justify-content: center;
  overflow: hidden;
  min-height: 28rem;
  padding: 0.9rem;
  border: 1px solid rgba(169, 200, 255, 0.12);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(180deg, rgba(6, 11, 17, 0.22), rgba(6, 11, 17, 0.62)),
    radial-gradient(circle at 50% 15%, rgba(169, 200, 255, 0.1), transparent 30%),
    linear-gradient(180deg, rgba(8, 15, 23, 0.32), rgba(5, 8, 13, 0.72));
}

.room-glow {
  position: absolute;
  inset: auto 50% 6% auto;
  width: 52%;
  aspect-ratio: 1 / 0.54;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 244, 219, 0.2), rgba(255, 244, 219, 0));
  filter: blur(18px);
  transform: translateX(50%);
}

.orbit-ring {
  position: absolute;
  border: 1px solid rgba(169, 200, 255, 0.14);
  border-radius: 999px;
  opacity: 0.85;
}

.orbit-ring-large {
  inset: 14% 10% auto 10%;
  height: 62%;
}

.orbit-ring-small {
  inset: 22% 18% auto 18%;
  height: 42%;
  border-color: rgba(255, 157, 180, 0.14);
}

.cubism-frame {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
  pointer-events: none;
}

.avatar-rig {
  --level: 0;
  --mouth-open: 0.08;
  --bob: 0px;
  --drift-x: 0px;
  --drift-y: 0px;
  position: relative;
  width: min(100%, 30rem);
  aspect-ratio: 1 / 1.18;
  transform: translate3d(var(--drift-x), calc(var(--bob) + var(--drift-y)), 0);
  will-change: transform;
}

.avatar-shadow,
.avatar-aura,
.avatar-body,
.avatar-hood,
.avatar-features,
.avatar-mouth,
.avatar-mouth-core,
.avatar-mouth-shine,
.avatar-brows,
.avatar-eyes,
.avatar-blush {
  position: absolute;
}

.avatar-shadow {
  inset: auto 14% 0 14%;
  height: 12%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(0, 0, 0, 0.46), rgba(0, 0, 0, 0));
  filter: blur(16px);
}

.avatar-aura {
  inset: 15% 12% 10% 12%;
  border-radius: 46% 46% 34% 34% / 34% 34% 40% 40%;
  background:
    radial-gradient(circle at 50% 18%, rgba(169, 200, 255, 0.28), rgba(169, 200, 255, 0)),
    radial-gradient(circle at 50% 62%, rgba(255, 157, 180, 0.16), rgba(255, 157, 180, 0));
  filter: blur(24px);
  opacity: calc(0.58 + var(--level) * 0.24);
}

.avatar-body {
  inset: auto 12% 0 12%;
  height: 42%;
  border-radius: 42% 42% 10% 10% / 44% 44% 10% 10%;
  background:
    radial-gradient(circle at 50% 16%, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0)),
    linear-gradient(180deg, #272f3e 0%, #10161f 42%, #090d13 100%);
  border: 1px solid rgba(255, 255, 255, 0.03);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.avatar-body::before,
.avatar-body::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.avatar-body::before {
  inset: 14% 28% auto 28%;
  height: 54%;
  border-radius: 0 0 999px 999px;
  border: 2px solid rgba(209, 226, 255, 0.16);
  border-top: 0;
}

.avatar-body::after {
  inset: 18% auto auto 50%;
  width: 1px;
  height: 22%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0));
  transform: translateX(-50%);
}

.avatar-part {
  position: absolute;
  pointer-events: none;
  user-select: none;
}

.avatar-hair-back {
  inset: 13% 21% auto 21%;
  width: 58%;
  opacity: 0.94;
  filter: drop-shadow(0 18px 26px rgba(0, 0, 0, 0.24));
}

.avatar-hood {
  inset: 18% 23% auto 23%;
  height: 52%;
  border-radius: 45% 45% 38% 38% / 30% 30% 44% 44%;
  background:
    radial-gradient(circle at 50% 30%, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0)),
    linear-gradient(180deg, #bfd7fb 0%, #8ab0e7 52%, #618bc4 100%);
  box-shadow:
    inset 0 -36px 44px rgba(0, 0, 0, 0.14),
    0 28px 42px rgba(0, 0, 0, 0.16);
}

.avatar-hood::before {
  content: "";
  position: absolute;
  inset: 12% 19% 12% 19%;
  border-radius: 50% 50% 44% 44% / 32% 32% 54% 54%;
  background: rgba(7, 12, 19, 0.88);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.avatar-hood::after {
  content: "";
  position: absolute;
  inset: 4% 44% auto 44%;
  width: 12%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(28, 35, 46, 0.92);
  box-shadow:
    -0.7rem 0.35rem 0 0 rgba(28, 35, 46, 0.92),
    0.7rem 0.35rem 0 0 rgba(28, 35, 46, 0.92);
}

.avatar-face {
  inset: 22% 36% auto 36%;
  width: 28%;
  opacity: 0.16;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.12));
}

.avatar-bangs {
  inset: 20% 36% auto 36%;
  width: 28%;
  opacity: 0.38;
  mix-blend-mode: soft-light;
}

.avatar-lock {
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.2));
}

.avatar-lock-left {
  inset: 31% auto auto 29%;
  width: 12%;
  opacity: 0.92;
  transform: rotate(-12deg);
}

.avatar-lock-right {
  inset: 30% 28% auto auto;
  width: 13%;
  opacity: 0.92;
  transform: rotate(11deg);
}

.avatar-features {
  inset: 0;
}

.avatar-features::before,
.avatar-features::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.avatar-features::before {
  inset: 23% 36.6% auto 36.6%;
  aspect-ratio: 0.78;
  border-radius: 44% 44% 40% 40% / 38% 38% 58% 58%;
  background:
    radial-gradient(circle at 50% 22%, rgba(255, 246, 238, 0.86), rgba(255, 246, 238, 0) 18%),
    linear-gradient(180deg, #f7e7d8 0%, #f0ddce 72%, #e4cabd 100%);
  box-shadow:
    inset 0 -14px 18px rgba(168, 118, 100, 0.14),
    0 14px 20px rgba(0, 0, 0, 0.1);
}

.avatar-features::after {
  inset: 48.7% 47.2% auto 47.2%;
  height: 6.2%;
  border-radius: 50% 50% 70% 70%;
  background:
    radial-gradient(circle at 50% 0, rgba(255, 240, 230, 0.84), rgba(255, 240, 230, 0)),
    linear-gradient(180deg, rgba(182, 131, 117, 0.2), rgba(182, 131, 117, 0));
  filter: blur(0.5px);
}

.avatar-brows {
  inset: 33% 38.5% auto 38.5%;
  height: 5%;
}

.avatar-brow {
  position: absolute;
  top: 0;
  width: 24%;
  height: 2px;
  border-radius: 999px;
  background: rgba(90, 78, 104, 0.76);
  transform-origin: center center;
}

.avatar-brow-left {
  left: 16%;
  transform: rotate(-10deg);
}

.avatar-brow-right {
  right: 16%;
  transform: rotate(10deg);
}

.avatar-eyes {
  inset: 37.2% 39.4% auto 39.4%;
  height: 6%;
}

.avatar-eye {
  position: absolute;
  top: 0;
  width: 14%;
  height: 100%;
  border-radius: 999px;
  background:
    radial-gradient(circle at 50% 64%, #0c1520 0 34%, transparent 35%),
    radial-gradient(circle at 50% 52%, #cfe6ff 0 24%, transparent 25%),
    linear-gradient(180deg, #4c6887 0%, #263243 80%);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.08),
    inset 0 -4px 8px rgba(0, 0, 0, 0.22);
  transform-origin: center center;
  transform: scaleY(var(--blink, 1));
}

.avatar-eye-left {
  left: 19%;
}

.avatar-eye-right {
  right: 19%;
}

.avatar-blush {
  top: 45%;
  width: 10%;
  height: 3.6%;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(255, 171, 191, 0.45), rgba(255, 171, 191, 0));
  opacity: calc(0.54 + var(--level) * 0.12);
  filter: blur(3px);
}

.avatar-blush-left {
  left: 39%;
}

.avatar-blush-right {
  right: 39%;
}

.avatar-mouth {
  inset: 50.8% 44.2% auto 44.2%;
  height: 7%;
}

.avatar-mouth-core,
.avatar-mouth-shine {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.avatar-mouth-core {
  bottom: 0;
  width: calc(1.4rem + var(--level) * 0.9rem);
  height: calc(0.42rem + var(--mouth-open) * 0.95rem);
  min-height: 0.42rem;
  border-radius: 999px 999px 70% 70%;
  background:
    radial-gradient(circle at 50% 22%, rgba(255, 196, 211, 0.92), rgba(255, 196, 211, 0) 48%),
    linear-gradient(180deg, #ff9db4 0%, #942840 86%);
  box-shadow:
    inset 0 -2px 7px rgba(77, 10, 29, 0.4),
    0 0 16px rgba(255, 157, 180, calc(0.14 + var(--level) * 0.2));
}

.avatar-mouth-shine {
  top: 20%;
  width: 42%;
  height: 20%;
  border-radius: 999px;
  background: rgba(255, 240, 246, 0.7);
  opacity: calc(0.26 + var(--level) * 0.2);
}

.speech-card {
  padding: 1rem 1.1rem 1.05rem;
  border: 1px solid rgba(169, 200, 255, 0.14);
  border-radius: var(--radius-md);
  background: rgba(10, 16, 24, 0.78);
  backdrop-filter: blur(12px);
}

.speech-label {
  margin-bottom: 0.45rem;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.audio-test-btn {
  display: inline-flex;
  align-items: center;
  padding: 0.3rem 0.7rem;
  border: 1px solid rgba(169, 200, 255, 0.32);
  border-radius: 999px;
  background: rgba(169, 200, 255, 0.08);
  color: var(--accent);
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}

.audio-test-btn:hover {
  background: rgba(169, 200, 255, 0.18);
}

.audio-test-btn:active {
  transform: scale(0.97);
}

.audio-test-btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

.audio-meter {
  margin-top: 0.7rem;
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.audio-meter[hidden] {
  display: none;
}

.audio-meter-track {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: rgba(169, 200, 255, 0.1);
  overflow: hidden;
}

.audio-meter-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #6fb4ff 0%, #ff9db4 100%);
  transition: width 0.08s linear;
}

.audio-meter-label {
  font-size: 0.72rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 4.5rem;
  text-align: right;
}

.speech-line {
  margin: 0;
  color: var(--text);
  font-size: 1rem;
  line-height: 1.58;
  min-height: 3.2rem;
}

.chat-panel {
  display: flex;
}

.chat-frame {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 1rem;
  min-height: calc(100vh - 2.5rem);
  padding: 1.3rem;
}

.chat-intro {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
}

.chat-note {
  max-width: 22rem;
  text-align: right;
  font-size: 0.95rem;
}

llm-chat {
  display: block;
  flex: 1;
  min-height: 42rem;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .stage-panel,
  .chat-frame {
    min-height: auto;
  }

  .stage-copy h1 {
    max-width: 16ch;
  }
}

@media (max-width: 760px) {
  .app-shell {
    gap: 1rem;
    padding: 0.85rem;
  }

  .stage-panel,
  .chat-frame {
    padding: 1rem;
    border-radius: 24px;
  }

  .stage-copy h1 {
    font-size: clamp(2rem, 10vw, 3.1rem);
  }

  .chat-intro {
    flex-direction: column;
    align-items: start;
  }

  .chat-note {
    max-width: none;
    text-align: left;
  }

  .avatar-stage {
    min-height: 24rem;
  }

  .avatar-scene {
    min-height: 22rem;
    padding: 0.8rem;
  }

  llm-chat {
    min-height: 34rem;
  }
}
