/* 台股看盤後台：深色看盤風格。台股慣例：紅漲綠跌。 */
:root {
  color-scheme: dark;
  --bg: #07090d;
  --surface: #10141b;
  --surface-2: #161b24;
  --surface-3: #1d2430;
  --border: #252d3a;
  --text: #e6e9ef;
  --text-2: #a3acbb;
  --text-3: #6b7587;
  --up: #ff4d4f;
  --down: #22c55e;
  --flat: #c3cad6;
  --accent: #3987e5;
  --warn: #e0a526;
  --ma5: #c98500;
  --ma20: #3987e5;
  --ma60: #d55181;
  --radius: 8px;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Consolas, monospace;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; letter-spacing: .02em; margin-right: 8px; white-space: nowrap; }
.brand span { color: var(--up); }
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px;
  border: 1px solid var(--border); font-size: 12px; color: var(--text-2); white-space: nowrap;
}
.pill.ok::before { content: "●"; color: var(--down); }
.pill.bad::before { content: "●"; color: var(--up); }
.pill.warn::before { content: "▲"; color: var(--warn); font-size: 10px; }
.topbar .spacer { flex: 1; }
.clock { font-family: var(--mono); color: var(--text-2); font-size: 13px; }

.tabs { display: flex; gap: 2px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab {
  background: none; border: 0; padding: 10px 14px; cursor: pointer; color: var(--text-2);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--up); }

main { padding: 16px; }
.view { display: none; }
.view.active { display: block; }

/* ---------- generic ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card > header {
  display: flex; align-items: center; gap: 8px; justify-content: space-between;
  padding: 10px 14px; border-bottom: 1px solid var(--border); font-weight: 600;
}
.card > .body { padding: 12px 14px; }
.grid { display: grid; gap: 12px; }
/* grid 子元素預設 min-width:auto，會被不換行的表格撐開而超出螢幕 */
.grid > *, .terminal > *, .side > * { min-width: 0; }
.btn {
  background: var(--surface-3); border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 12px; cursor: pointer;
}
.btn:hover { border-color: var(--text-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { border-color: #6b2a2c; color: #ff8a8c; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.sm { padding: 2px 8px; font-size: 12px; }
a.btn { color: inherit; text-decoration: none; display: inline-block; }
input[type=text], input[type=number], input[type=password], input[type=email], select, textarea {
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.empty { padding: 28px 12px; text-align: center; color: var(--text-3); }
.toast {
  position: fixed; right: 16px; bottom: 16px; z-index: 50; max-width: 360px;
  background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
.toast.error { border-color: #6b2a2c; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 6px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-3); font-weight: 500; font-size: 12px; position: sticky; top: 0; background: var(--surface); }
td.r, th.r { text-align: right; }
tbody tr:hover { background: var(--surface-2); }
tr.clickable { cursor: pointer; }
.table-wrap { overflow: auto; max-height: 70vh; }

.badge { display: inline-block; padding: 0 7px; border-radius: 4px; font-size: 12px; font-weight: 600; }
.badge.BUY { background: rgba(255,77,79,.16); color: var(--up); }
.badge.SELL { background: rgba(34,197,94,.16); color: var(--down); }
.badge.WATCH { background: rgba(224,165,38,.16); color: var(--warn); }
.badge.neutral { background: var(--surface-3); color: var(--text-2); }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 12px; }
.kpi { padding: 12px 14px; }
.kpi .label { color: var(--text-3); font-size: 12px; }
.kpi .value { font-size: 20px; font-weight: 600; margin-top: 2px; }

/* ---------- 看盤 ---------- */
.terminal { display: grid; grid-template-columns: 220px minmax(0, 1fr) 320px; gap: 12px; }
.watchlist .body { padding: 0; max-height: calc(100vh - 170px); overflow: auto; }
.watch-item {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; width: 100%; text-align: left;
  padding: 8px 12px; background: none; border: 0; border-bottom: 1px solid var(--border); cursor: pointer;
}
.watch-item:hover { background: var(--surface-2); }
.watch-item.active { background: var(--surface-3); box-shadow: inset 3px 0 0 var(--up); }
.watch-item .sym { font-weight: 600; }
.watch-item .nm { color: var(--text-2); font-size: 12px; grid-column: 1; font-family: var(--mono); }
.watch-item .badge { grid-row: 1 / span 2; grid-column: 2; align-self: center; }
.watch-search { width: calc(100% - 16px); margin: 8px; }
.watch-search.watch-query { margin-top: 0; }
.watch-item .cat { margin-left: 6px; padding: 0 5px; border-radius: 3px; font-size: 11px; font-weight: 400; color: var(--text-2); background: var(--surface-3); vertical-align: 1px; }
.watch-group {
  display: flex; align-items: center; gap: 6px; padding: 5px 12px; font-size: 12px; font-weight: 600;
  color: var(--text-2); background: var(--surface-2); border-bottom: 1px solid var(--border); cursor: pointer; user-select: none;
}
.watch-group .gname { flex: 1; }
.watch-group .caret { transition: transform .15s; }
.watch-group.collapsed .caret { transform: rotate(-90deg); }
.watch-empty { padding: 10px 12px; font-size: 12px; color: var(--text-3); border-bottom: 1px dashed var(--border); }
.watch-item[draggable], .watch-group[draggable] { cursor: grab; }
.watchlist .dragging { opacity: .4; }
.watchlist .drop-before { box-shadow: inset 0 2px 0 var(--warn); }
.watchlist .drop-after { box-shadow: inset 0 -2px 0 var(--warn); }
.watchlist .drop-into { outline: 1px dashed var(--warn); outline-offset: -2px; }

.chart-card > header { flex-wrap: wrap; }
.quote { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.quote .title { font-size: 18px; font-weight: 700; }
.quote .price { font-size: 22px; font-weight: 700; font-family: var(--mono); }
.legend {
  display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 6px 14px; font-size: 12px;
  border-bottom: 1px solid var(--border); color: var(--text-2); min-height: 30px;
}
.legend b { color: var(--text); font-weight: 500; font-family: var(--mono); }
.swatch { display: inline-block; width: 10px; height: 2px; vertical-align: middle; margin-right: 4px; }
.events { padding: 4px 14px; font-size: 12px; min-height: 26px; border-bottom: 1px solid var(--border); }
.events span { margin-right: 14px; }
.pane { position: relative; }
.pane-label { position: absolute; left: 8px; top: 4px; z-index: 2; font-size: 11px; color: var(--text-3); pointer-events: none; }
.pane + .pane { border-top: 1px solid var(--border); }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 8px 14px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-2); }
.toolbar label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button { background: none; border: 0; padding: 2px 10px; cursor: pointer; color: var(--text-2); font-size: 12px; }
.seg button.active { background: var(--surface-3); color: var(--text); }
.marker-key { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 6px 14px 10px; font-size: 12px; color: var(--text-3); }
.side .card + .card { margin-top: 12px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.stat-grid .label { color: var(--text-3); font-size: 12px; }
.stat-grid .value { font-family: var(--mono); font-size: 15px; }
.notes { margin: 8px 0 0; padding-left: 18px; color: var(--text-2); font-size: 12px; }
.chart-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-3); z-index: 3; background: rgba(16,20,27,.6); }

/* ---------- 策略設定 ---------- */
.strategy-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 12px; }
.param-group { margin-bottom: 18px; }
.param-group h3 { font-size: 13px; color: var(--text-2); margin: 0 0 8px; font-weight: 600; }
.param-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.param { display: flex; flex-direction: column; gap: 3px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2); }
.param.changed { border-color: var(--warn); }
.param label { font-size: 13px; }
.param .hint { font-size: 11px; color: var(--text-3); }
.param input[type=number] { width: 100%; }
.param .err { color: var(--up); font-size: 12px; }
.formula { font-size: 13px; color: var(--text-2); line-height: 1.8; }
.formula code { font-family: var(--mono); color: var(--text); background: var(--surface-3); padding: 0 4px; border-radius: 3px; }
.history-item { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.history-item:last-child { border-bottom: 0; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- login ---------- */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; padding: 28px; }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card form { display: grid; gap: 12px; margin-top: 20px; }
.login-card label { display: grid; gap: 4px; font-size: 13px; color: var(--text-2); }
.login-card input { padding: 8px 10px; }
.login-card .error { color: var(--up); font-size: 13px; min-height: 20px; }

@media (max-width: 1200px) {
  .terminal { grid-template-columns: 200px minmax(0, 1fr); }
  .terminal .side { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
  .terminal .side .card + .card { margin-top: 0; }
  .strategy-layout { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  main { padding: 12px; }
  .terminal { grid-template-columns: 1fr; }
  .watchlist .body { max-height: 180px; }
}

/* ---------- 多步驟登入 / 帳號安全 ---------- */
.login-card { max-width: 420px; }
.login-card .step { display: grid; gap: 12px; margin-top: 16px; }
.login-card .step.hidden { display: none; }
.steps { display: flex; gap: 6px; list-style: none; padding: 0; margin: 16px 0 0; font-size: 12px; color: var(--text-3); counter-reset: step; }
.steps li { flex: 1; padding-top: 6px; border-top: 3px solid var(--border); counter-increment: step; }
.steps li::before { content: counter(step) ". "; }
.steps li.current { color: var(--text); border-top-color: var(--up); }
.steps li.done { color: var(--text-2); border-top-color: var(--down); }
.steps li.done::after { content: " ✓"; color: var(--down); }
.notice { padding: 8px 10px; border-radius: 6px; background: rgba(224,165,38,.12); border: 1px solid rgba(224,165,38,.35); font-size: 13px; }
.rules { margin: -4px 0 0; padding-left: 18px; font-size: 12px; color: var(--text-3); }
.rules li.ok { color: var(--down); }
.rules li.ok::marker { content: "✓ "; }
.rules li.bad { color: var(--up); }
.rules li.bad::marker { content: "✗ "; }
.howto { margin: 0; padding-left: 18px; font-size: 13px; color: var(--text-2); }
/* QR 必須是白底黑碼並保留留白，才能穩定被掃描 */
.qr { justify-self: center; padding: 12px; background: #fff; border-radius: 6px; min-width: 208px; min-height: 208px; display: grid; place-items: center; }
.qr .faint { color: #555; font-size: 12px; text-align: center; }
.secret { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.secret code { font-family: var(--mono); background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: 2px 6px; word-break: break-all; flex: 1; }
.btn.link { background: none; border: 0; color: var(--text-3); margin-top: 12px; padding: 0; }
.btn.link:hover { color: var(--text); }
dialog.modal { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); padding: 0; width: min(380px, calc(100vw - 32px)); }
dialog.modal::backdrop { background: rgba(0,0,0,.6); }
dialog.modal form { display: grid; gap: 10px; padding: 16px; }
dialog.modal h2 { font-size: 16px; margin: 0; }
dialog.modal label { display: grid; gap: 4px; font-size: 13px; color: var(--text-2); }
dialog.modal .error { color: var(--up); font-size: 13px; min-height: 18px; }

/* ---------- 設定 / 使用者管理 ---------- */
.settings-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 12px; align-items: start; }
.settings-form { display: grid; gap: 14px; }
.settings-form fieldset { border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px 12px; margin: 0; display: grid; gap: 10px; }
.settings-form legend { padding: 0 6px; font-weight: 600; font-size: 13px; color: var(--text-2); display: flex; gap: 8px; align-items: center; }
.settings-form label { display: grid; gap: 4px; font-size: 13px; color: var(--text-2); }
.settings-form .hint { font-size: 12px; color: var(--text-3); }
.settings-form .hint .btn { margin-left: 6px; }
.settings-form .hint.warn { color: var(--warn); }
.settings-form .error { color: var(--up); font-size: 13px; min-height: 18px; }
.settings-form .param input { width: 100%; }
#security-panel { display: grid; gap: 10px; font-size: 13px; }
.role-admin { color: var(--warn); }
@media (max-width: 1200px) { .settings-layout { grid-template-columns: 1fr; } }

/* ---------- 模擬 / 實際下單、損益、委託預覽 ---------- */
.mode-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.mode-bar .seg button { padding: 5px 14px; font-size: 13px; }
.mode-bar .seg button.active[data-mode="paper"] { box-shadow: inset 0 -2px 0 var(--accent); }
.mode-bar .seg button.active[data-mode="live"] { box-shadow: inset 0 -2px 0 var(--up); }
.pnl { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 12px; }
.pnl .kpi.main { grid-column: span 2; }
.pnl .kpi.main .value { font-size: 28px; }
.pnl .kpi .sub { font-size: 12px; color: var(--text-3); font-family: var(--mono); }
.pnl .notice { grid-column: 1 / -1; }
.risk-fail { color: var(--up); white-space: normal; min-width: 180px; font-size: 12px; }
.risk-ok { color: var(--text-3); font-size: 12px; }
.status-pill { font-size: 12px; padding: 0 6px; border-radius: 4px; background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.status-pill.pending { background: rgba(57,135,229,.18); color: #8db8f0; }
.status-pill.approved { background: rgba(34,197,94,.14); color: var(--down); }
.status-pill.blocked { background: rgba(255,77,79,.14); color: var(--up); }
.tag-risk { font-size: 11px; padding: 0 5px; border-radius: 3px; background: rgba(224,165,38,.16); color: var(--warn); margin-left: 4px; }
label.inline { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); }
.settings-form label.check { display: flex; align-items: flex-start; gap: 8px; }
.settings-form label.check input { margin-top: 3px; }
.discover h3 { font-size: 13px; color: var(--text-2); margin: 4px 0 8px; font-weight: 600; }
.discover + .discover, .discover .table-wrap + h3 { margin-top: 16px; }

/* ---------- 看盤圖表高度（autoSize 依容器高度） ---------- */
.pane-main { height: 420px; }
.pane-volume { height: 110px; }
.pane-osc { height: 150px; }
.grid.two-one { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.card > header { flex-wrap: wrap; }
.more-tab { display: none; }

/* ---------- 訪客模式 / 引導 ---------- */
.guest-banner {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: space-between;
  padding: 8px 16px; font-size: 13px; color: var(--text-2);
  background: linear-gradient(90deg, rgba(57,135,229,.16), rgba(57,135,229,.04));
  border-bottom: 1px solid rgba(57,135,229,.35);
}
.guest-banner b { color: var(--text); }
.gate { max-width: 560px; margin: 24px auto; text-align: center; }
.gate h2 { font-size: 18px; margin: 8px 0; }
.gate .actions { justify-content: center; margin-top: 12px; }
.benefits { margin: 0; padding-left: 20px; font-size: 13px; color: var(--text-2); display: grid; gap: 4px; }
.benefits li::marker { content: "✓  "; color: var(--down); }

/* 開始使用清單（goal-gradient：顯示進度，越接近完成越有動力） */
.onboard { margin-bottom: 12px; }
.onboard .progress { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; margin: 2px 0 10px; }
.onboard .progress span { display: block; height: 100%; background: var(--down); transition: width .3s; }
.onboard ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.onboard li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2); font-size: 13px; }
.onboard li.done { color: var(--text-3); text-decoration: line-through; }
.onboard li .check { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--text-3); flex: none; display: grid; place-items: center; font-size: 11px; }
.onboard li.done .check { border-color: var(--down); background: var(--down); color: #000; }
.onboard li button { margin-left: auto; }

/* 復原碼 */
.codes { margin: 0; padding: 10px 12px 10px 36px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 16px; font-family: var(--mono); background: var(--bg); border: 1px solid var(--border); border-radius: 6px; }
.more-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.more-grid .tab { display: flex; flex-direction: column; align-items: center; gap: 2px; border: 1px solid var(--border); border-radius: 8px; padding: 12px 4px; min-height: 64px; }
.more-grid .tab::before { content: attr(data-icon); font-size: 20px; }
.more-grid .tab.active { border-color: var(--up); }
.pw-wrap { position: relative; display: grid; }
.pw-wrap input { padding-right: 52px; }
.pw-toggle { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); background: none; border: 0; color: var(--text-3); cursor: pointer; padding: 6px 8px; font-size: 12px; }
.chart-loading .actions { justify-content: center; margin-top: 8px; }
.chart-loading > div { text-align: center; padding: 0 16px; }

/* 鍵盤操作時才顯示焦點框 */
.btn:focus-visible, .tab:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* 登入頁：註冊 / 忘記密碼入口、遺失 MFA（progressive disclosure：需要時才展開） */
.login-card .links { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.login-card .links .btn.link { margin-top: 0; }
.login-card .recover summary { cursor: pointer; color: var(--text-3); font-size: 13px; padding: 6px 0; }
.login-card .recover summary:hover { color: var(--text); }
.login-card .recover .step { margin-top: 8px; }
.login-card .guest-link { display: block; text-align: center; margin-top: 16px; text-decoration: none; color: var(--accent); }
.login-card .guest-link.hidden { display: none; }
.login-card .steps.hidden { display: none; }

/* ---------- 平板 ---------- */
@media (max-width: 1200px) {
  .grid.two-one { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- 手機（RWD）：底部分頁、44px 觸控目標、單欄 ---------- */
@media (max-width: 760px) {
  body { font-size: 15px; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .topbar { padding: 8px 12px; gap: 8px; padding-top: max(8px, env(safe-area-inset-top)); }
  .topbar .pills, .topbar .clock, .hide-mobile { display: none; }
  .brand { font-size: 15px; }
  .guest-banner { padding: 8px 12px; }
  /* 頂端已有註冊按鈕：手機上只留一個醒目的 CTA */
  .guest-banner .btn { display: none; }

  /* Fitts's law：手指好按的大小 */
  .btn { min-height: 44px; padding: 8px 14px; }
  .btn.sm { min-height: 36px; padding: 6px 10px; font-size: 13px; }
  .btn.link { min-height: 0; }
  /* 16px 以上避免 iOS 聚焦輸入框時自動放大 */
  input[type=text], input[type=number], input[type=password], input[type=email], select, textarea { font-size: 16px; min-height: 44px; }
  input[type=checkbox] { width: 20px; height: 20px; }
  .toolbar label, .settings-form label.check { min-height: 36px; }

  /* 底部分頁列（Jakob's law：與常用 App 一致） */
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; padding: 0 0 env(safe-area-inset-bottom);
    border-top: 1px solid var(--border); border-bottom: 0; overflow: visible; justify-content: space-around; gap: 0;
  }
  .tabs .tab { display: none; }
  .tabs .tab.primary, .tabs .more-tab { display: flex; }
  .tabs .tab {
    flex: 1; flex-direction: column; align-items: center; gap: 2px; min-height: 56px; padding: 6px 2px;
    font-size: 11px; border-bottom: 0; border-top: 2px solid transparent;
  }
  .tabs .tab::before { content: attr(data-icon); font-size: 18px; line-height: 1.2; }
  .tabs .tab.active { border-top-color: var(--up); border-bottom-color: transparent; }
  .more-tab.active-inside { color: var(--text); border-top-color: var(--up); }

  main { padding: 10px; }
  .card > header { padding: 10px 12px; }
  .card > .body { padding: 10px 12px; }
  /* minmax(0, …)：不讓表格（white-space: nowrap）把整欄撐得比螢幕寬 */
  .terminal { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .terminal .side { grid-template-columns: minmax(0, 1fr); }
  .watchlist .body { max-height: 200px; }
  .pane-main { height: 300px; }
  .pane-volume { height: 80px; }
  .pane-osc { height: 110px; }
  .marker-key { display: none; }
  .quote .price { font-size: 20px; }
  th, td { padding: 8px; }
  .table-wrap { max-height: none; -webkit-overflow-scrolling: touch; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .pnl { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi .value { font-size: 18px; }
  .pnl .kpi.main .value { font-size: 24px; }
  .strategy-layout, .settings-layout { grid-template-columns: minmax(0, 1fr); }
  .param-grid { grid-template-columns: minmax(0, 1fr); }
  .actions.stack-mobile { flex-direction: column; align-items: stretch; }
  .actions.stack-mobile .btn { text-align: center; }
  #sim-form label.inline { width: 100%; justify-content: space-between; }
  .mode-bar .seg { width: 100%; }
  .mode-bar .seg button { flex: 1; min-height: 40px; }
  .toast { left: 12px; right: 12px; max-width: none; bottom: calc(72px + env(safe-area-inset-bottom)); }
  dialog.modal { width: calc(100vw - 24px); max-height: calc(100vh - 24px); overflow: auto; }
  dialog.modal.sheet { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: 14px 14px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .login-wrap { place-items: start center; padding-top: 24px; }
  .login-card { padding: 20px; }
  .codes { grid-template-columns: 1fr; }
}
