/* --- 1. 全局变量与基础设置 --- */
:root {
    /* 基础色盘 */
    --bg-color: #0a0a0a;
    --panel-bg: rgba(20, 20, 25, 0.95);
    --text-main: #c0c0c0;
    --border-color: #4a4a4a;
    
    /* 身份主题色 */
    --theme-default: #a0a0a0;
    --theme-monster: #8e44ad;  /* 紫色 */
    --theme-hero: #f39c12;     /* 金色 */
    --theme-logic: #3498db;    /* 蓝色 */
    
    /* 当前动态主题色 (默认灰色) */
    --current-theme: var(--theme-default);
}

body {
    font-family: 'Noto Serif SC', serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    margin: 0;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    /* 背景图设置 */
    background-size: cover;
    background-position: center;
    transition: background-image 0.8s ease-in-out;
    overflow: hidden;
}

/* 背景遮罩：让背景变暗模糊，突出前景 */
body::before {
    content: '';
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(2px);
    z-index: -1;
}

/* --- 2. 布局容器 --- */
#app {
    width: 950px;
    height: 90vh;
    display: grid;
    grid-template-columns: 260px 1fr; /* 左侧 260px，右侧自适应 */
    gap: 20px;
    padding: 20px;
    box-sizing: border-box;
}

/* 通用面板样式 */
.panel {
    background: var(--panel-bg);
    border: 2px solid var(--border-color);
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 25px rgba(0,0,0,0.6);
    position: relative;
    transition: border-color 0.3s;
}

/* --- 3. 左侧：角色信息面板 --- */
.char-panel {
    padding: 20px;
}

.char-header {
    border-bottom: 1px solid #333;
    margin-bottom: 15px;
    text-align: center;
    padding-bottom: 10px;
}

.char-title {
    font-family: 'Cinzel', serif;
    font-size: 1.4em;
    color: var(--current-theme); /* 跟随觉醒变色 */
    margin: 0;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.char-subtitle {
    font-size: 0.8em;
    color: #666;
    margin-top: 5px;
}

/* 属性网格 */
.stat-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
}

.stat-item {
    background: rgba(255,255,255,0.05);
    padding: 8px 12px;
    font-size: 0.95em;
    border-left: 3px solid #555;
    font-family: 'Cinzel', monospace;

    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
}
.stat-item:hover {
    background: rgba(255,255,255,0.1);
}

/* --- 4. 身份进度条区域 --- */
.identity-section {
    margin-top: 20px;
    border-top: 1px solid #333;
    padding-top: 15px;
}

.bar-group {
    margin-bottom: 15px;
}

.bar-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.8em;
    margin-bottom: 4px;
    color: #888;
}

.bar-track {
    background: #222;
    height: 6px;
    border-radius: 3px;
    overflow: hidden;
    border: 1px solid #333;
}

.bar-fill {
    height: 100%;
    width: 0%; /* JS控制 */
    transition: width 0.6s cubic-bezier(0.25, 1, 0.5, 1);
}

.fill-monster { background: var(--theme-monster); box-shadow: 0 0 5px var(--theme-monster); }
.fill-hero { background: var(--theme-hero); box-shadow: 0 0 5px var(--theme-hero); }
.fill-logic { background: var(--theme-logic); box-shadow: 0 0 5px var(--theme-logic); }

/* --- 5. 系统菜单按钮 --- */
.system-menu {
    margin-top: auto; /* 推到底部 */
    display: flex;
    gap: 10px;
}

.sys-btn {
    flex: 1;
    background: #1a1a1a;
    border: 1px solid #444;
    color: #888;
    padding: 8px;
    cursor: pointer;
    font-size: 0.8em;
    transition: 0.2s;
    font-family: 'Noto Serif SC', serif;
}

.sys-btn:hover {
    background: #333;
    color: #fff;
    border-color: #666;
}

/* --- 6. 右侧：剧情舞台 --- */
.stage-panel {
    padding: 30px;
    position: relative;
}

/* 故事文本区 */
#story-content {
    flex-grow: 1;
    overflow-y: auto;
    font-size: 1.15em;
    line-height: 1.8;
    padding-right: 15px;
    margin-bottom: 20px;
    /* 自定义滚动条 */
    scrollbar-width: thin;
    scrollbar-color: var(--current-theme) #111;
}

/* Webkit 滚动条样式 */
#story-content::-webkit-scrollbar { width: 6px; }
#story-content::-webkit-scrollbar-track { background: #111; }
#story-content::-webkit-scrollbar-thumb { background: var(--current-theme); border-radius: 3px; }

/* 文本高亮 */
.highlight {
    color: var(--current-theme);
    font-weight: bold;
    text-shadow: 0 0 2px rgba(0,0,0,0.5);
}

/* --- 7. 选项按钮区域 --- */
#choices-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 100px; /* 防止内容跳动 */
}

.choice-btn {
    background: linear-gradient(90deg, #151515, #222);
    border: 1px solid #333;
    border-left: 4px solid #555;
    color: #ccc;
    padding: 16px 20px;
    text-align: left;
    cursor: pointer;
    font-family: 'Noto Serif SC', serif;
    font-size: 1em;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
}

.choice-btn:hover:not(:disabled) {
    background: #2a2a2a;
    border-left-color: var(--current-theme);
    padding-left: 25px; /* 移动动画 */
    color: #fff;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

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

.choice-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    filter: grayscale(1);
}

/* 特殊选项边框色 */
.choice-monster { border-left-color: var(--theme-monster); }
.choice-hero { border-left-color: var(--theme-hero); }
.choice-logic { border-left-color: var(--theme-logic); }

/* --- 8. 加载遮罩层 --- */
#loading-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: #000;
    z-index: 999;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    transition: opacity 0.5s ease;
}

/* 确保loading-overlay内的语言切换链接相对于loading-overlay定位 */
#loading-overlay .lang-switch-link {
    position: absolute;
    top: 20px;
    right: 20px;
}

.game-title {
    font-family: 'Cinzel', serif;
    text-align: center;
    font-size: 3em;
    color: #888;
    letter-spacing: 5px;
    margin-bottom: 30px;
    text-shadow: 0 0 10px rgba(255,255,255,0.1);
}

.start-btn {
    padding: 12px 40px;
    background: var(--theme-default);
    border: none;
    color: #000;
    font-weight: bold;
    cursor: pointer;
    font-family: 'Cinzel', serif;
    font-size: 1.2em;
    text-transform: uppercase;
    transition: 0.3s;
    min-width: 200px;
}

.start-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(255,255,255,0.3);
}

/* --- 9. Toast 通知弹窗 --- */
#toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(0,0,0,0.9);
    border-left: 4px solid var(--current-theme);
    padding: 15px 25px;
    color: #fff;
    font-family: 'Noto Serif SC', serif;
    transform: translateX(150%); /* 默认隐藏在右侧外 */
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 1000;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
    pointer-events: none;
}

#toast.show {
    transform: translateX(0);
}

/* =========================================
   MOBILE RESPONSIVE (手机端适配)
   ========================================= */

/* 1. 调整主容器：从固定宽度变为 100% 自适应 */
#app {
    width: 100%;
    max-width: 950px; /*在大屏上保持原样，小屏自动缩放*/
}

/* 2. 针对小于 768px 的屏幕 (手机竖屏) */
@media screen and (max-width: 768px) {
    
    body {
        /* 防止手机浏览器下拉刷新导致的橡皮筋效果，更像原生App */
        background-attachment: scroll;
        background-position: center top;
    }

    #app {
        /* 改为上下布局 */
        display: flex;
        flex-direction: column; 
        height: 100vh; /* 占满全屏 */
        padding: 10px; /* 减小边距 */
        gap: 10px;
    }

    /* --- 上半部分：剧情区 (Stage) --- */
    .stage-panel {
        order: 1; /* 让剧情显示在最上面 */
        flex: 1;  /* 自动占据剩余所有空间 */
        min-height: 0; /* 关键：防止 Flex 子元素溢出无法滚动 */
        padding: 20px 15px; /* 减小内边距 */

        background: rgba(0,0,0,0.4) !important;

        border: none;
        box-shadow: none;
    }

    #story-content {
        font-size: 1.1em; /* 手机上字体稍微调小一点点适配 */
        padding-right: 5px;
        text-shadow: 0 2px 4px rgba(0,0,0,0.9);
        color: #fff;
    }

    .highlight {
        text-shadow: 0 0 10px currentColor;
    }

    /* 按钮增大点击区域，方便手指触摸 */
    .choice-btn {
        padding: 14px 15px;
        font-size: 0.95em;
        margin-bottom: 5px;
    }

    /* --- 下半部分：角色面板 (Char) --- */
    .char-panel {
        order: 2; /* 放在底部 */
        height: auto;
        flex-shrink: 0; /* 不允许被压缩 */
        padding: 10px;
        border-top: 2px solid var(--border-color);
        /* 稍微改一下背景色，区分层次 */
        background: rgba(15, 15, 20, 0.98);
        z-index: 10;
    }

    /* 头部简化：名字放左边，系统按钮放右边 */
    .char-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        border: none;
        margin-bottom: 8px;
        padding-bottom: 0;
    }

    .char-title {
        font-size: 1.1em;
        text-align: left;
    }
    
    .char-subtitle { display: none; /* 手机上隐藏职业描述，省空间 */ }

    /* 属性栏改为横向 2x2 排列 */
    .stat-grid {
        display: grid;
        grid-template-columns: 1fr 1fr; /* 两列 */
        gap: 5px;
        margin-bottom: 10px;
    }
    
    .stat-item {
        padding: 4px 8px;
        font-size: 0.8em;
    }

    /* 身份条压缩高度 */
    .identity-section {
        margin-top: 0;
        border-top: none;
        padding-top: 0;
        display: flex;
        gap: 10px;
        overflow-x: auto; /* 如果太挤允许横向滚动 */
    }
    
    .bar-group {
        flex: 1; /* 三个条平分宽度 */
        margin-bottom: 0;
    }
    
    .bar-label span:first-child {
        display: none; /* 手机上隐藏文字标签(如"怪物性")，只看颜色和数值，省空间 */
    }
    .bar-label { justify-content: center; } /* 数值居中 */

    /* 系统菜单调整到右上角，或者隐藏 */
    .system-menu {
        margin-top: 0;
        display: none; /* 手机上暂时隐藏重置按钮，防止误触，或者移到顶部 */
    }
    
    /* 可以在右上角加一个小的设置图标来唤起菜单，目前Demo先简化隐藏 */
}

/* --- 转场遮罩层 --- */
#transition-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: 2000;
    pointer-events: none; /* 默认不阻挡点击，显示时开启 */
    opacity: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 1s ease;
}

.transition-content {
    text-align: center;
    color: #fff;
}

#trans-title {
    font-family: 'Cinzel', serif;
    font-size: 3em;
    margin: 0;
    letter-spacing: 5px;
    text-transform: uppercase;
    text-shadow: 0 0 20px rgba(0,0,0,0.8);
    transform: translateY(20px);
    opacity: 0;
    transition: all 1.5s ease;
}

#trans-sub {
    font-family: 'Noto Serif SC', serif;
    font-size: 1.2em;
    color: #aaa;
    margin-top: 15px;
    letter-spacing: 2px;
    opacity: 0;
    transform: translateY(20px);
    transition: all 1.5s ease 0.5s; /* 延迟显示 */
}

/* --- 状态类 --- */

/* 1. 章节过场 (黑色背景) */
#transition-overlay.mode-chapter {
    background: #000;
    pointer-events: all; /* 阻挡操作 */
}
/* 激活状态 */
#transition-overlay.active { opacity: 1; }
#transition-overlay.active #trans-title,
#transition-overlay.active #trans-sub {
    opacity: 1;
    transform: translateY(0);
}

/* 2. 死亡/失败 (血红背景) */
#transition-overlay.mode-death {
    background: rgba(50, 0, 0, 0.95);
    pointer-events: all;
}
#transition-overlay.mode-death #trans-title { color: #e74c3c; }

/* 3. 结局 (白色/金色背景 - 可选，这里用深邃黑) */
#transition-overlay.mode-ending {
    background: #000;
    pointer-events: all;
}
#transition-overlay.mode-ending #trans-title { color: var(--theme-hero); }


/* --- 受伤特效 (屏幕边缘红光) --- */
@keyframes damage-flash {
    0% { box-shadow: inset 0 0 0 0 rgba(255,0,0,0); }
    50% { box-shadow: inset 0 0 100px 50px rgba(160, 0, 0, 0.5); }
    100% { box-shadow: inset 0 0 0 0 rgba(255,0,0,0); }
}

.damage-effect {
    animation: damage-flash 0.5s ease-out;
}

/* --- 骰子动画遮罩 --- */
#dice-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.85); /* 深色背景 */
    z-index: 3000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none; /* 默认不阻挡点击 */
    transition: opacity 0.3s;
}

#dice-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.dice-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    transform: scale(0.8);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#dice-overlay.active .dice-wrapper {
    transform: scale(1);
}

/* --- D20 骰子视觉 (用 CSS 画一个发光的六边形模拟) --- */
.d20-shape {
    width: 120px;
    height: 120px;
    background: linear-gradient(135deg, #333, #111);
    border: 4px solid var(--theme-hero); /* 默认金色边框 */
    border-radius: 20px; /* 圆角矩形，简单美观 */
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Cinzel', serif;
    font-size: 3.5em;
    font-weight: bold;
    color: #fff;
    box-shadow: 0 0 30px rgba(243, 156, 18, 0.3);
    position: relative;
}

/* 滚动时的震动动画 */
@keyframes shake-dice {
    0% { transform: translate(1px, 1px) rotate(0deg); }
    10% { transform: translate(-1px, -2px) rotate(-1deg); }
    20% { transform: translate(-3px, 0px) rotate(1deg); }
    30% { transform: translate(3px, 2px) rotate(0deg); }
    40% { transform: translate(1px, -1px) rotate(1deg); }
    50% { transform: translate(-1px, 2px) rotate(-1deg); }
    60% { transform: translate(-3px, 1px) rotate(0deg); }
    70% { transform: translate(3px, 1px) rotate(-1deg); }
    80% { transform: translate(-1px, -1px) rotate(1deg); }
    90% { transform: translate(1px, 2px) rotate(0deg); }
    100% { transform: translate(1px, -2px) rotate(-1deg); }
}

.d20-shape.rolling {
    animation: shake-dice 0.1s infinite;
    color: #888;
    border-color: #666;
    box-shadow: none;
}

/* --- 结果文本 --- */
.dice-info {
    font-family: 'Noto Serif SC', serif;
    font-size: 1.2em;
    color: #ccc;
    opacity: 0;
    transition: opacity 0.5s;
}

/* --- 成功/失败印章 --- */
.dice-result-stamp {
    font-family: 'Cinzel', serif;
    font-size: 3em;
    font-weight: bold;
    text-transform: uppercase;
    border: 5px solid currentColor;
    padding: 10px 30px;
    border-radius: 10px;
    transform: scale(2) rotate(-10deg); /* 初始放大 */
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* 成功样式 */
.dice-result-stamp.success {
    color: #2ecc71; /* 绿色 */
    text-shadow: 0 0 20px rgba(46, 204, 113, 0.5);
}

/* 失败样式 */
.dice-result-stamp.fail {
    color: #e74c3c; /* 红色 */
    text-shadow: 0 0 20px rgba(231, 76, 60, 0.5);
}

/* 印章盖下动画 */
.dice-result-stamp.stamp-down {
    transform: scale(1) rotate(-10deg);
    opacity: 1;
}

/* --- Language Switcher --- */
/* 主页面语言切换链接 - 右上角 */
.lang-switch-link {
    position: absolute !important;
    top: 20px !important;
    right: 20px !important;
    background: rgba(255, 255, 255, 0.1) !important;
    border: 2px solid rgba(255, 255, 255, 0.3) !important;
    color: #fff !important;
    padding: 10px 20px !important;
    border-radius: 5px !important;
    cursor: pointer !important;
    font-family: 'Cinzel', 'Noto Serif SC', serif !important;
    font-size: 0.9em !important;
    transition: all 0.3s ease !important;
    backdrop-filter: blur(5px) !important;
    -webkit-backdrop-filter: blur(5px) !important;
    z-index: 1000 !important;
    text-decoration: none !important;
    display: inline-block !important;
    line-height: 1.4 !important;
    white-space: nowrap !important;
}

.lang-switch-link:hover {
    background: rgba(255, 255, 255, 0.2) !important;
    border-color: rgba(255, 255, 255, 0.5) !important;
    transform: translateY(-2px) !important;
    box-shadow: 0 4px 12px rgba(255, 255, 255, 0.2) !important;
}

.lang-switch-link:active {
    transform: translateY(0) !important;
}

/* 系统菜单中的语言切换按钮 */
.lang-link {
    background: transparent !important;
    border: none !important;
    color: var(--current-theme, #9370db) !important;
    padding: 8px 12px !important;
    font-size: 1.2em !important;
    cursor: pointer !important;
    transition: all 0.3s ease !important;
    text-decoration: none !important;
    display: inline-block !important;
    text-align: center !important;
    min-width: 44px !important;
}

.lang-link:hover {
    transform: scale(1.1) !important;
    filter: brightness(1.3) !important;
}

.lang-link:active {
    transform: scale(0.95) !important;
}

/* 移动端优化 */
@media (max-width: 768px) {
    .lang-switch-link {
        top: 10px !important;
        right: 10px !important;
        padding: 8px 15px !important;
        font-size: 0.8em !important;
    }
}