/* ========================================
   墨韵幽境 — 打字机效果
   ======================================== */

/* ── 基础打字机 ── */

.typewriter {
    overflow: hidden;
    white-space: pre-wrap;
    margin: 0 auto;
}

.typewriter::after {
    content: '|';
    animation: inkBlink 0.8s step-end infinite;
    color: var(--amber);
}

@keyframes inkBlink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* ── 流畅打字机 ── */

.typewriter-smooth {
    overflow: hidden;
    white-space: pre-wrap;
    border-right: 2px solid var(--amber);
    animation:
        typing 2s steps(40, end),
        inkCaretBlink 0.8s step-end infinite;
    animation-fill-mode: forwards;
}

.typewriter-smooth::after {
    content: none;
}

@keyframes typing {
    from { width: 0; }
    to { width: 100%; }
}

@keyframes inkCaretBlink {
    from, to { border-color: transparent; }
    50% { border-color: var(--amber); }
}

/* ── 逐字显示 ── */

.typewriter-char {
    display: inline-block;
    opacity: 0;
    transform: translateY(6px);
    animation: charReveal 0.08s ease forwards;
}

@keyframes charReveal {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── 打字完成 ── */

.typewriter-done::after {
    content: none;
}

.typewriter-done {
    border-right: none;
    animation: none !important;
}

/* ── 打字进行中 ── */

.typewriter-active {
    border-right: 2px solid var(--amber);
    animation: inkCaretBlink 0.8s step-end infinite !important;
}

.typewriter-active::after {
    content: none !important;
}

/* ── 速度变体 ── */

.typewriter-fast.typewriter-smooth {
    animation: typing 1s steps(40, end), inkCaretBlink 0.8s step-end infinite;
}

.typewriter-slow.typewriter-smooth {
    animation: typing 4s steps(40, end), inkCaretBlink 0.8s step-end infinite;
}

/* ── 段落打字 ── */

.typewriter-paragraph {
    overflow: hidden;
}

.typewriter-paragraph span {
    display: inline-block;
    opacity: 0;
    transform: translateY(4px);
}

.typewriter-paragraph span.visible {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.06s ease, transform 0.06s ease;
}

/* ── 响应式 ── */

@media (max-width: 768px) {
    .typewriter-smooth {
        animation: typing 3s steps(30, end), inkCaretBlink 0.8s step-end infinite;
    }
}

/* ── 减少动画 ── */

@media (prefers-reduced-motion: reduce) {
    html:not(.dn-motion-preview) .typewriter,
    html:not(.dn-motion-preview) .typewriter-smooth,
    html:not(.dn-motion-preview) .typewriter-char {
        animation: none !important;
        opacity: 1 !important;
        transform: none !important;
        border-right: none !important;
    }

    html:not(.dn-motion-preview) .typewriter::after,
    html:not(.dn-motion-preview) .typewriter-smooth::after {
        content: none !important;
    }
}

/* ── 剧情叙事区：确保透明 ── */

#gameplay-screen #text-display-area,
#gameplay-screen .narrative-shell {
    background: transparent !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    box-shadow: none !important;
    border: none !important;
}

#gameplay-screen #scene-text.typewriter {
    overflow: visible !important;
}
