/**
 * 实时交互（数字人）页面样式
 *
 * 独立于 studio.css：这个页面是**沉浸式通话**，和主播工作台的密度、断点、
 * 4:3 预览约束都不一样。混用一套样式只会让两边互相牵制。
 */
:root {
  --bg: #08080d;
  --panel: #12121a;
  --panel-2: #181822;
  --line: #2a2938;
  --text: #f4f2fb;
  --muted: #a09db4;
  --faint: #6e6b82;
  --accent: #8b7cf6;
  --accent-soft: #8b7cf633;
  --danger: #e5484d;
  --radius: 22px;
  --stage-max: 620px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(ellipse at 12% 0, #2a1b3d55, transparent 48%),
    radial-gradient(ellipse at 95% 8%, #1e2a4d55, transparent 46%),
    var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; transition: background .18s, transform .18s, border-color .18s, opacity .18s; }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { cursor: not-allowed; opacity: .45; }
button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid #b7aaff; outline-offset: 3px;
}
[hidden] { display: none !important; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.defs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ============================ 画廊 ============================ */
.gallery-view {
  min-height: 100vh;
  padding: 44px clamp(24px, 5vw, 72px) 56px;
  max-width: 1500px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}
.gallery-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
}
.eyebrow {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .22em;
  color: #b9a9ff;
}
.gallery-copy h1 {
  margin: 0;
  font-size: clamp(24px, 3vw, 34px);
  font-weight: 650;
  letter-spacing: -.02em;
}
.gallery-sub { margin: 9px 0 0; color: var(--muted); font-size: 13px; }
.cap-pill {
  flex-shrink: 0;
  margin-top: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid #3a3650;
  background: #ffffff08;
  color: #c9c4e2;
  font-size: 11px;
  white-space: nowrap;
}
.cap-pill.bad { border-color: #5b2a31; background: #e5484d14; color: #ffb3b7; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(238px, 1fr));
  gap: 20px;
}
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  aspect-ratio: 3 / 4.25;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid #ffffff12;
  background: #14141d;
  text-align: left;
  isolation: isolate;
}
.card:hover { border-color: #8b7cf666; }
.card:focus-visible { outline: 2px solid #b7aaff; outline-offset: 3px; }

/* 角色卡：大图 + 底部渐变信息 */
.character-card { padding: 0; }
.character-card .card-art {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center 18%;
  transition: transform .45s ease, filter .3s ease;
}
.character-card:hover .card-art { transform: scale(1.045); }
.character-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #0b0b1255 0%, transparent 32%, transparent 52%, #08080dd9 100%);
  z-index: 1;
}
.card-expand {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 3;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #0c0c1480;
  border: 1px solid #ffffff24;
  color: #fff;
  backdrop-filter: blur(10px);
}
.card-expand:hover { background: #ffffff1f; }
.card-info {
  position: relative;
  z-index: 2;
  margin-top: auto;
  padding: 20px 18px 20px;
}
.card-info b {
  display: block;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -.01em;
  text-shadow: 0 1px 12px #0008;
}
.card-info small {
  display: block;
  margin-top: 6px;
  color: #cfccdd;
  font-size: 12.5px;
  line-height: 1.5;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  text-shadow: 0 1px 10px #0009;
}
.card-delete {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 3;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #0c0c1480;
  border: 1px solid #ffffff24;
  color: #ffc6c8;
  opacity: 0;
}
.character-card:hover .card-delete { opacity: 1; }
.card-delete:hover { background: #e5484d33; }

/* 新建角色卡 */
.create-card {
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: linear-gradient(155deg, #1d1d27, #14141c);
  border-color: #ffffff1a;
  color: #f2f0fa;
}
.create-card:hover { border-color: #8b7cf6aa; background: linear-gradient(155deg, #242232, #17171f); }
.create-art {
  position: relative;
  width: 104px;
  height: 82px;
}
.create-art .mini {
  position: absolute;
  border-radius: 12px;
  border: 1px solid #ffffff2a;
  background: linear-gradient(140deg, #8b7cf6, #e28bc4);
  box-shadow: 0 8px 22px #0005;
}
.create-art .mini.back {
  width: 46px; height: 54px;
  left: 8px; top: 16px;
  transform: rotate(-12deg);
  opacity: .55;
}
.create-art .mini.front {
  width: 46px; height: 54px;
  left: 24px; top: 12px;
  transform: rotate(3deg);
  background: linear-gradient(140deg, #f0b6a0, #8b7cf6);
}
.create-art .plus-badge {
  position: absolute;
  right: 2px; top: 20px;
  width: 42px; height: 42px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: #f3f1fb;
  color: #1a1a22;
  border: 2px solid #d8d4e8;
  box-shadow: 0 6px 18px #0006;
  z-index: 2;
}
.create-art .plus-badge svg { width: 22px; height: 22px; stroke-width: 2; }
.create-card b { font-size: 17px; font-weight: 650; }
.create-card small { color: var(--faint); font-size: 11.5px; text-align: center; padding: 0 18px; }
.create-card[disabled] { filter: grayscale(.4); }
.gallery-foot { margin: 34px 0 0; color: #5f5c73; font-size: 11px; }

/* ============================ 通话 ============================ *
 * 两个**先后状态**，不是左右并排：
 *   · 建链中：只显示居中的准备页（头像光环 / 标题 / 取消）
 *   · 接通后：准备页消失，只显示居中的竖屏通话卡片
 * `.is-live` 由 enterLive() 加上，挂断/失败/取消时移除。
 */
.call-view {
  position: relative;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr;
}
.prep-panel {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 44px 36px;
  background: #050507;
  overflow: hidden;
  animation: fade-in .3s ease;
}
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
.prep-panel::before {
  content: "";
  position: absolute;
  width: 560px; height: 560px;
  border-radius: 50%;
  background: radial-gradient(circle, #6f5bd41f, transparent 66%);
  pointer-events: none;
}
.prep-inner { position: relative; width: min(560px, 100%); text-align: center; }

.orbit {
  position: relative;
  width: 280px;
  height: 280px;
  margin: 0 auto 30px;
  display: grid;
  place-items: center;
}
.orbit-avatar {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 22%;
  border: 1px solid #ffffff2e;
  box-shadow: 0 0 44px #8b7cf64d, 0 10px 30px #0009;
  z-index: 2;
}
.orbit-ring {
  position: absolute;
  border-radius: 50%;
  border: 1px dashed #ffffff2b;
}
.orbit-ring.r1 { inset: 24px; animation: spin 26s linear infinite; }
.orbit-ring.r2 { inset: 52px; border-color: #ffffff1c; animation: spin-rev 20s linear infinite; }
.orbit-ring.r3 { inset: 82px; border-style: dotted; border-color: #ffffff14; animation: spin 34s linear infinite; }
.orbit-dots {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background-image: radial-gradient(circle, #ffffff55 1px, transparent 1.4px);
  background-size: 100% 100%;
  -webkit-mask-image: radial-gradient(circle, transparent 52%, #000 53%, #000 66%, transparent 67%);
  mask-image: radial-gradient(circle, transparent 52%, #000 53%, #000 66%, transparent 67%);
  opacity: .5;
  animation: pulse 3.2s ease-in-out infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes spin-rev { to { transform: rotate(-360deg); } }
@keyframes pulse { 0%,100% { opacity: .28; } 50% { opacity: .62; } }

.prep-title { margin: 0; font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
.prep-tagline { margin: 10px 0 0; color: #a7a3ba; font-size: 13px; }
.prep-status { margin: 22px 0 0; color: #77738c; font-size: 12px; }
.cancel-btn {
  margin: 26px auto 0;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #f4f2fb;
  color: #e5484d;
  box-shadow: 0 8px 24px #0006;
}
.cancel-btn:hover { background: #fff; transform: scale(1.04); }
.cancel-btn svg { width: 22px; height: 22px; stroke-width: 2; }

.transcript {
  list-style: none;
  margin: 26px auto 0;
  padding: 0;
  max-height: 168px;
  overflow-y: auto;
  text-align: left;
  scrollbar-width: thin;
  scrollbar-color: #3a3750 transparent;
}
.transcript:empty { display: none; }
.transcript li {
  padding: 7px 0;
  color: #b9b5ca;
  font-size: 12.5px;
  line-height: 1.6;
  border-bottom: 1px solid #ffffff08;
}
.transcript li b { color: #d9d3ff; font-weight: 600; margin-right: 7px; font-size: 11px; }
.transcript li.user b { color: #8fd0b3; }
.back-link {
  margin: 24px auto 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid #ffffff1c;
  color: #b9b5ca;
  font-size: 12px;
}
.back-link:hover { background: #ffffff0d; }
.back-link svg { width: 16px; height: 16px; }

.stage-column {
  /* 建链阶段：**保留在布局里但不可见**，原因不是视觉 —— TRTC 的远端渲染器
     在 display:none 的容器里可能不创建 <video>。用 opacity:0 盖在准备页下面，
     既让准备页独占视觉，又保证远端视频元素真的被创建。接通后淡入。 */
  position: absolute;
  inset: 0;
  z-index: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: #0a0a10;
  min-width: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity .32s ease;
}
.stage {
  position: relative;
  width: 100%;
  max-width: var(--stage-max);
  height: min(calc(100vh - 48px), 960px);
  aspect-ratio: 9 / 16;
  border-radius: 26px;
  overflow: hidden;
  background: #000;
  border: 1px solid #ffffff14;
  box-shadow: 0 24px 70px #000a;
  isolation: isolate;
}
.remote-view { position: absolute; inset: 0; background: #05050a; }
.remote-view video {
  width: 100%;
  height: 100%;
  object-fit: cover !important;
  background: transparent;
}
/* TRTC 自己插入 <video> 时可能带内联 object-fit —— cover 需要 !important 压住 */
.remote-view::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #05050944 0%, transparent 22%, transparent 62%, #050509cc 100%);
  pointer-events: none;
}

.stage-top {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 3;
}
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  border-radius: 999px;
  background: #0b0b1280;
  border: 1px solid #ffffff22;
  backdrop-filter: blur(10px);
  font-size: 10.5px;
  color: #f4f2fb;
}
.live-badge i { width: 6px; height: 6px; border-radius: 50%; background: #ff5a63; box-shadow: 0 0 8px #ff5a63; }
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #0b0b1266;
  border: 1px solid #ffffff22;
  color: #fff;
  backdrop-filter: blur(10px);
}
.icon-btn:hover { background: #ffffff1f; }
.icon-btn svg { width: 18px; height: 18px; }

.stage-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  padding: 0 18px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
/* 剩余时间放在右上角，与左侧的通话中徽标对称 */
.call-remain {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: 999px;
  background: #0b0b1280;
  border: 1px solid #ffffff22;
  backdrop-filter: blur(10px);
  font-size: 11.5px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: .03em;
  color: #ffffffb3;
  text-shadow: 0 1px 8px #0009;
  transition: color .2s, border-color .2s;
}
.call-remain.danger { color: #ffb3b8; font-weight: 650; border-color: #e5484d55; }
.controls { display: flex; align-items: center; gap: 14px; }
.ctrl {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #16161ecc;
  border: 1px solid #ffffff1f;
  color: #f4f2fb;
  backdrop-filter: blur(12px);
}
.ctrl:hover { background: #24242fdd; }
.ctrl[aria-pressed="false"] { color: #ff8d93; background: #2a1418d9; border-color: #e5484d44; }
.ctrl.hangup {
  width: 58px;
  height: 58px;
  background: var(--danger);
  border-color: #ff7b80;
  color: #fff;
  box-shadow: 0 8px 24px #e5484d55;
}
.ctrl.hangup:hover { background: #f2555a; }
.ctrl svg { width: 21px; height: 21px; }
.stage-foot { margin: 0; font-size: 10px; color: #ffffff8a; letter-spacing: .04em; text-shadow: 0 1px 6px #0008; }

.caption {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 186px;
  z-index: 3;
  text-align: center;
  font-size: 13px;
  line-height: 1.6;
  color: #fff;
  text-shadow: 0 1px 10px #000c, 0 0 3px #000;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
}
.caption.show { opacity: 1; }
.caption b { color: #d9d3ff; font-weight: 600; margin-right: 6px; }

.autoplay-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  background: #05050a55;
  backdrop-filter: blur(2px);
}
.autoplay-btn {
  padding: 11px 22px;
  border-radius: 999px;
  background: #f4f2fb;
  color: #17171f;
  font-weight: 600;
  box-shadow: 0 8px 24px #0008;
}

.text-form {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 150px;
  z-index: 4;
  display: flex;
  gap: 8px;
}
.text-form input {
  flex: 1;
  min-width: 0;
  height: 42px;
  border-radius: 999px;
  border: 1px solid #ffffff26;
  background: #0b0b12cc;
  color: #fff;
  padding: 0 16px;
  font-size: 13px;
  backdrop-filter: blur(12px);
}
.text-form input::placeholder { color: #8f8b9f; }
.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #f4f2fb;
  color: #17171f;
  flex-shrink: 0;
}
.send-btn svg { width: 18px; height: 18px; }

/* 接通后：准备页收起，竖屏通话卡片占满整个内容区 */
.call-view.is-live .prep-panel { display: none; }
.call-view.is-live .stage-column {
  position: relative;
  z-index: 1;
  opacity: 1;
  pointer-events: auto;
  padding: 20px;
  background:
    radial-gradient(ellipse at 50% 40%, #171326 0%, transparent 62%),
    #06060b;
}
.call-view.is-live .stage {
  animation: stage-in .38s cubic-bezier(.22, .8, .3, 1);
  box-shadow: 0 30px 90px #000d, 0 0 60px #6f5bd41a;
}
@keyframes stage-in {
  from { opacity: .35; transform: scale(.965); }
  to { opacity: 1; transform: scale(1); }
}


/* 本地摄像头预览（右上角小窗）。只有摄像头打开时才显示。
   ⚠️ 必须放在 `.stage` 外面：stage 接通时有一个 transform 动画，fixed 子元素会以它
   为包含块，位置会跟着动画跑。 */
.local-preview {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 20;
  width: min(260px, 28vw);
  aspect-ratio: 4 / 3;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid #ffffff2e;
  background: #000;
  box-shadow: 0 14px 40px #000b;
  pointer-events: none;
  animation: fade-in .25s ease;
}
.local-view,
.local-view video {
  width: 100%;
  height: 100%;
}
.local-view video {
  object-fit: cover !important;
  /* 本地预览镜像由 SDK 的 mirror:'view' 负责，这里不要再翻一次。 */
  background: #000;
}

/* ============================ 新建角色弹窗 ============================ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: #05050ab8;
  backdrop-filter: blur(10px);
}
.modal-card {
  width: min(470px, 100%);
  max-height: min(86vh, 760px);
  overflow-y: auto;
  border-radius: 20px;
  border: 1px solid #ffffff1a;
  background: linear-gradient(160deg, #1a1a24, #121219);
  box-shadow: 0 30px 90px #000c;
  scrollbar-width: thin;
}
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 22px 14px;
}
.modal-head h3 { margin: 0; font-size: 18px; font-weight: 650; }
.modal-head p { margin: 5px 0 0; color: var(--faint); font-size: 11.5px; }
.modal-body { padding: 4px 22px 6px; }
.upload-box {
  width: 100%;
  height: 150px;
  border-radius: 14px;
  border: 1px dashed #ffffff2a;
  background: #ffffff06;
  display: grid;
  place-items: center;
  overflow: hidden;
  margin-bottom: 16px;
}
.upload-box:hover { border-color: #8b7cf6aa; background: #8b7cf610; }
.upload-box img { width: 100%; height: 100%; object-fit: cover; }
.upload-placeholder { display: grid; place-items: center; gap: 8px; color: #9a96ad; font-size: 12px; }
.upload-placeholder svg { width: 28px; height: 28px; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; margin-bottom: 7px; color: #bcb8cd; font-size: 12px; }
.field input, .field textarea {
  width: 100%;
  border-radius: 10px;
  border: 1px solid #333042;
  background: #0e0e15;
  padding: 10px 12px;
  color: #f4f2fb;
  font-size: 13px;
  resize: vertical;
}
.field input::placeholder, .field textarea::placeholder { color: #67637a; }
.modal-error { min-height: 18px; margin: 2px 0 8px; color: #ff9aa0; font-size: 11.5px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 22px 22px;
}
.btn {
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 550;
}
.btn.ghost { background: #ffffff0a; border: 1px solid #ffffff1c; color: #d7d3e4; }
.btn.ghost:hover { background: #ffffff14; }
.btn.primary { background: linear-gradient(135deg, #8b7cf6, #6f5bd4); color: #fff; box-shadow: 0 6px 20px #6f5bd455; }
.btn.primary:hover { filter: brightness(1.06); }

/* ============================ Toast ============================ */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 16px);
  z-index: 80;
  max-width: min(560px, 90vw);
  padding: 10px 18px;
  border-radius: 10px;
  background: #242130;
  border: 1px solid #ffffff1a;
  color: #f4f2fb;
  font-size: 12.5px;
  text-align: center;
  box-shadow: 0 10px 30px #0008;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ============================ 响应式 ============================ */
@media (max-width: 980px) {
  .prep-panel {
    min-height: 100vh;
    padding: 26px 22px;
  }
  .orbit { width: 170px; height: 170px; margin-bottom: 16px; }
  .orbit-avatar { width: 64px; height: 64px; }
  .prep-title { font-size: 18px; }
  .transcript { max-height: 96px; }
  .stage-column { padding: 14px; }
  .stage { height: auto; aspect-ratio: 9 / 16; max-height: calc(100vh - 28px); }
}
@media (max-width: 640px) {
  .gallery-view { padding: 26px 16px 40px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .card { border-radius: 16px; }
  .card-info b { font-size: 16px; }
  .card-info small { font-size: 11px; }
  .create-art { transform: scale(.82); margin: -8px 0; }
  .local-preview { width: 132px; top: 12px; right: 12px; }
}
