/* ======================================
   沙雕即时互动剧 — 宫廷大戏 样式表
   ====================================== */

/* === Reset & Base === */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --gold: #d4a853;
    --gold-light: #f0d68a;
    --gold-dark: #a07830;
    --bg-dark: #1a0f0a;
    --bg-panel: rgba(26, 15, 10, 0.85);
    --text-light: #f5e6d0;
    --text-dim: #a89080;
    --red-accent: #c0392b;
    --stage-ratio: 56.25%; /* 16:9 */
    --subtitle-bg: rgba(10, 5, 2, 0.82);
}

body {
    font-family: 'Noto Serif SC', 'PingFang SC', serif;
    background: var(--bg-dark);
    color: var(--text-light);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(212, 168, 83, 0.06) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 50%, rgba(192, 57, 43, 0.04) 0%, transparent 60%);
}

/* === 开场遮罩 === */
#intro-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at center, rgba(26, 15, 10, 0.95), #0d0805);
    transition: opacity 0.8s ease, visibility 0.8s ease;
}

#intro-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.intro-content {
    text-align: center;
    animation: fadeInUp 1s ease-out;
}

.drama-title {
    font-family: 'Ma Shan Zheng', cursive;
    font-size: 4rem;
    color: var(--gold);
    text-shadow: 0 0 30px rgba(212, 168, 83, 0.4), 0 4px 8px rgba(0,0,0,0.6);
    margin-bottom: 0.5rem;
    letter-spacing: 0.1em;
}

.drama-subtitle {
    font-size: 1.2rem;
    color: var(--text-dim);
    margin-bottom: 2.5rem;
    letter-spacing: 0.3em;
}

/* === 金色按钮 === */
.btn-gold {
    font-family: 'Noto Serif SC', serif;
    font-size: 1.1rem;
    font-weight: 700;
    padding: 14px 40px;
    border: 2px solid var(--gold);
    background: linear-gradient(135deg, rgba(212, 168, 83, 0.15), rgba(160, 120, 48, 0.25));
    color: var(--gold-light);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    letter-spacing: 0.1em;
}

.btn-gold:hover {
    background: linear-gradient(135deg, rgba(212, 168, 83, 0.3), rgba(160, 120, 48, 0.4));
    box-shadow: 0 0 25px rgba(212, 168, 83, 0.3), inset 0 0 15px rgba(212, 168, 83, 0.1);
    transform: translateY(-2px);
}

.btn-gold:active {
    transform: translateY(0);
}

/* === 舞台容器 === */
#stage-wrapper {
    width: 90vw;
    max-width: 960px;
}

#stage {
    position: relative;
    width: 100%;
    padding-top: var(--stage-ratio);
    background: #2a1f18;
    border-radius: 12px;
    overflow: hidden;
    border: 2px solid rgba(212, 168, 83, 0.3);
    box-shadow:
        0 0 40px rgba(0, 0, 0, 0.6),
        0 0 80px rgba(212, 168, 83, 0.08),
        inset 0 0 60px rgba(0, 0, 0, 0.3);
    /* background-image 由 JS 根据 dramaConfig.background 动态设置 */
    background-size: cover;
    background-position: center;
}

/* === 动态角色区域 === */
#characters-area {
    position: absolute;
    inset: 0;
    bottom: 15%;
    pointer-events: none;
}

.character-slot {
    position: absolute;
    bottom: 0;
    width: 22%;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: opacity 0.4s ease, filter 0.4s ease, transform 0.4s ease;
    opacity: 0;
}

.character-slot.visible {
    opacity: 1;
}

.character-slot.speaking {
    filter: drop-shadow(0 0 15px rgba(212, 168, 83, 0.5));
    z-index: 10;
}

.character-slot.dimmed {
    filter: brightness(0.5) saturate(0.6);
    z-index: 1;
}

/* === 角色合成 === */
.character-container {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    overflow: hidden;
}

.char-body {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: bottom;
    filter: drop-shadow(3px 5px 8px rgba(0,0,0,0.5));
}

.char-face {
    position: absolute;
    top: 22%;
    left: 47%;
    transform: translateX(-50%);
    width: 20%;
    height: auto;
    pointer-events: none;
    image-rendering: auto;
}

/* === 角色名字 === */
.char-name {
    margin-top: 6px;
    padding: 3px 14px;
    background: var(--bg-panel);
    border: 1px solid rgba(212, 168, 83, 0.4);
    border-radius: 20px;
    font-size: 0.8rem;
    color: var(--gold-light);
    letter-spacing: 0.15em;
    white-space: nowrap;
    backdrop-filter: blur(6px);
}

/* === 说话指示器 === */
#speaking-indicator {
    position: absolute;
    bottom: 22%;
    left: 50%;
    transform: translateX(-50%);
    display: none;
    gap: 6px;
}

#speaking-indicator.active {
    display: flex;
}

#speaking-indicator .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--gold);
    animation: bounce 1.2s infinite ease-in-out;
}

#speaking-indicator .dot:nth-child(2) { animation-delay: 0.15s; }
#speaking-indicator .dot:nth-child(3) { animation-delay: 0.3s; }

/* === 字幕条 === */
#subtitle-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 16px 24px;
    background: var(--subtitle-bg);
    backdrop-filter: blur(12px);
    border-top: 1px solid rgba(212, 168, 83, 0.2);
    min-height: 70px;
    display: flex;
    align-items: center;
    gap: 12px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#subtitle-bar.visible {
    opacity: 1;
}

#subtitle-char {
    flex-shrink: 0;
    padding: 4px 12px;
    background: linear-gradient(135deg, var(--gold-dark), var(--gold));
    color: var(--bg-dark);
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.1em;
}

#subtitle-text {
    font-size: 1.1rem;
    line-height: 1.6;
    color: var(--text-light);
    letter-spacing: 0.05em;
}

/* === 打字机效果 === */
#subtitle-text .typed-cursor {
    display: inline-block;
    width: 2px;
    height: 1.2em;
    background: var(--gold);
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: cursorBlink 0.8s step-end infinite;
}

/* === 控制面板 === */
#controls {
    margin-top: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

/* === 小控制按钮 (上一句/下一句) === */
.btn-control {
    font-size: 1.2rem;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: 2px solid rgba(212, 168, 83, 0.3);
    background: rgba(26, 15, 10, 0.6);
    color: var(--gold-light);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-control:hover:not(:disabled) {
    background: rgba(212, 168, 83, 0.2);
    border-color: var(--gold);
    transform: scale(1.05);
}

.btn-control:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    background: rgba(0,0,0,0.3);
    border-color: rgba(255,255,255,0.1);
}

.btn-interrupt {
    font-family: 'Noto Serif SC', serif;
    font-size: 1rem;
    font-weight: 700;
    padding: 12px 28px;
    border: 2px solid var(--red-accent);
    background: linear-gradient(135deg, rgba(192, 57, 43, 0.2), rgba(192, 57, 43, 0.35));
    color: #ff8a80;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    letter-spacing: 0.08em;
    white-space: nowrap;
    animation: pulseGlow 2s infinite ease-in-out;
}

.btn-interrupt:hover:not(:disabled) {
    background: linear-gradient(135deg, rgba(192, 57, 43, 0.4), rgba(192, 57, 43, 0.6));
    box-shadow: 0 0 30px rgba(192, 57, 43, 0.4);
    transform: scale(1.05);
}

.btn-interrupt:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    animation: none;
}

/* === 导演麦克风按钮 === */
.btn-voice {
    font-family: 'Noto Serif SC', serif;
    font-size: 1rem;
    font-weight: 700;
    padding: 12px 24px;
    border: 2px solid var(--gold);
    background: linear-gradient(135deg, rgba(212, 168, 83, 0.15), rgba(212, 168, 83, 0.3));
    color: var(--gold-light);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    letter-spacing: 0.08em;
    white-space: nowrap;
}

.btn-voice:hover:not(:disabled) {
    background: linear-gradient(135deg, rgba(212, 168, 83, 0.3), rgba(212, 168, 83, 0.5));
    box-shadow: 0 0 25px rgba(212, 168, 83, 0.3);
    transform: scale(1.05);
}

.btn-voice:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-voice.recording {
    border-color: #e74c3c;
    background: linear-gradient(135deg, rgba(231, 76, 60, 0.3), rgba(231, 76, 60, 0.5));
    color: #ff6b6b;
    animation: recordPulse 1.2s ease-in-out infinite;
}

@keyframes recordPulse {
    0%, 100% { box-shadow: 0 0 10px rgba(231, 76, 60, 0.3); }
    50% { box-shadow: 0 0 30px rgba(231, 76, 60, 0.6), 0 0 60px rgba(231, 76, 60, 0.2); }
}

#progress-bar {
    flex: 1;
    height: 8px;
    background: rgba(212, 168, 83, 0.15);
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    position: relative;
    transition: height 0.2s ease, background 0.2s ease;
}

#progress-bar:hover {
    height: 12px;
    background: rgba(212, 168, 83, 0.25);
}

#progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--gold-dark), var(--gold));
    border-radius: 4px;
    transition: width 0.3s ease;
    pointer-events: none;
}

/* === 弹窗 === */
.modal-hidden {
    display: none !important;
}

/* 通用全屏弹窗定位 */
#interrupt-modal,
#rename-modal,
#login-prompt-modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
}

.modal-content {
    position: relative;
    z-index: 1;
    background: linear-gradient(145deg, #2a1f18, #1a0f0a);
    border: 1px solid rgba(212, 168, 83, 0.4);
    border-radius: 16px;
    padding: 32px;
    width: 90%;
    max-width: 500px;
    animation: fadeInUp 0.4s ease-out;
    box-shadow: 0 20px 60px rgba(0,0,0,0.6), 0 0 40px rgba(212, 168, 83, 0.1);
}

.modal-content h2 {
    font-family: 'Ma Shan Zheng', cursive;
    font-size: 1.8rem;
    color: var(--gold);
    margin-bottom: 8px;
}

.modal-hint {
    font-size: 0.9rem;
    color: var(--text-dim);
    margin-bottom: 20px;
}

#interrupt-input {
    width: 100%;
    padding: 14px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(212, 168, 83, 0.3);
    border-radius: 8px;
    color: var(--text-light);
    font-family: 'Noto Serif SC', serif;
    font-size: 1rem;
    resize: none;
    outline: none;
    transition: border-color 0.3s;
}

#interrupt-input:focus {
    border-color: var(--gold);
}

#interrupt-input::placeholder {
    color: var(--text-dim);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 20px;
}

.btn-secondary {
    font-family: 'Noto Serif SC', serif;
    font-size: 0.95rem;
    padding: 10px 24px;
    border: 1px solid var(--text-dim);
    background: transparent;
    color: var(--text-dim);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-secondary:hover {
    border-color: var(--text-light);
    color: var(--text-light);
}

/* === 剧终画面 === */
#end-screen {
    position: fixed;
    inset: 0;
    z-index: 150;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 5, 2, 0.9);
    backdrop-filter: blur(10px);
}

#end-screen.modal-hidden {
    display: none;
}

.end-content {
    text-align: center;
    animation: fadeInUp 0.6s ease-out;
}

.end-content h2 {
    font-family: 'Ma Shan Zheng', cursive;
    font-size: 3rem;
    color: var(--gold);
    margin-bottom: 12px;
}

.end-content p {
    color: var(--text-dim);
    margin-bottom: 30px;
    font-size: 1.1rem;
}

.end-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ======================================
   CSS 沙雕动画库
   ====================================== */

.shake {
    animation: shakeAnim 0.4s ease-in-out 3;
}

.jump {
    animation: jumpAnim 0.5s ease-in-out 2;
}

.spin {
    animation: spinAnim 0.8s ease-in-out 1;
}

.fade-out {
    animation: fadeOutAnim 0.8s ease-out forwards;
}

.zoom-in {
    animation: zoomInAnim 0.5s ease-out forwards;
}

.walking {
    animation: walkingBounce 0.35s ease-in-out infinite;
}

/* === Keyframes === */

@keyframes shakeAnim {
    0%, 100% { transform: translateX(0); }
    10% { transform: translateX(-12px) rotate(-2deg); }
    20% { transform: translateX(12px) rotate(2deg); }
    30% { transform: translateX(-10px) rotate(-1.5deg); }
    40% { transform: translateX(10px) rotate(1.5deg); }
    50% { transform: translateX(-8px) rotate(-1deg); }
    60% { transform: translateX(8px) rotate(1deg); }
    70% { transform: translateX(-5px); }
    80% { transform: translateX(5px); }
    90% { transform: translateX(-2px); }
}

@keyframes jumpAnim {
    0%, 100% { transform: translateY(0); }
    30% { transform: translateY(-40px) scaleX(0.9) scaleY(1.1); }
    50% { transform: translateY(-50px) scaleX(0.85) scaleY(1.15); }
    70% { transform: translateY(-20px); }
    85% { transform: translateY(5px) scaleX(1.1) scaleY(0.9); }
}

@keyframes spinAnim {
    0% { transform: rotate(0deg) scale(1); }
    50% { transform: rotate(180deg) scale(0.85); }
    100% { transform: rotate(360deg) scale(1); }
}

@keyframes fadeOutAnim {
    0% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(20px); }
}

@keyframes zoomInAnim {
    0% { transform: scale(1); }
    60% { transform: scale(1.35); }
    100% { transform: scale(1.25); }
}

@keyframes walkingBounce {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    25% { transform: translateY(-15px) rotate(-1deg); }
    75% { transform: translateY(-15px) rotate(1deg); }
}

/* === Utility Keyframes === */

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-10px); }
}

@keyframes pulseGlow {
    0%, 100% { box-shadow: 0 0 5px rgba(192, 57, 43, 0.2); }
    50% { box-shadow: 0 0 20px rgba(192, 57, 43, 0.4), 0 0 40px rgba(192, 57, 43, 0.1); }
}

@keyframes cursorBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* === 响应式 === */
@media (max-width: 600px) {
    .drama-title {
        font-size: 2.5rem;
    }

    .character-slot {
        width: 35%;
    }

    #slot-left { left: 3%; }
    #slot-right { right: 3%; }

    #subtitle-bar {
        padding: 12px 16px;
    }

    #subtitle-text {
        font-size: 0.95rem;
    }

    .btn-control {
        padding: 8px 10px;
        font-size: 1rem;
    }

    .btn-interrupt {
        font-size: 0.85rem;
        padding: 10px 14px;
    }
    
    .btn-voice {
        font-size: 0.85rem;
        padding: 10px 14px;
    }

    #controls {
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
    }
    
    #progress-bar {
        width: 100%;
        margin-top: 8px;
    }
}
