/* style.css */
:root {
    /* 色彩變數 */
    --bg-color-start: #0a0b10;
    /* 極深的夜空黑 */
    --bg-color-mid: #0f1626;
    /* 深邃星空藍 */
    --bg-color-cold: #1a2530;
    /* 階段3過渡：黯淡的冰原灰藍 */

    --text-primary: #e0e6ed;
    --text-secondary: #9aa8b8;

    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-glow: rgba(255, 255, 255, 0.2);

    --error-glow: rgba(255, 75, 75, 0.4);

    /* Code Colors */
    --code-keyword: #c678dd;
    --code-var: #e5c07b;
    --code-comment: #7f848e;
    --code-error: #e06c75;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color-start);
    background-image: linear-gradient(135deg, var(--bg-color-start) 0%, var(--bg-color-mid) 100%);
    color: var(--text-primary);
    font-family: 'Noto Serif TC', serif;
    /* 預設內容使用明體帶出情感 */
    overflow: hidden;
    /* 預設鎖住滾動 */
    transition: background-image 3s ease, background-color 3s ease;
    min-height: 100vh;
}

body.cold-theme {
    background-color: var(--bg-color-cold);
    background-image: linear-gradient(135deg, var(--bg-color-start) 0%, var(--bg-color-cold) 100%);
}

#particle-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    pointer-events: none;
    overflow: hidden;
}

.particle {
    position: absolute;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.8);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
    opacity: 0;
    animation: fadeAndFloat linear infinite;
    transition: opacity 2s ease;
}

.particle.dimmed {
    opacity: 0.1 !important;
    animation-duration: 20s !important;
    /* 變慢 */
}

@keyframes fadeAndFloat {
    0% {
        opacity: 0;
        transform: translateY(0) scale(0.8);
    }

    20% {
        opacity: 0.8;
    }

    80% {
        opacity: 0.5;
    }

    100% {
        opacity: 0;
        transform: translateY(-20vh) scale(1.2);
    }
}

/* Typography & LayoutSpacing */
.space-padding-small {
    height: 10vh;
}

.space-padding {
    height: 25vh;
}

.space-padding-large {
    height: 40vh;
}

.end-margin {
    height: 80vh;
}

/* Stage Gateway */
.fullscreen-section {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
    transition: opacity 2s ease, visibility 2s ease;
}

.fullscreen-section:not(.active) {
    opacity: 0;
    visibility: hidden;
}

.gateway-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.gateway-hint {
    font-family: 'Noto Sans TC', sans-serif;
    font-weight: 300;
    letter-spacing: 0.2em;
    font-size: 1.1rem;
    color: var(--text-secondary);
}

.gateway-input {
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--text-secondary);
    color: var(--text-primary);
    font-size: 2rem;
    text-align: center;
    letter-spacing: 0.5em;
    padding: 10px;
    width: 150px;
    outline: none;
    font-family: 'Noto Sans TC', sans-serif;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.gateway-input::placeholder {
    color: rgba(255, 255, 255, 0.2);
}

.gateway-input:focus {
    border-bottom-color: var(--text-primary);
    box-shadow: 0 4px 10px -5px var(--glass-glow);
}

.gateway-input.error {
    animation: shake 0.4s ease-in-out;
    border-bottom-color: #ff4b4b;
    box-shadow: 0 4px 15px -5px var(--error-glow);
}

.gateway-msg {
    font-family: 'Noto Sans TC', sans-serif;
    font-size: 0.9rem;
    color: var(--text-primary);
    min-height: 1.5em;
    opacity: 0;
    transition: opacity 1s ease;
}

.gateway-msg.show {
    opacity: 1;
}

@keyframes shake {

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

    20%,
    60% {
        transform: translateX(-5px);
    }

    40%,
    80% {
        transform: translateX(5px);
    }
}

/* Scroll Content */
#scroll-content {
    position: relative;
    width: 100%;
    margin: 0 auto;
    max-width: 600px;
    /* 行動裝置優先，限制最大寬度以利閱讀 */
    padding: 0 20px;
    z-index: 5;
}

#scroll-content.hidden {
    display: none;
}

.story-section {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

/* Animations Triggered by Observer */
.observe-item {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 1.5s cubic-bezier(0.2, 0.8, 0.2, 1), transform 1.5s cubic-bezier(0.2, 0.8, 0.2, 1);
    will-change: opacity, transform;
}

.observe-item.active {
    opacity: 1;
    transform: translateY(0);
}

/* 文字樣式 */
.fade-text {
    line-height: 2;
    font-size: 1.15rem;
    letter-spacing: 0.1em;
    color: var(--text-primary);
    margin: 10px 0;
}

/* Blur Reveal */
.blur-text {
    filter: blur(8px);
    transition: filter 2.5s ease, opacity 2s ease, transform 2s ease;
}

.blur-text.active {
    filter: blur(0);
}

/* Code Card (Glassmorphism) */
.code-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 25px;
    text-align: left;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    position: relative;
    /* initial state for observer */
    opacity: 0;
    transform: translateY(40px) scale(0.95);
    transition: all 1.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.code-card.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    animation: hoverFloat 6s ease-in-out infinite alternate 1.5s;
    /* 進入後再開始懸停動畫 */
}

.code-card.error-card {
    border-color: rgba(224, 108, 117, 0.3);
    box-shadow: 0 8px 32px 0 rgba(224, 108, 117, 0.1);
}

@keyframes hoverFloat {
    0% {
        transform: translateY(0px);
    }

    100% {
        transform: translateY(-10px);
    }
}

.code-content {
    font-family: 'Noto Sans TC', monospace;
    font-size: 0.95rem;
    line-height: 1.6;
    letter-spacing: 0.05em;
    color: var(--text-primary);
    text-shadow: 0 0 2px rgba(255, 255, 255, 0.1);
    /* 微弱的珍珠光澤 */
}

.code-keyword {
    color: var(--code-keyword);
}

.code-var {
    color: var(--code-var);
}

.code-comment {
    color: var(--code-comment);
    font-style: italic;
}

.code-error {
    color: var(--code-error);
    font-weight: 500;
}

/* Final Resolution Text */
.final-text {
    font-size: 1.2rem;
    line-height: 2.2;
}

.extremely-slow-text {
    transition-duration: 4s;
    font-size: 1.3rem;
    letter-spacing: 0.15em;
}

/* 飛機距離特效 */
.distance-visual {
    width: 90%;
    max-width: 400px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 2rem 0;
    color: var(--text-secondary);
    font-size: 0.95rem;
    position: relative;
    /* initial state for observer */
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 1.5s cubic-bezier(0.2, 0.8, 0.2, 1), transform 1.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.distance-visual.active {
    opacity: 1;
    transform: translateY(0);
}

.distance-visual .line {
    flex-grow: 1;
    height: 1px;
    border-top: 1px dashed var(--text-secondary);
    margin: 0 15px;
    position: relative;
}

.distance-visual .plane-icon {
    position: absolute;
    top: -14px;
    left: 0%;
    font-size: 18px;
    color: var(--text-primary);
    transform: rotate(0deg);
    /* 將機頭朝向右邊 */
}

.distance-visual.active .plane-icon {
    animation: flyRight 35s linear forwards 0.5s;
}

@keyframes flyRight {
    to {
        left: 95%;
    }
}