:root {
  color-scheme: light;
  --ink: #30261f;
  --ink-soft: #6b5849;
  --paper: #fffaf0;
  --paper-strong: #fffdf8;
  --sage: #58745a;
  --sage-dark: #2f5538;
  --green: #2f7d4f;
  --green-deep: #1f5d3a;
  --red: #b83d2b;
  --red-deep: #8f2f24;
  --line: rgba(74, 53, 37, 0.16);
  --shadow: 0 24px 70px rgba(56, 37, 24, 0.24);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 255, 255, 0.82), transparent 30rem),
    linear-gradient(135deg, #344f52, #87603d 58%, #d9a766);
  color: var(--ink);
  display: grid;
  min-height: 100dvh;
  place-items: start center;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

.phone {
  background:
    linear-gradient(180deg, rgba(39, 30, 24, 0.42), rgba(53, 39, 30, 0.16) 35%, rgba(255, 250, 242, 0.97) 63%),
    url("/static/assets/warm-home-background.png") center / cover no-repeat;
  display: grid;
  grid-template-rows: minmax(315px, 43%) minmax(220px, 1fr) auto;
  height: 100dvh;
  max-height: 940px;
  max-width: 430px;
  min-height: 720px;
  overflow: hidden;
  position: relative;
  width: min(100vw, 430px);
}

.phone::before {
  background:
    linear-gradient(180deg, rgba(30, 21, 17, 0.56), rgba(61, 45, 34, 0.05) 34%, rgba(255, 250, 243, 0.98) 67%),
    radial-gradient(circle at 50% 33%, rgba(255, 255, 255, 0.16), transparent 15rem);
  content: "";
  inset: 0;
  pointer-events: none;
  position: absolute;
  z-index: 0;
}

.phone > * {
  position: relative;
  z-index: 1;
}

.call-hero {
  color: #fffaf4;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  padding: max(18px, env(safe-area-inset-top)) 18px 12px;
  text-shadow: 0 1px 16px rgba(25, 18, 12, 0.5);
}

.call-top {
  display: grid;
  gap: 12px;
}

.brand-row {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  min-height: 36px;
}

.brand {
  font-size: 19px;
  font-weight: 780;
  letter-spacing: 0;
}

.status-pill {
  align-items: center;
  backdrop-filter: blur(18px);
  background: rgba(255, 253, 247, 0.24);
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 999px;
  display: inline-flex;
  font-size: 14px;
  font-weight: 760;
  gap: 7px;
  min-height: 34px;
  padding: 0 12px;
  white-space: nowrap;
}

.status-dot {
  background: #dfeabd;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(223, 234, 189, 0.24);
  height: 9px;
  width: 9px;
}

[data-mode="connecting"] .status-dot,
[data-mode="listening"] .status-dot,
[data-mode="userSpeaking"] .status-dot,
[data-mode="thinking"] .status-dot,
[data-mode="agentSpeaking"] .status-dot {
  animation: dotPulse 1.6s ease-in-out infinite;
}

[data-mode="error"] .status-dot,
[data-mode="ended"] .status-dot {
  background: #e9c0b6;
  box-shadow: none;
}

.theme-block {
  display: grid;
  gap: 5px;
}

.theme-label {
  color: rgba(255, 250, 242, 0.86);
  font-size: 13px;
  font-weight: 760;
}

.theme-title {
  font-size: clamp(23px, 6.4vw, 30px);
  font-weight: 830;
  line-height: 1.16;
  margin: 0;
  text-wrap: balance;
}

.privacy-note {
  backdrop-filter: blur(18px);
  background: rgba(31, 24, 19, 0.34);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 18px;
  color: rgba(255, 252, 247, 0.94);
  font-size: 14px;
  line-height: 1.43;
  margin: 0;
  padding: 9px 12px;
}

.call-center {
  align-items: center;
  display: grid;
  gap: 12px;
  justify-items: center;
  min-height: 0;
  padding-top: 10px;
  text-align: center;
}

.avatar-shell {
  align-items: center;
  aspect-ratio: 1;
  display: grid;
  justify-items: center;
  max-width: 168px;
  position: relative;
  width: min(42vw, 168px);
}

.avatar-ring {
  border: 1px solid rgba(255, 255, 255, 0.46);
  border-radius: 50%;
  inset: 8px;
  opacity: 0;
  position: absolute;
}

.avatar-ring.second {
  inset: -2px;
}

[data-mode="connecting"] .avatar-ring,
[data-mode="listening"] .avatar-ring,
[data-mode="userSpeaking"] .avatar-ring,
[data-mode="thinking"] .avatar-ring,
[data-mode="agentSpeaking"] .avatar-ring {
  animation: ringPulse 2s ease-out infinite;
}

[data-mode="agentSpeaking"] .avatar-ring.second,
[data-mode="listening"] .avatar-ring.second,
[data-mode="userSpeaking"] .avatar-ring.second {
  animation-delay: 0.45s;
}

.agent-avatar {
  align-items: center;
  background:
    radial-gradient(circle at 35% 26%, rgba(255, 255, 255, 0.96), rgba(255, 241, 201, 0.5) 35%, rgba(73, 111, 83, 0.95) 100%);
  border: 1px solid rgba(255, 255, 255, 0.68);
  border-radius: 50%;
  box-shadow: 0 20px 48px rgba(55, 34, 20, 0.35);
  color: rgba(255, 255, 255, 0.94);
  display: flex;
  font-size: 56px;
  font-weight: 860;
  height: 118px;
  justify-content: center;
  position: relative;
  width: 118px;
  z-index: 1;
}

.call-status {
  display: grid;
  gap: 6px;
  justify-items: center;
}

.agent-status {
  font-size: 24px;
  font-weight: 840;
  line-height: 1.2;
  margin: 0;
  text-wrap: balance;
}

.agent-caption {
  color: rgba(255, 252, 246, 0.9);
  font-size: 15px;
  font-weight: 660;
  line-height: 1.42;
  margin: 0;
  max-width: 310px;
}

.sound-wave {
  align-items: center;
  display: flex;
  gap: 5px;
  height: 22px;
  justify-content: center;
  margin-top: 3px;
}

.sound-wave span {
  animation: wave 1s ease-in-out infinite;
  background: rgba(255, 252, 245, 0.78);
  border-radius: 999px;
  height: 8px;
  width: 5px;
}

.sound-wave span:nth-child(2) {
  animation-delay: 0.1s;
  height: 15px;
}

.sound-wave span:nth-child(3) {
  animation-delay: 0.2s;
  height: 22px;
}

.sound-wave span:nth-child(4) {
  animation-delay: 0.3s;
  height: 15px;
}

.sound-wave span:nth-child(5) {
  animation-delay: 0.4s;
  height: 10px;
}

[data-mode="idle"] .sound-wave span,
[data-mode="ended"] .sound-wave span,
[data-mode="error"] .sound-wave span {
  animation-play-state: paused;
  opacity: 0.7;
  transform: scaleY(0.45);
}

.transcript {
  background: rgba(255, 250, 241, 0.98);
  border-top: 1px solid rgba(99, 72, 48, 0.12);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  padding: 8px 14px 0;
}

.transcript-head {
  align-items: center;
  display: flex;
  justify-content: space-between;
  min-height: 30px;
}

.transcript-title {
  font-size: 17px;
  font-weight: 840;
}

.transcript-state {
  color: var(--green-deep);
  font-size: 14px;
  font-weight: 780;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 0 12px;
  scroll-behavior: smooth;
}

.message {
  align-items: flex-start;
  display: flex;
  gap: 8px;
}

.message.human {
  flex-direction: row-reverse;
}

.avatar {
  align-items: center;
  background: #e6ead4;
  border-radius: 50%;
  color: var(--sage-dark);
  display: flex;
  flex: 0 0 auto;
  font-size: 13px;
  font-weight: 850;
  height: 30px;
  justify-content: center;
  width: 30px;
}

.message.human .avatar {
  background: #f1dfcd;
  color: #7b4c32;
}

.bubble {
  background: #fffdf8;
  border: 1px solid rgba(94, 68, 46, 0.12);
  border-radius: 16px 16px 16px 5px;
  box-shadow: 0 5px 14px rgba(62, 42, 23, 0.07);
  color: var(--ink);
  font-size: 18px;
  line-height: 1.45;
  max-width: min(86%, 320px);
  padding: 8px 10px 9px;
  white-space: normal;
  word-break: break-word;
}

.message.human .bubble {
  background: #eaf2df;
  border-color: rgba(63, 108, 57, 0.12);
  border-radius: 16px 16px 5px 16px;
}

.bubble.live {
  border-color: rgba(47, 125, 79, 0.32);
  box-shadow: 0 0 0 3px rgba(47, 125, 79, 0.08);
}

.meta {
  color: var(--ink-soft);
  display: block;
  font-size: 12px;
  font-weight: 760;
  line-height: 1.2;
  margin-bottom: 4px;
}

.bubble-text {
  white-space: pre-line;
}

.typing {
  animation: caret 0.9s steps(2, start) infinite;
  color: var(--green-deep);
  font-weight: 900;
  margin-left: 2px;
}

.controls {
  background: rgba(255, 250, 241, 0.98);
  border-top: 1px solid rgba(99, 72, 48, 0.12);
  padding: 12px 16px max(16px, env(safe-area-inset-bottom));
}

.idle-controls {
  align-items: center;
  display: grid;
  gap: 10px;
  justify-items: center;
}

.call-button {
  align-items: center;
  background: linear-gradient(180deg, #3f9b62, #2f7d4f);
  border-radius: 999px;
  box-shadow: 0 16px 34px rgba(47, 125, 79, 0.28);
  color: #fffaf4;
  cursor: pointer;
  display: inline-flex;
  font-size: 22px;
  font-weight: 850;
  gap: 10px;
  justify-content: center;
  min-height: 76px;
  min-width: min(100%, 264px);
  outline-offset: 4px;
  padding: 0 26px;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

[data-mode="connecting"] .call-button {
  background: linear-gradient(180deg, #5f8062, #3e6545);
}

.call-button svg {
  height: 30px;
  width: 30px;
}

.start-hint {
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 660;
  line-height: 1.35;
  margin: 0;
  text-align: center;
}

.live-controls {
  align-items: end;
  display: none;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

[data-mode="connecting"] .idle-controls,
[data-mode="listening"] .idle-controls,
[data-mode="userSpeaking"] .idle-controls,
[data-mode="thinking"] .idle-controls,
[data-mode="agentSpeaking"] .idle-controls {
  display: none;
}

[data-mode="connecting"] .live-controls,
[data-mode="listening"] .live-controls,
[data-mode="userSpeaking"] .live-controls,
[data-mode="thinking"] .live-controls,
[data-mode="agentSpeaking"] .live-controls {
  display: grid;
}

.phone-control,
.hangup-button {
  align-items: center;
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  outline-offset: 3px;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
  user-select: none;
}

.phone-control:active,
.hangup-button:active,
.call-button:active {
  transform: translateY(1px) scale(0.99);
}

.phone-control {
  background: #fffdf7;
  border: 1px solid rgba(70, 50, 35, 0.13);
  border-radius: 20px;
  color: var(--ink-soft);
  flex-direction: column;
  font-size: 13px;
  font-weight: 820;
  gap: 4px;
  min-height: 64px;
  padding: 6px 2px;
}

.phone-control svg,
.hangup-button svg {
  height: 21px;
  width: 21px;
}

.phone-control.is-on {
  background: #e4f0df;
  border-color: rgba(47, 125, 79, 0.22);
  color: var(--green-deep);
}

.hangup-button {
  background: linear-gradient(180deg, var(--red), var(--red-deep));
  border-radius: 20px;
  box-shadow: 0 10px 22px rgba(143, 47, 36, 0.22);
  color: #fffaf4;
  flex-direction: column;
  font-size: 13px;
  font-weight: 850;
  gap: 4px;
  min-height: 64px;
  padding: 6px 2px;
}

.modal-backdrop {
  align-items: end;
  background: rgba(25, 18, 12, 0.5);
  display: none;
  inset: 0;
  padding: 18px;
  position: absolute;
  z-index: 8;
}

.modal-backdrop.is-open {
  display: flex;
}

.end-sheet {
  background: #fffaf1;
  border: 1px solid rgba(80, 56, 35, 0.14);
  border-radius: 26px;
  box-shadow: var(--shadow);
  padding: 20px;
  width: 100%;
}

.end-sheet h2 {
  font-size: 22px;
  line-height: 1.25;
  margin: 0 0 8px;
}

.end-sheet p {
  color: var(--ink-soft);
  font-size: 16px;
  line-height: 1.48;
  margin: 0;
}

.sheet-actions {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
  margin-top: 18px;
}

.sheet-actions button {
  border-radius: 16px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 820;
  min-height: 54px;
}

.ghost {
  background: #f2eadc;
  color: var(--ink);
}

.danger {
  background: var(--red);
  color: #fffaf4;
}

.playback-fallback {
  background: var(--sage-dark);
  border-radius: 999px;
  bottom: calc(96px + env(safe-area-inset-bottom));
  box-shadow: 0 14px 32px rgba(31, 85, 56, 0.2);
  color: #fffaf4;
  cursor: pointer;
  display: none;
  font-size: 16px;
  font-weight: 820;
  left: 50%;
  min-height: 52px;
  padding: 0 18px;
  position: absolute;
  transform: translateX(-50%);
  z-index: 7;
}

.playback-fallback.is-visible {
  display: block;
}

#assistantPlayer {
  display: none;
}

@keyframes ringPulse {
  0% {
    opacity: 0.5;
    transform: scale(0.82);
  }

  100% {
    opacity: 0;
    transform: scale(1.18);
  }
}

@keyframes wave {
  0%,
  100% {
    transform: scaleY(0.48);
  }

  50% {
    transform: scaleY(1);
  }
}

@keyframes dotPulse {
  0%,
  100% {
    box-shadow: 0 0 0 4px rgba(223, 234, 189, 0.24);
  }

  50% {
    box-shadow: 0 0 0 7px rgba(223, 234, 189, 0.1);
  }
}

@keyframes caret {
  50% {
    opacity: 0;
  }
}

@media (min-width: 700px) {
  body {
    padding: 24px 0;
  }

  .phone {
    border-radius: 32px;
    box-shadow: var(--shadow);
    height: min(100dvh - 48px, 900px);
    min-height: 760px;
  }
}

@media (max-width: 374px) {
  .phone {
    grid-template-rows: minmax(296px, 41%) minmax(210px, 1fr) auto;
  }

  .call-hero {
    padding-left: 14px;
    padding-right: 14px;
  }

  .theme-title {
    font-size: 23px;
  }

  .privacy-note {
    font-size: 13px;
    padding: 8px 10px;
  }

  .agent-avatar {
    font-size: 48px;
    height: 104px;
    width: 104px;
  }

  .agent-status {
    font-size: 22px;
  }

  .bubble {
    font-size: 17px;
    max-width: min(82%, 286px);
  }

  .controls {
    padding-left: 12px;
    padding-right: 12px;
  }

  .live-controls {
    gap: 8px;
  }

  .phone-control,
  .hangup-button {
    font-size: 12px;
  }
}

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