:root {
  --ink: #1f2421;
  --ink-2: #55605a;
  --ink-3: #8b948e;
  --paper: #f6f2e9;
  --card: #ffffff;
  --brand: #1b7a6b;
  --brand-dark: #12604f;
  --brand-soft: #e3f0ec;
  --accent: #c8553d;
  --warn-bg: #fdf0e6;
  --line: rgba(31, 36, 33, 0.12);
  --radius: 16px;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: #e8e3d8;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  color: var(--ink);
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.phone {
  width: 390px;
  height: 780px;
  max-height: calc(100vh - 40px);
  background: var(--paper);
  border-radius: 30px;
  box-shadow: 0 18px 50px rgba(31, 36, 33, 0.22);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.topbar {
  padding: 18px 18px 14px;
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
}

.brand { font-size: 19px; font-weight: 600; letter-spacing: 0.5px; line-height: 1.3; }
.brand span { display: block; font-size: 12px; font-weight: 400; opacity: 0.82; margin-top: 5px; letter-spacing: 0; }

.mode-chip {
  font-size: 11px;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 20px;
  padding: 5px 10px;
  white-space: nowrap;
  flex-shrink: 0;
}

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.welcome {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--line);
  line-height: 1.65;
  font-size: 15px;
}
.welcome h3 { margin: 0 0 8px; font-size: 16px; color: var(--brand-dark); }
.welcome p { margin: 0 0 10px; color: var(--ink-2); }
.welcome .tips { display: flex; flex-wrap: wrap; gap: 7px; }
.welcome .tips button {
  font: inherit;
  font-size: 12.5px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  border: 1px solid rgba(27, 122, 107, 0.2);
  border-radius: 14px;
  padding: 7px 11px;
  cursor: pointer;
}
.welcome .tips button:active { background: #d2e7e0; }

.msg { display: flex; flex-direction: column; max-width: 88%; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.bot { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 12px 14px;
  border-radius: 14px;
  font-size: 16.5px;
  line-height: 1.72;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg.user .bubble {
  background: var(--brand);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.bot .bubble {
  background: var(--card);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}

.understood {
  font-size: 11.5px;
  color: var(--ink-3);
  margin: 0 4px 5px;
  line-height: 1.5;
}
.understood b { color: var(--brand); font-weight: 500; }

.meta { font-size: 10.5px; color: var(--ink-3); margin-top: 5px; padding: 0 4px; }

.cite {
  margin-top: 9px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #fbfaf6;
  width: 100%;
}
.cite-head {
  font-size: 11.5px;
  color: var(--ink-2);
  padding: 8px 12px;
  background: #f1ede2;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
}
.cite-item { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.cite-item:last-child { border-bottom: none; }
.cite-title { font-size: 12.5px; font-weight: 500; color: var(--ink); line-height: 1.45; }
.cite-meta { font-size: 11px; color: var(--brand); margin-top: 3px; }
.cite-snippet { font-size: 11.5px; color: var(--ink-2); line-height: 1.6; margin-top: 6px; }
.cite-foot { display: flex; align-items: center; gap: 8px; margin-top: 7px; }
.cite-foot a { font-size: 11px; color: var(--brand); text-decoration: none; border-bottom: 1px dashed var(--brand); }
.tag-warn {
  font-size: 10px;
  color: #8a4318;
  background: var(--warn-bg);
  border: 1px solid #ecccb0;
  border-radius: 10px;
  padding: 2px 7px;
}

.composer {
  flex-shrink: 0;
  padding: 10px 12px 14px;
  background: var(--paper);
  border-top: 1px solid var(--line);
  display: flex;
  gap: 8px;
  align-items: center;
}

.mic {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--brand);
  color: #fff;
  font-size: 12px;
  line-height: 1.15;
  font-family: inherit;
  cursor: pointer;
  flex-shrink: 0;
}
.mic:active { background: var(--brand-dark); }

#input {
  flex: 1;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 23px;
  padding: 0 16px;
  font-size: 16px;
  font-family: inherit;
  background: var(--card);
  color: var(--ink);
  outline: none;
  min-width: 0;
}
#input:focus { border-color: var(--brand); }

.send {
  height: 44px;
  padding: 0 18px;
  border: none;
  border-radius: 22px;
  background: var(--brand-dark);
  color: #fff;
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
  flex-shrink: 0;
}
.send:disabled { opacity: 0.45; cursor: default; }

.sheet-mask {
  position: absolute;
  inset: 0;
  background: rgba(20, 24, 22, 0.42);
  display: none;
  align-items: flex-end;
  z-index: 20;
}
.sheet-mask.open { display: flex; }

.sheet {
  width: 100%;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 16px 16px 22px;
  max-height: 72%;
  overflow-y: auto;
  animation: rise 0.18s ease-out;
}
@keyframes rise { from { transform: translateY(18px); opacity: 0.6; } to { transform: none; opacity: 1; } }

.sheet h4 { margin: 0 0 4px; font-size: 15px; }
.sheet .hint { font-size: 11.5px; color: var(--ink-3); margin: 0 0 12px; line-height: 1.5; }

.demo-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: #fbfaf6;
  border-radius: 12px;
  padding: 11px 13px;
  margin-bottom: 8px;
  font-family: inherit;
  cursor: pointer;
}
.demo-item:active { background: var(--brand-soft); }
.demo-item .label { font-size: 12px; color: var(--brand); margin-bottom: 4px; }
.demo-item .text { font-size: 14.5px; color: var(--ink); line-height: 1.5; }

.typing { font-size: 13px; color: var(--ink-3); padding-left: 6px; }
.typing i {
  display: inline-block;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--ink-3);
  margin-right: 3px;
  animation: blink 1.1s infinite;
}
.typing i:nth-child(2) { animation-delay: 0.18s; }
.typing i:nth-child(3) { animation-delay: 0.36s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }

/* ============ 录音面板 ============ */
.rec-mask {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(31, 36, 33, 0.55);
  backdrop-filter: blur(3px);
  z-index: 60;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.rec-mask.open { display: flex; }

.rec-panel {
  width: 100%;
  max-width: 300px;
  background: var(--card);
  border-radius: 20px;
  padding: 26px 22px 20px;
  text-align: center;
  box-shadow: 0 18px 40px rgba(20, 30, 26, 0.28);
  animation: recIn 0.22s ease-out;
}
@keyframes recIn {
  from { transform: translateY(12px) scale(0.97); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.rec-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--brand-dark);
  letter-spacing: 0.3px;
}
.rec-sub {
  font-size: 12.5px;
  color: var(--ink-3);
  margin-top: 7px;
  line-height: 1.5;
  min-height: 18px;
}

.rec-wave {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 46px;
  margin: 16px 0 6px;
}
.rec-wave i {
  display: block;
  width: 4px;
  height: 4px;
  border-radius: 2px;
  background: var(--brand);
  opacity: 0.85;
  transition: height 0.08s linear;
}

.rec-time {
  font-size: 12px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  margin-bottom: 18px;
}

.rec-actions { display: flex; gap: 10px; }
.rec-btn {
  flex: 1;
  border: none;
  border-radius: 12px;
  padding: 13px 0;
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.12s, background 0.15s;
}
.rec-btn:active { transform: scale(0.97); }
.rec-btn.ghost {
  background: #f0ece2;
  color: var(--ink-2);
}
.rec-btn.solid {
  background: var(--brand);
  color: #fff;
  font-weight: 600;
}
.rec-btn.solid:hover { background: var(--brand-dark); }

.rec-fallback {
  display: none;
  margin-top: 14px;
  font-size: 12px;
  color: var(--ink-3);
  line-height: 1.6;
}
.rec-fallback a { color: var(--brand); text-decoration: none; border-bottom: 1px dashed var(--brand); }

/* ============ 朗读按钮 ============ */
.speak-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 7px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--brand);
  font-family: inherit;
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.speak-btn:hover { background: var(--brand-soft); border-color: var(--brand); }
.speak-btn.on {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

@media (max-width: 520px) {
  body { padding: 0; }
  .phone { width: 100%; height: 100vh; max-height: none; border-radius: 0; box-shadow: none; }
  .sheet-mask.open { position: fixed; }
  .rec-mask.open { position: fixed; }
}
