/* Phones and tablets: the menus and the screens around a match (main menu, solo lobby, Play online, the room, the
   round panel, the end screen, the tutorial offer, the how-to guide). Every rule sits in a touch or narrow-screen
   media block, so a desktop with a mouse renders exactly as before. Loaded after the other stylesheets.
   Two tiers:
   - TOUCH, any touch tablet or phone: 44 px touch targets, 16 px inputs (no iOS zoom), no hover-only cues.
     (pointer: coarse) and (max-width: 1024px), (pointer: coarse) and (max-height: 500px), (max-width: 760px)
   - PHONE, one column: (max-width: 760px), (pointer: coarse) and (max-width: 900px), (pointer: coarse) and (max-height: 500px)
     with landscape phones, (pointer: coarse) and (max-height: 500px), getting two columns where it helps.
   The same PHONE query is in showcase.js (a lower pixel ratio) and recent.js (Recent matches start folded). */

/* ======================================================================= TOUCH */
@media (pointer: coarse) and (max-width: 1024px), (pointer: coarse) and (max-height: 500px), (max-width: 760px) {
  #lobby { -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
  #lobby .mp-tabs button, #lobby .howlink, #lobby .mp-btn, #lobby .seg button, #lobby .seg.sm button, #lobby .roles button,
  #lobby .loadout select, #lobby .mp-name input { min-height: 44px; }
  #lobby .roles button { height: 44px; padding: 0 14px; }
  #lobby .seg.sm button { height: 44px; padding: 0 14px; }
  #lobby .mp-row .mp-btn { height: 44px; min-width: 72px; }
  #lobby .loadout select, #lobby .mp-name input { height: 44px; font-size: 16px; }
  #lobby .bp-slot { min-height: 52px; }
  #lobby .bp-all { min-height: 44px; padding: 0 8px; }
  #lobby .bp-tile { min-height: 64px; }
  #lobby .mp-seat { min-height: 52px; }
  #lobby .mp-seat .pt.bp-edit { width: 44px; height: 44px; }
  #lobby .mp-seat:has(.bp-edit) { grid-template-columns: 44px minmax(0, 1fr) auto; }
  #lobby .lb-kit .ka { min-height: 48px; }
  #lobby .rc-box summary { display: flex; align-items: center; min-height: 44px; }
  #lobby .lobby-card.wide .ch { padding-left: 2px; padding-right: 2px; }
  #lobby .lobby-card.wide .ch b { font-size: 11.5px; letter-spacing: -.01em; }
  #lobby .credit a { display: inline-block; padding: 15px 0; margin: -15px 0; }
  /* Keyboard hints mean nothing on a touch screen. */
  #lobby .lb-body > .keys { display: none; }

  #over .go, #roundpanel .go { min-height: 48px; }
  #over .rm-host, #over .ov-acts #again { min-height: 48px; }
  #over .fb-star { min-width: 44px; min-height: 44px; }
  #over .fb-link { min-height: 44px; padding: 0 4px; }
  #over .fb-chip { min-height: 44px; min-width: 44px; padding: 0 14px; }
  #over .fb-send { min-height: 44px; }
  #over .fb-text, #over .fb-contact { font-size: 16px; }
  #over .fb-contact { min-height: 44px; }
  .to-btns .go, .to-btns .ghost { min-height: 48px; }
  #howto .hbtns button { min-height: 44px; }
  #howto .hno { min-height: 44px; margin: 4px 0 8px; }
  #howto .hno input { width: 22px; height: 22px; }
  #howto .hreset { min-height: 44px; }
}

/* ======================================================================= PHONE */
@media (max-width: 760px), (pointer: coarse) and (max-width: 900px), (pointer: coarse) and (max-height: 500px) {
  /* ---- the menu card: edge to edge, inside the safe area ---- */
  #lobby { grid-template-columns: minmax(0, 1fr); place-items: start stretch; padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left); }
  #lobby .lobby-card, #lobby .lobby-card.wide { --c: 12px; width: 100%; min-width: 0; max-width: 100%; padding: 12px 12px 24px; }
  /* Room for the bar with the primary action, fixed at the bottom. */
  #lobby .lobby-card:has(.lb-go) { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }

  /* Header: title and who's online on one line, the mode tabs full width, then the guide links. */
  #lobby .lb-head { flex-wrap: wrap; gap: 8px; min-height: 0; }
  #lobby .lb-head h1 { font-size: 20px; letter-spacing: .1em; }
  #lobby .lb-meta { margin-left: auto; gap: 8px; font-size: 11px; }
  #lobby .mp-tabs { order: 3; flex: 1 1 100%; margin: 0; }
  #lobby .mp-tabs button { flex: 1; height: 44px; padding: 0 8px; font-size: 12px; }
  #lobby .howlinks { order: 4; flex: 1 1 100%; display: flex; gap: 8px; }
  #lobby .howlinks .howlink { flex: 1; justify-content: center; height: 44px; }
  #lobby .lb-rules { margin: 12px 0; font-size: 12px; line-height: 1.45; }

  /* One column: champions, the showcase, then the setup. */
  #lobby .lb-main, #lobby .mp-room .lb-main { display: flex; flex-direction: column; height: auto; gap: 16px; }
  #lobby .lb-main > section { min-height: 0; }
  #lobby .lb-pick { overflow: visible; padding-right: 0; }

  /* Role filter: one row that scrolls sideways. */
  #lobby .roles { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -12px 8px; padding: 0 12px; }
  #lobby .roles::-webkit-scrollbar { display: none; }
  #lobby .roles button { flex: none; }

  /* The champion picker: a strip that scrolls sideways, snapping to tiles. */
  #lobby .lobby-card.wide .chars { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 88px; grid-auto-rows: 112px; grid-template-rows: 112px;
    overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x proximity; scrollbar-width: none; margin: 0 -12px; padding: 0 12px 4px; scroll-padding: 0 12px; }
  #lobby .lobby-card.wide .chars::-webkit-scrollbar { display: none; }
  #lobby .lobby-card.wide .ch { scroll-snap-align: start; padding: 20px 4px 8px; gap: 4px; }
  #lobby .lobby-card.wide .ch .ic, #lobby .lobby-card.wide .ch .ic .svgi { width: 34px; height: 34px; }
  #lobby .lobby-card.wide .ch b { font-size: 12px; line-height: 1.2; }
  #lobby .ch .beg { font-size: 8px; line-height: 12px; padding: 0 4px; }

  /* The showcase: the 3D stage capped in height, stats in two columns, the abilities folded. */
  #lobby .lb-show { --c: 10px; padding: 10px; gap: 10px; }
  #lobby .stage { flex: none; height: clamp(170px, 30vh, 240px); min-height: 0; }
  #lobby .st-hd h2 { font-size: 18px; }
  #lobby .st-tags { max-width: 60%; }
  #lobby .lb-stats { gap: 6px 12px; }
  #lobby .lb-stats .sb { grid-template-columns: 52px 1fr auto; }
  /* The fold header is the list's own ::before; a tap on it (lobby.js) toggles .mm-open. */
  #lobby .lb-kit { gap: 4px; }
  #lobby .lb-kit::before { content: "Abilities"; display: flex; align-items: center; min-height: 44px; padding: 0 12px; cursor: pointer;
    border: 1px solid var(--m-line); background: rgba(14, 22, 36, .85); font: 700 11px var(--ui); letter-spacing: .14em; text-transform: uppercase; color: #a9bad3;
    background-image: linear-gradient(45deg, transparent 45%, #a9bad3 45%, #a9bad3 55%, transparent 55%), linear-gradient(-45deg, transparent 45%, #a9bad3 45%, #a9bad3 55%, transparent 55%);
    background-size: 7px 7px; background-position: right 22px center, right 17px center; background-repeat: no-repeat; }
  #lobby .lb-kit:not(.mm-open) > .ka { display: none; }
  #lobby .lb-kit.mm-open::before { content: "Abilities · tap one for details"; }
  #lobby .lb-kit small { white-space: normal; }
  #lobby .lb-tip { width: calc(100% - 24px); left: 12px !important; }

  /* Setup: no scroll of its own; the catalysts fold behind their heading. */
  #lobby .lb-opts { --c: 10px; padding: 12px; overflow: visible; clip-path: none; }
  #lobby h3:has(+ .loadout) { min-height: 44px; margin: 0; align-items: center; cursor: pointer; position: relative; padding-right: 28px; }
  #lobby h3:has(+ .loadout)::after { content: ""; position: absolute; right: 8px; top: 50%; width: 8px; height: 8px; margin-top: -6px; border: solid #a9bad3; border-width: 0 2px 2px 0; transform: rotate(45deg); transition: transform .15s; }
  #lobby h3.mm-open:has(+ .loadout)::after { transform: rotate(-135deg); margin-top: -2px; }
  #lobby h3:not(.mm-open) + .loadout { display: none; }
  #lobby h3.mm-open + .loadout { margin-bottom: 8px; }
  #lobby .lb-opts > h3:not(:first-child) { margin-top: 12px; }
  #lobby .lb-opts .seg { margin-bottom: 8px; }
  #lobby .bp-row { grid-template-columns: 64px repeat(3, minmax(0, 1fr)); gap: 6px; }
  #lobby .bp-slot { padding: 6px 2px; }
  #lobby .bp-slot small { font-size: 11px; }

  /* The primary action: a bar fixed at the bottom of the screen (the card leaves room for it above). */
  #lobby .lb-go { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; margin: 0;
    padding: 10px calc(12px + env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
    background: linear-gradient(180deg, rgba(5, 8, 14, .82), rgba(5, 8, 14, .97)); border-top: 1px solid var(--m-line); }
  #lobby .lb-go .go { height: 52px; font-size: 15px; }
  #lobby .lb-go .keys, #lobby .mp-foot .keys { display: none; }
  #lobby .lb-go .mp-wait { padding: 12px; min-height: 52px; font-size: 13px; }

  #lobby .credit { margin-top: 16px; font-size: 11px; line-height: 1.5; }

  /* The bot champion picker: a sheet from the bottom of the screen, over the action bar. */
  #lobby .bp-pop { position: fixed; left: 0 !important; right: 0; top: auto !important; bottom: 0; z-index: 7; width: auto; max-height: 72vh; overflow: auto;
    --c: 0px; padding: 12px calc(12px + env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left)); clip-path: none; }
  #lobby .bp-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  #lobby .bp-tile { padding: 8px 2px 6px; }
  #lobby .bp-tile b { font-size: 11px; }

  /* Recent matches: the essential columns only (when, champion, result, score). */
  #lobby .rc-box { margin-top: 16px; }
  #lobby .rc-list { width: 100%; }
  #lobby .rc-list th:nth-child(2), #lobby .rc-list td:nth-child(2), #lobby .rc-list th:nth-child(6), #lobby .rc-list td:nth-child(6) { display: none; }
  #lobby .rc-list td { padding: 8px 6px; white-space: normal; }
  #lobby .rc-list th { padding: 4px 6px; }

  /* ---- Play online: one column; the list rows drop the mode column ---- */
  #lobby .mp-modes { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  #lobby .mp-box { --c: 10px; padding: 12px; }
  #lobby .mp-box p { margin-bottom: 12px; }
  #lobby .mp-name { margin-bottom: 12px; }
  #lobby .mp-bh { gap: 8px; }
  #lobby .mp-acts { flex: 1 1 100%; }
  #lobby .mp-acts .mp-btn { flex: 1; justify-content: center; }
  #lobby .mp-list { max-height: none; }
  #lobby .mp-row { grid-template-columns: minmax(0, 1fr) 44px auto; gap: 8px; padding: 6px 6px 6px 12px; }
  #lobby .mp-row .mp-mode { display: none; }
  #lobby .mp-row.mp-hd > span:nth-child(2) { display: none; }
  #lobby .mp-diff { flex-wrap: wrap; justify-content: space-between; }

  /* ---- the room: the seats first, then the champions ---- */
  #lobby .mp-head { flex-wrap: wrap; gap: 8px 12px; min-height: 0; margin-bottom: 12px; }
  #lobby .mp-hl { flex: 1 1 auto; }
  #lobby .mp-room h1.mp-title { font-size: 20px; }
  #lobby .mp-hr { margin-left: auto; }
  #lobby .mp-count { order: 3; flex: 1 1 100%; margin: 0; }
  #lobby .mp-room .lb-opts { order: -1; }
  #lobby .mp-teams { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
  #lobby .mp-seat { grid-template-columns: 32px minmax(0, 1fr) auto; padding: 4px 6px; gap: 6px; }
  #lobby .mp-seat .pt { width: 32px; height: 32px; }
  #lobby .mp-seat .who b { font-size: 12px; }
  #lobby .mp-seat .who b small.open { display: none; }
  #lobby .mp-side .mp-th { margin: 0 0 8px; }

  /* ---- the round panel ---- */
  #roundpanel { padding: calc(8px + env(safe-area-inset-top)) calc(8px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(8px + env(safe-area-inset-left)); }
  #roundpanel .rp-card { --c: 12px; max-height: 100%; overflow: auto; padding: 16px 12px; }
  #roundpanel .rp-band { padding-bottom: 10px; }
  #roundpanel .rp-card h2 { font-size: 22px; }
  #roundpanel .rp-score { font-size: 34px; }
  #roundpanel .mvp { margin-bottom: 10px; }
  /* Continue stays in reach while the table scrolls (the card is the scroller). */
  #roundpanel .rp-card .go { position: sticky; bottom: 0; z-index: 2; margin-top: 12px; }

  /* Stats tables: scroll sideways with the name column pinned. */
  #over .st-tbl, #roundpanel .st-tbl { display: block; overflow-x: auto; overscroll-behavior-x: contain; }
  #over .st-tbl th:first-child, #over .st-tbl td.who, #roundpanel .st-tbl th:first-child, #roundpanel .st-tbl td.who {
    position: sticky; left: 0; z-index: 1; background: #0c1320; max-width: 132px; overflow: hidden; text-overflow: ellipsis; }
  #over .st-tbl tr.me td.who, #roundpanel .st-tbl tr.me td.who { background: #0f2433; }
  #over .st-tbl th, #over .st-tbl td, #roundpanel .st-tbl th, #roundpanel .st-tbl td { padding: 8px 6px; font-size: 12px; }

  /* ---- the end of the match: the whole card scrolls; the actions stay pinned at its bottom ---- */
  #over { padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left); place-items: stretch; }
  #over .over-card { --c: 12px; width: 100%; height: 100%; max-height: none; overflow: auto; overscroll-behavior: contain; }
  #over .ov-scroll { flex: none; overflow: visible; padding: 16px 12px 12px; }
  #over .ov-hero { gap: 12px; }
  #over .over-card h1 { font-size: 30px; letter-spacing: .1em; }
  #over .ov-score { font-size: 38px; column-gap: 8px; }
  #over .ov-score .vs { font-size: 24px; }
  #over .ov-high { grid-template-columns: minmax(0, 1fr); }
  #over .awards { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  #over .over-card h3 { margin-top: 16px; }
  #over .rd { min-width: 0; flex: 1 1 130px; }
  #over .ov-foot { display: contents; }
  #over #overFb { flex: none; margin: 0 12px 12px; }
  #over #overFb.open { order: 0; max-height: none; overflow: visible; padding: 12px; }
  #over #overFb .fb-body { display: flex; flex-direction: column; gap: 8px; }
  #over #overFb .fb-send { align-self: stretch; }
  #over #overFb .fb-lbl { align-self: stretch; } #over #overFb .fb-text, #over #overFb .fb-contact { width: 100%; }
  #over #overFb .fb-count { align-self: flex-end; margin-top: -4px; }
  #over #overFb .fb-text { height: 88px; }
  #over .fb-head { gap: 4px 8px; }
  #over .fb-star { padding: 0; font-size: 24px; }
  #over .ov-acts { position: sticky; bottom: 0; z-index: 2; margin: auto 0 0; display: flex; align-items: flex-end; gap: 8px;
    padding: 10px calc(12px + env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) 12px;
    border-top: 1px solid rgba(140, 170, 210, .16); background: rgba(5, 9, 15, .96); }
  #over .rm-box { flex: 1 1 auto; min-width: 0; grid-template-columns: minmax(0, 1fr) auto; }
  #over .rm-box:has(> .rm-host[hidden]) { grid-template-columns: minmax(0, 1fr); }
  #over .rm-box .rm-go { min-width: 0; width: 100%; padding: 0 12px; font-size: 14px; letter-spacing: .1em; }
  #over .rm-status { text-align: left; white-space: normal; }
  #over .rm-host { padding: 0 10px; }
  #over .ov-acts #again { flex: none; padding: 0 12px; height: 52px; }
  #over .ov-acts #again:only-child { flex: 1; }

  /* ---- the first-visit offer and the how-to guide ---- */
  #tutoffer { padding: calc(12px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left)); overflow: auto; }
  .to-card { padding: 20px 16px; }
  .to-card h2 { font-size: 22px; }
  #howto .hcard { max-height: calc(100% - 24px); overflow: auto; }
}

/* Portrait phones: the primary choice first in the offer; the end screen's hero stacks under 380 px. */
@media (max-width: 760px) and (orientation: portrait), (pointer: coarse) and (max-width: 900px) and (orientation: portrait) {
  .to-btns { flex-direction: column-reverse; }
  .to-btns > .ghost, .to-btns > .go { flex: none; width: 100%; }
}

/* ============================================================ LANDSCAPE PHONES */
/* Short screens: two columns where it saves scrolling, a slimmer action bar. */
@media (pointer: coarse) and (max-height: 500px) {
  #lobby .mp-tabs { order: 3; flex: 1 1 auto; } #lobby .howlinks { order: 4; flex: 0 0 auto; }
  #lobby .howlinks .howlink { flex: none; padding: 0 16px; }
  #lobby .lb-rules { margin: 8px 0; }
  #lobby .lb-main, #lobby .mp-room .lb-main { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  #lobby .lb-main > section { min-width: 0; }
  #lobby .lb-main > .lb-pick { grid-column: 1 / -1; }
  #lobby .mp-room .lb-opts { order: 0; }
  #lobby .lb-show { display: grid; grid-template-columns: minmax(0, 1fr); }
  #lobby .stage { height: 180px; }
  #lobby .mp-teams { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  #lobby .mp-modes { grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); align-items: start; }
  #lobby .lobby-card:has(.lb-go) { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
  #lobby .lb-go { padding-top: 8px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  #lobby .lb-go .go { height: 48px; max-width: 420px; margin-left: auto; }
  #lobby .lb-go .mp-wait { max-width: 420px; margin-left: auto; }
  #lobby .bp-pop { max-height: 88vh; }
  #lobby .bp-grid { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  #over .ov-high { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
  #over .ov-acts { padding-top: 8px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  #over .ov-acts .go, #over .ov-acts #again { height: 48px; }
  #roundpanel .rp-card { width: min(640px, 100%); }
  #tutoffer { place-items: center; }
  .to-card { padding: 16px 20px; }
  .to-card h2 { margin: 4px 0 8px; font-size: 20px; }
  .to-btns { margin-top: 16px; }
  .to-card small { margin-top: 8px; }
}
