/* 字体导入 - 使用本地切片化的 WOFF2 字体（彻底摆脱外部 CDN 依赖） */
@import url('./local-fonts.css');

/* 对话框字体缩放变量（由 JS game.js 动态控制） */
:root {
    --dialogue-font-scale: 1;
}

html, body {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    background-color: #0d0d1a;
    overscroll-behavior: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.font-serif-sc {
    font-family: 'LXGW WenKai', 'LXGW WenKai Lite', 'Noto Serif SC', 'Times New Roman', Times, serif;
}

.font-calligraphy {
    font-family: 'Ma Shan Zheng', 'KaiTi', 'STKaiti', cursive;
}

/* 动画与特效 */
.fade-enter {
    opacity: 0;
}

.fade-enter-active {
    opacity: 1;
    transition: opacity 500ms ease-in;
}

.fade-exit {
    opacity: 1;
}

/* --- New Visual Effects --- */
/* Silver Energy Stream */
.energy-stream {
    position: absolute;
    width: 3px;
    background: linear-gradient(to top, transparent, #e0e0e0, transparent);
    opacity: 0;
    bottom: -20%;
    filter: drop-shadow(0 0 5px white);
    pointer-events: none;
}

@keyframes energy-flow {
    0% {
        transform: translateY(0) scaleY(0.2);
        opacity: 0;
    }

    20% {
        opacity: 0.8;
    }

    100% {
        transform: translateY(-120vh) scaleY(1.2);
        opacity: 0;
    }
}

/* --- Danger Surge & Heavy Breathing Effects --- */
/* Danger Vignette with pulsating multiply blend */
.danger-surge-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 25; /* Above background/characters, below UI */
    background: radial-gradient(ellipse at center, transparent 40%, rgba(70, 5, 5, 0.6) 80%, rgba(20, 0, 0, 0.98) 100%);
    box-shadow: inset 0 0 150px rgba(80, 0, 0, 0.7);
    opacity: 0;
    mix-blend-mode: multiply;
    transition: opacity 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    /* HW Accel */
    will-change: opacity, filter;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    transform: translateZ(0);
}

.danger-surge-active {
    opacity: 1;
    animation: danger-pulse 2.2s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

@keyframes danger-pulse {
    0%, 100% { opacity: 0.8; filter: hue-rotate(0deg) saturate(1.1); box-shadow: inset 0 0 130px rgba(80, 0, 0, 0.7); }
    50% { opacity: 1; filter: hue-rotate(-5deg) saturate(1.3); box-shadow: inset 0 0 190px rgba(110, 0, 0, 0.9); }
}

/* Heavy breathing screen scale and brightness rhythm */
@keyframes heavy-breathing {
    0%, 100% { 
        transform: translateZ(0) scale(1) translateY(0); 
        filter: brightness(1) contrast(1); 
    }
    30% { 
        transform: translateZ(0) scale(1.02) translateY(-2px); 
        filter: brightness(0.85) contrast(1.15); 
    }
    60% { 
        transform: translateZ(0) scale(1) translateY(0); 
        filter: brightness(1) contrast(1); 
    }
    80% { 
        transform: translateZ(0) scale(1.01) translateY(-1px); 
        filter: brightness(0.9) contrast(1.05); 
    }
}

.screen-breathing {
    animation: heavy-breathing 2.2s ease-in-out infinite;
    transform-origin: center center;
    will-change: transform, filter;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* --- Flash Transition Overlay (白闪转场) --- */
.flash-transition-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 50;
    background: rgba(255, 255, 255, 0);
    opacity: 0;
}

.flash-transition-active {
    animation: flash-strike 450ms ease-out forwards;
}

@keyframes flash-strike {
    0%   { opacity: 1; background: rgba(255, 255, 255, 0.95); }
    30%  { opacity: 0.8; background: rgba(255, 255, 255, 0.7); }
    100% { opacity: 0; background: rgba(255, 255, 255, 0); }
}

/* --- Slash Attack (刀光剑影) --- */
.slash-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 55;
    background: transparent;
    overflow: hidden;
}

.slash-overlay::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 250%; /* Make it long enough to cover diagonal */
    height: 4px;
    background: linear-gradient(to right, transparent 0%, rgba(255, 255, 255, 1) 40%, rgba(255, 255, 255, 1) 60%, transparent 100%);
    box-shadow: 0 0 20px 5px rgba(255, 255, 255, 0.8), 0 0 40px 10px rgba(200, 230, 255, 0.6);
    transform: translate(-50%, -50%) rotate(-35deg) scaleX(0);
    opacity: 0;
}

.slash-active::before {
    animation: slash-strike-anim 0.6s cubic-bezier(0.1, 0.9, 0.2, 1) forwards;
}

@keyframes slash-strike-anim {
    0% { transform: translate(-50%, -50%) rotate(-35deg) scaleX(0); opacity: 0; height: 1px; }
    20% { transform: translate(-50%, -50%) rotate(-35deg) scaleX(1); opacity: 1; height: 8px; filter: brightness(2); }
    50% { transform: translate(-50%, -50%) rotate(-35deg) scaleX(1); opacity: 0.8; height: 2px; filter: brightness(1.5); }
    100% { transform: translate(-50%, -50%) rotate(-35deg) scaleX(1); opacity: 0; height: 1px; }
}

@keyframes slash-shake-anim {
    0% { transform: translate(0, 0) scale(1.02); filter: brightness(1.5); }
    15% { transform: translate(-10px, 10px) scale(1.02); filter: brightness(1.2); }
    30% { transform: translate(10px, -10px) scale(1.02); }
    45% { transform: translate(-10px, -10px) scale(1.02); }
    60% { transform: translate(10px, 10px) scale(1.02); }
    75% { transform: translate(-5px, 5px) scale(1.02); }
    100% { transform: translate(0, 0) scale(1); filter: brightness(1); }
}

.screen-slash-shake {
    animation: slash-shake-anim 0.7s cubic-bezier(0.36, 0.07, 0.19, 0.97) forwards;
    transform-origin: center center;
}

/* --- Fading Consciousness (眼前发黑) --- */
.fading-consciousness-overlay {
    position: absolute;
    inset: -5%;
    pointer-events: none;
    z-index: 25;
    background: radial-gradient(circle at center, rgba(0,0,0,0.6) 0%, rgba(0,0,0,0.95) 80%, rgba(0,0,0,1) 100%);
    opacity: 0;
    transition: opacity 1.5s ease-in-out;
    will-change: opacity, backdrop-filter;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    transform: translateZ(0);
}

.fading-active {
    animation: blackout-pulse 4s ease-in-out infinite;
}

/* --- Heart Demon (心魔魅影) --- */
.heart-demon-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 25; /* Above background/characters, below UI */
    background: radial-gradient(ellipse at center, transparent 60%, rgba(139, 0, 139, 0.2) 85%, rgba(75, 0, 130, 0.7) 100%);
    box-shadow: inset 0 0 60px rgba(199, 21, 133, 0.4);
    opacity: 0;
    mix-blend-mode: multiply;
    transition: opacity 2s ease-in-out;
    /* 硬件加速：防止安卓设备由于 mix-blend-mode 和动画导致闪烁 */
    will-change: opacity, filter;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    transform: translateZ(0);
}

.heart-demon-active {
    opacity: 1;
    animation: demon-mist-pulse 4s cubic-bezier(0.4, 0, 0.2, 1) infinite alternate;
}

@keyframes demon-mist-pulse {
    0% { opacity: 0.7; filter: hue-rotate(0deg); box-shadow: inset 0 0 40px rgba(199, 21, 133, 0.3); }
    100% { opacity: 1; filter: hue-rotate(15deg); box-shadow: inset 0 0 80px rgba(199, 21, 133, 0.5); }
}

/* Wavy underwater distortion */
@keyframes demon-distortion {
    0% { 
        transform: translateZ(0) scale(1.02) skewX(0deg) skewY(0deg);
        filter: blur(0px) contrast(1);
    }
    33% { 
        transform: translateZ(0) scale(1.04) skewX(0.5deg) skewY(0.5deg);
        filter: blur(1px) contrast(1.1);
    }
    66% { 
        transform: translateZ(0) scale(1.02) skewX(-0.5deg) skewY(-0.5deg);
        filter: blur(0.5px) contrast(1.05);
    }
    100% { 
        transform: translateZ(0) scale(1.02) skewX(0deg) skewY(0deg);
        filter: blur(0px) contrast(1);
    }
}

.screen-demon-distortion {
    animation: demon-distortion 6s ease-in-out infinite;
    transform-origin: center center;
    /* 硬件加速：防止安卓设备重绘闪烁 */
    will-change: transform, filter;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* --- Waking Up Blur (视线失焦/大病初愈) --- */
@keyframes blur-wake-anim {
    0% { filter: blur(12px) brightness(0.2); }
    15% { filter: blur(8px) brightness(0.4); }
    25% { filter: blur(12px) brightness(0.2); } /* Blink closed */
    45% { filter: blur(5px) brightness(0.7); }
    55% { filter: blur(8px) brightness(0.4); } /* Blink closed slightly */
    100% { filter: blur(0px) brightness(1); }
}

.screen-blur-wake {
    animation: blur-wake-anim 5s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
    will-change: filter;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    transform: translateZ(0);
}

/* Eyelid cinematic mask (Eye Shape) */
@keyframes eyelid-anim {
    0% { height: 0%; opacity: 1; }
    15% { height: 25%; opacity: 1; }
    25% { height: 0%; opacity: 1; }
    45% { height: 60%; opacity: 0.9; }
    55% { height: 45%; opacity: 0.95; }
    100% { height: 180%; opacity: 0; }
}

.eyelid-mask {
    position: absolute; 
    top: 50%; left: 50%; 
    width: 150%;
/* 样式调整 */
    transform: translate(-50%, -50%);
    border-radius: 50%;
/* 100px 模糊让眼皮边缘有一种惺忪的虚化感，200vmax 扩张确保黑色填满外部屏幕 */
    box-shadow: 0 0 100px 200vmax #000; 
    background: transparent;
    z-index: 60; pointer-events: none;
    animation: eyelid-anim 5s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}

/* Base styles for particles... */

@keyframes blackout-pulse {
    0%, 100% { opacity: 0.3; backdrop-filter: blur(1px); }
/* 样式调整 */
    60% { opacity: 0.4; backdrop-filter: blur(2px); }
/* 禁止iOS长按菜单 */
}

/* 眩晕震荡 (Dizzy Sway) */
@keyframes dizzy-sway {
    0%, 100% { transform: translateZ(0) scale(1) rotate(0deg); }
    25% { transform: translateZ(0) scale(1.03) rotate(0.8deg); filter: blur(0.5px); }
    50% { transform: translateZ(0) scale(1) rotate(0deg); }
    75% { transform: translateZ(0) scale(1.02) rotate(-0.5deg); filter: blur(1px); }
}

.screen-dizzy {
    animation: dizzy-sway 5s ease-in-out infinite;
    transform-origin: center center;
    will-change: transform, filter;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* White Radial Flash (Blinding Sunlight Effect) */
.heavenly-beam {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at center, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0.9) 15%, rgba(255, 255, 255, 0.6) 35%, rgba(255, 255, 255, 0.3) 55%, transparent 80%);
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.8s cubic-bezier(0.22, 1, 0.36, 1);
    z-index: 15;
    pointer-events: none;
}

@keyframes float-dust {
    0% { transform: translate(0, 0); opacity: 0; }
    20% { opacity: 0.6; }
    80% { opacity: 0.6; }
    100% { transform: translate(calc(var(--tx) * 50px), calc(var(--ty) * 100px)); opacity: 0; }
}

@keyframes float-sakura {
    0% { transform: translate(0, -10vh) rotate(0deg); opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { transform: translate(calc(var(--tx) * 30vw), 110vh) rotate(360deg); opacity: 0; }
}

@keyframes fall-snow {
    0% { transform: translate(0, -10vh); opacity: 0; }
    10% { opacity: 0.8; }
    90% { opacity: 0.8; }
    100% { transform: translate(calc(var(--tx) * 10vw), 110vh); opacity: 0; }
}

@keyframes fall-rain {
    0% { transform: translate(0, -10vh) rotate(15deg); opacity: 0; }
    10% { opacity: 0.6; }
    90% { opacity: 0.6; }
    100% { transform: translate(-10vw, 110vh) rotate(15deg); opacity: 0; }
}

@keyframes float-ember {
    0% { transform: translate(0, 110vh); opacity: 0; }
    20% { opacity: 1; }
    80% { opacity: 0.8; }
    100% { transform: translate(calc(var(--tx) * 20vw), -10vh); opacity: 0; }
}

@keyframes rise-speedline {
    0% { transform: translateY(110vh); opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { transform: translateY(-30vh); opacity: 0; }
}

/* --- Particle Styles --- */
.particle-base {
    position: absolute;
    pointer-events: none;
    z-index: 15; 
}

.particle-dust {
    background: radial-gradient(circle, rgba(255,255,255,0.8) 0%, rgba(255,255,255,0) 70%);
    border-radius: 50%;
    animation: float-dust var(--dur) linear infinite;
}

.particle-sakura {
    background-color: #ffb7c5;
    border-radius: 100% 0 100% 0;
    box-shadow: 0 0 5px #ffb7c5;
    animation: float-sakura var(--dur) linear infinite;
}

.particle-snow {
    background-color: white;
    border-radius: 50%;
    box-shadow: 0 0 8px white;
    animation: fall-snow var(--dur) linear infinite;
}

.particle-rain {
    background: linear-gradient(to bottom, rgba(255,255,255,0), rgba(255,255,255,0.8));
    width: 2px !important;
    border-radius: 0;
    animation: fall-rain var(--dur) linear infinite;
}

.particle-ember {
    background: radial-gradient(circle, rgba(255,200,50,1) 0%, rgba(255,50,0,0.8) 40%, rgba(255,0,0,0) 80%);
    border-radius: 50%;
    mix-blend-mode: screen;
    animation: float-ember var(--dur) linear infinite;
}

.particle-speedline {
    background: linear-gradient(to top, rgba(255,255,255,0), rgba(255,255,255,0.7) 50%, rgba(255,255,255,0));
    border-radius: 0;
    box-shadow: 0 0 4px rgba(255,255,255,0.3);
    animation: rise-speedline var(--dur) linear infinite;
}

.fade-exit-active {
    opacity: 0;
    transition: opacity 300ms ease-in;
}

.dialogue-glass {
    background: rgba(13, 13, 26, 0.75);
    border-width: 1px;
    border-style: solid;
    /* border-color is dynamically controlled by JS/Tailwind */
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5), inset 0 0 10px rgba(148, 163, 184, 0.05);
}

/* 对话框文字 — 基准字号 × 缩放倍率（玩家可在设置中调节） */
.dialogue-text {
    font-size: calc(0.75rem * var(--dialogue-font-scale, 1));  /* 手机默认 = text-xs */
}
@media (min-width: 768px) {
    .dialogue-text {
        font-size: calc(1.125rem * var(--dialogue-font-scale, 1)); /* md:text-lg */
    }
}
@media (min-width: 1024px) {
    .dialogue-text {
        font-size: calc(1.5rem * var(--dialogue-font-scale, 1));   /* lg:text-2xl */
    }
}

/* 对话框盒子高度随字号缩放（覆盖 Tailwind 的 h-20/h-32/h-52 固定类） */
.dialogue-glass {
    height: calc(5rem * var(--dialogue-font-scale, 1)) !important;
}
@media (min-width: 768px) {
    .dialogue-glass {
        height: calc(8rem * var(--dialogue-font-scale, 1)) !important;
    }
}
@media (min-width: 1024px) {
    .dialogue-glass {
        height: calc(13rem * var(--dialogue-font-scale, 1)) !important;
    }
}


/* 角色立绘位置与动画 */
.char-sprite {
    transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    filter: drop-shadow(0 0 10px rgba(0, 0, 0, 0.3));
}

/* 手机竖屏时立绘高度适配 */
@media (orientation: portrait) {
    .char-sprite {
        height: 83% !important;
    }
}

/* 心魔发光特效 */
@keyframes demon-glow {
    0%, 100% {
        filter: 
            drop-shadow(0 0 15px #1a0033)
            drop-shadow(0 0 40px #000)
            drop-shadow(0 0 80px #120024);
    }
    50% {
        filter: 
            drop-shadow(0 0 25px #3b0066)
            drop-shadow(0 0 60px #000)
            drop-shadow(0 0 100px #21003d);
    }
}

.demon-aura {
    animation: demon-glow 2.5s ease-in-out infinite;
}

/* Character Entrance Animation */
@keyframes char-slide-up {
    0% {
        opacity: 0;
        transform: translateY(20px) scale(0.98);
    }

    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.char-enter-anim {
    animation: char-slide-up 0.6s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

/* Button Bloom & Hover Effects */
.btn-bloom {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    background-clip: padding-box;
    z-index: 10;
}

.btn-bloom:hover {
    text-shadow: 0 0 8px rgba(103, 232, 249, 0.8);
    transform: translateY(-1px);
}

/* Bloom Circle Effect */
.btn-bloom:after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: radial-gradient(circle, rgba(103, 232, 249, 0.3) 0%, transparent 70%);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.4s ease-out, height 0.4s ease-out;
    z-index: -1;
    pointer-events: none;
}

.btn-bloom:hover:after {
    width: 200%;
    height: 200%;
}

.btn-bloom svg {
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.btn-bloom:hover svg {
    transform: scale(1.15);
    filter: drop-shadow(0 0 4px rgba(103, 232, 249, 0.6));
}

/* 屏幕震动动画 */
@keyframes shake {

    0%,
    100% {
        transform: translateX(0) translateY(0);
    }

    10% {
        transform: translateX(-8px) translateY(-2px) rotate(-0.5deg);
    }

    20% {
        transform: translateX(8px) translateY(2px) rotate(0.5deg);
    }

    30% {
        transform: translateX(-6px) translateY(-1px) rotate(-0.3deg);
    }

    40% {
        transform: translateX(6px) translateY(1px) rotate(0.3deg);
    }

    50% {
        transform: translateX(-4px) translateY(-1px) rotate(-0.2deg);
    }

    60% {
        transform: translateX(4px) translateY(1px) rotate(0.2deg);
    }

    70% {
        transform: translateX(-2px) translateY(0) rotate(-0.1deg);
    }

    80% {
        transform: translateX(2px) translateY(0) rotate(0.1deg);
    }

    90% {
        transform: translateX(-1px) translateY(0);
    }
}

.screen-shake {
    animation: shake 0.6s ease-in-out;
}

/* 有节奏的持续震动动画 */
@keyframes rhythm-shake {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(3px);
    }
}

.screen-rhythm {
    animation: rhythm-shake 0.5s ease-in-out infinite;
}

/* 垂直极速下坠（剧烈高频震动） */
@keyframes falling-jitter {
    0% { transform: translateY(0); }
    50% { transform: translateY(4px); }
    100% { transform: translateY(0); }
}

.screen-falling {
    animation: falling-jitter 0.08s linear infinite;
}

/* 移动端优化：确保全屏高度 */
#app-root {
    height: 100vh;
    /* fallback */
    height: 100dvh;
}

/* 对话框包装器基准样式 */
.dialogue-wrapper {
    width: 100%;
    max-width: 56rem; /* Tailwind max-w-4xl */
    padding-left: 1rem; /* Tailwind px-4 */
    padding-right: 1rem;
}

/* 全平台横屏铺满适配 */
@media (orientation: landscape) {
    .dialogue-wrapper {
        width: 70%;
        padding-left: 0;
        padding-right: 0;
    }
}

/* 手机横屏高度极小的适配 */
@media (max-height: 500px) and (orientation: landscape) {
    .mobile-landscape-title {
        font-size: 1.8rem !important;
        line-height: 1.2 !important;
    }

    .mobile-landscape-btn {
        padding-top: 0.3rem !important;
        padding-bottom: 0.3rem !important;
        font-size: 1rem !important;
    }

    .mobile-landscape-gap {
        gap: 0.5rem !important;
        margin-top: 0.5rem !important;
    }

    /* === Ending Screen: Unified Responsive Styles === */
    
    /* Mobile Landscape: Compact the ending card */
    .ending-card {
        padding: 0.5rem 1.5rem !important;
        max-width: 95vw !important;
        gap: 0 !important;
    }
    
    .ending-card .ending-title {
        font-size: 1.1rem !important;
        margin-bottom: 0 !important;
    }

    .ending-card .ending-text {
        font-size: 0.8rem !important;
        white-space: nowrap !important;
    }

    .ending-card .ending-btn {
        padding: 0.3rem 1.5rem !important;
        font-size: 0.75rem !important;
    }
    
    .ending-card .ending-deco-line,
    .ending-card .w-12 {
        margin-top: 0.25rem !important;
        margin-bottom: 0.25rem !important;
    }

    /* 手机横屏：对话框进一步压缩 */
    .dialogue-glass {
        height: calc(4.8rem * var(--dialogue-font-scale, 1)) !important;
        /* Slightly increased height */
        padding: 0.4rem 0.6rem !important;
        /* Increased padding */
    }

    .dialogue-glass>div:first-child {
        padding-top: 0 !important;
    }

    .dialogue-glass p {
        font-size: calc(0.8rem * var(--dialogue-font-scale)) !important;
        line-height: 1.3 !important;
        margin-top: -0.1rem !important;
    }

    /* 手机横屏：隐藏菜单文字 */
    .menu-label {
        display: none !important;
    }

    /* 手机横屏：音量按钮位置调整 */
    .volume-btn-mobile {
        top: 0.2rem !important;
        right: 0.2rem !important;
        padding: 0.25rem !important;
    }

    /* 手机横屏：快捷菜单位置调整 */
    .mobile-landscape-bottom-adjust {
        bottom: 5rem !important;
        right: 0.5rem !important;
        gap: 0.5rem !important;
    }

    /* 手机横屏：存档界面强制2列 */
    .mobile-landscape-grid-2 {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}

/* 手机竖屏时立绘高度适配 */
@media (orientation: portrait) {
    /* 手机竖屏：对话框进一步压缩 */
    .dialogue-glass {
        /* 手机竖屏尺寸微调 */
        padding: 0.25rem 0.6rem !important; 
        height: calc(3.8rem * var(--dialogue-font-scale, 1)) !important;
    }
    .dialogue-glass p {
        font-size: calc(0.8rem * var(--dialogue-font-scale)) !important;
        line-height: 1.3 !important;
    }
    
    @media (min-width: 768px) {
        .dialogue-glass {
            height: calc(6.4rem * var(--dialogue-font-scale, 1)) !important; /* 缩小版 md 128px -> 102.4px */
        }
    }
    @media (min-width: 1024px) {
        .dialogue-glass {
            height: calc(10.4rem * var(--dialogue-font-scale, 1)) !important; /* 缩小版 lg 208px -> 166.4px */
        }
    }

    /* 开始画面 - 极度压缩 */
    .mobile-landscape-title {
        font-size: 1.5rem !important;
        margin-top: 0.5rem !important;
        line-height: 1.1 !important;
    }
    .mobile-landscape-btn {
        padding-top: 0.2rem !important;
        padding-bottom: 0.2rem !important;
        font-size: 0.85rem !important;
    }
    .mobile-landscape-gap {
        gap: 0.3rem !important;
        margin-top: 0.2rem !important;
    }

    /* 结局画面 - 极度压缩 */
    .ending-card {
        padding: 0.25rem 1rem !important;
        gap: 0 !important;
    }
    .ending-card .ending-title {
        font-size: 1.1rem !important;
        margin-bottom: 0 !important;
    }
    .ending-card .text-base { /* subtitle */
        font-size: 0.75rem !important;
        margin-top: 0.1rem !important;
        margin-bottom: 0 !important;
    }
    .ending-card .ending-text {
        font-size: 0.75rem !important;
        margin-top: 0.2rem !important;
        margin-bottom: 0.2rem !important;
        line-height: 1.2 !important;
    }
    .ending-card .ending-deco-line,
    .ending-card .w-12,
    .ending-card .w-16 {
        margin-top: 0.2rem !important;
        margin-bottom: 0.2rem !important;
        height: 1px !important;
    }
    .ending-card .ending-btn {
        padding: 0.2rem 1rem !important;
        font-size: 0.75rem !important;
    }

    /* 选项画面 - 极度压缩 */
    #screen-choice {
        flex-direction: column !important;
        justify-content: center !important;
        align-items: center !important;
    }
    #screen-choice .choice-btn-container {
        padding: 0.5rem 1rem !important;
        gap: 0.25rem !important;
        height: 100% !important;
        overflow-y: auto !important;
    }
    #screen-choice h2 {
        font-size: 0.9rem !important;
        line-height: 1.1 !important;
        margin-bottom: 0 !important;
    }
    #screen-choice .choice-options-wrap {
        gap: 0.25rem !important;
    }
    #screen-choice .choice-btn {
        padding: 0 !important;
        min-height: 0 !important;
    }
    #screen-choice .choice-btn > div:nth-child(3) {
        padding: 0.25rem 1rem !important;
    }
    #screen-choice .choice-btn span {
        font-size: 0.75rem !important;
    }
    /* 选项画面 - 极度压缩 */
    #screen-choice .w-12, #screen-choice .w-8, #screen-choice .w-20, #screen-choice .w-16 {
        display: none !important;
    }
}

/* 防盗图增强：禁止图片拖拽和长按 */
img {
    pointer-events: none;
    /* 让点击穿透，防止长按单独选中图片 */
    -webkit-user-drag: none;
/* 全局禁止选择文本（可选，增强保护） */
    user-select: none;
    -webkit-touch-callout: none;
/* 禁止iOS长按菜单 */
}

/* 全局禁止移动端长按系统菜单 */
body {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    /* 全局禁止选择文本（可选，增强保护） */
    user-select: none;
}

/* --- IMMERSIVE CHOICE MODAL STYLES --- */
.choice-btn-container {
    perspective: 1000px;
}

.choice-btn {
    position: relative;
    transform-style: preserve-3d;
    transition: all 0.5s cubic-bezier(0.23, 1, 0.32, 1);
}

/* Ink Stroke Hover Effect 窶・pure CSS (no external image dependency) */
.choice-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 120%;
    height: 120%;
    background:
        radial-gradient(ellipse 60% 40% at 20% 50%, rgba(148,163,184,0.25) 0%, transparent 70%),
        radial-gradient(ellipse 50% 60% at 80% 40%, rgba(148,163,184,0.2) 0%, transparent 65%),
        radial-gradient(ellipse 90% 30% at 50% 55%, rgba(148,163,184,0.15) 0%, transparent 80%);
    opacity: 0;
    transform: translate(-50%, -50%) scaleX(0);
    transition: all 0.4s ease-out;
    pointer-events: none;
    mix-blend-mode: screen;
    z-index: -1;
}

.choice-btn:hover::before {
    opacity: 0.15;
    transform: translate(-50%, -50%) scaleX(1);
}

.choice-btn:hover {
    transform: translateX(10px);
    padding-left: 2rem;
}

/* Staggered Fade In Animation */
@keyframes fadeInUpStagger {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Choice Modal Mobile Landscape Fixes --- */
@media (max-height: 500px) and (orientation: landscape) {

    /* Wrapper: Flex column starting from top with scroll */
    #screen-choice {
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important;
        align-items: center !important;
        overflow-y: auto !important;
    }

    /* Container: compact spacing */
    #screen-choice .choice-btn-container {
        height: auto !important;
        min-height: 0 !important;
        padding: 0.5rem 2rem !important;
        gap: 0.5rem !important;
    }

    #screen-choice h2 {
        font-size: 1rem !important;
        line-height: 1.3 !important;
        margin-bottom: 0 !important;
    }

    #screen-choice .choice-btn {
        min-height: 0 !important;
    }
    
    #screen-choice .choice-btn > div:nth-child(3) {
        padding: 0.35rem 1.2rem !important;
    }

    #screen-choice .choice-btn span {
        font-size: 0.8rem !important;
    }

    /* Shrink-wrap the options container */
    .choice-options-wrap {
        width: max-content !important;
        max-width: 90vw !important;
        margin: 0 auto !important;
        gap: 0.5rem !important;
    }
    
    /* Hide decorative dividers in compact mode */
    #screen-choice .w-12,
    #screen-choice .w-8 {
        display: none !important;
    }
}

/* --- Touch Devices (Mobiles and Tablets) Global Fix --- */
@media (hover: none) and (pointer: coarse) {
    /* Always show the rollback hint on touch devices since they can't hover */
    .rollback-hint {
        opacity: 0.8 !important;
        transform: scale(1) !important;
    }
    
    /* Always show the active indigo border on entries that can be rolled back to on touch devices */
    .rollback-text[data-hassnapshot="true"] {
        border-color: rgba(99, 102, 241, 0.5) !important; /* Tailwind border-indigo-500/50 */
    }
}

/* --- Premium Frontend Optimizations --- */

/* 1. Theme-Specific Ink Scrollbar */
.custom-scroll::-webkit-scrollbar {
    width: 6px;
}
.custom-scroll::-webkit-scrollbar-track {
    background: rgba(13, 13, 26, 0.3);
}

/* Frosted Ink Locked States */
.locked-card {
    filter: grayscale(1) contrast(0.8);
    background: rgba(15, 23, 42, 0.4) !important;
    border-color: rgba(51, 65, 85, 0.2) !important;
    box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.4);
}

.locked-card::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, transparent, rgba(0,0,0,0.2));
    pointer-events: none;
}

/* Glass Refraction Effect for Unlocked Cards */
.silk-card:not(.locked-card):hover {
    box-shadow: 
        0 20px 40px rgba(0,0,0,0.4),
        0 0 1px 1px rgba(148, 163, 184, 0.2),
        inset 0 0 20px rgba(148, 163, 184, 0.1);
}

/* --- Improved Scrollbar thumb appearance --- */
.custom-scroll::-webkit-scrollbar-thumb {
    background: linear-gradient(to bottom, 
        rgba(148, 163, 184, 0.1), 
        rgba(148, 163, 184, 0.4) 50%, 
        rgba(148, 163, 184, 0.1)
    );
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: content-box;
}
.custom-scroll::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.6);
}

/* 3. Silk-Border Card Decoration */
.silk-card {
    position: relative;
    overflow: hidden;
}

.silk-card::before {
    content: '';
    position: absolute;
    inset: 0;
    border: 1px solid rgba(148, 163, 184, 0.1);
    pointer-events: none;
    z-index: 10;
}

.silk-card:hover::before {
    border-color: rgba(148, 163, 184, 0.3);
    box-shadow: inset 0 0 15px rgba(148, 163, 184, 0.05);
}

/* Gold Accent for Titles */
.gold-glow {
    text-shadow: 0 0 20px rgba(251, 191, 36, 0.2);
}

/* Staggered entrance for cards */
.stagger-item {
    opacity: 0;
    animation: slideUpFade 0.6s ease-out forwards;
}

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

/* === Ending Screen: Glass Card Base === */
.ending-card {
    background: linear-gradient(135deg, rgba(15,23,42,0.4) 0%, rgba(15,23,42,0.15) 100%);
    border: 1px solid rgba(148, 163, 184, 0.12);
    border-radius: 2px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 
        0 25px 60px rgba(0,0,0,0.5),
        inset 0 0 60px rgba(0,0,0,0.15),
        0 0 1px 0 rgba(148,163,184,0.15);
}

/* Ending button hover glow */
.ending-btn:hover {
    box-shadow: 0 0 20px rgba(148,163,184,0.1), 0 0 2px rgba(148,163,184,0.2);
}

/* Sequenced Entrance Animation */
@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* === Choice Screen: Premium Button Styles === */
.choice-btn-glass {
    background: linear-gradient(135deg, rgba(15,23,42,0.35) 0%, rgba(30,41,59,0.2) 100%);
    border: 1px solid rgba(148,163,184,0.1);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.choice-btn:hover .choice-btn-glass {
    background: linear-gradient(135deg, rgba(30,41,59,0.5) 0%, rgba(51,65,85,0.3) 100%);
    border-color: rgba(148,163,184,0.2);
    box-shadow: 
        0 8px 32px rgba(0,0,0,0.3),
        inset 0 0 20px rgba(148,163,184,0.03);
}

/* Accent Bars */
.choice-accent-bar {
    background: linear-gradient(to bottom, transparent, rgba(148,163,184,0.15), transparent);
}
.choice-btn:hover .choice-accent-bar {
    background: linear-gradient(to bottom, transparent, rgba(251,191,36,0.5), transparent);
    box-shadow: 0 0 8px rgba(251,191,36,0.15);
}

.choice-accent-bar-right {
    background: linear-gradient(to bottom, transparent, rgba(148,163,184,0.15), transparent);
}
.choice-btn:hover .choice-accent-bar-right {
    background: linear-gradient(to bottom, transparent, rgba(251,191,36,0.5), transparent);
    box-shadow: 0 0 8px rgba(251,191,36,0.15);
}

/* === Touch Device: Choice Button Enhancements === */
@media (hover: none) and (pointer: coarse) {
    /* Always show gold accent bars on touch devices */
    .choice-accent-bar {
        background: linear-gradient(to bottom, transparent, rgba(251,191,36,0.35), transparent) !important;
    }
    .choice-accent-bar-right {
        background: linear-gradient(to bottom, transparent, rgba(251,191,36,0.35), transparent) !important;
    }
    
    /* Slightly enhanced glass panel for visual richness */
    .choice-btn-glass {
        border-color: rgba(148,163,184,0.15) !important;
    }

    /* Tap feedback: brief scale + flash */
    .choice-btn:active .choice-btn-glass {
        background: linear-gradient(135deg, rgba(30,41,59,0.6) 0%, rgba(51,65,85,0.4) 100%) !important;
        border-color: rgba(251,191,36,0.3) !important;
        box-shadow: 0 0 20px rgba(251,191,36,0.08) !important;
    }
    .choice-btn:active {
        transform: scale(0.97) !important;
        transition: transform 0.1s ease-out !important;
    }
    .choice-btn:active .choice-accent-bar,
    .choice-btn:active .choice-accent-bar-right {
        background: linear-gradient(to bottom, transparent, rgba(251,191,36,0.7), transparent) !important;
        box-shadow: 0 0 12px rgba(251,191,36,0.25) !important;
    }

    /* Same for ending buttons */
    .ending-btn:active {
        transform: scale(0.97) !important;
        transition: transform 0.1s ease-out !important;
        box-shadow: 0 0 20px rgba(148,163,184,0.15) !important;
    }
}

/* --- 手机端沉浸式隐藏按钮 (方案3) --- */
@media (max-width: 767px), (max-height: 500px) and (orientation: landscape) {
    .mobile-immersive-btns {
        opacity: 0.15 !important;
        /* 文字播放完无操作1.5秒逐渐淡出体验更好 */
        transition: opacity 1.5s ease-in-out !important; 
    }
    /* 打字时始终亮起，或者手指按住/触摸对话框主体时全部亮起 */
    .dialogue-glass.is-typing .mobile-immersive-btns,
    .dialogue-glass:active .mobile-immersive-btns,
    .mobile-immersive-btns:active {
        opacity: 1 !important;
        transition: opacity 0.2s ease-out !important; /* 迅速点亮 */
    }
}

/* --- iOS PWA 安全区域适配 --- */
/* 在 standalone (PWA) 模式下，viewport-fit=cover + black-translucent 会让内容
   延伸到状态栏下方。此规则给全屏面板加上安全区域 padding 防止文字被遮挡。 */
@supports (padding-top: env(safe-area-inset-top)) {
    .safe-area-screen {
        padding-top: calc(env(safe-area-inset-top) + 1rem) !important;
        padding-bottom: calc(env(safe-area-inset-bottom) + 1rem) !important;
        padding-left: calc(env(safe-area-inset-left) + 1rem) !important;
        padding-right: calc(env(safe-area-inset-right) + 1rem) !important;
    }

    @media (min-width: 768px) {
        .safe-area-screen {
            padding-top: calc(env(safe-area-inset-top) + 2rem) !important;
            padding-bottom: calc(env(safe-area-inset-bottom) + 2rem) !important;
            padding-left: calc(env(safe-area-inset-left) + 2rem) !important;
            padding-right: calc(env(safe-area-inset-right) + 2rem) !important;
        }
    }
}

/* --- CG 全屏查看器安全区域适配 --- */
/* CG 画廊点击查看大图时，图片和控制按钮需要避开刘海/药丸区域 */
@supports (padding-top: env(safe-area-inset-top)) {
    .cg-viewer-overlay {
        padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    }

    .cg-viewer-overlay > img {
        max-width: calc(100% - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)) !important;
        max-height: calc(100% - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) !important;
    }
}
