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

body {
    background-color: black;
    overflow: hidden;
    font-family: 'Ma Shan Zheng', cursive;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    width: 100vw;
}

#game-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

#game-container {
    position: absolute;
    width: 3840px;
    height: 2560px;
    transform-origin: center center;
    background-color: black;
    overflow: hidden;
    /* Prevent initial flash of unscaled content */
    opacity: 0;
    animation: fadeIn 0.5s forwards;
}

@keyframes fadeIn {
    to { opacity: 1; }
}

.scene {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.hidden {
    display: none !important;
}

.bg-image, .visual-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* Start Screen */
.start-buttons {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
}

.btn {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Let the container handle clicks */
    transition: transform 0.1s ease;
}

.btn-active {
    transform: scale(0.90);
}

/* Loading Screen */
#loading-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease;
    pointer-events: auto;
}

.sakura-spinner {
    animation: spin 2s linear infinite;
}

.sakura-spinner path {
    animation: pulse 1.5s ease-in-out infinite alternate;
}

.sakura-spinner path:nth-child(1) { animation-delay: 0s; }
.sakura-spinner path:nth-child(2) { animation-delay: 0.3s; }
.sakura-spinner path:nth-child(3) { animation-delay: 0.6s; }
.sakura-spinner path:nth-child(4) { animation-delay: 0.9s; }
.sakura-spinner path:nth-child(5) { animation-delay: 1.2s; }

@keyframes spin {
    100% { transform: rotate(360deg); }
}

@keyframes pulse {
    0% { opacity: 0.3; transform: scale(0.8); }
    100% { opacity: 1; transform: scale(1); }
}

.loading-text {
    margin-top: 20px;
    font-size: 24px;
    color: #ffb7c5;
    font-family: 'Ma Shan Zheng', cursive;
    letter-spacing: 2px;
}

/* Collision Layers */
#collision-layers {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0; /* Hide them visually, we will draw them to an offscreen canvas for pixel perfect collision */
}

.collision-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Characters */
#characters {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.character {
    position: absolute;
    transform: translate(-50%, -100%) scale(1.5); /* Anchor at bottom center, enlarge 1.5x */
    transform-origin: bottom center;
    transition: left 0.1s linear, top 0.1s linear, transform 0.3s ease;
    z-index: 5;
}

.character-bedroom {
    transform: translate(-50%, -100%) scale(2.25); /* Enlarge 1.5x again for bedroom */
}

/* Dialog System */
#dialog-system {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100;
}

#dialog-box {
    position: absolute;
    bottom: 0;
    width: 3000px;
    height: 450px;
    border-radius: 30px 30px 0 0;
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    padding: 80px 100px;
    box-shadow: 0 -10px 40px rgba(0,0,0,0.4);
    cursor: pointer;
    z-index: 102;
}

/* Player Dialog Style */
.dialog-player {
    background-color: rgba(0, 0, 0, 0.65);
    color: white;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-bottom: none;
    left: 0; /* Box on the far left */
}

/* Douhua Dialog Style */
.dialog-douhua {
    background-color: rgba(130, 125, 150, 0.45); /* Morandi Blue-Purple, more transparent */
    backdrop-filter: blur(30px); /* Stronger frosted glass */
    -webkit-backdrop-filter: blur(30px);
    color: #1a2b4c; /* 墨蓝色 */
    text-shadow: 0 0 3px rgba(255, 255, 255, 0.4); /* Frosted text effect */
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-bottom: none;
    right: 0; /* Box on the far right */
    left: auto !important;
}

#dialog-name {
    position: absolute;
    top: -50px;
    padding: 15px 50px;
    font-size: 80px;
    border-radius: 15px;
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
}

.dialog-player #dialog-name {
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.2);
    left: 60px;
    right: auto;
}

.dialog-douhua #dialog-name {
    background-color: rgba(130, 125, 150, 0.7);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    color: rgba(20, 20, 20, 0.9);
    border: 2px solid rgba(255, 255, 255, 0.3);
    left: 60px;
    right: auto;
}

/* Narrator Dialog Style */
#dialog-box.dialog-narrator {
    background-color: rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: black;
    border: none;
    left: 0;
    width: 100%;
    height: 250px;
    padding: 40px 100px;
    border-radius: 0;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
    bottom: 0;
}

#dialog-box.dialog-narrator #dialog-name {
    display: none;
}

#dialog-box.dialog-narrator #dialog-text {
    font-size: 90px;
    text-align: center;
    width: 100%;
    color: black;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.8);
}

#dialog-text {
    font-size: 110px;
    line-height: 1.5;
    white-space: pre-wrap;
}

.inner-thought {
    font-size: 80px;
}

.inner-thought-player {
    color: #cccccc; /* Gray */
}

.inner-thought-douhua {
    color: #d8849b; /* Pinkish, adjusted for Morandi bg */
}

.dialog-portrait {
    position: absolute;
    bottom: 0;
    height: 1400px; /* Adjust based on actual portrait size */
    z-index: 101; /* Behind dialog box */
    pointer-events: none;
}

#dialog-portrait-left {
    left: 0; /* Left side of screen */
    right: auto;
}

#dialog-portrait-right {
    right: -100px; /* Move further right */
    left: auto;
}

/* Dialog Options */
#dialog-options {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    gap: 40px;
    z-index: 105;
    width: 1200px;
}

.dialog-option {
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: white;
    font-size: 80px;
    padding: 40px 60px;
    border-radius: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.dialog-option:hover {
    background-color: rgba(0, 0, 0, 0.8);
    border-color: rgba(255, 255, 255, 0.8);
    transform: scale(1.02);
}

/* CG Gallery */
#cg-gallery {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    z-index: 200;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
}

#btn-cg-exit {
    position: absolute;
    top: 80px;
    left: 80px;
    font-size: 80px;
    padding: 20px 60px;
    background-color: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid white;
    border-radius: 20px;
    cursor: pointer;
    font-family: 'Ma Shan Zheng', cursive;
    z-index: 201;
    pointer-events: auto;
}

#cg-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

#cg-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: filter 0.3s;
}

.cg-locked {
    filter: blur(150px) brightness(0.3); /* 超级高斯模糊版，加重模糊和变暗 */
}

#cg-title {
    position: absolute;
    bottom: 100px;
    color: white;
    font-size: 100px;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
    z-index: 202;
}

#btn-cg-prev, #btn-cg-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 150px;
    color: rgba(255, 255, 255, 0.5);
    background: none;
    border: none;
    cursor: pointer;
    transition: color 0.2s;
    z-index: 201;
    pointer-events: auto;
}

#btn-cg-prev:hover, #btn-cg-next:hover {
    color: white;
}

#btn-cg-prev {
    left: 100px;
}

#btn-cg-next {
    right: 100px;
}

/* UI Buttons */
#game-ui {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 150;
}

.ui-btn {
    position: absolute;
    top: 60px;
    width: 120px;
    height: 120px;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.5);
    color: white;
    border: 4px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    cursor: pointer;
    pointer-events: auto;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    transition: all 0.2s ease;
    padding: 20px;
}

.ui-btn:hover {
    background-color: rgba(0, 0, 0, 0.8);
    border-color: white;
    transform: scale(1.1);
}

#btn-exit-game {
    left: 60px;
}

#btn-settings {
    right: 60px;
}

/* Settings Modal */
#settings-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.4);
    z-index: 250;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.settings-content {
    position: relative;
    background-color: rgba(255, 255, 255, 0.1);
    padding: 120px;
    border-radius: 60px;
    border: 4px solid rgba(255, 255, 255, 0.4);
    display: flex;
    flex-direction: column;
    gap: 80px;
    align-items: center;
    color: white;
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}

.close-btn {
    position: absolute;
    top: 40px;
    right: 40px;
    width: 80px;
    height: 80px;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    transition: color 0.2s;
    padding: 10px;
}

.close-btn:hover {
    color: white;
}

.settings-content h2 {
    font-size: 120px;
    margin-bottom: 40px;
}

.setting-row {
    display: flex;
    align-items: center;
    gap: 40px;
    font-size: 80px;
}

.setting-row input[type="range"] {
    width: 400px;
    height: 20px;
}

/* Mobile Portrait Warning */
#portrait-warning {
    display: none;
}

@media screen and (orientation: portrait) and (max-width: 900px) {
    #portrait-warning {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background-color: #000;
        color: #fff;
        z-index: 99999;
        justify-content: center;
        align-items: center;
        text-align: center;
        font-family: 'Ma Shan Zheng', cursive;
        font-size: 24px;
        line-height: 1.5;
    }
    
    .warning-content svg {
        animation: rotatePhone 2s ease-in-out infinite;
        margin-bottom: 20px;
    }
    
    #game-wrapper {
        display: none !important;
    }
}

@keyframes rotatePhone {
    0% { transform: rotate(0deg); }
    50% { transform: rotate(-90deg); }
    100% { transform: rotate(-90deg); }
}
