:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --text: #111714;
  --muted: #69736d;
  --line: rgba(17, 23, 20, 0.08);
  --accent: #1ec658;
  --accent-ink: #0e8a3c;
  --accent-soft: rgba(30, 198, 88, 0.12);
  --danger: #d93b40;
  --danger-soft: rgba(217, 59, 64, 0.1);
  --shadow: 0 1px 2px rgba(17, 23, 20, 0.04), 0 8px 24px rgba(17, 23, 20, 0.06);
  --radius: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1110;
    --surface: #171b19;
    --text: #ecf1ee;
    --muted: #95a09a;
    --line: rgba(236, 241, 238, 0.08);
    --accent-ink: #3bdb74;
    --accent-soft: rgba(30, 198, 88, 0.16);
    --danger: #ff6b6f;
    --danger-soft: rgba(255, 107, 111, 0.12);
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}

button { font: inherit; color: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.error { color: var(--danger); font-size: 14px; min-height: 1.5em; margin: 8px 0 0; }

.primary, .secondary {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 13px 16px;
  font-weight: 600;
}
.primary { background: var(--accent); color: #fff; }
.primary:disabled { opacity: 0.6; }
.secondary { background: var(--surface); border: 1px solid var(--line); }

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
}
.icon-button:hover { background: var(--line); color: var(--text); }

/* 登录 */
.login {
  max-width: 360px;
  margin: 0 auto;
  padding: max(15vh, 48px) 16px 32px;
  text-align: center;
}
.login-icon { border-radius: 18px; box-shadow: var(--shadow); }
.login h1 { font-size: 24px; margin: 20px 0 4px; letter-spacing: 0.02em; }
.login form { margin-top: 24px; display: grid; gap: 12px; }
.login input {
  width: 100%;
  padding: 13px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  outline: none;
}
.login input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* 新朋友：扫码关注但还没有名字 */
.new-friends { display: grid; gap: 8px; margin-top: 8px; }
.friend-card {
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  border: 1px solid var(--line);
}
.friend-card p { margin: 0 0 10px; font-size: 14px; }
.friend-card form { display: flex; gap: 8px; }
.friend-card input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.friend-card button { width: auto; padding: 9px 16px; }

/* 主画面 */
.main {
  max-width: 560px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 16px calc(32px + env(safe-area-inset-bottom));
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.brand img { border-radius: 8px; }

.banner {
  margin: 4px 0 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 14px;
}

.stage {
  display: grid;
  justify-items: center;
  padding: 40px 0 8px;
}

.mic {
  --level: 0;
  position: relative;
  width: 128px;
  height: 128px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 10px 30px rgba(30, 198, 88, 0.35);
  transition: transform 0.2s ease, background-color 0.2s ease;
}
.mic:active { transform: scale(0.96); }
.mic:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 6px; }
.mic-ring {
  position: absolute;
  inset: -14px;
  border-radius: 50%;
  background: var(--accent-soft);
  transform: scale(calc(0.9 + var(--level) * 0.45));
  opacity: 0;
  transition: transform 0.08s linear, opacity 0.3s ease;
  z-index: -1;
}
.mic .stop-icon { display: none; }
.mic[data-state="connecting"] { animation: breathe 1.4s ease-in-out infinite; }
.mic[data-state="listening"] .mic-ring,
.mic[data-state="speaking"] .mic-ring,
.mic[data-state="thinking"] .mic-ring { opacity: 1; }
.mic[data-state="listening"] .mic-icon,
.mic[data-state="speaking"] .mic-icon,
.mic[data-state="thinking"] .mic-icon { display: none; }
.mic[data-state="listening"] .stop-icon,
.mic[data-state="speaking"] .stop-icon,
.mic[data-state="thinking"] .stop-icon { display: block; }
.mic[data-state="thinking"] .mic-ring { animation: pulse 1.2s ease-in-out infinite; }

@keyframes breathe { 50% { transform: scale(0.94); opacity: 0.85; } }
@keyframes pulse { 50% { transform: scale(1.12); } }

@media (prefers-reduced-motion: reduce) {
  .mic, .mic-ring { transition: none; animation: none !important; }
}

.caption { margin: 20px 0 0; color: var(--muted); font-size: 15px; }

.transcript {
  width: 100%;
  margin-top: 12px;
  text-align: center;
}
.transcript p:empty { display: none; }
.transcript p { margin: 4px 0; overflow-wrap: anywhere; }
.ai-line { font-size: 17px; }
.user-line { color: var(--muted); font-size: 14px; }

/* 提醒清单 */
.lists { margin-top: 8px; }
.empty {
  text-align: center;
  color: var(--muted);
  padding: 24px 16px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.group { margin-top: 24px; }
.group h2 { font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 8px 4px; letter-spacing: 0.04em; }
.group .hint { margin: -4px 0 8px 4px; font-size: 12px; }
.cards { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 8px 14px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.card-body { flex: 1; min-width: 0; }
.card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; font-size: 13px; color: var(--muted); }
.card-time { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.chip {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 600;
}
.card-content { margin: 4px 0 0; overflow-wrap: anywhere; }
.card-error { margin: 4px 0 0; font-size: 13px; color: var(--danger); }
.card.sent .card-content { color: var(--muted); }
.badge { font-size: 12px; font-weight: 600; }
.badge.sent { color: var(--accent-ink); }
.badge.failed { color: var(--danger); }
.card .icon-button { flex: none; margin-top: -6px; }

/* 设置 */
.sheet {
  width: min(560px, 100%);
  max-height: 88dvh;
  margin: auto auto 0;
  padding: 8px 16px calc(24px + env(safe-area-inset-bottom));
  border: 0;
  border-radius: 20px 20px 0 0;
  background: var(--bg);
  color: var(--text);
}
@media (min-width: 640px) {
  .sheet { margin: auto; border-radius: 20px; }
}
.sheet::backdrop { background: rgba(0, 0, 0, 0.35); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; height: 52px; }
.sheet-head h2 { font-size: 18px; margin: 0; }
.setting-block {
  margin-top: 12px;
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--line);
}
.setting-block h3 { margin: 0 0 8px; font-size: 14px; color: var(--muted); font-weight: 600; }
.setting-block .secondary { border: 0; padding: 4px; color: var(--danger); background: transparent; }
.status-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; gap: 12px; }
.pill { font-size: 13px; color: var(--muted); text-align: right; }
.pill.ok { color: var(--accent-ink); }
.pill.bad { color: var(--danger); }

.contacts { list-style: none; padding: 0; margin: 0; }
.contacts li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.contacts li:last-child { border-bottom: 0; }
.contacts .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.contacts .tag { font-size: 12px; color: var(--muted); }
.contacts .tag.warn { color: var(--danger); }
.contacts input {
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.link-button { border: 0; background: transparent; color: var(--accent-ink); font-size: 14px; padding: 6px; }
.link-button.danger { color: var(--danger); }
.invite-hint { margin: 0 0 10px; }
.invite-form { display: flex; gap: 8px; }
.invite-form input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.invite-form button { width: auto; padding: 9px 16px; white-space: nowrap; }
.contacts li.invite-qr { display: grid; justify-items: center; gap: 4px; }
.qr-box { display: grid; place-items: center; margin-top: 12px; }
.qr-box img, .qr-img { width: 180px; height: 180px; border-radius: 12px; background: #fff; padding: 8px; }
