/* ==========================================================================
 * 数字人组件样式（digital-human.js 的配套样式）
 * 课程页和 dh-settings.html 共用这一份。
 * 色彩沿用站点主色：#3b82f6 / #8b5cf6 / #1e293b
 * ========================================================================== */

/* ======================== 悬浮球 ======================== */
/* dock 固定在视口右下角，装着悬浮球。
   z-index 900 低于随堂练习弹窗的 1000 —— 答题时弹窗会盖住它，不抢镜头 */
.dh-dock {
    position: fixed;
    right: 2rem;
    bottom: 2rem;
    z-index: 900;
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none; /* 只让球可点，dock 的空白区域不吞点击 */
}

.dh-dock > * {
    pointer-events: auto;
}

.dh-ball {
    position: relative;
    width: 60px;
    height: 60px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    color: white;
    font-size: 1.5rem;
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(59,130,246,0.45);
    opacity: 0.72; /* 常驻但半透明；实测这个尺寸只压住右侧面板最右 12px 一窄条 */
    transition: opacity 0.2s, transform 0.2s, background 0.2s, box-shadow 0.2s;
    /* 触摸设备上必须禁掉默认手势，否则拖动球会变成滚动页面 */
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

/* 拖拽中：取消 hover 的抬升，否则球会和手指错开位置 */
.dh-dock.is-dragging .dh-ball {
    transform: none;
    opacity: 1;
    cursor: grabbing;
    transition: none;
}

.dh-dock:hover .dh-ball,
.dh-ball:focus-visible {
    opacity: 1;
}

.dh-ball:hover {
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    transform: translateY(-4px);
    box-shadow: 0 12px 28px rgba(59,130,246,0.55);
}

.dh-ball:active {
    transform: translateY(-1px) scale(0.97);
}

/* 数字人已唤出时的状态：球变深色、图标转 90°，读作「再点收起」 */
.dh-ball.is-active {
    background: linear-gradient(135deg, #1e293b, #475569);
    box-shadow: 0 8px 24px rgba(30,41,59,0.4);
    opacity: 0.85;
}

.dh-ball.is-active .dh-ball-icon {
    transform: rotate(-90deg);
}

.dh-ball-icon {
    display: block;
    transition: transform 0.2s;
}

/* 呼吸光圈，吸引注意 */
.dh-ball-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid rgba(59,130,246,0.6);
    animation: dhPulse 2.2s ease-out infinite;
    pointer-events: none;
}

.dh-ball.is-active .dh-ball-ring {
    animation: none;
    opacity: 0;
}

@keyframes dhPulse {
    0% {
        transform: scale(1);
        opacity: 0.8;
    }
    100% {
        transform: scale(1.55);
        opacity: 0;
    }
}

.dh-ball-tag {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #1e293b;
    color: white;
    font-size: 0.6rem;
    font-weight: 600;
    padding: 0.1rem 0.4rem;
    border-radius: 2rem;
    letter-spacing: 0.5px;
}

/* ======================== 右键快捷设置框 ======================== */
.dh-popup {
    position: fixed;
    right: 2rem;
    bottom: 7.2rem;
    width: 272px;
    z-index: 960;
    background: white;
    border: 1px solid rgba(203,213,225,0.5);
    border-radius: 1rem;
    box-shadow: 0 20px 35px rgba(0,0,0,0.18);
    padding: 0.85rem 1rem 0.95rem;
    display: none;
}

.dh-popup.show {
    display: block;
    animation: dhPopIn 0.16s ease;
}

@keyframes dhPopIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

.dh-popup-title {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.86rem;
    font-weight: 600;
    color: #1e293b;
    padding-bottom: 0.6rem;
    margin-bottom: 0.7rem;
    border-bottom: 1px solid #eef2ff;
}

.dh-popup-hint {
    font-size: 0.68rem;
    color: #94a3b8;
    font-weight: 400;
    margin-left: auto;
}

.dh-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    margin-bottom: 0.55rem;
}

.dh-row-label {
    font-size: 0.78rem;
    color: #475569;
    white-space: nowrap;
}

.dh-row-value {
    font-size: 0.72rem;
    color: #3b82f6;
    font-variant-numeric: tabular-nums;
    min-width: 2.4rem;
    text-align: right;
}

.dh-select {
    flex: 1;
    min-width: 0;
    background: #f8fafc;
    color: #1e293b;
    border: 1px solid #e2e8f0;
    border-radius: 2rem;
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    outline: none;
}

.dh-slider {
    flex: 1;
    min-width: 0;
    height: 4px;
    border-radius: 2px;
    background: #e2e8f0;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.dh-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: #3b82f6;
    cursor: pointer;
}

.dh-switch {
    position: relative;
    width: 38px;
    height: 21px;
    flex: none;
    border: none;
    border-radius: 2rem;
    background: #cbd5e1;
    cursor: pointer;
    padding: 0;
    transition: background 0.2s;
}

.dh-switch::after {
    content: '';
    position: absolute;
    top: 2.5px;
    left: 2.5px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: white;
    transition: transform 0.2s;
}

.dh-switch.on {
    background: #3b82f6;
}

.dh-switch.on::after {
    transform: translateX(17px);
}

.dh-popup-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    margin-top: 0.75rem;
    padding: 0.5rem;
    background: #3b82f6;
    color: white;
    font-size: 0.78rem;
    text-decoration: none;
    border-radius: 2rem;
    transition: background 0.2s;
}

.dh-popup-link:hover {
    background: #2563eb;
}

/* ======================== 数字人舞台 ======================== */
/* 贴满视频区域。因为 .video-control-bar 是 .video-wrapper 的兄弟节点，
   这一层永远只压在视频上，不会遮住控制条 */
.dh-stage {
    position: absolute;
    inset: 0;
    overflow: hidden;
    background: linear-gradient(180deg, rgba(15,23,42,0) 38%, rgba(15,23,42,0.72) 100%);
    animation: dhFadeIn 0.2s ease;
}

@keyframes dhFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* 外层只负责定位，保持盒子稳定；动画放在里层 SVG 上。
   这样容器的边界不会随呼吸抖动 —— 右键点击的目标是稳定可命中的
   （动画挂在容器上会让元素永远"不稳定"，自动化点击会被拒绝） */
.dh-avatar {
    position: absolute;
    left: 1.2rem;
    bottom: 0;
    height: 82%;
    display: flex;
    align-items: flex-end;
    cursor: grab;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

/* 拖拽中：停掉呼吸动画，免得手和画面一起抖 */
.dh-avatar.is-dragging {
    cursor: grabbing;
}

.dh-avatar.is-dragging svg {
    animation: none;
}

@keyframes dhEnter {
    from {
        transform: translateY(14px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes dhBreath {
    0%, 100% { transform: scaleY(1); }
    50%      { transform: scaleY(1.02); }
}

.dh-avatar svg {
    height: 100%;
    width: auto;
    display: block;
    filter: drop-shadow(0 6px 18px rgba(0,0,0,0.45));
    transform-origin: bottom center;
    animation: dhEnter 0.25s ease, dhBreath 3.4s ease-in-out infinite 0.25s;
}

/* is-3d：canvas 要向盒子外溢出（画腿和手臂），所以盒子本身不能裁 */
.dh-avatar.is-3d {
    overflow: visible;
}

/* ---- 3D 后端（vrm）用的 canvas ----
   盒子（.dh-avatar）就是那个「位置盒子」：高度沿用基类的 82%，宽度 = 高度 × 取景比 ——
   比例在加载模型时按**「双手自然下垂」的实测轮廓宽度**算出（见 dh-vrm-rig.js 的
   loadAndAdopt）。盒子只代表"站姿的宽度"：拖拽、边界钳制、位置记忆都按它，
   所以拖到最边上时手刚好碰到视频边缘，换任何模型都自动对得上。
   canvas 比盒子**高**也**宽**，跟纵向同一个道理：
   · 高 150%（向下溢出）→ 多出来的是画腿的地方，由 .dh-stage 的 overflow:hidden 裁掉，
     于是腿是被**视频底边**切的，不是在画面中间被盒子那条看不见的边切；
   · 宽 = 盒子宽 × 1.8（左右各溢出 40%，居中）→ 手臂可以画到盒子外面去，
     不会在画面中间被 canvas 的边切出一条直边。canvas 是透明的，多出来的区域
     只让视频透出来，静止观感不变。
   ⚠️ 150% 必须与 dh-vrm-rig.js 里的 CANVAS_H_RATIO 一致；宽度与 left 由 rig 的
      resize() 按 CANVAS_W_RATIO 直接写 inline，下面这两行只是没跑 JS 时的兜底。
   刻意不加 drop-shadow：模型叠在视频上，给一块透明画布投影连边框都会投出来 */
.dh-avatar > canvas {
    position: absolute;
    top: 0;
    left: -40%;
    display: block;
    width: 180%;
    height: 150%;
}

/* 3D 形象加载中：盒子还是空的，给一句轻提示。
   （不再先铺一个 2D 形象再换成 3D —— 那两个会看到"2D 招手、然后变 3D"） */
.dh-avatar.is-loading::after {
    content: '正在加载 3D 形象…';
    position: absolute;
    left: 0;
    bottom: 0;
    padding: 0.15rem 0.5rem;
    border-radius: 0.5rem;
    background: rgba(15, 23, 42, 0.55);
    color: rgba(255, 255, 255, 0.75);
    font-size: 0.72rem;
    line-height: 1.4;
    white-space: nowrap;
}

/* 形象配色 */
.dh-face  { fill: #fde3cf; stroke: #e8b894; stroke-width: 1.5; }
.dh-hair  { fill: #2b3450; }
.dh-ear   { fill: #fde3cf; stroke: #e8b894; stroke-width: 1.2; }
.dh-neck  { fill: #f0cfae; }
.dh-torso { fill: #3b82f6; }
.dh-arm   { fill: none; stroke: #2563eb; stroke-width: 11; stroke-linecap: round; }
.dh-eye   { fill: #1e293b; }
.dh-brow  { fill: none; stroke: #2b3450; stroke-width: 2.6; stroke-linecap: round; }
.dh-mouth { fill: #d9534f; stroke: #b8433f; stroke-width: 1.2; }
.dh-blush { fill: #f7a8a0; opacity: 0.5; }

/* 字幕胶囊 */
.dh-subtitle {
    position: absolute;
    left: 50%;
    bottom: 1rem;
    transform: translateX(-50%);
    max-width: min(76%, 620px);
    background: rgba(30,41,59,0.86);
    color: white;
    font-size: 0.9rem;
    line-height: 1.55;
    padding: 0.55rem 1.15rem;
    border-radius: 2rem;
    text-align: center;
    /* 刻意不加 backdrop-filter：它让浏览器把"胶囊背后的一切"单独渲染一遍，
       而默认范围是整篇文档 —— 视频一播就变成整页逐帧重绘（知识点面板踩过这个坑）。
       背景已经 86% 不透明，模糊看不出来 */
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}

.dh-subtitle.show {
    opacity: 1;
}

/* 段落控制（在右键设置框里）。视频区右上角原来有一条工具条，已删除：
   显隐靠点悬浮球，驱动切换和逐段翻都收进设置框，视频上只留形象和字幕 */
.dh-seg-btns {
    display: flex;
    gap: 0.25rem;
}

.dh-mini {
    width: 30px;
    height: 24px;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    color: #475569;
    border-radius: 2rem;
    font-size: 0.68rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.dh-mini:hover {
    border-color: #3b82f6;
    background: white;
    color: #3b82f6;
}

.dh-mini:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.dh-seg-count {
    color: #3b82f6;
    font-variant-numeric: tabular-nums;
}

/* 状态提示（无音频、无中文音色等） */
.dh-note {
    position: absolute;
    left: 50%;
    top: 0.7rem;
    transform: translateX(-50%);
    background: rgba(239,68,68,0.92);
    color: white;
    font-size: 0.72rem;
    padding: 0.2rem 0.75rem;
    border-radius: 2rem;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}

.dh-note.show {
    opacity: 1;
}

/* ======================== 响应式 ======================== */
@media (max-width: 640px) {
    .dh-dock {
        right: 1rem;
        bottom: 1rem;
    }
    .dh-ball {
        width: 52px;
        height: 52px;
        font-size: 1.3rem;
        opacity: 0.85;
    }
    .dh-popup {
        right: 1rem;
        left: 1rem;
        width: auto;
        bottom: 5.6rem;
    }
    .dh-avatar {
        left: 0.6rem;
        height: 74%;
    }
    .dh-subtitle {
        font-size: 0.8rem;
        bottom: 0.6rem;
        max-width: 88%;
    }
}
