:root {
    --bg-color: #050505;
    --primary: #00f3ff;    /* 青色 */
    --secondary: #00ff41;  /* 綠色 */
    --danger: #ff0055;     /* 紅色 */
    --warn: #ffcc00;       /* 黃色 */
    --glass: rgba(10, 15, 20, 0.9);
    --font-head: 'Orbitron', sans-serif;
    --font-code: 'Share Tech Mono', monospace;
}

* { box-sizing: border-box; }

body {
    margin: 0; padding: 0;
    background-color: #000;
    color: var(--primary);
    font-family: var(--font-code);
    height: 100vh;
    width: 100vw;
    overflow: hidden; /* 禁止整個網頁捲動，只讓終端機內部捲動 */
    display: flex;
    justify-content: center;
    align-items: center;
}

/* --- 背景特效 --- */
.scanlines {
    position: fixed; inset: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
    background-size: 100% 3px, 3px 100%;
    pointer-events: none;
    z-index: 100;
    opacity: 0.4;
}

.noise-bg {
    position: fixed; inset: 0;
    opacity: 0.04;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='1'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 99;
}

.vignette {
    position: fixed; inset: 0;
    background: radial-gradient(circle, transparent 60%, #000 100%);
    pointer-events: none;
    z-index: 98;
}

/* --- 核心佈局 (修正高度問題) --- */
.layout-grid {
    display: grid;
    grid-template-columns: 320px 1fr; /* 左邊固定，右邊自適應 */
    gap: 20px;
    width: 95%;
    height: 90vh; /* 固定高度，關鍵！ */
    max-width: 1600px;
    z-index: 10;
    position: relative;
}

/* --- 左側 HUD 面板 --- */
.hud-panel {
    display: flex;
    flex-direction: column;
    gap: 15px;
    height: 100%;
    overflow-y: auto; /* 如果 HUD 內容太多也可以捲動 */
}

.hud-panel::-webkit-scrollbar { display: none; } /* 隱藏 HUD 的捲軸 */

.hud-box {
    background: var(--glass);
    border: 1px solid rgba(0, 243, 255, 0.3);
    padding: 15px;
    backdrop-filter: blur(4px);
    box-shadow: 0 0 15px rgba(0, 243, 255, 0.05);
    flex-shrink: 0; /* 防止被壓縮 */
}

.hud-title {
    font-family: var(--font-head);
    color: var(--secondary);
    border-bottom: 1px solid var(--secondary);
    padding-bottom: 5px;
    margin-bottom: 10px;
    letter-spacing: 2px;
    font-size: 0.9rem;
    font-weight: 700;
}

.hud-row {
    display: flex; justify-content: space-between;
    margin-bottom: 6px;
    font-size: 0.9rem;
    color: #889;
}
.hud-row span:last-child { font-weight: bold; }
.highlight { color: #fff; text-shadow: 0 0 5px var(--primary); }
.danger { color: var(--danger); text-shadow: 0 0 5px var(--danger); animation: blink 0.5s infinite alternate; }

/* 完整性條 */
.integrity-bar-wrap {
    width: 100%; height: 8px;
    background: #222;
    border: 1px solid #444;
    margin-bottom: 5px;
}
.integrity-bar {
    width: 100%; height: 100%;
    background: var(--danger);
    box-shadow: 0 0 10px var(--danger);
    transition: width 0.3s ease-out;
}

#decryption-canvas {
    width: 100%;
    height: 180px;
    background: rgba(0,0,0,0.5);
    border: 1px solid #333;
}

/* --- 右側 終端機 (滾動修復核心) --- */
.terminal-main {
    display: flex;
    flex-direction: column;
    height: 100%; /* 繼承父容器高度 */
    min-height: 0; /* Flexbox 溢出修復關鍵 */
}

.term-window {
    flex: 1; /* 佔滿剩餘空間 */
    background: rgba(5, 8, 10, 0.95);
    border: 1px solid var(--primary);
    display: flex;
    flex-direction: column; /* 垂直排列 */
    box-shadow: 0 0 30px rgba(0, 243, 255, 0.1);
    position: relative;
    overflow: hidden; /* 防止視窗本身出現捲軸 */
}

.term-header {
    background: rgba(0, 243, 255, 0.1);
    padding: 10px 15px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--primary);
    flex-shrink: 0; /* Header 不縮放 */
}

.lights span {
    display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px;
}
.lights .red { background: #ff5f56; }
.lights .yellow { background: #ffbd2e; }
.lights .green { background: #27c93f; }

.term-header .title {
    margin-left: auto; margin-right: auto;
    font-family: var(--font-head);
    font-size: 0.9rem;
    letter-spacing: 2px;
    color: #fff;
}

/* --- 訊息內容區 (這是會滾動的區域) --- */
.term-content {
    flex: 1; /* 自動佔滿中間區域 */
    padding: 20px;
    overflow-y: auto; /* ★★★ 這裡決定了只有中間會滾動 ★★★ */
    font-size: 1.1rem;
    line-height: 1.5;
    word-break: break-word; /* 防止長代碼撐破寬度 */
    scroll-behavior: auto; /* 為了 JS 快速滾動 */
}

/* 自定義捲軸樣式 (Webkit) */
.term-content::-webkit-scrollbar { width: 8px; }
.term-content::-webkit-scrollbar-track { background: #050505; }
.term-content::-webkit-scrollbar-thumb { 
    background: var(--primary); 
    border-radius: 2px;
}
.term-content::-webkit-scrollbar-thumb:hover { background: #fff; }

.log-line { margin-bottom: 4px; text-shadow: 0 0 2px rgba(0,243,255,0.3); }
.sys { color: #666; font-size: 0.9rem; }
.info { color: var(--primary); }
.warn { color: var(--warn); }
.error { color: var(--danger); }
.success { color: var(--secondary); }
.cmd { color: #fff; font-weight: bold; background: rgba(255,255,255,0.1); padding: 0 5px; }

/* 輸入區 */
.input-area {
    padding: 15px 20px;
    background: rgba(0,0,0,0.8);
    display: flex;
    align-items: center;
    border-top: 1px solid rgba(0, 243, 255, 0.2);
    flex-shrink: 0; /* 輸入框不縮放 */
}

.prompt { color: var(--secondary); margin-right: 10px; font-weight: bold; white-space: nowrap; }

#cmd-input {
    background: transparent; 
    border: none; 
    outline: none;
    color: #fff; 
    font-family: var(--font-code); 
    font-size: 1.1rem;
    flex: 1; 
    width: 100%;
}

.cursor-block {
    width: 10px; height: 1.2em; background: var(--secondary);
    animation: blink 1s step-end infinite;
    margin-left: 5px;
}

@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* --- 成功模態視窗 --- */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.9);
    z-index: 200;
    display: none;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}
.modal-overlay.active { display: flex; animation: fadeIn 0.5s; }

.modal-box {
    text-align: center;
    border: 2px solid var(--secondary);
    padding: 40px;
    background: rgba(0, 20, 0, 0.95);
    box-shadow: 0 0 50px var(--secondary);
    max-width: 90%;
}

.modal-glitch {
    font-family: var(--font-head);
    font-size: 3rem;
    color: #fff;
    font-weight: 900;
    margin-bottom: 20px;
    text-shadow: 2px 2px var(--danger), -2px -2px var(--primary);
}

.cyber-btn {
    background: var(--secondary);
    color: #000;
    border: none;
    padding: 15px 40px;
    font-family: var(--font-head);
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    margin-top: 30px;
    transition: 0.3s;
    text-transform: uppercase;
    letter-spacing: 2px;
}
.cyber-btn:hover {
    background: #fff;
    box-shadow: 0 0 30px var(--secondary);
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* =========================================
   RWD 響應式設計 (手機版適配)
   ========================================= */
@media (max-width: 900px) {
    .layout-grid {
        grid-template-columns: 1fr; /* 改為單欄 */
        grid-template-rows: auto 1fr; /* 上方是 HUD，下方是終端機 */
        height: 100vh; /* 佔滿全螢幕 */
        width: 100%;
        gap: 0;
    }

    /* 調整 HUD 變成頂部資訊列 */
    .hud-panel {
        flex-direction: row; /* 橫向排列 */
        height: auto;
        padding: 10px;
        background: #000;
        border-bottom: 1px solid var(--primary);
        gap: 10px;
        overflow-x: auto; /* 允許橫向滑動 */
        white-space: nowrap;
    }

    /* 隱藏比較不重要的 Canvas 和大區塊，只留關鍵數據 */
    #decryption-canvas, .hud-title { display: none; }
    
    .hud-box {
        padding: 8px;
        background: transparent;
        border: none;
        box-shadow: none;
        display: flex;
        align-items: center;
        gap: 15px;
    }

    .hud-row { margin-bottom: 0; font-size: 0.8rem; }
    .mt-20 { margin-top: 0; }
    
    /* 終端機佔滿剩下空間 */
    .terminal-main {
        padding: 0;
        border-top: none;
    }

    .term-window {
        border: none;
        border-top: 1px solid rgba(0, 243, 255, 0.3);
    }

    .term-content {
        padding: 10px;
        font-size: 0.9rem; /* 手機字體小一點 */
    }

    .input-area {
        padding: 10px;
    }

    .prompt { font-size: 0.9rem; }
    #cmd-input { font-size: 1rem; }

    /* 模態視窗調整 */
    .modal-glitch { font-size: 2rem; }
    .cyber-btn { padding: 12px 30px; font-size: 1rem; }
}