/* ==========================================================================
   Trade X — phones and tablets (mobile & iPad fix list, 2026-11-16).
   Linked after the inline <style> in index.html, so a rule here wins a tie on
   source order; selectors are raised only where an older rule is more specific.
   ========================================================================== */

/* ── M-02: a field under 16px makes iOS Safari zoom the page on tap ─────────
   Many fields set their size inline or with an ID selector, hence !important.
   Zoom is not blocked (no maximum-scale): that would cost accessibility. */
@media (max-width: 1024px), (pointer: coarse) {
  input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]),
  select, textarea { font-size: 16px !important; }
}

/* ── M-09: viewport-fit=cover puts the page under the notch and home bar ── */
body {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
.supfab { bottom: calc(22px + env(safe-area-inset-bottom)); right: calc(22px + env(safe-area-inset-right)); }

/* ── M-01 / M-06 / M-15: the header on a phone or portrait tablet ──────────
   One 56px row (logo, account, menu button). The menu row and the other
   controls open as a full-screen sheet from the button (navmenu.js), where each
   group is an accordion. The ticker is not shown here: it was a fourth sticky
   row on a 667px screen, and the markets page has the same prices. */
.navtog { display: none; }
@media (max-width: 860px) {
  .nav .ticker { display: none; }
  .nav .nav-in {
    flex-wrap: nowrap; height: 56px; row-gap: 0; padding-top: 0; padding-bottom: 0;
    padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right));
  }
  .nav .nav-in > .brand { order: 1; }
  .nav .nav-in .nav-act { order: 2; flex: 1 1 auto; min-width: 0; flex-wrap: nowrap; margin-left: auto; justify-content: flex-end; gap: 6px; }
  .nav .nav-in > .navtog { order: 3; display: grid; flex: 0 0 auto; margin-left: 6px; }
  .navtog .i-close { display: none; }
  .nav .nav-in .nav-links { display: none; }
  /* closed: the row keeps the account (or ログイン) only */
  html:not(.nav-open) .nav .nav-in .nav-act > :not(.sesswrap):not(.btn[data-view="login"]) { display: none !important; }
  .nav .sessmail { display: none; }
  .nav .sessbtn { padding: 4px; }

  html.nav-open, html.nav-open body { overflow: hidden; }
  html.nav-open .nav {
    position: fixed; inset: 0; height: 100vh; height: 100dvh; z-index: 200;
    overflow-y: auto; overscroll-behavior: contain; background: var(--bg);
  }
  html.nav-open .nav .nav-in {
    flex-wrap: wrap; height: auto; align-content: flex-start;
    padding-bottom: calc(28px + env(safe-area-inset-bottom));
  }
  html.nav-open .nav .nav-in > .brand { height: 56px; display: flex; align-items: center; }
  html.nav-open .nav .nav-in > .navtog { order: 2; margin-left: auto; align-self: center; }
  html.nav-open .navtog .i-open { display: none; }
  html.nav-open .navtog .i-close { display: block; }
  html.nav-open .nav .nav-in .nav-act {
    order: 3; flex: 1 0 100%; flex-wrap: wrap; justify-content: flex-start; margin-left: 0;
    gap: 8px; padding: 6px 0 14px; border-bottom: 1px solid var(--border);
  }
  html.nav-open .nav .nav-in .nav-act #langCur { display: inline; }
  html.nav-open .nav .nav-in .nav-links {
    display: flex; flex-direction: column; align-items: stretch; order: 4; flex: 1 0 100%;
    overflow: visible !important; gap: 0; height: auto;
  }
  html.nav-open .nav-links > a,
  html.nav-open .nav-links > .ndd > a {
    display: flex; align-items: center; justify-content: space-between; min-height: 52px;
    padding: 0 4px !important; font-size: 16px !important; border-bottom: 1px solid var(--border); border-radius: 0;
  }
  html.nav-open .nav-links .ndd-menu { padding: 4px 0 10px; background: transparent; }
  html.nav-open .nav-links .ndd-menu a { min-height: 44px; padding: 11px 12px; font-size: 15px; }
  html.nav-open .nav-links .ndd-menu a.sub { padding-left: 28px; font-size: 14px; }
}
/* a phone on its side: a sticky header would hold a third of 390px */
@media (max-height: 500px) and (orientation: landscape) {
  html:not(.nav-open) .nav { position: relative; }
}

/* ── M-03: User Center rows on a phone ─────────────────────────────────── */
@media (max-width: 600px) {
  .setrow .sb { flex: 1 1 calc(100% - 60px); min-width: 0; }
  .setrow .sv { flex: 1 1 100%; min-width: 0; text-align: left; padding-left: 50px; overflow-wrap: anywhere; }
  .conhead { padding: 20px 18px; gap: 14px; }
  .conhead > div { min-width: 0 !important; }
  .conhead > div:not(.av):first-of-type, .conhead > .av + div { flex: 1 1 calc(100% - 60px) !important; }
  .conhead .av { width: 44px; height: 44px; font-size: 18px; }
  .conhead .big { overflow-wrap: anywhere; }
  #view-user .conhead .big { font-size: 17px !important; line-height: 1.35; }   /* the email, not an amount */
}

/* ── M-14: the User / Asset / Order Center side menu became a one-row strip
   with half its tabs off-screen and no hint. Every tab shows, two per row. ── */
@media (max-width: 900px) {
  .conwrap .conside { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; overflow: visible; }
  .conwrap .conside button { width: auto; min-width: 0; min-height: 44px; justify-content: center; padding: 10px; white-space: normal; text-align: center; }
  .conwrap .conside button.sub { padding-left: 10px; }
}
/* 「セキュリティ設定」 wrapped onto two lines at 390px: the labels fit on one line with a tighter box */
@media (max-width: 480px) {
  .conwrap .conside button { padding: 10px 6px; gap: 6px; font-size: 13px; white-space: nowrap; }
  .conwrap .conside button svg { flex: none; width: 15px; height: 15px; }
}

/* ── M-07: on a phone the support button floats over the page's last lines; the page gets room to scroll them
   clear of it (button 52px + 22px gap) ── */
@media (max-width: 860px) {
  body { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
  body:has(#view-spot.on, #view-futures.on) { padding-bottom: 0; }
}

/* ── TX-33: one timeframe row. When the live chart (tvchart.js) is on, the
   older canvas toolbar above it drives a chart that is not shown. ───────── */
.xterm > div:has(> .xchart.tv-on) > .xchart-h { display: none; }

/* ── M-13: the hint names a mouse wheel ─────────────────────────────────── */
@media (pointer: coarse) { .tvbar .tvhint { display: none; } }

/* ── M-04: the trading screens on a phone ──────────────────────────────── */
.mtbar, .mtback { display: none; }
@media (max-width: 860px) {
  /* the pair and its stats on one swipeable row instead of three */
  .xterm .xbar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; gap: 16px; }
  .xterm .xbar::-webkit-scrollbar { display: none; }
  .xterm .xbar > * { flex: 0 0 auto; }
  .xterm .xbar > :first-child { cursor: pointer; display: flex; align-items: center; flex-wrap: nowrap; white-space: nowrap; }
  /* the chart toolbars on one swipeable row */
  .xterm .tvbar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .xterm .tvbar::-webkit-scrollbar { display: none; }
  .xterm .tvbar > * { flex: 0 0 auto; }
  .xterm .xbar > :first-child::after {
    content: ""; display: inline-block; flex: 0 0 auto; width: 7px; height: 7px; margin-left: 10px; margin-top: -4px;
    border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); opacity: .6;
  }
  /* the chart gets half the screen, never less than 280px */
  .xterm > div:nth-child(2) > .xchart,
  .xterm > .xt-chart > .xchart { flex: 0 0 auto; height: max(280px, 50vh); height: max(280px, 50dvh); min-height: 280px; }
  /* one side of the Spot ticket at a time; the bottom bar switches it */
  .xterm:not(.mt-sell) #spForm .xf-col:nth-child(2),
  .xterm.mt-sell #spForm .xf-col:nth-child(1) { display: none; }
  #spForm, #fuForm { scroll-margin-top: 66px; }

  #view-spot.on .mtbar, #view-futures.on .mtbar {
    display: flex; gap: 10px; position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
    padding: 10px max(14px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
    background: var(--surface); border-top: 1px solid var(--border);
  }
  .mtbar button { flex: 1; height: 46px; border-radius: 12px; font-weight: 700; font-size: 16px; color: #fff; border: 0; }
  .mtbar .buy { background: var(--up); }
  .mtbar .sell { background: var(--down); }
  #view-spot, #view-futures { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
  /* M-07: the support button sat on the ticket's 100% button; on these two
     screens support is reached from the menu (ヘルプセンター / お問い合わせ) */
  body:has(#view-spot.on, #view-futures.on) .supfab { display: none; }

  /* the pair list as a sheet, opened by tapping the pair name */
  .xterm.mt-pairs > .xt-pairs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 220; order: 0;
    max-height: 78vh !important; max-height: 78dvh !important; overflow-y: auto;
    border-radius: 16px 16px 0 0; box-shadow: 0 -12px 40px rgba(0, 0, 0, .35);
    padding-bottom: env(safe-area-inset-bottom); background: var(--surface);
  }
  .xterm.mt-pairs > .mtback { display: block; position: fixed; inset: 0; z-index: 210; background: rgba(0, 0, 0, .45); }
}

/* ── TX-34: from 1400px down the pair list spans the full width (term.css),
   but its rows kept the two-line layout of the 204px column: name on one line,
   price at the far end of the next. One line each: name, price, change. ──── */
@media (max-width: 1400px) {
  .xterm > .xt-pairs .prow { grid-template-columns: minmax(0, 1fr) auto 64px; grid-template-rows: auto; padding: 9px 14px; }
  .xterm > .xt-pairs .prow > b { grid-column: 1; grid-row: 1; }
  .xterm > .xt-pairs .prow > .px { grid-column: 2; grid-row: 1; text-align: right; }
  .xterm > .xt-pairs .prow > b ~ span:not(.px) { grid-column: 3; grid-row: 1; }
}

/* ── M-05: a landscape tablet. The chart column took what 100vh left after
   the toolbars (194px at 1180×820); the chart gets a floor instead. ─────── */
@media (max-width: 1400px) and (orientation: landscape) and (min-width: 861px) {
  .xterm > div:nth-child(2) > .xchart,
  .xterm > .xt-chart > .xchart { min-height: 360px; }
}
/* M-05 (part 2): at 1180×820 spot's row 1 was chart | book | 歩み値 and the order form wrapped below, its 買い
   button at y≈1,120 on an 820px screen. Futures already has the form in the third column; spot does the same and
   歩み値 moves below the chart, capped so the auto row stays a scrollable box. */
@media (max-width: 1400px) and (min-width: 1081px) and (orientation: landscape) {
  #view-spot .xterm > .xt-tape { order: 4; grid-column: 1 / -1; height: 340px; max-height: 340px; }
}

/* ── M-08: touch targets ───────────────────────────────────────────────── */
@media (pointer: coarse) {
  .qtabs button, .xchart-h button, .tvseg button, .pctbar button, .xf-tabs button,
  .xo-tabs button, .bk-tabs button, .mmtoggle button, .tabs button, .chip-btn { min-height: 40px; }
  .tvfs { min-width: 40px; min-height: 40px; }
  /* small icons get a 44px hit area around the same glyph */
  .favstar, [data-fav], .mtable td a[target="_blank"], .cx-open {
    display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px;
  }
  .cx-open { padding: 0 10px; }
  .prow .st { display: inline-flex; align-items: center; justify-content: center; min-width: 32px; min-height: 32px; margin: -6px 0 -6px -8px; }
}

/* ── M-12: a table box with more to see fades on that edge (tablehint.js) ── */
.xs-r { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent); }
.xs-l { -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 36px), transparent); mask-image: linear-gradient(to left, #000 calc(100% - 36px), transparent); }
.xs-r.xs-l { -webkit-mask-image: linear-gradient(to right, transparent, #000 36px, #000 calc(100% - 36px), transparent); mask-image: linear-gradient(to right, transparent, #000 36px, #000 calc(100% - 36px), transparent); }

.xs-tip { display: none; }
@media (max-width: 860px) {
  .xs-tip { display: block; margin: 0 0 6px; text-align: right; font-size: 12px; color: var(--text2); }
  .xs-tip[hidden] { display: none; }
}

/* the support panel above the home bar */
.suppanel { bottom: calc(86px + env(safe-area-inset-bottom)); }

/* ── M-11: wide tables scroll inside their own box ─────────────────────── */
@media (max-width: 860px) {
  #view-apidocs table { display: block; max-width: 100%; overflow-x: auto; }
}
