:root {
    --bg-color: #f0f2f5;
    --sidebar-bg: #2c3e50;
    --text-main: #333;
    --text-light: #ecf0f1;
    --border-radius: 12px;

    /* 核心数值颜色 */
    --color-green: #2ecc71;
    --color-blue: #3498db;
    --color-pink: #ff7675;
    --color-red: #d63031;
    --color-purple: #9b59b6;
}

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

body {
    font-family: 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    overflow: hidden;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    transition: background-image 0.6s ease, background-color 0.6s ease;
}

body.bg-school {
    background-image: url('./images/bg_classroom.png');
    background-color: #e8edf2;
}

body.bg-home {
    background-image: url('./images/bg_home.png');
    background-color: #1a0a10;
}

#game-container {
    width: 90vw;
    max-width: 1200px;
    height: 85vh;
    display: flex;
    background-color: rgba(255, 255, 255, 0.2);
    /* 全局半透明透明度 */
    backdrop-filter: blur(12px);
    /* 全局毛玻璃 */
    -webkit-backdrop-filter: blur(12px);
    border-radius: var(--border-radius);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.3);
    /* 加个极细的亮边增强质感 */
}

/* Sidebar Styles */
#sidebar {
    width: 300px;
    background-color: rgba(44, 62, 80, 0.6);
    color: var(--text-light);
    padding: 20px;
    display: flex;
    flex-direction: column;
    transition: background-color 0.5s ease;
    overflow-y: auto;
}

/* Sidebar Scrollbar */
#sidebar::-webkit-scrollbar {
    width: 6px;
}

#sidebar::-webkit-scrollbar-track {
    background: transparent;
}

#sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

#sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.4);
}

#sidebar.scene-school {
    background-color: rgba(52, 73, 94, 0.65);
    /* 稍显沉闷的学校色调 */
}

#sidebar.scene-home {
    background-color: rgba(44, 14, 24, 0.7);
    /* 压抑的惩罚室色调 */
}

#sidebar-close-btn {
    display: none;
}

.calendar-panel {
    background: rgba(0, 0, 0, 0.2);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    border-left: 4px solid #f1c40f;
}

.time-header {
    font-size: 0.85rem;
    color: #bdc3c7;
    margin-bottom: 5px;
}

.time-text {
    font-size: 1.1rem;
    font-weight: bold;
    color: #fff;
}

.scene-indicator {
    font-size: 1rem;
    font-weight: bold;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    color: #e67e22;
    margin-bottom: 15px;
}

.mt-3 {
    margin-top: 15px;
}

/* System Control Buttons */
.control-panel {
    display: flex;
    justify-content: space-between;
    gap: 5px;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sys-btn {
    background-color: rgba(255, 255, 255, 0.1);
    color: #ecf0f1;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 6px 8px;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
    flex: 1;
    transition: all 0.2s;
}

.sys-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.reset-btn:hover {
    background-color: rgba(231, 76, 60, 0.3);
    border-color: rgba(231, 76, 60, 0.5);
}

.stat-box {
    background: rgba(0, 0, 0, 0.2);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 15px;
    transition: all 0.3s;
}

.stat-label {
    display: block;
    font-weight: bold;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.progress-bar-container {
    width: 100%;
    height: 10px;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 5px;
    overflow: hidden;
    margin-bottom: 5px;
}

.progress-bar {
    height: 100%;
    border-radius: 5px;
    transition: width 0.5s ease-out;
}

.fill-red {
    background-color: var(--color-red);
}

.fill-pink {
    background-color: var(--color-pink);
}

.fill-purple {
    background-color: var(--color-purple);
}

.fill-green {
    background-color: var(--color-green);
}

.fill-blue {
    background-color: var(--color-blue);
}

.stat-value {
    font-family: monospace;
    font-weight: bold;
    font-size: 0.85rem;
    float: right;
}

.stat-desc {
    font-size: 0.75rem;
    color: #bdc3c7;
    margin-top: 15px;
    line-height: 1.4;
}

/* Flash anim for danger */
.danger-flash {
    animation: flash 1s infinite alternate;
}

@keyframes flash {
    from {
        box-shadow: 0 0 5px rgba(214, 48, 49, 0);
    }

    to {
        box-shadow: 0 0 20px rgba(214, 48, 49, 0.5);
    }
}

/* Chat Section Styles */
#chat-section {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background-color: transparent;
    /* 取消中央区自己的底色，直接透过全局背景 */
}

#chat-history {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.message {
    max-width: 75%;
    display: flex;
    flex-direction: column;
}

.msg-content {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 1rem;
    line-height: 1.5;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    word-wrap: break-word;
}

.player-msg {
    align-self: flex-end;
}

.player-msg .msg-content {
    background-color: #007aff;
    color: white;
    border-bottom-right-radius: 4px;
}

.ai-msg {
    align-self: flex-start;
}

.ai-msg .msg-content {
    background-color: rgba(255, 255, 255, 0.85);
    color: #333;
    border-bottom-left-radius: 4px;
}

.system-msg {
    align-self: center;
    max-width: 90%;
    align-items: center;
}

.system-msg .msg-content {
    background-color: rgba(255, 255, 255, 0.5);
    color: #444;
    font-size: 0.85rem;
    border-radius: 8px;
    box-shadow: none;
    text-align: center;
    backdrop-filter: blur(5px);
}

/* Choices Area */
#choices-area {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 15px;
    background-color: rgba(255, 255, 255, 0.3);
    /* 选择区半透明 */
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    justify-content: center;
}

.choice-btn {
    background-color: #f8f9fa;
    color: #333;
    border: 1px solid #ced4da;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.choice-btn:hover {
    background-color: #e9ecef;
    border-color: #adb5bd;
    transform: translateY(-1px);
}

.choice-btn:active {
    transform: translateY(1px);
}

.choice-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

#loading-indicator {
    text-align: center;
    padding: 10px;
    font-size: 0.85rem;
    color: #666;
    font-style: italic;
}

.hidden {
    display: none !important;
}

/* =========================================
   Mobile Responsiveness & Hamburger Menu
   ========================================= */

#mobile-header {
    display: none;
    padding: 10px 15px;
    background-color: rgba(255, 255, 255, 0.3);
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(5px);
    z-index: 10;
}

#sidebar-toggle {
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 20px;
    width: 26px;
    padding: 0;
}

#sidebar-toggle span {
    display: block;
    height: 3px;
    width: 100%;
    background-color: #333;
    border-radius: 2px;
    transition: all 0.3s;
}

#sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 99;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#sidebar-overlay.active {
    display: block;
    opacity: 1;
}

@media (max-width: 768px) {
    #game-container {
        width: 100vw;
        height: 100vh;
        border-radius: 0;
        border: none;
    }

    #mobile-header {
        display: flex;
        align-items: center;
    }

    #sidebar-close-btn {
        display: block;
        position: absolute;
        top: 10px;
        right: 15px;
        background: transparent;
        border: none;
        color: var(--text-light);
        font-size: 32px;
        cursor: pointer;
        z-index: 101;
    }

    /* Convert Sidebar to an Off-Canvas Drawer */
    #sidebar {
        position: fixed;
        top: 0;
        left: -320px;
        /* Hidden off-screen */
        height: 100vh;
        width: 280px;
        z-index: 100;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.5);
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.5s ease;
        overflow-y: auto;
        padding-bottom: 40px;

        /* 核心修复：去除 flex 属性，改回 block，让子元素自然堆叠以触发高度溢出 */
        display: block !important;
        -webkit-overflow-scrolling: touch;
    }

    #sidebar.active {
        left: 0;
        /* Slide in */
    }

    #chat-history {
        padding: 15px 10px;
    }

    .message {
        max-width: 85%;
    }

    .sys-btn {
        padding: 8px 5px;
    }
}

/* =========================================
   Cloud Save Modal
   ========================================= */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: rgba(44, 62, 80, 0.95);
    padding: 20px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    width: 90%;
    max-width: 400px;
    color: var(--text-light);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 10px;
    margin-bottom: 15px;
}

.close-btn {
    font-size: 24px;
    cursor: pointer;
    color: #bdc3c7;
}

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

.save-slots {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 60vh;
    overflow-y: auto;
}

.save-slots::-webkit-scrollbar {
    width: 5px;
}

.save-slots::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.save-slot-btn {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 15px;
    border-radius: 8px;
    color: var(--text-light);
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.save-slot-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--color-blue);
}

.slot-empty {
    color: #7f8c8d;
    font-style: italic;
}

.slot-data {
    display: flex;
    flex-direction: column;
}

.slot-label {
    font-weight: bold;
    font-size: 1rem;
    color: #3498db;
}

.slot-time {
    font-size: 0.8em;
    color: #bdc3c7;
    margin-top: 4px;
}