/* ==========================================================================
   Mobile / tablet responsive layer (public site only).
   Loaded after styles.css + theme-bg.css. Desktop (>=1100px) is untouched
   except where a rule is scoped to a max-width query.
   ========================================================================== */

/* Never allow sideways scrolling on the page itself. */
html, body { max-width: 100%; overflow-x: clip; }
img, svg, canvas, video, iframe { max-width: 100%; }

/* ---------- Tablet and below: rail becomes a compact top strip ---------- */
@media (max-width: 1099px) {
  .left-rail {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 10px;
    position: relative;
  }
  .left-rail .burn-widget { position: static; }
  .left-rail .burn-widget-toggle,
  .left-rail .mcap-widget-toggle { height: 100%; min-height: 56px; }
  .left-rail .burn-panel {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 6px);
    margin-top: 0;
    z-index: 50;
    max-height: min(420px, 60vh);
  }
  .burn-list a { min-height: 44px; justify-content: center; }

  /* Preset comparison table: scroll inside its panel, with a visible cue. */
  #mm-how .panel { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
  .preset-compare th:first-child { position: sticky; left: 0; background: var(--bg-card); z-index: 1; }

  /* Charts always fit the column. */
  .preset-charts, .preset-explain-charts, .chart-wrap, .spark-fallback, .split-bars, .split-bar { min-width: 0; max-width: 100%; }
  .preset-charts svg, .preset-explain-charts svg, .spark-fallback svg, .chart-wrap svg { width: 100%; height: auto; }

  /* Grids: let children shrink instead of pushing the page wider. */
  .partner-grid > *, .stats-grid > *, .split-row > *, .mm-how-grid > *,
  .preset-explain-grid > *, .dash-grid > *, .how-steps > *, .pair-steps li > div { min-width: 0; }

  /* Small inline links get a comfortable tap area without changing the look. */
  .pair-callout p a, .section-head p a, .faq a, .risk-banner a {
    display: inline-block;
    padding: 12px 0;
    margin: -12px 0;
  }
}

/* ---------- Phones (<= 640px) ---------- */
@media (max-width: 640px) {
  :root { --radius: 14px; }
  body { font-size: 15px; line-height: 1.55; }
  .wrap { width: calc(100% - 28px); }

  section { padding: 40px 0; }
  .hero { padding: 36px 0 36px; }
  h1 { font-size: clamp(1.95rem, 10vw, 2.6rem); line-height: 1.04; }
  h2, .section-head h2 { font-size: 1.4rem; line-height: 1.15; }
  h3 { font-size: 1rem; }
  .hero-sub { font-size: 0.98rem; }
  .section-head { flex-direction: column; align-items: stretch; gap: 8px; margin-bottom: 18px; }
  .section-head p { font-size: 0.92rem; }
  .eyebrow { font-size: 0.68rem; letter-spacing: 0.1em; }
  .hero-actions { gap: 10px; }
  .hero-actions .btn { flex: 1 1 140px; }

  .pair-callout { margin-top: 28px; padding: 16px 14px; }
  .pair-callout h2 { font-size: 1.2rem; }
  .pair-steps li { padding: 12px; gap: 10px; }

  .split-card, .stat-card, .panel, .partner-card { padding: 16px; }
  .split-card .pct { font-size: 1.9rem; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card .v { font-size: 1.15rem; overflow-wrap: anywhere; }
  .stat-card .k { font-size: 0.72rem; }

  /* Treasury / CA bar: compact, no overflow, address truncates. */
  .address-bar-inner { gap: 0 10px; padding: 2px 0; }
  .addr-item { gap: 6px 8px; min-width: 0; }
  .addr-item[data-role="ca"]:has(.addr-actions[hidden]) { min-height: 30px; }
  .addr-label { font-size: 0.62rem; letter-spacing: 0.06em; }
  .addr-short {
    font-size: 0.76rem;
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .addr-actions { gap: 4px; margin-left: auto; flex-shrink: 0; }
  .address-bar .icon-btn { padding: 0 10px; font-size: 0.74rem; min-width: 44px; min-height: 44px; }

  /* Rail strip: tighter cards. */
  .left-rail .burn-widget-toggle,
  .left-rail .mcap-widget-toggle { gap: 8px; padding: 8px 10px; border-radius: 14px; }
  .left-rail .mcap-icon, .left-rail .mcap-icon-svg { width: 24px; height: 24px; }
  .left-rail .burn-flame, .left-rail .burn-flame-svg { width: 22px; height: 30px; }
  .left-rail .burn-label { font-size: 0.6rem; letter-spacing: 0.05em; line-height: 1.25; }
  .left-rail .burn-value { font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .left-rail .burn-empty, .left-rail .mcap-updated { font-size: 0.64rem; }

  /* ----- Data tables collapse into cards ----- */
  .table-wrap { border: 0; background: transparent; overflow: visible; border-radius: 0; }
  .table-wrap table, .table-wrap tbody { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 14px;
    padding: 12px 14px;
    margin-bottom: 10px;
    background: var(--bg-card);
    border: 1px solid var(--line);
    border-radius: 12px;
  }
  .table-wrap td {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 2px;
    padding: 0;
    border: 0;
    min-width: 0;
    font-size: 0.86rem;
    overflow-wrap: anywhere;
  }
  .table-wrap td::before {
    content: attr(data-label);
    font-family: var(--mono);
    font-size: 0.62rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
  }
  .table-wrap td:not([data-label])::before, .table-wrap td.empty::before { content: none; }
  .table-wrap td.empty, .table-wrap td[colspan] { grid-column: 1 / -1; text-align: center; padding: 6px 0; }
  .table-wrap td a { min-height: 44px; display: inline-flex; align-items: center; align-self: flex-start; word-break: break-all; }
  .table-wrap td .badge { align-self: flex-start; }

  /* Long tables: show the first rows, rest behind a button (mobile.js). */
  .table-wrap.mw-collapsed tbody tr:nth-child(n+7) { display: none; }
  .mw-show-all {
    display: flex;
    width: 100%;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    margin-top: 2px;
    border-radius: 12px;
    border: 1px solid var(--line-strong);
    background: var(--bg-raised, #121318);
    color: var(--text);
    font-size: 0.9rem;
  }

  /* Split bars: legend wraps cleanly. */
  .split-bar-head { flex-wrap: wrap; gap: 4px 10px; }
  .split-bar-head h3 { font-size: 0.92rem; }
  .split-legend { flex-wrap: wrap; gap: 6px 12px; font-size: 0.74rem; }

  /* Partner cards: buttons wrap to full-width tappable rows. */
  .partner-card .btn, .partner-actions .btn { flex: 1 1 auto; }
  .chart-wrap iframe { height: 220px; }

  .preset-facts { grid-template-columns: 1fr 1fr; gap: 8px; }
  .faq summary, details > summary { min-height: 44px; display: flex; align-items: center; }

  .mobile-cta { padding-left: 14px; padding-right: 14px; }
  .mobile-cta .btn { font-size: 0.92rem; }
  footer { font-size: 0.78rem; }
}

/* ---------- Very small phones (<= 380px) ---------- */
@media (max-width: 380px) {
  .wrap { width: calc(100% - 24px); }
  .stats-grid { grid-template-columns: 1fr; }
  .table-wrap tr { padding: 12px; gap: 8px 10px; }
  .left-rail .burn-value { font-size: 0.92rem; }
  .left-rail .mcap-icon, .left-rail .mcap-icon-svg { width: 20px; height: 20px; }
  .nav-right .btn, .nav-right .btn-sm { padding-left: 12px; padding-right: 12px; }
}

/* ---------- Touch screens of any width (e.g. iPad landscape) ---------- */
@media (pointer: coarse) {
  .nav-links a, .nav-more-btn, .nav-right .btn, .icon-btn, .btn-sm { min-height: 44px; }
  .icon-btn { min-width: 44px; }
}

/* Tablets: treasury + CA share one row in the address bar. */
@media (min-width: 641px) and (max-width: 1099px) {
  .addr-item { flex: 0 1 auto; }
  .address-bar-inner { gap: 4px 28px; }
}
