/* Phone setup uses a centered content column inside the shared stable frame. */
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen :is(.lobby-faction-card, .ro-val, .setup-panels-wrapper, .subscribe-mega-card, .subscribe-content) {
  transition: none;
}
body#top[data-page='play'] #setup-screen .mode-card { touch-action: manipulation; }
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .setup-panels-wrapper > :is(#panel-hotseat, #panel-ai, #panel-online) {
  width: min(360px, 100%) !important;
  max-width: 360px;
  justify-self: center;
}
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen :is(#panel-hotseat, #panel-ai) > :is(.setup-body, .rolloff-wrap, .setup-rules) {
  width: 100% !important;
  max-width: 360px !important;
  box-sizing: border-box;
}
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #panel-online > :is(#online-setup-view, #online-active-session-view) {
  width: 100%;
  max-width: 360px;
  margin-inline: auto;
}
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen :is(#panel-hotseat, #panel-ai) > .setup-rules > .btn {
  margin-inline: auto;
  justify-content: center;
}

/* On short phones the existing compact form remains within the available height. */
@media (orientation: landscape) and (max-height: 599px) {
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen { --lobby-spacing-inset: 7px; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .setup-panels-wrapper { padding: var(--lobby-spacing-inset) !important; }
}

/* Use larger dice and clear rhythm once the field can accommodate them. */
@media (orientation: landscape) and (min-height: 390px) and (max-height: 599px) {
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen {
    --lobby-spacing-inset: clamp(10px, calc((100dvh - 344px - max(8px, env(safe-area-inset-bottom, 0px))) / 2), 18px);
  }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #panel-ai > .setup-body {
    min-height: 32px;
    margin: 0 0 6px !important;
    font: 500 12px/16px Inter, sans-serif !important;
  }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .rolloff-wrap { gap: 6px !important; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .lobby-faction-grid { gap: 14px !important; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .lobby-faction-card {
    width: 80px;
    min-width: 80px;
    padding: 2px 8px !important;
    gap: 3px !important;
    box-sizing: border-box;
  }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .lobby-faction-card > .ai-role-tag {
    min-height: 12px;
    height: 12px;
    padding: 1px 4px;
    font: 800 9px/10px Inter, sans-serif;
  }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .lobby-faction-card > .ro-val { width: 48px !important; height: 48px !important; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .lobby-faction-card > .ai-faction-name { font: 800 10px/10px Orbitron, sans-serif !important; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #ai-ro-result {
    min-height: 20px !important;
    height: 20px;
    font: 700 12px/17px Inter, sans-serif !important;
  }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #panel-ai > .setup-rules { padding-top: 12px !important; }
}

@media (orientation: landscape) and (min-height: 420px) and (max-height: 599px) {
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen {
    --lobby-spacing-inset: clamp(12px, calc((100dvh - 374px - max(8px, env(safe-area-inset-bottom, 0px))) / 2), 20px);
  }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #panel-ai > .setup-body {
    min-height: 34px;
    margin-bottom: 8px !important;
    line-height: 17px !important;
  }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .rolloff-wrap { gap: 8px !important; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .lobby-faction-grid { gap: 18px !important; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .lobby-faction-card {
    width: 88px;
    min-width: 88px;
    padding: 4px 10px !important;
    gap: 4px !important;
  }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .lobby-faction-card > .ai-role-tag {
    min-height: 14px;
    height: 14px;
    padding: 2px 4px;
    font: 800 9px/10px Inter, sans-serif;
  }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .lobby-faction-card > .ro-val { width: 56px !important; height: 56px !important; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .lobby-faction-card > .ai-faction-name { line-height: 12px !important; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #ai-ro-result { min-height: 24px !important; height: 24px; }
}

@media (orientation: portrait) and (min-height: 720px) {
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .setup-panels-wrapper { padding: 18px !important; }
}

/* Center the faction cards between the buttons; the result uses their lower gap. */
@media (orientation: landscape) and (min-height: 301px) and (max-height: 599px) {
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #panel-ai.lobby-duel-panel {
    --lobby-faction-height: 70px;
    --lobby-result-space: 20px;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 44px minmax(calc(var(--lobby-faction-height) + 2 * var(--lobby-result-space)), 1fr) 44px;
    gap: 8px !important;
    position: relative;
    align-items: center;
  }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #panel-ai > .setup-body {
    grid-row: 1; margin: 0 !important;
  }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #panel-ai > .rolloff-wrap { display: contents; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #panel-ai #btn-ai-rolloff {
    grid-column: 1; grid-row: 2; margin: 0 !important;
  }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #panel-ai .lobby-faction-grid {
    grid-column: 1; grid-row: 3; height: var(--lobby-faction-height); align-self: center;
  }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #panel-ai .lobby-faction-card { height: var(--lobby-faction-height); }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #panel-ai #ai-ro-result {
    grid-column: 1; grid-row: 3; align-self: end;
    display: grid; place-items: end center; margin: 0 !important;
    min-height: var(--lobby-result-space) !important; height: var(--lobby-result-space);
    line-height: 16px !important;
  }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #panel-ai > .setup-rules {
    grid-column: 1; grid-row: 4; padding: 0 !important; margin: 0 !important;
  }
}
@media (orientation: landscape) and (min-height: 301px) and (max-height: 350px) {
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #panel-ai.lobby-duel-panel {
    grid-template-rows: 44px minmax(calc(var(--lobby-faction-height) + 2 * var(--lobby-result-space)), 1fr) 44px;
    gap: 6px !important;
  }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #panel-ai #btn-ai-rolloff { grid-row: 1; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #panel-ai :is(.lobby-faction-grid, #ai-ro-result) { grid-row: 2; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #panel-ai > .setup-rules { grid-row: 3; }
}
@media (orientation: landscape) and (min-height: 390px) and (max-height: 419px) {
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #panel-ai.lobby-duel-panel { --lobby-faction-height: 84px; }
}
@media (orientation: landscape) and (min-height: 420px) and (max-height: 599px) {
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #panel-ai.lobby-duel-panel { --lobby-faction-height: 98px; --lobby-result-space: 22px; }
}

/* Browser chrome can leave only 280px of height; keep every primary target 44px. */
@media (orientation: landscape) and (max-height: 300px) {
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen { --lobby-spacing-inset: 6px; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .subscribe-content { gap: 6px 20px; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .mode-cards-container {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(2, 44px);
    gap: 6px;
    align-content: center;
  }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #card-mode-online { grid-column: 1 / -1; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .mode-card {
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 44px !important;
    min-height: 44px;
    padding: 4px;
    gap: 2px;
  }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .mode-card-icon { display: none; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .mode-card-title { font-size: 11px !important; line-height: 13px; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .mode-card-sub { font-size: 9px !important; line-height: 11px; letter-spacing: 0; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #panel-ai > .rolloff-wrap {
    display: grid;
    grid-template-columns: minmax(88px, .8fr) minmax(154px, 1.2fr);
    grid-template-rows: 44px 28px;
    align-items: center;
    gap: 4px 8px !important;
  }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #btn-ai-rolloff {
    grid-column: 1;
    grid-row: 1;
    padding: 4px !important;
    font-size: 10px !important;
    letter-spacing: 1px !important;
  }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #panel-ai .lobby-faction-grid {
    grid-column: 2;
    grid-row: 1 / 3;
    gap: 8px !important;
  }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #ai-ro-result {
    grid-column: 1;
    grid-row: 2;
    min-height: 28px !important;
    height: 28px;
    font: 700 10px/14px Inter, sans-serif !important;
  }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #panel-online .setup-body { display: none !important; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #online-join-status {
    min-height: 20px;
    height: 20px;
    font: 500 10px/10px Inter, sans-serif;
  }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #online-join-section > div:first-child { line-height: 12px !important; margin-block: 2px !important; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .phone-hotseat-notice h3 {
    margin-bottom: 6px;
    font: 700 13px/16px Orbitron, sans-serif;
  }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .phone-hotseat-notice p { font: 500 12px/16px Inter, sans-serif; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #panel-hotseat > .rolloff-wrap { margin-top: 8px !important; }
  /* The Online panel already contains the same rejoin/remove actions. */
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #resume-room-banner { display: none !important; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-device-note { margin-top: 4px; font-size: 10.5px; line-height: 14px; }
}
