/* Display-only installable-shell and phone/tablet ergonomics.
   Desktop layout (fine pointer, width > 1100px, not standalone) is unchanged.
   Does not change send, cancel, routing, or tap-to-price mapping. */

/* Standalone safe-area on the shared top bar. Height stays at least 40px. */
@media (display-mode: standalone) {
  .topbar {
    padding-top: env(safe-area-inset-top, 0px);
    box-sizing: border-box;
    min-height: calc(40px + env(safe-area-inset-top, 0px));
    height: auto;
  }
}

/* Form text at 16px on touch so iOS does not zoom on focus. */
@media (pointer: coarse) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  select,
  textarea,
  #blot-search,
  #game-search,
  #qty-input {
    font-size: 16px;
  }
  #blot-search {
    min-height: 44px;
    padding: 8px 10px;
  }
}

/* Help menu is viewport-fixed so it cannot shrink to the button wrapper. */
@media (pointer: coarse), (max-width: 1100px) {
  body:not(.pop-ladder) .help-menu {
    position: fixed !important;
    top: calc(var(--pwa-chrome-bottom, calc(40px + env(safe-area-inset-top, 0px))) + 4px);
    left: 8px;
    right: 8px;
    width: auto !important;
    max-height: min(70vh, 520px);
    overflow-y: auto;
    z-index: 220;
  }
}

/* Ladder first in the stacked 821–1100px band. Explicit desk-split stays multi-column.
   Above 1100px the three-column desk is untouched. */
@media (max-width: 1100px) {
  body:not(.desk-split):not(.pop-ladder) .center { order: 1; }
  body:not(.desk-split):not(.pop-ladder) .right { order: 2; }
  body:not(.desk-split):not(.pop-ladder) .left { order: 3; }
}

/* Tighter one-row top bar on phones. Home, Terminal, and account stay visible. */
@media (pointer: coarse) and (max-width: 820px) {
  body:not(.pop-ladder) .topbar {
    flex-wrap: nowrap;
    row-gap: 0;
    padding-left: 8px;
    padding-right: 8px;
    padding-bottom: 4px;
  }
  body:not(.pop-ladder) .nav-tabs a,
  body:not(.pop-ladder) .help-btn {
    min-height: 36px;
    min-width: 0;
    padding: 0 8px;
    font-size: 11px;
  }
  body:not(.pop-ladder) .cash-chip,
  body:not(.pop-ladder) .status-chip,
  body:not(.pop-ladder) #balance-display {
    max-width: 28vw;
    font-size: 10px;
    padding: 2px 6px;
  }
}

/* Sticky Games control and overlay list on stacked phone/tablet (not desk-split). */
@media (pointer: coarse) and (max-width: 1100px) {
  body:not(.desk-split):not(.pop-ladder):not(.pop-games) #games-fold {
    position: fixed;
    top: var(--pwa-games-top, calc(40px + env(safe-area-inset-top, 0px) + 6px));
    left: 8px;
    z-index: 118;
    min-height: 44px;
    min-width: 44px;
    padding: 0 14px;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    background: var(--panel, #121212);
    border: 1px solid var(--border, rgba(242, 240, 234, 0.08));
    color: var(--text, #f2f0ea);
  }
  /* .main is already below the top bar in document flow; only clear the fixed Games button. */
  body:not(.desk-split):not(.pop-ladder):not(.pop-games) .main {
    padding-top: 52px;
  }
  body.games-open:not(.desk-split):not(.pop-ladder):not(.pop-games) .left {
    position: fixed;
    top: calc(40px + env(safe-area-inset-top, 0px));
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 115;
    background: var(--bg, #0a0a0a);
    padding: 56px 10px 12px;
    display: flex !important;
    flex-direction: column;
    max-height: none;
    overflow: hidden;
    width: auto !important;
    height: auto !important;
  }
  body.games-open:not(.desk-split):not(.pop-ladder):not(.pop-games) #sport-nav,
  body.games-open:not(.desk-split):not(.pop-ladder):not(.pop-games) #game-search,
  body.games-open:not(.desk-split):not(.pop-ladder):not(.pop-games) #market-list {
    display: block !important;
  }
  body.games-open:not(.desk-split):not(.pop-ladder):not(.pop-games) #market-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    max-height: none;
  }
}

/* Separate labeled SOR row from Qty chips; show full ratios; larger tap targets.
   Same buttons and handlers. Leave desk-split and pop-out windows alone. */
@media (pointer: coarse) and (max-width: 1100px) {
  body:not(.desk-split):not(.pop-ladder) .trade-bar {
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    grid-template-rows: auto auto !important;
  }
  body:not(.desk-split):not(.pop-ladder) #split-row {
    display: grid !important;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto auto;
    height: auto !important;
    min-height: 0 !important;
    align-items: center;
    gap: 6px 8px;
    padding: 6px;
    overflow: visible !important;
    flex-wrap: nowrap;
  }
  body:not(.desk-split):not(.pop-ladder) .sor-lab {
    display: inline !important;
    grid-column: 1;
    grid-row: 1;
    align-self: center;
  }
  body:not(.desk-split):not(.pop-ladder) .split-presets {
    grid-column: 2;
    grid-row: 1;
    flex-wrap: wrap;
    overflow: visible;
  }
  body:not(.desk-split):not(.pop-ladder) .qty-presets {
    grid-column: 1 / -1;
    grid-row: 2;
    flex-wrap: wrap;
    margin-left: 0;
  }
  body:not(.desk-split):not(.pop-ladder) .split-preset .sp-full { display: inline; }
  body:not(.desk-split):not(.pop-ladder) .split-preset .sp-short { display: none; }
  body:not(.desk-split):not(.pop-ladder) .split-preset,
  body:not(.desk-split):not(.pop-ladder) .qty-preset {
    min-height: 36px;
    height: 36px;
    padding: 0 8px;
    font-size: 12px;
  }
  body:not(.desk-split):not(.pop-ladder) #book-cxl-btn,
  body:not(.desk-split):not(.pop-ladder) .book-cxl {
    min-height: 44px;
    min-width: 44px;
    height: 44px;
    font-size: 11px;
  }
}

/* Bottom inset in standalone so the home indicator does not cover controls. */
@media (display-mode: standalone) {
  body {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}
