:root {
  --bg: #0b0f17;
  --panel: #111723;
  --panel-2: #161e2c;
  --line: #222c3d;
  --text: #e6eaf2;
  --muted: #8b95a7;
  --buy: #2f81f7;
  --buy-2: #1f6feb;
  --sell: #f0464b;
  --sell-2: #d73a3f;
  --up: #26a69a;
  --down: #ef5350;
  --accent: #f5b041;
  --ok: #3fb950;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Segoe UI", sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { display: flex; flex-direction: column; font-size: 13px; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---- 上部バー ---- */
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap;
}
.brand { font-weight: 700; letter-spacing: .02em; }
.brand span { color: var(--accent); }
.sel {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px;
}
.tf-group { display: flex; gap: 2px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.tf-group button {
  background: transparent; border: 0; padding: 4px 8px; border-radius: 6px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.tf-group button.active { background: #26324a; color: var(--text); }
.spacer { flex: 1; }
.badge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.badge.demo { background: #4a3200; color: var(--accent); border: 1px solid #7a5300; }
.status { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #6b7280; }
.dot.ok { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.dot.ng { background: var(--sell); }
.icon-btn { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 4px 9px; }

/* ---- レイアウト ---- */
.layout { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 330px; min-height: 0; }
.chart-area { display: flex; flex-direction: column; min-width: 0; min-height: 0; border-right: 1px solid var(--line); }
.chart-wrap { position: relative; flex: 1; min-height: 240px; }
.chart { position: absolute; inset: 0; }
.overlay { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 3; }
.legend {
  position: absolute; left: 10px; top: 8px; z-index: 4; pointer-events: none;
  font-size: 12px; font-variant-numeric: tabular-nums; color: var(--muted);
  text-shadow: 0 0 4px var(--bg);
}
.legend b { color: var(--text); margin-right: 6px; }
.legend .up { color: var(--up); }
.legend .down { color: var(--down); }
.legend .bar-lag {
  margin-left: 8px; padding: 1px 6px; border-radius: 4px; font-size: 11px;
  color: #1a1200; background: #e3b341; text-shadow: none;
}
.ind-status {
  position: absolute; left: 10px; bottom: 34px; z-index: 4; font-size: 11px; color: var(--muted);
  pointer-events: none; text-shadow: 0 0 4px var(--bg);
}
.to-latest {
  position: absolute; right: 84px; bottom: 40px; z-index: 5; background: #26324a; border: 1px solid #3a4a68;
  color: var(--text); border-radius: 999px; padding: 4px 12px; font-size: 12px; box-shadow: 0 4px 12px rgba(0,0,0,.4);
}
.obj-settings { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.obj-settings label { display: flex; gap: 6px; align-items: center; }
.obj-settings small { color: var(--muted); }
.sub-charts { display: flex; flex-direction: column; }
.sub-chart { position: relative; height: 130px; border-top: 1px solid var(--line); }
.sub-chart .chart { right: auto; width: 100%; }
.sub-chart .sub-title { position: absolute; left: 10px; top: 4px; z-index: 4; font-size: 11px; color: var(--muted); pointer-events: none; }

.side { overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 10px; background: var(--bg); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.card-title { display: flex; justify-content: space-between; align-items: center; font-weight: 600; margin-bottom: 8px; }

/* ---- 発注 ---- */
.quote-row { display: grid; grid-template-columns: 1fr 64px 1fr; gap: 6px; align-items: stretch; }
.trade-btn {
  border: 0; border-radius: 10px; padding: 10px 6px; display: flex; flex-direction: column; align-items: center;
  gap: 2px; color: #fff; transition: transform .05s, filter .15s; user-select: none; -webkit-user-select: none;
  touch-action: manipulation; min-height: 64px;
}
.trade-btn:active { transform: scale(.98); }
.trade-btn.sell { background: linear-gradient(180deg, var(--sell), var(--sell-2)); }
.trade-btn.buy { background: linear-gradient(180deg, var(--buy), var(--buy-2)); }
.trade-btn .lbl { font-size: 12px; font-weight: 700; letter-spacing: .08em; opacity: .9; }
.trade-btn .px { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.trade-btn.armed { outline: 3px solid var(--accent); outline-offset: 2px; animation: pulse .6s infinite alternate; }
.trade-btn.armed .lbl::after { content: " ← もう一度"; }
.trade-btn:disabled { filter: grayscale(.7) brightness(.7); cursor: wait; }
@keyframes pulse { from { filter: brightness(1); } to { filter: brightness(1.25); } }
.spread { display: flex; flex-direction: column; align-items: center; justify-content: center; font-variant-numeric: tabular-nums; }
.spread span { font-size: 15px; font-weight: 600; }
.spread small { color: var(--muted); font-size: 10px; }

.seg { display: flex; gap: 2px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 2px; margin: 10px 0 8px; }
.seg.small { margin: 0; }
.seg-btn { flex: 1; background: transparent; border: 0; border-radius: 6px; padding: 5px 6px; color: var(--muted); font-size: 12px; }
.seg-btn.active { background: #26324a; color: var(--text); }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.field-row label, .field-grid label { color: var(--muted); font-size: 12px; }
input[type=number], input[type=password], input[type=text] {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 8px; width: 100%;
  font-variant-numeric: tabular-nums;
}
#riskInput { max-width: 150px; text-align: right; }
.stepper { display: flex; align-items: stretch; max-width: 170px; }
.stepper button { width: 36px; background: var(--panel-2); border: 1px solid var(--line); }
.stepper button:first-child { border-radius: 8px 0 0 8px; }
.stepper button:last-child { border-radius: 0 8px 8px 0; }
.stepper input { border-radius: 0; text-align: center; border-left: 0; border-right: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.chips button { background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 12px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.field-grid > div { display: flex; flex-direction: column; gap: 3px; }
.risk-info { margin: 8px 0; font-size: 12px; min-height: 1.4em; font-variant-numeric: tabular-nums; }
.risk-info .neg { color: var(--sell); }
.risk-info .pos { color: var(--ok); }
.switch-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); margin: 6px 0 10px; cursor: pointer; }
.switch-row input { display: none; }
.switch { width: 34px; height: 20px; border-radius: 999px; background: #39424f; position: relative; flex: none; transition: background .15s; }
.switch::after { content: ""; position: absolute; left: 2px; top: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; }
.switch-row input:checked + .switch { background: var(--accent); }
.switch-row input:checked + .switch::after { left: 16px; }
.close-row { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 4px; }
.ghost-btn { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 7px 6px; font-size: 12px; }
.ghost-btn:hover { background: var(--panel-2); }
.ghost-btn.armed { border-color: var(--accent); color: var(--accent); }
.ghost-btn.buy-t { color: #79b8ff; }
.ghost-btn.sell-t { color: #ff8a8e; }
.note { font-size: 11px; margin-top: 6px; }
.primary-btn { background: var(--buy); border: 0; border-radius: 8px; padding: 8px 16px; color: #fff; font-weight: 600; }

/* ---- 口座・ポジション・成績 ---- */
.kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; font-variant-numeric: tabular-nums; }
.kv-grid div { display: flex; flex-direction: column; }
.kv-grid span { color: var(--muted); font-size: 11px; }
.kv-grid b { font-size: 14px; font-weight: 600; }
.pos { color: var(--ok); }
.neg { color: var(--sell); }
.positions { display: flex; flex-direction: column; gap: 4px; max-height: 260px; overflow-y: auto; }
.pos-item {
  display: grid; grid-template-columns: auto 1fr auto auto; gap: 6px; align-items: center; padding: 6px 8px;
  background: var(--panel-2); border-radius: 8px; font-variant-numeric: tabular-nums; font-size: 12px;
}
.pos-item .side-tag { font-weight: 700; font-size: 11px; padding: 1px 6px; border-radius: 4px; }
.side-tag.buy { background: rgba(47,129,247,.18); color: #79b8ff; }
.side-tag.sell { background: rgba(240,70,75,.18); color: #ff8a8e; }
.pos-item .meta { color: var(--muted); font-size: 11px; }
.pos-item .ea { color: var(--accent); font-size: 10px; margin-left: 4px; }
.pos-item .x { background: transparent; border: 1px solid var(--line); border-radius: 6px; width: 28px; height: 26px; }
.pos-item .x.armed { border-color: var(--accent); color: var(--accent); }
.pos-empty { color: var(--muted); font-size: 12px; padding: 4px; }
table.stats { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 12px; }
table.stats th, table.stats td { padding: 4px 4px; text-align: right; border-bottom: 1px solid var(--line); }
table.stats th:first-child, table.stats td:first-child { text-align: left; color: var(--muted); font-weight: 400; }
table.stats thead th { color: var(--muted); font-weight: 400; }

/* ---- トースト・モーダル ---- */
.toasts { position: fixed; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 6px; z-index: 50; pointer-events: none; }
.toast {
  background: #1b2433; border: 1px solid var(--line); border-left: 4px solid var(--ok); padding: 8px 12px;
  border-radius: 8px; font-size: 12px; max-width: 360px; box-shadow: 0 6px 18px rgba(0,0,0,.4);
  animation: tin .15s ease-out; font-variant-numeric: tabular-nums;
}
.toast.err { border-left-color: var(--sell); }
@keyframes tin { from { opacity: 0; transform: translateY(6px); } }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 60; }
.modal-body { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; width: min(640px, 94vw); max-height: 86vh; overflow-y: auto; padding: 14px; }
.modal-body.narrow { width: min(380px, 92vw); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.modal-sub { margin: 14px 0 6px; color: var(--muted); font-size: 12px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.opt-row { display: flex; flex-direction: column; gap: 6px; }
.ind-settings { display: flex; flex-direction: column; gap: 10px; }
.ind-block { background: var(--panel-2); border-radius: 8px; padding: 8px; }
.ind-block .ind-name { font-weight: 600; margin-bottom: 6px; }
.ind-block .ind-name small { color: var(--muted); font-weight: 400; margin-left: 6px; }
.buf-row { display: flex; flex-direction: column; gap: 4px; margin: 6px 0; padding: 6px; font-size: 12px; border-top: 1px solid var(--line); }
.buf-head { display: flex; gap: 6px; align-items: center; }
.buf-no { color: var(--muted); min-width: 28px; font-variant-numeric: tabular-nums; }
.buf-label { flex: 1; min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; color: var(--text); font-size: 12px; }
.buf-ctl { display: grid; grid-template-columns: 1fr 44px 64px; gap: 6px; align-items: center; }
.buf-stat { color: var(--muted); font-size: 11px; }
.buf-row .peek { padding: 2px 6px; }
.buf-empty summary { cursor: pointer; color: var(--muted); font-size: 12px; margin-top: 6px; }
.ind-params { color: var(--muted); font-size: 11px; margin: -2px 0 6px; word-break: break-all; }
.ind-tools { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.ind-tools .ghost-btn { font-size: 12px; padding: 4px 8px; }
.file-btn { cursor: pointer; }
.candle-fill { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 6px; margin-bottom: 6px; background: var(--panel-2); border-radius: 8px; }
.candle-fill input[type=color] { width: 40px; height: 24px; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: none; }
.candle-fill small { width: 100%; }
.modal.peeking { background: transparent; pointer-events: none; }
.modal.peeking .modal-body { opacity: 0.06; transition: opacity .15s; }
.buf-row select { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 3px; }
.buf-row input[type=color] { width: 40px; height: 24px; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: none; }

/* ---- スマホ ---- */
@media (max-width: 900px) {
  html, body { height: auto; }
  body { display: block; font-size: 14px; }
  .layout { display: flex; flex-direction: column; }
  .chart-area { flex: none; border-right: 0; }
  .chart-wrap { flex: none; height: 52vh; min-height: 260px; }
  .sub-chart { height: 96px; }
  .side { overflow: visible; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .order-card { order: -1; }
  .brand { display: none; }
  .status #statusText { max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .toasts { left: 12px; right: 12px; bottom: 12px; }
  .toast { max-width: none; }
}

/* ポジションラインのドラッグ */
.chart-wrap.line-hover, .chart-wrap.line-hover * { cursor: ns-resize !important; }
.line-confirm {
  position: absolute; left: 50%; transform: translateX(-50%); z-index: 6;
  display: flex; align-items: center; gap: 8px; padding: 6px 8px;
  background: #161d2b; border: 1px solid #2f3b52; border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.45); font-size: 13px; white-space: nowrap;
}
.line-confirm[hidden] { display: none; }
.line-confirm button { border: 0; border-radius: 6px; padding: 6px 12px; font-size: 13px; cursor: pointer; }
.line-confirm .lc-ok { background: #2f81f7; color: #fff; }
.line-confirm .lc-cancel { background: #30363d; color: #c9d1d9; }
.hint { font-size: 11px; margin-top: 6px; line-height: 1.5; }

/* 履歴の読み込み中表示 */
.chart-loading {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); z-index: 5;
  max-width: 86%; padding: 10px 14px; border-radius: 8px; text-align: center; line-height: 1.6;
  background: rgba(22, 29, 43, .92); border: 1px solid #2f3b52; font-size: 13px; pointer-events: none;
}
.chart-loading[hidden] { display: none; }
.chart-loading small { color: var(--muted); }

/* 足の確定までのカウントダウン（最新価格ラベルの下） */
.countdown {
  position: absolute; z-index: 4; pointer-events: none; box-sizing: border-box;
  padding: 1px 0; text-align: center; font-size: 11px; line-height: 16px;
  font-variant-numeric: tabular-nums; color: #fff; background: #26a69a; border-radius: 0 0 2px 2px;
}
.countdown.down { background: #ef5350; }
.countdown[hidden] { display: none; }
.ind-off-list summary { cursor: pointer; color: var(--muted); font-size: 12px; margin-top: 8px; }
.ind-off { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 8px; font-size: 12px; }
.ind-off .ghost-btn { padding: 4px 10px; }

/* 上部の「履歴」切替ボタン */
.toggle-btn { font-size: 12px; margin-right: 6px; color: var(--muted); }
.toggle-btn.on { color: var(--text); border-color: var(--accent); background: rgba(47, 129, 247, .15); }

/* チャート上の線をクリックしたときの説明 */
.line-info {
  position: absolute; z-index: 7; min-width: 180px; max-width: 300px; padding: 8px 10px;
  background: #161d2b; border: 1px solid #2f3b52; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.45);
  font-size: 12px; line-height: 1.5;
}
.line-info[hidden] { display: none; }
.line-info .li-name { font-weight: 600; }
.line-info .li-sub { color: var(--muted); }
.line-info .li-sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.li-btns { display: flex; gap: 6px; margin-top: 6px; }
.li-btns button { border: 0; border-radius: 6px; padding: 5px 10px; font-size: 12px; cursor: pointer; }

/* ローソク足の設定 */
.candle-settings { display: flex; flex-direction: column; gap: 6px; background: var(--panel-2); border-radius: 8px; padding: 8px; font-size: 12px; }
.cs-row { display: grid; grid-template-columns: 80px auto 1fr auto 1fr; gap: 6px; align-items: center; }
.cs-row input[type=color] { width: 40px; height: 24px; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: none; }
.cs-row label { display: flex; gap: 4px; align-items: center; }
.cs-presets { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.cs-presets .ghost-btn { padding: 4px 8px; }

.li-edit { display: flex; gap: 6px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.li-edit select { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 3px; font-size: 12px; }
.li-edit input[type=color] { width: 36px; height: 24px; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: none; }
.li-edit .ghost-btn { padding: 3px 8px; font-size: 11px; }
.modal-foot.left { justify-content: flex-start; flex-wrap: wrap; }
.modal-foot .spacer { flex: 1; }
.bi-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.bi-row input[type=number] { width: 56px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 3px 5px; color: var(--text); }
.bi-row input[type=color] { width: 40px; height: 24px; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: none; }
.bi-row input[type=range] { width: 120px; }
.bi-row label { display: flex; gap: 4px; align-items: center; }

/* 口座の切り替え・本番表示 */
.acct-sel { max-width: 180px; }
.badge.real { background: #5a1014; color: #ffb3b8; border: 1px solid #b4232c; }
body.is-real .topbar { box-shadow: inset 0 -2px 0 #b4232c; }

/* iPhoneのホーム画面から開いたとき、下端のバー（ホームインジケーター）に重ならないように */
.side { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.toasts { bottom: max(12px, env(safe-area-inset-bottom)); }

/* ---- v0.9: 予約注文・操作メニュー・サブウィンドウのオブジェクト ---- */
.pending-box { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin-bottom: 2px; }
.pending-box .field-grid { margin-bottom: 6px; }
.pending-box .field-row { margin: 4px 0; }
.pend-chips { margin: 0 0 4px; }
.pend-chips button { padding: 3px 8px; font-variant-numeric: tabular-nums; }
.small-sel { padding: 4px 6px; font-size: 12px; max-width: 210px; }
.exp-at { width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; margin: 2px 0 4px; color-scheme: dark; }
.pending-box .note { margin-top: 4px; line-height: 1.5; }
.from-lbl { color: var(--muted); font-size: 10px; margin-left: 4px; }
#pendKindLbl { color: var(--muted); font-size: 10px; margin-left: 4px; }
.close-row .wide { grid-column: 1 / -1; }
.pos-item { grid-template-columns: auto 1fr auto auto auto; }
.pos-item .more { font-weight: 700; letter-spacing: -1px; }
.ord-item .ot { color: var(--muted); font-size: 10px; margin-left: 2px; }
.ord-item .dist { color: var(--muted); font-weight: 400; font-size: 11px; }
.sub-overlay { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 3; }
.chart-wrap.label-hover, .chart-wrap.label-hover * { cursor: pointer !important; }
#mainChart { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }

.trade-menu {
  position: fixed; z-index: 70; min-width: 220px; max-width: min(340px, 92vw); padding: 6px;
  background: #161d2b; border: 1px solid #2f3b52; border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.55);
  display: flex; flex-direction: column; gap: 2px; font-size: 13px;
}
.trade-menu[hidden] { display: none; }
.tm-head { padding: 4px 6px 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.tm-sub { padding: 0 6px 4px; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; border-bottom: 1px solid var(--line); margin-bottom: 2px; line-height: 1.5; }
.tm-btn { text-align: left; background: transparent; border: 0; border-radius: 6px; padding: 8px 8px; color: var(--text); font-variant-numeric: tabular-nums; }
.tm-btn:hover:not(:disabled) { background: #222c3d; }
.tm-btn:disabled { color: #5b6472; cursor: not-allowed; }
.tm-btn.warn { color: #ffb3b8; }
.tm-btn.sub { color: var(--muted); font-size: 12px; }
.tm-row { display: flex; align-items: center; gap: 6px; padding: 4px 8px; }
.tm-row input { width: 80px; padding: 4px 6px; }
.tm-row .tm-btn { padding: 5px 10px; background: #26324a; }
.buy-c { color: #79b8ff; font-weight: 700; }
.sell-c { color: #ff8a8e; font-weight: 700; }
@media (max-width: 900px) {
  .tm-btn { padding: 11px 10px; }
}

/* ---- v0.10: 描画ツール ---- */
.draw-bar {
  position: absolute; top: 6px; right: 70px; z-index: 6; display: flex; align-items: center; gap: 2px;
  background: rgba(17, 23, 35, .92); border: 1px solid var(--line); border-radius: 8px; padding: 2px;
}
.draw-bar button {
  min-width: 30px; height: 28px; padding: 0 6px; background: transparent; border: 0; border-radius: 6px;
  color: var(--muted); font-size: 13px; line-height: 1;
}
@media (hover: hover) { .draw-bar button:hover { background: #222c3d; color: var(--text); } }
.draw-bar button.active { background: #26324a; color: var(--accent); }
.draw-bar button.off { opacity: .4; }
.draw-bar button.armed { color: var(--accent); outline: 1px solid var(--accent); }
.draw-bar .db-main { font-size: 15px; }
.draw-tools { display: flex; align-items: center; gap: 2px; }
.draw-tools[hidden] { display: none; }
.db-sep { width: 1px; height: 18px; background: var(--line); margin: 0 2px; }
.draw-edit {
  position: absolute; top: 42px; right: 70px; z-index: 6; display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  max-width: min(560px, 92%); padding: 6px 8px; font-size: 12px;
  background: #161d2b; border: 1px solid #2f3b52; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.45);
}
.draw-edit[hidden] { display: none; }
.draw-edit .de-name { font-weight: 600; }
.draw-edit .de-px { color: var(--muted); font-variant-numeric: tabular-nums; }
.draw-edit select { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 3px; font-size: 12px; }
.draw-edit input[type=color] { width: 34px; height: 24px; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: none; }
.draw-edit label { display: flex; align-items: center; gap: 4px; }
.draw-edit .de-levels { width: 230px; padding: 4px 6px; font-size: 12px; }
.draw-edit .ghost-btn { padding: 4px 8px; }
.chart-wrap.drawing, .chart-wrap.drawing * { cursor: crosshair !important; }
.chart-wrap.draw-hover, .chart-wrap.draw-hover * { cursor: move !important; }
.chart-wrap.handle-hover, .chart-wrap.handle-hover * { cursor: grab !important; }
@media (max-width: 900px) {
  /* スマホは縦並び（チャートの右上から下へ）。編集パネルはチャートの下側に出して重ならないようにする */
  .draw-bar { flex-direction: column; }
  .draw-tools { flex-direction: column; }
  .db-sep { width: 18px; height: 1px; margin: 2px 0; }
  .draw-bar button { min-width: 34px; height: 32px; }
  .draw-edit { top: auto; bottom: 34px; left: 6px; right: auto !important; max-width: calc(100% - 64px); }
  .draw-edit .de-levels { width: 150px; }
}

/* Bid/Ask の価格ラベル（価格軸の上） */
.px-tag {
  position: absolute; z-index: 4; pointer-events: none; box-sizing: border-box; height: 20px;
  text-align: center; font-size: 11px; line-height: 20px; font-variant-numeric: tabular-nums; border-radius: 2px;
}
.px-tag[hidden] { display: none; }

/* ---- v0.11: 複数チャート・見るだけモード ---- */
.layout-group button { min-width: 30px; font-size: 14px; }
.pane-main { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; }
.chart-area[data-layout="2h"] { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: minmax(0, 1fr); }
.chart-area[data-layout="2v"] { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: 1fr 1fr; }
.chart-area[data-layout="4"] { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.chart-area[data-layout="2h"] > *, .chart-area[data-layout="2v"] > *, .chart-area[data-layout="4"] > * { min-width: 0; min-height: 0; }
.pane-sub { width: 100%; height: 100%; border: 0; background: var(--bg); box-shadow: inset 1px 1px 0 var(--line); }
@media (max-width: 900px) { .layout-group { display: none; } }

body.embed .side, body.embed .brand, body.embed #accountSelect, body.embed #settingsBtn, body.embed #layoutBtns,
body.embed #demoBadge, body.embed #drawBar, body.embed #drawEdit, body.embed #latency { display: none !important; }
body.embed .layout { grid-template-columns: minmax(0, 1fr); }
body.embed .chart-area { border-right: 0; }
body.embed .topbar { padding: 3px 6px; gap: 6px; flex-wrap: nowrap; overflow-x: auto; }
body.embed .topbar .sel { padding: 3px 6px; }
body.embed .tf-group button { padding: 2px 6px; font-size: 12px; }
body.embed .status #statusText { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
/* 追加チャートは幅が狭くてもスマホ用の縦積みにしない（iframeの中は常にチャートだけを全面に） */
html.embed, html.embed body { height: 100%; }
html.embed body { display: flex; flex-direction: column; font-size: 13px; }
html.embed .layout { display: grid; flex: 1; min-height: 0; }
html.embed .chart-area { display: flex; flex-direction: column; min-height: 0; }
html.embed .chart-wrap { flex: 1; height: auto; min-height: 120px; }
html.embed .sub-chart { height: 90px; }
.bi-row .bb-devs { width: 110px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 3px 5px; color: var(--text); }
/* 複数チャートのとき: メインもセルの中に収める（サブウィンドウではみ出して隣のチャートを隠さない） */
.chart-area[data-layout="2h"] .pane-main, .chart-area[data-layout="2v"] .pane-main, .chart-area[data-layout="4"] .pane-main { overflow: hidden; }
.chart-area[data-layout="2v"] .chart-wrap, .chart-area[data-layout="4"] .chart-wrap { min-height: 120px; }
.chart-area[data-layout="2v"] .sub-chart, .chart-area[data-layout="4"] .sub-chart { height: 90px; }

/* サーバーと画面の版が違うときの警告 */
.ver-warn { padding: 6px 12px; background: #4a3200; color: #ffd27a; border-bottom: 1px solid #7a5300; font-size: 12px; line-height: 1.5; }
body.embed .ver-warn { display: none !important; }

/* ---- v0.12: 注文パネルの配置（右／下／浮かせる）。PCだけ。スマホは従来の縦並び ---- */
.panel-mode button { min-width: 0; font-size: 12px; padding: 4px 8px; white-space: nowrap; }
.panel-bar, .float-tabs { display: none; }
.pb-grip { color: #5b6472; letter-spacing: 1px; }
.pb-title { font-weight: 600; font-size: 12px; }
.pb-summary { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pb-btn { background: transparent; border: 1px solid transparent; border-radius: 6px; padding: 2px 8px; color: var(--muted); }
.pb-btn:hover { border-color: var(--line); color: var(--text); }
.panel-bar .pb-btn.active { color: var(--accent); }

/* 下パネル: チャートを上に、注文パネルを下に4列 */
body[data-panel="bottom"] .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
body[data-panel="bottom"] .chart-area { border-right: 0; }
body[data-panel="bottom"] .side {
  height: var(--bottom-h, 290px); overflow: hidden; padding: 0 8px 8px; border-top: 1px solid #2f3b52; background: var(--panel);
  display: grid; gap: 8px; align-content: stretch;
  grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 0.9fr);
  grid-template-rows: 30px minmax(0, 1fr) minmax(0, 1fr);
}
body[data-panel="bottom"] .panel-bar { display: flex; align-items: center; gap: 10px; grid-column: 1 / -1; cursor: ns-resize; user-select: none; -webkit-user-select: none; touch-action: none; }
body[data-panel="bottom"] .side > .card { min-height: 0; overflow: auto; margin: 0; }
body[data-panel="bottom"] #cardOrder { grid-column: 1; grid-row: 2 / 4; column-count: 2; column-gap: 14px; }
body[data-panel="bottom"] #cardOrder > * { break-inside: avoid; }
body[data-panel="bottom"] #cardPos { grid-column: 2; grid-row: 2 / 4; }
body[data-panel="bottom"] #cardOrd { grid-column: 3; grid-row: 2 / 4; }
body[data-panel="bottom"] #cardAccount { grid-column: 4; grid-row: 2; }
body[data-panel="bottom"] #cardStats { grid-column: 4; grid-row: 3; }
body[data-panel="bottom"] .positions { max-height: none; }
body[data-panel="bottom"] .side .hint { display: none; }
body[data-panel="bottom"].panel-min .side { height: 38px; }
body[data-panel="bottom"].panel-min .side > .card { display: none; }
@media (max-width: 1250px) {
  body[data-panel="bottom"] .side { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1fr); }
  body[data-panel="bottom"] #cardOrd { grid-column: 2; grid-row: 3; }
  body[data-panel="bottom"] #cardPos { grid-row: 2; }
  body[data-panel="bottom"] #cardAccount { grid-column: 3; }
  body[data-panel="bottom"] #cardStats { grid-column: 3; }
}

/* 全画面＋浮かせる: チャートを画面いっぱいに、注文パネルはドラッグで動かせるウィンドウ */
body[data-panel="float"] .layout { grid-template-columns: minmax(0, 1fr); }
body[data-panel="float"] .chart-area { border-right: 0; }
body[data-panel="float"] .side {
  position: fixed; z-index: 40; width: 340px; max-height: calc(100vh - 70px); overflow-y: auto; padding: 0 8px 8px; gap: 8px;
  left: var(--float-x, auto); top: var(--float-y, 64px); right: auto;
  background: rgba(17, 23, 35, .97); border: 1px solid #2f3b52; border-radius: 12px; box-shadow: 0 12px 32px rgba(0, 0, 0, .55);
}
body[data-panel="float"] .panel-bar {
  display: flex; align-items: center; gap: 8px; position: sticky; top: 0; z-index: 1; margin: 0 -8px; padding: 6px 8px;
  background: #161e2c; border-bottom: 1px solid var(--line); cursor: move; user-select: none; -webkit-user-select: none; touch-action: none;
}
body[data-panel="float"] .float-tabs { display: flex; margin: 0; }
body[data-panel="float"] .side .card { margin: 0; }
body[data-panel="float"] .side .hint { display: none; }
body[data-panel="float"] .side[data-tab="pos"] #cardOrd,
body[data-panel="float"] .side[data-tab="pos"] #cardAccount,
body[data-panel="float"] .side[data-tab="pos"] #cardStats,
body[data-panel="float"] .side[data-tab="ord"] #cardPos,
body[data-panel="float"] .side[data-tab="ord"] #cardAccount,
body[data-panel="float"] .side[data-tab="ord"] #cardStats,
body[data-panel="float"] .side[data-tab="acc"] #cardPos,
body[data-panel="float"] .side[data-tab="acc"] #cardOrd { display: none; }
/* 小さくすると SELL/BUY だけ */
body[data-panel="float"].panel-min .side { width: 300px; overflow: hidden; }
body[data-panel="float"].panel-min .side > .card:not(.order-card), body[data-panel="float"].panel-min .float-tabs { display: none; }
body[data-panel="float"].panel-min #cardOrder > :not(.quote-row) { display: none; }
body[data-panel="float"].panel-min #cardOrder { padding: 6px; }
body[data-panel="float"].panel-min .trade-btn { min-height: 48px; padding: 6px 4px; }
body[data-panel="float"].panel-min .trade-btn .px { font-size: 16px; }
body.panel-dragging, body.panel-dragging * { cursor: grabbing !important; }
@media (max-width: 900px) { .panel-mode { display: none; } }

/* v0.12 調整 */
.panel-mode { align-items: center; }
.panel-mode .pm-label { font-size: 11px; color: var(--muted); padding: 0 4px 0 6px; }
.panel-mode button { padding: 4px 9px; }
.pb-title { white-space: nowrap; }
body[data-panel="bottom"] #cardOrder > .quote-row { column-span: all; margin-bottom: 8px; }
body[data-panel="float"] .side { max-height: calc(100vh - var(--float-y, 64px) - 8px); }
body[data-panel="float"].panel-min .side { width: 340px; }
@media (max-width: 1400px) { .brand { display: none; } }
body.embed #panelModeBtns { display: none !important; }

/* ---- v0.12.1 ---- */
/* 注文欄の左右のまとまり（右パネル・浮かせるときは今までどおり縦に並ぶ） */
.oc-left, .oc-right { display: contents; }
/* 下パネルの注文欄: SELL/BUYを小さく、左＝注文の種類・ロット、右＝SL/TP、全決済は下に1列 */
body[data-panel="bottom"] #cardOrder { column-count: auto; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px 12px; align-content: start; }
body[data-panel="bottom"] #cardOrder > .quote-row { grid-column: 1 / -1; margin: 0; grid-template-columns: 1fr 54px 1fr; }
body[data-panel="bottom"] #cardOrder .trade-btn { min-height: 38px; padding: 4px 6px; flex-direction: row; justify-content: center; gap: 10px; }
body[data-panel="bottom"] #cardOrder .trade-btn .px { font-size: 16px; }
body[data-panel="bottom"] #cardOrder .spread span { font-size: 13px; }
body[data-panel="bottom"] .oc-left, body[data-panel="bottom"] .oc-right { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
body[data-panel="bottom"] #cardOrder .seg { margin: 0; }
body[data-panel="bottom"] #cardOrder .field-row { margin: 0; }
body[data-panel="bottom"] #cardOrder .chips { margin: 0; }
body[data-panel="bottom"] #cardOrder .risk-info { margin: 0; }
body[data-panel="bottom"] #cardOrder .switch-row { margin: 0; }
body[data-panel="bottom"] #cardOrder .close-row { grid-column: 1 / -1; grid-template-columns: 1.3fr 1fr 1fr 1.8fr; }
body[data-panel="bottom"] #cardOrder .close-row .wide { grid-column: auto; }
body[data-panel="bottom"] #closeNote { display: none; }

/* サブウィンドウ（RSIなど）の上端をドラッグで高さを変える（TradingView風） */
.sub-resize { position: absolute; left: 0; right: 0; top: -4px; height: 9px; z-index: 6; cursor: ns-resize; touch-action: none; }
.sub-resize:hover, .sub-resize.dragging { background: linear-gradient(transparent 3px, rgba(47, 129, 247, .55) 3px, rgba(47, 129, 247, .55) 6px, transparent 6px); }
body.sub-dragging, body.sub-dragging * { cursor: ns-resize !important; user-select: none; -webkit-user-select: none; }

/* サインのアラート */
.buf-row .bell { padding: 2px 6px; opacity: .45; }
.buf-row .bell.on { opacity: 1; border-color: var(--accent); }

/* ヘッダーを1行に（PC）。入りきらない幅では横にスクロール */
@media (min-width: 901px) {
  .topbar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; gap: 8px; }
  .topbar::-webkit-scrollbar { display: none; }
  .topbar > :not(.spacer) { flex: none; }
  .topbar .status { flex: 0 1 auto; min-width: 0; }
  .topbar .status #statusText { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 240px; }
  .tf-group button { padding: 4px 7px; }
  .acct-sel { max-width: 170px; }
}
@media (min-width: 901px) and (max-width: 1700px) { .brand { display: none; } .panel-mode .pm-label { display: none; } }
@media (min-width: 901px) and (max-width: 1500px) { .topbar .status #statusText { display: none; } }
body[data-panel="bottom"] #cardOrder .close-row .ghost-btn { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 11px; padding: 6px 4px; }
body[data-panel="bottom"] #cardOrder .field-row label { white-space: nowrap; }

/* 自動ロック中の表示（発注にPINが必要） */
.lock-btn { color: #1a1200; background: #e3b341; border-color: #e3b341; font-weight: 600; white-space: nowrap; }
.lock-btn:hover { filter: brightness(1.08); }
