/* --- 通用樣式 (已修正) --- */
html, body {
    height: 100%; /* 确保 html 和 body 可以撑满视口 */
    margin: 0;
    padding: 0;
}

/* --- 多人游戏状态样式 --- */
#multiplayer-status {
    display: flex;
    align-items: center;
    gap: 15px;
    font-size: 0.9em;
}

#connection-status {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8em;
    font-weight: bold;
}

#connection-status.connected {
    background-color: #28a745;
    color: white;
}

#connection-status.disconnected {
    background-color: #dc3545;
    color: white;
}

#players-count {
    color: #6c757d;
    font-size: 0.8em;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: #1a1a1a;
    color: #e0e0e0;
    display: flex; /* 【核心】让 body 成为 Flex 容器 */
    overflow: hidden; /* 防止出现双滚动条 */
}

.page {
    display: none;
    /* 【核心】移除了 position: absolute, top, left */
    width: 100%;
    height: 100%; /* 页面将自动撑满 body */
    flex-direction: column; /* 页面内部的元素默认垂直排列 */
}

.page.active {
    display: flex;
}

h1 {
    text-align: center;
    padding: 20px;
    margin: 0;
    background-color: #1f1f1f;
    border-bottom: 1px solid #333;
    font-size: 1.5em;
    width: 100%;
    box-sizing: border-box;
    position: relative;
    z-index: 10;
    flex-shrink: 0; /* 【新增】防止标题在 flex 布局中被压缩 */
}

/* --- 登入頁面樣式 --- */
#login-page {
    background-color: #242424;
}

.form-container {
    background-color: #2a2a2a;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5);
    text-align: center;
    width: 90%;
    max-width: 400px;
}

.form-container h1 {
    background: none;
    border: none;
    margin-bottom: 10px;
    font-size: 2em;
}

.form-container p {
    color: #aaa;
    margin-bottom: 30px;
}

#username-input {
    width: calc(100% - 24px);
    padding: 12px;
    margin-bottom: 20px;
    border: 1px solid #444;
    border-radius: 8px;
    background-color: #333;
    color: #e0e0e0;
    font-size: 1em;
}

#login-btn {
    width: 100%;
    padding: 12px 20px;
    border: none;
    background-color: #007bff;
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.1em;
    transition: background-color 0.2s;
}

#login-btn:hover {
    background-color: #0056b3;
}


/* --- 劇本選擇頁面樣式 --- */
#scenario-selection-page {
    /* 【核心修复】覆盖 .page 的居中对齐，让内容从顶部开始并撑满宽度 */
    justify-content: flex-start; /* 子元素从容器顶部开始排列，而不是垂直居中 */
    align-items: stretch;      /* 子元素在交叉轴（水平方向）上撑满整个容器宽度 */
}

#scenario-selection-page::-webkit-scrollbar {
    width: 8px;
}
#scenario-selection-page::-webkit-scrollbar-track {
    background: #1a1a1a;
}
#scenario-selection-page::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 4px;
}
#scenario-selection-page::-webkit-scrollbar-thumb:hover {
    background: #777;
}


/* ============================= */
/*        剧本卡片样式            */
/* ============================= */
.scenario-card {
    background-color: #2a2a2a;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;

    display: flex;
    flex-direction: column;

    /* ✅ 防止被压缩或塌陷 */
    height: auto;
    min-height: 0;
}

.scenario-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0, 123, 255, 0.3);
}

.scenario-card img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    display: block;
    flex-shrink: 0;
}

.scenario-card .card-content {
    padding: 20px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.scenario-card h2 {
    font-size: 1.4em;
    margin: 0 0 10px;
    flex-shrink: 0;
}

.scenario-card p {
    font-size: 0.9em;
    color: #b0b0b0;
    line-height: 1.6;
    margin: 0;
    flex-grow: 1; /* ✅ 让描述文字撑开内容区域 */
}

#chat-page {
    justify-content: center; /* 垂直方向居中 */
    align-items: center;   /* 水平方向居中 */
}

/* --- 聊天頁面樣式 --- */
#game-container {
    width: 90%;
    max-width: 900px;
    height: 95vh;
    background-color: #2a2a2a;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ... (其他聊天頁面樣式保持不變) ... */
#game-container h1 { font-size: 1.2em; padding: 15px; }
#chat-box { flex-grow: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 15px; }
#chat-box::-webkit-scrollbar { width: 8px; }
#chat-box::-webkit-scrollbar-track { background: #2a2a2a; }
#chat-box::-webkit-scrollbar-thumb { background: #555; border-radius: 4px; }
#chat-box::-webkit-scrollbar-thumb:hover { background: #777; }

.message { max-width: 85%; padding: 10px 15px; border-radius: 18px; line-height: 1.5; white-space: pre-wrap; }
.message p { margin: 0; padding: 0; display: inline;}
.user-message { background-color: #0055b3; color: white; align-self: flex-end; border-bottom-right-radius: 4px;}
.keeper-message, .system-message { background-color: #3a3a3a; color: #e0e0e0; align-self: flex-start; border-bottom-left-radius: 4px; }
.system-error-message { background-color: #5d1a1a; color: #ffc0c0; align-self: flex-start; border-bottom-left-radius: 4px; }
#input-area { display: flex; padding: 15px; border-top: 1px solid #333; background-color: #1f1f1f; }
#player-input { flex-grow: 1; padding: 10px; border: 1px solid #444; border-radius: 20px; background-color: #333; color: #e0e0e0; font-size: 1em; }
#player-input:focus { outline: none; border-color: #007bff; }
#send-btn { margin-left: 10px; padding: 10px 20px; border: none; background-color: #007bff; color: white; border-radius: 20px; cursor: pointer; font-size: 1em; transition: background-color 0.2s; }
#send-btn:hover { background-color: #0056b3; }
#dice-roll-btn {
    margin-left: 10px;
    padding: 0; /* 移除内边距，让图标居中 */
    width: 42px; /* 固定宽度 */
    height: 42px; /* 固定高度，与输入框和发送按钮对齐 */
    border: 1px solid #007bff;
    background-color: transparent;
    color: #007bff;
    border-radius: 50%; /* 圆形按钮 */
    cursor: pointer;
    font-size: 1.5em; /* 放大骰子图标 */
    line-height: 42px; /* 垂直居中图标 */
    text-align: center; /* 水平居中图标 */
    transition: all 0.2s;
}

/* 骰子按钮可用时的悬浮效果 */
#dice-roll-btn:not(:disabled):hover {
    background-color: #007bff;
    color: white;
}

/* 骰子按钮禁用时的样式 */
#dice-roll-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    border-color: #555;
    color: #555;
}



/* --- 【核心修改】手機響應式樣式 --- */
/* 當螢幕寬度小於或等於 768px 時，應用以下樣式 */
@media (max-width: 768px) {
    
    /* ▼▼▼ 用下面这段代码替换掉你原来的  规则 ▼▼▼ */
    #scenario-list {
        /* 从 Grid 布局切换为 Flexbox 布局 */
        display: flex;
        flex-direction: column; /* 确保卡片垂直排列 */

        /* 其他样式保持不变 */
        padding: 20px;
        gap: 20px;
    }

    /* 讓遊戲容器在手機上佔滿全螢幕 */
    #game-container {
        width: 100%;
        height: 100%;
        border-radius: 0;
        box-shadow: none;
    }

    /* 適當減小手機上的字體大小 */
    h1 {
        font-size: 1.2em;
        padding: 15px;
    }

    .scenario-card h2 {
        font-size: 1.2em;
    }

    .scenario-card p {
        font-size: 0.9em;
    }
}

/* style.css */

/* ... 您现有的所有样式保持不变 ... */


/* ▼▼▼ 【新增】游戏页面头部的样式 ▼▼▼ */
.game-header {
    display: flex;
    justify-content: space-between; /* 让标题和按钮分布在两侧 */
    align-items: center;
    width: 100%;
    background-color: #1f1f1f;
    border-bottom: 1px solid #333;
    box-sizing: border-box;
}

.game-header h1 {
    width: auto; /* 覆盖原来的 width: 100% */
    flex-grow: 1; /* 标题占据大部分空间 */
    border-bottom: none; /* 移除标题自己的下边框 */
    background: none;
    text-align: left; /* 标题居左 */
    padding: 15px 20px;
}

#restart-btn {
    flex-shrink: 0; /* 防止按钮被压缩 */
    margin-right: 20px;
    padding: 8px 16px;
    border: 1px solid #007bff;
    background-color: #007bff;
    color: white;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.2s;
}

#restart-btn:hover {
    background-color: #0056b3;
    border-color: #0056b3;
}

/* ▼▼▼ 【新增】确认弹窗的样式 ▼▼▼ */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: none; /* 默认隐藏 */
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-overlay.active {
    display: flex; /* active 类用于显示弹窗 */
}

.modal-content {
    background-color: #2a2a2a;
    padding: 30px 40px;
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5);
    text-align: center;
    width: 90%;
    max-width: 450px;
}

.modal-content h2 {
    margin-top: 0;
    font-size: 1.8em;
}

.modal-content p {
    color: #b0b0b0;
    line-height: 1.6;
    margin: 15px 0 30px;
}

.modal-buttons {
    display: flex;
    justify-content: space-around;
    gap: 20px;
}

.modal-buttons button {
    flex-grow: 1;
    padding: 12px 20px;
    border: none;
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.1em;
    transition: opacity 0.2s;
}

.modal-buttons button:hover {
    opacity: 0.8;
}

/* 【核心】根据您的要求，为按钮上色 */
#confirm-restart-yes {
    background-color: #dc3545; /* 危险操作 - 红色 */
}

#confirm-restart-no {
    background-color: #28a745; /* 安全操作 - 绿色 */
}

/* style.css (请用这段代码替换掉所有相关的旧样式) */

/* --- 消息行、头像、消息框的最终布局样式 --- */

/* 1. 消息行的基础容器 */
.message-row {
    display: flex;
    align-items: flex-start; /* 确保头像和消息框顶部对齐 */
    max-width: 80%;
    margin-bottom: 15px;
}

/* 2. 主持人消息行 (靠左) */
.keeper-message-row, .system-message-row {
    align-self: flex-start; /* 整行靠左 */
    flex-direction: row; /* 内容正向排列：头像 -> 消息框 */
}

/* 3. 玩家消息行 (靠右) */
.user-message-row {
    align-self: flex-end; /* 整行靠右 */
    flex-direction: row-reverse; /* 内容反向排列：消息框 <- 头像 */
}

/* 4. 通用头像样式 */
.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: #4a4a4a;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    flex-shrink: 0;
    user-select: none;
    position: relative;
    margin: 0 10px; /* 统一为左右都添加边距 */
}

/* 5. 玩家头像可点击样式 */
.user-message-row .avatar {
    cursor: pointer;
}

/* 6. 确保消息框本身没有冲突的对齐样式 */
.message {
   align-self: auto;
}

/* 7. 修正消息框圆角 */
.user-message {
    align-self: auto;
    border-bottom-left-radius: 18px; 
}
.keeper-message, .system-message {
    align-self: auto;
    border-bottom-right-radius: 18px; 
}

/* style.css (請用這段代碼替換掉之前的 .rollback-menu 樣式) */

.rollback-menu {
    position: absolute;
    bottom: 110%; /* 顯示在頭像的正上方 */
    left: 50%;
    transform: translateX(-50%);
    
    background-color: #333; /* 【樣式優化】深色背景 */
    color: #e0e0e0;
    border: 1px solid #555;
    border-radius: 6px;
    padding: 8px 14px;
    white-space: nowrap; 
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    z-index: 10;
    cursor: pointer;
    font-size: 14px;
    
    /* 【樣式優化】添加漸入動畫 */
    opacity: 0;
    transform: translateX(-50%) translateY(5px);
    animation: fadeInMenu 0.2s forwards;
}

/* 【樣式優化】為菜單添加一個小箭頭 */
.rollback-menu::after {
    content: '';
    position: absolute;
    top: 100%; /* 箭頭在菜單底部 */
    left: 50%;
    transform: translateX(-50%);
    border-width: 6px;
    border-style: solid;
    border-color: #333 transparent transparent transparent;
}

@keyframes fadeInMenu {
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* --- 消息樣式調整 (保持不變) --- */
.message { align-self: auto; }
.user-message { align-self: auto; border-bottom-left-radius: 18px; }
.keeper-message, .system-message { align-self: auto; border-bottom-right-radius: 18px; }

/* style.css (在文件末尾添加) */

/* --- 新增：通知類型消息樣式 --- */
.notification-message {
    align-self: center; /* 水平居中 */
    background-color: transparent;
    color: #888; /* 暗灰色文字 */
    font-size: 0.8em; /* 小一號字體 */
    padding: 5px 10px;
    margin: 5px 0;
    text-align: center;
}

/* --- 新增：页面主头部样式 --- */
.header-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 30px;
    background-color: #1f1f1f;
    border-bottom: 1px solid #333;
    width: 100%;
    box-sizing: border-box;
    flex-shrink: 0;
}
.logo { display: flex; align-items: center; font-size: 1.5em; gap: 10px; }
.logo img { height: 40px; }
.search-bar { flex-grow: 1; margin: 0 40px; display: flex; }
.search-bar input { width: 100%; padding: 10px 15px; border: 1px solid #444; background-color: #333; color: #e0e0e0; border-radius: 20px 0 0 20px; outline: none; }
.search-bar button { padding: 10px 20px; border: 1px solid #007bff; background-color: #007bff; color: white; border-radius: 0 20px 20px 0; cursor: pointer; }
.user-profile { color: #ccc; }

/* --- 新增：分类导航栏样式 --- */
.category-nav {
    display: flex;
    padding: 0 30px;
    background-color: #2a2a2a;
    border-bottom: 1px solid #333;
    width: 100%;
    box-sizing: border-box;
    flex-shrink: 0;
}
.nav-tab {
    padding: 15px 20px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    color: #b0b0b0;
    cursor: pointer;
    font-size: 1em;
    transition: all 0.2s;
}
.nav-tab:hover {
    color: white;
}
.nav-tab.active {
    color: #007bff;
    border-bottom-color: #007bff;
}
/* --- 修改后的剧本列表样式 --- */

/* 列表容器现在作为网格的父级 */
#scenario-list-container {
    width: 100%;
    flex-grow: 1;
    overflow-y: auto;
    box-sizing: border-box;
}

/* 栅格布局 */
#scenario-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 30px;
    
    max-width: 1300px; /* 可以稍微放宽一点以容纳更多卡片 */
    margin: 0 auto;
    padding: 30px; /* 内边距 */
    box-sizing: border-box;
    align-content: start; /* 解决之前讨论过的重叠问题 */
}

/* 【核心】使用回 scenario-card 的样式 */
.scenario-card {
    background-color: #2a2a2a;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
    display: flex;
    flex-direction: column;
}

.scenario-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0, 123, 255, 0.3);
}

.scenario-card img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    display: block;
}

.scenario-card .card-content {
    padding: 20px;
    flex-grow: 1;
}

.scenario-card h2 {
    font-size: 1.4em;
    margin: 0 0 10px;
}

.scenario-card p {
    font-size: 0.9em;
    color: #b0b0b0;
    line-height: 1.6;
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 3; /* 卡片模式下可以显示3行摘要 */
    -webkit-box-orient: vertical;  
    overflow: hidden;
}

.empty-list-info {
    color: #888;
    text-align: center;
    padding: 50px;
    grid-column: 1 / -1; /* 让提示信息占据整行 */
}

/* public/style.css (在文件末尾添加) */

/* --- 新增：玩家头像按钮样式 --- */
#player-avatar-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: #007bff;
    color: white;
    border: none;
    font-size: 1.2em;
    font-weight: bold;
    cursor: pointer;
    margin-left: 15px;
    flex-shrink: 0;
    display: none; /* 默认隐藏 */
    align-items: center;
    justify-content: center;
    order: -1; /* 确保它在标题左边 */
}
#player-avatar-btn:hover {
    background-color: #0056b3;
}

/* --- 新增：开始故事按钮样式 --- */
#start-game-btn {
    display: none; /* 默认隐藏 */
    margin-right: 10px;
    padding: 10px 15px;
    border: none;
    background-color: #28a745; /* 绿色 */
    color: white;
    border-radius: 20px;
    cursor: pointer;
    font-size: 1em;
    white-space: nowrap;
}
#start-game-btn:hover {
    background-color: #218838;
}

/* --- 新增：角色卡弹窗样式 --- */
#character-sheet-content {
    text-align: left;
    max-height: 60vh;
    overflow-y: auto;
    padding-right: 15px; /* 为滚动条留出空间 */
    margin-bottom: 20px;
}
#character-sheet-content h2 {
    text-align: center;
    margin-top: 0;
    color: #00aaff;
}
#character-sheet-content h3 {
    border-bottom: 1px solid #444;
    padding-bottom: 5px;
    margin-top: 20px;
}
#character-sheet-content ul {
    list-style: none;
    padding-left: 0;
}
#character-sheet-content li {
    background-color: #333;
    padding: 8px 12px;
    border-radius: 4px;
    margin-bottom: 8px;
}
#close-character-sheet-btn {
    background-color: #007bff;
    width: 100%;
}

/* Room management styles */
#room-management {
    padding: 20px;
    background-color: #2a2a2a;
    border-radius: 8px;
    margin: 20px;
}

.room-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.room-controls button {
    background-color: #3498db;
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.room-controls button:hover {
    background-color: #2980b9;
}

#rooms-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.room-card {
    background-color: #3a3a3a;
    border: 1px solid #555;
    border-radius: 8px;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
}

.room-card:hover {
    border-color: #3498db;
    background-color: #404040;
}

.room-info h3 {
    margin: 0 0 5px 0;
    color: #3498db;
}

.room-info p {
    margin: 3px 0;
    font-size: 0.9em;
    color: #ccc;
}

.room-info strong {
    color: #e0e0e0;
}

.room-status {
    font-weight: bold;
}

.room-status.password-protected {
    color: #f39c12;
}

.room-status.open {
    color: #27ae60;
}

.room-actions {
    margin-left: 15px;
}

.join-room-btn {
    background-color: #27ae60;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.join-room-btn:hover {
    background-color: #229954;
}

.rooms-empty {
    text-align: center;
    padding: 40px;
    color: #888;
    font-style: italic;
}

/* Modal form styles */
.modal-form {
    margin: 20px 0;
}

.modal-form label {
    display: block;
    margin-bottom: 5px;
    color: #e0e0e0;
    font-weight: bold;
}

.modal-form input,
.modal-form select {
    width: 100%;
    padding: 8px;
    margin-bottom: 15px;
    border: 1px solid #555;
    border-radius: 4px;
    background-color: #3a3a3a;
    color: #e0e0e0;
}

.modal-form input:focus,
.modal-form select:focus {
    outline: none;
    border-color: #3498db;
}