:root {
    --bg-dark: #030305;
    --neon-cyan: #00f3ff;
    --neon-red: #ff003c;
    /* 稍微增加透明度，讓背景粒子更明顯 */
    --glass-bg: rgba(10, 15, 20, 0.75);
    --border-dim: rgba(0, 243, 255, 0.3);
    --font-ui: 'Rajdhani', sans-serif;
    --font-code: 'JetBrains Mono', monospace;
}

/* 全域設定 */
body {
    margin: 0;
    /* 在桌面版隱藏 overflow，在行動版會重新開啟 */
    overflow: hidden;
    background-color: var(--bg-dark);
    color: #fff;
    font-family: var(--font-ui);
    cursor: crosshair; /* 戰術準心游標 */
    user-select: none;
    height: 100vh; /* 確保 body 高度 */
}

/* 背景粒子 Canvas */
#bg-particles {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: -2;
    pointer-events: none; /* 確保不擋住滑鼠互動 */
}

/* 復古噪點層 */
.noise-overlay {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    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.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.05'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: -1;
}

/* 暗角效果 */
.vignette {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: radial-gradient(circle at center, transparent 40%, #000 100%);
    pointer-events: none;
    z-index: -1;
}

/* UI 佈局容器 */
.ui-container {
    height: 100vh; /* 桌面版佔滿全螢幕 */
    padding: 10px 20px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

/* 頂部資訊條 */
.top-bar {
    display: flex;
    align-items: center;
    height: 40px;
    flex-shrink: 0; /* 防止被壓縮 */
    border-bottom: 1px solid var(--border-dim);
    margin-bottom: 15px;
    font-family: var(--font-code);
    font-size: 12px;
    color: var(--neon-cyan);
    letter-spacing: 2px;
}

.decoration-line {
    flex-grow: 1;
    height: 1px;
    background: linear-gradient(90deg, var(--neon-cyan), transparent);
    margin: 0 20px;
    opacity: 0.5;
}

/* 主要 Grid 佈局 (桌面版) */
.grid-layout {
    display: grid;
    /* 左側固定 320px，右側佔滿剩餘空間 */
    grid-template-columns: 320px 1fr;
    gap: 20px;
    flex: 1; /* 填滿 ui-container 的剩餘高度 */
    min-height: 0; /* 重要：防止 Grid/Flex 子元素溢出 */
}

/* 面板通用樣式 */
.panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px); /* Safari 支援 */
    border: 1px solid var(--border-dim);
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* 確保圓角/切角不溢出 */
}

.panel-header {
    height: 36px;
    flex-shrink: 0;
    background: rgba(0, 243, 255, 0.08);
    display: flex;
    align-items: center;
    padding-left: 12px;
    border-bottom: 1px solid var(--border-dim);
}

.panel-title {
    font-family: var(--font-code);
    font-size: 12px;
    color: var(--neon-cyan);
    font-weight: 800;
    letter-spacing: 1px;
}

/* 左側控制面板內容區 */
.control-panel .panel-content {
    padding: 20px;
    flex: 1; /* 填滿垂直空間 */
    overflow-y: auto; /* 內容過多時可滾動 */
    scrollbar-width: thin; /* Firefox 細滾動條 */
    scrollbar-color: var(--neon-cyan) #111;
}

/* Webkit 滾動條樣式 */
.panel-content::-webkit-scrollbar { width: 6px; }
.panel-content::-webkit-scrollbar-track { background: #111; }
.panel-content::-webkit-scrollbar-thumb { background: var(--neon-cyan); }

/* 裝飾性角落 (僅裝飾用，用 CSS border 實現) */
.corner-bracket {
    position: absolute;
    width: 8px; height: 8px;
    border: 2px solid var(--neon-cyan);
    opacity: 0.8;
    pointer-events: none;
}
.top-left { top: 0; left: 0; border-bottom: none; border-right: none; }
.top-right { top: 0; right: 0; border-bottom: none; border-left: none; }
.bottom-left { bottom: 0; left: 0; border-top: none; border-right: none; }
.bottom-right { bottom: 0; right: 0; border-top: none; border-left: none; }

/* 上傳區域 */
.upload-hex {
    height: 140px;
    border: 1px dashed var(--border-dim);
    background: rgba(0, 243, 255, 0.05);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s ease;
    /* 賽博龐克切角效果 */
    clip-path: polygon(15px 0, 100% 0, 100% calc(100% - 15px), calc(100% - 15px) 100%, 0 100%, 0 15px);
}

.upload-hex:hover {
    border-color: var(--neon-cyan);
    background: rgba(0, 243, 255, 0.1);
    box-shadow: 0 0 25px rgba(0, 243, 255, 0.15);
}

.hex-content { text-align: center; }
.icon-upload {
    width: 30px; height: 30px; margin: 0 auto 10px;
    border: 2px solid var(--neon-cyan); border-radius: 4px;
    position: relative;
}
.icon-upload::after {
    content: '↑'; position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%); color: var(--neon-cyan); font-weight: bold;
}

.text-main { font-weight: 700; font-size: 16px; color: #fff; letter-spacing: 1px; margin-bottom: 5px; }
.text-sub { font-family: var(--font-code); font-size: 10px; color: var(--neon-cyan); opacity: 0.7; }

.separator {
    margin: 25px 0 15px 0;
    font-family: var(--font-code);
    font-size: 10px; color: var(--neon-cyan);
    border-bottom: 1px solid var(--border-dim);
    padding-bottom: 4px; opacity: 0.8;
}

/* 控件樣式 */
.control-group { margin-bottom: 25px; }
.control-group label {
    font-family: var(--font-code); font-size: 10px; color: #888;
    display: block; margin-bottom: 10px; letter-spacing: 1px;
}

.mode-switch-container { display: flex; gap: 8px; }

/* 賽博按鈕基礎樣式 */
.cyber-btn {
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--border-dim);
    color: #aaa;
    font-family: var(--font-ui);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    text-transform: uppercase;
    letter-spacing: 1px;
    position: relative;
    overflow: hidden;
    /* 按鈕切角 */
    clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
}

.cyber-btn:hover {
    color: #fff; border-color: var(--neon-cyan);
    background: rgba(0, 243, 255, 0.1);
}

.cyber-btn.active, .cyber-btn:active {
    background: var(--neon-cyan); color: #000;
    border-color: var(--neon-cyan); font-weight: 700;
    box-shadow: 0 0 15px rgba(0, 243, 255, 0.4);
}

.cyber-btn.sm { flex: 1; padding: 10px 0; font-size: 11px; }
.cyber-btn.lg { 
    width: 100%; padding: 16px; font-size: 14px; font-weight: 700;
    margin-top: 10px; border-color: var(--neon-cyan); color: var(--neon-cyan);
}
.cyber-btn.lg:hover:not(:disabled) {
    background: var(--neon-cyan); color: #000;
    box-shadow: 0 0 30px rgba(0, 243, 255, 0.3);
}
.cyber-btn.lg:disabled {
    opacity: 0.4; cursor: not-allowed; filter: grayscale(1);
}

/* 高級 Slider (Input Range) */
.range-wrapper {
    position: relative; height: 6px; background: #111;
    margin-top: 12px; border: 1px solid #333;
}
.cyber-range {
    -webkit-appearance: none; width: 100%; height: 100%;
    background: transparent; position: absolute; top: 0; left: 0;
    z-index: 2; margin: 0; cursor: pointer;
}
/* 滑塊樣式 (Chrome/Safari) */
.cyber-range::-webkit-slider-thumb {
    -webkit-appearance: none; width: 16px; height: 16px;
    background: var(--neon-cyan); border: 2px solid #000;
    transform: rotate(45deg); box-shadow: 0 0 10px var(--neon-cyan);
    margin-top: -5px; /* 校準位置 */
}
/* 滑塊樣式 (Firefox) */
.cyber-range::-moz-range-thumb {
    width: 16px; height: 16px; background: var(--neon-cyan);
    border: 2px solid #000; transform: rotate(45deg);
    box-shadow: 0 0 10px var(--neon-cyan); border-radius: 0;
}
/* 進度條填充層 (由 JS 控制寬度) */
.range-track-fill {
    position: absolute; top: 0; left: 0; height: 100%;
    background: var(--neon-cyan); width: 80%; z-index: 1; opacity: 0.6;
}

.label-row { display: flex; justify-content: space-between; align-items: center; }
.value-display { font-family: var(--font-code); color: var(--neon-cyan); font-size: 14px; font-weight: bold; }

/* Log Terminal (底部訊息欄) */
.log-terminal {
    height: 150px; flex-shrink: 0;
    background: rgba(0,0,0,0.6);
    border-top: 1px solid var(--border-dim);
    padding: 15px;
    font-family: var(--font-code); font-size: 11px; color: #0f0;
    overflow-y: auto;
    display: flex; flex-direction: column-reverse; /* 新訊息在最上方 */
}
.log-line { margin-bottom: 4px; word-break: break-all; }

/* =========================================
   右側視圖關鍵修改 (修復圖片過小問題)
   ========================================= */
.viewport-panel {
    /* 確保右側面板沒有內邊距擠壓 Canvas */
    padding: 0 !important; 
}

.viewport-frame {
    position: relative;
    width: 100%;
    /* 關鍵：使用 flex: 1 讓它填滿剩餘垂直空間 */
    flex: 1; 
    background: #000;
    overflow: hidden;
    display: flex; /* 確保內部 Canvas 置中填滿 */
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    /* 確保 Canvas 不會因為父層計算問題而被壓縮 */
    object-fit: contain; 
}

/* HUD 標記 (角落十字) */
.hud-marker {
    position: absolute; width: 15px; height: 15px;
    border: 1px solid var(--neon-cyan); opacity: 0.5; pointer-events: none;
}
.m-tl { top: 10px; left: 10px; border-bottom: 0; border-right: 0; }
.m-tr { top: 10px; right: 10px; border-bottom: 0; border-left: 0; }
.m-bl { bottom: 10px; left: 10px; border-top: 0; border-right: 0; }
.m-br { bottom: 10px; right: 10px; border-top: 0; border-left: 0; }

/* 中央準心 */
.hud-crosshair {
    position: absolute; top: 50%; left: 50%;
    width: 60px; height: 60px;
    transform: translate(-50%, -50%);
    border: 1px dashed rgba(0, 243, 255, 0.3);
    border-radius: 50%; pointer-events: none;
}
.hud-crosshair::after {
    content: ''; position: absolute; top: 50%; left: 50%;
    width: 4px; height: 4px; background: var(--neon-red);
    transform: translate(-50%, -50%); border-radius: 50%;
    box-shadow: 0 0 10px var(--neon-red);
}

/* 底部數據顯示 */
.meta-data {
    position: absolute; bottom: 15px; right: 20px;
    font-family: var(--font-code); font-size: 10px; color: var(--neon-cyan);
    display: flex; gap: 20px; opacity: 0.7;
    text-shadow: 0 0 5px rgba(0, 243, 255, 0.3);
    pointer-events: none;
}

/* Loading 動畫 */
.loader-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(3, 3, 5, 0.9);
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    z-index: 10; opacity: 0; pointer-events: none; transition: opacity 0.3s ease;
}
.loader-overlay.active { opacity: 1; pointer-events: all; }

.cyber-spinner {
    width: 60px; height: 60px;
    border: 3px solid transparent;
    border-top-color: var(--neon-cyan); border-bottom-color: var(--neon-red);
    border-radius: 50%; animation: spin 1.5s cubic-bezier(0.68, -0.55, 0.27, 1.55) infinite;
}
.decoding-text {
    margin-top: 20px; font-family: var(--font-code); letter-spacing: 3px;
    font-size: 12px; color: var(--neon-cyan);
    animation: blink 0.8s infinite alternate;
}

@keyframes spin { 100% { transform: rotate(360deg); } }
@keyframes blink { from { opacity: 0.4; } to { opacity: 1; } }


/* =========================================
   響應式設計 (Responsive Design)
   當螢幕寬度小於 900px 時觸發
   ========================================= */
@media screen and (max-width: 900px) {
    body {
        /* 行動版允許捲動 */
        overflow: auto;
        height: auto;
        min-height: 100vh;
    }

    .ui-container {
        height: auto; /* 不再強制全螢幕高度 */
        min-height: 100vh;
        padding: 10px;
    }

    .top-bar {
        font-size: 10px;
        margin-bottom: 10px;
    }
    .decoration-line { margin: 0 10px; }

    .grid-layout {
        /* 改為單欄佈局 */
        grid-template-columns: 1fr;
        /* 第一列 (控制面板): 高度 auto (依內容撐開)
           第二列 (畫布面板): 至少 450px 高，或是佔據螢幕 60% 高度
        */
        grid-template-rows: auto minmax(450px, 60vh); 
        gap: 15px;
    }

    /* 控制面板在行動版不需要捲動 */
    .control-panel .panel-content {
        overflow-y: visible;
        padding: 15px;
    }

    .upload-hex { height: 100px; }
    .log-terminal { height: 100px; }

    /* 調整按鈕大小更適合觸控 */
    .cyber-btn.sm { padding: 12px 0; font-size: 12px; }
    .cyber-btn.lg { padding: 18px; font-size: 16px; }

    /* 確保畫布面板在手機上也有足夠高度 */
    .viewport-panel {
        min-height: 450px;
    }
}

/* 3D 特殊按鈕 */
.special-mode {
    border-color: var(--neon-red);
    color: var(--neon-red);
    font-weight: bold;
}
.special-mode.active {
    background: var(--neon-red);
    color: #000;
    box-shadow: 0 0 20px rgba(255, 0, 60, 0.4);
}
.btn-blink {
    animation: blink-red 1s infinite;
    margin-right: 5px;
}
@keyframes blink-red { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* 數據分析覆蓋層 (預設隱藏，分析時顯示) */
.analysis-overlay {
    position: absolute;
    bottom: 40px; left: 20px;
    width: 250px;
    background: rgba(0, 0, 0, 0.8);
    border: 1px solid var(--border-dim);
    padding: 10px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.5s;
    z-index: 5;
}
.analysis-overlay.visible { opacity: 1; }

.chart-title {
    font-size: 10px; color: #888; margin-bottom: 5px;
}
.chart-bars {
    display: flex;
    align-items: flex-end;
    height: 60px;
    gap: 1px;
    border-bottom: 1px solid #444;
}
.hist-bar {
    flex: 1;
    background: var(--neon-cyan);
    opacity: 0.6;
    transition: height 0.2s;
}

.data-readout {
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: var(--neon-red);
}