* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #faf6f0;
  --card: #ffffff;
  --primary: #c05621;
  --primary-dark: #9c4419;
  --text: #2d2418;
  --text-light: #8a7a66;
  --user-bubble: #c05621;
  --ai-bubble: #f0e8dc;
  --danger: #c53030;
}

html, body {
  height: 100%;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.view {
  display: none;
  flex-direction: column;
  height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
}
.view.active { display: flex; }

/* ---------- 首页 ---------- */
.home-header {
  text-align: center;
  padding: 48px 24px 24px;
}
.home-header h1 {
  font-size: 40px;
  letter-spacing: 4px;
  color: var(--primary);
}
.subtitle {
  margin-top: 10px;
  font-size: 18px;
  color: var(--text-light);
}

.start-buttons {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px 24px;
}
.big-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 22px;
  border: 2px solid var(--primary);
  border-radius: 20px;
  background: var(--card);
  color: var(--primary);
  cursor: pointer;
  transition: transform 0.1s;
}
.big-btn:active { transform: scale(0.97); }
.big-btn.primary {
  background: var(--primary);
  color: #fff;
}
.btn-icon { font-size: 36px; }
.btn-label { font-size: 26px; font-weight: 700; }
.btn-hint { font-size: 15px; opacity: 0.75; }

/* ---------- 书籍栏与章节列表 ---------- */
.book-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 24px 4px;
  background: var(--card);
  border-radius: 16px;
  padding: 12px 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.book-info { display: flex; align-items: center; gap: 8px; min-width: 0; }
.book-title { font-size: 19px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book-author { font-size: 14px; color: var(--text-light); white-space: nowrap; }
.icon-btn { border: none; background: none; font-size: 16px; cursor: pointer; }
.book-actions { display: flex; gap: 8px; }
.book-actions a { text-decoration: none; color: var(--primary); }

.chapter-list-wrap { flex: 1; overflow-y: auto; padding: 12px 24px 32px; }
.chapter-list { display: flex; flex-direction: column; gap: 10px; }
.chapter-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  cursor: pointer;
  transition: transform 0.1s;
}
.chapter-card:active { transform: scale(0.98); }
.chapter-num-badge {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  background: #f3e5d3;
  color: var(--primary);
}
.chapter-card.has-content .chapter-num-badge { background: var(--primary); color: #fff; }
.chapter-card-main { flex: 1; min-width: 0; }
.chapter-card-title { font-size: 19px; font-weight: 700; }
.chapter-card-desc { font-size: 14px; color: var(--text-light); margin-top: 2px; }
.chapter-card-stats { font-size: 13px; color: var(--primary); margin-top: 4px; }
.chapter-card-go { font-size: 20px; color: #d0c2ac; }

/* ---------- 章节详情 ---------- */
.chapter-detail { flex: 1; overflow-y: auto; padding: 8px 20px 32px; }
.chapter-actions { display: flex; gap: 10px; margin-bottom: 8px; }
.big-btn.slim { flex: 1; padding: 14px; flex-direction: row; gap: 8px; border-radius: 14px; }
.big-btn.slim .btn-icon { font-size: 22px; }
.big-btn.slim .btn-label { font-size: 18px; }
.section-title { font-size: 17px; color: var(--text-light); margin: 18px 0 10px; }
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.photo-grid .empty-hint { grid-column: 1 / -1; }
.photo-item { position: relative; }
.photo-item img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 10px;
  border: 3px solid #fff;
  box-shadow: 0 1px 5px rgba(0,0,0,0.15);
}
.photo-item .photo-caption {
  font-size: 12px;
  color: var(--text-light);
  text-align: center;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- 照片提醒条 ---------- */
.photo-hint-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 8px 16px 0;
  background: #fdf3e3;
  border: 1px solid #eed9b8;
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 15px;
  color: #8a5a1e;
}
.photo-hint-bar.hidden { display: none; }
.chip.solid { background: var(--primary); color: #fff; border-color: var(--primary); }

.round-btn.photo { background: #7c6a52; box-shadow: 0 4px 12px rgba(124,106,82,0.35); }
.send-btn.plain { background: var(--card); color: var(--text); border: 2px solid #ddd0c0; }

/* 访谈里的照片气泡 */
.caption.photo, .msg.photo {
  background: #fff;
  padding: 8px;
  border: 1px solid #eadfce;
}
.caption.photo img, .msg.photo img {
  max-width: 200px;
  border-radius: 10px;
  display: block;
}

/* ---------- 轻提示 ---------- */
.toast {
  position: fixed;
  bottom: 120px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(45,36,24,0.9);
  color: #fff;
  font-size: 16px;
  padding: 12px 22px;
  border-radius: 999px;
  z-index: 99;
  transition: opacity 0.3s;
}
.toast.hidden { opacity: 0; pointer-events: none; }

.howto {
  margin: 8px 24px 0;
  background: var(--card);
  border-radius: 16px;
  padding: 16px 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.howto h2 {
  font-size: 18px;
  color: var(--primary);
  margin-bottom: 8px;
}
.howto ol {
  padding-left: 22px;
  font-size: 16px;
  line-height: 1.9;
  color: var(--text);
}
.mictest-link { margin-top: 10px; font-size: 14px; }
.mictest-link a { color: var(--primary); }

.session-list-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 8px 24px 32px;
}
.session-list-wrap h2 {
  font-size: 20px;
  color: var(--text-light);
  margin: 16px 0 12px;
}
.session-item {
  position: relative;
  background: var(--card);
  border-radius: 14px;
  padding: 16px 44px 16px 16px; /* 右侧给删除按钮留位置 */
  margin-bottom: 10px;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.session-item .s-preview { font-size: 18px; margin-bottom: 6px; }
.session-item .s-meta { font-size: 14px; color: var(--text-light); }
.empty-hint {
  text-align: center;
  color: var(--text-light);
  font-size: 16px;
  padding: 24px 0;
}

/* ---------- 对话页通用 ---------- */
.talk-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px;
}
.status-pill {
  flex: 1;
  text-align: center;
  font-size: 17px;
  color: var(--text-light);
  background: var(--card);
  border-radius: 999px;
  padding: 8px 16px;
}
.status-pill.live, #voice-status.live { color: #2f7d32; }

/* 语音状态指示灯 */
.voice-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.orb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #b0a593;
}
.orb.idle { background: #b0a593; }
.orb.speaking {
  background: var(--primary);
  animation: pulse 1s ease-in-out infinite;
}
.orb.listening {
  background: #2f7d32;
  animation: breathe 1.6s ease-in-out infinite;
}
.orb.thinking {
  background: #b0a593;
  animation: blink 0.9s ease-in-out infinite;
}
.orb.paused { background: #b0a593; }
.orb.error { background: var(--danger); }
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.35); opacity: 0.7; }
}
@keyframes breathe {
  0%, 100% { transform: scale(1); opacity: 0.75; }
  50% { transform: scale(1.2); opacity: 1; }
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.voice-hint {
  text-align: center;
  font-size: 15px;
  color: var(--text-light);
  padding: 6px 24px;
}

/* 麦克风音量条 */
.mic-meter-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 24px 0;
}
.mic-meter-label { font-size: 13px; color: var(--text-light); white-space: nowrap; }
.mic-meter {
  flex: 1;
  height: 8px;
  background: #e8ddcb;
  border-radius: 999px;
  overflow: hidden;
}
#mic-level {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #7db87f, #2f7d32);
  border-radius: 999px;
  transition: width 0.08s linear;
}

.control {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.control-label {
  font-size: 14px;
  color: var(--text-light);
}
.small-btn {
  border: 1px solid #ddd0c0;
  background: var(--card);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 15px;
  cursor: pointer;
  white-space: nowrap;
}
.small-btn.danger { border-color: #e5b8b8; color: #c53030; }

/* 列表项右上角的删除小按钮 */
.del-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}
.photo-del { background: rgba(0, 0, 0, 0.45); color: #fff; }
.s-del { top: 10px; right: 10px; background: #f3ece0; color: #8a7a66; }
.del-btn:active { background: #c53030; color: #fff; }

/* ---------- 语音访谈 ---------- */
.captions {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.caption-hint {
  text-align: center;
  color: var(--text-light);
  font-size: 17px;
  margin-top: 40px;
}
.caption {
  max-width: 88%;
  padding: 14px 18px;
  border-radius: 18px;
  font-size: 22px;
  line-height: 1.55;
}
.caption.user {
  align-self: flex-end;
  background: var(--user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.caption.ai {
  align-self: flex-start;
  background: var(--ai-bubble);
  border-bottom-left-radius: 4px;
}
.caption.interim { opacity: 0.75; }
.caption.interim::after, .msg.interim::after {
  content: "▍";
  animation: blink 0.8s ease-in-out infinite;
}

.voice-controls {
  display: flex;
  justify-content: center;
  gap: 32px;
  padding: 20px 0 36px;
}
.round-btn {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 30px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(192,86,33,0.4);
}
.round-btn.muted { background: #a09484; box-shadow: none; }
.round-btn.danger {
  background: var(--danger);
  font-size: 20px;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(197,48,48,0.35);
}

/* ---------- 文字访谈 ---------- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.msg {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 19px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user {
  align-self: flex-end;
  background: var(--user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.ai {
  align-self: flex-start;
  background: var(--ai-bubble);
  border-bottom-left-radius: 4px;
}

.topic-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 16px;
}
.chip {
  border: 1px solid var(--primary);
  color: var(--primary);
  background: var(--card);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 15px;
  white-space: nowrap;
  cursor: pointer;
}

.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom));
}
#chat-input {
  flex: 1;
  min-width: 0;
  font-size: 19px;
  padding: 12px 16px;
  border: 2px solid #ddd0c0;
  border-radius: 14px;
  outline: none;
  background: var(--card);
}
#chat-input:focus { border-color: var(--primary); }
.send-btn {
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 18px;
  padding: 0 20px;
  border-radius: 14px;
  cursor: pointer;
  white-space: nowrap;
}
.send-btn.danger { background: var(--danger); }
