/* Tournament of Eight on wide screens (iPad, the Duo's inner screen). Nov 26, 2026. Contract: docs/ipad-duo/GAME-WORKER-GUIDE.md.
   Only in --wide builds, linked last with the gate's media query; every rule starts with html.tc-wide, so a phone never
   applies a line. Level "column" (game.json): #app is the root (760 portrait, 1180 landscape). No JS: the page has no layout code.
     tall (iPad portrait):   one wider column; the two home cards side by side; 4 x 2 seats; the bracket two matches a row.
     wide (iPad landscape):  bracket page: rounds on the left (two a row, scrolling on their own), title, banner and the final
                             standings in a side panel on the thumb side that never scrolls away. Home and lobby: two columns.
     fold (Duo inner):       the same two areas as wide, one on each half; nothing crosses the hinge; rounds one a row.
   The match itself (#stage, full screen): the embedded game runs in the iframe with ITS OWN wide layout, judged from the
   iframe's window (gate 500 x 500): every iPad size and the Duo inner screen get the game's wide / fold layout, the Duo outer
   screen and phones the phone layout. An iframe sees no safe-area insets, so the iframe is inset here instead: the iPad home
   bar (and a landscape notch side) never covers the game's own buttons. */

/* ------------------------------------------------------------------ the match: keep the game clear of the home bar */
html.tc-wide #stage #frameWrap { background: var(--ui-bg, var(--bg)); }
html.tc-wide #stage #frameWrap iframe { top: 0; left: env(safe-area-inset-left); right: auto; bottom: auto;
  width: calc(100% - env(safe-area-inset-left) - env(safe-area-inset-right)); height: calc(100% - env(safe-area-inset-bottom)); }
html.tc-wide #stage #hud { padding-left: calc(env(safe-area-inset-left) + 14px); padding-right: calc(env(safe-area-inset-right) + 14px);
  font-size: 14px; }
html.tc-wide #stage #hud svg { width: 30px; height: 30px; }
html.tc-wide #stage #hud .clock { font-size: 18px; }

/* ------------------------------------------------------------------ all wide modes: a little more room */
/* the frame's top bar (above #app) spans the screen with the iPad margins (unified UI spec: 24) */
html.tc-wide body > .tcf-bar { max-width: none; padding-left: calc(env(safe-area-inset-left) + 24px); padding-right: calc(env(safe-area-inset-right) + 24px); }
html.tc-wide #app { padding-left: 16px; padding-right: 16px; }
html.tc-wide #app h1.serif:not(#bracketTitle) { font-size: 34px; }
html.tc-wide #app .lead { font-size: 15px; max-width: 620px; margin-left: auto; margin-right: auto; }
html.tc-wide #lobby .seats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
html.tc-wide #lobby .seat { min-height: 68px; }
/* the bracket: rounds as a grid; round and tier labels across, matches two a row (one a row in fold) */
html.tc-wide #rounds { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 10px; align-content: start; }
html.tc-wide #rounds > :is(.rule, .tier) { grid-column: 1 / -1; }
html.tc-wide #rounds > .matches { min-width: 0; }
/* round 3 (newest, so always first when it is there): four places at stake, one match each. Two tiers a row, each label over
   its match: labels in rows 2 and 4, matches in rows 3 and 5. Round 3 is there when #rounds' 4th child is a tier label
   (in round 2 it is a match). Later rounds follow from row 6 (auto placement). */
html.tc-wide #rounds:has(> .tier:nth-child(4)) > .rule:nth-child(1) { grid-row: 1; }
html.tc-wide #rounds:has(> .tier:nth-child(4)) > :nth-child(2) { grid-row: 2; grid-column: 1; }
html.tc-wide #rounds:has(> .tier:nth-child(4)) > :nth-child(3) { grid-row: 3; grid-column: 1; }
html.tc-wide #rounds:has(> .tier:nth-child(4)) > :nth-child(4) { grid-row: 2; grid-column: 2; }
html.tc-wide #rounds:has(> .tier:nth-child(4)) > :nth-child(5) { grid-row: 3; grid-column: 2; }
html.tc-wide #rounds:has(> .tier:nth-child(4)) > :nth-child(6) { grid-row: 4; grid-column: 1; }
html.tc-wide #rounds:has(> .tier:nth-child(4)) > :nth-child(7) { grid-row: 5; grid-column: 1; }
html.tc-wide #rounds:has(> .tier:nth-child(4)) > :nth-child(8) { grid-row: 4; grid-column: 2; }
html.tc-wide #rounds:has(> .tier:nth-child(4)) > :nth-child(9) { grid-row: 5; grid-column: 2; }

/* ------------------------------------------------------------------ tall: one wider column */
/* home: the top bar at the top, the rest in the middle of the screen; the two cards side by side */
html.tc-wide.tcw-tall #home:not(.hidden) { display: grid; flex: 1; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto auto auto auto auto auto minmax(0, 1.4fr); column-gap: 14px; row-gap: 12px; }
html.tc-wide.tcw-tall #home > :not(.card) { grid-column: 1 / -1; }
html.tc-wide.tcw-tall #home > h1 { grid-row: 3; }
html.tc-wide.tcw-tall #home > .sub { grid-row: 4; }
html.tc-wide.tcw-tall #home > .lead { grid-row: 5; }
html.tc-wide.tcw-tall #home > .card { grid-row: 6; align-self: stretch; }
html.tc-wide.tcw-tall #home > .card:not(#onlineCard) { grid-column: 1; justify-content: center; }
html.tc-wide.tcw-tall #home > #onlineCard { grid-column: 2; }
html.tc-wide.tcw-tall #home > #practiceBtn { grid-row: 7; }
html.tc-wide.tcw-tall #home > #modeNote { grid-row: 8; }
/* no lobby codes on this site (practice only): the name card alone, centred */
html.tc-wide.tcw-tall #home:has(> #onlineCard.hidden) > .card:not(#onlineCard) { grid-column: 1 / -1; width: 100%; max-width: 480px; justify-self: center; }
html.tc-wide.tcw-tall #home:has(> #onlineCard.hidden) > #practiceBtn { width: 100%; max-width: 480px; justify-self: center; }
/* lobby: the top bar at the top, the rest in the middle (free space split above and below) */
html.tc-wide.tcw-tall #lobby:not(.hidden) { flex: 1; }
html.tc-wide.tcw-tall #lobby > h1 { margin-top: auto; }
html.tc-wide.tcw-tall #lobby > #lobbyNote { margin-bottom: auto; padding-bottom: 8vh; }
html.tc-wide.tcw-tall #lobby #hostCard { align-self: center; width: 100%; max-width: 560px; }

/* ------------------------------------------------------------------ wide and fold: two areas */
/* home: title and words | the two cards and the practice button */
html.tc-wide:is(.tcw-wide, .tcw-fold) #home:not(.hidden) { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto auto auto auto auto minmax(0, 1fr);
  column-gap: 40px; row-gap: 12px; align-content: stretch; width: 100%; max-width: 1000px; margin: 0 auto; flex: 1; }
html.tc-wide:is(.tcw-wide, .tcw-fold) #home > h1 { grid-column: 1; grid-row: 3; align-self: end; }
html.tc-wide:is(.tcw-wide, .tcw-fold) #home > .sub { grid-column: 1; grid-row: 4; }
html.tc-wide:is(.tcw-wide, .tcw-fold) #home > .lead { grid-column: 1; grid-row: 5 / span 3; align-self: start; }
html.tc-wide:is(.tcw-wide, .tcw-fold) #home > .card:not(#onlineCard) { grid-column: 2; grid-row: 3 / span 2; }
html.tc-wide:is(.tcw-wide, .tcw-fold) #home > #onlineCard { grid-column: 2; grid-row: 5; }
html.tc-wide:is(.tcw-wide, .tcw-fold) #home > #practiceBtn { grid-column: 2; grid-row: 6; }
html.tc-wide:is(.tcw-wide, .tcw-fold) #home > #modeNote { grid-column: 2; grid-row: 7; }
html.tc-wide:is(.tcw-wide, .tcw-fold) #home:has(> #onlineCard.hidden) > .card:not(#onlineCard) { grid-row: 3 / span 3; align-self: end; }
/* lobby: title, code and count | seats, host card and note */
html.tc-wide:is(.tcw-wide, .tcw-fold) #lobby:not(.hidden) { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr);
  grid-template-rows: auto minmax(0, 1fr) auto auto auto auto auto minmax(0, 1fr);
  column-gap: 32px; row-gap: 12px; align-content: stretch; width: 100%; max-width: 1100px; margin: 0 auto; flex: 1; }
html.tc-wide:is(.tcw-wide, .tcw-fold) #lobby > h1 { grid-column: 1; grid-row: 3; align-self: end; }
html.tc-wide:is(.tcw-wide, .tcw-fold) #lobby > .codechip { grid-column: 1; grid-row: 4; justify-self: center; }
html.tc-wide:is(.tcw-wide, .tcw-fold) #lobby > .count { grid-column: 1; grid-row: 5; align-self: start; }
html.tc-wide:is(.tcw-wide, .tcw-fold) #lobby > .seats { grid-column: 2; grid-row: 3 / span 2; align-self: end; }
html.tc-wide:is(.tcw-wide, .tcw-fold) #lobby > #hostCard { grid-column: 2; grid-row: 5; }
html.tc-wide:is(.tcw-wide, .tcw-fold) #lobby > #lobbyNote { grid-column: 2; grid-row: 6; }
/* bracket: the page is one screen tall; the rounds scroll on their own, the panel stays */
html.tc-wide:is(.tcw-wide, .tcw-fold) #app:has(> #bracket:not(.hidden)) { height: calc(var(--tcvh, 100dvh) - 44px - calc(env(safe-area-inset-top) + var(--tc-frost, 0px))); }
html.tc-wide:is(.tcw-wide, .tcw-fold) #bracket:not(.hidden) { display: grid; flex: 1; min-height: 0;
  grid-template-columns: minmax(0, 1fr) clamp(300px, 30%, 380px); grid-template-rows: auto auto auto minmax(0, 1fr);
  column-gap: 24px; row-gap: 12px; }
html.tc-wide:is(.tcw-wide, .tcw-fold) #bracket > #roundLabel { grid-column: 2; grid-row: 1; }
html.tc-wide:is(.tcw-wide, .tcw-fold) #bracket > #bracketTitle { grid-column: 2; grid-row: 2; }
html.tc-wide:is(.tcw-wide, .tcw-fold) #bracket > .banner { grid-column: 2; grid-row: 3; }
html.tc-wide:is(.tcw-wide, .tcw-fold) #bracket > #podiumBox { grid-column: 2; grid-row: 4; min-height: 0; overflow-y: auto;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding-bottom: 4px; }
html.tc-wide:is(.tcw-wide, .tcw-fold) #bracket > #rounds { grid-column: 1; grid-row: 2 / -1; min-height: 0; overflow-y: auto;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 0 4px 8px; }
html.tc-wide:is(.tcw-wide, .tcw-fold) #bracket > #rounds > .rule:first-child { margin-top: 2px !important; }
/* thumb on the left: the panel swaps sides */
html.tc-wide.tcw-left.tcw-wide #bracket:not(.hidden) { grid-template-columns: clamp(300px, 30%, 380px) minmax(0, 1fr); }
html.tc-wide.tcw-left:is(.tcw-wide, .tcw-fold) #bracket > :is(#roundLabel, #bracketTitle, .banner, #podiumBox) { grid-column: 1; }
html.tc-wide.tcw-left:is(.tcw-wide, .tcw-fold) #bracket > #rounds { grid-column: 2; }

/* ------------------------------------------------------------------ fold: the two areas are the two halves of the screen */
html.tc-wide.tcw-fold #app { padding-left: 0; padding-right: 0; }
html.tc-wide.tcw-fold :is(#home, #lobby, #bracket):not(.hidden) { max-width: none; width: var(--tcw-w); margin: 0;
  padding: 0 16px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: calc(var(--tcw-hinge-w) + 32px); }
html.tc-wide.tcw-fold #rounds { grid-template-columns: minmax(0, 1fr); }
html.tc-wide.tcw-fold #rounds:has(> .tier:nth-child(4)) > * { grid-row: auto; grid-column: 1; }
html.tc-wide.tcw-fold #lobby .seats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
html.tc-wide.tcw-fold #lobby > .seats { grid-row: 3 / span 3; align-self: center; }
html.tc-wide.tcw-fold #lobby > #hostCard { grid-row: 6; }
html.tc-wide.tcw-fold #lobby > #lobbyNote { grid-row: 7; }
html.tc-wide.tcw-fold #lobby > .count { grid-row: 5 / span 3; }
html.tc-wide.tcw-fold #app h1.serif:not(#bracketTitle) { font-size: 30px; }
/* a real hinge: the pop-ups keep to the thumb half instead of straddling it */
html.tc-wide.tcw-fold.tcw-hinge .overlay { justify-content: flex-end; }
html.tc-wide.tcw-fold.tcw-hinge.tcw-left .overlay { justify-content: flex-start; }
html.tc-wide.tcw-fold.tcw-hinge .overlay > .sheet { max-width: min(420px, calc((var(--tcw-w) - var(--tcw-hinge-w)) / 2 - 32px)); }
