:root {
    --bg-color: #050510;
    --text-color: #e0e0ff;
    --accent-color: #4deeea;
    --glow-color: rgba(77, 238, 234, 0.6);
    --blue-back-glow: rgba(0, 60, 255, 0.15);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

html {
    background: #000;
}

body {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background-color: var(--bg-color);
    /* Background gradient moved to #main-background to prevent flash */
    color: var(--text-color);
    font-family: 'Noto Serif TC', 'Cinzel', serif;
    /* iOS safe area support */
    padding-bottom: env(safe-area-inset-bottom, 0);
}

#main-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at center, #1a1a3a 0%, #020205 80%);
    z-index: -1; /* Behind everything */
}

.bg-glow {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100vw;
    height: 100vh;
    background: radial-gradient(circle at center, rgba(30, 60, 255, 0.3) 0%, rgba(0,0,0,0) 60%);
    pointer-events: none;
    z-index: 0;
}

/* Bottom Gradient Overlay for Intro */
#bottom-gradient {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 30vh;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0.4) 50%, rgba(0, 0, 0, 0) 100%);
    pointer-events: none;
    z-index: 5;
    opacity: 1;
    transition: opacity 1.5s ease;
}

#bottom-gradient.hidden {
    opacity: 0;
}

#canvas-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    cursor: pointer; 
}

/* Intro Layer */
#intro-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    padding-top: 15vh;
    pointer-events: none;
    transition: opacity 1.5s ease;
}

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

/* Beautified Title */
.intro-title {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-transform: uppercase;
    font-family: 'Cinzel', serif;
    line-height: 1;
    pointer-events: none;
}

.title-the {
    font-size: 1rem;
    letter-spacing: 12px;
    opacity: 0.5;
    margin-bottom: 8px;
    font-weight: 400;
}

.title-magic {
    font-size: 4.5rem; 
    font-weight: 900;
    letter-spacing: 8px;
    background: linear-gradient(180deg, #ffffff 0%, #a0c4ff 50%, #4deeea 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 0 30px rgba(77, 238, 234, 0.4));
    margin-bottom: 5px;
}

.title-ball {
    font-size: 2rem;
    font-weight: 400;
    letter-spacing: 15px;
    opacity: 0.6;
}

.intro-hint {
    margin-top: 40px;
    font-size: 0.85rem;
    font-family: 'Noto Serif TC', serif;
    opacity: 0.4;
    letter-spacing: 2px;
    animation: pulseHint 3s ease-in-out infinite;
    pointer-events: none;
}

@keyframes pulseHint {
    0%, 100% { opacity: 0.3; transform: translateY(0); }
    50% { opacity: 0.6; transform: translateY(-3px); }
}


/* Main UI Layer */
#ui-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 11;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 2rem;
}

/* Beautified Header */
.header {
    text-align: center;
    width: 100%;
    pointer-events: auto;
    margin-top: 20px;
    opacity: 1;
    transition: opacity 1s ease;
}

.header.hidden {
    opacity: 0;
    pointer-events: none;
}

h1 {
    font-family: 'Cinzel', serif;
    font-size: 1rem;
    letter-spacing: 6px;
    margin-bottom: 10px;
    text-transform: uppercase;
    font-weight: 400;
    background: linear-gradient(90deg, rgba(255,255,255,0.1) 0%, rgba(77, 238, 234, 0.4) 50%, rgba(255,255,255,0.1) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Center Guide Message */
#center-guide {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 12;
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.8s ease;
}

#center-guide.hidden {
    opacity: 0;
}

#guide-text {
    font-size: 1.2rem;
    font-family: 'Noto Serif TC', serif;
    color: rgba(220, 230, 255, 1);
    letter-spacing: 3px;
    text-shadow: 
        0 0 10px rgba(0, 0, 0, 0.8),
        0 0 20px rgba(0, 0, 0, 0.6),
        0 0 40px rgba(77, 238, 234, 0.4),
        0 2px 4px rgba(0, 0, 0, 0.9);
    animation: guideFloat 3s ease-in-out infinite;
    padding: 15px 30px;
    background: radial-gradient(ellipse at center, rgba(0, 10, 30, 0.5) 0%, rgba(0, 0, 0, 0) 70%);
    border-radius: 30px;
}

@keyframes guideFloat {
    0%, 100% { transform: translateY(0); opacity: 0.8; }
    50% { transform: translateY(-5px); opacity: 1; }
}

#bottom-ui {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    margin-bottom: calc(30px + env(safe-area-inset-bottom, 0px));
    pointer-events: none;
}

#instruction-container {
    text-align: center;
    min-height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

/* Refined Instruction Animation */
.instruction {
    font-size: 1rem;
    font-family: 'Noto Serif TC', serif;
    color: rgba(200, 210, 255, 0.85); 
    letter-spacing: 1px;
    opacity: 0;
    transform: translateY(15px) scale(0.98);
    transition: 
        opacity 0.6s cubic-bezier(0.4, 0, 0.2, 1), 
        transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 12px 24px;
}

.instruction.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.instruction.fade-out {
    opacity: 0;
    transform: translateY(-10px) scale(0.98);
    transition: 
        opacity 0.3s ease-out, 
        transform 0.3s ease-out;
}

/* Subtle Language Switch */
.lang-switch {
    display: flex;
    justify-content: center;
    gap: 8px;
    pointer-events: auto;
    opacity: 0.4;
    transition: opacity 0.3s ease;
}

.lang-switch:hover {
    opacity: 0.8;
}

.lang-btn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    padding: 4px 8px;
    font-family: 'Cinzel', serif;
    font-size: 0.7rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 400;
    letter-spacing: 1px;
}

.lang-btn:hover {
    color: rgba(255, 255, 255, 0.9);
}

.lang-btn.active {
    color: rgba(255, 255, 255, 0.9);
}

/* Copyright Footer */
#copyright {
    position: fixed;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    right: 18px;
    z-index: 20;
    pointer-events: auto;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
}

#copyright:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(77, 238, 234, 0.3);
}

.copyright-symbol {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.4);
    transition: color 0.3s ease;
}

.copyright-text {
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.35);
    font-family: 'Cinzel', serif;
    letter-spacing: 1px;
    transition: color 0.3s ease;
}

#copyright:hover .copyright-symbol,
#copyright:hover .copyright-text {
    color: rgba(255, 255, 255, 0.7);
}

.copyright-popup {
    position: absolute;
    bottom: 25px;
    right: 0;
    background: rgba(0, 0, 0, 0.9);
    border: 1px solid rgba(77, 238, 234, 0.3);
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 0.75rem;
    color: rgba(200, 210, 255, 0.8);
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.3s ease;
    line-height: 1.6;
}

.copyright-popup a {
    color: var(--accent-color);
    text-decoration: none;
}

.copyright-popup a:hover {
    text-decoration: underline;
}

#copyright:hover .copyright-popup {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

#reading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.1);
    z-index: 4;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    mix-blend-mode: overlay;
}

#reading-overlay.active {
    opacity: 1;
    animation: pulseFlash 1.5s infinite;
}

@keyframes pulseFlash {
    0% { opacity: 0; }
    50% { opacity: 0.3; background: rgba(77, 238, 234, 0.2); }
    100% { opacity: 0; }
}

@media (max-width: 768px) {
    #intro-layer {
        padding-top: 12vh;
    }
    
    .title-magic {
        font-size: 3rem;
        letter-spacing: 5px;
    }
    
    .title-ball {
        font-size: 1.5rem;
        letter-spacing: 10px;
    }
    
    .title-the {
        font-size: 0.8rem;
        letter-spacing: 8px;
    }
    
    .instruction {
        font-size: 0.9rem;
        padding: 10px 18px;
    }

    #bottom-ui {
        margin-bottom: calc(12% + env(safe-area-inset-bottom, 0px));
    }
    
    .lang-btn {
        font-size: 0.65rem;
    }
    
    h1 {
        font-size: 0.85rem;
        letter-spacing: 4px;
    }
    
    #guide-text {
        font-size: 1rem;
        letter-spacing: 2px;
        padding: 12px 20px;
    }
}
