:root {
  color-scheme: dark;
  --bg: #0f172a;
  --phone: #111827;
  --panel: #1f2937;
  --panel-strong: #273244;
  --text: #f8fafc;
  --muted: #94a3b8;
  --line: rgba(148, 163, 184, .16);
  --user: #1e3a5f;
  --ai: #1f2937;
  --user-border: rgba(96, 165, 250, .24);
  --ai-border: rgba(148, 163, 184, .18);
  --accent: #38bdf8;
  --accent-hover: #7dd3fc;
  --accent-soft: rgba(56, 189, 248, .18);
  --shadow: rgba(2, 6, 23, .28);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background: #0f172a;
  color: var(--text);
  font: 14px/1.48 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .34;
  background: rgba(255, 255, 255, .018);
}

audio {
  display: none;
}

.chat {
  position: relative;
  width: min(560px, calc(100% - 22px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 16px 126px;
  background: var(--phone);
  box-shadow: 0 28px 80px rgba(2, 6, 23, .36);
  overflow: hidden;
}

.turn {
  display: grid;
  gap: 8px;
  margin: 0 0 14px;
}

.message-row {
  display: flex;
  width: 100%;
}

.message-row.caller {
  justify-content: flex-start;
}

.message-row.ai {
  justify-content: flex-end;
}

.bubble {
  border: 1px solid var(--line);
  border-radius: 18px;
  max-width: min(82%, 420px);
  padding: 10px 13px;
  background: var(--panel);
  overflow-wrap: anywhere;
  box-shadow: 0 8px 22px var(--shadow);
  cursor: pointer;
  scroll-margin: 42vh;
  backdrop-filter: blur(14px);
  transition: border-color .18s ease, transform .18s ease, box-shadow .18s ease, background .18s ease;
}

.bubble:hover,
.bubble:focus-visible {
  border-color: rgba(125, 211, 252, .5);
  transform: translateY(-1px);
  outline: none;
}

.bubble.active {
  border-color: rgba(125, 211, 252, .72);
  outline: 1px solid rgba(125, 211, 252, .32);
  outline-offset: 3px;
  animation: activePulse 1.6s ease-in-out infinite;
}

@keyframes activePulse {
  0%, 100% {
    box-shadow: 0 8px 22px var(--shadow), 0 0 0 0 rgba(56, 189, 248, .2);
  }
  50% {
    box-shadow: 0 8px 22px var(--shadow), 0 0 0 10px rgba(56, 189, 248, .07);
  }
}

.bubble.user {
  background: var(--user);
  border-color: var(--user-border);
  border-top-left-radius: 8px;
}

.bubble.assistant {
  background: var(--ai);
  border-color: var(--ai-border);
  border-top-right-radius: 8px;
}

.role {
  margin-bottom: 6px;
  color: #a9b7ca;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .12em;
}

.role span {
  color: var(--muted);
  font-weight: 650;
  text-transform: none;
}

.text {
  color: rgba(248, 250, 252, .96);
  white-space: pre-wrap;
}

.details {
  display: none;
  margin-top: 10px;
  padding-top: 2px;
  color: rgba(248, 250, 252, .9);
}

.bubble.open .details {
  display: block;
}

.latency-list {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  border-top: 1px solid var(--line);
}

.latency-list li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  color: rgba(248, 250, 252, .92);
}

.latency-list span {
  color: var(--muted);
  font-size: 12px;
}

.latency-list strong {
  font-size: 12px;
  white-space: nowrap;
}

.detail-section {
  margin-top: 6px;
}

.detail-section b {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.candidate {
  padding: 6px 0;
  border-top: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
}

.candidate:first-child {
  border-top: 0;
  padding-top: 0;
}

.candidate span {
  display: inline-block;
  min-width: 28px;
  margin-right: 8px;
  color: var(--muted);
  font-weight: 700;
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

.player {
  position: fixed;
  left: 50%;
  bottom: 16px;
  z-index: 10;
  width: min(520px, calc(100% - 34px));
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: 48px 1fr 72px 1fr 48px;
  align-items: center;
  gap: 12px;
  padding: 15px 14px calc(12px + env(safe-area-inset-bottom));
  border: 1px solid rgba(203, 213, 225, .13);
  border-radius: 26px;
  background: rgba(31, 41, 55, .96);
  backdrop-filter: blur(20px);
  box-shadow: 0 18px 52px rgba(2, 6, 23, .48), inset 0 1px 0 rgba(255,255,255,.06);
  overflow: hidden;
}

.player-center {
  display: grid;
  justify-items: center;
}

.player-prev {
  justify-self: start;
}

.player-next {
  justify-self: end;
}

.player-btn,
.play-btn {
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(148, 163, 184, .25);
  background: rgba(255, 255, 255, .07);
  color: var(--text);
  cursor: pointer;
  line-height: 1;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08), 0 8px 20px rgba(0, 0, 0, .22);
  transition: transform .16s ease, border-color .16s ease, background .16s ease;
}

.player-btn:hover,
.play-btn:hover,
.player-btn:focus-visible,
.play-btn:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(125, 211, 252, .5);
  outline: none;
}

.player-btn {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  font-size: 28px;
}

.play-btn {
  width: 62px;
  height: 62px;
  border-radius: 999px;
  background: var(--accent);
  border-color: rgba(125, 211, 252, .55);
  color: #082f49;
  font-size: 20px;
  font-weight: 800;
  box-shadow: 0 14px 32px var(--accent-soft), inset 0 1px 0 rgba(255,255,255,.3);
}

.player-time {
  color: #dbeafe;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 42px;
  text-align: center;
  letter-spacing: .02em;
}

.player-time-current,
.player-time-duration {
  justify-self: center;
}

.empty {
  width: min(720px, calc(100% - 24px));
  margin: 40px auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: var(--muted);
  text-align: center;
}

@media (max-width: 560px) {
  .chat {
    width: 100%;
    padding: 12px 10px 112px;
  }

  .bubble {
    max-width: 90%;
    border-radius: 16px;
  }

  .player {
    bottom: 10px;
    width: calc(100% - 18px);
    grid-template-columns: 40px 1fr 60px 1fr 40px;
    gap: 8px;
    padding: 15px 10px calc(10px + env(safe-area-inset-bottom));
    border-radius: 24px;
  }

  .player-btn {
    width: 38px;
    height: 38px;
  }

  .play-btn {
    width: 52px;
    height: 52px;
  }

  .player-time {
    font-size: 12px;
  }
}
