/* Layout: one phone-width column — top bar, one scrolling screen, a P/L bar that appears with open positions, six-item tab bar. */
:root {
  color-scheme: dark;
  --bg: #07080e;          /* black-navy ground between rows */
  --panel: #151a30;       /* rows, bars */
  --panel-2: #1e2545;     /* raised controls, selected segment */
  --line: #2b3254;
  --fg: #f3f5fb;
  --muted: #9aa3c0;
  --accent: #46a4f0;      /* selected tab */
  --cta: #1f4699;         /* primary action */
  --buy: #e8365d;         /* Ask / 買, 陽線, plus */
  --sell: #2e8983;        /* Bid / 売 */
  --down: #5fd4c8;        /* 陰線, minus */
  --ink: #10131f;         /* text on white controls */
  --paper: #ffffff;       /* inputs */
  --font-ui: "Roboto", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", system-ui, sans-serif;
  --font-num: "Roboto Condensed", "Roboto", "Hiragino Sans", "Noto Sans JP", sans-serif;
  --gl: max(16px, env(safe-area-inset-left, 0px));
  --gr: max(16px, env(safe-area-inset-right, 0px));
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.4 var(--font-ui);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, p, dl, dd { margin: 0; }

#app {
  position: relative;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  font-variant-numeric: tabular-nums;
}
@media (min-width: 520px) { #app { border-inline: 1px solid var(--line); } }

/* ---------- top bar ---------- */
.topbar {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 56px;
  padding-left: var(--gl);
  padding-right: var(--gr);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.topbar h1 {
  position: absolute; left: 50%; transform: translateX(-50%);
  font-size: 1.2rem; font-weight: 500; letter-spacing: .04em; white-space: nowrap;
  pointer-events: none;
}
.tb-back { display: grid; place-items: center; width: 36px; height: 36px; margin-left: -8px; }
.demo-pill {
  font-size: .68rem; font-weight: 700; letter-spacing: .12em;
  color: var(--muted); border: 1px solid var(--muted); border-radius: 4px; padding: 1px 6px;
}
.tb-asset { margin-left: auto; text-align: right; line-height: 1.15; }
.tb-asset small { display: block; font-size: .62rem; color: var(--muted); }
.tb-asset b { font-family: var(--font-num); font-size: .98rem; }

/* ---------- screens ---------- */
.screens { position: relative; flex: 1; min-height: 0; }
.screen { position: absolute; inset: 0; overflow-y: auto; overscroll-behavior: contain; }
.screen.col { display: flex; flex-direction: column; overflow: hidden; }
.scrollcol { flex: 1; min-height: 0; overflow-y: auto; }

.fineprint { padding: 14px var(--gr) 22px var(--gl); font-size: .72rem; color: var(--muted); }
.sec {
  padding: 12px var(--gr) 10px var(--gl);
  font-size: 1rem; font-weight: 700; background: var(--bg);
}

/* ---------- market ---------- */
.onboard {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px var(--gr) 12px var(--gl);
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
}
.onboard strong { display: block; }
.onboard span { font-size: .78rem; color: var(--muted); }
.btn-primary { padding: 9px 18px; border-radius: 6px; font-weight: 700; color: #fff; background: var(--cta); }
.colhead, .rate {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr) 40px minmax(0, 1fr);
  column-gap: 6px;
  padding-left: var(--gl);
  padding-right: var(--gr);
}
.colhead { padding-block: 9px; color: var(--muted); font-size: .92rem; background: var(--panel); text-align: center; }
.colhead span:first-child { text-align: left; }
.rate {
  width: 100%; align-items: center; text-align: left;
  padding-block: 9px 10px; margin-top: 3px; background: var(--panel);
}
.rate:active { background: var(--panel-2); }
.r-pair { display: flex; flex-direction: column; align-items: center; gap: 5px; font-size: .8rem; font-weight: 700; text-align: center; line-height: 1.15; }
.r-side { min-width: 0; }
.r-side .px { text-align: center; }
.r-kv { display: flex; justify-content: space-between; gap: 6px; font-size: .8rem; color: var(--muted); white-space: nowrap; }
.r-kv span:last-child { color: var(--fg); font-family: var(--font-num); }
.r-kv .up, .up { color: var(--buy) !important; }
.r-kv .dn, .dn { color: var(--down) !important; }
.r-spr, .spr {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%;
  border: 1.5px solid var(--fg); font-family: var(--font-num); font-size: .9rem; background: var(--panel);
}

.px { font-family: var(--font-num); font-weight: 700; white-space: nowrap; line-height: 1.1; transition: color .25s; }
.px .a { font-size: 1.1rem; }
.px .b { font-size: 1.75rem; }
.px .c { font-size: 1.2rem; }
.px[data-dir="u"] { color: #ff8aa2; }
.px[data-dir="d"] { color: #8ee6dc; }

.flagpair { position: relative; display: inline-block; width: 34px; height: 26px; flex: none; }
.flagpair svg { position: absolute; width: 24px; height: 16px; border-radius: 3px; box-shadow: 0 0 0 1px rgba(255,255,255,.35); }
.flagpair svg:first-child { left: 0; top: 0; }
.flagpair svg:last-child { right: 0; bottom: 0; }

/* ---------- pair bar (chart / order / speed) ---------- */
.pairbar {
  flex: none; display: grid; grid-template-columns: 64px 1fr 64px; align-items: center; gap: 6px;
  padding: 8px var(--gr) 8px var(--gl);
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.pb-btn { height: 40px; border-radius: 6px; background: var(--panel-2); font-size: .85rem; font-weight: 700; }
.pb-btn.primary { background: var(--cta); font-size: 1rem; }
.pb-mid { min-width: 0; text-align: center; }
.pairpick { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; }
.pairsel {
  appearance: none; -webkit-appearance: none;
  min-width: 0; max-width: 100%;
  font: 700 1.25rem var(--font-ui); color: var(--fg);
  background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23f3f5fb' stroke-width='2'/%3E%3C/svg%3E") no-repeat right 2px center / 12px 8px;
  border: 0; padding: 2px 20px 2px 0; text-overflow: ellipsis;
}
.pairsel option { color: var(--fg); background: var(--panel); }
.hl { font-family: var(--font-num); font-size: .86rem; white-space: nowrap; color: var(--fg); }
.hl i { font-style: normal; font-weight: 700; margin-right: 3px; }
.hl .h { color: var(--buy); } .hl .l { color: var(--down); margin-left: 8px; } .hl .c { margin-left: 8px; font-family: var(--font-ui); font-size: .78rem; }

/* ---------- chart ---------- */
.tfbar { flex: none; display: flex; gap: 6px; padding: 6px var(--gr) 6px var(--gl); background: var(--panel); border-bottom: 1px solid var(--line); }
.tfbar button { flex: 1; height: 34px; border-radius: 5px; background: var(--panel-2); color: var(--muted); font-size: .9rem; }
.tfbar button.on { color: var(--accent); box-shadow: inset 0 0 0 1.5px var(--accent); }
.chartwrap { position: relative; flex: 1; min-height: 120px; background: #000; }
.chartwrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.ohlc { position: absolute; left: 8px; top: 5px; right: 70px; font-family: var(--font-num); font-size: .76rem; line-height: 1.45; color: var(--fg); pointer-events: none; }
.ohlc .t { color: var(--muted); }
.ohlc b { font-weight: 500; margin-left: 7px; }
.ohlc .ma5 { color: #b8b23a; } .ohlc .ma25 { color: #e060c0; } .ohlc .ma75 { color: #3f7cf0; }
.posstrip, .sp-pos {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px var(--gr) 8px var(--gl); background: var(--panel); border-top: 1px solid var(--line);
  font-size: .86rem;
}
.posstrip b, .sp-pos b { font-family: var(--font-num); font-size: 1.25rem; margin-left: auto; white-space: nowrap; }
.posstrip .who, .sp-pos .who { white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.posstrip small, .sp-pos small { color: var(--muted); font-family: var(--font-num); font-size: .86rem; }
.sp-pos { border-bottom: 1px solid var(--line); color: var(--muted); min-height: 44px; }
.sp-pos .who { color: var(--fg); }
.tag { display: inline-block; min-width: 1.7em; padding: 0 5px; border-radius: 3px; font-size: .78rem; font-weight: 700; text-align: center; color: #fff; }
.tag.buy { background: var(--buy); } .tag.sell { background: var(--sell); }
.btn-line { padding: 7px 14px; border-radius: 6px; border: 1px solid var(--muted); font-size: .86rem; font-weight: 700; white-space: nowrap; }
.btn-line.danger { border-color: var(--buy); color: #ff8aa2; }

/* ---------- order ---------- */
.quote2 { position: relative; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 8px var(--gr) 8px var(--gl); background: var(--bg); }
.quote2 button { border-radius: 5px; padding: 6px 8px 8px; color: #fff; text-align: center; transition: filter .15s, transform .08s; }
.quote2 button:active { transform: scale(.97); filter: brightness(1.25); }
.quote2 small { display: block; font-size: .9rem; font-weight: 700; opacity: .95; }
.quote2 .px .a { font-size: 1.5rem; } .quote2 .px .b { font-size: 2.3rem; } .quote2 .px .c { font-size: 1.6rem; }
.quote2 .px[data-dir] { color: #fff; }
.q-sell { background: var(--sell); } .q-buy { background: var(--buy); }
.quote2 .spr { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: var(--bg); border-color: var(--bg); width: 42px; height: 42px; font-size: 1rem; pointer-events: none; }
.quote2.dim .q-sell, .quote2.dim .q-buy { opacity: .55; }
.quote2.dim .sel { opacity: 1; box-shadow: inset 0 0 0 2px #fff; }
.quote2.tall { flex: none; }
.quote2.tall button { padding-block: 16px 20px; }

.otabs { display: flex; background: var(--panel); border-bottom: 1px solid var(--line); }
.otabs button { flex: 1; min-height: 48px; font-weight: 700; font-size: .92rem; line-height: 1.05; color: var(--muted); border-bottom: 2px solid transparent; }
.otabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
[aria-disabled="true"] { opacity: .55; }

.frow {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px var(--gr) 10px var(--gl); margin-bottom: 3px; background: var(--panel); min-height: 60px;
}
.frow.wrap { flex-wrap: wrap; }
.frow > label, .frow > .lbl { color: var(--muted); font-size: .95rem; white-space: nowrap; }
.frow > span:first-child:not(.lbl) { font-size: .86rem; color: var(--muted); min-width: 0; }
.seg { display: flex; flex: 1; max-width: 300px; padding: 3px; border-radius: 999px; background: #2a3050; }
.seg button { flex: 1; height: 40px; border-radius: 999px; font-weight: 700; color: #d5d9ea; white-space: nowrap; }
.seg button.on[data-side="buy"] { background: var(--buy); color: #fff; }
.seg button.on[data-side="sell"] { background: var(--sell); color: #fff; }
.seg.white button.on { background: var(--paper); color: var(--ink); }
.stepper { display: flex; align-items: center; flex: 1; max-width: 300px; height: 46px; padding: 4px; border-radius: 6px; background: var(--paper); color: var(--ink); }
.stepper button { width: 40px; height: 100%; border-radius: 4px; background: #eef0f5; color: var(--ink); font-size: 1.4rem; line-height: 1; }
.stepper button:active { background: #d5d9e6; }
.stepper input { flex: 1; min-width: 0; width: 40px; border: 0; background: transparent; color: var(--ink); font: 700 1.2rem var(--font-num); text-align: right; padding: 0 6px; }
.stepper .unit { color: #8a8fa3; font-family: var(--font-num); padding-right: 8px; white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px var(--gr) 8px var(--gl); background: var(--panel); margin-bottom: 3px; }
.chips button { padding: 6px 12px; border-radius: 999px; background: var(--panel-2); font-size: .84rem; font-weight: 700; }
.chips button:active { background: var(--cta); }
.chips-note { margin-left: auto; font-size: .8rem; color: var(--muted); }
.chips-note b { color: var(--fg); font-family: var(--font-num); font-size: .95rem; }
.kv { padding: 10px var(--gr) 12px var(--gl); background: var(--panel); }
.kv > div { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; }
.kv dt { color: var(--muted); }
.kv dd { font-family: var(--font-num); font-size: 1.05rem; text-align: right; }
.kv.big > div { padding: 9px 0; border-bottom: 1px solid var(--line); }
.cta-wrap { flex: none; padding: 12px var(--gr) 14px var(--gl); background: var(--bg); }
.cta-wrap.slim { padding-block: 6px 10px; }
.cta { display: block; width: 100%; max-width: 340px; margin: 0 auto; height: 54px; border-radius: 6px; background: var(--cta); color: #fff; font-size: 1.15rem; font-weight: 700; letter-spacing: .04em; }
.cta:active { filter: brightness(1.2); }
.cta.ghost { background: transparent; box-shadow: inset 0 0 0 1.5px var(--muted); color: var(--fg); }
.cta[disabled] { opacity: .4; }
.cta-wrap.slim .cta { height: 44px; font-size: .95rem; }

/* ---------- account / inquiry ---------- */
.subtabs { position: sticky; top: 0; z-index: 2; display: grid; grid-template-columns: repeat(4, 1fr); background: var(--panel); border-bottom: 1px solid var(--line); }
.subtabs.two { grid-template-columns: repeat(2, 1fr); }
.subtabs button { min-height: 48px; padding: 0 2px; font-weight: 700; font-size: .9rem; color: var(--muted); border-bottom: 2px solid transparent; }
.subtabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
.hero-num { padding: 18px var(--gr) 16px var(--gl); margin: 8px 0 3px; background: var(--panel); }
.hero-num small { display: block; color: var(--muted); font-size: .86rem; }
.hero-num b { display: block; font-family: var(--font-num); font-size: 2.2rem; line-height: 1.2; overflow-wrap: anywhere; }
.hero-num b .u { font-size: 1rem; font-weight: 500; margin-left: 3px; color: var(--muted); }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px var(--gr) 11px var(--gl); margin-bottom: 3px; background: var(--panel); }
.list-row .main { min-width: 0; }
.list-row .main strong { display: flex; align-items: center; gap: 6px; font-size: .95rem; flex-wrap: wrap; }
.list-row .main small { display: block; color: var(--muted); font-size: .78rem; font-family: var(--font-num); margin-top: 2px; }
.list-row .amt { text-align: right; white-space: nowrap; }
.list-row .amt b { display: block; font-family: var(--font-num); font-size: 1.2rem; }
.list-row .amt .btn-line { margin-top: 5px; padding: 5px 14px; }
.empty { padding: 44px var(--gr) 44px var(--gl); text-align: center; color: var(--muted); }
.empty .btn-line { display: inline-block; margin-top: 14px; }
.bar-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px var(--gr) 10px var(--gl); }
.bar-actions span { color: var(--muted); font-size: .86rem; }
.money-input { display: flex; align-items: center; flex: 1; max-width: 300px; height: 48px; padding: 0 12px; border-radius: 6px; background: var(--paper); }
.money-input input { flex: 1; min-width: 0; width: 60px; border: 0; background: transparent; color: var(--ink); font: 700 1.3rem var(--font-num); text-align: right; }
.money-input span { color: #8a8fa3; margin-left: 6px; }
.hint { padding: 8px var(--gr) 0 var(--gl); font-size: .8rem; color: var(--muted); }
.switch { appearance: none; -webkit-appearance: none; width: 52px; height: 30px; border-radius: 999px; background: #3a4166; position: relative; cursor: pointer; transition: background .2s; margin: 0; flex: none; }
.switch::after { content: ""; position: absolute; left: 3px; top: 3px; width: 24px; height: 24px; border-radius: 50%; background: #c9cee0; transition: transform .2s, background .2s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(22px); background: #fff; }
.confirm-inline { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px var(--gr) 12px var(--gl); background: #2a1620; margin-bottom: 3px; }
.confirm-inline span { flex: 1 1 100%; }
.about { padding: 4px var(--gr) 28px var(--gl); color: var(--muted); font-size: .86rem; display: grid; gap: 8px; max-width: 34em; }
.about b { color: var(--fg); }

/* ---------- P/L bar & tab bar ---------- */
.plbar { flex: none; display: flex; align-items: center; gap: 10px; padding: 6px var(--gr) 6px var(--gl); background: var(--panel); border-top: 1px solid var(--line); }
.plbar-main { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 10px; text-align: left; }
.plbar small { color: var(--muted); font-size: .78rem; white-space: nowrap; }
.plbar b { font-family: var(--font-num); font-size: 1.3rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plbar-close { flex: none; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--muted); font-size: .86rem; font-weight: 700; }

.tabbar { flex: none; display: grid; grid-template-columns: repeat(6, 1fr); padding: 4px max(2px, env(safe-area-inset-right, 0px)) 4px max(2px, env(safe-area-inset-left, 0px)); background: var(--panel); border-top: 1px solid var(--line); }
.tabbar button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 5px 0 4px; color: var(--muted); font-size: .64rem; font-weight: 700; white-space: nowrap; }
.tabbar svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tabbar svg.dots { fill: currentColor; stroke: none; }
.tabbar button.on { color: var(--accent); }

/* ---------- sheet ---------- */
.sheet-wrap { position: absolute; inset: 0; z-index: 20; display: flex; align-items: flex-end; background: rgba(0,0,0,.6); }
.sheet { width: 100%; padding: 18px var(--gr) calc(18px + env(safe-area-inset-bottom, 0px)) var(--gl); border-radius: 16px 16px 0 0; background: var(--panel); animation: rise .22s ease-out; }
.sheet h2 { font-size: 1.1rem; margin-bottom: 6px; }
.sheet .kv { padding-inline: 0; }
.sheet-btns { display: grid; grid-template-columns: 1fr 1.5fr; gap: 10px; margin-top: 14px; }
.sheet-btns.one { grid-template-columns: 1fr; }
.sheet-btns .cta { max-width: none; }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }

/* ---------- toasts ---------- */
#toasts { position: absolute; left: 0; right: 0; top: 64px; z-index: 50; display: grid; justify-items: center; gap: 6px; padding: 0 var(--gr) 0 var(--gl); pointer-events: none; }
.toast { max-width: 100%; padding: 9px 16px; border-radius: 8px; background: rgba(30,37,69,.97); box-shadow: 0 4px 18px rgba(0,0,0,.5), inset 0 0 0 1px var(--line); font-size: .9rem; animation: toast 3.1s ease forwards; }
.toast.warn { box-shadow: 0 4px 18px rgba(0,0,0,.5), inset 0 0 0 1px var(--buy); }
@keyframes toast { from { transform: translateY(-12px); opacity: 0; } 8%, 88% { transform: none; opacity: 1; } to { opacity: 0; } }

@media (max-width: 360px) {
  body { font-size: 14px; }
  .colhead, .rate { grid-template-columns: 70px minmax(0, 1fr) 36px minmax(0, 1fr); column-gap: 4px; }
  .px .b { font-size: 1.5rem; }
  .pairsel { font-size: 1.05rem; }
}
@media (max-height: 620px) {
  .quote2.tall button { padding-block: 8px 10px; }
  .frow { min-height: 50px; padding-block: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  .sheet { animation-duration: .01s; }
  .toast { animation: none; }
}

/* Short screens: the speed-order column scrolls instead of clipping its last button. */
#s-speed { overflow-y: auto; }
#s-speed .chartwrap { flex: 1 0 130px; }
