:root {
  --bg: #17171d;
  --bg-soft: #1e1e26;
  --bubble-her: #262630;
  --bubble-me: linear-gradient(135deg, #ff8fab, #ff6d8f);
  --text: #ececf1;
  --text-dim: #9a9aa6;
  --accent: #ff7d9c;
  --danger: #ff5a6e;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  overscroll-behavior: none;
}
#app { height: 100dvh; display: flex; flex-direction: column; max-width: 560px; margin: 0 auto; }

/* ---------- header ---------- */
header {
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg-soft); border-bottom: 1px solid #2a2a33;
}
#avatar { width: 42px; height: 42px; border-radius: 50%; }
.head-text { flex: 1; }
.name { font-size: 17px; font-weight: 600; }
.status { font-size: 12px; color: var(--text-dim); display: flex; align-items: center; gap: 5px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: #4cd97b; display: inline-block; }
#voiceToggle {
  background: none; border: 1px solid #33333d; color: var(--text);
  font-size: 18px; border-radius: 10px; padding: 6px 10px; cursor: pointer;
}
#voiceToggle.off { opacity: .4; }

/* ---------- messages ---------- */
#msgs { flex: 1; overflow-y: auto; padding: 14px 14px 6px; scroll-behavior: smooth; }
.row { display: flex; margin: 7px 0; gap: 8px; align-items: flex-end; }
.row.me { justify-content: flex-end; }
.row .ava { width: 34px; height: 34px; border-radius: 50%; flex: none; }
.bubble {
  max-width: 74%; padding: 9px 13px; border-radius: 16px;
  font-size: 15.5px; line-height: 1.55; word-break: break-word; white-space: pre-wrap;
}
.row.her .bubble { background: var(--bubble-her); border-top-left-radius: 5px; }
.row.me .bubble { background: var(--bubble-me); color: #2b0d15; border-top-right-radius: 5px; font-weight: 500; }
.meta { font-size: 11px; color: var(--text-dim); margin: 2px 4px; }
.row.me .meta { text-align: right; }
.voice-chip {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 6px;
  background: #33333d; border-radius: 999px; padding: 4px 12px;
  font-size: 13px; color: var(--text); cursor: pointer; user-select: none;
}
.voice-chip.playing { color: var(--accent); }
.voice-chip .ico { font-size: 14px; }
.divider { text-align: center; font-size: 12px; color: var(--text-dim); margin: 14px 0 8px; }
.divider.miss { color: var(--accent); }
.typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.typing i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--text-dim);
  animation: blink 1.2s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.bubble.err { background: #3a1e24; color: #ffb3bd; }

/* ---------- composer ---------- */
footer {
  background: var(--bg-soft); border-top: 1px solid #2a2a33;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
}
#recBar {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 6px 0 10px; font-size: 13px; color: var(--accent);
}
#recBar.hidden { display: none; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
#recHint { color: var(--text-dim); }
#recHint.cancel { color: var(--danger); }
.bar { display: flex; gap: 8px; align-items: flex-end; }
#micBtn {
  width: 42px; height: 42px; flex: none; border-radius: 50%;
  border: 1px solid #33333d; background: var(--bg); font-size: 19px; cursor: pointer;
  position: relative; touch-action: none; user-select: none;
}
#micBtn.rec { background: var(--danger); border-color: var(--danger); animation: pulse 1.2s infinite; }
#micBtn.cancel-mode { background: #555; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(255,90,110,.45); } 70% { box-shadow: 0 0 0 14px rgba(255,90,110,0); } 100% { box-shadow: 0 0 0 0 rgba(255,90,110,0); } }
#input {
  flex: 1; resize: none; max-height: 120px; border: 1px solid #33333d; border-radius: 18px;
  background: var(--bg); color: var(--text); font-size: 15.5px; padding: 10px 14px;
  outline: none; font-family: inherit; line-height: 1.4;
}
#input:focus { border-color: #4a4a56; }
#sendBtn {
  flex: none; border: none; border-radius: 18px; padding: 10px 16px;
  background: var(--accent); color: #2b0d15; font-size: 15px; font-weight: 600; cursor: pointer;
}
#sendBtn:disabled { opacity: .35; }

/* ---------- gate ---------- */
#gate {
  position: fixed; inset: 0; background: var(--bg); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
#gate.hidden, .hidden { display: none !important; }
.gate-card { text-align: center; max-width: 320px; width: 100%; }
.gate-card img { width: 84px; height: 84px; border-radius: 50%; }
.gate-card h1 { margin: 12px 0 4px; font-size: 22px; }
.gate-card p { color: var(--text-dim); font-size: 13.5px; line-height: 1.6; }
#gateInput {
  width: 100%; margin: 18px 0 10px; padding: 12px 16px; border-radius: 14px;
  border: 1px solid #33333d; background: var(--bg-soft); color: var(--text);
  font-size: 16px; outline: none; text-align: center;
}
#gateBtn {
  width: 100%; padding: 12px; border: none; border-radius: 14px;
  background: var(--accent); color: #2b0d15; font-size: 16px; font-weight: 600; cursor: pointer;
}
#gateErr { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translateX(-50%); background: #000000cc; color: var(--text);
  font-size: 13.5px; padding: 9px 16px; border-radius: 10px; z-index: 60;
  opacity: 0; transition: opacity .25s; pointer-events: none; max-width: 80vw;
}
#toast.show { opacity: 1; }
