/* Mobile interaction review. Load after iphone-v10.css. */
#app:focus { outline: none; }
@media (max-width: 640px) {
  /* Keep the mounted back row at the height used by the sticky prize rail. */
  .route-back-shell .terminal-toolbar {
    height: var(--route-bar-height);
    min-height: var(--route-bar-height);
    flex-wrap: nowrap;
    align-items: center;
  }
  .route-back-shell .terminal-toolbar .back-bar {
    flex: 1 1 auto;
    flex-wrap: nowrap;
  }
  .route-back-shell .terminal-mode { display: none; }
  .route-back-shell .back-button {
    min-width: 0;
    flex: 0 1 auto;
    max-height: var(--route-bar-height);
    text-align: left;
    line-height: 1.3;
    overflow-wrap: anywhere;
  }
  .route-back-shell .back-bar > span:last-child {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  /* A translated navigation label may take two lines within the same safe area. */
  .mobile-nav button {
    padding: 4px 2px;
    gap: 3px;
    line-height: 1.15;
  }
  .mobile-nav button > span {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
    text-align: center;
  }
  .mobile-nav .icon { width: 20px; height: 20px; }

  /* Long dialogs retain a reachable close control while their body scrolls. */
  dialog .modal-head {
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 10px 14px 10px 18px;
    background: #1c2129;
    border-bottom: 1px solid var(--line);
  }
  dialog .modal-head h2 {
    min-width: 0;
    font-size: 18px;
    line-height: 1.35;
    overflow-wrap: anywhere;
  }
  dialog .modal-head .icon-button {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }
  dialog .modal-body { min-width: 0; overflow-wrap: anywhere; }
  .language-option { min-width: 0; }
  .language-option > span { min-width: 0; overflow-wrap: anywhere; }
  .language-option > .icon { flex: 0 0 18px; width: 18px; }
  .language-option strong { line-height: 1.35; }
  .language-option small { line-height: 1.4; }
  .modal-actions { grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); }
  .modal-actions > :only-child { grid-column: 1 / -1; }

  /* Translated chart controls wrap as groups; labels and tappable areas stay intact. */
  .chart-toolbar { flex-wrap: wrap; align-items: center; gap: 4px 8px; }
  .timeframes { min-width: 0; flex: 0 0 auto; }
  .timeframes button { min-width: 40px; min-height: 44px; }
  .chart-options { min-width: 0; margin-left: auto; flex-wrap: wrap; }
  .chart-options button { min-height: 44px; font-size: 12px; padding-inline: 8px; }
  .orders-tabs, .mobile-trade-tabs {
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }
  .orders-tabs button, .mobile-trade-tabs button { flex: 0 0 auto; min-height: 44px; }
  .position-actions .btn, .position-actions > button,
  .claim-cell .claim-btn, .academy-filters > .filters .filter { min-height: 44px; }
  .position-actions > button { min-width: 0; overflow-wrap: anywhere; }
  .pair-picker { min-height: 44px; }

  /* Keep the accepted compact 2 x 2 card layout; let its translated heading wrap. */
  .market-overview .section-head { min-width: 0; flex-wrap: wrap; gap: 4px 12px; }
  .overview-actions { margin-left: auto; }
  .overview-actions .text-btn { min-height: 44px; }
  .directory-foot, .footer-links { flex-wrap: wrap; }
  .footer-links { gap: 10px 20px; }
  .footer-links button { min-height: 44px; text-align: left; }
  .reading-body p { font-size: 16px; line-height: 1.8; }
}

/* Wide phone landscape viewports otherwise fall back to crowded desktop navigation. */
@media (orientation: landscape) and (max-height: 540px) and (max-width: 1024px) {
  :root {
    --header: calc(48px + env(safe-area-inset-top, 0px));
    --route-bar-height: 44px;
  }
  .site-header {
    height: var(--header);
    min-height: var(--header);
    gap: 12px;
    padding-top: env(safe-area-inset-top, 0px);
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
  }
  .header-nav, .header-actions > .contest-badge { display: none; }
  .header-actions { gap: 6px; }
  .header-actions .language-btn, .header-actions .contest-account-btn { min-height: 44px; }
  .container, .reading-page, .route-back-inner {
    width: calc(100% - max(24px, env(safe-area-inset-left, 0px)) - max(24px, env(safe-area-inset-right, 0px)));
    margin-inline: auto;
  }
  .terminal-page {
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
  }
  .route-back-shell { top: var(--header); }
  .route-back-shell .terminal-toolbar {
    height: var(--route-bar-height);
    min-height: var(--route-bar-height);
    flex-wrap: nowrap;
    align-items: center;
  }
  .route-back-shell .terminal-mode { display: none; }
  .route-back-shell .back-bar { min-height: 44px; }
  .route-back-shell :is(.back-button, .terminal-toolbar button) { min-height: 44px; }
  .arena-prize-rail { position: relative; top: auto !important; }
  dialog {
    max-height: calc(100dvh - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  }
  dialog .modal-head {
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 8px 14px 8px 18px;
    background: #1c2129;
    border-bottom: 1px solid var(--line);
  }
  dialog .modal-head .icon-button {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }
  .site-header button, .chart-toolbar button, .contract-controls > button,
  .order-type-tabs button, .futures-order-tabs > button,
  .position-actions > button, .claim-cell .claim-btn,
  .orders-tabs button, dialog .modal-actions button { min-height: 44px; }
  .mobile-nav {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    position: fixed;
    inset: auto 0 0;
    z-index: 50;
    height: calc(52px + env(safe-area-inset-bottom, 0px));
    padding: 4px max(8px, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) max(8px, env(safe-area-inset-left, 0px));
    border-top: 1px solid #323b48;
    background: #141a22f4;
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
  }
  .mobile-nav button {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 44px;
    gap: 6px;
    padding: 4px;
    font-size: 12px;
    line-height: 1.2;
    color: #a4adbb;
  }
  .mobile-nav button.active { color: var(--yellow); background: #f0b90b12; }
  .mobile-nav button > span { min-width: 0; overflow-wrap: anywhere; }
  .mobile-nav .icon { width: 18px; height: 18px; }
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }
  input:not([type="range"]):not([type="checkbox"]):not([type="radio"]),
  select, textarea { font-size: 16px !important; }
  .chart-toolbar { flex-wrap: wrap; }
}
