/* The largest mode and online subview establish one padded, stable setup frame. */
body#top[data-page='play'] #setup-screen :is(.mode-card, .mode-card-icon, .mode-card::before) {
  transition: none !important;
}
body#top[data-page='play'] #setup-screen .setup-panels-wrapper > :is(#panel-hotseat, #panel-ai, #panel-online) {
  transition: none !important;
  animation: none !important;
}
/* Hidden panels keep their dimensions, but no child may animate inherited visibility. */
body#top[data-page='play'] #setup-screen .setup-panels-wrapper * {
  transition-property: color, background-color, border-color, box-shadow !important;
  transition-delay: 0s !important;
}
body#top[data-page='play'] #setup-screen .setup-panels-wrapper [data-lobby-inactive='true'],
body#top[data-page='play'] #setup-screen .setup-panels-wrapper [data-lobby-inactive='true'] * {
  visibility: hidden !important;
  pointer-events: none !important;
  transition: none !important;
}
html:not([data-phone-device='true']) body#top[data-page='play'] #setup-screen .mode-card {
  /* Every card keeps the former selected size; color and glow indicate selection. */
  transform: scale(1.04) !important;
}
body#top[data-page='play'] #setup-screen .setup-panels-wrapper {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto;
  align-items: stretch;
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  padding: 12px !important;
  box-sizing: border-box;
}
body#top[data-page='play'] #setup-screen .setup-panels-wrapper > :is(#panel-hotseat, #panel-ai, #panel-online) {
  grid-area: 1 / 1;
  display: flex !important;
  height: auto !important;
  width: 100% !important;
  min-width: 0;
  align-self: stretch;
}
body#top[data-page='play'] #setup-screen .setup-panels-wrapper > #panel-online {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
}
body#top[data-page='play'] #setup-screen #panel-online > :is(#online-setup-view, #online-active-session-view) {
  grid-area: 1 / 1;
  display: flex !important;
  height: auto !important;
  min-height: 0 !important;
  width: 100%;
  justify-content: flex-start !important;
  gap: 8px;
}
body#top[data-page='play'] #setup-screen :is(#panel-hotseat, #panel-ai, #panel-online, #online-setup-view, #online-active-session-view, #host-room-info, #online-join-section, #btn-host-match)[style*='display: none'] {
  visibility: hidden !important;
  pointer-events: none !important;
}
body#top[data-page='play'] #setup-screen #online-setup-view > .online-box {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto;
  min-height: 0 !important;
  width: 100%;
  max-width: 350px !important;
  padding: 8px !important;
  gap: 8px !important;
}
body#top[data-page='play'] #setup-screen #btn-host-match {
  grid-area: 1 / 1;
  display: flex !important;
  align-items: center;
  justify-content: center;
}
body#top[data-page='play'] #setup-screen #online-join-section {
  grid-area: 2 / 1;
  display: flex !important;
  min-width: 0;
  gap: 8px !important;
}
body#top[data-page='play'] #setup-screen #host-room-info {
  grid-area: 1 / 1 / 3 / 2;
  display: flex !important;
  height: auto;
  min-height: 0;
  width: 100%;
  padding: 10px !important;
  gap: 8px !important;
}
body#top[data-page='play'] #setup-screen #panel-online :is(button, input) {
  min-height: 44px !important;
  height: 44px !important;
  box-sizing: border-box;
  font-size: 12px !important;
}
body#top[data-page='play'] #setup-screen #online-join-status {
  display: block !important;
  height: 28px;
  min-height: 28px;
  line-height: 14px;
  margin: 0;
}
body#top[data-page='play'] #setup-screen #online-active-session-view > .online-box {
  min-height: 0;
  width: 100%;
  max-width: 350px;
  padding: 8px !important;
  gap: 8px !important;
}

/* Preserve the consistency layer's geometry and add padding around all three modes. */
@media (min-width: 1101px), (min-width: 700px) and (min-height: 600px) {
  html:not([data-phone-device='true']) body#top[data-page='play']:not(.phone-match-active) #setup-screen .setup-panels-wrapper {
    display: grid !important;
    height: auto !important;
    min-height: 0 !important;
    padding: 12px !important;
  }
  html:not([data-phone-device='true']) body#top[data-page='play']:not(.phone-match-active) #setup-screen .setup-panels-wrapper > :is(#panel-hotseat, #panel-ai) {
    min-height: var(--lobby-duel-height);
  }
}

/* Phone forms use the same reserved result and action rows in every mode. */
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .setup-panels-wrapper {
  display: grid !important;
  padding: 12px !important;
  min-height: 0 !important;
}
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .setup-panels-wrapper > :is(#panel-hotseat, #panel-ai) {
  gap: 0 !important;
  justify-content: flex-start !important;
}
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #panel-ai > .setup-body {
  min-height: 34px;
  margin: 0 0 8px !important;
  font: 500 12px/17px Inter, sans-serif !important;
}
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .rolloff-wrap {
  gap: 6px !important;
  min-height: 0 !important;
  margin: 0 !important;
}
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .lobby-faction-grid {
  margin: 0 !important;
  gap: 14px !important;
}
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .lobby-faction-card {
  gap: 3px !important;
  padding: 2px 8px !important;
}
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .lobby-faction-card > .ai-role-tag {
  height: 14px;
  min-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: 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/12px Orbitron, sans-serif !important;
}
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #ai-ro-result {
  height: 22px;
  min-height: 22px !important;
  margin: 0 !important;
  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: 12px 0 0 !important; margin: 0 !important; }
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen :is(#btn-ai-rolloff, #btn-ai-start) { min-height: 44px; height: 44px; }
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #panel-online .setup-body {
  min-height: 34px;
  margin: 0 !important;
  font: 500 12px/17px Inter, sans-serif !important;
}
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #panel-online input { font-size: 16px !important; letter-spacing: 1px !important; }
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #host-room-info {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: auto 44px 44px;
  padding: 8px !important;
  gap: 6px !important;
}
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #host-room-info > div:first-child { grid-column: 1; grid-row: 1; align-self: center; font-size: 9px !important; letter-spacing: 1px !important; }
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #display-room-code { grid-column: 2; grid-row: 1; font-size: 20px !important; letter-spacing: 2px !important; }
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #host-room-info > div:nth-child(3) { grid-column: 1 / -1; grid-row: 2; margin: 0 !important; gap: 6px !important; }
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #online-host-status { grid-column: 1; grid-row: 3; font-size: 10px !important; line-height: 1.35; text-align: left; margin: 0 !important; }
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #btn-cancel-host { grid-column: 2; grid-row: 3; min-width: 0; padding: 4px !important; margin: 0 !important; font-size: 10px !important; letter-spacing: 0 !important; }
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #online-setup-view > .online-box { padding: 0 !important; border: 0 !important; }
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #online-active-session-view > .online-box {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: auto auto;
  padding: 6px !important;
  gap: 6px 8px !important;
}
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #online-active-session-view > .online-box > div:first-child { grid-column: 1 / -1; grid-row: 1; }
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #online-active-session-view > .online-box > div:nth-child(2) { grid-column: 1; grid-row: 2; align-self: center; margin: 0 !important; }
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #online-active-session-view > .online-box > div:nth-child(3) { grid-column: 2; grid-row: 2; margin: 0 !important; gap: 6px !important; }
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #active-session-code { font-size: 20px !important; letter-spacing: 2px !important; }
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #active-session-role { font-size: 10px !important; line-height: 1.35; letter-spacing: 0 !important; }
html[data-phone-device='true'] body#top[data-page='play'] #setup-screen :is(#btn-rejoin-game, #btn-remove-connection) { min-width: 0; padding: 4px !important; font-size: 10px !important; letter-spacing: .2px !important; }

@media (orientation: landscape) and (max-height: 599px) {
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen.modal { padding-block: max(8px, env(safe-area-inset-top, 0px)) max(8px, env(safe-area-inset-bottom, 0px)); }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .setup-panels-wrapper { padding: 7px !important; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #panel-ai > .setup-body { min-height: 30px; margin-bottom: 4px !important; font: 500 12px/15px Inter, sans-serif !important; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .lobby-faction-card { padding-block: 0 !important; gap: 2px !important; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .lobby-faction-card > .ai-role-tag { height: 10px; min-height: 10px; padding: 0 4px; font: 800 8px/10px Inter, sans-serif; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .lobby-faction-card > .ro-val { width: 44px !important; height: 44px !important; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .lobby-faction-card > .ai-faction-name { font-size: 9px !important; line-height: 10px !important; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .rolloff-wrap { gap: 4px !important; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #ai-ro-result { height: 18px; min-height: 18px !important; }
}

@media (orientation: landscape) and (max-height: 350px) {
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .mode-card { height: 44px !important; min-height: 44px; padding: 4px 8px; gap: 2px 8px; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .mode-card-title { font-size: 12px !important; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .mode-card-sub { font-size: 10px !important; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .mode-card-icon svg { width: 22px; height: 22px; }
}

@media (orientation: portrait) and (max-height: 760px) {
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen.modal { padding-block: 12px; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .subscribe-content { gap: 12px; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .subscribe-content > div:first-child > img { width: 32px !important; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .setup-title { font-size: 18px !important; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .mode-card { height: 78px; min-height: 78px; padding: 6px; gap: 4px; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .mode-card-icon svg { width: 24px; height: 24px; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen #btn-start-tutorial { min-height: 44px; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-device-note { margin-top: 8px; font-size: 11px; line-height: 15px; }
}
@media (orientation: portrait) and (max-height: 620px) {
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .subscribe-content { gap: 8px; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .subscribe-content > div:first-child { display: none !important; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .mode-card { height: 64px; min-height: 64px; padding: 4px; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .mode-card-icon svg { width: 20px; height: 20px; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .mode-card-title { font-size: 12px !important; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .mode-card-sub { font-size: 10px !important; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .setup-panels-wrapper { padding: 10px !important; }
  html[data-phone-device='true'] body#top[data-page='play'] #setup-screen .lobby-faction-card > .ro-val { width: 44px !important; height: 44px !important; }
}
