/* Accessibility fixes for phone and desktop clients: target sizes, minimum text sizes, focus rings. Loaded last. */

/* Rules carry #root so they outrank the class-only !important rules in the earlier sheets.
   The shared TV view (shared-* classes) is styled in tv-a11y.css and is left alone here. */

/* ---------------------------------------------------------------------------------------------
   1. Hit areas (WCAG 2.5.8, 24px minimum on every device).
   A transparent ::before overlay grows the clickable area around the centre of a small control.
   The control keeps its painted size, so nothing around it moves. ::after stays free for the
   keyboard-hint labels. --a11y-hit is the wanted minimum side.
   --------------------------------------------------------------------------------------------- */
#root :is(
  .player-name-row > .player-mute-button,
  .lobby-name-button,
  .lobby-player-admin .quiet-button,
  .topbar > .brand,
  .win-fx-toggles label,
  .bot-step
) { position: relative; }

#root :is(
  .player-mute-button,
  .lobby-name-button,
  .lobby-player-admin .quiet-button,
  .topbar > .brand,
  .win-fx-toggles label,
  .bot-step
)::before {
  content: "";
  position: absolute;
  inset: min(0px, (100% - var(--a11y-hit, 24px)) / 2);
}

/* The in-game name button clips its text with overflow:hidden, which would also clip an overlay.
   Padding with an equal negative margin makes the box itself taller and leaves the row height alone. */
#root .player-name-row > button.player-name.emoji-name-button { padding-block: 5px !important; margin-block: -5px !important; }

/* The strip is the bottom edge of the page and has the score right under the name row: the mute button grows up.
   In a full 14-player strip the next card covers its right 7px, so it grows 8px further left, over the end of its own name. */
#root#root .player-name-row > .player-mute-button::before { top: min(0px, 100% - var(--a11y-hit, 24px)); bottom: 0; left: min(0px, 100% - var(--a11y-hit, 24px) - 8px); right: 0; }

/* ---------------------------------------------------------------------------------------------
   2. Touch targets on phones: 44px where the control has room, never under 40px.
   Same overlay as above with a 44px minimum. Controls that sit against a neighbour or a clipping
   edge grow away from it instead of around their centre.
   --------------------------------------------------------------------------------------------- */
@media (hover: none) and (pointer: coarse) and (max-width: 932px) {
  #root :is(
    .lobby-tab, .randomise-button, .preview-animations-button, .room-code, .lobby-players-head, .lobby-topics-head,
    .order-arrows button, .order-area > button.primary, .word-hint-button,
    .icon-button, .profile-top-button, .ready-skip-button, .emoji-piece-button,
    .question-upvote-button, .question-report-button,
    .map-roll-button, .lobby-options label > button, .map-choice-row > button,
    .final-breakdown, .final-screen .button-row > button,
    .lobby label:has(> input, > select)
  ) { position: relative; }

  #root :is(
    .lobby-tab, .randomise-button, .preview-animations-button, .room-code, .lobby-players-head, .lobby-topics-head,
    .order-arrows button, .order-area > button.primary, .word-hint-button, .answer-option,
    .icon-button, .profile-top-button, .ready-skip-button, .emoji-piece-button,
    .question-upvote-button, .question-report-button,
    .map-roll-button, .lobby-options label > button, .map-choice-row > button,
    .final-breakdown, .final-screen .button-row > button,
    .lobby label:has(> input, > select)
  )::before,
  body > .emoji-quick::before {
    content: "";
    position: absolute;
    inset: min(0px, (100% - 44px) / 2);
  }
  #root :is(.player-mute-button, .lobby-name-button, .lobby-player-admin .quiet-button, .topbar > .brand, .win-fx-toggles label, .bot-step) { --a11y-hit: 44px; }

  /* Bot stepper: each 28px step button grows 18px over the count between them, not over the next field. */
  #root#root .bot-stepper > .bot-step::before { top: min(0px, 100% - 40px); bottom: -4px; }
  #root#root .bot-stepper > .bot-step:first-child::before { left: 0; right: -18px; }
  #root#root .bot-stepper > .bot-step:last-child::before { left: -18px; right: 0; }

  /* Lobby mute button sits in the card corner above the host buttons: it grows up and to the left. */
  #root#root .lobby-player > .player-mute-button::before { top: calc(100% - 40px); bottom: 0; left: calc(100% - 38px); right: -6px; }

  /* Like and dislike sit side by side against the right edge of the stage: 44px tall, and the left one grows left. */
  #root#root .question-report-button::before { left: 0; right: 0; }
  #root#root .question-upvote-button::before { left: min(0px, 100% - 44px); right: 0; }

  /* The dice button sits against the edge of its column: 44px tall, no sideways growth. */
  #root#root .map-roll-button::before { left: 0; right: 0; }

  /* Avatar, colour and accessory tiles sit in rows that clip an overlay, so the tiles themselves go from 42px to 44px. */
  #root .identity-choice { min-width: 44px !important; min-height: 44px !important; flex-basis: 44px !important; }

  /* Room code: the lobby scroller clips anything above it, so the code grows down into the gap. */
  #root#root .room-code::before { top: 0; bottom: min(0px, 100% - 40px); }

  /* Final screen buttons sit on the bottom edge of the screen: they grow up. */
  #root#root .final-screen .button-row > button::before { bottom: 0; top: min(0px, 100% - 44px); }

  /* The seat name clips long names with overflow:hidden. Padding with an equal negative margin gives
     the edit button's 44px overlay room inside that clip and keeps the card rows where they were. */
  #root .lobby-player > .lobby-seat-name:has(> .lobby-name-button) { padding-block: 11px; margin-block: -11px; }
  /* On the character stage the name is centred with room around it. The button text keeps its own ellipsis. */
  #root .lobby-character-stage > .lobby-seat-name:has(> .lobby-name-button) { overflow: visible; }

  /* Section heads sit right under the room code: they grow down only. */
  #root#root :is(.lobby-players-head, .lobby-topics-head)::before { top: 0; bottom: min(0px, 100% - 44px); }
}

@media (hover: none) and (pointer: coarse) and (max-width: 932px) {
  /* The attack-order toggle is static on phones; top/left belong to its desktop absolute position. */
  #root .battle-round-track .battle-track-toggle { position: relative !important; top: auto !important; left: auto !important; right: auto !important; }
  #root .battle-round-track .battle-track-toggle::before { content: ""; position: absolute; inset: min(0px, (100% - 44px) / 2); }

  /* Host buttons in a player card: 40px tall for real (the card grows), plus 4px of overlay below. */
  #root .lobby .lobby-player .lobby-player-admin .quiet-button { min-height: 40px !important; height: 40px !important; min-width: 40px !important; padding-inline: 3px !important; font-size: 12px !important; }
  #root .lobby .lobby-player .lobby-player-admin { gap: 3px !important; }
  #root#root .lobby .lobby-player .lobby-player-admin .quiet-button::before { top: 0; bottom: -4px; left: 0; right: 0; }

  /* -------------------------------------------------------------------------------------------
     3. Minimum text size on phones: 12px.
     ------------------------------------------------------------------------------------------- */
  #root :is(
    .bot-seat-config > strong, .bot-difficulty-summary, .map-credit, .player-score-delta small, .battle-track-heading span,
    .room-code-label, .pf-total small, .player-score small, .hl-detail, .pf-legend li, .hl-kicker, .you-label, .final-row strong,
    .win-fx-toggles legend, .win-fx-toggles-hint, .bot-settings-disclosure > summary > span, .bot-count,
    .lobby-player > span, .lobby-options label > button, .lobby-options label > button span, .map-choice-row > button, .map-choice-row > button span
  ) { font-size: 12px !important; }

  /* Bot settings: one seat per row, wrapping, with readable labels and full-size fields.
     Before, two seats shared a row and the number field was squeezed to 10px wide. */
  #root .bot-difficulty-grid { grid-template-columns: minmax(0, 1fr) !important; gap: 6px !important; }
  #root .bot-seat-config { flex-wrap: wrap; gap: 4px 10px !important; padding: 6px 8px !important; }
  #root .bot-difficulty { flex-wrap: wrap; gap: 4px 12px !important; }
  #root .bot-difficulty label { flex: 0 0 auto; gap: 6px !important; font-size: 12px !important; }
  #root .bot-difficulty input { flex: 0 0 auto; width: 52px !important; height: 40px !important; min-height: 40px !important; font-size: 14px !important; }
  #root .bot-difficulty select { flex: 0 0 auto; width: auto; max-width: 150px !important; height: 40px !important; min-height: 40px !important; padding: 3px 6px !important; font-size: 13px !important; }
}

@media (hover: none) and (pointer: coarse) and (max-width: 932px) and (orientation: landscape) {
  /* The landscape top bar is 44px high with the title 14px under its top edge: 40px is what fits. */
  #root .topbar > .brand { --a11y-hit: 40px; }

  /* Question timers in landscape: 21px-high fields become 40px, the same as in portrait. */
  #root .duration-grid label { grid-template-columns: minmax(0, 1fr) 48px !important; }
  #root .map-roll-button { width: 40px !important; min-width: 40px !important; height: 40px !important; min-height: 40px !important; }
  #root .duration-grid input { width: 48px !important; height: 40px !important; min-height: 40px !important; font-size: 14px !important; }
}

/* ---------------------------------------------------------------------------------------------
   4. Map tiles: keyboard focus and controller focus (data-pad-focus).
   after-dark.css ("Input access") already draws the ring: a solid lime #D8FF36 stroke, 7px, that
   follows the tile outline, with no box outline. Lime has 16:1 against the board but under 3:1
   against the light player colours (#FFE23D 1.1:1, #86D542 1.6:1), and a focused tile is painted in
   the player colour. Two things are added here and nothing else is changed:
   - the focused tile is filled with the player colour mixed 40% into the board colour, so the lime
     ring has 4.8:1 or more against its own tile for every colour in the palette;
   - a dark edge sits outside the ring, between it and light neighbours. The brightness filter is
     dropped because it would lighten the fill again.
   --------------------------------------------------------------------------------------------- */
#root svg.candy-board path.tile:is(:focus-visible, [data-pad-focus]):not([class*="shared-"] *) {
  fill: color-mix(in srgb, var(--player, #3b2b52) 40%, #120A1F) !important;
  filter: drop-shadow(0 0 3px #120A1F) drop-shadow(0 0 3px #120A1F) drop-shadow(0 0 5px #D8FF36) !important;
}
