/* css/style.css */
/* 核心變數定義：管理主題顏色與元件規範 */
:root {
    --bg-body: #161618;
    --panel: rgba(20, 20, 22, 0.88); /* 深色半透明：提升可讀性 */
    --panel-light: rgba(28, 28, 30, 0.78); 
    --input: rgba(28, 28, 30, 0.82);
    --text: #f0f0f2;
    --subtext: #8e8e93;
    --accent: #0a84ff;
    --accent-hover: #0077ed;
    --border: rgba(255, 255, 255, 0.14);
    --success: #30d158;
    --danger: #ff453a;
    --warn: #ff9f0a;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --mono: "SF Mono", "Menlo", "Consolas", monospace;
    --radius: 16px; 
    --shadow: 0 8px 32px rgba(0,0,0,0.3);
    --switch-bg-off: #48484a;
    --switch-bg-on: var(--accent);
    --switch-knob: #fff;
    --btn-default-bg: #3a3a3c; 
}

/* 淺色模式主題覆蓋設定 */
body.light-mode {
    --bg-body: transparent;
    --panel: rgba(255, 255, 255, 0.65); /* 亮色下底色稍濃以利閱讀 */
    --panel-light: rgba(255, 255, 255, 0.4);
    --input: rgba(0, 0, 0, 0.05);
    --text: #1c1c1e;
    --subtext: #6e6e73;
    --accent: #007aff;
    --accent-hover: #006add;
    --border: rgba(0, 0, 0, 0.08);
    --success: #34c759;
    --danger: #ff3b30;
    --warn: #ff9500;
    --switch-bg-off: #e9e9ea;
    --shadow: 0 12px 40px rgba(0,0,0,0.15); /* 亮色模式強化陰影區隔背景 */
    --btn-default-bg: #e5e5ea;
}

/* 全域基礎樣式與排版佈局 */
* { box-sizing: border-box; }
body {
    background-color: var(--bg-body); color: var(--text); font-family: var(--font);
    margin: 0; padding: 40px 20px; font-size: 13px; line-height: 1.5;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* 內容容器配置：完全移除背景，讓卡片直接浮在背景圖上 */
.app-container { 
    max-width: 1100px; 
    margin: 0 auto; 
    min-height: 85vh; 
    display: flex; 
    flex-direction: column; 
    background: transparent !important;
}

/* 頁首標頭區域樣式：加入毛玻璃與底色 */
header {
    display: flex; justify-content: space-between; align-items: flex-start;
    margin-bottom: 30px; padding: 20px; 
    background: var(--panel);
    backdrop-filter: blur(12px);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02)) , var(--panel);
    text-shadow: 0 1px 0 rgba(0,0,0,0.25);

}
h1 { font-size: 24px; font-weight: 700; margin: 0; letter-spacing: -0.5px; }
.badge { background: var(--accent); color: #fff; padding: 3px 8px; border-radius: 6px; font-size: 11px; font-weight: 600; vertical-align: middle; }
.header-controls { display: flex; gap: 12px; align-items: center; }
.status-msg { margin-top: 6px; color: var(--subtext); font-size: 12px; font-weight: 500; }

/* 語系選擇選單樣式 */
.lang-selector {
    background: rgba(255, 255, 255, 0.1); color: var(--text); border: 1px solid var(--border);
    padding: 8px 12px; border-radius: 10px; font-size: 12px; cursor: pointer; outline: none;
}
body.light-mode .lang-selector { background: rgba(0, 0, 0, 0.05); }

/* 連線頁面引導介面 */
.connect-container {
    flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center;
    padding: 60px 40px; background: var(--panel) !important;
    backdrop-filter: blur(20px);
    border-radius: var(--radius);
    box-shadow: var(--shadow); margin-bottom: 30px; text-align: center;
    background: linear-gradient(180deg, rgba(255,255,255,0.07), rgba(255,255,255,0.02)) , var(--panel) !important;
    text-shadow: 0 1px 0 rgba(0,0,0,0.25);

}
.connect-logo {
    width: 300px; max-width: 90%; margin-bottom: 40px;
    transition: filter 0.3s, opacity 0.3s;
    filter: invert(1); opacity: 0.95;
}
body.light-mode .connect-logo { filter: none; opacity: 0.85; }

/* 各式按鈕組件定義 */
.hero-btn {
    background: var(--accent); color: white; font-size: 16px; font-weight: 600;
    padding: 14px 40px; border-radius: 30px; border: none; cursor: pointer;
    box-shadow: 0 8px 20px rgba(10, 132, 255, 0.3);
    transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
}
.hero-btn:hover { background: var(--accent-hover); transform: translateY(-2px); box-shadow: 0 12px 24px rgba(10, 132, 255, 0.4); }
.hero-btn:active { transform: translateY(0); }

button {
    background: var(--btn-default-bg);
    color: var(--text); border: 1px solid var(--border);
    padding: 8px 16px; border-radius: 10px; font-size: 13px; font-weight: 600;
    cursor: pointer; transition: all 0.2s; white-space: nowrap;
}
button:hover { 
    background: var(--accent); color: white; border-color: var(--accent);
    box-shadow: 0 0 12px rgba(10, 132, 255, 0.4);
    transform: scale(1.05); /* 驚喜感互動 */
}
button:disabled { opacity: 0.3; cursor: not-allowed; background: var(--switch-bg-off); border-color: transparent; }
button.primary { background: var(--accent); color: white; border-color: transparent; }
button.primary:hover { background: var(--accent-hover); box-shadow: 0 4px 12px rgba(10, 132, 255, 0.3); }
button.small { padding: 5px 12px; height: 32px; }
button.icon-btn { padding: 4px 10px; font-size: 14px; }
button.danger { color: var(--danger); border: 1px solid rgba(255, 69, 58, 0.3); background: rgba(255, 69, 58, 0.05); }
button.danger:hover { background: var(--danger); color: white; border-color: var(--danger); box-shadow: 0 0 12px rgba(255, 69, 58, 0.4); }
button.large { padding: 12px 40px; font-size: 14px; }

/* 輸入框與選擇控制項：解決選單顏色問題 */
select, input[type="number"] {
    background: rgba(255, 255, 255, 0.1); color: var(--text); border: 1px solid var(--border);
    padding: 8px 12px; border-radius: 8px; font-family: inherit; font-size: 14px;
    font-weight: 600; text-align: center; min-width: 90px; outline: none; transition: border-color 0.2s;
}
body.light-mode select { 
    background: rgba(255, 255, 255, 0.9); 
    color: #1c1c1e;
}
select option {
    background: #fff;
    color: #333;
}
body:not(.light-mode) select option {
    background: #2c2c2e;
    color: #f0f0f2;
}

select:focus, input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(10, 132, 255, 0.2); }
label { color: var(--subtext); font-weight: 600; font-size: 12px; }

/* 警示訊息開關樣式 */
.warning-msg { display: none; font-size: 12px; color: var(--warn); margin-top: 8px; text-align: right; }
.warning-msg.active { display: block; }

/* 儀表板與狀態欄：獨立套用毛玻璃效果 */
.status-bar {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 20px;
    background: var(--panel) !important; 
    backdrop-filter: blur(12px);
    padding: 20px; border-radius: var(--radius);
    margin-bottom: 24px; box-shadow: var(--shadow);
    background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02)) , var(--panel) !important;
    text-shadow: 0 1px 0 rgba(0,0,0,0.25);

}
.stat-item { display: flex; flex-direction: column; gap: 6px; }
.stat-label { font-size: 11px; color: var(--subtext); text-transform: uppercase; font-weight: 700; letter-spacing: 0.8px; }
.stat-val { font-family: var(--mono); font-weight: 600; color: var(--accent); font-size: 15px; }

/* 格線系統佈局規範 */
.dashboard-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 24px; margin-bottom: 24px; }
.col-full { grid-column: span 12; }
.col-half { grid-column: span 6; }
@media (max-width: 850px) { .col-half { grid-column: span 12; } }

/* 卡片容器：獨立套用毛玻璃效果與底色 */
.card {
    background: var(--panel) !important;
    backdrop-filter: blur(12px);
    border-radius: var(--radius); 
    padding: 28px;
    box-shadow: var(--shadow); 
    display: flex; flex-direction: column;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02)) , var(--panel) !important;
    color: var(--text);
    text-shadow: 0 1px 0 rgba(0,0,0,0.25);

}
.card:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 35px rgba(0,0,0,0.4);
}
.card-header {
    display: flex; justify-content: space-between; margin-bottom: 20px; font-weight: 700;
    align-items: center; font-size: 16px; border-bottom: 1px solid var(--border); padding-bottom: 16px;
}
.header-note { font-size: 12px; color: var(--subtext); font-weight: 400; margin-left: 8px; }
.control-group { margin-bottom: 20px; }
.control-row { display: flex; justify-content: space-between; align-items: center; min-height: 36px; }
.current-row { text-align: right; font-size: 12px; color: var(--subtext); margin-top: 4px; }
.current-val { color: var(--accent); font-weight: 600; font-family: var(--mono); margin-left: 4px; }
.divider { height: 1px; background: var(--border); margin: 24px 0; }

/* DPI 專屬選取列設計 */
#dpi-list { display: flex; flex-direction: column; gap: 10px; }
.dpi-row {
    display: grid; grid-template-columns: 50px 24px 60px 1fr auto; align-items: center; gap: 16px;
    padding: 14px 20px; background: rgba(255,255,255,0.05); border-radius: 10px;
    border: 1px solid transparent; transition: all 0.2s; cursor: pointer;
}
body.light-mode .dpi-row { background: rgba(0,0,0,0.03); }
.dpi-row:hover { transform: translateX(8px); border-color: var(--accent); }
.dpi-row.active { background: rgba(10, 132, 255, 0.15); border: 1px solid var(--accent); }
.dot { width: 12px; height: 12px; border-radius: 50%; transition: transform 0.2s; }
.dpi-row:hover .dot { transform: scale(1.3); }

/* 二進位滑動開關元件設計 */
.switch { position: relative; display: inline-block; width: 48px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--switch-bg-off); border-radius: 24px; transition: .3s;
}
.slider:before {
    position: absolute; content: ""; height: 20px; width: 20px; left: 3px; bottom: 3px;
    background-color: var(--switch-knob); border-radius: 50%; transition: .3s;
}
input:checked + .slider { background-color: var(--switch-bg-on); }
input:checked + .slider:before { transform: translateX(22px); }

/* 設定檔管理介面樣式 */
.profile-grid-container { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; }
.profile-card {
    background: var(--panel-light); border: 1px solid var(--border); border-radius: 12px;
    padding: 20px; display: flex; flex-direction: column; gap: 16px; transition: transform 0.2s;
}
.profile-card:hover { transform: translateY(-2px); border-color: var(--subtext); }
.profile-card-header { font-weight: 700; font-size: 14px; border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 4px; }
.profile-card-body { display: flex; flex-direction: column; gap: 12px; }
.profile-control-row { display: flex; justify-content: space-between; align-items: center; }

/* 修正：將恢復原廠設定區域設為 Flexbox 並置中排版 */
.reset-section { display: flex; justify-content: center; padding-top: 10px; }

/* 按鍵清單設計樣式 */
#btn-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }
.btn-card {
    background: rgba(255,255,255,0.05); padding: 16px; border-radius: 12px;
    display: flex; flex-direction: column; align-items: flex-start; gap: 12px;
    border: 1px solid transparent; transition: all 0.2s;
}
body.light-mode .btn-card { background: rgba(0,0,0,0.03); }
.btn-card:hover { border-color: var(--border); transform: translateY(-2px); }
.btn-info { width: 100%; display: flex; flex-direction: row; justify-content: space-between; align-items: center; }
.btn-name { font-weight: 700; font-size: 15px; color: var(--text); }
.btn-current { font-size: 12px; color: var(--subtext); }
.btn-actions { width: 100%; display: flex; gap: 8px; }
.btn-actions select { flex: 1; }
.btn-actions button { flex-shrink: 0; }

/* 日誌監控視窗樣式 */
.console {
    background: rgba(0, 0, 0, 0.85); border-radius: var(--radius); border: 1px solid var(--border);
    font-family: var(--mono); font-size: 12px; overflow: hidden; margin-top: 20px;
    box-shadow: var(--shadow);
}
.console-head { background: #111; padding: 8px 16px; color: var(--subtext); border-bottom: 1px solid #222; display: flex; justify-content: space-between; font-weight: 600; }
.console-body { height: 160px; overflow-y: auto; padding: 10px 16px; color: #ccc; }
.log-line { display: flex; gap: 10px; margin-bottom: 4px; border-bottom: 1px solid #1a1a1a; padding-bottom: 2px; }
.ts { color: #555; min-width: 80px; }
.dir { font-weight: bold; min-width: 30px; }
.dir.tx { color: #d69d85; } .dir.rx { color: #57a64a; } .dir.sys { color: #569cd6; } .dir.err { color: #ff453a; }

/* 頁尾頁面裝飾與按鈕樣式 */
.footer { margin-top: 40px; padding: 24px; display: flex; justify-content: space-between; color: var(--subtext); font-size: 12px; }

/* 全域橫幅警告與 Loading 特效樣式 */
.banner { background: rgba(255, 69, 58, 0.1); border: 1px solid rgba(255, 69, 58, 0.3); color: #ff453a; padding: 16px 20px; border-radius: 12px; margin-bottom: 24px; display: none; align-items: center; gap: 12px; font-weight: 500; }
.loading-overlay { 
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    z-index: 10000; display: none; 
    flex-direction: column; justify-content: center; align-items: center;

    /* 視覺更乾淨：降低遮罩霧化感，避免「整頁看不清」 */
    background: radial-gradient(1200px 700px at 50% 35%, rgba(10,132,255,0.18), transparent 60%),
                radial-gradient(900px 700px at 70% 60%, rgba(48,209,88,0.10), transparent 62%),
                rgba(0,0,0,0.58);

    backdrop-filter: blur(4px) saturate(120%);
    -webkit-backdrop-filter: blur(4px) saturate(120%);
    color: white;
}

.loading-overlay.active { display: flex; animation: fadeIn 0.2s; }
.spinner { width: 40px; height: 40px; border: 4px solid rgba(255,255,255,0.2); border-radius: 50%; border-top-color: var(--accent); animation: spin 0.8s linear infinite; margin-bottom: 16px; }

/* 動畫基礎關鍵影格 */
@keyframes spin { 100% { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* 輔助說明框樣式定義 */
.info-box {
    background: rgba(142, 142, 147, 0.1); border-left: 4px solid var(--accent);
    padding: 12px 16px; margin: 12px 0; border-radius: 6px;
    font-size: 12.5px; line-height: 1.6; color: var(--subtext); white-space: pre-line;
}
body.light-mode .info-box { background: rgba(0, 0, 0, 0.04); color: #444; }

/* --- 背景功能新增樣式 --- */
.bg-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;

    /* 使用多層方式：底層圖片 + 上層粒子/光暈，提升「wow」感 */
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;

    opacity: 0;
    transform: scale(1.02);
    filter: saturate(1.1) contrast(1.05);

    transition: opacity 0.6s ease, transform 0.8s cubic-bezier(0.16, 1, 0.3, 1);
    will-change: transform, opacity;
}

.bg-overlay::before,
.bg-overlay::after {
    content: "";
    position: absolute;
    inset: -15%;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.6s ease;
    will-change: transform, opacity, background-position;
}

/* 動態光暈層 + 慢速景深粒子（slow layer）：增加空間深度（不影響操作區） */
.bg-overlay::before {
    background:
        /* Aurora / glow */
        radial-gradient(640px 420px at 18% 26%, rgba(10,132,255,0.20), transparent 62%),
        radial-gradient(560px 460px at 74% 34%, rgba(48,209,88,0.12), transparent 60%),
        radial-gradient(700px 560px at 46% 78%, rgba(255,159,10,0.12), transparent 66%),
        radial-gradient(980px 780px at 82% 86%, rgba(255,69,58,0.08), transparent 70%),

        /* Slow bokeh dust (larger, softer) */
        radial-gradient(10px 10px at 12% 18%, rgba(255,255,255,0.10), transparent 62%),
        radial-gradient(8px 8px at 24% 72%, rgba(255,255,255,0.08), transparent 62%),
        radial-gradient(12px 12px at 36% 42%, rgba(255,255,255,0.06), transparent 62%),
        radial-gradient(9px 9px at 58% 22%, rgba(255,255,255,0.07), transparent 62%),
        radial-gradient(11px 11px at 66% 64%, rgba(255,255,255,0.06), transparent 62%),
        radial-gradient(8px 8px at 82% 28%, rgba(255,255,255,0.06), transparent 62%),
        radial-gradient(12px 12px at 88% 78%, rgba(255,255,255,0.05), transparent 62%);

    mix-blend-mode: screen;
    filter: blur(3px);
    opacity: 0.95;
    animation: bg-glow 11s ease-in-out infinite alternate, bg-particles-slow 28s linear infinite;
}

/* 近景粒子（fast layer）：更密、更明顯的漂浮感（純 CSS、低負擔） */
.bg-overlay::after {
    background:
        /* Tiny stars / dust */
        radial-gradient(2px 2px at 6% 14%, rgba(255,255,255,0.24), transparent 60%),
        radial-gradient(1px 1px at 12% 36%, rgba(255,255,255,0.22), transparent 60%),
        radial-gradient(2px 2px at 18% 62%, rgba(255,255,255,0.20), transparent 60%),
        radial-gradient(1px 1px at 22% 82%, rgba(255,255,255,0.20), transparent 60%),
        radial-gradient(2px 2px at 28% 18%, rgba(255,255,255,0.22), transparent 60%),
        radial-gradient(1px 1px at 32% 44%, rgba(255,255,255,0.18), transparent 60%),
        radial-gradient(2px 2px at 38% 70%, rgba(255,255,255,0.20), transparent 60%),
        radial-gradient(1px 1px at 42% 90%, rgba(255,255,255,0.18), transparent 60%),

        radial-gradient(2px 2px at 48% 10%, rgba(255,255,255,0.22), transparent 60%),
        radial-gradient(1px 1px at 52% 32%, rgba(255,255,255,0.20), transparent 60%),
        radial-gradient(2px 2px at 56% 56%, rgba(255,255,255,0.18), transparent 60%),
        radial-gradient(1px 1px at 60% 78%, rgba(255,255,255,0.20), transparent 60%),

        radial-gradient(2px 2px at 66% 22%, rgba(255,255,255,0.22), transparent 60%),
        radial-gradient(1px 1px at 70% 44%, rgba(255,255,255,0.20), transparent 60%),
        radial-gradient(2px 2px at 74% 66%, rgba(255,255,255,0.18), transparent 60%),
        radial-gradient(1px 1px at 78% 86%, rgba(255,255,255,0.18), transparent 60%),

        radial-gradient(2px 2px at 84% 16%, rgba(255,255,255,0.22), transparent 60%),
        radial-gradient(1px 1px at 88% 38%, rgba(255,255,255,0.20), transparent 60%),
        radial-gradient(2px 2px at 92% 60%, rgba(255,255,255,0.18), transparent 60%),
        radial-gradient(1px 1px at 96% 82%, rgba(255,255,255,0.18), transparent 60%),

                /* ultra subtle texture (reduced scanlines) */
        repeating-linear-gradient(
            180deg,
            rgba(255,255,255,0.010) 0px,
            rgba(255,255,255,0.010) 1px,
            rgba(255,255,255,0.000) 10px,
            rgba(255,255,255,0.000) 18px
        );
opacity: 0.46;
    filter: blur(0.35px);
    animation: bg-particles-fast 12s linear infinite;
}

.bg-overlay.active {
    opacity: 0.72;
    transform: scale(1.06);
    animation: bg-kenburns 18s ease-in-out infinite alternate;
}

.bg-overlay.active::before,
.bg-overlay.active::after {
    opacity: 1;
}


/* 強化毛玻璃效果（但避免「整體看起來被霧化」） */
header, .card, .status-bar, .connect-container, .console {
    backdrop-filter: blur(10px) saturate(140%) contrast(108%);
    -webkit-backdrop-filter: blur(10px) saturate(140%) contrast(108%);
    border: 1px solid var(--border) !important;
}


body.light-mode .bg-overlay.active { opacity: 0.42; filter: saturate(1.02) contrast(1.02); }

@keyframes bg-kenburns {
    0% { transform: scale(1.06) translate3d(0, 0, 0); background-position: 50% 50%; }
    50% { transform: scale(1.10) translate3d(-1.5%, -1%, 0); background-position: 52% 48%; }
    100% { transform: scale(1.08) translate3d(1.5%, 1.2%, 0); background-position: 48% 52%; }
}

@keyframes bg-glow {
    0% { transform: translate3d(-1%, -1%, 0) scale(1.02); opacity: 0.9; }
    100% { transform: translate3d(1.2%, 1.2%, 0) scale(1.06); opacity: 1; }
}

@keyframes bg-particles {
    0% { transform: translate3d(0, 0, 0) scale(1); opacity: 0.55; }
    50% { transform: translate3d(-1.2%, 0.8%, 0) scale(1.02); opacity: 0.65; }
    100% { transform: translate3d(0.8%, -1.2%, 0) scale(1); opacity: 0.55; }
}

/* --- 深層美化補強：一致配色、可讀性、hover 觸感 --- */
:root{
    --glow: 0 0 0 1px rgba(10,132,255,0.18), 0 16px 48px rgba(0,0,0,0.45);
}
.card:hover, .btn-card:hover, header:hover, .status-bar:hover{
    box-shadow: var(--glow);
}
button, select, input[type="number"]{
    transition: transform 0.18s ease, box-shadow 0.22s ease, background 0.22s ease, border-color 0.22s ease;
}
button:hover{
    transform: translateY(-1px);
    box-shadow: 0 12px 30px rgba(0,0,0,0.35);
}
button:active{
    transform: translateY(0px) scale(0.99);
}
select:focus, input[type="number"]:focus, button:focus{
    outline: none;
    box-shadow: 0 0 0 3px rgba(10,132,255,0.25);
    border-color: rgba(10,132,255,0.35);
}

/* 避免任何非預期的「整頁霧化」：嚴格禁止對主要容器套用 filter blur */
.app-container, header, .card, .status-bar, .connect-container, .console {
    filter: none !important;
}


@media (prefers-reduced-motion: reduce) {
    .bg-overlay.active { animation: none !important; }
    .bg-overlay::before, .bg-overlay::after { animation: none !important; }
    button, .card, header, .status-bar { transition: none !important; }
}

/* ===== v6 deep parallax & triple particle layers ===== */
.bg-overlay{
  --px:0px;
  --py:0px;
}

.bg-overlay.active{
  transform:
    translate3d(calc(var(--px) * 0.15), calc(var(--py) * 0.15), 0)
    scale(1.06);
}

/* far layer (reuse ::before) */
.bg-overlay.active::before{
  animation-duration: 26s;
  transform:
    translate3d(calc(var(--px) * 0.05), calc(var(--py) * 0.05), 0);
}

/* mid layer (reuse ::after) */
.bg-overlay.active::after{
  animation-duration: 14s;
  transform:
    translate3d(calc(var(--px) * 0.12), calc(var(--py) * 0.12), 0);
}

/* near sparkle layer */
.bg-overlay .bg-near-layer{
  position:absolute;
  inset:-10%;
  pointer-events:none;
  background:
    radial-gradient(2px 2px at 12% 22%, rgba(255,255,255,.35), transparent 60%),
    radial-gradient(1px 1px at 32% 72%, rgba(255,255,255,.25), transparent 60%),
    radial-gradient(2px 2px at 76% 44%, rgba(255,255,255,.28), transparent 60%),
    radial-gradient(1px 1px at 55% 18%, rgba(255,255,255,.22), transparent 60%),
    radial-gradient(2px 2px at 18% 66%, rgba(255,255,255,.30), transparent 60%),
    radial-gradient(1px 1px at 88% 32%, rgba(255,255,255,.26), transparent 60%);
  opacity:.7;
  filter:blur(.3px);
  animation: bg-near-float 9s linear infinite;
  transform:
    translate3d(calc(var(--px) * 0.25), calc(var(--py) * 0.25), 0);
}

@keyframes bg-near-float{
  0%{transform:translate3d(calc(var(--px)*.25),calc(var(--py)*.25),0)}
  50%{transform:translate3d(calc(var(--px)*.35),calc(var(--py)*.35),0)}
  100%{transform:translate3d(calc(var(--px)*.25),calc(var(--py)*.25),0)}
}

/* ===== v7 cinematic flow & comfort dynamics ===== */

/* background energy flow layer */
.bg-overlay::marker{content:'';} /* keep parser stable */

.bg-overlay .bg-energy-layer{
  position:absolute;
  inset:-20%;
  pointer-events:none;
  background:
    radial-gradient(900px 380px at 10% 30%, rgba(10,132,255,0.06), transparent 60%),
    radial-gradient(820px 420px at 80% 40%, rgba(48,209,88,0.05), transparent 62%),
    radial-gradient(900px 520px at 50% 80%, rgba(255,159,10,0.04), transparent 65%);
  mix-blend-mode: screen;
  filter: blur(18px);
  opacity:.9;
  animation: bg-energy-flow 22s ease-in-out infinite alternate;
  transform: translate3d(calc(var(--px)*0.08), calc(var(--py)*0.08), 0);
}

@keyframes bg-energy-flow{
  0%{transform:translate3d(-2%, -1%, 0) scale(1.02)}
  100%{transform:translate3d(2%, 1.5%, 0) scale(1.06)}
}

/* camera push transition */
.bg-overlay.push-enter{
  animation: bg-push-in 720ms cubic-bezier(.2,.8,.2,1) both;
}
@keyframes bg-push-in{
  0%{transform:scale(1.12); filter:brightness(1.15) blur(2px);}
  100%{transform:scale(1.06); filter:brightness(1.0) blur(0px);}
}

/* UI micro highlight sweep (no layout move) */
.card::after, header::after, .status-bar::after{
  content:"";
  position:absolute;
  inset:0;
  border-radius:inherit;
  pointer-events:none;
  background:
    linear-gradient(120deg, transparent 30%, rgba(255,255,255,.06) 45%, transparent 60%);
  opacity:0;
  transition:opacity .3s ease;
}

.card:hover::after,
header:hover::after,
.status-bar:hover::after{
  opacity:1;
  animation: ui-sweep 1.2s ease;
}

@keyframes ui-sweep{
  from{background-position:-120% 0}
  to{background-position:220% 0}
}

/* rhythm tuning */
.bg-overlay.active{ animation-timing-function: cubic-bezier(.25,.6,.25,1); }

/* ===== v8 premium phase drift / focus field / active breathing ===== */

/* phase drift color & luminance field */
.bg-overlay .bg-phase-layer{
  position:absolute;
  inset:-25%;
  pointer-events:none;
  background:
    radial-gradient(1200px 600px at 30% 40%, rgba(120,180,255,0.05), transparent 65%),
    radial-gradient(1000px 700px at 70% 60%, rgba(255,200,140,0.035), transparent 70%),
    radial-gradient(1400px 900px at 50% 50%, rgba(255,255,255,0.03), transparent 72%);
  mix-blend-mode: soft-light;
  filter: blur(26px);
  opacity:.9;
  animation: bg-phase-drift 46s linear infinite alternate;
  transform:
    translate3d(calc(var(--px)*0.04), calc(var(--py)*0.04), 0);
}

@keyframes bg-phase-drift{
  0%{
    filter: blur(26px) hue-rotate(0deg) brightness(1.0);
    transform: translate3d(-1.5%, -1%, 0) scale(1.02);
  }
  100%{
    filter: blur(28px) hue-rotate(6deg) brightness(1.05);
    transform: translate3d(1.5%, 1%, 0) scale(1.05);
  }
}

/* focus field (center lift, edge calm) */
.bg-overlay.focus-field::after{
  content:"";
  position:absolute;
  inset:-5%;
  pointer-events:none;
  background:
    radial-gradient(65% 55% at 50% 45%, rgba(255,255,255,0.06), transparent 60%),
    radial-gradient(120% 90% at 50% 50%, rgba(0,0,0,0.25), transparent 55%);
  mix-blend-mode: soft-light;
  animation: focus-breathe 10s ease-in-out infinite;
}

@keyframes focus-breathe{
  0%{opacity:.35}
  50%{opacity:.55}
  100%{opacity:.35}
}

/* active state breathing (generic, non-glow) */
.active-breath{
  animation: active-breath 2.8s ease-in-out infinite;
}

@keyframes active-breath{
  0%{filter:brightness(1)}
  50%{filter:brightness(1.04)}
  100%{filter:brightness(1)}
}

/* ===== v9 depth micro-shift & idle polish ===== */

/* ultra slow depth micro shift */
.bg-overlay.bg-micro{
  animation: bg-micro-root 60s ease-in-out infinite alternate;
}
@keyframes bg-micro-root{
  from{transform:translate3d(0,0,0) scale(1.06)}
  to{transform:translate3d(-0.6%,0.4%,0) scale(1.065)}
}

/* far / mid / near slight phase offsets */
.bg-overlay.bg-micro::before{ animation-duration: 72s !important; }
.bg-overlay.bg-micro::after{ animation-duration: 48s !important; }
.bg-overlay.bg-micro .bg-near-layer{ animation-duration: 24s !important; }

/* idle light sweep for panels (single run) */
.idle-sweep::after{
  content:"";
  position:absolute;
  inset:0;
  border-radius:inherit;
  pointer-events:none;
  background:linear-gradient(120deg, transparent 30%, rgba(255,255,255,.05) 45%, transparent 60%);
  animation: idle-sweep 1.6s ease forwards;
}
@keyframes idle-sweep{
  from{background-position:-140% 0; opacity:.0}
  30%{opacity:.8}
  to{background-position:220% 0; opacity:0}
}

/* ===== v10 performance & stability layer ===== */

/* isolate heavy background painting */
.bg-overlay{
  contain: paint;
}

/* narrow will-change usage to background only */
.bg-overlay,
.bg-overlay::before,
.bg-overlay::after,
.bg-overlay .bg-near-layer,
.bg-overlay .bg-energy-layer,
.bg-overlay .bg-phase-layer{
  will-change: transform, opacity, filter;
}

/* light mode for low power / reduced motion */
body.fx-light .bg-overlay::before,
body.fx-light .bg-overlay::after,
body.fx-light .bg-overlay .bg-near-layer,
body.fx-light .bg-overlay .bg-energy-layer,
body.fx-light .bg-overlay .bg-phase-layer{
  animation-duration: 2.5x;
  opacity: 0.75;
}

@media (prefers-reduced-motion: reduce){
  body:not(.fx-force) .bg-overlay,
  body:not(.fx-force) .bg-overlay::before,
  body:not(.fx-force) .bg-overlay::after,
  body:not(.fx-force) .bg-overlay .bg-near-layer,
  body:not(.fx-force) .bg-overlay .bg-energy-layer,
  body:not(.fx-force) .bg-overlay .bg-phase-layer{
    animation: none !important;
    transition: none !important;
  }
}


/* ===== v11 dark as default baseline tuning ===== */

:root{
  --bg-body: #0e0f12;
  --panel: rgba(20, 22, 28, 0.92);
  --panel-light: rgba(28, 30, 38, 0.82);
  --input: rgba(26, 28, 36, 0.85);

  --text: #f2f4f8;
  --subtext: #a2a8b3;

  --border: rgba(255,255,255,0.12);

  --accent: #4aa3ff;
  --accent-hover: #78b8ff;
}

/* deep dark background optimisation for visual layers */
.bg-overlay{
  filter: saturate(1.05) contrast(1.06) brightness(0.92);
}

/* reduce highlight intensity for dark default */
.bg-overlay .bg-energy-layer{ opacity: .75; }
.bg-overlay .bg-phase-layer{ opacity: .78; }

/* focus field slightly softer in dark mode */
.bg-overlay.focus-field::after{
  background:
    radial-gradient(65% 55% at 50% 45%, rgba(255,255,255,0.045), transparent 60%),
    radial-gradient(120% 90% at 50% 50%, rgba(0,0,0,0.35), transparent 55%);
}

/* cards & panels contrast re-balance for dark */
.card,
header,
.status-bar,
.connect-container,
.console{
  box-shadow:
    0 8px 30px rgba(0,0,0,0.55),
    inset 0 1px 0 rgba(255,255,255,0.03);
}

/* text rendering comfort on dark background */
body{
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

/* keep existing light mode as opt-in */
body.light-mode{
  --bg-body: #f3f5f9;
  --panel: rgba(255,255,255,0.86);
  --panel-light: rgba(255,255,255,0.80);
  --input: rgba(255,255,255,0.92);

  --text: #1a1d24;
  --subtext: #5a6270;

  --border: rgba(0,0,0,0.08);

  --accent: #0a84ff;
  --accent-hover: #006edc;
}

/* ===== v12 dark esports + apple light ===== */

/* --- Dark (default, esports) --- */
:root{
  --bg-body:#0b0d12;
  --panel:rgba(18,20,28,.94);
  --panel-light:rgba(24,26,36,.86);
  --input:rgba(20,22,32,.9);
  --text:#f5f7fb;
  --subtext:#9aa3b2;
  --border:rgba(120,140,255,.18);
  --accent:#6b7cff;
  --accent-hover:#9aa6ff;
}

/* sharpen esports contrast */
.card,header,.status-bar,.connect-container{
  box-shadow:
    0 0 0 1px rgba(120,140,255,.08),
    0 18px 48px rgba(0,0,0,.65);
}

/* background color temperature for esports */
.bg-overlay .bg-energy-layer{
  background:
    radial-gradient(900px 380px at 15% 30%, rgba(110,130,255,.10), transparent 60%),
    radial-gradient(820px 420px at 80% 40%, rgba(120,90,255,.08), transparent 62%),
    radial-gradient(900px 520px at 50% 80%, rgba(80,180,255,.06), transparent 65%);
}

/* --- Apple-like light mode --- */
body.light-mode{
  --bg-body:#f5f6f8;
  --panel:rgba(255,255,255,.82);
  --panel-light:rgba(255,255,255,.72);
  --input:rgba(255,255,255,.9);
  --text:#1c1c1e;
  --subtext:#6e6e73;
  --border:rgba(0,0,0,.06);
  --accent:#0a84ff;
  --accent-hover:#409cff;
}

body.light-mode .card,
body.light-mode header,
body.light-mode .status-bar,
body.light-mode .connect-container{
  box-shadow:
    0 6px 20px rgba(0,0,0,.08);
  backdrop-filter: blur(14px) saturate(160%);
}

/* ===== v13 esports dark focus ring & selection highlight ===== */

/* apply only in dark (esports) mode */
body:not(.light-mode) :is(
  button,
  select,
  input,
  .card,
  .btn-card,
  .dpi-row,
  .status-item,
  .connect-container
):focus-visible{
  outline: none;
  box-shadow:
    0 0 0 2px rgba(107,124,255,.55),
    0 0 0 6px rgba(107,124,255,.18),
    0 8px 28px rgba(107,124,255,.35);
}

/* keyboard focus for custom rows */
body:not(.light-mode) .dpi-row:focus-visible,
body:not(.light-mode) .btn-card:focus-visible{
  position: relative;
  z-index: 1;
}

/* selection / active highlight (esports style) */
body:not(.light-mode) .active,
body:not(.light-mode) .selected,
body:not(.light-mode) [aria-selected="true"]{
  background:
    linear-gradient(90deg,
      rgba(107,124,255,.18),
      rgba(107,124,255,.04) 60%);
  box-shadow:
    inset 3px 0 0 rgba(107,124,255,.9),
    0 0 0 1px rgba(107,124,255,.25);
}

/* prevent light-mode from inheriting esports rings */
body.light-mode :is(
  button,
  select,
  input,
  .card,
  .btn-card,
  .dpi-row
):focus-visible{
  box-shadow:
    0 0 0 2px rgba(10,132,255,.35);
}

/* improve accessibility contrast */
body:not(.light-mode) :focus-visible{
  scroll-margin: 12px;
}

/* ===== v14 esports dark color boost + status system + jp light palette ===== */

/* -------- Esports Dark : stronger contrast & comfort -------- */
body:not(.light-mode){
  --es-bg:#07080d;
  --es-panel:#0f1220;
  --es-panel-2:#131733;
  --es-text:#f5f7ff;
  --es-sub:#9aa4ff;
  --es-accent:#7c8cff;
  --es-accent-2:#57d4ff;

  --status-success:#2cff9a;
  --status-warn:#ffd35a;
  --status-error:#ff5b7a;
  --status-info:#6bc7ff;
}

body:not(.light-mode){
  background-color:var(--es-bg);
}

/* reinforce panels for esports contrast */
body:not(.light-mode) .card,
body:not(.light-mode) header,
body:not(.light-mode) .status-bar,
body:not(.light-mode) .connect-container{
  background:
    linear-gradient(180deg, rgba(255,255,255,.03), rgba(0,0,0,.12)),
    var(--es-panel);
  color:var(--es-text);
}

/* -------- Status color system (dark esports) -------- */
body:not(.light-mode) .is-success,
body:not(.light-mode) [data-status="success"]{
  border-color:var(--status-success);
  box-shadow:0 0 0 1px rgba(44,255,154,.35);
}

body:not(.light-mode) .is-warn,
body:not(.light-mode) [data-status="warn"]{
  border-color:var(--status-warn);
  box-shadow:0 0 0 1px rgba(255,211,90,.35);
}

body:not(.light-mode) .is-error,
body:not(.light-mode) [data-status="error"]{
  border-color:var(--status-error);
  box-shadow:0 0 0 1px rgba(255,91,122,.45);
}

body:not(.light-mode) .is-info,
body:not(.light-mode) [data-status="info"]{
  border-color:var(--status-info);
  box-shadow:0 0 0 1px rgba(107,199,255,.35);
}

/* left bar indicator for lists / rows */
body:not(.light-mode) :is(.dpi-row,.btn-card,.card).is-success::before,
body:not(.light-mode) :is(.dpi-row,.btn-card,.card)[data-status="success"]::before{
  content:"";
  position:absolute;
  left:0; top:0; bottom:0;
  width:3px;
  background:var(--status-success);
}

body:not(.light-mode) :is(.dpi-row,.btn-card,.card).is-error::before,
body:not(.light-mode) :is(.dpi-row,.btn-card,.card)[data-status="error"]::before{
  content:"";
  position:absolute;
  left:0; top:0; bottom:0;
  width:3px;
  background:var(--status-error);
}

/* -------- Disabled / unavailable options -------- */
select:disabled,
button:disabled,
input:disabled{
  opacity:.45;
  cursor:not-allowed;
}

select option:disabled{
  color:#777 !important;
}

body:not(.light-mode) select option:disabled{
  color:#556 !important;
  background:#0b0e1a;
}

/* visually blocked state inside lists */
body:not(.light-mode) .is-disabled,
body:not(.light-mode) [aria-disabled="true"]{
  opacity:.45;
  filter:grayscale(.3);
  pointer-events:none;
}

/* -------- Light mode : Japanese anime inspired soft palette -------- */
body.light-mode{
  --jp-bg:#f6f7fb;
  --jp-panel:#ffffff;
  --jp-sub:#8a8fb0;

  --jp-accent-pink:#ff7ab6;
  --jp-accent-blue:#6ba7ff;
  --jp-accent-mint:#6ee7c8;
  --jp-accent-violet:#b59bff;

  background:
    radial-gradient(1200px 600px at 20% 0%, rgba(255,122,182,.12), transparent 60%),
    radial-gradient(900px 600px at 90% 10%, rgba(107,167,255,.12), transparent 55%),
    var(--jp-bg);
}

/* soft anime style panels */
body.light-mode .card,
body.light-mode header,
body.light-mode .status-bar,
body.light-mode .connect-container{
  background:
    linear-gradient(180deg, rgba(255,255,255,.9), rgba(255,255,255,.75)),
    var(--jp-panel);
  border:1px solid rgba(255,255,255,.6);
}

/* light mode accent remap */
body.light-mode .primary,
body.light-mode button.primary{
  background:linear-gradient(135deg,var(--jp-accent-pink),var(--jp-accent-blue));
  border:none;
}

/* light mode status colors */
body.light-mode .is-success,
body.light-mode [data-status="success"]{ border-color:var(--jp-accent-mint); }

body.light-mode .is-warn,
body.light-mode [data-status="warn"]{ border-color:#ffd27a; }

body.light-mode .is-error,
body.light-mode [data-status="error"]{ border-color:#ff8a9e; }

body.light-mode .is-info,
body.light-mode [data-status="info"]{ border-color:var(--jp-accent-blue); }


/* ===== v15 clearer disabled + cyan esports palette + loading/busy/syncing ===== */

/* ---------- Esports dark palette (remove purple dominance, go cyan/ice blue) ---------- */
body:not(.light-mode){
  --es-accent:#3fdcff;        /* main accent */
  --es-accent-strong:#27bfff; /* focus / action */
  --es-accent-soft:#9be9ff;   /* soft glow */

  --status-success:#26f2a3;
  --status-warn:#ffd166;
  --status-error:#ff4d6d;
  --status-info:#4fc3ff;
}

/* re-balance previous rings / selection to new accent */
body:not(.light-mode) :is(
  button,
  select,
  input,
  .card,
  .btn-card,
  .dpi-row,
  .status-item,
  .connect-container
):focus-visible{
  box-shadow:
    0 0 0 2px rgba(63,220,255,.65),
    0 0 0 6px rgba(63,220,255,.22),
    0 10px 32px rgba(63,220,255,.35);
}

body:not(.light-mode) .active,
body:not(.light-mode) .selected,
body:not(.light-mode) [aria-selected="true"]{
  background:
    linear-gradient(90deg,
      rgba(63,220,255,.18),
      rgba(63,220,255,.04) 60%);
  box-shadow:
    inset 3px 0 0 rgba(63,220,255,.95),
    0 0 0 1px rgba(63,220,255,.35);
}

/* ---------- Stronger disabled / unavailable visuals ---------- */

/* base disabled */
select:disabled,
button:disabled,
input:disabled{
  opacity:.38;
  cursor:not-allowed;
  filter:grayscale(.55) contrast(.9);
}

/* option disabled : add strike + muted color */
select option:disabled{
  color:#666 !important;
  text-decoration: line-through;
}

body:not(.light-mode) select option:disabled{
  color:#445 !important;
  background:
    repeating-linear-gradient(
      45deg,
      #0b0f1f,
      #0b0f1f 6px,
      #0f1428 6px,
      #0f1428 12px
    );
}

/* card / row style unavailable */
body:not(.light-mode) .is-disabled,
body:not(.light-mode) [aria-disabled="true"]{
  opacity:.38;
  filter:grayscale(.6) blur(.2px);
  pointer-events:none;
  position:relative;
}

/* explicit "Not available" mark */
body:not(.light-mode) .is-disabled::after,
body:not(.light-mode) [aria-disabled="true"]::after{
  content:"NOT AVAILABLE";
  position:absolute;
  right:10px;
  top:8px;
  font-size:11px;
  letter-spacing:.08em;
  color:#8fa6ff;
  background:rgba(15,20,40,.75);
  padding:2px 6px;
  border-radius:4px;
}

/* ---------- Loading / Busy / Syncing visual system (esports dark) ---------- */

/* common base */
body:not(.light-mode) .is-loading,
body:not(.light-mode) .is-busy,
body:not(.light-mode) .is-syncing{
  position:relative;
  pointer-events:none;
  filter:saturate(.9);
}

/* shimmer overlay */
body:not(.light-mode) .is-loading::before,
body:not(.light-mode) .is-busy::before,
body:not(.light-mode) .is-syncing::before{
  content:"";
  position:absolute;
  inset:0;
  border-radius:inherit;
  background:
    linear-gradient(120deg,
      transparent 20%,
      rgba(63,220,255,.15) 35%,
      rgba(63,220,255,.25) 45%,
      rgba(63,220,255,.15) 55%,
      transparent 70%);
  animation: es-loading-sweep 1.4s linear infinite;
  pointer-events:none;
}

@keyframes es-loading-sweep{
  from{transform:translateX(-120%);}
  to{transform:translateX(120%);}
}

/* top progress bar style for syncing */
body:not(.light-mode) .is-syncing::after{
  content:"";
  position:absolute;
  left:0; right:0; top:0;
  height:2px;
  background:
    linear-gradient(90deg,
      transparent,
      var(--es-accent-strong),
      transparent);
  animation: es-sync-bar 1.1s ease-in-out infinite;
}

@keyframes es-sync-bar{
  0%{transform:translateX(-100%);}
  100%{transform:translateX(100%);}
}

/* busy (stronger dim + small pulse) */
body:not(.light-mode) .is-busy{
  opacity:.7;
}

body:not(.light-mode) .is-busy{
  animation: es-busy-pulse 1.6s ease-in-out infinite;
}

@keyframes es-busy-pulse{
  0%{filter:brightness(.95);}
  50%{filter:brightness(1.05);}
  100%{filter:brightness(.95);}
}

/* loading label hint (optional) */
body:not(.light-mode) .is-loading[data-label]::after{
  content:attr(data-label);
  position:absolute;
  right:10px;
  bottom:8px;
  font-size:11px;
  color:var(--es-accent-soft);
  letter-spacing:.06em;
}

/* light mode keeps its soft style, do not inherit esports effects */
body.light-mode .is-loading::before,
body.light-mode .is-busy::before,
body.light-mode .is-syncing::before,
body.light-mode .is-syncing::after{
  animation:none;
}

/* ===== v16 accent rebalance + toast/snackbar system (dark esports / light jp) ===== */

/* ---------- Global: remove any purple tendency on main text / controls ---------- */
body:not(.light-mode){
  --ui-accent-main:#2fe6ff;      /* cyan ice */
  --ui-accent-strong:#1fb4ff;
  --ui-accent-soft:#8ff2ff;
}

/* force text / switches / sliders to cyan family */
body:not(.light-mode) a,
body:not(.light-mode) .primary,
body:not(.light-mode) button.primary{
  color:var(--ui-accent-soft);
}

body:not(.light-mode) input[type="checkbox"]:checked,
body:not(.light-mode) input[type="radio"]:checked{
  accent-color:var(--ui-accent-main);
}

/* ---------- Dark esports toast / snackbar ---------- */
body:not(.light-mode) .toast,
body:not(.light-mode) .snackbar{
  position:relative;
  background:
    linear-gradient(180deg, rgba(255,255,255,.04), rgba(0,0,0,.35)),
    #0c1224;
  color:#f4f7ff;
  border-left:4px solid var(--ui-accent-main);
  box-shadow:
    0 12px 40px rgba(0,0,0,.65),
    0 0 0 1px rgba(47,230,255,.15);
  overflow:hidden;
}

/* layered motion feel */
body:not(.light-mode) .toast::before,
body:not(.light-mode) .snackbar::before{
  content:"";
  position:absolute;
  inset:0;
  background:
    linear-gradient(120deg,
      transparent 20%,
      rgba(47,230,255,.18) 35%,
      rgba(47,230,255,.28) 45%,
      rgba(47,230,255,.18) 55%,
      transparent 70%);
  animation: es-toast-sweep 2.2s linear infinite;
  pointer-events:none;
}

@keyframes es-toast-sweep{
  from{transform:translateX(-120%);}
  to{transform:translateX(120%);}
}

/* status variants */
body:not(.light-mode) .toast.is-success{border-left-color:var(--status-success);}
body:not(.light-mode) .toast.is-warn{border-left-color:var(--status-warn);}
body:not(.light-mode) .toast.is-error{border-left-color:var(--status-error);}
body:not(.light-mode) .toast.is-info{border-left-color:var(--status-info);}

/* ---------- Light JP toast / snackbar ---------- */
body.light-mode .toast,
body.light-mode .snackbar{
  position:relative;
  background:
    linear-gradient(180deg, rgba(255,255,255,.95), rgba(255,255,255,.88));
  color:#222;
  border-left:4px solid var(--jp-accent-blue);
  box-shadow:
    0 10px 24px rgba(0,0,0,.12);
  overflow:hidden;
}

/* soft layered highlight for light mode */
body.light-mode .toast::before,
body.light-mode .snackbar::before{
  content:"";
  position:absolute;
  inset:0;
  background:
    linear-gradient(120deg,
      transparent 25%,
      rgba(255,122,182,.18) 38%,
      rgba(107,167,255,.18) 48%,
      rgba(110,231,200,.18) 58%,
      transparent 75%);
  animation: jp-toast-sweep 3.2s ease-in-out infinite;
  pointer-events:none;
}

@keyframes jp-toast-sweep{
  from{transform:translateX(-120%); opacity:.4;}
  50%{opacity:.8;}
  to{transform:translateX(120%); opacity:.4;}
}

body.light-mode .toast.is-success{border-left-color:var(--jp-accent-mint);}
body.light-mode .toast.is-warn{border-left-color:#ffd27a;}
body.light-mode .toast.is-error{border-left-color:#ff8a9e;}
body.light-mode .toast.is-info{border-left-color:var(--jp-accent-blue);}

/* ===== v17 effect level switch ===== */

/* reduced: no background, no visual effects */
body.fx-reduced .bg-overlay{ display:none !important; }

body.fx-reduced .toast::before,
body.fx-reduced .snackbar::before,
body.fx-reduced .is-loading::before,
body.fx-reduced .is-busy,
body.fx-reduced .is-syncing::before,
body.fx-reduced .is-syncing::after{
  animation:none !important;
}

/* standard: keep UI effects, remove animated background only */
body.fx-standard .bg-overlay{ display:none !important; }

/* full: default (no override) */


/* ===== v18 FX levels: keep static background for reduced/standard ===== */

/* FULL: everything as-is (default) */

/* STANDARD: keep background image static, remove particles/energy/phase, keep UI effects */
body.fx-standard .bg-overlay{
  display:block !important;
  animation:none !important;
  transform:none !important;
  filter:none !important;
}
body.fx-standard .bg-overlay::before,
body.fx-standard .bg-overlay::after,
body.fx-standard .bg-overlay .bg-near-layer,
body.fx-standard .bg-overlay .bg-energy-layer,
body.fx-standard .bg-overlay .bg-phase-layer{
  animation:none !important;
  transform:none !important;
  filter:none !important;
  opacity:0 !important;
  display:none !important;
}
body.fx-standard .bg-overlay.focus-field::after{
  /* focus-field overlay off in standard */
  content:none !important;
}

/* REDUCED: keep background image static, no particles, no UI micro-animations (hover/idle/toast/loading shimmer) */
body.fx-reduced .bg-overlay{
  display:block !important;
  animation:none !important;
  transform:none !important;
  filter:none !important;
}
body.fx-reduced .bg-overlay::before,
body.fx-reduced .bg-overlay::after,
body.fx-reduced .bg-overlay .bg-near-layer,
body.fx-reduced .bg-overlay .bg-energy-layer,
body.fx-reduced .bg-overlay .bg-phase-layer{
  animation:none !important;
  transform:none !important;
  filter:none !important;
  opacity:0 !important;
  display:none !important;
}
body.fx-reduced .bg-overlay.focus-field::after{ content:none !important; }

/* disable hover sweep & idle sweep in reduced */
body.fx-reduced .card::after,
body.fx-reduced header::after,
body.fx-reduced .status-bar::after{
  opacity:0 !important;
  animation:none !important;
}
body.fx-reduced .idle-sweep::after{
  content:none !important;
  animation:none !important;
}

/* also stop toast/snackbar sweep and loading/busy/syncing */
body.fx-reduced .toast::before,
body.fx-reduced .snackbar::before,
body.fx-reduced .is-loading::before,
body.fx-reduced .is-busy,
body.fx-reduced .is-syncing::before,
body.fx-reduced .is-syncing::after{
  animation:none !important;
}


/* =========================================================
   FX 等級控制說明（工程維護註解）

   fx-full
     - 完整動態模式
     - 啟用背景動態、粒子層、視差效果與所有 UI 動畫

   fx-standard
     - 保留背景畫面（靜態）
     - 關閉背景動畫、粒子、能量層與視差
     - 保留所有 UI 動態與提示動畫

   fx-reduced
     - 保留背景畫面（靜態）
     - 關閉背景動畫、粒子與所有 UI 動態效果
     - 用於低效能設備或除錯場景

   注意：
   - 實際動畫是否啟用，請依 body 上的 class 判斷
   - 本段僅為說明用途，不影響任何邏輯
   ========================================================= */



.header-controls{
  display:flex !important;
  align-items:flex-end !important;
  justify-content:flex-end !important;
  gap: 12px !important;
  flex-wrap: wrap !important;
}

/* Keep existing buttons/selects untouched, only style wrappers */
.header-controls .hc-item{
  display:flex;
  flex-direction:column;
  gap: 0;
  min-width: 170px;
}

.header-controls .hc-label{
  font-size: 10.5px;
  letter-spacing: .02em;
  opacity: .65;
  padding-left: 10px;
  margin: 0 0 6px 0;
  line-height: 1;
}

.header-controls select{
  height: 36px;
  border-radius: 14px;
}

/* Make theme button align with selects */
#btn-theme{
  height: 36px !important;
  border-radius: 14px !important;
}

/* Read status aligns but stays independent */
#btn-read{
  height: 36px !important;
  border-radius: 14px !important;
  white-space: nowrap;
}

/* Smaller screens: avoid squeezing */
@media (max-width: 980px){
  .header-controls .hc-item{ min-width: 150px; flex: 1 1 150px; }
}



/* Goal: theme | background | web visuals | language | read status, aligned and elegant */
.header-controls{
  display:grid !important;
  grid-template-columns: 52px minmax(220px, 260px) minmax(220px, 260px) minmax(200px, 240px) auto !important;
  column-gap: 14px !important;
  row-gap: 10px !important;
  align-items:end !important;
  justify-content:end !important;
  flex-wrap: unset !important;
}

.header-controls #btn-theme{
  justify-self:end;
  align-self:end;
}

.header-controls .hc-item{
  min-width: 0 !important;
}

.header-controls .hc-label{
  display:block;
  text-align:left;
  padding-left: 10px;
}

#btn-read{
  justify-self:end;
  align-self:end;
}

/* Make selects visually consistent */
.header-controls select.lang-selector,
.header-controls select{
  width: 100%;
  height: 36px;
  border-radius: 14px;
}

/* If there is a placeholder fx slot, keep its width consistent */
.header-controls .hc-fxph #fx-level-slot{
  width: 100%;
  min-height: 36px;
}

/* Responsive: stack into two neat rows instead of chaotic wrap */
@media (max-width: 980px){
  .header-controls{
    grid-template-columns: 52px 1fr 1fr;
    justify-content:start !important;
  }
  #btn-read{
    grid-column: 1 / -1;
    justify-self:start;
  }
}
@media (max-width: 640px){
  .header-controls{
    grid-template-columns: 52px 1fr;
  }
  .header-controls .hc-item{
    grid-column: 2 / -1;
  }
  #btn-read{
    grid-column: 1 / -1;
  }
}



.badge{
  display:inline-flex;
  align-items:center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(90,120,255,.95);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  line-height: 1;
  box-shadow: 0 10px 24px rgba(0,0,0,.22);
}
body.light-mode .badge{
  box-shadow: 0 10px 24px rgba(0,0,0,.14);
}

/* Override v34 grid: single-row flex on desktop */
.header-controls{
  display:flex !important;
  flex-wrap: nowrap !important;
  align-items: flex-end !important;
  justify-content: flex-end !important;
  gap: 14px !important;
  row-gap: 0 !important;
}

/* Item rhythm */
.header-controls .hc-item{
  width: 230px;
  min-width: 230px !important;
  display:flex;
  flex-direction:column;
  align-items:stretch;
}

/* Labels always visible and anchored */
.header-controls .hc-label{
  display:block !important;
  opacity: .68;
  font-size: 10.5px;
  letter-spacing: .02em;
  padding-left: 10px;
  margin: 0 0 6px 0;
  line-height: 1;
  white-space: nowrap;
}

/* Selects consistent */
.header-controls select,
.header-controls select.lang-selector{
  width: 100%;
  height: 36px;
  border-radius: 14px;
}

/* Theme + Read align to row baseline */
#btn-theme, #btn-read{
  height: 36px !important;
  border-radius: 14px !important;
  white-space: nowrap;
}

/* Responsive: allow wrap, but keep it orderly (two rows max) */
@media (max-width: 980px){
  .header-controls{
    flex-wrap: wrap !important;
    justify-content: flex-start !important;
    gap: 12px !important;
  }
  .header-controls .hc-item{
    width: min(260px, 100%);
    min-width: 180px !important;
    flex: 1 1 180px;
  }
}
@media (max-width: 560px){
  .header-controls .hc-item{
    flex: 1 1 100%;
    width: 100%;
  }
}



header{
  display:flex !important;
  align-items:flex-start !important;
  justify-content:space-between !important;
  gap: 18px !important;
}

.header-left{
  flex: 1 1 auto;
  max-width: 520px;  /* prevents title area from eating the whole row */
  min-width: 320px;
}

.header-controls{
  flex: 0 0 auto;
  display:flex !important;
  flex-wrap: nowrap !important;
  align-items: flex-end !important;
  justify-content: flex-end !important;
  gap: 14px !important;
}

/* Consistent compact widths so everything fits */
.header-controls .hc-item{
  width: 200px;
  min-width: 200px !important;
}

.header-controls .hc-label{
  font-size: 10px;
  opacity: .66;
  padding-left: 10px;
  margin: 0 0 6px 0;
  white-space: nowrap;
}

/* Controls sizing */
.header-controls select,
.header-controls select.lang-selector{
  width: 100%;
  height: 34px;
  border-radius: 14px;
  font-size: 13px;
}

#btn-theme, #btn-read{
  height: 34px !important;
  border-radius: 14px !important;
}

/* Mobile: allow wrap (orderly) */
@media (max-width: 980px){
  header{
    display:block !important;
  }
  .header-left{
    max-width: unset;
  }
  .header-controls{
    margin-top: 10px;
    flex-wrap: wrap !important;
    justify-content:flex-start !important;
  }
  .header-controls .hc-item{
    width: min(240px, 100%);
    min-width: 180px !important;
    flex: 1 1 180px;
  }
}



/* ===== Header toolbar (clean, stable) =====
   Desktop: single-row ordered menu
   Mobile: wraps in a consistent grid-like flow
*/
header{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap: 18px;
}

.header-left{
  flex: 1 1 auto;
  max-width: 560px;
  min-width: 320px;
  display:flex;
  flex-direction:column;
  gap: 6px;
}

.header-left h1{ margin:0; }

.badge{
  display:inline-flex;
  align-items:center;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(90,120,255,.95);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  line-height: 1;
  box-shadow: 0 10px 24px rgba(0,0,0,.22);
}

.header-controls{
  flex: 0 0 auto;
  display:flex;
  flex-wrap: nowrap;
  align-items:flex-end;
  justify-content:flex-end;
  gap: 14px;
}

.header-controls .hc-item{
  width: 200px;
  min-width: 200px;
  display:flex;
  flex-direction:column;
  align-items:stretch;
}

.header-controls .hc-label{
  display:block;
  font-size: 10px;
  opacity: .66;
  padding-left: 10px;
  margin: 0 0 6px 0;
  line-height: 1;
  white-space: nowrap;
}

.header-controls select,
.header-controls select.lang-selector{
  width: 100%;
  height: 34px;
  border-radius: 14px;
  font-size: 13px;
}

#btn-theme, #btn-read{
  height: 34px;
  border-radius: 14px;
  white-space: nowrap;
}

/* Responsive */
@media (max-width: 980px){
  header{
    display:block;
  }
  .header-left{
    max-width: unset;
    min-width: unset;
  }
  .header-controls{
    margin-top: 12px;
    flex-wrap: wrap;
    justify-content:flex-start;
    gap: 12px;
  }
  .header-controls .hc-item{
    width: min(240px, 100%);
    min-width: 180px;
    flex: 1 1 180px;
  }
}
@media (max-width: 560px){
  .header-controls .hc-item{
    flex: 1 1 100%;
    width: 100%;
  }
}


/* =========================
   v39 Top Controls Bar
   - Move controls out of header into a dedicated top bar
   - Keep visual consistent + readable
   ========================= */

.top-controls-bar{
  position: sticky;
  top: 10px;
  z-index: 60;
  width: 100%;
  margin: 10px 0 6px;
  pointer-events: none; /* allow inner to manage hit testing cleanly */
}
.top-controls-inner{
  pointer-events: auto;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 14px;
  padding: 10px 12px;
  border-radius: 18px;
  background: rgba(12, 16, 24, 0.62);
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 18px 55px rgba(0,0,0,0.45);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

/* keep header clean (left content only) */
header{
  display: block;
  margin-top: 0;
}
.header-left{
  padding-top: 2px;
}

/* Controls sizing + rhythm (Apple-like) */
.top-controls-inner .hc-item{
  width: 210px;
  min-width: 210px;
  display:flex;
  flex-direction:column;
}
.top-controls-inner .hc-label{
  display:block !important;
  font-size: 10px;
  opacity: .70;
  letter-spacing: .02em;
  padding-left: 10px;
  margin: 0 0 6px 0;
  line-height: 1;
  white-space: nowrap;
}

/* Select readability */
.top-controls-inner select,
.top-controls-inner select.lang-selector{
  width: 100%;
  height: 34px;
  border-radius: 14px;
  font-size: 13px;
}

/* Buttons align */
.top-controls-inner #btn-theme,
.top-controls-inner #btn-read,
.top-controls-inner #btn-connect-mini{
  height: 34px !important;
  border-radius: 14px !important;
  white-space: nowrap;
}

/* Ensure dropdown options are readable in both themes */
.top-controls-inner select option,
.top-controls-inner select optgroup{
  color: #e9eefc;
  background: #111520;
}
body.light-mode .top-controls-inner select option,
body.light-mode .top-controls-inner select optgroup{
  color: #0b1220;
  background: #ffffff;
}

/* Mobile: wrap neatly, keep glass */
@media (max-width: 980px){
  .top-controls-inner{
    justify-content: flex-start;
    flex-wrap: wrap;
  }
  .top-controls-inner .hc-item{
    width: min(240px, 100%);
    min-width: 180px;
    flex: 1 1 180px;
  }
}
@media (max-width: 560px){
  .top-controls-inner .hc-item{
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
  }
}


/* ===== v40 Dropdown readability + alignment ===== */
select, option, optgroup{
  text-align: left;
}
select option, select optgroup{
  padding: 6px 10px;
}
/* Ensure optgroup label alignment (browser-dependent) */
select optgroup{
  font-weight: 700;
}


/* ===== v41 Top Menu Bar: theme-consistent + spacing harmony ===== */
/* 1) Make top menu bar follow light/dark theme of main UI */
.top-controls-bar{
  /* default (dark) */
  background: rgba(16, 18, 24, 0.72);
  border: 1px solid rgba(255,255,255,0.10);
  box-shadow: 0 18px 50px rgba(0,0,0,0.40);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

/* Light mode matches the light cards (less contrast, softer shadow) */
body.light-mode .top-controls-bar{
  background: rgba(250, 250, 252, 0.72);
  border: 1px solid rgba(0,0,0,0.08);
  box-shadow: 0 18px 45px rgba(0,0,0,0.14);
}

/* Ensure controls inside follow theme */
.top-controls-bar select,
.top-controls-bar button{
  transition: background-color .18s ease, border-color .18s ease, color .18s ease, box-shadow .18s ease;
}

body.light-mode .top-controls-bar select,
body.light-mode .top-controls-bar button{
  background: rgba(255,255,255,0.72);
  border-color: rgba(0,0,0,0.10);
  color: rgba(20,22,26,0.92);
}

/* 2) Make spacing between top bar and header consistent with other sections */
.top-controls-bar{
  margin-bottom: 18px; /* align with section gaps */
}

@media (max-width: 980px){
  .top-controls-bar{
    margin-bottom: 16px;
  }
}

/* v41: when top menu exists, keep header spacing consistent */
.top-controls-bar + .container header,
.top-controls-bar + header{
  margin-top: 0 !important;
}


/* ===== v42 Fix: Top menu bar follows theme (apply to INNER, remove ugly slab) ===== */
.top-controls-bar{
  /* keep as layout wrapper only */
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

/* Dark / Light styling belongs to the rounded inner container */
.top-controls-inner{
  background: rgba(12, 16, 24, 0.62) !important;
  border: 1px solid rgba(255,255,255,0.08) !important;
  box-shadow: 0 18px 55px rgba(0,0,0,0.45) !important;
  backdrop-filter: blur(14px) !important;
  -webkit-backdrop-filter: blur(14px) !important;
}

body.light-mode .top-controls-inner{
  background: rgba(255,255,255,0.70) !important;
  border: 1px solid rgba(0,0,0,0.10) !important;
  box-shadow: 0 18px 45px rgba(0,0,0,0.14) !important;
}

/* Consistent spacing between top menu and the first main header card */
.top-controls-bar{
  margin: 12px 0 18px !important;
}

/* Ensure controls surfaces also match in light mode */
body.light-mode .top-controls-inner select,
body.light-mode .top-controls-inner button{
  background: rgba(255,255,255,0.78) !important;
  border-color: rgba(0,0,0,0.10) !important;
  color: rgba(20,22,26,0.92) !important;
}
