/* ==========================================================================
   Phone focus (Nov 2026): on a phone controller each phase shows only the thing to act on or watch, centred.
   Loaded last. Everything sits behind the same phone query as mobile.css / fit.css, so the TV, desktop players
   and tablets are untouched. Markup: reveal-screen.js (PhoneScoreBoard), battle-screens.js (PhoneBattleScores).

   Question   the question and its answers (fit.css already drops the header, strip and attack track).
   Reveal     act 1: answer order, picks, the right answer and the verdicts. Act 2: players and scores only.
   Result     battle result: the duel and the same score board; no strip.
   ========================================================================== */

/* The board only exists for phones. */
.pf-board { display: none; }

@media (hover: none) and (pointer: coarse) and (max-width: 932px) {
  /* ---------- Reveal and battle result: no score strip, no attack track ----------
     The strip showed old totals and then one tiny "+18 Correct" at a time; the board below carries every score
     with its reason. Your piece (the strip's emotion button) moves to the bottom-left corner, opposite Ready. */
  .game-shell:has(> .main-stage > :is(.question-screen.is-reveal, .geo-question.is-reveal, .review-with-votes, .battle-outcome, .battle-ready)) > :is(.player-strip, .battle-round-track),
  .game-shell:has(> .main-stage > :is(.question-screen.is-reveal, .geo-question.is-reveal, .review-with-votes, .battle-outcome, .battle-ready)) .battle-round-track { display: none !important; }
  /* The attack track is gone, so the room the stage kept for it goes too. */
  .game-shell:has(.battle-round-track):has(> .main-stage > :is(.question-screen.is-reveal, .geo-question.is-reveal, .review-with-votes, .battle-outcome, .battle-ready)) > .main-stage { padding-top: 8px !important; }
  body:has(.game-shell > .main-stage > :is(.question-screen.is-reveal, .geo-question.is-reveal, .review-with-votes, .battle-outcome, .battle-ready)) .emoji-quick {
    display: grid; place-items: center; position: fixed; z-index: 70; top: auto; right: auto;
    bottom: max(10px, env(safe-area-inset-bottom)); left: max(10px, env(safe-area-inset-left));
    width: 48px; height: 48px; padding: 0; border: 2px solid var(--player, #fff); border-radius: 50%; cursor: pointer;
    background: #140b22d9; box-shadow: 0 6px 18px #0008; -webkit-tap-highlight-color: transparent;
  }

  /* ---------- Reveal act 2: the question steps back, the board steps in ----------
     Both are always laid out; only opacity changes, so the page never reflows at the switch. */
  .pf-main { transition: opacity 260ms ease, visibility 0s linear 0s; }
  .pf-main.pf-out { opacity: 0 !important; visibility: hidden !important; pointer-events: none !important; transition: opacity 260ms ease, visibility 0s linear 260ms; }
  /* Fixed and off-flow parts of the question leave with it. */
  .pf-main.pf-out * { animation-play-state: paused !important; }

  .pf-board { display: grid; font-family: var(--ad-font-ui, system-ui, sans-serif); color: var(--ad-ink, #F7F2FF); }
  .pf-board.is-overlay {
    position: fixed; inset: 0; z-index: 30; place-items: center; box-sizing: border-box;
    padding: calc(64px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) calc(84px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    opacity: 0; visibility: hidden; pointer-events: none;
    transition: opacity 240ms ease, visibility 0s linear 240ms;
  }
  .pf-board.is-overlay.is-on { opacity: 1; visibility: visible; transition: opacity 320ms ease 180ms, visibility 0s linear 0s; }
  .pf-board.is-inline { width: 100%; justify-items: center; }
  .pf-board-card { width: min(100%, 430px); max-height: 100%; min-height: 0; box-sizing: border-box; display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 12px; }
  .pf-board.is-overlay.is-on .pf-board-card { pointer-events: auto; }

  .pf-board-head { display: grid; justify-items: center; gap: 8px; }
  .pf-board-head h2 { margin: 0; font-family: var(--ad-font-display, inherit); font-weight: 800; font-size: 26px; line-height: 1.1; letter-spacing: -.01em; }
  /* The score types of this question. Each lights up as its points land for everyone. */
  .pf-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
  .pf-legend li {
    --pf-c: var(--ad-lime, #D8FF36);
    padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; line-height: 1.2; white-space: nowrap;
    color: var(--ad-spent, #8F7FA8); background: #ffffff0d; box-shadow: inset 0 0 0 1px #ffffff14;
    transition: color 240ms ease, background-color 240ms ease, box-shadow 240ms ease;
  }
  .pf-legend li.is-in { color: var(--pf-c); background: color-mix(in srgb, var(--pf-c) 14%, transparent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--pf-c) 45%, transparent); }
  .pf-legend li.is-now { color: var(--ad-night, #120A1F); background: var(--pf-c); box-shadow: none; }

  .pf-rows { list-style: none; margin: 0; padding: 0 2px 2px; min-height: 0; overflow-y: auto; overscroll-behavior: contain; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; align-content: start; }
  .pf-row {
    display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; grid-template-areas: "who name total" "who chips chips";
    align-items: center; column-gap: 10px; row-gap: 5px; padding: 9px 12px 9px 10px; border-radius: 14px;
    background: #ffffff0f; box-shadow: inset 3px 0 0 var(--player, #fff); align-content: start;
  }
  .pf-row.is-you { background: #ffffff1c; box-shadow: inset 3px 0 0 var(--player, #fff), inset 0 0 0 1px #ffffff2e; }
  .pf-who { grid-area: who; align-self: start; display: grid; place-items: center; width: 32px; height: 32px; }
  .pf-who .avatar { width: 32px !important; height: 32px !important; }
  .pf-name { grid-area: name; min-width: 0; display: flex; align-items: baseline; gap: 4px; font-size: 17px; font-weight: 700; line-height: 1.2; }
  .pf-name span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .pf-name small { flex: none; font-size: 12px; font-weight: 600; color: var(--ad-muted, #C3B3DA); }
  .pf-total { grid-area: total; min-width: 4.2ch; text-align: right; font-family: var(--ad-font-display, inherit); font-weight: 800; font-size: 22px; line-height: 1; font-variant-numeric: tabular-nums; white-space: nowrap; }
  .pf-total small { margin-left: 3px; font-family: var(--ad-font-ui, inherit); font-size: 11px; font-weight: 600; color: var(--ad-muted, #C3B3DA); }
  /* Every chip holds its place from the first frame, unseen, so a landing chip never pushes its neighbours. */
  .pf-chips { grid-area: chips; display: flex; flex-wrap: wrap; gap: 4px 6px; min-height: 24px; align-items: center; }
  .pf-chip {
    --pf-c: var(--ad-lime, #D8FF36);
    display: inline-flex; align-items: baseline; gap: 5px; padding: 3px 9px; border-radius: 999px; line-height: 1.25; white-space: nowrap;
    background: color-mix(in srgb, var(--pf-c) 15%, transparent);
    opacity: 0; transform: translateY(5px) scale(.86);
    transition: opacity 200ms ease, transform 380ms cubic-bezier(.2, 1.5, .4, 1);
  }
  .pf-chip.is-in { opacity: 1; transform: none; }
  .pf-chip b { font-family: var(--ad-font-display, inherit); font-weight: 800; font-size: 15px; color: var(--pf-c); font-variant-numeric: tabular-nums; }
  .pf-chip small { font-size: 13px; font-weight: 600; color: var(--ad-ink, #F7F2FF); }
  /* The type that has just landed stands out in every row at once. */
  .pf-chip.is-now { box-shadow: inset 0 0 0 1.5px var(--pf-c); }
  .pf-chip.pf-none { background: none; padding-left: 0; }
  .pf-chip.pf-none small { color: var(--ad-spent, #8F7FA8); font-weight: 600; }
  .pf-row.is-blank .pf-name, .pf-row.is-blank .pf-total { color: var(--ad-muted, #C3B3DA); }

  /* One colour per score type, shared by the legend and the chips. */
  .pf-board .pf-beat-place { --pf-c: #D8FF36; }
  .pf-board .pf-beat-fastest { --pf-c: #5CE1FF; }
  .pf-board .pf-beat-sole { --pf-c: #FF8CC6; }
  .pf-board .pf-beat-underdog { --pf-c: #C9A2FF; }
  .pf-board .pf-beat-battle { --pf-c: #FFC83D; }
  .pf-board .pf-beat-double { --pf-c: #FFA24A; }
  .pf-board .pf-beat-revenge { --pf-c: #FF7A6B; }
  .pf-board .pf-chip.is-loss { --pf-c: #FF7A6B; }

  /* Bigger rooms: two columns of tighter rows (6 to 10 players), tighter still beyond that. */
  .pf-size-some .pf-board-card, .pf-size-many .pf-board-card { width: min(100%, 560px); gap: 10px; }
  .pf-size-some .pf-rows, .pf-size-many .pf-rows { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .pf-size-some .pf-row, .pf-size-many .pf-row { grid-template-columns: 26px minmax(0, 1fr) auto; column-gap: 7px; row-gap: 4px; padding: 7px 8px; border-radius: 12px; }
  .pf-size-some .pf-who, .pf-size-many .pf-who { width: 26px; height: 26px; }
  .pf-size-some .pf-who .avatar, .pf-size-many .pf-who .avatar { width: 26px !important; height: 26px !important; }
  .pf-size-some .pf-name, .pf-size-many .pf-name { font-size: 14px; }
  .pf-size-some .pf-name small, .pf-size-many .pf-name small { display: none; }
  .pf-size-some .pf-total, .pf-size-many .pf-total { font-size: 17px; min-width: 3.6ch; }
  .pf-size-some .pf-total small, .pf-size-many .pf-total small { display: none; }
  .pf-size-some .pf-chips, .pf-size-many .pf-chips { grid-column: 1 / -1; grid-row: 2; gap: 3px 4px; min-height: 20px; }
  .pf-size-some .pf-row, .pf-size-many .pf-row { grid-template-areas: "who name total" "chips chips chips"; }
  .pf-size-some .pf-chip, .pf-size-many .pf-chip { padding: 2px 6px; gap: 3px; }
  .pf-size-some .pf-chip b, .pf-size-many .pf-chip b { font-size: 13px; }
  .pf-size-some .pf-chip small, .pf-size-many .pf-chip small { font-size: 11px; }
  .pf-size-many .pf-row { padding: 5px 7px; }
  .pf-size-many .pf-board-head h2 { font-size: 20px; }
}

/* Landscape phones: short and wide, so the rows sit side by side and the head shrinks. */
@media (hover: none) and (pointer: coarse) and (max-width: 932px) and (orientation: landscape) {
  .pf-board.is-overlay { padding-top: calc(52px + env(safe-area-inset-top)); padding-bottom: calc(10px + env(safe-area-inset-bottom)); padding-right: max(12px, env(safe-area-inset-right)); }
  .pf-board-card { width: min(100%, 720px); gap: 8px; }
  .pf-board-head { grid-auto-flow: column; justify-content: center; align-items: center; gap: 12px; }
  .pf-board-head h2 { font-size: 20px; }
  .pf-rows { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 8px; }
  .pf-row { padding: 7px 10px 7px 9px; row-gap: 4px; }
  .pf-size-some .pf-board-card, .pf-size-many .pf-board-card { width: 100%; }
  .pf-size-some .pf-rows { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .pf-size-many .pf-rows { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  /* Ready floats bottom-right: the board keeps clear of it instead of sliding under. */
  body:has(.ready-skip) .pf-board.is-overlay { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  .pf-main, .pf-main.pf-out, .pf-board.is-overlay, .pf-board.is-overlay.is-on, .pf-chip, .pf-legend li { transition: none !important; }
  .pf-chip { transform: none; }
}

/* ---------- Battle ready and battle result ----------
   The target, topic and question screens have just shown the map with the tile, and the next map screen shows it
   again; here it only pushed the duel, the stakes and the scores off the bottom (or, sideways, squeezed them into
   a sliver). Without it the screen is the heading, who is fighting whom, and what is at stake (ready) or what
   everyone scored (result). */
@media (hover: none) and (pointer: coarse) and (max-width: 932px) {
  .main-stage > :is(.battle-ready, .battle-outcome) > .land-layout > .land-map-slot { display: none !important; }
  .main-stage > :is(.battle-ready, .battle-outcome) > .land-layout { grid-template-columns: minmax(0, 1fr) !important; grid-template-rows: minmax(0, 1fr) !important; }
  .main-stage > :is(.battle-ready, .battle-outcome) > .land-layout > .land-sidecar { grid-column: 1 / -1 !important; grid-row: 1 !important; width: 100% !important; max-width: none !important; height: auto !important; max-height: 100% !important; align-self: start; justify-self: center; box-sizing: border-box; }
  .main-stage > .battle-ready > .land-layout > .land-sidecar { margin-top: 5dvh; gap: 14px; align-items: center; }
  .main-stage > .battle-ready .land-panel-description { font-size: 18px !important; }
  /* In the page (battle result) the heading above already says what this is: the legend leads the board. */
  .pf-board.is-inline .pf-board-head h2 { display: none; }
  .pf-board.is-inline { margin-top: 10px; }
  .pf-board.is-inline .pf-rows { overflow: visible; gap: 6px; }
  /* A row with nothing to list stays one line tall. */
  .pf-row.is-blank { grid-template-columns: 32px minmax(0, 1fr) auto auto; grid-template-areas: "who name chips total"; }
  .pf-row.is-blank .pf-chips { min-height: 0; flex-wrap: nowrap; }
  .pf-size-some .pf-row.is-blank, .pf-size-many .pf-row.is-blank { grid-template-columns: 26px minmax(0, 1fr) auto; grid-template-areas: "who name total"; }
  .pf-size-some .pf-row.is-blank .pf-chips, .pf-size-many .pf-row.is-blank .pf-chips { display: none; }
}
/* Sideways: the heading and the duel on the left, the board on the right, using the full height. */
@media (hover: none) and (pointer: coarse) and (max-width: 932px) and (orientation: landscape) {
  .main-stage > .battle-outcome { display: grid !important; grid-template-columns: minmax(340px, 5fr) minmax(0, 8fr) !important; grid-template-rows: minmax(0, 1fr) auto auto minmax(0, 1fr) !important; column-gap: 16px; align-content: stretch !important; }
  .main-stage > .battle-outcome > .land-layout, .main-stage > .battle-outcome > .land-layout > .land-sidecar { display: contents !important; }
  .main-stage > .battle-outcome > .stage-timer { display: none !important; }
  .main-stage > .battle-outcome > .land-header { grid-column: 1; grid-row: 2; }
  .main-stage > .battle-outcome > .land-layout > .land-sidecar > :not(.pf-board) { grid-column: 1; grid-row: 3; justify-self: center; }
  .main-stage > .battle-outcome > .land-layout > .land-sidecar > .pf-board { grid-column: 2; grid-row: 1 / -1; align-self: center; margin-top: 0; max-height: 100%; min-height: 0; overflow-y: auto; }
  .main-stage > .battle-ready > .land-layout > .land-sidecar { margin-top: 0; }
}

/* ---------- Big rooms on a small screen ----------
   Past ten players (or six, sideways) the reasons no longer fit at a glance: chips keep their points and their
   type colour, and the legend above names each colour. */
@media (hover: none) and (pointer: coarse) and (max-width: 932px) {
  .pf-size-many .pf-chip:not(.pf-none) small { display: none; }
  .pf-size-many .pf-chips { min-height: 18px; }
}
@media (hover: none) and (pointer: coarse) and (max-width: 932px) and (orientation: landscape) {
  .pf-size-some .pf-chip:not(.pf-none) small { display: none; }
  .pf-size-some .pf-row, .pf-size-many .pf-row { grid-template-columns: 26px minmax(0, 1fr) auto auto; grid-template-areas: "who name chips total"; align-items: center; }
  .pf-size-some .pf-chips, .pf-size-many .pf-chips { grid-area: chips; grid-column: auto; grid-row: auto; flex-wrap: nowrap; min-height: 0; }
  .pf-size-some .pf-who, .pf-size-many .pf-who { align-self: center; }
}
@media (hover: none) and (pointer: coarse) and (max-width: 932px) and (orientation: landscape) {
  /* Three across keeps room for the names beside three chips. */
  .pf-size-many .pf-rows { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px 6px; }
  .pf-size-some .pf-name, .pf-size-many .pf-name { min-width: 3ch; }
}
@media (hover: none) and (pointer: coarse) and (max-width: 932px) and (orientation: landscape) {
  /* Sideways the reveal fills the height and scrolls, so your piece moves up into the header, beside the title. */
  body:has(.game-shell > .main-stage > :is(.question-screen.is-reveal, .geo-question.is-reveal, .review-with-votes, .battle-outcome, .battle-ready)) .emoji-quick {
    top: max(2px, env(safe-area-inset-top)); bottom: auto; left: calc(max(10px, env(safe-area-inset-left)) + 196px); width: 42px; height: 42px;
  }
  body:has(.game-shell > .main-stage > :is(.question-screen.is-reveal, .geo-question.is-reveal, .review-with-votes, .battle-outcome, .battle-ready)) .emoji-quick .avatar { width: 30px !important; height: 30px !important; }
}
