:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --line: rgba(20, 24, 40, 0.08);
  --text: #171a22;
  --text-2: #62687a;
  --text-3: #9aa0b0;
  --accent: #ff6a4d;
  --accent-2: #ff9a6b;
  --user: #2f6bff;
  --radius: 18px;
  --shadow-sm: 0 1px 2px rgba(16, 20, 36, 0.04), 0 8px 24px rgba(16, 20, 36, 0.05);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(1000px 600px at 12% -10%, rgba(255, 154, 107, 0.16), transparent 60%),
    radial-gradient(900px 600px at 100% 110%, rgba(47, 107, 255, 0.1), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei',
    'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.6;
}

.app {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 20px;
  height: 100dvh;
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px;
}

/* ------------------------------ 左侧 ------------------------------ */
.side {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 26px 22px 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow-sm);
  min-height: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-2);
}

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.center {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 0;
}

.orb-wrap {
  flex: none;
  width: 100%;
  display: grid;
  place-items: center;
  padding-bottom: 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.orb {
  position: relative;
  width: 168px;
  height: 168px;
  display: grid;
  place-items: center;
  transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

.core {
  position: relative;
  width: 118px;
  height: 118px;
  border-radius: 50%;
  background: linear-gradient(150deg, #dfe3ee, #c9cedd);
  box-shadow: inset 0 -10px 24px rgba(255, 255, 255, 0.7), 0 12px 30px rgba(24, 30, 52, 0.12);
  transition: background 0.4s ease, box-shadow 0.4s ease;
}

.halo {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid rgba(120, 130, 160, 0.22);
  opacity: 0;
  transform: scale(0.86);
}

/* 连接中 */
body[data-state='connecting'] .core {
  background: linear-gradient(150deg, #ffe2d6, #ffc7ae);
}
body[data-state='connecting'] .halo {
  opacity: 1;
  animation: ripple 2.4s ease-out infinite;
}
body[data-state='connecting'] .halo-2 {
  animation-delay: 1.2s;
}

/* 聆听 */
body[data-state='listening'] .core {
  background: linear-gradient(150deg, #d9f3e4, #a9e6c6);
  box-shadow: inset 0 -10px 24px rgba(255, 255, 255, 0.6), 0 14px 36px rgba(34, 160, 108, 0.24);
}
body[data-state='listening'] .halo {
  opacity: 1;
  border-color: rgba(34, 170, 115, 0.3);
  animation: ripple 2.6s ease-out infinite;
}
body[data-state='listening'] .halo-2 {
  animation-delay: 1.3s;
}

/* 播报 */
body[data-state='speaking'] .orb {
  transform: scale(1.04);
}
body[data-state='speaking'] .core {
  background: linear-gradient(150deg, #ffb08c, #ff6a4d 70%);
  box-shadow: inset 0 -12px 26px rgba(255, 255, 255, 0.4), 0 18px 44px rgba(255, 106, 77, 0.36);
  animation: breathe 1.5s ease-in-out infinite;
}
body[data-state='speaking'] .halo {
  opacity: 1;
  border-color: rgba(255, 106, 77, 0.34);
  animation: ripple 1.8s ease-out infinite;
}
body[data-state='speaking'] .halo-2 {
  animation-delay: 0.9s;
}

/* 错误 */
body[data-state='error'] .core {
  background: linear-gradient(150deg, #ffe0e0, #ffb9b9);
  box-shadow: 0 12px 30px rgba(214, 60, 60, 0.22);
}

@keyframes ripple {
  0% {
    transform: scale(0.82);
    opacity: 0.85;
  }
  100% {
    transform: scale(1.5);
    opacity: 0;
  }
}

@keyframes breathe {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

.status-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.status {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.hint {
  max-width: 260px;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-3);
  min-height: 38px;
}

.level {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 28px;
  margin: 4px 0 6px;
}

.level i {
  width: 3px;
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  opacity: 0.35;
  transform: scaleY(0.06);
  transform-origin: center;
  transition: transform 0.08s linear, opacity 0.2s ease;
}

body[data-state='listening'] .level i,
body[data-state='speaking'] .level i {
  opacity: 0.9;
}

.side-foot {
  width: 100%;
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 8px;
}

.field {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
}

.field-label {
  font-size: 12.5px;
  color: var(--text-3);
  white-space: nowrap;
}

.field select {
  flex: 1;
  min-width: 0;
  appearance: none;
  padding: 8px 30px 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fafbff
    url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5L6 8l3.5-3.5' fill='none' stroke='%2362687a' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")
    no-repeat right 10px center;
  font-size: 13px;
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
}

.field select:focus-visible,
.btn:focus-visible,
.text-btn:focus-visible {
  outline: 2px solid rgba(255, 106, 77, 0.5);
  outline-offset: 2px;
}

/* ------------------------------ 右侧 ------------------------------ */
.main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.main-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
}

.main-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
}

.text-btn {
  border: 0;
  background: none;
  padding: 4px 6px;
  font-size: 13px;
  color: var(--text-3);
  cursor: pointer;
  border-radius: 8px;
  font-family: inherit;
}

.text-btn:hover {
  color: var(--text);
  background: rgba(20, 24, 40, 0.05);
}

.transcript {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.transcript::-webkit-scrollbar {
  width: 8px;
}

.transcript::-webkit-scrollbar-thumb {
  background: rgba(20, 24, 40, 0.12);
  border-radius: 8px;
}

.empty {
  margin: auto;
  text-align: center;
  color: var(--text-3);
}

.empty-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-2);
}

.empty-desc {
  font-size: 12.5px;
  margin-top: 4px;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 82%;
  animation: fade-up 0.28s ease both;
}

.msg .who {
  font-size: 12px;
  color: var(--text-3);
  padding: 0 4px;
}

.msg .bubble {
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.65;
  word-break: break-word;
  white-space: pre-wrap;
}

.msg.user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg.user .bubble {
  background: linear-gradient(160deg, #3a76ff, #2f5ff0);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.msg.ai {
  align-self: flex-start;
}

.msg.ai .bubble {
  background: #f4f6fb;
  color: var(--text);
  border-bottom-left-radius: 6px;
}

.msg.done .bubble {
  opacity: 0.98;
}

.msg.live .bubble::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 4px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.45;
  animation: blink 1s steps(2, start) infinite;
  vertical-align: middle;
}

.msg.system {
  align-self: center;
  max-width: 100%;
}

.msg.system .bubble {
  background: transparent;
  color: var(--text-3);
  font-size: 12.5px;
  padding: 2px 8px;
  text-align: center;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes blink {
  to {
    visibility: hidden;
  }
}

.controls {
  display: flex;
  gap: 10px;
  padding: 16px 22px calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(250, 251, 255, 0.7);
}

.btn {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 11px 22px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn.primary {
  color: #fff;
  background: linear-gradient(140deg, var(--accent-2), var(--accent));
  box-shadow: 0 10px 24px rgba(255, 106, 77, 0.3);
}

.btn.ghost {
  background: #fff;
  border-color: var(--line);
  color: var(--text-2);
}

.btn.ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: rgba(20, 24, 40, 0.18);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

/* ------------------------------ Toast ------------------------------ */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 20px);
  max-width: min(560px, calc(100vw - 40px));
  padding: 11px 16px;
  border-radius: 12px;
  background: rgba(23, 26, 34, 0.92);
  color: #fff;
  font-size: 13px;
  line-height: 1.5;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 50;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.error {
  background: rgba(190, 46, 46, 0.95);
}

/* ------------------------------ 移动端 ------------------------------ */
@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 12px;
    padding: 12px;
    height: 100dvh;
  }

  .side {
    padding: 14px 16px;
    gap: 12px;
    border-radius: 20px;
  }

  .brand {
    align-self: stretch;
  }

  .center {
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    gap: 14px;
    padding: 0;
  }

  .orb-wrap {
    width: auto;
    flex: none;
    padding: 0;
  }

  .orb {
    width: 62px;
    height: 62px;
  }

  .core {
    width: 46px;
    height: 46px;
  }

  .status-block {
    align-items: flex-start;
    gap: 2px;
    min-width: 0;
  }

  .status {
    font-size: 15px;
  }

  .hint {
    max-width: none;
    min-height: 0;
    text-align: left;
    font-size: 12px;
    line-height: 1.45;
  }

  .level {
    display: none;
  }

  .side-foot {
    width: 100%;
    padding-top: 12px;
    margin-top: 0;
  }

  .main {
    border-radius: 20px;
  }

  .transcript {
    padding: 16px;
    gap: 12px;
  }

  .msg {
    max-width: 92%;
  }

  .controls {
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  }

  .btn {
    flex: 1;
    padding: 11px 12px;
  }
}
