:root {
  --ink: #12100f;
  --ink-2: #191615;
  --ink-3: #221d1c;
  --line: #352d2b;
  --text: #e8e0dc;
  --text-dim: #a89e9a;
  --text-faint: #6d6461;
  --rose: #b03a48;
  --rose-deep: #6d1f2b;
  --gold: #b9986a;
  --serif: "Songti SC", "SimSun", "Noto Serif CJK SC", "Source Han Serif SC", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --radius: 10px;
  /* 手机端由 JS 用 visualViewport 写入实时高度：软键盘弹出时整页跟着缩，
     不会把输入框顶到键盘底下。JS 没跑起来就退回视口高度。 */
  --app-h: 100vh;
  /* 顶部海报的高度（手机端 JS / CSS 都会写），收起时另算 */
  --hero-h: clamp(148px, 28vh, 300px);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}

.shell {
  display: grid;
  /* 列轨也必须用 minmax(0, 1fr)：裸写 1fr 等于 minmax(auto, 1fr)，
     最小值是 auto，内容一多就会把轨道撑破。 */
  grid-template-columns: minmax(320px, 40%) minmax(0, 1fr);
  grid-template-rows: var(--app-h);
  height: var(--app-h);
  overflow: hidden;
}

/* 动态视口单位可用时优先用它：地址栏收起/展开时高度更准 */
@supports (height: 100dvh) {
  :root { --app-h: 100dvh; }
}

/* ---------------------------------------------------------------- 舞台 */

.stage {
  position: relative;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: radial-gradient(120% 90% at 50% 18%, #2a1518 0%, #150f10 55%, #0d0b0b 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 2.2vh, 26px);
  padding: clamp(12px, 3vh, 36px) clamp(12px, 3vw, 30px);
}

/* 视频是横的，竖着的舞台栏放不下就会留白；用同一帧放大虚化当底，留白才像“打光”而不是空 */
.stage-bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(18, 16, 15, 0.9) 0%, rgba(18, 16, 15, 0.6) 45%, rgba(18, 16, 15, 0.94) 100%),
    radial-gradient(46% 34% at 50% 44%, rgba(176, 58, 72, 0.22), transparent 72%),
    repeating-linear-gradient(115deg, rgba(255, 255, 255, 0.012) 0 1px, transparent 1px 7px),
    url('/char/phrolova_face_poster.webp') center / cover no-repeat;
  filter: blur(22px) saturate(1.05);
  transform: scale(1.15);
  opacity: 0.75;
}

/* 舞台上的角色换成了循环视频（960×652 的横向特写），
   所以画框也跟着改成横的：宽度吃满栏宽，高度按比例算，矮窗口用 max-height 兜住。 */
.stage-figure {
  position: relative;
  z-index: 1;
  flex: none;
  width: min(100%, 680px);
  max-height: calc(var(--app-h) - 250px);
  aspect-ratio: 960 / 652;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(185, 152, 106, 0.28);
  box-shadow:
    0 0 0 5px rgba(0, 0, 0, 0.22),
    0 24px 60px rgba(0, 0, 0, 0.62),
    0 0 100px rgba(176, 58, 72, 0.14);
  will-change: auto;
}

.stage-figure video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 42%;
  filter: saturate(0.98) contrast(1.02);
  user-select: none;
  pointer-events: none;
  background: #150f10;
}

.stage-veil {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(18, 16, 15, 0.66) 0%, transparent 32%);
  pointer-events: none;
}

/* 画面本身在动，就不用再加浮动动画了（眨眼/镜头呼吸交给视频） */

.nameplate {
  position: relative;
  z-index: 2;
  text-align: center;
}

.nameplate h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(30px, 3.4vw, 44px);
  letter-spacing: 0.22em;
  font-weight: 500;
  text-shadow: 0 2px 24px rgba(0, 0, 0, 0.8);
}

.nameplate p {
  margin: 10px 0 0;
  font-size: 12px;
  letter-spacing: 0.28em;
  color: var(--gold);
  opacity: 0.85;
}

.chips {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.chips li {
  font-size: 11px;
  letter-spacing: 0.12em;
  padding: 3px 9px;
  border: 1px solid rgba(185, 152, 106, 0.35);
  border-radius: 999px;
  color: var(--text-dim);
}

/* ---------------------------------------------------------------- 对话 */

.room {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;      /* grid/flex 子项必须显式归零，否则内容会把整页顶高 */
  overflow: hidden;
  background: var(--ink-2);
}

.room-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(18, 16, 15, 0.6);
  backdrop-filter: blur(8px);
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: background 0.3s;
}
.dot.ok { background: #4c8a5e; box-shadow: 0 0 8px rgba(76, 138, 94, 0.7); }
.dot.warn { background: #b0723a; }

.room-title {
  font-size: 12px;
  letter-spacing: 0.22em;
  color: var(--text-faint);
}

.bar-actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }

/* 背景音乐：工具条上是开关 + 一条细音量；手机上音量挪进设置抽屉 */
.music-vol {
  width: 86px;
  accent-color: var(--rose);
  cursor: pointer;
}

.music-set {
  margin: 18px 0 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--ink);
}
.music-set-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.music-set-head span { font-size: 12px; letter-spacing: 0.06em; color: var(--text-dim); }
.music-set input[type='range'] {
  width: 100%;
  accent-color: var(--rose);
  cursor: pointer;
}

/* 进度条：拖它就能跳，下面跟一行时间 */
.music-seek { margin-top: 12px; accent-color: var(--gold); }

.music-time {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.music-line {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}
.music-line .music-tag {
  flex: none;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}
.music-line input { flex: 1; width: auto; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border-radius: 6px;
  touch-action: manipulation;   /* 手机上别等 300ms */
  transition: background 0.18s, border-color 0.18s, opacity 0.18s;
}

.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-dim);
  padding: 6px 12px;
  font-size: 12px;
}
.ghost:hover:not(:disabled) { background: var(--ink-3); color: var(--text); }
.ghost:disabled { opacity: 0.35; cursor: default; }

.primary {
  background: linear-gradient(180deg, var(--rose) 0%, var(--rose-deep) 100%);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #fff;
  padding: 7px 18px;
  font-size: 13px;
}
.primary:hover { filter: brightness(1.1); }

/* 消息 */

.log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 26px clamp(18px, 4vw, 52px) 18px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.log::-webkit-scrollbar { width: 8px; }
.log::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

.msg { margin: 0 0 22px; max-width: 46em; }

.msg .who {
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--text-faint);
  margin-bottom: 7px;
}

.msg.char .body {
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.95;
  color: #efe7e3;
  padding-left: 14px;
  border-left: 2px solid rgba(176, 58, 72, 0.45);
}

.msg.user { margin-left: auto; }
.msg.user .who { text-align: right; }
.msg.user .body {
  text-align: right;
  font-size: 15px;
  line-height: 1.7;
  color: var(--text-dim);
}

.msg .body p { margin: 0 0 0.9em; }
.msg .body p:last-child { margin-bottom: 0; }

.action {
  font-style: normal;
  color: #9a8f8b;
  font-size: 0.94em;
  letter-spacing: 0.02em;
}

.caret {
  display: inline-block;
  width: 7px;
  height: 1.05em;
  margin-left: 2px;
  vertical-align: -0.15em;
  background: var(--rose);
  animation: blink 1s steps(2) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

.sys-note {
  font-size: 12px;
  color: var(--text-faint);
  text-align: center;
  margin: 18px 0;
  letter-spacing: 0.08em;
}

.sys-note.err { color: #c97676; }

/* 输入 */

.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 14px clamp(18px, 4vw, 52px) max(18px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--ink);
}

.composer textarea {
  flex: 1;
  resize: none;
  min-height: 44px;
  max-height: 160px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--ink-2);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.2s;
}
.composer textarea:focus { border-color: rgba(176, 58, 72, 0.6); }
.composer textarea::placeholder { color: var(--text-faint); }

#btnSend {
  height: 44px;
  padding: 0 20px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--rose) 0%, var(--rose-deep) 100%);
  color: #fff;
  font-size: 14px;
  letter-spacing: 0.1em;
}
#btnSend:disabled { opacity: 0.4; cursor: default; }

/* 设置面板 */

.sheet {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--ink-2);
  color: var(--text);
  padding: 0;
  width: min(520px, calc(100vw - 32px));
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7);
}
.sheet::backdrop { background: rgba(0, 0, 0, 0.66); backdrop-filter: blur(3px); }

.sheet-body { padding: 26px 26px 20px; margin: 0; }

.sheet h2 {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 19px;
  letter-spacing: 0.06em;
}

.hint { font-size: 12.5px; color: var(--text-faint); line-height: 1.7; margin: 0 0 18px; }
.hint.small { margin: 14px 0 0; font-size: 12px; }

.sheet label { display: block; margin-bottom: 14px; }
.sheet label span {
  display: block;
  font-size: 11.5px;
  letter-spacing: 0.12em;
  color: var(--text-faint);
  margin-bottom: 6px;
}

.sheet input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--ink);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  outline: none;
}
.sheet input:focus { border-color: rgba(176, 58, 72, 0.6); }

.presets { display: flex; gap: 8px; margin-bottom: 4px; }
.presets button {
  flex: 1;
  background: var(--ink-3);
  border: 1px solid var(--line);
  color: var(--text-dim);
  padding: 8px 0;
  font-size: 12px;
}
.presets button:hover { border-color: rgba(185, 152, 106, 0.5); color: var(--text); }

/* 邀请码：输入框 + 兑换按钮同一行 */
.invite-row { display: flex; gap: 8px; }
.invite-row input {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
}
.invite-row button {
  flex: none;
  padding: 0 14px;
  font-size: 12.5px;
  white-space: nowrap;
}

.sheet menu {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: 22px 0 0;
  padding: 0;
}

/* ------------------------------------------------------------ 存档抽屉 */

.sheet.wide { width: min(620px, calc(100vw - 32px)); }

.save-current { display: flex; gap: 8px; margin: 0 0 16px; }
.save-current input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--ink);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: none;
}
.save-current input:focus { border-color: rgba(176, 58, 72, 0.6); }

.ctx-box {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--ink);
  padding: 12px 14px;
  margin: 0 0 16px;
}
.ctx-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 11.5px;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  margin-bottom: 10px;
}
.ctx-head span:last-child { color: var(--gold); letter-spacing: 0; white-space: nowrap; }
.ctx-bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.ctx-row {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr) 46px;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  color: var(--text-dim);
}
.ctx-k { white-space: nowrap; color: var(--text-faint); }
.ctx-bar { height: 5px; border-radius: 3px; background: var(--ink-3); overflow: hidden; }
.ctx-bar i {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, rgba(176, 58, 72, 0.85), rgba(185, 152, 106, 0.8));
}
.ctx-v { text-align: right; color: var(--text-faint); font-variant-numeric: tabular-nums; }

.save-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }

.save-list {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  display: grid;
  gap: 6px;
  max-height: 210px;
  overflow-y: auto;
}
.save-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--ink);
}
.save-row.active { border-color: rgba(185, 152, 106, 0.45); background: rgba(185, 152, 106, 0.06); }
.save-main { min-width: 0; flex: 1; display: grid; gap: 3px; }
.save-main b {
  font-weight: 500;
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.save-meta { font-size: 11px; color: var(--text-faint); }
.save-ops { display: flex; gap: 5px; flex: none; }
.save-ops .ghost { padding: 5px 8px; font-size: 11.5px; }

.ctx-actions { display: flex; gap: 8px; }
.ctx-actions .ghost { flex: 1; padding: 9px 0; font-size: 12.5px; }
.ghost.danger { color: #c97676; border-color: rgba(201, 118, 118, 0.3); }
.ghost.danger:hover:not(:disabled) { background: rgba(201, 118, 118, 0.1); color: #d98b8b; }

.fold {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--ink);
  overflow: hidden;
}
.fold > summary { cursor: pointer; padding: 10px 13px; font-size: 12px; color: var(--text-dim); }
.fold[open] > summary { border-bottom: 1px solid var(--line); }
.pin-list {
  list-style: none;
  margin: 0;
  padding: 8px 11px;
  display: grid;
  gap: 6px;
  max-height: 200px;
  overflow-y: auto;
}
.pin-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-dim); }
.pin-txt { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pin-txt em { font-style: normal; color: var(--text-faint); margin-right: 6px; }
.pin-ops { display: flex; gap: 5px; }
.pin-row .ghost { padding: 4px 8px; font-size: 11px; }
.empty { font-size: 12px; color: var(--text-faint); padding: 4px 2px; }

/* 说话时：极轻微地前倾一点，框外泛起一点红 */
.stage-figure video {
  transition: transform 0.55s cubic-bezier(0.4, 0, 0.2, 1), filter 0.55s ease;
}
.stage.speaking .stage-figure video {
  transform: scale(1.008);
  filter: saturate(1.05) brightness(1.03);
}
.stage.speaking .stage-figure {
  box-shadow:
    0 0 0 5px rgba(0, 0, 0, 0.22),
    0 24px 60px rgba(0, 0, 0, 0.62),
    0 0 130px rgba(176, 58, 72, 0.34);
}

.ghost.on {
  color: var(--gold);
  border-color: rgba(185, 152, 106, 0.5);
}

/* 点一下重听 */
.msg.char { cursor: pointer; }
.msg.char .body { transition: border-left-color 0.2s, background 0.2s; }
.msg.char:hover .body { border-left-color: rgba(176, 58, 72, 0.85); }
.msg.char:hover .who::after { content: ' · 点一下重听'; opacity: 0.6; }

.prompt-view {
  margin: 18px 0 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--ink);
  overflow: hidden;
}
.prompt-view summary {
  cursor: pointer;
  padding: 10px 14px;
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  user-select: none;
}
.prompt-view[open] summary { border-bottom: 1px solid var(--line); }
.prompt-view pre {
  margin: 0;
  padding: 14px;
  max-height: 320px;
  overflow: auto;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.75;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ------------------------------------------------------------ Q 版小助手 */

.mascot {
  position: fixed;
  right: clamp(8px, 1.8vw, 24px);
  bottom: calc(92px + env(safe-area-inset-bottom));
  width: clamp(92px, 11vw, 158px);
  aspect-ratio: 1;
  z-index: 30;
  cursor: grab;
  touch-action: none; /* 触屏拖动时别让页面跟着滚 */
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  filter: drop-shadow(0 10px 26px rgba(0, 0, 0, 0.6));
  animation: mascot-bob 4.6s ease-in-out infinite;
  transition: transform 0.18s ease;
}

.mascot:hover { transform: scale(1.04); }
.mascot:active { transform: scale(0.97); }
.mascot:focus-visible { outline: 2px solid rgba(185, 152, 106, 0.7); outline-offset: 6px; border-radius: 8px; }

/* 拖动中：停掉上下浮动，否则会跟着手一起抖 */
.mascot.is-dragging,
.mascot.is-dragging:hover,
.mascot.is-dragging:active {
  animation: none;
  cursor: grabbing;
  transform: none;
  transition: none;
}

.mascot img {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.mascot[data-state='sleep'] { animation-duration: 8s; }

@keyframes mascot-bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-6px); }
}

@media (prefers-reduced-motion: reduce) {
  .mascot { animation: none; }
}

.mascot-bubble {
  position: absolute;
  right: 82%;
  bottom: 76%;
  max-width: min(200px, 46vw);
  padding: 7px 11px;
  background: rgba(30, 24, 23, 0.95);
  border: 1px solid rgba(185, 152, 106, 0.32);
  border-radius: 9px;
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
  animation: bubble-in 0.18s ease-out;
}

.mascot-bubble::after {
  content: '';
  position: absolute;
  right: -5px;
  bottom: 10px;
  width: 8px;
  height: 8px;
  background: inherit;
  border-right: 1px solid rgba(185, 152, 106, 0.32);
  border-bottom: 1px solid rgba(185, 152, 106, 0.32);
  transform: rotate(-45deg);
}

@keyframes bubble-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* 被拖到左边 / 顶部时，气泡翻到另一侧 */
.mascot[data-flip-x='1'] .mascot-bubble { right: auto; left: 82%; }
.mascot[data-flip-x='1'] .mascot-bubble::after {
  right: auto;
  left: -5px;
  border-right: none;
  border-left: 1px solid rgba(185, 152, 106, 0.32);
  transform: rotate(45deg);
}
.mascot[data-flip-y='1'] .mascot-bubble { bottom: auto; top: 82%; }
.mascot[data-flip-y='1'] .mascot-bubble::after { bottom: auto; top: 6px; }

/* ================================================================ 响应式
   断点思路：
     > 1100px       桌面：左舞台右对话，维持原样
     721 ~ 1100px   平板：舞台列收窄，不再挤压对话
     ≤ 720px        手机竖屏：立绘从「左侧画框」变成「顶部整幅海报」，
                    对话变成压在海报下沿的圆角面板（一整块应用的感觉）
     横屏矮屏        手机横屏：回到左右分栏，按 3:7 切，绝不上下堆
   ==================================================================== */

/* ---------------------------------------------------------------- 平板横屏 */

@media (max-width: 1100px) and (min-width: 721px) and (orientation: landscape) {
  .shell { grid-template-columns: minmax(240px, 36%) minmax(0, 1fr); }
  .stage { padding: clamp(12px, 2.4vh, 26px) clamp(10px, 2vw, 22px); }
  /* 横向视频：宽度吃满这一栏，高度按比例，别撑出屏幕 */
  .stage-figure {
    width: 100%;
    max-height: calc(var(--app-h) - 200px);
  }
  .nameplate h1 { font-size: clamp(26px, 3vw, 36px); }
}

/* ------------------------------------------------------ 竖屏：手机 + 平板 */

/* 竖屏一律「海报 + 面板」：手机上更好用，平板上也比两栏里塞一条细立绘好看 */
@media (max-width: 1024px) and (orientation: portrait), (max-width: 720px) {
  .shell {
    display: flex;
    flex-direction: column;
    height: var(--app-h);
    min-height: 0;
  }

  /* ===== 立绘：顶部整幅海报 ===== */
  .stage {
    position: relative;
    flex: none;
    display: block;
    width: 100%;
    height: var(--hero-h);
    padding: 0;
    border: 0;
    background: #150f10;
  }

  /* 盖在立绘上的暗角：上面压住状态栏，下面直接化进对话面板 */
  .stage-bg {
    z-index: 2;
    filter: none;
    transform: none;
    opacity: 1;
    background:
      linear-gradient(to bottom, rgba(12, 10, 10, 0.5) 0%, rgba(12, 10, 10, 0) 26%),
      linear-gradient(to top, #191615 0%, rgba(25, 22, 21, 0.85) 13%, rgba(18, 16, 15, 0) 54%),
      radial-gradient(90% 120% at 50% 28%, rgba(176, 58, 72, 0.22), transparent 70%);
  }

  .stage-figure {
    position: absolute;
    inset: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    aspect-ratio: auto;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    will-change: auto;
  }

  /* 手机上是条横向的窄带，取景往下压一点，露出眼睛和脸 */
  .stage-figure video {
    object-position: 50% 34%;
  }

  .stage-veil { background: linear-gradient(to top, rgba(18, 16, 15, 0.5) 0%, transparent 40%); }

  .stage.speaking .stage-figure { box-shadow: none; }
  .stage.speaking .stage-figure video { transform: none; filter: saturate(1.06) brightness(1.05); }

  .nameplate {
    position: absolute;
    z-index: 3;
    left: max(18px, env(safe-area-inset-left));
    right: max(18px, env(safe-area-inset-right));
    bottom: 34px;
    text-align: left;
    transition: bottom 0.34s cubic-bezier(0.32, 0.72, 0.28, 1);
  }

  .nameplate h1 {
    font-size: clamp(24px, 5.6vw, 34px);
    letter-spacing: 0.2em;
    line-height: 1.1;
    transition: font-size 0.3s ease;
  }

  .nameplate p {
    margin-top: 8px;
    font-size: 10.5px;
    letter-spacing: 0.22em;
    transition: opacity 0.2s ease;
  }

  .chips {
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 11px;
    transition: opacity 0.2s ease;
  }

  .chips li { font-size: 10px; padding: 2px 8px; }

  /* ===== 对话：压在海报上的圆角面板 ===== */
  .room {
    position: relative;
    z-index: 4;
    flex: 1;
    min-height: 0;
    margin-top: -16px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 20px 20px 0 0;
    background: var(--ink-2);
    box-shadow: 0 -16px 36px rgba(0, 0, 0, 0.55);
  }

  .room-bar {
    position: relative;
    gap: 8px;
    padding: 13px 14px 9px;
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
    background: transparent;
    backdrop-filter: none;
    border-bottom: 1px solid rgba(53, 45, 43, 0.75);
  }

  /* 面板顶上的一道小把手：她这层是“可以压下去的” */
  .room-bar::before {
    content: '';
    position: absolute;
    top: 5px;
    left: 50%;
    width: 34px;
    height: 3px;
    margin-left: -17px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.13);
  }

  .room-title { font-size: 11px; letter-spacing: 0.14em; }
  .bar-actions { gap: 5px; }
  .ghost { padding: 6px 9px; font-size: 11.5px; }
  .music-vol { display: none; }   /* 手机工具栏放不下，音量在设置抽屉里 */

  .log {
    padding: 18px 15px 8px;
    padding-left: max(15px, env(safe-area-inset-left));
    padding-right: max(15px, env(safe-area-inset-right));
    scroll-behavior: auto;      /* 平滑滚动和逐字追底会互相打架 */
    /* 别加 -webkit-overflow-scrolling: touch：旧 iOS 上它会让这个容器里的点击失灵 */
  }

  .msg { margin-bottom: 20px; max-width: 100%; }
  .msg .who { font-size: 10.5px; letter-spacing: 0.16em; margin-bottom: 6px; }
  .msg.char .body { font-size: 16.5px; line-height: 1.88; padding-left: 11px; }
  .msg.user { max-width: 86%; }
  .msg.user .body { font-size: 15px; line-height: 1.65; }

  .composer {
    gap: 8px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  .composer textarea {
    font-size: 16px;   /* 小于 16px 时 iOS 一聚焦就整页放大 */
    min-height: 42px;
    max-height: 32dvh;
    padding: 10px 12px;
  }

  #btnSend { height: 42px; padding: 0 15px; font-size: 13.5px; letter-spacing: 0.06em; }

  /* 设置：从底部升起的抽屉 */
  .sheet {
    position: fixed;
    inset: auto 0 0 0;
    margin: 0;
    width: 100%;
    max-width: 100%;
    max-height: 90dvh;
    border: 0;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -24px 60px rgba(0, 0, 0, 0.72);
  }

  .sheet[open] { animation: sheet-rise 0.26s cubic-bezier(0.32, 0.72, 0.28, 1); }

  /* 手机上抽屉占满宽度（.sheet.wide 的特异性更高，得单独盖回来） */
  .sheet.wide { width: 100%; max-width: 100%; }

  .sheet-body {
    max-height: 90dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 22px 18px calc(18px + env(safe-area-inset-bottom));
  }

  .sheet h2 { font-size: 18px; }
  .hint { font-size: 12px; }
  .sheet input { font-size: 16px; padding: 11px 12px; }
  .sheet menu { margin-top: 20px; gap: 8px; }
  .sheet menu button { flex: 1; padding: 11px 0; font-size: 14px; }

  /* 存档：手机上每行折成两段，操作按钮换行右对齐 */
  .save-row { flex-wrap: wrap; }
  .save-ops { width: 100%; justify-content: flex-end; }
  .save-actions .ghost { flex: 1 1 calc(50% - 4px); }
  .ctx-actions .ghost { padding: 10px 0; font-size: 13px; }

  /* Q 版小助手：浮在输入框上方，别压住输入 */
  .mascot {
    right: max(10px, env(safe-area-inset-right));
    bottom: calc(var(--composer-h, 74px) + 10px);
    width: 74px;
  }
  .mascot-bubble { max-width: 60vw; font-size: 12px; }
}

@keyframes sheet-rise {
  from { transform: translateY(24px); opacity: 0.35; }
  to   { transform: translateY(0); opacity: 1; }
}

/* 平板竖屏：1024 宽铺满会把每行拉太长，居中收成一条阅读列 */
@media (min-width: 721px) and (max-width: 1024px) and (orientation: portrait) {
  .room-bar,
  .log,
  .composer {
    padding-left: max(26px, calc((100% - 760px) / 2));
    padding-right: max(26px, calc((100% - 760px) / 2));
  }
  .nameplate { left: max(26px, calc((100% - 760px) / 2)); }
  .msg { max-width: 100%; }
  .mascot { width: 92px; }
}

/* --------------------------------------------------------- 小屏手机 */

@media (max-width: 380px) {
  .room-title { display: none; }
  .nameplate h1 { font-size: 22px; }
  .msg.char .body { font-size: 16px; line-height: 1.85; }
  .ghost { padding: 6px 7px; font-size: 11px; }
  .composer { gap: 6px; }
  #btnSend { padding: 0 12px; }
  .mascot { width: 66px; }
}

/* ------------------------------------------------------ 手机横屏（矮屏） */

@media (orientation: landscape) and (max-height: 560px) {
  .shell {
    display: grid;
    grid-template-columns: minmax(120px, 34%) minmax(0, 1fr);
    grid-template-rows: var(--app-h);
  }

  /* 回到左右分栏：横屏时上下堆会把对话压死 */
  .stage {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: auto;
    height: 100%;
    padding: 8px;
    border-right: 1px solid var(--line);
    transition: none;
  }

  .stage-bg {
    z-index: 0;
    background:
      radial-gradient(120% 90% at 50% 18%, #2a1518 0%, #150f10 55%, #0d0b0b 100%),
      repeating-linear-gradient(115deg, rgba(255, 255, 255, 0.012) 0 1px, transparent 1px 7px);
  }

  .stage-figure {
    position: relative;
    inset: auto;
    z-index: 1;
    width: min(100%, calc((var(--app-h) - 96px) * 1.472));
    height: auto;
    max-width: 100%;
    max-height: none;
    aspect-ratio: 960 / 652;
    border: 1px solid rgba(185, 152, 106, 0.28);
    border-radius: 5px;
    box-shadow:
      0 0 0 4px rgba(0, 0, 0, 0.22),
      0 16px 40px rgba(0, 0, 0, 0.6);
  }

  .stage-figure video { object-position: 50% 42%; }

  .nameplate {
    position: static;
    z-index: 2;
    left: auto;
    right: auto;
    bottom: auto;
    text-align: center;
    transition: none;
  }

  .nameplate h1 { font-size: 19px; letter-spacing: 0.18em; }
  .nameplate p { margin-top: 5px; font-size: 9.5px; letter-spacing: 0.14em; opacity: 0.8; }
  .chips { display: none; }

  .room {
    margin: 0;
    border-top: 0;
    border-radius: 0;
    box-shadow: none;
    background: var(--ink-2);
  }

  .room-bar { padding: 9px 14px; }
  .room-bar::before { display: none; }
  .room-title { font-size: 11px; }
  .ghost { padding: 5px 9px; font-size: 11.5px; }

  .log { padding: 12px 14px 6px; }
  .msg { margin-bottom: 16px; }
  .msg.char .body { font-size: 15.5px; line-height: 1.8; }

  .composer { padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); }
  .composer textarea { font-size: 16px; min-height: 38px; max-height: 30dvh; padding: 8px 11px; }
  #btnSend { height: 38px; padding: 0 14px; }

  .mascot { width: 62px; bottom: calc(var(--composer-h, 62px) + 8px); }

  .sheet {
    position: fixed;
    inset: 0;
    margin: auto;
    width: min(560px, 94vw);
    max-height: 94dvh;
    border: 1px solid var(--line);
    border-radius: 14px;
  }
  .sheet-body { max-height: 94dvh; padding: 18px 20px; }
}

/* 触屏设备上 :hover 会“粘住”，桌面才需要的悬停效果一律关掉 */
@media (hover: none) {
  .msg.char:hover .body { border-left-color: rgba(176, 58, 72, 0.45); }
  .msg.char:hover .who::after { content: none; }
  .ghost:hover:not(:disabled) { background: transparent; color: var(--text-dim); }
  .presets button:hover { border-color: var(--line); color: var(--text-dim); }
  .mascot:hover { transform: none; }
}
