/* Mobile layout layer. Loaded after the desktop and page-specific styles so
   responsive behavior stays isolated from the trading calculations. */
.mobile-nav-toggle { display: none; }
.mobile-nav-backdrop { display: none; }

@media (max-width: 768px) {
  html, body { width: 100%; max-width: 100%; overflow-x: hidden; }

  /* Keep the app bar compact. The navigation itself lives in a right drawer,
     so it must never create a second wide row in the page header. */
  .header {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    height: 54px;
    min-height: 54px;
    padding: max(8px, env(safe-area-inset-top)) 10px 8px;
  }
  .header-logo { flex: 1 1 auto !important; order: 0 !important; min-width: 0; width: auto; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .header-right { flex: 0 0 auto !important; order: 0 !important; min-width: 0; width: auto; margin-left: auto; gap: 4px; flex-wrap: nowrap; justify-content: flex-end; }
  .header-right .conn, .header-right #hdr-time { display: none; }
  .mobile-nav-toggle {
    display: grid; place-items: center; gap: 4px; width: 36px; min-width: 36px; height: 36px;
    padding: 8px; border: 1px solid var(--border2); border-radius: 10px;
    background: transparent; color: var(--txt); cursor: pointer;
  }
  .mobile-nav-toggle span { display: block; width: 16px; height: 2px; border-radius: 2px; background: currentColor; transition: transform .18s, opacity .18s; }
  .mobile-nav-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
  .mobile-nav-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
  .mobile-nav-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }
  .main-tabs {
    position: fixed;
    top: 54px; right: 0; bottom: 0; z-index: 1002;
    display: flex;
    flex-direction: column; align-items: stretch; gap: 0;
    /* 常见 APP 抽屉约占屏宽 70% 左右；保留内容可读宽度，但不再把页面
       压成只剩一条窄缝。 */
    width: min(78vw, 280px); min-width: 220px; height: auto; min-height: 0;
    margin: 0; padding: 12px 12px max(18px, env(safe-area-inset-bottom));
    background: var(--panel); border: 1px solid var(--border2); border-right: 0;
    box-shadow: -16px 0 38px rgba(0,0,0,.35);
    overflow-x: hidden; overflow-y: auto; scrollbar-width: thin;
    transform: translateX(105%); transition: transform .22s ease;
  }
  .header.mobile-nav-open { z-index: 1003; }
  .header.mobile-nav-open .main-tabs { transform: translateX(0); }
  .header.mobile-nav-open ~ .mobile-nav-backdrop {
    display: block; position: fixed; z-index: 1001; inset: 54px 0 0;
    background: rgba(0,0,0,.48);
  }
  .tab-btn { flex: 0 0 auto; width: 100%; min-height: 46px; padding: 0 12px; text-align: left; font-size: 13px; border-bottom: 1px solid var(--border); }
  .wallet-connect { max-width: 138px; min-height: 38px; padding: 6px 10px; overflow: hidden; text-overflow: ellipsis; }
  .theme-toggle { width: 36px; min-width: 36px; height: 36px; min-height: 36px; }

  /* Compact four-cell ticker: symbol on the first row, price/change/high/low
     on the second row. The volume field is intentionally omitted on phones. */
  .terminal-marketbar {
    display: grid;
    grid-template-columns: 1.25fr repeat(3, minmax(0, 1fr));
    align-items: center;
    gap: 5px;
    height: auto; min-height: 0;
    padding: 8px 10px 10px;
    overflow: visible;
  }
  .terminal-marketbar > .terminal-symbol {
    grid-column: 1 / -1;
    width: 100%; min-width: 0; padding: 0;
  }
  .terminal-marketbar > .ticker-stat { min-width: 0; padding: 2px 1px; }
  .terminal-marketbar > .ticker-stat span {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 9px;
  }
  .terminal-marketbar > .ticker-stat b {
    display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px;
  }
  .terminal-marketbar > .ticker-stat:nth-child(6),
  .terminal-marketbar > .ticker-stat:nth-child(7) { display: none; }
  .terminal-marketbar > .ticker-stat:nth-child(5) { display: block; }
  .ticker-price-stat select { max-width: 100%; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

  /* Stack terminal sections in a deliberate order, with shorter market-data
     panels so the order form becomes reachable without excessive scrolling. */
  .terminal-grid { display: flex; flex-direction: column; min-height: 0; }
  .terminal-grid > .terminal-chart { height: auto; min-height: 0; flex: 0 0 auto; border-right: 0; }
  #trade-chart { height: 340px; min-height: 280px; flex: 0 0 auto; }
  .terminal-toolbar { min-width: 0; }
  .chart-indicator-bar { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .chart-indicator-bar::-webkit-scrollbar { display: none; }
  .terminal-grid > .orderbook-panel {
    width: 100%; height: 318px; min-height: 318px; flex: 0 0 auto; border-right: 0;
  }
  .orderbook-panel > .terminal-section-title { height: 40px; min-height: 40px; }
  .book-row { height: 22px; }
  .terminal-grid > .order-entry {
    width: 100%; max-height: none; min-height: 0; flex: 0 0 auto;
    border-right: 0; border-left: 0; border-radius: 0;
  }
  .order-entry.aentry > .order-field { min-height: 42px; height: 42px; }
  .order-entry.aentry > .order-field input,
  .order-entry.aentry > .order-field select,
  .order-entry.aentry > .order-field .order-select-trigger { height: 40px; line-height: 40px; font-size: 16px; }
  .order-entry.aentry > .terminal-order-btn { min-height: 48px; height: 48px; font-size: 14px; }
  .order-entry.aentry > .amount-slider { height: 22px; margin-top: 12px; }
  .order-entry.aentry > .slider-labels button { min-height: 34px; height: 34px; font-size: 11px; }
  .terminal-grid > .terminal-bottom { width: 100%; min-height: 260px; flex: 0 0 auto; border-right: 0; }
  .terminal-bottom > .terminal-tabs { min-width: 0; height: 46px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .terminal-bottom > .terminal-tabs::-webkit-scrollbar { display: none; }
  .terminal-bottom > .terminal-tabs button { min-height: 46px; padding: 0 12px; font-size: 12px; white-space: nowrap; }
  .terminal-account-content { height: auto; min-height: 180px; max-height: none; overflow-x: auto; }

  /* Keep account-history tables horizontally scrollable: their columns are
     numerous and are more useful as a compact table than unlabeled cards. */
  .assets-record-block .account-history { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .assets-record-block .account-history table { display: table !important; width: max-content; min-width: 690px; }
  .assets-record-block .account-history tbody { display: table-row-group !important; }
  .assets-record-block .account-history tr { display: table-row !important; margin: 0; padding: 0; background: transparent; }
  .assets-record-block .account-history th,
  .assets-record-block .account-history td { display: table-cell !important; width: auto !important; min-height: 0; white-space: nowrap; text-align: right !important; }
  .assets-record-block .account-history td::before { content: none !important; }

  /* Shared mobile touch targets and prevention of accidental page-width growth. */
  button, select, input { max-width: 100%; }
  .panel, .portal-section, .portal-metrics, .assets-overview, .assets-main, .assets-distribution { max-width: 100%; }
  .portal-shell, .aim-page, .account-shell { width: 100%; min-width: 0; }
  .aim-table-wrap { width: 100%; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .aim-table-wrap table { width: max-content; min-width: 720px; }

  .portal-button, .assets-primary-action, .assets-secondary-action { min-height: 42px; }

  /* A 币交易页：顶部行情信息用两列紧凑展示，避免交易量/求购额度
     各占一整行把 K 线推到屏幕下方。 */
  .atrade-spot-price-strip {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
    padding: 12px !important;
  }
  .atrade-spot-price-strip > .atrade-spot-meta {
    width: 100%; min-width: 0 !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px 12px !important;
  }
  .atrade-spot-meta .meta-kv { min-width: 0; overflow: hidden; }
  .atrade-spot-meta .meta-kv span,
  .atrade-spot-meta .meta-kv b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .atrade-spot-meta .meta-kv b { font-size: 11px; }
  .atrade-chart-card .atrade-chart-host { flex: 1 1 auto; min-height: 0; height: auto !important; }

  .miner-page-hero { min-height: 150px; margin-bottom: 14px; padding: 14px; gap: 6px; }
  .miner-page-hero-copy { flex: 1 1 56%; }
  .miner-page-hero h2 { font-size: 18px; margin-top: 6px; }
  .miner-page-hero p { font-size: 10px; line-height: 1.5; }
  .miner-page-hero-tags { gap: 4px; margin-top: 10px; }
  .miner-page-hero-tags span { padding: 3px 6px; font-size: 9px; }
  .miner-page-hero img { width: 46%; max-height: 128px; }

  /* 矿池分档明细在窄屏改成带标签的双列卡片，避免表格被全局规则
     拆成一串没有语义的长文字。 */
  .pool-table-wrap { overflow: visible; padding: 0 8px; }
  .pool-table { display: block !important; min-width: 0; width: 100% !important; }
  .pool-table thead { display: none !important; }
  .pool-table tbody { display: block !important; width: 100% !important; }
  /* base.css 的通用 table:not(.no-mobile-stack) 规则优先级更高，需明确覆盖，
     否则 tr/td 会被重新变成 display:block，卡片就会退化为单列长串。 */
  .pool-table tr { display: grid !important; width: 100% !important; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 10px; padding: 12px; margin-bottom: 8px; border: 1px solid #203536; border-radius: 10px; background: #101a1c; }
  .pool-table td { display: flex !important; width: auto !important; flex-direction: column; align-items: flex-start; gap: 2px; min-height: 0; padding: 0; border: 0; text-align: left !important; font-size: 12px; }
  .pool-table td::before { content: attr(data-label); color: #81918e; font-size: 9px; }
  .pool-table td:first-child { grid-column: 1 / -1; width: auto !important; padding-bottom: 5px; border-bottom: 1px solid #203536; font-size: 14px; }
  .pool-table td:first-child::before { content: none; }

  /* 子导航在超窄屏保持容器宽度，按钮在内部横向滑动，不能把 body 撑宽。 */
  .earn-sub-tabs { display: flex !important; width: 100% !important; max-width: 100% !important; min-width: 0; }

  /* 激活套餐卡片：手机上只保留短文案，矿机图作为主视觉，避免标题逐字换行。 */
  .act-copy-full { display: none !important; }
  .act-copy-short { display: inline !important; }
  .earn-activation-v2-grid { grid-template-columns: 1fr !important; }
  .act-banner { padding: 14px 16px; }
  .act-banner-row { gap: 6px; }
  .act-plan-tag { padding: 4px 8px; font-size: 10px; }
  .act-banner-row .portal-chip { padding: 3px 6px; font-size: 9px; white-space: nowrap; }
  .act-miner-art { height: 84px; margin: 5px auto 0; }
  .act-miner-art img { width: min(100%, 230px); }
  .act-plan-title { margin: 9px 0 4px; font-size: 16px; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .act-bnb { font-size: 27px; }
  .act-arrow { gap: 8px; padding: 8px 0 4px; }
  .act-arrow strong { font-size: 13px; white-space: nowrap; }
  .act-arrow .arrow-box { width: 30px; height: 30px; flex: 0 0 30px; }
  .act-body { padding: 14px 16px 16px; gap: 12px; }
  .act-stats { gap: 8px 12px; }
  .act-stats .stat-item strong { font-size: 13px; white-space: nowrap; }
}

@media (max-width: 480px) {
  .header { height: 54px; min-height: 54px; padding-left: 10px; padding-right: 10px; }
  .header-right { gap: 3px; }
  .wallet-connect { max-width: 116px; padding-left: 8px; padding-right: 8px; }
  .tab-btn { padding-left: 11px; padding-right: 11px; }
  .terminal-marketbar { grid-template-columns: 1.2fr repeat(3, minmax(0, 1fr)); gap: 4px; }
  .terminal-symbol .coin-mark { width: 28px; height: 28px; }
  .terminal-symbol b { font-size: 14px; }
  .terminal-grid > .terminal-chart { min-height: 0; }
  #trade-chart { height: 300px; min-height: 260px; }
  .terminal-grid > .orderbook-panel { height: 300px; min-height: 300px; }
  .orderbook-panel .book-row { height: 20px; font-size: 9px; }
  .order-entry.aentry > .side-switch { margin-left: 10px; margin-right: 10px; }
  .order-entry.aentry > .order-type-tabs { margin-left: 10px; margin-right: 10px; }
  .order-entry.aentry > .order-field,
  .order-entry.aentry > label:not(.reduce-only-control) { margin-left: 10px; margin-right: 10px; }
  .order-entry.aentry > .quote-box { margin-left: 10px; margin-right: 10px; }
  .assets-header { flex-wrap: wrap; }
  .assets-header-actions { width: 100%; justify-content: flex-end; }
  .assets-quick-actions { width: 100%; }
  .assets-quick-actions > button { min-width: 0; }
  .portal-shell, .aim-page { padding-left: 10px; padding-right: 10px; }
  .aim-table-wrap table { min-width: 680px; }
  .atrade-terminal-grid { display: flex; flex-direction: column; gap: 10px; }
  .atrade-cell-chart { min-height: 0; }
  .atrade-cell-chart .atrade-chart-section { height: 300px !important; min-height: 260px !important; margin: 0 !important; }
}

@media (max-width: 360px) {
  .terminal-marketbar > .ticker-stat span { font-size: 8px; }
  .terminal-marketbar > .ticker-stat b { font-size: 10px; }
  .terminal-tabs button, .timeframe-tabs button { padding-left: 8px; padding-right: 8px; }
  .order-entry.aentry > .order-field { grid-template-columns: 50px minmax(0, 1fr) 48px; padding-left: 7px; padding-right: 7px; }
}

/* 质押数量弹窗：手机端保留完整输入框与底部安全间距，避免原生 prompt 顶在浏览器上方 */
@media (max-width: 768px) {
  .stake-modal { align-items: center; padding: 14px; }
  .stake-dialog { width: 100%; max-height: calc(100svh - 28px); border-radius: 16px; }
  .stake-dialog-head { padding: 16px 16px 13px; }
  .stake-dialog-head h3 { font-size: 18px; }
  .stake-dialog-body { padding: 14px 16px 8px; }
  .stake-dialog-actions { padding: 12px 16px 16px; }
  .stake-dialog-actions button { flex: 1; min-width: 0; }
  .stake-amount-field input { font-size: 20px; }
}
