/* Mobile layout (docs/design/ui.md "Mobile"). index.html links this file with
   media="(hover: none) and (pointer: coarse) and (max-width: 1024px)" (= MOBILE_QUERY in mobile.js), so none of it
   applies on a mouse-driven device: the desktop layout (style.css) is untouched. Loaded after style.css, so a rule
   here wins over the desktop rule of the same specificity.
   Portrait: one column (opponent, battlefield, phase bar, you, prompt, hand, tab bar); the left/right panels (zones,
   toolbar, log, card inspector, review panels) open as a bottom sheet from the tab bar. Landscape: battlefield, phase
   bar and hand on the left, the player panels, prompt and tab bar on the right. */
:root { --m-head: 36px; --m-bar-h: 46px; }
body { font-size: 14px; -webkit-text-size-adjust: 100%; }
button, .card, .pb-cell, .tl, .opt, .pv-line, .deck-list tr { touch-action: manipulation; }
input, select { font-size: 16px; } /* iOS zooms into a focused input under 16 px */
button { min-height: 34px; padding: 5px 10px; }
button.small { min-height: 30px; font-size: 12px; padding: 3px 8px; }
.card:hover { filter: none; }
.hslot:hover { transform: none; }
.kbd, .tb-keys, .pb-legend { display: none !important; }
.tablev2, .m-sheet, .menu, .m-bar { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

/* ---------------------------------------------------------------- header */
#top { height: auto; min-height: var(--m-head); flex-wrap: wrap; gap: 4px 8px; padding: 3px 6px; }
#top nav { display: flex; gap: 4px; flex-wrap: wrap; }
#top button.nav { padding: 3px 7px; min-height: 30px; font-size: 12.5px; white-space: nowrap; }
#status-line { font-size: 12px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.at-table .brand { display: none; }
@media (max-width: 520px) { .brand { display: none; } #top { flex-wrap: nowrap; } } /* one header line on a phone (the error banners sit under it) */
body.at-table #top { height: var(--m-head); flex-wrap: nowrap; overflow: hidden; }
body.at-table #top nav { flex-wrap: nowrap; }
#errors { top: 40px; width: calc(100vw - 12px); }
.error-banner { margin: 4px 0; }

/* ---------------------------------------------------------------- lobby */
.lobby { grid-template-columns: minmax(0, 1fr); padding: 8px; gap: 8px; }
.lobby-main { grid-template-columns: minmax(0, 1fr); gap: 8px; }
.picker, .settings { padding: 8px; min-width: 0; }
.qbtn { padding: 8px 10px; }
.filters { flex-wrap: wrap; }
.filters select, .filters input { flex: 1 1 150px; min-width: 0; }
.deck-list { max-height: 42vh; }
.deck-list th, .deck-list td { padding: 7px 6px; }
.preview-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.pv-line { padding: 4px 0; cursor: pointer; }
.settings label { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
.settings label select, .settings label input[type=number] { flex: 1 1 auto; min-width: 0; max-width: 100%; }
.settings label input[type=checkbox] { width: 20px; height: 20px; flex: none; }
.settings button.primary { width: 100%; min-height: 46px; }

/* ---------------------------------------------------------------- saved games, leaks: wide tables scroll in place */
.games, .leaks { padding: 8px; overflow-x: auto; }
.games td, .games th { white-space: nowrap; padding: 6px; }
.leak-table { display: block; overflow-x: auto; }
.leak-controls label { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px; }

/* ---------------------------------------------------------------- table: one column */
body.at-table #app { height: calc(100vh - var(--m-head)); height: calc(100dvh - var(--m-head)); }
.tablev2, .tablev2.in-review {
  display: grid; grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto auto auto auto auto;
  grid-template-areas: "opp" "field" "phase" "me" "prompt" "hand" "bar";
}
.lcol, .center { display: contents; }
.rcol, .in-review .toolbar { display: none; } /* (their panels are in the sheet; the review toolbar repeats the header) */
#pp-opp { grid-area: opp; }
#field { grid-area: field; }
#phasebar { grid-area: phase; }
#pp-me { grid-area: me; }
#prompt { grid-area: prompt; }
#hand { grid-area: hand; }
#m-bar { grid-area: bar; }

/* player panels: one strip each, life on the right */
.ppanel { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "top life" "cnt life" "pool life"; column-gap: 8px; align-items: center; padding: 2px 8px; border-left: 0; border-right: 0; }
.pp-top { grid-area: top; }
.pp-mid { grid-area: life; margin: 0; flex-direction: row-reverse; gap: 6px; }
.pp-counts { grid-area: cnt; gap: 2px 8px; }
.pp-pool { grid-area: pool; margin-top: 1px; }
.pp-life { font-size: 27px; min-width: 38px; }
.pp-sub { max-width: 34vw; font-size: 10.5px; text-align: right; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* battlefield */
.half { padding: 3px 4px; gap: 3px; }
.row, .grp { gap: 4px; }
.row { min-height: calc(var(--ch) + 2px); }
.slot.has-att { margin-bottom: 16px; }
.half.me .slot.atk, .half.me .slot.pick-attack { transform: translateY(-8px); }
.half.opp .slot.atk { transform: translateY(8px); }
.revealed { flex: none; flex-wrap: nowrap; overflow-x: auto; } /* (review: the other hand, one scrolling line) */
.revealed .zlabel { flex: none; max-width: 30vw; }
.revealed .card.sz-mini { width: auto; max-width: 42vw; flex: none; }
.banners { width: 94%; max-width: 94%; }
.result-banner { font-size: 14px; }
.result-banner button { margin-top: 6px; }
/* the stack: a strip between the two battlefields (in the flow, so it never covers a permanent to tap) */
.field { grid-template-rows: minmax(0, 1fr) auto minmax(0, 1fr); }
#half-opp { grid-row: 1; }
#stackwin { grid-row: 2; }
#half-me { grid-row: 3; }
.stackwin { position: static; max-width: none; padding: 2px 4px 3px; border-left: 0; border-right: 0; box-shadow: none; }
.stackwin .win-title { font-size: 12px; margin: 0 0 2px; }
.st-items { gap: 5px; }
.st-item { width: 132px; flex-direction: row; flex-wrap: wrap; align-items: flex-start; gap: 2px 4px; }
.st-label { flex: 1 1 100%; }
.st-item .card.sz-stack { width: 54px; height: 76px; font-size: 9px; }
.card.sz-stack .c-text, .card.sz-stack .c-type { display: none; }
.card.sz-stack .c-art { flex: 1 1 0; }
.card.sz-stack .c-head { flex-direction: column; align-items: flex-start; }
.st-item > :not(.st-label):not(.card) { flex: 1 1 60px; min-width: 0; }
.st-ab { max-width: none; font-size: 10px; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.chooser { width: calc(100% - 10px); max-height: calc(100% - 10px); padding: 6px; }
.chooser .opt { min-height: 40px; }
.chooser .win-title .muted { display: none; }
.chooser:has(.oref) .win-title::after { content: " · Hold an option to see its card."; color: var(--muted); font-weight: 400; }

/* phase bar: whose turn / who acts on one line, the steps (tap one = its stops) on the next */
.phasebar2 { flex-wrap: wrap; gap: 1px 8px; padding: 2px 4px; min-height: 0; }
.pb-turn { min-width: 0; font-size: 12.5px; }
.pb-act { margin-left: auto; font-size: 12px; padding: 0 4px; overflow: hidden; text-overflow: ellipsis; max-width: 62vw; }
.pb-steps { order: 3; flex: 1 1 100%; gap: 0; }
.pb-cell { flex: 1 1 0; padding: 2px 0; }
.pb-step { padding: 1px 2px; }
.pb-stop { pointer-events: none; min-height: 0; }
.pb-long { display: none; } .pb-short { display: inline; } /* (always the short step names) */

/* prompt box: bigger buttons */
#prompt { max-height: 34vh; max-height: 34dvh; overflow: auto; padding: 4px 8px; border-left: 0; border-right: 0; }
.pr-title { margin-bottom: 1px; }
.pr-text { font-size: 14px; margin-bottom: 3px; }
.pr-hint { font-size: 12px; margin-bottom: 3px; }
.pr-buttons { gap: 6px; margin: 3px 0; }
.pr-btn { min-height: 40px; padding: 6px 12px; font-size: 14px; }
.pr-btn.main { min-width: 96px; }
.pr-all summary { padding: 6px 0; font-size: 12.5px; }
.pr-all .opt { min-height: 38px; }
.undo-bar { margin-top: 4px; }
.undo-btn { min-height: 36px; padding: 3px 6px; }
.in-review #prompt .muted.pr-hint { display: none; } /* (the arrow-key / V hint) */

/* hand: scrolls sideways; name and cost on two lines so the cost leaves the name room */
#hand { height: 112px; justify-content: flex-start; padding: 6px 6px 4px; gap: 5px; }
#hand .hslot:first-child { margin-left: auto; }
#hand .hslot:last-child { margin-right: auto; }
.card.sz-hand .c-head { flex-direction: column; align-items: flex-start; gap: 0; }
.card.sz-hand .c-name { max-width: 100%; font-size: 11px; }
.card.sz-hand .ms { min-width: 12px; height: 12px; line-height: 12px; font-size: 8px; }
.card.sz-hand .c-art { flex: 1 1 0; }
.card.sz-hand .c-text { display: none; }

/* tab bar and bottom sheet */
.m-bar { display: flex; gap: 4px; height: var(--m-bar-h); padding: 4px 6px; background: #0b0b0c; border-top: 1px solid #3a3b3f; }
.m-bar button { flex: 1 1 0; min-width: 0; min-height: 0; font-size: 13px; padding: 2px; border-radius: 0; }
.m-bar button.on { background: #2c5fa8; border-color: #3d74c4; }
.m-bar button.m-has-act::after { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #7fb6ff; box-shadow: 0 0 6px #5aa0ff; margin-left: 5px; vertical-align: middle; }
.m-sheet { position: fixed; left: 0; right: 0; bottom: var(--m-bar-h); height: min(60vh, 560px); height: min(60dvh, 560px); z-index: 120; display: flex; flex-direction: column; background: #0c0c0e; border-top: 2px solid #5a5d63; box-shadow: 0 -8px 24px #000c; }
.m-sheet.m-nobar { bottom: 0; }
.m-sheet[hidden], .m-pane[hidden] { display: none; }
.m-sheet-head { display: flex; align-items: center; gap: 8px; padding: 3px 6px 3px 10px; border-bottom: 1px solid #26272a; flex: none; }
.m-sheet-title { font: 700 14px var(--serif); flex: 1; }
.m-sheet-body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.m-pane { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 6px; display: flex; flex-direction: column; gap: 6px; }
.m-pane[data-pane="log"], .m-pane[data-pane="moves"] { overflow: hidden; }
.m-pane .logpanel { flex: 1 1 auto; min-height: 0; overflow: auto; }
.m-pane .zones { flex: none; min-height: 0; overflow: visible; }
.m-pane .zlist .card.sz-mini { height: 30px; font-size: 13px; }
.m-zhead { font: 700 12px var(--serif); color: var(--muted); margin-top: 2px; }
.m-pane .toolbar { gap: 8px; padding: 6px; }
.m-pane .tb-row { gap: 6px; font-size: 13px; }
.m-pane .tb-check { font-size: 13px; gap: 6px; }
.m-pane .tb-check input { width: 20px; height: 20px; }
.m-pane .inspector { flex: none; }
.m-pane .insp-title { display: none; }
.m-pane .insp-img { max-width: min(300px, 82vw); }
.m-pane .tl { padding: 6px 4px; }
.m-pane .opt { min-height: 36px; }
.m-pane .lobby-side .inspector, .m-pane #lobby-inspector { background: transparent; border: 0; padding: 0; }

/* menus (card options, passing, stops, yield) open as a sheet above the tab bar */
.menu { left: 6px !important; right: 6px; top: auto !important; bottom: calc(var(--m-bar-h) + 6px); min-width: 0; max-width: none; max-height: 65vh; max-height: 65dvh; }
.menu-item { min-height: 44px; padding: 8px 12px; font-size: 15px; }
.menu-head { font-size: 11px; padding: 8px 12px 4px; }

/* review: the id/decks line clamped, the stepper as a 6-column grid (prev / next / slider first) */
.review-head { padding: 3px 6px; font-size: 11.5px; }
.review-head > div:first-child { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.review-head .engine-line { margin: 2px 0; font-size: 11px; }
.stepper { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; margin-top: 3px; }
.stepper > * { min-width: 0; }
.stepper button { padding: 3px 2px; font-size: 12px; min-height: 34px; white-space: nowrap; overflow: hidden; }
.stepper > :nth-child(1) { grid-row: 3; grid-column: 1 / 5; }
.stepper > :nth-child(2) { grid-row: 2; grid-column: 1; }
.stepper > :nth-child(3) { grid-row: 1; grid-column: 1; }
.stepper > :nth-child(4) { grid-row: 1; grid-column: 2; }
.stepper > :nth-child(5) { grid-row: 2; grid-column: 2; }
.stepper > :nth-child(6) { grid-row: 2; grid-column: 3; }
.stepper > :nth-child(7) { grid-row: 2; grid-column: 4; }
.stepper > :nth-child(8) { grid-row: 2; grid-column: 5; }
.stepper > :nth-child(9) { grid-row: 2; grid-column: 6; }
.stepper input[type=range] { grid-row: 1; grid-column: 3 / 6; min-width: 0; width: 100%; }
.stepper > #rv-pos { grid-row: 1; grid-column: 6; font-size: 10.5px; line-height: 1.15; align-self: center; }
.stepper > label { grid-row: 3; grid-column: 5 / 7; font-size: 11.5px; display: flex; align-items: center; gap: 4px; }
.stepper .seg .seg-b { min-height: 32px; padding: 2px 10px; }

/* ---------------------------------------------------------------- landscape phone */
@media (orientation: landscape) {
  :root { --m-head: 32px; --m-bar-h: 40px; }
  .tablev2, .tablev2.in-review {
    grid-template-columns: minmax(0, 1fr) minmax(210px, 36%);
    grid-template-rows: auto auto minmax(0, 1fr) auto auto auto;
    grid-template-areas: "field opp" "field me" "field prompt" "phase prompt" "hand prompt" "hand bar";
  }
  .phasebar2 { flex-wrap: nowrap; }
  .pb-steps { order: 0; flex: 1 1 auto; }
  .pb-act { display: none; }
  #hand { height: 96px; }
  #prompt { max-height: none; border-left: 1px solid #6d7178; }
  #pp-opp, #pp-me { border-left: 1px solid #34363b; }
  .m-sheet { left: auto; right: 0; width: min(440px, 64vw); top: var(--m-head); height: auto; border-top: 0; border-left: 2px solid #5a5d63; }
  .review-head > div:first-child { -webkit-line-clamp: 1; }
  .review-head .engine-line { display: none; } /* (provenance; shown in portrait. An engine error banner stays) */
  /* the stepper as one row that scrolls sideways: prev / next first */
  .stepper { display: flex; flex-wrap: nowrap; overflow-x: auto; }
  .stepper > * { flex: none; }
  .stepper > :nth-child(3), .stepper > :nth-child(4) { order: -1; }
  .stepper input[type=range] { width: 160px; }
  .stepper > #rv-pos { width: 64px; }
}
