:root {
  --bg: #0d1117; --panel: #161b22; --panel2: #1f2630; --line: #2a313c; --text: #e6edf3; --muted: #8b949e;
  --buy: #2f81f7; --sell: #e5534b; --up: #26a69a; --down: #ef5350; --warn: #d29922; --ok: #3fb950;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.35 -apple-system, "Hiragino Sans", "Yu Gothic UI", "Segoe UI", sans-serif; overscroll-behavior: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
button:disabled { opacity: .45; cursor: default; }
[hidden] { display: none !important; }
#app, .screen { height: 100%; }
#main { display: flex; flex-direction: column; padding-top: var(--safe-t); }

/* 登録 */
#pair { display: flex; align-items: center; justify-content: center; padding: 16px; }
.pair-box { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }
.pair-box h1 { margin: 0 0 4px; font-size: 22px; }
.pair-box label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
.pair-box input { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; font-size: 18px; color: var(--text); }
#pair-code { letter-spacing: .4em; text-align: center; font-size: 24px; }
.primary { background: var(--buy); color: #fff; border-radius: 8px; padding: 12px; font-weight: 600; }
.err { color: var(--sell); min-height: 1.2em; margin: 0; }
.muted { color: var(--muted); text-align: center; padding: 24px 8px; }

/* 上部 */
#top { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line); min-height: 40px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.on { background: var(--ok); } .dot.off { background: var(--sell); } .dot.half { background: var(--warn); }
#acct { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: 10px; padding: 1px 6px; border-radius: 4px; background: var(--warn); color: #000; font-weight: 700; }
.badge.demo { background: #30363d; color: var(--text); }
.spacer { flex: 1; }
.chip { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; font-size: 13px; }

/* チャート */
.tab { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#pricebar { display: grid; grid-template-columns: 1fr 96px 1fr; gap: 6px; padding: 6px; background: var(--bg); }
.trade { border-radius: 8px; padding: 6px 8px; display: flex; flex-direction: column; align-items: flex-start; color: #fff; min-height: 52px; }
.trade small { font-size: 11px; opacity: .85; font-weight: 600; }
.trade b { font-size: 20px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.trade.sell { background: var(--sell); } .trade.buy { background: var(--buy); align-items: flex-end; }
.trade:active:not(:disabled) { filter: brightness(1.2); }
#lot-box { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
#lot-box small { font-size: 10px; color: var(--muted); }
.lot-row { display: flex; align-items: center; gap: 2px; }
#lot { width: 52px; text-align: center; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 4px 2px; font-size: 15px; font-variant-numeric: tabular-nums; }
.mini { width: 20px; height: 28px; background: var(--panel2); border-radius: 4px; font-size: 14px; }
#risk { width: 64px; text-align: center; background: var(--panel); border: 1px solid #6b5a1e; border-radius: 6px; padding: 4px 2px; font-size: 14px; font-variant-numeric: tabular-nums; }
#lot-box { width: 100%; }
#pricebar { grid-template-columns: 1fr 108px 1fr; }
#ordbar { display: flex; align-items: center; gap: 6px; padding: 0 6px 6px; font-size: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { padding: 5px 9px; color: var(--muted); font-size: 12px; }
.seg button.on { background: var(--panel2); color: var(--text); font-weight: 600; }
.tog { border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; color: var(--muted); font-size: 12px; font-weight: 600; }
.tog.on { color: #fff; border-color: transparent; }
#d-sl.on { background: var(--sell); } #d-tp.on { background: #2e8b57; }
#draft-info { flex: 1; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#draft-info b { color: var(--text); }
#sheet .acts { display: flex; flex-direction: column; gap: 6px; }
#sheet .acts button { text-align: left; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 11px 12px; }
#sheet .acts button small { display: block; color: var(--muted); font-size: 11px; }
#sheet .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#sheet label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
#ordbar2 { display: flex; align-items: center; gap: 6px; padding: 0 6px 6px; font-size: 12px; }
#ordbar2 .pre { flex: 1; display: flex; align-items: center; gap: 6px; color: var(--muted); }
#preset-sel { flex: 1; background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; font-size: 13px; }
#hedge-btn.busy { opacity: .5; }
.settings h4 { margin: 8px 0 0; font-size: 14px; }
.note-s { margin: 0; font-size: 12px; color: var(--muted); }
.ind-box { border: 1px solid var(--line); border-radius: 8px; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.ind-box .nm { font-weight: 600; font-size: 13px; }
.bufrow { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.bufrow .sw { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); }
.bufrow .bl { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bufrow .shc { display: inline-flex; align-items: center; gap: 2px; }
.bufrow .shc button { width: 22px; height: 22px; background: var(--panel2); border-radius: 4px; }
.bufrow .shc b { min-width: 26px; text-align: center; color: var(--text); font-weight: 600; }
.bufrow .kind { border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px; font-size: 12px; }
.prow-e { display: grid; grid-template-columns: 1.2fr 1fr 1fr .7fr .8fr 28px; gap: 4px; align-items: center; }
.prow-e input { min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 4px; font-size: 13px; }
.prow-e .del { color: var(--sell); font-size: 18px; }
.prow-h { font-size: 11px; color: var(--muted); }
.primary.sm { padding: 6px 14px; }
.tag { font-size: 10px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; margin-left: 4px; font-weight: 400; }
#banner { padding: 6px 10px; font-size: 12px; background: #33290f; border-bottom: 1px solid #6b5a1e; color: #f0d58a; }
#banner.bad { background: #3a1d1d; border-color: #7d2b28; color: #ffb4ad; }
#chart-wrap { position: relative; flex: 1; min-height: 0; }
#chart { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
#chart-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); pointer-events: none; text-align: center; padding: 16px; }
#sum-strip { display: flex; gap: 12px; justify-content: space-between; padding: 6px 10px; font-size: 12px; background: var(--panel); border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
#sum-strip b { font-weight: 600; }
.pos { color: var(--buy); } .neg { color: var(--sell); }

/* ポジション */
#tab-pos { overflow-y: auto; }
#acct-sum { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; padding: 10px 12px; background: var(--panel); border-bottom: 1px solid var(--line); font-size: 13px; font-variant-numeric: tabular-nums; }
#acct-sum .big { grid-column: 1 / -1; font-size: 22px; font-weight: 700; text-align: center; }
#acct-sum span:nth-child(even) { text-align: right; }
/* 選択バーは下に重ねて出す（一覧の位置がずれてタップ先が変わらないように） */
#sel-bar { position: fixed; left: 0; right: 0; bottom: calc(46px + var(--safe-b)); display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: #1c2a3f; border-top: 1px solid #36506b; z-index: 5; }
#pos-list { padding-bottom: 64px; }
#sel-info { flex: 1; font-size: 13px; }
.danger { background: var(--sell); color: #fff; border-radius: 6px; padding: 6px 12px; font-weight: 600; }
.ghost { border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; color: var(--muted); }
#pos-list, #log-list { list-style: none; margin: 0; padding: 0; }
.prow { display: grid; grid-template-columns: 28px 1fr auto 36px; align-items: center; gap: 6px; padding: 10px 8px 10px 10px; border-bottom: 1px solid var(--line); }
.prow.sel { background: #12233b; }
.prow input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--buy); }
.prow .l1 { font-weight: 600; } .prow .l2 { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.prow .pl { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.prow .x { color: var(--sell); font-size: 20px; height: 36px; }
.side-buy { color: var(--buy); } .side-sell { color: var(--sell); }

/* 履歴・設定 */
#tab-log { overflow-y: auto; }
.lrow { padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 12px; }
.lrow .st { font-weight: 700; margin-right: 6px; }
.st-done { color: var(--ok); } .st-partial, .st-unknown { color: var(--warn); } .st-failed, .st-rejected { color: var(--sell); } .st-accepted, .st-executing { color: var(--muted); }
.settings { padding: 16px 12px; display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 8px; }

/* 下部タブ */
#tabs { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--panel); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
#tabs button { padding: 10px 0 12px; color: var(--muted); font-size: 13px; }
#tabs button.on { color: var(--buy); font-weight: 600; }
#pos-count { margin-left: 4px; font-size: 11px; }

/* シート・トースト */
#sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 10; }
#sheet { position: fixed; left: 0; right: 0; bottom: 0; background: var(--panel); border-radius: 14px 14px 0 0; padding: 16px 16px calc(16px + var(--safe-b)); z-index: 11; display: flex; flex-direction: column; gap: 12px; max-width: 560px; margin: 0 auto; }
#sheet h3 { margin: 0; font-size: 16px; }
#sheet .kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; font-variant-numeric: tabular-nums; }
#sheet .kv span:nth-child(even) { text-align: right; }
#sheet .btns { display: flex; gap: 8px; }
#sheet .btns button { flex: 1; padding: 12px; border-radius: 8px; font-weight: 600; }
#sheet .chips { display: flex; gap: 6px; flex-wrap: wrap; }
#sheet .chips button { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; }
#sheet input { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px; font-size: 16px; width: 100%; }
#sheet .note { font-size: 12px; color: var(--muted); margin: 0; }
.cancel { background: var(--panel2); }
#toasts { position: fixed; left: 8px; right: 8px; bottom: calc(112px + var(--safe-b)); display: flex; flex-direction: column; gap: 6px; z-index: 20; pointer-events: none; align-items: center; }
.toast { background: #22303f; border: 1px solid #36506b; color: var(--text); border-radius: 10px; padding: 10px 14px; font-size: 13px; max-width: 520px; width: 100%; box-shadow: 0 4px 16px rgba(0,0,0,.4); }
.toast.ok { border-color: #2e6b3a; } .toast.bad { border-color: #7d2b28; background: #3a1d1d; } .toast.warn { border-color: #6b5a1e; background: #33290f; }
