:root {
  --ink: #11100e;
  --paper: #f4f0e8;
  --paper-muted: #c7c1b6;
  --line: rgba(244, 240, 232, 0.14);
  --acid: #eaff4f;
  --cyan: #6ce5dd;
  --coral: #ff765c;
  --panel: #1a1916;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--ink);
}

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  color: var(--paper);
  background:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    var(--ink);
  background-size: 32px 32px;
  font-family: "DM Sans", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

.app-shell {
  width: min(100%, 760px);
  height: 100dvh;
  min-height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto minmax(180px, 1fr) auto;
  overflow: hidden;
}

.topbar {
  height: 72px;
  padding: max(18px, env(safe-area-inset-top)) 20px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  color: var(--paper);
  text-decoration: none;
  font-family: "Fraunces", Georgia, serif;
  font-size: 25px;
  font-weight: 600;
  line-height: 1;
}

.brand span {
  color: var(--acid);
}

.connection-pill {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--paper-muted);
  background: rgba(17, 16, 14, 0.75);
  font-size: 12px;
  font-weight: 600;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #716d66;
}

.connection-pill[data-state="connecting"] .status-dot {
  background: var(--acid);
  animation: blink 0.9s ease-in-out infinite;
}

.connection-pill[data-state="live"] .status-dot {
  background: var(--cyan);
  box-shadow: 0 0 0 4px rgba(108, 229, 221, 0.12);
}

.connection-pill[data-state="error"] .status-dot {
  background: var(--coral);
}

.conversation-stage {
  padding: 30px 20px 18px;
  border-bottom: 1px solid var(--line);
  position: relative;
  overflow: hidden;
}

.stage-copy {
  position: relative;
  z-index: 2;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--acid);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
}

h1 {
  margin: 0;
  max-width: 590px;
  font-family: "Fraunces", Georgia, serif;
  font-size: clamp(40px, 11vw, 74px);
  line-height: 0.94;
  font-weight: 600;
  letter-spacing: 0;
}

h1 em {
  color: var(--cyan);
  font-weight: inherit;
}

.stage-note {
  max-width: 320px;
  margin: 16px 0 0;
  color: var(--paper-muted);
  font-size: 13px;
  line-height: 1.6;
}

.signal {
  height: 62px;
  margin: 24px -2px 0;
  display: grid;
  grid-template-columns: repeat(21, 1fr);
  align-items: center;
  gap: 4px;
  opacity: 0.45;
  transition: opacity 220ms ease;
}

.signal span {
  width: 100%;
  height: 20px;
  max-height: 52px;
  border-radius: 1px;
  background: var(--paper-muted);
  transform-origin: center;
}

.signal span:nth-child(5n + 1) { height: 8px; }
.signal span:nth-child(5n + 2) { height: 22px; }
.signal span:nth-child(5n + 3) { height: 38px; }
.signal span:nth-child(5n + 4) { height: 28px; }
.signal span:nth-child(5n + 5) { height: 14px; }

.signal.active {
  opacity: 1;
}

.signal.active span {
  background: var(--acid);
  animation: wave 880ms ease-in-out infinite alternate;
  animation-delay: calc(var(--i) * -55ms);
}

.signal.speaking span {
  background: var(--cyan);
}

.active-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 24px;
  color: var(--paper-muted);
  font-size: 12px;
}

.timer {
  color: var(--paper);
  font-variant-numeric: tabular-nums;
}

.transcript-panel {
  min-height: 0;
  padding: 18px 20px 8px;
  display: flex;
  flex-direction: column;
  background: rgba(26, 25, 22, 0.72);
}

.panel-heading {
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-heading h2 {
  margin: 0;
  color: var(--paper-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.text-button {
  padding: 4px 0;
  border: 0;
  color: var(--paper-muted);
  background: none;
  font-size: 12px;
  cursor: pointer;
}

.transcript {
  min-height: 0;
  padding: 8px 0 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #504d47 transparent;
}

.empty-state {
  margin: 20px 0;
  color: #77736c;
  font-size: 13px;
}

.message {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 10px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
  animation: reveal 260ms ease-out both;
}

.message-role {
  padding-top: 2px;
  color: var(--paper-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.message.ai .message-role {
  color: var(--cyan);
}

.message.user .message-role {
  color: var(--acid);
}

.message-text {
  min-width: 0;
  margin: 0;
  color: var(--paper);
  font-size: 15px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.message.streaming .message-text::after {
  content: "";
  display: inline-block;
  width: 5px;
  height: 1em;
  margin-left: 4px;
  vertical-align: -2px;
  background: var(--cyan);
  animation: blink 0.7s steps(1) infinite;
}

.controls {
  min-height: calc(92px + var(--safe-bottom));
  padding: 12px 20px calc(12px + var(--safe-bottom));
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) 64px;
  gap: 12px;
  align-items: center;
  border-top: 1px solid var(--line);
  background: rgba(17, 16, 14, 0.96);
}

.primary-control,
.secondary-control {
  height: 56px;
  border-radius: 5px;
  cursor: pointer;
  transition: transform 150ms ease, background 150ms ease, opacity 150ms ease;
}

.primary-control:active,
.secondary-control:active {
  transform: scale(0.97);
}

.primary-control {
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 11px;
  color: var(--ink);
  background: var(--acid);
  font-size: 15px;
  font-weight: 600;
}

.primary-control:disabled,
.secondary-control:disabled {
  cursor: not-allowed;
  opacity: 0.38;
}

.mic-mark {
  width: 16px;
  height: 21px;
  border: 2px solid currentColor;
  border-radius: 8px;
  position: relative;
}

.mic-mark::after {
  content: "";
  width: 9px;
  height: 5px;
  border-bottom: 2px solid currentColor;
  border-left: 2px solid currentColor;
  border-right: 2px solid currentColor;
  border-radius: 0 0 7px 7px;
  position: absolute;
  left: 50%;
  bottom: -7px;
  transform: translateX(-50%);
}

.secondary-control {
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--paper-muted);
  background: var(--panel);
  font-size: 10px;
}

.secondary-control[aria-pressed="true"] {
  border-color: var(--acid);
  color: var(--acid);
}

.secondary-control.danger:not(:disabled) {
  color: var(--coral);
}

.control-icon {
  font-size: 17px;
  font-weight: 600;
  line-height: 1;
}

.toast {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: calc(104px + var(--safe-bottom));
  width: min(calc(100% - 40px), 520px);
  padding: 12px 14px;
  border-left: 3px solid var(--coral);
  border-radius: 3px;
  color: var(--paper);
  background: #292522;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.34);
  font-size: 13px;
  line-height: 1.5;
  transform: translateX(-50%);
}

@keyframes wave {
  from { transform: scaleY(0.28); }
  to { transform: scaleY(1.08); }
}

@keyframes blink {
  50% { opacity: 0.35; }
}

@keyframes reveal {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (min-width: 620px) {
  body {
    padding: 22px 0;
  }

  .app-shell {
    height: calc(100dvh - 44px);
    min-height: calc(100dvh - 44px);
    max-height: 920px;
    border: 1px solid var(--line);
    box-shadow: 0 30px 100px rgba(0, 0, 0, 0.32);
  }

  .conversation-stage {
    padding: 40px 30px 20px;
  }

  .topbar,
  .transcript-panel,
  .controls {
    padding-left: 30px;
    padding-right: 30px;
  }
}

@media (max-height: 700px) {
  .conversation-stage {
    padding-top: 16px;
  }

  h1 {
    font-size: 38px;
  }

  .signal {
    height: 42px;
    margin-top: 14px;
  }
}

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