/* 動態字體縮放（透過 html 根字體等比例放大所有 rem 文字，預設大字 18px） */
html { font-size: 18px; color-scheme: light; }
html.dark { color-scheme: dark; }
html[data-font-scale="normal"] { font-size: 16px; }
html[data-font-scale="large"] { font-size: 18px; }
html[data-font-scale="xlarge"] { font-size: 20px; }

/* 確保輸入框至少 1rem (>=16px)，避免 iOS Safari 自動放大且同步跟隨字體倍率 */
input, select, textarea { font-size: 1rem !important; }

/* 修復 Windows Chrome/Edge 黑底模式下原生下拉選單白底白字問題 */
html.dark select, html.dark option {
  background-color: #18181b;
  color: #fafafa;
}
html:not(.dark) select, html:not(.dark) option {
  background-color: #ffffff;
  color: #09090b;
}

body, button, input, select, textarea, code, pre, .font-mono {
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", Roboto, system-ui, -apple-system, sans-serif !important;
  font-variant-numeric: tabular-nums;
}

.touch-btn { min-height: 46px; }
#trendChartCanvas { touch-action: none; }

/* 隱藏手動下單點數輸入框的原生上下箭頭，保留完整 5 位數顯示寬度 */
.manual-price-input::-webkit-outer-spin-button,
.manual-price-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.manual-price-input {
  -moz-appearance: textfield;
  appearance: textfield;
}
/* 統一左側「做多／做空」與右側「市價平倉」按鈕高度，確保橫放與桌機水平底部完全齊平 */
.manual-action-btn {
  height: 46px;
  min-height: 46px;
}
.manual-price-input {
  font-size: 1.25rem !important;
}

/* 手機直放左欄點數比例保護（讓點數大而清晰，且於 360px 窄機亦不截斷換行） */
@media (max-width: 639px) {
  .left-hero-num { font-size: min(1.7rem, 7.2vw) !important; }
  .left-hero-dir { font-size: min(2rem, 8.8vw) !important; }
  .left-sub-num { font-size: min(0.85rem, 3.6vw) !important; }
  .left-meta-text { font-size: min(0.76rem, 3.2vw) !important; }
  .left-band-pts { font-size: min(1.65rem, 7vw) !important; }
  .left-band-sub { font-size: min(0.82rem, 3.4vw) !important; }
  #bandRangeRow { font-size: min(0.85rem, 3.5vw) !important; }
  .manual-price-input { font-size: min(1.2rem, 5vw) !important; }
}

/* 展開收合區塊箭頭過渡 */
details#ordersAccordion > summary::-webkit-details-marker { display: none; }
details#ordersAccordion > summary { list-style: none; }
details#ordersAccordion[open] .orders-chevron { transform: rotate(180deg); }

/* 套利:ON 紅色緊張心跳雙拍跳動閃爍（撲通-撲通-短停，節奏約 1.05s） */
@keyframes arbHeartbeatBtn {
  0% {
    transform: scale(1);
    border-color: #dc2626;
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.55), 0 0 6px rgba(220, 38, 38, 0.25);
  }
  12% {
    transform: scale(1.03);
    border-color: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.55), 0 0 14px rgba(239, 68, 68, 0.6);
  }
  24% {
    transform: scale(0.992);
    border-color: #b91c1c;
    box-shadow: 0 0 0 1px rgba(220, 38, 38, 0.3), 0 0 6px rgba(220, 38, 38, 0.25);
  }
  38% {
    transform: scale(1.045);
    border-color: #ff3b30;
    box-shadow: 0 0 0 5px rgba(239, 68, 68, 0.45), 0 0 20px rgba(239, 68, 68, 0.78);
  }
  56% {
    transform: scale(1);
    border-color: #dc2626;
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0), 0 0 5px rgba(220, 38, 38, 0.2);
  }
  100% {
    transform: scale(1);
    border-color: #dc2626;
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0), 0 0 5px rgba(220, 38, 38, 0.2);
  }
}

@keyframes arbHeartbeatTag {
  0% {
    transform: scale(1);
    background-color: #dc2626;
    filter: brightness(1);
  }
  12% {
    transform: scale(1.06);
    background-color: #ef4444;
    filter: brightness(1.18);
  }
  24% {
    transform: scale(0.98);
    background-color: #b91c1c;
    filter: brightness(0.92);
  }
  38% {
    transform: scale(1.09);
    background-color: #ff2d20;
    filter: brightness(1.26);
  }
  56% {
    transform: scale(1);
    background-color: #dc2626;
    filter: brightness(1);
  }
  100% {
    transform: scale(1);
    background-color: #dc2626;
    filter: brightness(1);
  }
}

.arb-heartbeat-on {
  animation: arbHeartbeatBtn 1.05s cubic-bezier(0.25, 0.1, 0.25, 1) infinite;
  will-change: transform, box-shadow;
}
.arb-heartbeat-tag {
  animation: arbHeartbeatTag 1.05s cubic-bezier(0.25, 0.1, 0.25, 1) infinite;
  will-change: transform, filter;
}

/* 全裝置統一由底部導覽列切換分頁（電腦網頁版與手機直／橫放一致） */
#mobileBottomNav.logged-in-mobile-nav { display: block !important; }

/* ============================================================
   頂部導覽列（獨立固定 px 尺規：與下方 #appShell 左右完全對齊，
   中央單行橫向放大「[帳戶名膠囊燈號] 套利:OFF/ON」，全尺寸不換行）
   ============================================================ */
#topHeaderInner {
  min-height: 58px !important;
  flex-wrap: nowrap !important;
}
#brandCircle {
  width: 40px !important;
  height: 40px !important;
}
#brandCircleText { font-size: 17px !important; }
#brandBadgeCode {
  font-size: 12px !important;
  padding: 2px 6px !important;
}
#brandVersionBadge {
  font-size: 11px !important;
  padding: 1px 6px !important;
}
#brandSubLine {
  font-size: 12px !important;
  line-height: 1.25 !important;
  margin-top: 2px !important;
}
#headerTradeControls {
  flex: 1 1 auto !important;
  min-width: 0 !important;
}
#stopOrderToggleBtn {
  width: 100% !important;
  max-width: 380px !important;
  height: 40px !important;
  padding: 0 14px !important;
  gap: 9px !important;
}
#accountSummaryTag {
  font-size: 16.5px !important;
  padding: 4px 9px !important;
  border-radius: 6px !important;
  max-width: 150px !important;
}
#stopOrderText {
  font-size: 16.5px !important;
  letter-spacing: 0.02em !important;
}
#stopOrderDot {
  width: 9px !important;
  height: 9px !important;
}
#headerEnvBadge {
  height: 38px !important;
  min-width: 38px !important;
  padding: 0 9px !important;
  justify-content: center !important;
  font-size: 15px !important;
}
#fontScaleBtn,
#themeToggleBtn,
#headerLogoutBtn {
  height: 38px !important;
  min-height: 38px !important;
  padding: 0 11px !important;
  font-size: 13px !important;
}
#headerLogoutBtn {
  padding: 0 13px !important;
}

/* 平板／手機橫向（640px ~ 1279px） */
@media (max-width: 1279px) {
  #topHeaderInner {
    min-height: 50px !important;
    gap: 8px !important;
  }
  #brandCircle {
    width: 34px !important;
    height: 34px !important;
  }
  #brandCircleText { font-size: 14px !important; }
  #brandBadgeCode {
    font-size: 11px !important;
    padding: 1.5px 5px !important;
  }
  #brandSubLine { font-size: 11px !important; }
  #stopOrderToggleBtn {
    max-width: 320px !important;
    height: 36px !important;
    padding: 0 12px !important;
    gap: 7px !important;
  }
  #accountSummaryTag {
    font-size: 15px !important;
    padding: 3px 8px !important;
    border-radius: 6px !important;
    max-width: 130px !important;
  }
  #stopOrderText { font-size: 15px !important; }
  #stopOrderDot {
    width: 7px !important;
    height: 7px !important;
  }
  #headerEnvBadge,
  #fontScaleBtn,
  #themeToggleBtn,
  #headerLogoutBtn {
    height: 34px !important;
    min-height: 34px !important;
    font-size: 12px !important;
    padding: 0 8px !important;
  }
  #headerEnvBadge {
    min-width: 34px !important;
    font-size: 14px !important;
    padding: 0 7px !important;
  }
}

/* 手機直放（< 640px，單行放大「[帳戶名] 套利:OFF/ON」，與下方卡片左右切齊不換行） */
@media (max-width: 639px) {
  #topHeaderInner {
    min-height: 46px !important;
    padding-top: 5px !important;
    padding-bottom: 5px !important;
    gap: 5px !important;
  }
  #headerBrand { gap: 4px !important; }
  #brandCircle {
    width: 28px !important;
    height: 28px !important;
    border-width: 1.5px !important;
  }
  #brandCircleText { font-size: 11.5px !important; }
  #brandBadgeCode {
    font-size: 9.5px !important;
    padding: 1px 4px !important;
  }
  #brandSubLine {
    font-size: 9px !important;
    line-height: 1.15 !important;
    margin-top: 1px !important;
    letter-spacing: -0.02em !important;
  }
  #headerTradeControls { padding: 0 2px !important; }
  #stopOrderToggleBtn {
    max-width: 100% !important;
    height: 32px !important;
    padding: 0 7px !important;
    gap: 5px !important;
    border-width: 1.5px !important;
    border-radius: 9px !important;
  }
  #accountSummaryTag {
    font-size: 13px !important;
    padding: 3px 6px !important;
    border-radius: 5px !important;
    max-width: 88px !important;
  }
  #stopOrderText {
    font-size: 13px !important;
    letter-spacing: -0.01em !important;
  }
  #stopOrderDot {
    width: 6px !important;
    height: 6px !important;
  }
  #headerRightTools { gap: 3px !important; }
  #headerEnvBadge {
    height: 30px !important;
    min-width: 30px !important;
    padding: 0 5px !important;
    font-size: 12px !important;
  }
  #fontScaleBtn,
  #themeToggleBtn,
  #headerLogoutBtn {
    height: 30px !important;
    min-height: 30px !important;
    padding: 0 6px !important;
    font-size: 10.5px !important;
    border-radius: 7px !important;
  }
  #themeToggleBtn {
    font-size: 11.5px !important;
  }
}

/* 超窄螢幕手機（< 400px，例如 360px Android / 375px iPhone SE） */
@media (max-width: 399px) {
  #topHeaderInner { gap: 4px !important; }
  #headerBrand { gap: 3px !important; }
  #brandCircle {
    width: 24px !important;
    height: 24px !important;
  }
  #brandCircleText { font-size: 10px !important; }
  #brandBadgeCode {
    font-size: 9px !important;
    padding: 1px 3.5px !important;
  }
  #brandSubLine { font-size: 8.5px !important; }
  #stopOrderToggleBtn {
    height: 30px !important;
    padding: 0 5px !important;
    gap: 4px !important;
  }
  #accountSummaryTag {
    font-size: 11.5px !important;
    padding: 2.5px 5px !important;
    border-radius: 4px !important;
    max-width: 72px !important;
  }
  #stopOrderText { font-size: 11.5px !important; }
  #headerRightTools { gap: 2.5px !important; }
  #headerEnvBadge {
    height: 28px !important;
    min-width: 28px !important;
    padding: 0 4px !important;
    font-size: 11px !important;
  }
  #fontScaleBtn,
  #themeToggleBtn,
  #headerLogoutBtn {
    height: 28px !important;
    min-height: 28px !important;
    padding: 0 4.5px !important;
    font-size: 9.5px !important;
  }
  #themeToggleBtn { font-size: 10.5px !important; }
}

/* 手機橫向旋轉專屬配置（Landscape 且可視高度 <= 600px，鎖定單行頂部導覽不換行） */
@media (orientation: landscape) and (max-height: 600px) {
  #topHeaderInner {
    min-height: 44px !important;
    padding-top: 4px !important;
    padding-bottom: 4px !important;
    flex-wrap: nowrap !important;
    gap: 8px !important;
  }
  .touch-btn { min-height: 34px !important; }
  #brandCircle { width: 32px !important; height: 32px !important; }
  #brandCircleText { font-size: 13px !important; }
  #brandBadgeCode { font-size: 10.5px !important; padding: 1px 5px !important; }
  #brandSubLine { display: block !important; font-size: 10.5px !important; line-height: 1.15 !important; }
  #fontScalePrefix, #themeLabel { display: none !important; }
  #stopOrderToggleBtn {
    max-width: 300px !important;
    height: 34px !important;
    padding: 0 11px !important;
    gap: 7px !important;
  }
  #accountSummaryTag {
    font-size: 14px !important;
    padding: 3px 7px !important;
    border-radius: 5px !important;
    max-width: 120px !important;
  }
  #stopOrderText { font-size: 14px !important; }
  #headerEnvBadge { height: 32px !important; min-width: 32px !important; padding: 0 7px !important; font-size: 13px !important; }
  #fontScaleBtn, #themeToggleBtn, #headerLogoutBtn {
    height: 32px !important;
    min-height: 32px !important;
    padding: 0 8px !important;
    font-size: 11.5px !important;
  }
  #mobileBottomNav > div { height: 2.2rem !important; }
  #mobileBottomNav .mobile-nav-btn { flex-direction: row !important; gap: 0.3rem !important; font-size: 0.78rem !important; line-height: 1 !important; }
  #mobileBottomNav .mobile-nav-btn > span:first-child { font-size: 0.9rem !important; }
  #appShell { padding-top: 0.45rem !important; padding-bottom: 2.85rem !important; }
  #toastContainer { bottom: 2.6rem !important; }
  #dashboardMainGrid { grid-template-columns: repeat(12, minmax(0, 1fr)) !important; gap: 0.75rem !important; }
  #dashboardLeftCol { grid-column: span 7 / span 7 !important; }
  #dashboardRightCol { grid-column: span 5 / span 5 !important; }
  #dashboardLeftCol, #dashboardRightCol { padding: 0.65rem !important; gap: 0.5rem !important; }
  #leftTopSplitGrid { gap: 0.5rem !important; }
  #hSignalBadge, #spotQuoteTile {
    padding: 0.5rem 0.55rem !important;
    min-height: 4.8rem !important;
    overflow: hidden !important;
  }
  #hSignalSuffix { display: none !important; }
  #spotCardTitleText, #hSignalNameText {
    font-size: min(0.92rem, 2.1vw) !important;
    line-height: 1.15 !important;
  }
  #spotIndexDisplay {
    font-size: min(1.7rem, 3.9vw) !important;
    line-height: 1.08 !important;
  }
  #hSignalDirText {
    font-size: min(2.05rem, 5vw) !important;
    line-height: 1.05 !important;
  }
  #spotChangeDisplay {
    font-size: min(0.9rem, 2.05vw) !important;
    line-height: 1.15 !important;
  }
  #anchorMetaText {
    font-size: min(0.82rem, 1.85vw) !important;
    line-height: 1.15 !important;
  }
  #bandCardsGrid .left-card-title {
    font-size: min(0.95rem, 2.15vw) !important;
  }
  #lowerPtsDisplay, #livePriceDisplay, #upperPtsDisplay {
    font-size: min(1.85rem, 4.4vw) !important;
    line-height: 1.08 !important;
  }
  #bandCardsGrid .left-band-sub {
    font-size: min(0.95rem, 2.2vw) !important;
    line-height: 1.2 !important;
  }
  #bandRangeRow {
    font-size: min(0.95rem, 2.2vw) !important;
  }
  #manualTradeBlock { padding-top: 0.45rem !important; }
  #manualEntryPairGrid { gap: 0.45rem !important; }
  .manual-price-input { font-size: min(1.25rem, 2.8vw) !important; }
  .manual-action-btn { height: 36px !important; min-height: 36px !important; font-size: 0.9rem !important; }
  #chartControlsCard { padding: 0.5rem 0.75rem !important; }
  #chartMainCard { padding: 0.5rem 0.75rem !important; }
  #chartHeaderRow { padding-bottom: 0.35rem !important; gap: 0.5rem !important; }
  #chartBigPrice { font-size: 1.5rem !important; }
  #chartCrosshairBar { padding: 0.25rem 0.5rem !important; }
  #chartCanvasWrap { height: calc(100dvh - 195px) !important; min-height: 185px !important; }
}
