:root {
    --bg-color: #8b0000;
    /* 初始喜庆红 */
    --text-color: #ffd700;
    /* 金色文字 */
    --glitch-color-1: #00ffff;
    --glitch-color-2: #ff00ff;
    --error-color: #ff0000;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Arial', sans-serif;
    /* 初始正常字体 */
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    text-transform: uppercase;
    position: relative;
    transition: background-color 2s ease;
}

/* CRT 扫描线效果 - 初始隐藏 */
#scanline {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to bottom,
            rgba(255, 255, 255, 0),
            rgba(255, 255, 255, 0) 50%,
            rgba(0, 0, 0, 0.2) 50%,
            rgba(0, 0, 0, 0.2));
    background-size: 100% 4px;
    z-index: 10;
    pointer-events: none;
    animation: scanlineAnim 10s linear infinite;
    opacity: 0;
    /* 初始不可见 */
    transition: opacity 2s;
}

/* 噪点效果 - 初始隐藏 */
#noise {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url('data:image/svg+xml;utf8,%3Csvg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"%3E%3Cfilter id="noiseFilter"%3E%3CfeTurbulence type="fractalNoise" baseFrequency="0.65" numOctaves="3" stitchTiles="stitch"/%3E%3C/filter%3E%3Crect width="100%25" height="100%25" filter="url(%23noiseFilter)" opacity="0.1"/%3E%3C/svg%3E');
    z-index: 9;
    opacity: 0;
    /* 初始不可见 */
    pointer-events: none;
    animation: noiseAnim 0.5s steps(10) infinite;
    transition: opacity 2s;
}

.container {
    text-align: center;
    z-index: 20;
    position: relative;
    /* filter: blur(0.5px); 移除初始模糊 */
}

#title {
    font-size: 3rem;
    letter-spacing: 0.2rem;
    margin-bottom: 10px;
    opacity: 1;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.date-display {
    font-size: 2.5rem;
    margin-bottom: 20px;
    color: var(--text-color);
    letter-spacing: 5px;
    text-shadow: 0 0 5px rgba(255, 215, 0, 0.5);
    /* 金色发光 */
}

#timer {
    font-size: 10rem;
    font-weight: bold;
    position: relative;
    color: var(--text-color);
    text-shadow: 4px 4px 8px rgba(0, 0, 0, 0.3);
}

/* 故障文字效果 */
.glitch {
    position: relative;
}

/* 只有当添加 .active-glitch 类时才启用故障效果 */
.active-glitch.glitch::before,
.active-glitch.glitch::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-color);
}

.active-glitch.glitch::before {
    left: 2px;
    text-shadow: -1px 0 var(--error-color);
    clip: rect(24px, 550px, 90px, 0);
    animation: glitch-anim-2 3s infinite linear alternate-reverse;
}

.active-glitch.glitch::after {
    left: -2px;
    text-shadow: -1px 0 var(--glitch-color-1);
    clip: rect(85px, 550px, 140px, 0);
    animation: glitch-anim-1 2.5s infinite linear alternate-reverse;
}

#error-msg {
    margin-top: 30px;
    color: var(--error-color);
    font-size: 1.5rem;
    text-align: left;
    border: 1px solid var(--error-color);
    padding: 20px;
    background: rgba(0, 0, 0, 0.8);
    box-shadow: 0 0 20px rgba(255, 0, 0, 0.3);
    font-family: 'Courier New', monospace;
    display: none;
    /* 初始隐藏 */
}

/* 通用隐藏类 */
.hidden {
    display: none !important;
}

/* 启动屏幕 - 喜庆风格 */
#start-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #8b0000 0%, #ff4500 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    cursor: pointer;
}

#start-screen.hidden {
    display: none;
}

/* 信息按钮 */
#info-btn {
    position: fixed;
    top: 20px;
    left: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.5);
    color: white;
    font-size: 20px;
    cursor: pointer;
    z-index: 2000;
    transition: all 0.3s;
}

#info-btn:hover {
    background: rgba(255, 255, 255, 0.4);
}

#info-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2100;
}

.modal-content {
    background: #333;
    padding: 30px;
    border-radius: 10px;
    color: #fff;
    max-width: 400px;
    text-align: center;
    border: 1px solid #555;
    font-family: sans-serif;
    /* 保持易读性 */
    text-transform: none;
}

.modal-content h3 {
    margin-bottom: 15px;
    color: #ffd700;
}

.modal-content p {
    margin-bottom: 15px;
    line-height: 1.5;
}

.modal-content button {
    padding: 8px 20px;
    background: #555;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
}

.modal-content button:hover {
    background: #666;
}

.start-content {
    text-align: center;
    animation: pulse 2s infinite;
    color: #ffd700;
}

.start-content h1 {
    font-size: 4rem;
    margin-bottom: 1rem;
    color: #ffd700;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.start-content p {
    font-size: 1.5rem;
    color: #fff;
    opacity: 0.9;
}

@keyframes pulse {
    0% {
        opacity: 0.8;
        transform: scale(0.98);
    }

    50% {
        opacity: 1;
        transform: scale(1.02);
    }

    100% {
        opacity: 0.8;
        transform: scale(0.98);
    }
}

#error-msg.visible {
    display: block;
    animation: shake 0.5s cubic-bezier(.36, .07, .19, .97) both;
}

#scare-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: black;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    display: none;
}

/* 动画定义 */
@keyframes scanlineAnim {
    0% {
        transform: translateY(0);
    }

    100% {
        transform: translateY(4px);
    }
}

@keyframes noiseAnim {
    0% {
        transform: translate(0, 0);
    }

    10% {
        transform: translate(-5%, -5%);
    }

    20% {
        transform: translate(-10%, 5%);
    }

    30% {
        transform: translate(5%, -10%);
    }

    40% {
        transform: translate(-5%, 15%);
    }

    50% {
        transform: translate(-10%, 5%);
    }

    60% {
        transform: translate(15%, 0);
    }

    70% {
        transform: translate(0, 10%);
    }

    80% {
        transform: translate(-15%, 0);
    }

    90% {
        transform: translate(10%, 5%);
    }

    100% {
        transform: translate(5%, 0);
    }
}

@keyframes glitch-anim-1 {
    0% {
        clip: rect(20px, 9999px, 80px, 0);
    }

    20% {
        clip: rect(100px, 9999px, 160px, 0);
    }

    40% {
        clip: rect(50px, 9999px, 20px, 0);
    }

    60% {
        clip: rect(10px, 9999px, 120px, 0);
    }

    80% {
        clip: rect(140px, 9999px, 90px, 0);
    }

    100% {
        clip: rect(60px, 9999px, 30px, 0);
    }
}

@keyframes glitch-anim-2 {
    0% {
        clip: rect(120px, 9999px, 15px, 0);
    }

    20% {
        clip: rect(10px, 9999px, 90px, 0);
    }

    40% {
        clip: rect(150px, 9999px, 50px, 0);
    }

    60% {
        clip: rect(60px, 9999px, 10px, 0);
    }

    80% {
        clip: rect(30px, 9999px, 140px, 0);
    }

    100% {
        clip: rect(90px, 9999px, 70px, 0);
    }
}

@keyframes shake {

    10%,
    90% {
        transform: translate3d(-1px, 0, 0);
    }

    20%,
    80% {
        transform: translate3d(2px, 0, 0);
    }

    30%,
    50%,
    70% {
        transform: translate3d(-4px, 0, 0);
    }

    40%,
    60% {
        transform: translate3d(4px, 0, 0);
    }
}

/* 跨年失败时的样式 */
body.failed {
    background-color: #000;
    /* 变黑 */
    font-family: 'VT323', monospace;
    /* 变回恐怖字体 */
    color: #e0e0e0;
    /* 灰色文字 */
}

/* 逐渐崩坏的阶段 */
body.decay-1 {
    animation: decay1-anim 2s infinite alternate;
}

@keyframes decay1-anim {
    0% {
        filter: sepia(0.3) hue-rotate(0deg);
    }

    100% {
        filter: sepia(0.6) hue-rotate(-10deg) blur(0.5px);
    }
}

body.decay-2 {
    filter: grayscale(1) contrast(2);
    animation: decay2-flash 0.2s infinite;
}

@keyframes decay2-flash {

    0%,
    90% {
        background-color: #000;
    }

    95% {
        background-color: #300;
    }

    /* 偶尔闪红 */
    100% {
        background-color: #000;
    }
}

body.decay-3 {
    animation: decay3-chaos 0.1s infinite;
}

@keyframes decay3-chaos {
    0% {
        filter: invert(1) hue-rotate(0deg);
        transform: scale(1) translate(0, 0);
    }

    25% {
        filter: invert(0.8) hue-rotate(90deg);
        transform: scale(1.02) translate(2px, -2px);
    }

    50% {
        filter: invert(1) hue-rotate(180deg);
        transform: scale(0.98) translate(-2px, 2px);
    }

    75% {
        filter: invert(0.9) hue-rotate(270deg);
        transform: scale(1.01) translate(1px, 1px);
    }

    100% {
        filter: invert(1) hue-rotate(360deg);
        transform: scale(1) translate(0, 0);
    }
}

/* 阶段2时的文字效果 */
body.decay-2 #timer {
    text-shadow: 4px 0 #fff, -4px 0 #000;
}

/* 阶段3时的文字彻底崩坏 */
body.decay-3 #timer,
body.decay-3 .date-display {
    font-family: 'Creepster', cursive;
    letter-spacing: -10px;
    animation: text-chaos 0.05s infinite;
}

@keyframes text-chaos {
    0% {
        transform: skew(0deg);
        opacity: 1;
    }

    50% {
        transform: skew(20deg);
        opacity: 0.5;
    }

    100% {
        transform: skew(-20deg);
        opacity: 0.8;
    }
}

.glitch-heavy {
    animation: heavy-glitch 0.2s infinite;
}

@keyframes heavy-glitch {
    0% {
        transform: translate(2px, 2px);
    }

    25% {
        transform: translate(-2px, -2px);
    }

    50% {
        transform: translate(-2px, 2px);
    }

    75% {
        transform: translate(2px, -2px);
    }

    100% {
        transform: translate(2px, 2px);
    }
}

/* 移动端适配 */
@media (max-width: 768px) {
    #timer {
        font-size: 5rem;
    }

    body.failed #timer {
        font-size: 4rem;
    }

    #title {
        font-size: 1.5rem;
    }

    .start-content h1 {
        font-size: 2rem;
    }

    #error-msg {
        font-size: 1rem;
        padding: 15px;
        width: 90%;
        margin: 20px auto;
    }
}