/* ===================== MOTIFX スタイル ===================== */
:root {
  --bg: #0b1220; --bg2: #111a2c; --panel: #141f33; --panel2: #1a2740; --line: #24334f;
  --text: #e6edf7; --sub: #8fa1bd; --muted: #5f7190;
  --buy: #ff4d5e; --sell: #3d8bff; --buy-bg: rgba(255,77,94,.14); --sell-bg: rgba(61,139,255,.14);
  --gold: #f5b83d; --ok: #2ecc8f; --warn: #ffb020; --danger: #ff4d5e;
  --accent: #f5b83d; --radius: 12px; --shadow: 0 6px 24px rgba(0,0,0,.35);
  --font: "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", system-ui, -apple-system, sans-serif;
  --mono: "SF Mono", "Roboto Mono", ui-monospace, Menlo, Consolas, monospace;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #eef2f8; --bg2: #ffffff; --panel: #ffffff; --panel2: #f4f7fb; --line: #dbe3ee;
  --text: #15202f; --sub: #5b6b82; --muted: #8a99ae;
  --buy: #e8283c; --sell: #1f6fe0; --buy-bg: rgba(232,40,60,.09); --sell-bg: rgba(31,111,224,.09);
  --shadow: 0 6px 20px rgba(20,40,80,.12);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.buy { color: var(--buy); } .sell { color: var(--sell); }
.pos { color: var(--buy); } .neg { color: var(--sell); }
.sub { color: var(--sub); } .muted { color: var(--muted); }
.small { font-size: 12px; } .tiny { font-size: 11px; }
.hidden { display: none !important; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

/* ---- ボタン・入力 ---- */
.btn { border: 1px solid var(--line); background: var(--panel2); border-radius: 10px; padding: 10px 14px; font-weight: 600; transition: transform .08s, filter .15s; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #1b1300; border-color: transparent; }
.btn.buy { background: var(--buy); color: #fff; border-color: transparent; }
.btn.sell { background: var(--sell); color: #fff; border-color: transparent; }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn.block { width: 100%; }
.input, select.input { width: 100%; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none; }
.input:focus { border-color: var(--accent); }
label.lbl { display: block; font-size: 12px; color: var(--sub); margin: 10px 0 4px; }
.seg { display: flex; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 3px; flex-wrap: wrap; }
.seg button { flex: 1; border: 0; background: transparent; padding: 7px 8px; border-radius: 8px; color: var(--sub); font-weight: 600; font-size: 12px; white-space: nowrap; }
.seg button.on { background: var(--panel2); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.25); }
.seg.buysell button.on.b { background: var(--buy); color: #fff; }
.seg.buysell button.on.s { background: var(--sell); color: #fff; }
.stepper { display: flex; align-items: stretch; }
.stepper button { width: 42px; border: 1px solid var(--line); background: var(--panel2); font-size: 18px; }
.stepper button:first-child { border-radius: 10px 0 0 10px; } .stepper button:last-child { border-radius: 0 10px 10px 0; }
.stepper .input { border-radius: 0; text-align: center; border-left: 0; border-right: 0; }

/* ---- 用語の「?」 ---- */
.q { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; border-radius: 50%; background: var(--panel2); border: 1px solid var(--line); color: var(--sub); font-size: 10px; font-weight: 700; cursor: pointer; margin-left: 4px; vertical-align: middle; flex: none; }
.q:hover { color: var(--accent); border-color: var(--accent); }

/* ---- 画面 ---- */
.screen { min-height: 100%; }
#screen-login, #screen-pending, #screen-loading { display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 32px 24px; text-align: center; box-shadow: var(--shadow); }
.login-card img.logo { width: 96px; height: 96px; border-radius: 22px; }
.login-card h1 { margin: 12px 0 4px; letter-spacing: .12em; font-size: 28px; }
.gbtn { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; background: #fff; color: #222; border: 1px solid #dadce0; border-radius: 999px; padding: 12px; font-weight: 600; margin-top: 20px; }
.uidbox { background: var(--bg2); border: 1px dashed var(--line); border-radius: 10px; padding: 12px; font-family: var(--mono); word-break: break-all; margin: 12px 0; user-select: all; }

/* ---- アプリ枠 ---- */
#screen-app { display: flex; flex-direction: column; min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px; padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top)); background: color-mix(in srgb, var(--bg2) 92%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: .12em; font-size: 16px; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.statusline { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 11px; color: var(--sub); min-width: 0; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); white-space: nowrap; }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.chip.live .dot { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.chip.ref .dot { background: var(--warn); }
.chip.closed .dot { background: var(--danger); }
.acct-mini { white-space: nowrap; margin-left: auto; text-align: right; font-size: 11px; color: var(--sub); line-height: 1.3; }
.acct-mini b { font-size: 14px; color: var(--text); }
.iconbtn { border: 1px solid var(--line); background: var(--panel2); border-radius: 10px; width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; flex: none; }

.banners { display: flex; flex-direction: column; }
.banner { padding: 8px 16px; font-size: 13px; display: flex; gap: 8px; align-items: center; border-bottom: 1px solid var(--line); }
.banner.ref { background: rgba(255,176,32,.14); color: var(--warn); }
.banner.closed { background: rgba(143,161,189,.12); color: var(--sub); }
.banner.offline { background: rgba(255,77,94,.16); color: var(--danger); }
.banner.mc { background: rgba(255,176,32,.2); color: var(--warn); font-weight: 700; }
.banner.info { background: rgba(61,139,255,.12); color: var(--sell); }

.pcnav { display: none; gap: 4px; padding: 8px 16px 0; }
.pcnav button { border: 0; background: transparent; color: var(--sub); padding: 8px 14px; border-radius: 10px 10px 0 0; font-weight: 700; }
.pcnav button.on { background: var(--panel); color: var(--text); }

main { flex: 1; padding: 12px; padding-bottom: 90px; width: 100%; max-width: 1600px; margin: 0 auto; }
.panel, .page { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: none; min-width: 0; }
.panel.show, .page.show { display: block; }
.page { max-width: 980px; margin: 0 auto; }
.ph { display: flex; align-items: center; gap: 8px; margin: -2px 0 10px; }
.ph h2 { font-size: 15px; margin: 0; }
.ph h2 small { font-weight: 400; color: var(--sub); font-size: 11px; margin-left: 6px; }

@media (max-width: 1023px) {
  .topbar { flex-wrap: wrap; gap: 6px 10px; padding: 6px 12px; }
  .statusline { order: 3; width: 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .statusline::-webkit-scrollbar { display: none; }
  main { padding: 8px; padding-bottom: 90px; }
}
footer.foot { text-align: center; padding: 12px 16px 96px; font-size: 11px; color: var(--muted); line-height: 1.7; }
footer.foot a { color: var(--sub); }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--bg2); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar button { border: 0; background: transparent; padding: 8px 0 7px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10px; font-weight: 700; }
.tabbar button svg { width: 22px; height: 22px; }
.tabbar button.on { color: var(--accent); }

/* ---- PCマルチパネル ---- */
@media (min-width: 1024px) {
  .tabbar { display: none; }
  .pcnav { display: flex; }
  footer.foot { padding-bottom: 16px; }
  main { padding-bottom: 12px; }
  main.trade { display: grid; grid-template-columns: 300px minmax(0, 1fr) 330px; grid-template-rows: auto 1fr; gap: 12px; align-items: start; }
  main.trade #p-rates { grid-column: 1; grid-row: 1 / span 2; }
  main.trade #p-chart { grid-column: 2; grid-row: 1; }
  main.trade #p-order { grid-column: 3; grid-row: 1 / span 2; }
  main.trade #p-positions { grid-column: 2; grid-row: 2; }
}

/* ---- レート一覧 ---- */
.rate { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; padding: 10px 8px; border-radius: 10px; cursor: pointer; border: 1px solid transparent; }
.rate:hover { background: var(--panel2); }
.rate.sel { border-color: var(--accent); background: var(--panel2); }
.rate .sym { font-weight: 800; font-size: 15px; }
.rate .chg { font-size: 11px; }
.px { text-align: center; border-radius: 8px; padding: 6px 8px; min-width: 84px; transition: background .5s; }
.px .l { font-size: 10px; font-weight: 700; opacity: .8; }
.px .v { font-family: var(--mono); font-weight: 700; font-size: 16px; }
.px.bid { background: var(--sell-bg); color: var(--sell); }
.px.ask { background: var(--buy-bg); color: var(--buy); }
.px .v small { font-size: 12px; }
.px .v big { font-size: 20px; }
.flash-up { animation: fu .7s; } .flash-down { animation: fd .7s; }
@keyframes fu { 0% { background: var(--buy); color: #fff; } 100% {} }
@keyframes fd { 0% { background: var(--sell); color: #fff; } 100% {} }
.spr { font-size: 10px; color: var(--sub); text-align: center; grid-column: 2 / span 2; margin-top: -4px; }

/* ---- チャート ---- */
.chartbox { position: relative; height: 380px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.subchart { position: relative; height: 110px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); margin-top: 6px; }
.subchart .tag, .chartbox .tag { position: absolute; left: 8px; top: 6px; z-index: 3; font-size: 11px; color: var(--sub); pointer-events: none; }
.chart-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 20px; color: var(--sub); z-index: 4; background: color-mix(in srgb, var(--panel) 75%, transparent); }
.chart-trade { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; margin-top: 10px; align-items: center; }
.chart-trade .btn { padding: 8px; }
.chart-trade .btn .v { display: block; font-family: var(--mono); font-size: 17px; }
.ind-toggles { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.ind-toggles label { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--sub); background: var(--panel2); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; cursor: pointer; }
.tv-credit { font-size: 10px; color: var(--muted); text-align: right; margin-top: 4px; }

/* ---- 注文 ---- */
.order-quote { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 6px; }
.order-quote .px { padding: 10px; }
.kv { display: flex; justify-content: space-between; font-size: 12px; padding: 4px 0; color: var(--sub); }
.kv b { color: var(--text); font-family: var(--mono); font-weight: 600; }
.note { font-size: 12px; color: var(--sub); background: var(--bg2); border-radius: 10px; padding: 8px 10px; margin-top: 8px; line-height: 1.6; }
.err { color: var(--danger); font-size: 12px; min-height: 16px; margin-top: 6px; }

/* ---- ポジション ---- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 8px; overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: 8px 12px; color: var(--sub); font-weight: 700; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.list { display: flex; flex-direction: column; gap: 6px; }
.card { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.card .top { display: flex; align-items: center; gap: 8px; }
.badge { display: inline-block; font-size: 10px; font-weight: 800; padding: 2px 6px; border-radius: 6px; }
.badge.buy { background: var(--buy); color: #fff; } .badge.sell { background: var(--sell); color: #fff; }
.badge.gray { background: var(--line); color: var(--sub); }
.badge.gold { background: var(--gold); color: #2b1d00; }
.pl { font-family: var(--mono); font-weight: 800; font-size: 16px; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; font-size: 13px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 12px; }
table.tbl th { text-align: left; color: var(--sub); font-weight: 600; padding: 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.tbl td { padding: 7px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tblwrap { overflow-x: auto; }

/* ---- 口座 ---- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.stat .l { font-size: 11px; color: var(--sub); display: flex; align-items: center; }
.stat .v { font-family: var(--mono); font-weight: 800; font-size: 18px; margin-top: 4px; }
.gauge { display: flex; flex-direction: column; align-items: center; }
.gauge svg { width: 220px; max-width: 100%; }

/* ---- マイページ ---- */
.menu { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 700px) { .menu { grid-template-columns: repeat(3, 1fr); } }
.menu button { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 16px 12px; text-align: left; font-weight: 700; display: flex; gap: 10px; align-items: center; }
.menu button .ic { font-size: 22px; }
.menu button small { display: block; font-weight: 400; color: var(--sub); font-size: 11px; }
.profile { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.avatar { width: 52px; height: 52px; border-radius: 50%; background: var(--panel2); border: 2px solid var(--accent); display: flex; align-items: center; justify-content: center; font-size: 28px; flex: none; }
.avatar.sm { width: 32px; height: 32px; font-size: 18px; border-width: 1px; }

/* ---- ランキング ---- */
.rank-row { display: grid; grid-template-columns: 36px 40px 1fr auto; gap: 8px; align-items: center; padding: 10px; border-radius: 10px; background: var(--panel2); border: 1px solid var(--line); }
.rank-row.me { border-color: var(--accent); }
.rank-no { font-weight: 900; font-size: 18px; text-align: center; color: var(--sub); }
.rank-no.r1 { color: #f5c542; } .rank-no.r2 { color: #c0c8d4; } .rank-no.r3 { color: #d48a4a; }

/* ---- ショップ・デスク ---- */
.desk-stage { background: linear-gradient(180deg, #1c2b45, #0f1a2c); border-radius: 14px; overflow: hidden; border: 1px solid var(--line); }
:root[data-theme="light"] .desk-stage { background: linear-gradient(180deg, #dfe8f5, #c7d5ea); }
.desk-stage svg { display: block; width: 100%; height: auto; }
.shop-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 700px) { .shop-grid { grid-template-columns: repeat(4, 1fr); } }
.item { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; display: flex; flex-direction: column; gap: 6px; }
.item .ic { font-size: 30px; height: 40px; display: flex; align-items: center; justify-content: center; }
.item.owned { border-color: var(--ok); }
.badges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (min-width: 700px) { .badges { grid-template-columns: repeat(6, 1fr); } }
.bdg { text-align: center; padding: 10px 4px; border-radius: 12px; background: var(--panel2); border: 1px solid var(--line); font-size: 11px; }
.bdg .ic { font-size: 28px; filter: grayscale(1) opacity(.35); }
.bdg.got .ic { filter: none; }
.bdg.got { border-color: var(--gold); }

/* ---- モーダル・トースト ---- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 100; display: flex; align-items: flex-end; justify-content: center; animation: fadein .15s; }
@media (min-width: 700px) { .modal-bg { align-items: center; } }
.modal { background: var(--panel); border: 1px solid var(--line); width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 18px 16px; padding-bottom: max(18px, env(safe-area-inset-bottom)); animation: slideup .2s; }
.modal.wide { max-width: 760px; }
@media (min-width: 700px) { .modal { border-radius: 18px; } }
.modal h3 { margin: 0 0 10px; font-size: 16px; }
.modal .actions { display: flex; gap: 8px; margin-top: 16px; }
.modal .actions .btn { flex: 1; }
@keyframes fadein { from { opacity: 0; } }
@keyframes slideup { from { transform: translateY(30px); opacity: 0; } }
#toast-root { position: fixed; left: 50%; transform: translateX(-50%); bottom: 84px; z-index: 200; display: flex; flex-direction: column; gap: 6px; width: min(92vw, 420px); pointer-events: none; }
@media (min-width: 1024px) { #toast-root { bottom: 20px; } }
.toast { background: var(--panel2); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 10px; padding: 10px 12px; box-shadow: var(--shadow); font-size: 13px; animation: slideup .2s; }
.toast.ok { border-left-color: var(--ok); } .toast.err { border-left-color: var(--danger); }

/* ---- 学習 ---- */
.lesson-list { display: grid; grid-template-columns: 1fr; gap: 8px; }
@media (min-width: 700px) { .lesson-list { grid-template-columns: repeat(2, 1fr); } }
.lesson-item { display: flex; align-items: center; gap: 10px; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; text-align: left; }
.lesson-item .no { width: 32px; height: 32px; border-radius: 50%; background: var(--bg2); display: flex; align-items: center; justify-content: center; font-weight: 800; flex: none; }
.lesson-item.done .no { background: var(--ok); color: #fff; }
.lesson { font-size: 15px; line-height: 1.8; }
.lesson h3 { font-size: 18px; margin: 0 0 8px; }
.lesson .big { font-size: 17px; font-weight: 700; }
.lesson .fig { background: var(--bg2); border-radius: 14px; padding: 12px; margin: 12px 0; text-align: center; border: 1px solid var(--line); }
.lesson .fig svg { width: 100%; max-width: 440px; height: auto; }
.lesson input[type=range] { width: 100%; accent-color: var(--accent); }
.lesson .fig .row > span, .lesson .fig .row > b { white-space: nowrap; }
.lesson .result { font-size: 16px; font-weight: 800; font-family: var(--mono); }
.quiz { background: var(--panel2); border-radius: 12px; padding: 12px; margin-top: 10px; }
.quiz .opts { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.quiz .opts button { text-align: left; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.quiz .opts button.right { border-color: var(--ok); background: rgba(46,204,143,.15); }
.quiz .opts button.wrong { border-color: var(--danger); background: rgba(255,77,94,.12); }
.progress { height: 6px; background: var(--bg2); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); }

/* 学習アニメーション */
@keyframes swapL { 0%, 15% { transform: translateX(0); } 45%, 60% { transform: translateX(150px); } 90%, 100% { transform: translateX(0); } }
@keyframes swapR { 0%, 15% { transform: translateX(0); } 45%, 60% { transform: translateX(-150px); } 90%, 100% { transform: translateX(0); } }
.anim-swapL { animation: swapL 4s ease-in-out infinite; }
.anim-swapR { animation: swapR 4s ease-in-out infinite; }
@keyframes rise { 0% { transform: translateY(30px); } 50% { transform: translateY(-30px); } 100% { transform: translateY(30px); } }
.anim-rise { animation: rise 5s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }
.anim-pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes drain { 0% { height: 140px; y: 30px; fill: #2ecc8f; } 60% { fill: #ffb020; } 85% { fill: #ff4d5e; } 100% { height: 0px; y: 170px; fill: #ff4d5e; } }
.anim-drain { animation: drain 6s ease-in infinite; }
@keyframes draw { from { stroke-dashoffset: 600; } to { stroke-dashoffset: 0; } }
.anim-draw { stroke-dasharray: 600; animation: draw 3s ease-out infinite alternate; }
@keyframes blink { 0%, 60% { opacity: 0; } 70%, 100% { opacity: 1; } }
.anim-blink { animation: blink 3s infinite alternate; }
@keyframes coin { 0% { transform: translateY(0); opacity: 0; } 20% { opacity: 1; } 100% { transform: translateY(-40px); opacity: 0; } }
.anim-coin { animation: coin 2s ease-out infinite; }
@media (prefers-reduced-motion: reduce) { * { animation-duration: 0s !important; animation-iteration-count: 1 !important; } }

/* チャート配色テーマ（ショップ） */
.dskline { stroke: var(--line); }
