/* Phone landscape only. Portrait and setup retain their original styles.
   Reuse the same DOM: rotating must never recreate a round or its audio clock. */
@media (orientation: landscape) and (min-width: 568px) and (max-height: 560px) {
  html:has(body[data-view="match"]) { height: 100%; overflow: hidden; overscroll-behavior: none; }
  body[data-view="match"] { height: 100%; overflow: hidden; overscroll-behavior: none; }

  body[data-view="match"] .full-game {
    --portrait-gutter: 40px;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    max-width: none;
    padding: max(8px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr) 148px;
    grid-template-rows: 44px 44px minmax(0, 1fr);
    gap: 6px 12px;
    overflow: hidden;
  }
  body[data-view="match"] :is(.topbar, .match-view, .match-bar) { display: contents; }
  body[data-view="match"] .wordmark { grid-area: 1 / 1; align-self: center; }
  body[data-view="match"] .top-actions { grid-area: 1 / 3; justify-content: flex-end; }
  body[data-view="match"] #pool-label {
    grid-area: 1 / 2;
    align-self: center;
    justify-self: start;
    max-width: 100%;
  }
  body[data-view="match"] .match-details { grid-area: 2 / 3; align-self: center; }
  body[data-view="match"] .scoreboard {
    grid-area: 2 / 1 / 3 / 3;
    min-width: 0;
    gap: 6px;
    padding: 1px 1px 3px;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    touch-action: pan-x;
    scrollbar-width: none;
  }
  body[data-view="match"] .scoreboard::-webkit-scrollbar { display: none; }
  body[data-view="match"] .score-chip {
    min-width: 108px;
    grid-template-columns: 25px minmax(0, 1fr);
    column-gap: 6px;
    padding: 4px 9px;
    border-radius: 12px;
  }
  body[data-view="match"] .score-avatar { font-size: 23px; }
  body[data-view="match"] .score-name { font-size: 12px; }
  body[data-view="match"] .score-lives { font-size: 10px; margin-top: 1px; }

  body[data-view="match"] .round-view {
    grid-area: 3 / 1 / 4 / -1;
    min-height: 0;
    padding: 0;
    grid-template-columns: calc(100vh - var(--portrait-gutter)) minmax(0, 1fr);
    grid-template-columns: calc(100svh - var(--portrait-gutter)) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) 48px 18px;
    gap: 6px 16px;
    align-content: stretch;
    container-type: size;
  }
  body[data-view="match"] :is(.question-side, .timer-side) { display: contents; }
  body[data-view="match"] .question {
    grid-area: 1 / 1;
    top: 0;
    width: 100%;
    font-size: clamp(28px, 7.6vh, 37px);
    font-size: clamp(28px, 7.6svh, 37px);
    line-height: 1.15;
    min-height: 3.45em;
    letter-spacing: -1px;
    text-align: center;
  }
  body[data-view="match"] .draw-button {
    grid-area: 2 / 1;
    justify-self: center;
    min-height: 48px;
    margin: 0;
    padding-block: 9px;
  }
  body[data-view="match"] .timer-side .dial {
    grid-area: 1 / 2;
    justify-self: center;
    /* Viewport fallback for iOS versions without container units. */
    width: min(100%, calc(100vh - 178px - max(8px, env(safe-area-inset-top)) - max(8px, env(safe-area-inset-bottom))));
    width: min(100%, calc(100cqh - 78px));
    height: auto;
    aspect-ratio: 1;
    margin: 0;
    container-type: size;
  }
  body[data-view="match"] .timer-side .potato { font-size: clamp(80px, calc(68vh - 132px), 220px); font-size: 68cqw; }
  body[data-view="match"] .dial-face { inset: 12%; }
  body[data-view="match"] .orbit-inner { inset: 6%; }
  body[data-view="match"] .dial-label { display: none; }
  body[data-view="match"] .round-button {
    grid-area: 2 / 2;
    justify-self: center;
    width: 100%;
    max-width: 340px;
    min-height: 48px;
    height: 48px;
    font-size: 17px;
    border-radius: 17px;
  }
  body[data-view="match"] #round-note {
    grid-area: 3 / 2;
    justify-self: center;
    margin: 0;
    font-size: 11px;
    line-height: 18px;
    text-align: center;
  }

  /* Keep loss selection and results on screen too, including twelve players. */
  body[data-view="match"] .resolution-view {
    grid-area: 3 / 1 / 4 / -1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: 18px auto minmax(0, 1fr) 44px;
    gap: 6px 12px;
    max-width: none;
    min-height: 0;
    height: 100%;
    padding: 0;
    margin: 0;
    align-items: center;
  }
  body[data-view="match"] .resolution-view > .eyebrow { grid-area: 1 / 2 / 2 / 4; margin: 0; font-size: 10px; }
  body[data-view="match"] .resolution-view h1 { grid-area: 2 / 2 / 3 / 4; font-size: 26px; line-height: 1.1; }
  body[data-view="match"] .resolution-note { grid-area: 3 / 2 / 4 / 4; margin: 0; font-size: 13px; line-height: 1.35; }
  body[data-view="match"] .result-avatar { grid-area: 1 / 1 / 3 / 2; margin: 0; font-size: 64px; }
  body[data-view="match"] .result-hearts { grid-area: 3 / 1; margin: 0; gap: 3px; font-size: 14px; }
  body[data-view="match"] .winner-mark { grid-area: 1 / 1 / 4 / 2; }
  body[data-view="match"] .winner-mark > span:first-child { font-size: 32px; }
  body[data-view="match"] .resolution-view :is(.start-button, .secondary-button, .text-button) {
    min-height: 44px;
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 6px 9px;
    font-size: 13px;
    border-radius: 15px;
  }
  body[data-view="match"] :is(#next-round, #rematch) { grid-area: 4 / 1; }
  body[data-view="match"] #undo-loss { grid-area: 4 / 2 / 5 / 4; }
  body[data-view="match"] #new-game { grid-area: 4 / 2; }
  body[data-view="match"] #undo-final { grid-area: 4 / 3; }
  body[data-view="match"] #boom-view {
    grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr);
    grid-template-rows: 32px 16px minmax(0, 1fr) 44px;
  }
  body[data-view="match"] #boom-view .resolution-icon { grid-area: 1 / 1; font-size: 30px; margin: 0; }
  body[data-view="match"] #boom-view .eyebrow { grid-area: 2 / 1; }
  body[data-view="match"] #boom-title { grid-area: 3 / 1; }
  body[data-view="match"] #boom-view .resolution-note { grid-area: 4 / 1; }
  body[data-view="match"] .loss-players {
    grid-area: 1 / 2 / 4 / 3;
    align-self: stretch;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-auto-rows: minmax(44px, 1fr);
    gap: 5px;
    margin: 0;
  }
  body[data-view="match"] .loss-player {
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr);
    align-content: center;
    gap: 1px 4px;
    padding: 3px;
    border: 2px solid #b274594f;
    border-radius: 12px;
  }
  body[data-view="match"] .loss-player[aria-pressed="true"] { border-color: var(--yellow); }
  body[data-view="match"] .loss-avatar { grid-row: span 2; font-size: 23px; }
  body[data-view="match"] .loss-name { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  body[data-view="match"] .loss-lives { font-size: 10px; }
  body[data-view="match"] #confirm-loss { grid-area: 4 / 2; }
  body[data-view="match"] #match-error {
    position: fixed;
    bottom: max(8px, env(safe-area-inset-bottom));
    left: max(20px, env(safe-area-inset-left));
    right: max(20px, env(safe-area-inset-right));
    z-index: 5;
    margin: 0;
    padding: 10px;
    border-radius: 12px;
    background: var(--background);
  }
}

@media (orientation: landscape) and (min-width: 568px) and (max-height: 370px) {
  body[data-view="match"] .full-game { --portrait-gutter: 28px; }
  body[data-view="match"] #round-note { font-size: 10px; }
}
