* { margin: 0; padding: 0; box-sizing: border-box; }
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
            min-height: 100vh; color: #fff; padding: 6px;
            /* status-bar-style 設 black-translucent，內容會鑽到手機狀態列底下，
               最上面那行合約資訊會被時間/電量蓋住 → 用 safe-area 把它推下來 */
            padding-top: calc(6px + env(safe-area-inset-top));
        }
        .container { max-width: 500px; margin: 0 auto; }
        h1 { text-align: center; margin-bottom: 10px; font-size: 20px; color: #00d4ff; }
        .card {
            background: rgba(255,255,255,0.1); border-radius: 10px;
            padding: 8px; margin-bottom: 8px;
            backdrop-filter: blur(10px); border: 1px solid rgba(255,255,255,0.1);
        }
        .card-title {
            font-size: 14px; color: #888; margin-bottom: 6px;
            display: flex; align-items: center; gap: 8px;
            flex-wrap: wrap;   /* 保險：螢幕太窄時讓切換鈕整排掉到下一行，而不是被裁掉 */
        }
        /* 原本的青色裝飾條已移除：標題文字都拿掉了，只剩按鈕，留著會像多一根雜線 */
        .price-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
        /* 右欄（風險指標／無持倉／策略燈號）不准被壓縮，手機上才不會被擠掉或錯位 */
        .price-row > div:last-child { flex-shrink: 0; }
        .price-value { font-size: 28px; font-weight: bold; }
        .risk-badge { padding: 4px 10px; border-radius: 12px; font-size: 12px; font-weight: bold; }
        .risk-safe { background: #00ff88; color: #000; }
        .risk-warn { background: #ffc107; color: #000; }
        .risk-danger { background: #ff4757; color: #fff; }
        .grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
        .grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
        .stat-item { text-align: center; }
        .stat-label { color: #888; font-size: 11px; }
        .stat-value { font-size: 16px; font-weight: bold; }
        .stat-value.positive { color: #00ff88; }
        .stat-value.negative { color: #ff4757; }
        .stat-value.warning { color: #ffc107; }
        .position-row {
            display: flex; justify-content: space-between; align-items: center;
            background: rgba(0,212,255,0.1); border-radius: 8px; padding: 10px; margin-top: 8px;
        }
        .pos-left { display: flex; align-items: center; gap: 10px; }
        .pos-dir { padding: 3px 8px; border-radius: 10px; font-size: 12px; font-weight: bold; }
        .dir-long { background: #ff4757; color: #fff; }
        .dir-short { background: #00ff88; color: #000; }
        .pos-info { font-size: 13px; color: #aaa; }
        .pos-pnl { font-size: 22px; font-weight: bold; }
        .pnl-note { font-size: 10px; color: #666; text-align: right; }
        .no-pos { color: #888; text-align: center; padding: 15px; font-size: 14px; }
        /* 左欄撐滿剩餘寬度，重新整理按鈕才推得到中間，不會讓中段空一大塊 */
        .price-main { flex: 1; min-width: 0; }
        /* 價格那一列（重新整理按鈕已移到圖表卡片標題列，這裡只剩價格） */
        .price-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
        /* 行內最後更新時間（接在結算倒數後面） */
        .update-inline { color: #667; font-size: 10px; margin-left: 6px; white-space: nowrap; }
        .refresh-btn {
            padding: 5px 12px; background: #00d4ff; color: #000; border: none;
            border-radius: 12px; font-size: 12px; font-weight: bold; cursor: pointer;
            white-space: nowrap;
            transition: transform .08s ease, background .15s ease, box-shadow .15s ease;
            -webkit-tap-highlight-color: transparent; user-select: none;
        }
        .refresh-btn:active { transform: scale(0.92); background: #00a6c7;
            box-shadow: inset 0 2px 6px rgba(0,0,0,0.35); }
        .refresh-btn:disabled { opacity: 0.6; cursor: default; }
        .refresh-btn.spinning { pointer-events: none; }
        .refresh-btn.spinning .ricon { display: inline-block; animation: spin 0.7s linear infinite; }
        @keyframes spin { to { transform: rotate(360deg); } }
        .loading { text-align: center; padding: 30px; color: #888; }
        .error { background: rgba(255,71,87,0.2); border: 1px solid #ff4757;
            border-radius: 8px; padding: 15px; text-align: center; color: #ff4757; }
        .warn-box { background: rgba(255,193,7,0.2); border: 1px solid #ffc107;
            border-radius: 8px; padding: 15px; text-align: center; color: #ffc107; }
        /* overflow:hidden 是保險：十字線的 overlay 是絕對定位疊在圖上的，
           它的尺寸一算錯就會往下溢出，把下面那排按鈕（清除全部／工具鈕）
           整片蓋住 —— 看得到但點不到。裁掉溢出，錯了也不會吃掉點擊。
           容器內的 exit/pnl/pending/econ 面板都是 inset:0，不受影響；
           十字線的資訊框是 position:fixed 掛在 body，也不會被裁。 */
        .chart-container { position: relative; height: 340px; margin-top: 5px; overflow: hidden; }
        #chart { width: 100%; height: 100%; }
        .chart-info { display: flex; justify-content: space-between; font-size: 11px; color: #888; margin-top: 5px; }
        .chart-ohlc { display: flex; gap: 10px; flex-wrap: wrap; }
        .chart-ohlc span { white-space: nowrap; }
        /* 標題左半：太長就用「…」截斷，不要換行把 header 撐成兩行 */
        .chart-hdr-title {
            color: #888; font-size: 11px;
            min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
        }
        /* 漲跌數字：絕不換行也不被壓縮，永遠靠右完整顯示（手機上原本會被擠成兩行） */
        .chart-change { font-weight: bold; white-space: nowrap; flex-shrink: 0; margin-left: 8px; }
        .chart-change.up { color: #ff4757; }
        .chart-change.down { color: #00ff88; }
        .toast-container { position: fixed; top: 10px; right: 10px; z-index: 9999; }
        .toast {
            background: rgba(0,212,255,0.95); color: #000; padding: 10px 15px;
            border-radius: 8px; margin-bottom: 5px; font-size: 13px; font-weight: bold;
            animation: slideIn 0.3s ease, fadeOut 0.5s ease 4.5s forwards;
            max-width: 300px;
        }
        @keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
        @keyframes fadeOut { to { opacity: 0; transform: translateY(-10px); } }
        .order-bar { display: flex; gap: 8px; margin-top: 8px; }
        .order-btn {
            flex: 1; padding: 10px; border: none; border-radius: 8px;
            font-size: 14px; font-weight: bold; cursor: pointer; color: #fff;
        }
        .order-btn.buy { background: #ff4757; }
        .order-btn.sell { background: #00cc66; }
        .order-btn.close { background: #666; }
        .order-btn:active { opacity: 0.7; }
        .modal-overlay {
            display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
            background: rgba(0,0,0,0.7); z-index: 10000; align-items: center; justify-content: center;
        }
        .modal-overlay.show { display: flex; }
        .modal-box {
            background: #1e2a3a; border-radius: 12px; padding: 20px; width: 300px;
            border: 1px solid rgba(255,255,255,0.2); text-align: center;
        }
        .modal-title { font-size: 18px; font-weight: bold; margin-bottom: 12px; }
        .modal-msg { color: #aaa; font-size: 14px; margin-bottom: 16px; }
        .modal-btns { display: flex; gap: 10px; }
        .modal-btns button {
            flex: 1; padding: 10px; border: none; border-radius: 8px;
            font-size: 14px; font-weight: bold; cursor: pointer;
        }
        .modal-cancel { background: #444; color: #fff; }
        .modal-confirm { color: #fff; }
        .settlement-badge {
            display: inline-block; padding: 2px 8px; border-radius: 10px;
            font-size: 11px; font-weight: bold; margin-left: 6px;
        }
        .settle-far { background: rgba(0,212,255,0.2); color: #00d4ff; }
        .settle-near { background: rgba(255,193,7,0.2); color: #ffc107; }
        .settle-urgent { background: rgba(255,71,87,0.2); color: #ff4757; }
        .chart-toggle {
            display: inline-flex; background: rgba(255,255,255,0.1); border-radius: 12px;
            padding: 2px; margin-left: auto; font-size: 11px;
        }
        .chart-toggle button {
            padding: 3px 10px; border: none; border-radius: 10px; cursor: pointer;
            background: transparent; color: #888; font-size: 11px;
        }
        .chart-toggle button.active { background: #00d4ff; color: #000; font-weight: bold; }
        /* 按鈕文字一律不換行：否則寬度不足時會變成「數/據」「外包/K」兩行 */
        .chart-toggle button { white-space: nowrap; }

        /* ===== 窄螢幕（手機）===== */
        @media (max-width: 520px) {
            /* 重新整理縮成只有圖示：省下約 60px，切換鈕才擠得進同一排，
               不會被 flex-wrap 推到下一行去獨佔一排 */
            .refresh-btn .rlabel { display: none; }
            .refresh-btn { padding: 7px 11px; font-size: 13px; }
            /* 手機加大上下內距把按鈕變高（好按），左右收窄換水平空間。
               垂直方向不佔整排寬度，所以可以放心加大。字級維持 11px 不再縮。 */
            .chart-toggle button { padding: 7px 8px; }
            .chart-toggle { padding: 3px; }
        }
        /* ===== 更窄的機型（400px 以下）：只再收左右內距，字級與高度都不動 ===== */
        @media (max-width: 400px) {
            .chart-toggle button { padding: 7px 5px; }
        }

        /* ===== 平板／桌機：整體等比放大 =====
           問題：整個版面是照手機設計的（.container 上限 500px、字級 10~14px），
           在 iPad Air 上（縱向 CSS 寬 820px、橫向 1180px）內容只佔中間一小條，
           字又是手機的小字級 —— 看起來就是「畫面超級小」。

           為什麼用 zoom，而不是逐條放大字級：
           很多字級是寫死在 dashboard.js 模板字串的 inline style 裡
           （style="font-size:10px" 之類，光是 badge、合約選單、警告文字就幾十處），
           media query 覆寫不到 inline style，只放大 class 定義的部分會變成
           「一半大一半小」。zoom 連 inline 值一起縮放，版面比例完全不變。

           為什麼用寬度判斷，而不是偵測 iPad：
           iPadOS 13 之後 Safari 預設送的 UA 是 Macintosh，UA 根本認不出 iPad
           （要靠 maxTouchPoints 反推）。用寬度反而更準，而且 Android 平板、
           桌機瀏覽器一起受益。

           canvas 不會因此模糊：drawChart 每次都用 getBoundingClientRect() × dpr
           重設 canvas 尺寸，容器變寬會自動拿到更高的解析度。
           十字線也不受影響：rect 與滑鼠 clientX 在 zoom 下屬於同一個座標系，
           相減的結果不變。

           倍率分觸控和滑鼠兩套：平板是手持、觀看距離遠，要放大得多；
           桌機螢幕大又近，同樣倍率會大到誇張，所以給溫和的一階。 */

        /* 平板（觸控）縱向：iPad Air 縱向 820px */
        @media (min-width: 700px) and (pointer: coarse) {
            body { zoom: 1.45; }
            /* 平板不再限制 500px —— 多出來的寬度讓給 K 線圖 */
            .container { max-width: 100%; }
        }
        /* 平板（觸控）橫向：iPad Air 橫向 1180px，再放大一階 */
        @media (min-width: 1000px) and (pointer: coarse) {
            body { zoom: 1.7; }
        }
        /* 桌機瀏覽器：只做小幅放大，容器放寬到 900px 就好 */
        @media (min-width: 700px) and (pointer: fine) {
            body { zoom: 1.25; }
            .container { max-width: 900px; }
            .card { backdrop-filter: none; }
        }
