/* ============ 水乡老船工 AI 伴游 ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --ink: #2c3a33;
  --ink-light: #5a6b60;
  --paper: rgba(250, 247, 238, 0.94);
  --paper-line: rgba(44, 58, 51, 0.16);
  --red: #b8432f;
  --red-dark: #963526;
  --green: #3f7d4e;
  --green-pale: #e5efe4;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  background: #cfe4dd;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

#scene-container { position: fixed; inset: 0; }
#scene-container canvas { display: block; }

/* ---------- 加载遮罩 ---------- */
#loading-overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, #dcefe6 0%, #bfddd2 60%, #9cc4b8 100%);
  transition: opacity .6s;
}
#loading-overlay.hidden { opacity: 0; pointer-events: none; }
.loading-inner { text-align: center; }
.loading-boat { font-size: 54px; animation: bob 1.6s ease-in-out infinite; }
.loading-text { margin-top: 14px; font-size: 15px; letter-spacing: 2px; color: var(--ink-light); }
@keyframes bob { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-10px) } }

/* ---------- 顶部标题 ---------- */
#top-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 18px 22px 0;
  pointer-events: none;
}
.title-block {
  background: linear-gradient(180deg, rgba(250,247,238,.92), rgba(250,247,238,.78));
  border: 1px solid var(--paper-line);
  border-radius: 14px;
  padding: 12px 20px;
  box-shadow: 0 4px 18px rgba(44, 58, 51, .12);
}
.title-block h1 {
  font-family: "STKaiti", "KaiTi", serif;
  font-size: 24px; font-weight: 700;
  letter-spacing: 3px; color: var(--ink);
}
.title-sep { color: var(--red); }
.slogan { margin-top: 4px; font-size: 12px; letter-spacing: 1px; color: var(--ink-light); }

.top-btns { display: flex; gap: 10px; pointer-events: auto; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid var(--paper-line);
  background: var(--paper);
  font-size: 18px; cursor: pointer;
  box-shadow: 0 3px 10px rgba(44, 58, 51, .15);
  transition: transform .15s, background .15s;
}
.icon-btn:hover { transform: translateY(-2px); background: #fffdf6; }
.icon-btn.muted { opacity: .55; }

/* ---------- 字幕条 ---------- */
#subtitle-bar {
  position: fixed; top: 118px; left: 50%; transform: translateX(-50%);
  z-index: 10;
  display: flex; align-items: center; gap: 12px;
  max-width: min(640px, calc(100vw - 40px));
  background: rgba(44, 58, 51, 0.72);
  color: #f7f3e6;
  border-radius: 22px;
  padding: 9px 20px;
  font-size: 14px; line-height: 1.5;
  backdrop-filter: blur(4px);
  transition: opacity .3s;
}
#subtitle-bar.idle { background: rgba(44, 58, 51, 0.5); }
#subtitle-text {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.eq { display: flex; align-items: flex-end; gap: 3px; height: 16px; flex: none; }
.eq span {
  width: 4px; height: 4px; border-radius: 2px; background: #f2c76e;
  transition: height .12s;
}
#subtitle-bar.speaking .eq span { animation: eqbar .8s ease-in-out infinite; }
#subtitle-bar.speaking .eq span:nth-child(2) { animation-delay: .15s; }
#subtitle-bar.speaking .eq span:nth-child(3) { animation-delay: .3s; }
#subtitle-bar.speaking .eq span:nth-child(4) { animation-delay: .45s; }
@keyframes eqbar { 0%,100% { height: 4px } 50% { height: 15px } }

/* ---------- 聊天面板 ---------- */
#chat-panel {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  z-index: 10;
  width: min(520px, calc(100vw - 24px));
  background: var(--paper);
  border: 1px solid var(--paper-line);
  border-radius: 18px;
  box-shadow: 0 8px 30px rgba(44, 58, 51, .18);
  padding: 14px 16px 12px;
  display: flex; flex-direction: column; gap: 10px;
  max-height: 52vh;
}
#chat-messages {
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px;
  min-height: 40px; max-height: 30vh;
  scrollbar-width: thin;
}
#chat-messages::-webkit-scrollbar { width: 5px; }
#chat-messages::-webkit-scrollbar-thumb { background: rgba(44,58,51,.25); border-radius: 4px; }

.msg { display: flex; }
.msg .bubble {
  max-width: 82%;
  padding: 9px 14px;
  border-radius: 14px;
  font-size: 14px; line-height: 1.65;
  word-break: break-word; white-space: pre-wrap;
}
.msg.user { justify-content: flex-end; }
.msg.user .bubble {
  background: var(--green);
  color: #f7fbf4;
  border-bottom-right-radius: 4px;
}
.msg.bot { justify-content: flex-start; }
.msg.bot .bubble {
  background: #fff;
  border: 1px solid var(--paper-line);
  color: var(--ink);
  border-bottom-left-radius: 4px;
}
.msg .avatar {
  flex: none; width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px; background: #fff; border: 1px solid var(--paper-line);
}
.msg.user .avatar { margin-left: 8px; order: 2; background: var(--green-pale); }
.msg.bot .avatar { margin-right: 8px; }
.msg.bot.speaking .avatar { box-shadow: 0 0 0 3px rgba(242,199,110,.55); }

.bubble .cursor { display: inline-block; width: 2px; height: 15px; background: var(--red); vertical-align: -2px; animation: blink 0.8s infinite; margin-left: 2px; }
@keyframes blink { 0%,100% { opacity: 1 } 50% { opacity: 0 } }

/* 快捷提问 */
#quick-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid rgba(63, 125, 78, .45);
  background: var(--green-pale);
  color: var(--green);
  font-size: 12.5px;
  padding: 5px 12px;
  border-radius: 16px;
  cursor: pointer;
  transition: all .15s;
}
.chip:hover { background: var(--green); color: #fff; }

/* 输入行 */
#input-row { display: flex; gap: 10px; }
#chat-input {
  flex: 1;
  border: 1px solid var(--paper-line);
  border-radius: 22px;
  padding: 10px 18px;
  font-size: 14px;
  outline: none;
  background: #fff;
  color: var(--ink);
  transition: border .15s;
}
#chat-input:focus { border-color: var(--green); }
#btn-send {
  border: none; border-radius: 22px;
  background: var(--red);
  color: #fff;
  font-size: 14px; letter-spacing: 2px;
  padding: 10px 24px;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
#btn-send:hover { background: var(--red-dark); }
#btn-send:active { transform: scale(.96); }
#btn-send:disabled { background: #c9b8ae; cursor: not-allowed; }

.chat-tip { font-size: 11px; color: rgba(44, 58, 51, .55); text-align: center; }

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(30, 40, 35, .4);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal.hidden { display: none; }
.modal-card {
  width: min(430px, 100%);
  background: var(--paper);
  border-radius: 18px;
  box-shadow: 0 12px 40px rgba(0,0,0,.3);
  overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--paper-line);
}
.modal-head h2 { font-size: 17px; letter-spacing: 2px; }
.modal-close { border: none; background: none; font-size: 16px; cursor: pointer; color: var(--ink-light); }
.modal-body { padding: 16px 20px 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-body label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--ink-light); }
.modal-body input, .modal-body select {
  border: 1px solid var(--paper-line);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 14px; outline: none;
  background: #fff; color: var(--ink);
}
.modal-body input:focus, .modal-body select:focus { border-color: var(--green); }
.token-help {
  font-size: 12px; line-height: 1.6;
  color: var(--ink-light);
  background: var(--green-pale);
  border-radius: 10px; padding: 9px 12px;
}
.voice-row { display: flex; gap: 8px; }
.voice-row select { flex: 1; }
.mini-btn {
  border: 1px solid rgba(184, 67, 47, .4);
  background: #fff; color: var(--red);
  border-radius: 10px; padding: 0 14px; font-size: 13px;
  cursor: pointer;
}
.mini-btn:hover { background: #fdf1ee; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.primary-btn {
  border: none; background: var(--red); color: #fff;
  border-radius: 10px; padding: 9px 26px; font-size: 14px;
  letter-spacing: 2px; cursor: pointer;
}
.primary-btn:hover { background: var(--red-dark); }
.ghost-btn {
  border: 1px solid var(--paper-line); background: #fff; color: var(--ink-light);
  border-radius: 10px; padding: 9px 18px; font-size: 14px; cursor: pointer;
}
.save-tip { font-size: 12px; color: var(--green); min-height: 16px; text-align: center; }
.about-body p { font-size: 13.5px; line-height: 1.8; color: var(--ink); }

/* ---------- 微信提示 ---------- */
#wechat-tip {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 60;
  background: #fff8e0; border: 1px solid #e8d9a0;
  color: #8a6d1a; font-size: 13px;
  border-radius: 12px; padding: 8px 16px;
  box-shadow: 0 4px 16px rgba(0,0,0,.15);
}

.hidden { display: none !important; }

/* ---------- 移动端适配 ---------- */
@media (max-width: 640px) {
  #top-bar { padding: 12px 12px 0; }
  .title-block { padding: 10px 14px; }
  .title-block h1 { font-size: 19px; letter-spacing: 2px; }
  .slogan { font-size: 11px; }
  .icon-btn { width: 37px; height: 37px; font-size: 16px; }
  #subtitle-bar { top: 96px; padding: 8px 14px; font-size: 13px; }
  #chat-panel { bottom: 10px; padding: 10px 10px 8px; border-radius: 16px; }
  #chat-messages { max-height: 26vh; }
  .bubble { font-size: 13.5px; }
  #btn-send { padding: 10px 18px; }
  .chat-tip { display: none; }
}

/* 版本角标（排查缓存用） */
#ver-badge { position: fixed; right: 8px; bottom: 8px; z-index: 999; padding: 2px 8px; font-size: 11px; color: rgba(255,255,255,.55); background: rgba(0,0,0,.25); border-radius: 10px; pointer-events: none; }
