:root {
  --bg: #0f1115;
  --bg-panel: #171a21;
  --bg-bubble-user: #2f6fed;
  --bg-bubble-ai: #232833;
  --text: #e8eaf0;
  --text-dim: #8b93a3;
  --accent: #4d8dff;
  --danger: #ff5c5c;
  --ok: #34d17b;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* 顶栏 */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid #23262e;
  flex-shrink: 0;
}

.title-wrap { display: flex; align-items: center; gap: 8px; min-width: 0; }

#topbar h1 { font-size: 18px; margin: 0; font-weight: 600; }

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-online  { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.dot-offline { background: var(--danger); }
.dot-nosr    { background: #f5a623; }

.status-text { font-size: 12px; color: var(--text-dim); white-space: nowrap; }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  cursor: pointer;
}
.icon-btn:active { background: #262b36; color: var(--text); }

/* 对话区 */
#chat {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.empty-tip {
  margin: auto;
  text-align: center;
  color: var(--text-dim);
  font-size: 16px;
}
.empty-tip .sub { font-size: 13px; opacity: .7; }

.msg-row { display: flex; width: 100%; }
.msg-row.user { justify-content: flex-end; }
.msg-row.ai { justify-content: flex-start; }

.bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 16px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg-row.user .bubble {
  background: var(--bg-bubble-user);
  border-bottom-right-radius: 6px;
}
.msg-row.ai .bubble {
  background: var(--bg-bubble-ai);
  border-bottom-left-radius: 6px;
}
.bubble.interim { opacity: .65; font-style: italic; }

.msg-time {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
  opacity: .8;
}

/* 识别不可用提示 */
.sr-tip {
  margin: 0 16px 8px;
  padding: 10px 14px;
  background: #3a2f16;
  color: #f5c76a;
  border-radius: 12px;
  font-size: 14px;
  text-align: center;
  flex-shrink: 0;
}
.hidden { display: none !important; }

/* 底部控制区 */
#controls {
  flex-shrink: 0;
  padding: 8px 16px calc(12px + var(--safe-bottom));
  background: var(--bg-panel);
  border-top: 1px solid #23262e;
}

.state-label {
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
  min-height: 20px;
  margin-bottom: 6px;
}
.state-label.listening { color: var(--accent); }
.state-label.thinking  { color: #f5a623; }
.state-label.speaking  { color: var(--ok); }

.controls-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.input-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  background: #1e222b;
  border: 1px solid #2a2f3a;
  border-radius: 24px;
  padding-left: 16px;
  min-height: 48px;
}
.input-wrap.highlight {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(77, 141, 255, .25);
}

#text-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 16px;
  min-height: 44px;
  min-width: 0;
}
#text-input::placeholder { color: var(--text-dim); }

.send-btn { color: var(--accent); }

/* 麦克风按钮 */
.mic-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(145deg, #3b7bff, #2f5fd0);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 4px 14px rgba(47, 111, 237, .4);
  transition: transform .12s ease;
}
.mic-btn:active { transform: scale(.94); }
.mic-btn:disabled {
  background: #2a2f3a;
  color: var(--text-dim);
  box-shadow: none;
  cursor: not-allowed;
}

/* 录音中的脉冲动画 */
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(255, 92, 92, .55); }
  70%  { box-shadow: 0 0 0 22px rgba(255, 92, 92, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 92, 92, 0); }
}
.mic-btn.listening {
  background: linear-gradient(145deg, #ff6b6b, #e04848);
  animation: pulse 1.4s ease-out infinite;
}

/* 播放中(说话)的呼吸动画 */
@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 0 rgba(52, 209, 123, .45); }
  50%      { box-shadow: 0 0 0 14px rgba(52, 209, 123, 0); }
}
.mic-btn.speaking {
  background: linear-gradient(145deg, #38c172, #2a9d5c);
  animation: breathe 1.6s ease-in-out infinite;
}

.mic-btn.thinking {
  background: linear-gradient(145deg, #f5a623, #d98c12);
}
