/* ========================================================
   心屿 · 具身数字人咨询室
   配色：暖木、米白、鼠尾草绿。整体安静，不喧闹。
   ======================================================== */

:root {
  --ink: #2B2620;
  --ink-2: #6B6156;
  --ink-3: #9C9285;
  --line: #E7DFD2;
  --card: #FFFDF9;
  --brand: #4E7A6B;
  --brand-soft: #E7EFE9;
  --danger: #B4513F;
  --wall-1: #F6EDDF;
  --wall-2: #EADCC8;
  --wood: #C8A57D;
  --wood-d: #AE8A64;
}

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

html, body {
  height: 100%;
  margin: 0;
  background: #F1E8DA;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
  overscroll-behavior: none;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  background: #F7F2E9;
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 40px rgba(90, 72, 48, .1);
}

/* ---------------- 顶栏 ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 8px;
  flex: 0 0 auto;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 9px;
  background: linear-gradient(155deg, #8FB7A4, #4E7A6B);
  display: flex; align-items: center; justify-content: center; gap: 3px;
  box-shadow: 0 4px 10px rgba(78, 122, 107, .25);
}
.brand-mark span { display: block; width: 3.5px; height: 8px; border-radius: 3px; background: #fff; }
.brand-mark span:last-child { height: 13px; }
.brand-text b { display: block; font-size: 15px; letter-spacing: .6px; line-height: 1.2; }
.brand-text i {
  display: block; font-style: normal; font-size: 10.5px; color: var(--ink-3); margin-top: 2px;
}
.top-actions { display: flex; gap: 6px; align-items: center; }
.ghost-btn {
  height: 28px; padding: 0 11px; border-radius: 14px;
  border: 1px solid var(--line); background: rgba(255, 253, 249, .8);
  color: var(--ink-2); font-size: 11.5px; cursor: pointer;
  font-family: inherit;
}
.ghost-btn:active { background: #F0EAE0; }

/* ---------------- 咨询室场景 ---------------- */
.scene {
  position: relative;
  flex: 0 0 auto;
  height: 54vh;
  min-height: 306px;
  max-height: 440px;
  margin: 0 10px;
  border-radius: 22px;
  overflow: hidden;
  background: var(--wall-1);
  box-shadow: inset 0 0 0 1px rgba(140, 115, 85, .12), 0 8px 24px rgba(120, 96, 66, .12);
}

/* 从窗口斜进来的光 */
.scene::before {
  content: "";
  position: absolute; left: -20%; right: -20%; top: -18%; height: 74%;
  background: linear-gradient(102deg, rgba(255, 240, 206, .5) 0%, rgba(255, 240, 206, .18) 38%, transparent 62%);
  transform: rotate(-6deg);
  z-index: 6; pointer-events: none;
}
/* 暗角，把视线收到中间 */
.scene::after {
  content: "";
  position: absolute; inset: 0; z-index: 7; pointer-events: none;
  box-shadow:
    inset 0 -26px 40px rgba(116, 92, 62, .16),
    inset 0 0 46px rgba(120, 96, 66, .1);
  border-radius: inherit;
}

/* 墙面 */
.wall {
  position: absolute; inset: 0 0 30% 0;
  background:
    radial-gradient(120% 90% at 50% 108%, rgba(255, 240, 214, .9), transparent 62%),
    linear-gradient(178deg, #FBF3E5 0%, var(--wall-1) 42%, var(--wall-2) 100%);
}
.wall::before {
  content: "";
  position: absolute; inset: 0;
  background: repeating-linear-gradient(90deg, rgba(171, 146, 112, .13) 0 1px, transparent 1px 32px);
  opacity: .8;
}
.wall::after {
  content: "";
  position: absolute; left: 0; right: 0; top: 0; height: 26%;
  background: linear-gradient(rgba(140, 112, 78, .1), transparent);
}
.wall-seam {
  position: absolute; left: 0; right: 0; bottom: 30%; height: 6px;
  background: linear-gradient(#E0D0B8, #D3BF9F);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .5) inset;
  z-index: 3;
}

/* 地板 */
.floor {
  position: absolute; left: 0; right: 0; bottom: 0; height: 30%;
  background:
    linear-gradient(rgba(120, 88, 56, .16), transparent 12%),
    linear-gradient(#C9A87F 0%, #D8BA92 34%, #C9A57B 100%);
  z-index: 2;
}
.floor::after {
  content: "";
  position: absolute; inset: 0;
  background: repeating-linear-gradient(88deg, rgba(120, 88, 56, .18) 0 1.5px, transparent 1.5px 30px);
  opacity: .85;
}
.floor-shine {
  position: absolute; left: 50%; bottom: 0; width: 76%; height: 32%;
  transform: translateX(-50%);
  background: radial-gradient(58% 100% at 50% 100%, rgba(255, 246, 228, .6), transparent 74%);
  z-index: 2;
  pointer-events: none;
}

/* 地毯 */
.rug {
  position: absolute; left: 12%; right: 12%; bottom: 1.5%; height: 50px;
  border-radius: 50%;
  background:
    radial-gradient(closest-side, #F0E3CE 0%, #E6D5BB 56%, rgba(208, 186, 156, .5) 100%);
  box-shadow: inset 0 0 0 1px rgba(168, 143, 110, .2), 0 2px 6px rgba(140, 112, 78, .12);
  z-index: 4;
}
.rug::after {
  content: "";
  position: absolute; inset: 10px 26px;
  border-radius: 50%;
  border: 1px dashed rgba(168, 143, 110, .4);
}

/* 挂画 */
.frame {
  position: absolute; left: 10px; top: 16%; width: 54px;
  padding: 3px; border-radius: 3px;
  background: linear-gradient(#B99B77, #A0815F);
  box-shadow: 0 3px 6px rgba(90, 70, 45, .2);
  z-index: 4;
}
.frame-in { border-radius: 1px; overflow: hidden; display: block; background: #FBF3E6; }
.frame-in svg { display: block; width: 100%; height: auto; }

/* 门牌 */
.plaque {
  position: absolute; right: 10px; top: 13px;
  padding: 5px 9px; border-radius: 5px;
  background: linear-gradient(#DCC3A1, #C9A87F);
  box-shadow: 0 2px 5px rgba(90, 70, 45, .18), inset 0 1px 0 rgba(255, 255, 255, .5);
  z-index: 6;
}
.plaque span {
  font-size: 9.5px; letter-spacing: 1.2px; color: #58452F; font-weight: 600;
}

/* 书架 */
.shelf {
  position: absolute; right: 10px; bottom: 26%; width: 46px;
  z-index: 5;
  display: flex; flex-direction: column; gap: 3px;
  padding: 3px 3px 0;
  border-radius: 3px;
  background: linear-gradient(#C9A87F, #B8946D);
  box-shadow: 0 3px 8px rgba(110, 84, 55, .2), inset 0 1px 0 rgba(255, 255, 255, .35);
}
.shelf-row {
  display: flex; align-items: flex-end; gap: 2px;
  height: 25px; padding: 0 3px 2px;
  border-bottom: 3px solid #A9865F;
  background: linear-gradient(rgba(108, 84, 58, .22), rgba(108, 84, 58, .1));
}
.shelf-row i { display: block; width: 4px; border-radius: 1px 1px 0 0; height: 16px; }
.shelf-row i:nth-child(2n) { height: 19px; }
.shelf-row i:nth-child(3n) { height: 13px; }

/* 台灯 */
.lamp {
  position: absolute; left: 12px; bottom: 30%; width: 34px; z-index: 5;
  display: flex; flex-direction: column; align-items: center;
}
.lamp-shade {
  width: 30px; height: 17px; border-radius: 15px 15px 3px 3px;
  background: linear-gradient(#F6E3C4, #E3C69C);
  box-shadow: 0 0 22px 6px rgba(255, 214, 150, .55);
}
.lamp-pole { width: 2.5px; height: 44px; background: linear-gradient(#A98C6A, #8E7355); }
.lamp-base { width: 20px; height: 4px; border-radius: 3px; background: #8E7355; }

/* 绿植 */
.plant {
  position: absolute; left: -6px; bottom: 0; width: 74px; height: 112px;
  z-index: 7; pointer-events: none;
}

/* 光龛（数字人容器） */
.alcove {
  position: absolute; left: 50%; bottom: 12%;
  transform: translateX(-50%);
  width: 55%; height: 76%;
  border-radius: 50% 50% 6px 6px / 28% 28% 6px 6px;
  overflow: hidden;
  background: radial-gradient(120% 92% at 50% 26%, #FFFAF0 0%, #F5EBDB 56%, #E9DAC5 100%);
  box-shadow:
    0 0 0 1px rgba(178, 152, 118, .26),
    0 0 0 6px rgba(255, 250, 240, .55),
    0 10px 24px rgba(128, 104, 74, .18),
    inset 0 18px 36px rgba(255, 240, 214, .75);
  z-index: 5;
}
.alcove-glow {
  position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background:
    radial-gradient(70% 50% at 50% 0%, rgba(255, 236, 200, .85), transparent 70%),
    radial-gradient(90% 60% at 50% 110%, rgba(196, 170, 136, .35), transparent 70%);
}
#avatar { position: absolute; inset: 0; z-index: 2; }
#avatar canvas, #avatar video { display: block; width: 100% !important; height: 100% !important; }

.alcove-loading {
  position: absolute; inset: 0; z-index: 3;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; background: rgba(250, 243, 232, .92);
  transition: opacity .5s ease;
}
.alcove-loading.done { opacity: 0; pointer-events: none; }
.alcove-loading span { font-size: 11.5px; color: var(--ink-2); }
.orbit { display: flex; gap: 5px; align-items: flex-end; height: 18px; }
.orbit i {
  display: block; width: 4px; border-radius: 3px; background: var(--brand);
  animation: bob 1.1s ease-in-out infinite;
}
.orbit i:nth-child(1) { height: 8px; animation-delay: 0s; }
.orbit i:nth-child(2) { height: 14px; animation-delay: .15s; }
.orbit i:nth-child(3) { height: 10px; animation-delay: .3s; }
@keyframes bob { 0%, 100% { transform: scaleY(.5); opacity: .5; } 50% { transform: scaleY(1); opacity: 1; } }
.bar { width: 76px; height: 3px; border-radius: 3px; background: rgba(160, 140, 110, .22); overflow: hidden; }
.bar em { display: block; height: 100%; width: 0%; background: var(--brand); transition: width .3s ease; }

/* 状态胶囊 */
.status-pill {
  position: absolute; left: 10px; top: 10px; z-index: 8;
  display: flex; align-items: center; gap: 5px;
  padding: 4px 9px; border-radius: 20px;
  background: rgba(255, 252, 245, .86);
  box-shadow: 0 1px 4px rgba(120, 96, 66, .12);
  font-size: 10.5px; color: var(--ink-2);
  backdrop-filter: blur(4px);
}
.status-pill em {
  display: block; width: 5px; height: 5px; border-radius: 50%; background: #C3B49F;
}
.status-pill.on em { background: #5E9C7E; box-shadow: 0 0 0 3px rgba(94, 156, 126, .18); }
.status-pill.busy em { background: #C99A5B; box-shadow: 0 0 0 3px rgba(201, 154, 91, .18); }

/* 字幕 */
.subtitle {
  position: absolute; left: 10px; right: 10px; bottom: 9px; z-index: 9;
  padding: 7px 11px; border-radius: 11px;
  background: rgba(40, 34, 26, .74);
  color: #FDF7EC; font-size: 12.5px; line-height: 1.55;
  max-height: 3.3em; overflow: hidden;
  opacity: 0; transform: translateY(4px);
  transition: opacity .22s ease, transform .22s ease;
  backdrop-filter: blur(6px);
}
.subtitle.show { opacity: 1; transform: translateY(0); }

/* ---------------- 对话区 ---------------- */
.chat {
  flex: 1 1 auto;
  min-height: 90px;
  overflow-y: auto;
  padding: 12px 16px 4px;
  scroll-behavior: smooth;
}
.msg { display: flex; margin-bottom: 10px; }
.msg.me { justify-content: flex-end; }
.bubble {
  max-width: 84%;
  padding: 9px 13px;
  border-radius: 4px 14px 14px 14px;
  background: var(--card);
  border: 1px solid rgba(231, 223, 210, .9);
  font-size: 14px;
  line-height: 1.62;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 1px 2px rgba(120, 96, 66, .05);
}
.msg.me .bubble {
  border-radius: 14px 4px 14px 14px;
  background: linear-gradient(160deg, #5C8878, #4E7A6B);
  border-color: transparent;
  color: #fff;
}
.bubble.typing { color: var(--ink-3); letter-spacing: 3px; }
.bubble.err { background: #FCEEEA; border-color: #F1D6CE; color: #8C4132; }

.crisis {
  margin: 2px 0 12px;
  padding: 13px 14px;
  border: 1px solid #EFCFC6;
  border-radius: 14px;
  background: #FDF4F1;
}
.crisis b { display: block; font-size: 13.5px; color: #A34534; margin-bottom: 5px; }
.crisis p { margin: 0 0 10px; font-size: 12px; color: #7C4B41; line-height: 1.66; }
.crisis-row { display: flex; gap: 7px; }
.crisis-row a {
  flex: 1; text-align: center; padding: 8px 0; border-radius: 18px;
  border: 1px solid #E4B8AD; color: #A34534; font-size: 12.5px; text-decoration: none;
}
.crisis-row a.main { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }

/* ---------------- 输入区 ---------------- */
.composer {
  flex: 0 0 auto;
  padding: 8px 14px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid #EDE5D8;
  background: #FFFDF9;
}
.chips { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button {
  flex: 0 0 auto; padding: 6px 12px; border-radius: 16px;
  border: 1px solid var(--line); background: #FAF6EF;
  font-size: 12px; color: var(--ink-2); cursor: pointer;
  font-family: inherit; white-space: nowrap;
}
.chips button:active { background: var(--brand-soft); }

.input-row { display: flex; gap: 7px; align-items: flex-end; }
.input-row textarea {
  flex: 1; resize: none; max-height: 88px; min-height: 42px;
  padding: 11px 13px; border-radius: 13px; border: 1px solid transparent;
  /* 16px 是 iOS Safari 的分水岭：小于 16px 聚焦时会强制放大页面，
     之前靠禁止缩放绕过去，代价是视力不好的人没法放大看。 */
  background: #F5F1E8; font-size: 16px; line-height: 1.4;
  font-family: inherit; color: var(--ink); outline: none;
}
.input-row textarea:focus { border-color: rgba(78, 122, 107, .35); background: #FBF8F1; }
.input-row textarea::placeholder { color: #B6AC9D; }

.mic, .send {
  height: 42px; border: none; border-radius: 13px; cursor: pointer;
  font-family: inherit; display: flex; align-items: center; justify-content: center;
}
.mic {
  width: 42px; background: #F1ECE1; color: #7A7166;
  transition: background .18s ease, color .18s ease, transform .18s ease;
}
.mic svg { width: 21px; height: 21px; }
.mic.on {
  background: var(--danger); color: #fff; transform: scale(1.04);
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(180, 81, 63, .35); }
  50% { box-shadow: 0 0 0 7px rgba(180, 81, 63, 0); }
}
.send {
  min-width: 56px; padding: 0 15px; background: #EFEAE0; color: #A8A092;
  font-size: 13.5px; font-weight: 600;
}
.send.on { background: var(--ink); color: #fff; }
.tip { margin: 7px 0 0; font-size: 10.5px; color: #B4AA9B; text-align: center; line-height: 1.5; }

/* ---------------- 遮罩 / 面板 ---------------- */
.veil {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(120% 90% at 50% 18%, #FBF3E5 0%, #F0E3D0 58%, #E4D4BC 100%);
  transition: opacity .45s ease, visibility .45s ease;
}
.veil.hide { opacity: 0; visibility: hidden; }
.veil-inner { width: 84%; max-width: 340px; text-align: center; }
.veil-orb {
  width: 84px; height: 84px; margin: 0 auto 20px;
  border-radius: 50%;
  background: linear-gradient(160deg, #A6C7B4, #4E7A6B);
  display: flex; align-items: center; justify-content: center; gap: 7px;
  box-shadow: 0 14px 34px rgba(78, 122, 107, .28);
  animation: breathe 4.4s ease-in-out infinite;
}
.veil-orb span { display: block; width: 6px; height: 20px; border-radius: 4px; background: #fff; opacity: .92; }
.veil-orb span:last-child { height: 13px; }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }
.veil h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: 2px; font-weight: 600; }
.veil-sub { margin: 0 0 16px; font-size: 11.5px; color: var(--ink-3); letter-spacing: 1px; }
.veil-desc { margin: 0 0 22px; font-size: 13px; color: var(--ink-2); line-height: 1.9; }
.enter {
  width: 100%; height: 48px; border: none; border-radius: 24px;
  background: var(--ink); color: #fff; font-size: 15px; font-weight: 600;
  font-family: inherit; cursor: pointer; letter-spacing: 1px;
  box-shadow: 0 10px 22px rgba(43, 38, 32, .2);
}
.veil-note { margin: 16px 0 0; font-size: 10.5px; color: #A79C8C; line-height: 1.8; }

/* ---------------- 口令门 ---------------- */
.lock {
  position: fixed; inset: 0; z-index: 80;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(120% 90% at 50% 18%, #FBF3E5 0%, #F0E3D0 58%, #E4D4BC 100%);
  transition: opacity .35s ease, visibility .35s ease;
}
.lock.hide { opacity: 0; visibility: hidden; pointer-events: none; }
.lock-inner { width: 84%; max-width: 320px; text-align: center; }
.lock-orb {
  width: 60px; height: 60px; margin: 0 auto 18px;
  border-radius: 18px;
  background: linear-gradient(160deg, #A6C7B4, #4E7A6B);
  display: flex; align-items: center; justify-content: center; gap: 5px;
  box-shadow: 0 12px 26px rgba(78, 122, 107, .26);
}
.lock-orb span { display: block; width: 5px; height: 15px; border-radius: 3px; background: #fff; opacity: .92; }
.lock-orb span:last-child { height: 10px; }
.lock-brand {
  margin: 0 0 10px; font-size: 10.5px; letter-spacing: 2px;
  color: #A2907A; text-transform: none;
}
.lock h1 { margin: 0 0 10px; font-size: 18px; letter-spacing: 1px; font-weight: 600; }
.lock-desc { margin: 0 0 20px; font-size: 12.5px; color: var(--ink-2); line-height: 1.9; }
.lock-input {
  width: 100%; height: 46px; padding: 0 16px;
  border-radius: 14px; border: 1px solid #E0D5C4;
  background: rgba(255, 253, 249, .92);
  font-size: 16px; font-family: inherit; color: var(--ink);
  text-align: center; letter-spacing: 3px;
  outline: none; transition: border-color .2s ease, box-shadow .2s ease;
}
.lock-input::placeholder { color: #BDB2A2; letter-spacing: 1px; }
.lock-input:focus { border-color: #A7C3B5; box-shadow: 0 0 0 3px rgba(78, 122, 107, .1); }
.lock-err {
  min-height: 16px; margin: 8px 0 10px;
  font-size: 11.5px; color: var(--danger); line-height: 1.5;
}
.lock .enter { margin-top: 2px; }
.lock .enter:disabled { opacity: .55; }
.lock-note { margin: 16px 0 0; font-size: 10.5px; color: #A79C8C; line-height: 1.8; }

.sheet {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(38, 32, 24, .4);
  display: none; align-items: flex-end; justify-content: center;
  backdrop-filter: blur(2px);
}
.sheet.open { display: flex; }
.sheet-body {
  width: 100%; max-width: 480px;
  max-height: 88vh; overflow-y: auto;
  background: var(--card);
  border-radius: 22px 22px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
}
.sheet-body h3 { margin: 0 0 5px; font-size: 16.5px; }
.sheet-body .sub { margin: 0 0 16px; font-size: 12px; color: var(--ink-3); line-height: 1.6; }
.hot {
  display: block; padding: 12px 14px; margin-bottom: 9px;
  border-radius: 13px; border: 1px solid #EFD9D1;
  background: #FDF6F3; text-decoration: none;
}
.hot b { display: block; font-size: 13.5px; color: #A34534; margin-bottom: 3px; }
.hot span { font-size: 11.5px; color: #8B6459; }
.center-card {
  padding: 13px 14px; margin: 12px 0 16px;
  border-radius: 13px; background: #F5F1E8;
  border: 1px solid #E8DFCE;
}
.center-card b { display: block; font-size: 13.5px; margin-bottom: 6px; }
.center-card p { margin: 0 0 6px; font-size: 12px; color: var(--ink-2); line-height: 1.7; }
.center-card p.muted { color: var(--ink-3); margin-bottom: 0; }
.close {
  width: 100%; height: 46px; border-radius: 23px; border: 1px solid var(--line);
  background: #fff; font-size: 14.5px; color: var(--ink-2);
  font-family: inherit; cursor: pointer;
}
.clear-hist {
  width: 100%; margin-top: 10px; padding: 8px 0;
  border: none; background: none; cursor: pointer;
  font-family: inherit; font-size: 11.5px; color: #B0A596;
  text-decoration: underline; text-underline-offset: 3px;
}

/* 窄屏 / 矮屏适配 */
@media (max-height: 700px) {
  .scene { height: 46vh; min-height: 260px; }
}
@media (max-width: 360px) {
  .alcove { width: 64%; }
  .bubble { font-size: 13.5px; }
}
