/**
 * CRT Theme - Main Game Integration (Layout Adjusted)
 * 策略：Wrapper Only + Fixed Width + Thicker Border
 */

/* VT323 等宽复古字体 */
@import url('https://fonts.googleapis.com/css2?family=VT323&display=swap');

:root {
    --bezel-color: #222;
    --bg-screen: #031205;
    /* --phosphor-primary 和 --phosphor-dim 由 main.css 主题系统控制 */
}

/* 覆盖 body 样式，使其成为黑暗房间背景，并居中显示器 */
body {
    background-color: #080808 !important;
    overflow: hidden !important;
    margin: 0 !important;
    /* 安全区域支持 - Safe Area Support for notch screens */
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left) !important;
    width: 100vw !important;
    height: calc(var(--vh, 1vh) * 100) !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    font-family: 'VT323', 'Zpix', monospace !important;
    box-sizing: border-box !important;
}

/* ========== 1. 物理容器 (The Container) ========== */

/* 显示器外壳 - 调整尺寸和边框 */
.monitor-bezel {
    position: relative;
    width: 1390px;
    /* 增加宽度以容纳右侧心电图面板 */
    height: 95vh;
    /* 保持高度 */
    max-width: 98vw;
    /* 防止在小屏幕溢出 */
    background: var(--bezel-color);
    border-radius: 30px;
    /* 稍微增加圆角 */
    padding: 50px 220px 50px 70px;
    /* 非对称边框：上 右 下 左 */
    box-shadow:
        inset 0 0 2px rgba(255, 255, 255, 0.1),
        0 0 0 5px #1a1a1a,
        0 20px 50px rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

/* 屏幕区域 */
.crt-screen {
    width: 100%;
    height: 100%;
    background-color: var(--bg-screen);
    border-radius: 100px / 10px;
    /* 曲率 */
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.8);
    /* 内部暗角 */
}

/* ========== 2. 适配原有容器 (Wrapper Strategy) ========== */

/* 强制覆盖 app-container 样式，使其填满 CRT 屏幕 */
.app-container {
    width: 100% !important;
    height: 100% !important;
    border: none !important;
    /* 移除原有的绿色边框 */
    margin: 0 !important;
    padding: 15px 25px !important;
    /* 内边距让内容远离曲面边缘 */
    box-sizing: border-box !important;
    position: relative;
    z-index: 5;
    background-color: var(--bg-screen) !important;
    /* 暗绿色背景，与内部一致 */
}

/* 调整内部比例，适配较窄的容器 */
.left-sidebar {
    width: 25% !important;
    /* 增加比例以保持视觉宽度 */
}

.right-area {
    width: 75% !important;
    /* 减小比例 */
}

/* 同样适配 opening-screen */
.opening-screen {
    width: 100% !important;
    height: 100% !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    z-index: 20;
    /* 在 app-container 之上 */
    background-color: var(--bg-screen) !important;
}

/* ========== 3. 信号特效 (The Signal) ========== */

/* 扫描线 - 使用主题颜色 */
.scanlines {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to bottom,
            transparent,
            transparent 50%,
            rgba(0, 0, 0, 0.15) 50%,
            rgba(0, 0, 0, 0.15));
    background-size: 100% 4px;
    pointer-events: none;
    z-index: 50;
    opacity: 0.5;
}

/* 玻璃反光 */
.glass-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 30% 30%,
            rgba(255, 255, 255, 0.05),
            transparent 40%);
    pointer-events: none;
    z-index: 60;
    mix-blend-mode: screen;
}

/* 刷新线动画 - 使用主题颜色 */
.refresh-line {
    position: absolute;
    width: 100%;
    height: 100px;
    background: linear-gradient(to bottom,
            transparent,
            var(--phosphor-dim),
            transparent);
    opacity: 0.15;
    top: -100px;
    left: 0;
    animation: scan 10s linear infinite;
    pointer-events: none;
    z-index: 55;
}

@keyframes scan {
    0% {
        top: -100px;
    }

    100% {
        top: 120%;
    }
}

/* ========== 4. 视觉增强 (Glow & Typography) ========== */

/* 全局文字辉光 - 双重发光模拟荧光管效果 */
.app-container,
.opening-screen {
    text-shadow:
        0 0 2px var(--phosphor-dim),
        0 0 8px var(--phosphor-dim);
    transition: text-shadow 0.3s ease;
}

/* 滚动条隐藏 (为了沉浸感) */
::-webkit-scrollbar {
    width: 0px;
    background: transparent;
}

/* ========== 5. 线条优化 (Line Optimization) ========== */

/* 移除左侧栏内部的水平分割线 */
.file-list,
.tab-switch,
.statistics,
.title-bar,
.feedback-area {
    border-bottom: none !important;
}

/* P5 例外：标题栏有内容时显示虚线分割线 */
.title-bar.has-content {
    border-bottom: 2px dashed var(--phosphor-dim) !important;
}

.input-box-area {
    border-right: none !important;
}

/* 左侧栏垂直分割线 - 字符样式 (Dashed模拟) */
.left-sidebar {
    border-right: 2px dashed var(--phosphor-dim) !important;
}

/* ========== 6. 心电图面板 (ECG Panel) ========== */

/* 心电图面板容器 - 绝对定位在右侧边框区域 */
.ecg-panel {
    position: absolute;
    top: 50px;
    right: 10px;
    width: 200px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    z-index: 100;
}

/* 心电图模块 - 移除外壳，透明容器 */
.ecg-module {
    background-color: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
}

/* 心电图屏幕 - 圆角过渡，与主屏幕背景一致 */
.ecg-screen {
    background-color: var(--bg-screen);
    border: none;
    border-radius: 15px;
    height: 120px;
    width: 100%;
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.6);
}

/* 心电图网格背景 - 已禁用 */
.ecg-grid {
    display: none;
}

/* Canvas 填满屏幕 */
.ecg-screen canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* 心电图信息栏 */
.ecg-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
}

/* 便签样式 - 纱布/旧纸质感 */
.ecg-label {
    background: linear-gradient(135deg,
        #f5f5f0 0%,
        #e8e8e0 50%,
        #f0f0e8 100%);
    padding: 8px 12px;
    border: none;
    box-shadow:
        2px 2px 4px rgba(0,0,0,0.3),
        inset 0 0 10px rgba(0,0,0,0.05);
    transform: rotate(-2deg);
    font-family: 'Caveat', 'Ma Shan Zheng', cursive;
    font-size: 14px;
    color: #1a1a1a;
    line-height: 1.4;
    text-shadow: none;
}

/* 语言切换 - 默认隐藏所有语言标签 */
.ecg-label-zh,
.ecg-label-en {
    display: none;
}

/* 中文模式显示中文标签 */
body.lang-zh .ecg-label-zh {
    display: inline-block;
}

/* 英文模式显示英文标签 */
body.lang-en .ecg-label-en {
    display: inline-block;
}

/* ========== 品牌铭牌 ========== */
.brand-plate {
    position: absolute;
    bottom: 50px;
    right: 10px;
    width: 200px;
    text-align: center;
    padding: 15px 10px;
}

.brand-name {
    font-family: 'Orbitron', sans-serif;
    font-size: 16px;
    color: #555;
    letter-spacing: 3px;
    text-transform: uppercase;
    text-shadow:
        1px 1px 0 #222,
        -1px -1px 0 #444;
}

.brand-name-cn {
    font-family: 'Noto Serif SC', serif;
    font-size: 12px;
    color: #444;
    letter-spacing: 6px;
    margin-top: 4px;
}

/* 响应式：小屏幕隐藏心电图 */
@media (max-width: 1200px) {
    .ecg-panel {
        display: none;
    }
    .monitor-bezel {
        width: 1200px;
        padding: 50px;
    }
}

/* ========== 7. 手机横屏适配 (Mobile Landscape) ========== */

/* 检测手机横屏（与 app.js 的 isMobileLandscape() 保持一致）：
   条件1: 高度 ≤ 600px 且横屏（覆盖大多数手机）
   条件2: 宽高比 ≥ 2:1 且高度 ≤ 1200px 且横屏（覆盖超宽屏/折叠屏设备）

   设备参考：
   - iPhone 15 Pro Max 横屏: 932 × 430
   - 用户设备案例: 1080 × 517（需要条件1覆盖）
*/
@media (max-height: 600px) and (orientation: landscape),
       (min-aspect-ratio: 2/1) and (max-height: 1200px) and (orientation: landscape) {
    /* 隐藏灰色边框，内容全屏 */
    .monitor-bezel {
        width: 100vw;
        height: calc(var(--vh, 1vh) * 100);
        max-width: 100vw;
        padding: 0;
        background: transparent;
        border-radius: 0;
        box-shadow: none;
    }

    /* CRT 屏幕占满全部空间 */
    .crt-screen {
        border-radius: 0;
        box-shadow: none;
    }

    /* 隐藏装饰元素 */
    .ecg-panel,
    .brand-plate {
        display: none !important;
    }

    /* 减小内边距，利用更多空间 */
    .app-container {
        padding: 8px 12px !important;
    }

    /* 输入区自适应高度 */
    .input-area {
        min-height: auto !important;
        padding: 6px 12px !important;
    }

    /* System 输出区只显示1行（利用高度裁剪，配合 justify-content: flex-end） */
    .system-output {
        min-height: auto !important;
        height: 28px !important;
        flex: 0 0 auto !important;
        overflow: hidden !important;
    }

    /* 标签栏靠左，间距紧凑 */
    .tab-switch {
        justify-content: flex-start !important;
        gap: 4px !important;
        padding-left: 4px !important;
        padding-right: 16px !important; /* 避免和右侧虚线重叠 */
    }

    /* 选中标签发光效果减小 */
    .tab-btn.active {
        box-shadow: 0 0 6px var(--phosphor-dim, #4e9c4e) !important;
    }

    /* 输出行紧凑化 */
    .output-line {
        font-size: 18px !important;
        margin: 0 !important;
        line-height: 1.3 !important;
        /* 横屏模式也允许换行 */
        white-space: normal !important;
        word-break: break-word !important;
    }

    /* 手机横屏只显示最新的1条系统消息 */
    .system-output .output-line:first-child {
        display: none !important;
    }

    /* 输入行紧凑化 */
    .input-line {
        padding: 4px 0 !important;
        font-size: 18px !important;
    }

    .prompt {
        font-size: 18px !important;
    }

    .command-input {
        font-size: 18px !important;
    }

    /* 功能按钮栏紧凑化 */
    .function-bar {
        padding: 2px 0 !important;
        gap: 8px !important;
    }

    .func-btn {
        font-size: 16px !important;
        padding: 2px 8px !important;
    }
}

/* 手机竖屏提示：请旋转设备 */
.mobile-rotate-hint {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: calc(var(--vh, 1vh) * 100);
    background: #080808;
    z-index: 9999;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: var(--phosphor-primary, #48a04e);
    font-family: 'VT323', 'Zpix', monospace;
    font-size: 24px;
    text-align: center;
    padding: 20px;
    box-sizing: border-box;
}

/* 根据语言显示对应文字 */
.mobile-rotate-hint .rotate-text-zh,
.mobile-rotate-hint .rotate-text-en {
    display: none;
    line-height: 1.6;
}

/* 默认显示双语 */
.mobile-rotate-hint .rotate-text-zh {
    display: block;
}
.mobile-rotate-hint .rotate-text-en {
    display: block;
    font-size: 18px;
    opacity: 0.7;
    margin-top: 10px;
}

/* 中文模式只显示中文 */
body.lang-zh .mobile-rotate-hint .rotate-text-en {
    display: none;
}

/* 英文模式只显示英文 */
body.lang-en .mobile-rotate-hint .rotate-text-zh {
    display: none;
}
body.lang-en .mobile-rotate-hint .rotate-text-en {
    display: block;
    font-size: 24px;
    opacity: 1;
}

/* 手机竖屏时显示提示 */
@media (max-width: 500px) and (orientation: portrait) {
    .mobile-rotate-hint {
        display: flex;
    }

    .monitor-bezel {
        display: none;
    }
}

/* ========== PWA 安装引导样式（Android 用） ========== */

.pwa-guide {
    margin-top: 40px;
    padding-top: 25px;
    border-top: 1px solid #333;
    font-size: 16px;
    max-width: 300px;
    display: none;  /* 默认隐藏 */
}

.pwa-guide-title {
    margin-bottom: 20px;
    font-size: 14px;
    opacity: 0.6;
}

.pwa-guide-title .pwa-title-zh,
.pwa-guide-title .pwa-title-en {
    display: block;
}

/* Android 设备显示 Android 引导 */
body.is-android .pwa-guide-android {
    display: block;
}

/* PWA 模式下隐藏引导 */
body.is-pwa .pwa-guide {
    display: none !important;
}

.pwa-step {
    margin: 12px 0;
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
}

.pwa-icon {
    font-size: 20px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--phosphor-dim, #48a04e);
    border-radius: 4px;
    flex-shrink: 0;
}

.pwa-step .pwa-text-zh,
.pwa-step .pwa-text-en {
    display: block;
    font-size: 14px;
    line-height: 1.4;
}

.pwa-step strong {
    color: var(--phosphor-primary, #80ff8a);
}

/* 语言控制 - PWA 引导 */
body.lang-zh .pwa-guide .pwa-text-en,
body.lang-zh .pwa-guide .pwa-title-en {
    display: none;
}

body.lang-en .pwa-guide .pwa-text-zh,
body.lang-en .pwa-guide .pwa-title-zh {
    display: none;
}

/* ========== iOS 强制 PWA 提示样式 ========== */

.ios-pwa-required {
    display: none;  /* 默认隐藏 */
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: calc(var(--vh, 1vh) * 100);
    background: #080808;
    z-index: 10000;  /* 高于所有元素 */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: var(--phosphor-primary, #48a04e);
    font-family: 'VT323', 'Zpix', monospace;
    text-align: center;
    padding: 30px;
    box-sizing: border-box;
}

.ios-pwa-title {
    font-size: 28px;
    margin-bottom: 15px;
}

.ios-pwa-subtitle {
    font-size: 16px;
    opacity: 0.6;
    margin-bottom: 40px;
}

.ios-pwa-steps {
    max-width: 320px;
    text-align: left;
}

.ios-pwa-steps .pwa-step {
    margin: 20px 0;
    display: flex;
    align-items: flex-start;
    gap: 15px;
}

.pwa-step-num {
    font-size: 18px;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--phosphor-primary, #48a04e);
    border-radius: 50%;
    flex-shrink: 0;
}

.ios-pwa-steps .pwa-step .pwa-text-zh,
.ios-pwa-steps .pwa-step .pwa-text-en {
    font-size: 16px;
    line-height: 1.5;
}

.share-icon {
    display: inline-block;
    font-size: 18px;
    vertical-align: middle;
}

/* 语言控制 - iOS PWA 提示 */
.ios-pwa-required .pwa-text-zh,
.ios-pwa-required .pwa-title-zh {
    display: block;
}

.ios-pwa-required .pwa-text-en,
.ios-pwa-required .pwa-title-en {
    display: block;
    font-size: 14px;
    opacity: 0.7;
    margin-top: 5px;
}

body.lang-zh .ios-pwa-required .pwa-text-en,
body.lang-zh .ios-pwa-required .pwa-title-en {
    display: none;
}

body.lang-en .ios-pwa-required .pwa-text-zh,
body.lang-en .ios-pwa-required .pwa-title-zh {
    display: none;
}

body.lang-en .ios-pwa-required .pwa-text-en,
body.lang-en .ios-pwa-required .pwa-title-en {
    font-size: inherit;
    opacity: 1;
    margin-top: 0;
}

/* ========== iOS 非 PWA 模式：强制显示 PWA 提示，隐藏游戏 ========== */

/* iOS 浏览器（非 PWA）始终显示强制提示 */
body.is-ios:not(.is-pwa) .ios-pwa-required {
    display: flex !important;
}

/* iOS 浏览器（非 PWA）隐藏游戏界面和旋转提示 */
body.is-ios:not(.is-pwa) .monitor-bezel {
    display: none !important;
}

body.is-ios:not(.is-pwa) .mobile-rotate-hint {
    display: none !important;
}

/* iOS PWA 模式下隐藏强制提示 */
body.is-ios.is-pwa .ios-pwa-required {
    display: none !important;
}