/* 基础重置和全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* 亮色主题 */
    --bg-primary: #f5f5f5;
    --bg-secondary: white;
    --bg-tertiary: #ededed;
    --bg-chat: #f5f5f5;
    --text-primary: #333;
    --text-secondary: #999;
    --text-tertiary: #b3b3b3;
    --border-color: #e6e6e6;
    --border-light: #d9d9d9;
    --bubble-received: white;
    --bubble-sent: #95ec69;
    --bubble-sent-text: #333;
    --accent-color: #07c160;
    --choice-bg: white;
    --choice-border: #e6e6e6;
    --choice-hover: #f8f8f8;
    --choice-active: #e6f7ff;
    --shadow-light: rgba(0, 0, 0, 0.1);
    --shadow-medium: rgba(0, 0, 0, 0.15);
    --avatar-system: #07c160;
    --avatar-user: #1aad19;
    --loading-bg: rgba(255, 255, 255, 0.9);
    --loading-border: #e6e6e6;
}

[data-theme="dark"] {
    /* 暗色主题 */
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-tertiary: #3a3a3a;
    --bg-chat: #1a1a1a;
    --text-primary: #e6e6e6;
    --text-secondary: #999;
    --text-tertiary: #666;
    --border-color: #404040;
    --border-light: #505050;
    --bubble-received: #2d2d2d;
    --bubble-sent: #4a90e2;
    --bubble-sent-text: white;
    --accent-color: #4a90e2;
    --choice-bg: #2d2d2d;
    --choice-border: #404040;
    --choice-hover: #3a3a3a;
    --choice-active: #4a4a4a;
    --shadow-light: rgba(0, 0, 0, 0.3);
    --shadow-medium: rgba(0, 0, 0, 0.4);
    --avatar-system: #4a90e2;
    --avatar-user: #5cb85c;
    --loading-bg: rgba(26, 26, 26, 0.9);
    --loading-border: #404040;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    min-height: 100vh;
    color: var(--text-primary);
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* 容器 */
.container {
    max-width: 100%;
    margin: 0 auto;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    transition: background-color 0.3s ease;
}

/* 头部区域 */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-light);
    position: sticky;
    top: 0;
    z-index: 100;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.title {
    font-size: 20px;
    font-weight: 500;
    color: var(--text-primary);
    transition: color 0.3s ease;
}

.menu-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: background-color 0.2s;
    color: var(--text-primary);
}

.menu-btn:hover {
    background: var(--choice-hover);
}

/* 菜单面板 */
.menu-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: none;
    backdrop-filter: blur(5px);
}

.menu-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-secondary);
    border-radius: 20px;
    padding: 30px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 20px 40px var(--shadow-light);
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.menu-content h3 {
    margin-bottom: 20px;
    text-align: center;
    font-size: 20px;
    color: var(--text-primary);
    transition: color 0.3s ease;
}

.menu-item {
    margin-bottom: 15px;
}

.file-label, .menu-item button {
    display: block;
    width: 100%;
    padding: 15px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, background-color 0.3s ease;
    text-align: center;
    text-decoration: none;
}

.file-label:hover, .menu-item button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px var(--shadow-medium);
}

/* 故事信息区域 */
.story-info {
    padding: 15px 20px;
    text-align: center;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.story-title {
    font-size: 18px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 6px;
    transition: color 0.3s ease;
}

.story-description {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    transition: color 0.3s ease;
}

.story-author {
    font-size: 12px;
    color: var(--text-tertiary);
    transition: color 0.3s ease;
}

/* 对话区域 */
.dialogue-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    background: var(--bg-chat);
    background-image: 
        radial-gradient(circle at 20px 20px, rgba(255,255,255,0.08) 1px, transparent 1px),
        radial-gradient(circle at 80px 80px, rgba(255,255,255,0.08) 1px, transparent 1px);
    background-size: 100px 100px;
    transition: background-color 0.3s ease;
    position: relative;
}

[data-theme="dark"] .dialogue-container {
    background-image: 
        radial-gradient(circle at 20px 20px, rgba(255,255,255,0.03) 1px, transparent 1px),
        radial-gradient(circle at 80px 80px, rgba(255,255,255,0.03) 1px, transparent 1px);
}

.dialogue-messages {
    max-width: 600px;
    margin: 0 auto;
    padding-bottom: 20px;
}

.message {
    margin-bottom: 15px;
    animation: slideIn 0.3s ease-out;
    display: flex;
    align-items: flex-start;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.received {
    justify-content: flex-start;
}

.message.sent {
    justify-content: flex-end;
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    background: var(--avatar-system);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 16px;
    font-weight: 500;
    margin-right: 10px;
    flex-shrink: 0;
    transition: background-color 0.3s ease;
}

.message.sent .message-avatar {
    background: var(--avatar-user);
    margin-right: 0;
    margin-left: 10px;
    order: 2;
}

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

.message.sent .message-content {
    align-items: flex-end;
}

.message-bubble {
    background: var(--bubble-received);
    color: var(--text-primary);
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: 0 2px 4px var(--shadow-light);
    position: relative;
    word-wrap: break-word;
    margin-bottom: 5px;
    transition: background-color 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
}

.message.sent .message-bubble {
    background: var(--bubble-sent);
    color: var(--bubble-sent-text);
}

.message-bubble::before {
    content: '';
    position: absolute;
    top: 12px;
    width: 0;
    height: 0;
    border-style: solid;
}

.message.received .message-bubble::before {
    left: -8px;
    border-width: 8px 8px 8px 0;
    border-color: transparent var(--bubble-received) transparent transparent;
    transition: border-color 0.3s ease;
}

.message.sent .message-bubble::before {
    right: -8px;
    border-width: 8px 0 8px 8px;
    border-color: transparent transparent transparent var(--bubble-sent);
    transition: border-color 0.3s ease;
}

.message-character {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-secondary);
    margin-bottom: 4px;
    padding: 0 4px;
    transition: color 0.3s ease;
}

.message-text {
    font-size: 16px;
    line-height: 1.4;
    word-wrap: break-word;
}

.message-time {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
    padding: 0 4px;
    transition: color 0.3s ease;
}

/* 选择区域 */
.choices-container {
    padding: 15px 20px 20px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-light);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.choice-btn {
    display: block;
    width: 100%;
    padding: 12px 16px;
    margin-bottom: 8px;
    background: var(--choice-bg);
    border: 1px solid var(--choice-border);
    border-radius: 8px;
    font-size: 16px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s, background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
    text-align: left;
    box-shadow: 0 1px 3px var(--shadow-light);
}

.choice-btn:hover {
    background: var(--choice-hover);
    border-color: var(--accent-color);
    transform: translateY(-1px);
    box-shadow: 0 2px 6px var(--shadow-medium);
}

.choice-btn:active {
    transform: translateY(0);
    background: var(--choice-active);
}

.choice-btn:last-child {
    margin-bottom: 0;
}

/* 结局显示区域 */
.ending-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}

.ending-content {
    background: var(--bg-secondary);
    border-radius: 20px;
    padding: 40px 30px;
    width: 90%;
    max-width: 500px;
    text-align: center;
    box-shadow: 0 20px 40px var(--shadow-light);
    animation: zoomIn 0.5s ease-out;
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

@keyframes zoomIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.ending-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 20px;
    transition: color 0.3s ease;
}

.ending-text {
    font-size: 16px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 30px;
    transition: color 0.3s ease;
}

.restart-btn {
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 15px 30px;
    font-size: 16px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, background-color 0.3s ease;
}

.restart-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px var(--shadow-medium);
}

/* 加载提示 */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--loading-bg);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
    transition: background-color 0.3s ease;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--loading-border);
    border-top: 4px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
    transition: border-color 0.3s ease;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.loading p {
    font-size: 16px;
    color: var(--text-primary);
    transition: color 0.3s ease;
}

/* 移动端适配 */
@media (max-width: 768px) {
    .header {
        padding: 12px 15px;
    }
    
    .title {
        font-size: 18px;
    }
    
    .menu-btn {
        font-size: 18px;
        padding: 6px;
    }
    
    .menu-content {
        width: 95%;
        padding: 25px;
    }
    
    .story-info {
        padding: 12px 15px;
    }
    
    .dialogue-container {
        padding: 15px;
    }
    
    .choices-container {
        padding: 12px 15px 15px;
    }
    
    .choice-btn {
        padding: 10px 12px;
        font-size: 14px;
    }
    
    .message-bubble {
        padding: 10px 12px;
    }
    
    .message-text {
        font-size: 14px;
    }
    
    .message-avatar {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }
    
    .ending-content {
        padding: 30px 20px;
    }
    
    .ending-title {
        font-size: 18px;
    }
    
    .ending-text {
        font-size: 14px;
    }
    
    /* 移动端主题切换优化 */
    [data-theme="dark"] .dialogue-container {
        background-image: 
            radial-gradient(circle at 15px 15px, rgba(255,255,255,0.02) 1px, transparent 1px),
            radial-gradient(circle at 60px 60px, rgba(255,255,255,0.02) 1px, transparent 1px);
        background-size: 75px 75px;
    }
}

/* 超小屏幕适配 */
@media (max-width: 480px) {
    .header {
        padding: 10px 12px;
    }
    
    .title {
        font-size: 16px;
    }
    
    .menu-content {
        width: 98%;
        padding: 20px;
    }
    
    .story-info {
        padding: 10px 12px;
    }
    
    .dialogue-container {
        padding: 12px;
    }
    
    .choices-container {
        padding: 10px 12px 15px;
    }
    
    .choice-btn {
        padding: 8px 10px;
        font-size: 13px;
    }
    
    .message-bubble {
        padding: 8px 10px;
    }
    
    .message-text {
        font-size: 13px;
    }
    
    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 12px;
        margin-right: 8px;
    }
    
    .message.sent .message-avatar {
        margin-right: 0;
        margin-left: 8px;
    }
    
    /* 超小屏幕主题优化 */
    [data-theme="dark"] .dialogue-container {
        background-image: 
            radial-gradient(circle at 12px 12px, rgba(255,255,255,0.015) 1px, transparent 1px),
            radial-gradient(circle at 48px 48px, rgba(255,255,255,0.015) 1px, transparent 1px);
        background-size: 60px 60px;
    }
}

/* 黑暗模式特殊优化 */
[data-theme="dark"] .menu-panel {
    background: rgba(0, 0, 0, 0.8);
}

[data-theme="dark"] .ending-container {
    background: rgba(0, 0, 0, 0.9);
}

[data-theme="dark"] .message-bubble {
    border: 1px solid var(--border-color);
}

[data-theme="dark"] .message.sent .message-bubble {
    border-color: transparent;
}

/* 主题切换过渡效果 */
* {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

/* 特殊元素的过渡 */
.menu-panel {
    transition: background-color 0.3s ease;
}

.ending-container {
    transition: background-color 0.3s ease;
}

/* 滚动条样式 */
.dialogue-container::-webkit-scrollbar {
    width: 4px;
}

.dialogue-container::-webkit-scrollbar-track {
    background: transparent;
}

.dialogue-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

.dialogue-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* 选择动画优化 */
.choice-btn {
    will-change: transform;
}

.message {
    will-change: transform, opacity;
}

/* 提升性能 */
.container {
    will-change: background-color;
}

.message-bubble {
    will-change: background-color, border-color;
}

.message-avatar {
    will-change: background-color;
} 