/* Public lineup: pitch and bench form one surface; the roster remains a
   compact companion. Card geometry is owned by lineup-presentation.css. */
body:is(.teams-directory-page, .team-page) .site-main {
  padding: 12px 0 28px;
}

:is(.teams-directory-page, .team-page) .lineup-stadium {
  --lineup-bottom-reserve: 80px;
}

.teams-directory-page .team-selector-workspace {
  gap: 12px;
}

.teams-directory-page .team-selector-head,
.team-page .team-page-hero {
  min-height: 88px;
  padding: 12px 16px;
  gap: 12px;
}

.teams-directory-page .team-selector-head .team-crest-large,
.team-page .team-page-hero .team-crest-large {
  width: 58px;
  height: 58px;
}

.teams-directory-page .team-selector-head .team-selector-identity h2,
.team-page .team-page-hero h1 {
  margin-block: 2px;
  font-size: clamp(24px, 1.8vw, 36px);
}

.teams-directory-page .team-selector-panels {
  width: calc(100% - 20px);
  margin: 10px;
  padding: 0;
  gap: 12px;
}

body:is(.teams-directory-page, .team-page) .lineup-public-card > header,
body:is(.teams-directory-page, .team-page) .roster-public-card > header {
  min-height: 54px;
  padding: 9px 14px;
  gap: 8px;
}

:is(.teams-directory-page, .team-page) .lineup-public-card > header h2,
:is(.teams-directory-page, .team-page) .roster-public-card > header h2 {
  margin: 0;
  font-size: 20px;
}

:is(.teams-directory-page, .team-page) .lineup-public-card > header > div:first-child,
:is(.teams-directory-page, .team-page) .roster-public-card > header > div:first-child {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.teams-directory-page .team-selector-rail {
  height: clamp(400px, calc(100dvh - 108px), 1400px);
}

.teams-directory-page .team-selector-panels {
  grid-template-columns: minmax(0, 1.9fr) minmax(290px, 1fr);
  grid-template-rows: auto;
  align-items: stretch;
}

.teams-directory-page .directory-lineup-card,
.team-page .lineup-public-card {
  min-width: 0;
  min-height: 0;
  container-type: inline-size;
}

.teams-directory-page .directory-lineup-card {
  grid-column: 1;
  grid-row: 1;
}

.teams-directory-page .directory-roster-card {
  grid-column: 2;
  grid-row: 1;
  min-height: 0;
}

.team-page .team-public-layout {
  grid-template-columns: minmax(0, 1.75fr) minmax(300px, 1fr);
  align-items: stretch;
}

.team-page .roster-public-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  contain: size;
}

.team-page .roster-public-card .team-roster-list {
  min-height: 0;
  max-height: none;
  overflow-y: auto;
}

.team-page .team-roster-row {
  grid-template-columns: 40px 70px minmax(0, 1fr) auto;
  gap: 10px;
  min-height: 92px;
  padding: 10px 8px;
}

.team-page .team-roster-row > .roster-avatar-stack,
.team-page .team-roster-row > .roster-player-info { min-width: 0; }

.team-page .team-roster-row > .roster-avatar-stack {
  display: grid;
  justify-items: center;
}

:is(.teams-directory-page, .team-page) .public-lineup-bench {
  margin: 0;
  padding: 8px 12px 10px;
  background: var(--surface-2);
}

:is(.teams-directory-page, .team-page) .public-lineup-bench > header {
  min-height: 24px;
  padding: 0 0 6px;
  margin: 0;
}

:is(.teams-directory-page, .team-page) .public-lineup-bench > header > div {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

:is(.teams-directory-page, .team-page) .team-bench-row {
  grid-template-columns: repeat(7, var(--lineup-card-width));
  justify-content: safe center;
  gap: 10px;
  margin-top: 0;
  padding: 4px 2px 7px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
}

:is(.teams-directory-page, .team-page) .team-bench-row:focus-visible {
  outline: 2px solid var(--lime);
  outline-offset: -2px;
}

.lineup-bench-card {
  position: relative;
  display: grid;
  justify-items: center;
  align-content: start;
  min-width: 0;
  gap: 5px;
}

.lineup-bench-card [data-lineup-card] {
  width: var(--lineup-card-width);
  min-width: 0;
}

.lineup-bench-card > .lineup-empty-card {
  width: var(--lineup-card-width);
}

.lineup-bench-position {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 20px;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-input);
  color: var(--text-2);
  font-size: clamp(11px, .9cqi, 14px);
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.lineup-card-flags:empty { display: none; }

/* Keep saved match provenance close to its cards, separate from the current
   lineup visibility and editability indicators in the header. */
.teams-directory-page .lineup-source-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px 12px;
  padding: 7px 12px;
}

.teams-directory-page .lineup-source-banner > .lineup-source-copy {
  flex: 1 1 260px;
  gap: 2px;
}

.teams-directory-page .lineup-source-title-row { gap: 6px; }
.teams-directory-page .lineup-source-banner strong { font-size: 13px; }
.teams-directory-page .lineup-source-title-row > em {
  min-height: 20px;
  padding: 1px 6px;
  font-size: 11px;
}
.teams-directory-page .lineup-source-banner small {
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.teams-directory-page .lineup-source-banner > .lineup-source-actions {
  display: flex;
  flex: 0 1 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  margin-left: auto;
}

.teams-directory-page .lineup-source-actions > :is(a, button) {
  min-height: 32px;
  padding: 0 9px;
  border-color: var(--line-strong);
  border-radius: 6px;
  background: var(--surface-1);
  color: var(--text-1);
  font-size: 12px;
}

.teams-directory-page .lineup-source-actions > :is(a, button):is(:hover, :focus-visible) {
  border-color: var(--lime);
  color: var(--text-1);
  outline: 2px solid var(--lime);
  outline-offset: 2px;
}

@media (min-width: 761px) and (max-height: 800px) {
  body:is(.teams-directory-page, .team-page) .site-main { padding-top: 8px; }
  .teams-directory-page .team-selector-head,
  .team-page .team-page-hero { min-height: 76px; padding-block: 6px; }
  .team-page .team-public-layout { margin-top: 8px; }
  body:is(.teams-directory-page, .team-page) .lineup-public-card > header {
    min-height: 48px;
    padding-block: 6px;
  }
  :is(.teams-directory-page, .team-page) .team-staff-stack {
    --staff-avatar-size: 32px;
    --staff-label-size: 10px;
    --staff-name-size: 14px;
    --staff-row-gap: 2px;
  }
}

@media (min-width: 1200px) and (max-width: 1539px) {
  .teams-directory-page .team-selector-workspace {
    grid-template-columns: 190px minmax(0, 1fr);
    min-width: 0;
  }
  .teams-directory-page .team-selector-panels {
    grid-template-columns: minmax(0, 1.9fr) minmax(270px, .85fr);
  }
}

@media (max-width: 1539px) {
  .teams-directory-page .team-selector-panels,
  .team-page .team-public-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .teams-directory-page .directory-lineup-card,
  .teams-directory-page .directory-roster-card {
    grid-column: 1;
    grid-row: auto;
  }
  .teams-directory-page .directory-roster-card,
  .team-page .roster-public-card {
    min-height: 0;
    height: auto;
    contain: none;
  }
  .teams-directory-page .directory-roster-card .team-roster-list,
  .team-page .roster-public-card .team-roster-list {
    max-height: 580px;
    overflow-y: auto;
  }
}

@media (max-width: 760px) {
  .teams-directory-page .team-selector-rail { height: auto; }
  .team-page .team-page-hero { flex-wrap: wrap; padding: 18px; }
  .team-page .team-hero-actions { width: 100%; margin-left: 0; }
  .team-page .team-hero-actions .button-link { width: 100%; }
  .teams-directory-page .lineup-source-banner > .lineup-source-actions {
    margin-left: 0;
    justify-content: flex-start;
  }
  .teams-directory-page .lineup-source-actions > :is(a, button) {
    flex: 0 1 auto;
  }
  .team-page .team-roster-row {
    grid-template-columns: 32px 60px minmax(0, 1fr);
    min-height: 86px;
    gap: 7px;
  }
  .team-page .team-roster-row > em { display: none; }
}

@media (min-width: 2400px) {
  .team-page .site-main { width: min(3520px, calc(100% - 120px)); }
  .teams-directory-page .team-selector-panels {
    grid-template-columns: minmax(0, 2fr) minmax(440px, 1fr);
  }
  .lineup-bench-position { min-height: 24px; font-size: 13px; }
}

/* Keep the team identity compact above the pitch without reducing player cards
   or hiding the historical source banner. */
@media (min-width: 1200px) and (max-height: 1250px) {
  body:is(.teams-directory-page, .team-page) .site-main { padding-top: 4px; }
  .team-page .team-public-layout { margin-top: 4px; }
  .teams-directory-page .team-selector-head,
  .team-page .team-page-hero { min-height: 64px; padding: 8px 14px; }
  .teams-directory-page .team-selector-head .team-crest-large,
  .team-page .team-page-hero .team-crest-large { width: 46px; height: 46px; }
  .teams-directory-page .team-selector-head .team-selector-identity h2,
  .team-page .team-page-hero h1 { font-size: 28px; line-height: 1.1; }
  :is(.teams-directory-page, .team-page) .team-staff-stack {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px;
    --staff-avatar-size: 32px; --staff-label-size: 10px; --staff-name-size: 14px;
  }
  body:is(.teams-directory-page, .team-page) .lineup-public-card > header,
  body:is(.teams-directory-page, .team-page) .roster-public-card > header {
    min-height: 44px; padding-block: 6px;
  }
  .teams-directory-page .team-selector-panels { margin-block: 8px; }
  :is(.teams-directory-page, .team-page) .public-lineup-bench { padding-block: 6px 4px; }
  :is(.teams-directory-page, .team-page) .public-lineup-bench > header { padding-bottom: 4px; }
  :is(.teams-directory-page, .team-page) .team-bench-row { padding-block: 2px 3px; }
  :is(.teams-directory-page, .team-page) .lineup-bench-card { gap: 3px; }
}

.lineup-formation-badge[hidden] { display: none !important; }

/* Wide pitches budget the supported formations with their horizontal offsets;
   narrow pitches separately reserve six collision-spaced tactical lines.
   Visibility and provenance share that budget, without a hidden formation.
   The complete pitch stays in document flow rather than a vertical scroller. */
body:is(.teams-directory-page, .team-page) .lineup-public-card {
  --lineup-card-width: 108px;
  --team-lineup-pitch-height: calc(6 * (var(--lineup-card-width) * 37 / 36 + 16px) + 30px);
  --team-lineup-collision-height: calc(6 * (var(--lineup-card-width) * 37 / 36 + 32px) + 80px);
  --team-lineup-chrome-height: 274px;
  --team-lineup-panel-height: calc(var(--team-lineup-pitch-height) + var(--team-lineup-chrome-height));
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  block-size: var(--team-lineup-panel-height);
  min-block-size: var(--team-lineup-panel-height);
  max-block-size: var(--team-lineup-panel-height);
  align-self: stretch;
}

body:is(.teams-directory-page, .team-page) .lineup-public-card > :is(header, .lineup-source-banner, .public-lineup-bench) {
  flex: 0 0 auto;
}

body:is(.teams-directory-page, .team-page) .lineup-public-card > .lineup-stadium-scroll {
  /* Keep the pitch independent of provenance and substitute counts. Its
     remaining frame space belongs to the bench, without a blank footer. */
  flex: 0 0 var(--team-lineup-pitch-height);
  block-size: var(--team-lineup-pitch-height);
  min-block-size: var(--team-lineup-pitch-height);
  max-block-size: var(--team-lineup-pitch-height);
  overflow-y: hidden;
}

body:is(.teams-directory-page, .team-page) .lineup-public-card > .public-lineup-bench {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-block-size: 0;
}

body:is(.teams-directory-page, .team-page) .public-lineup-bench > header {
  flex: 0 0 auto;
}

body:is(.teams-directory-page, .team-page) .public-lineup-bench > .team-bench-row {
  flex: 1 1 auto;
  align-items: center;
}

body:is(.teams-directory-page, .team-page) .public-lineup-bench > .team-bench-empty {
  display: grid;
  place-items: center;
  flex: 1 1 auto;
}

body:is(.teams-directory-page, .team-page) .lineup-public-card > .lineup-stadium-scroll > .lineup-stadium {
  min-block-size: 100%;
}

body:is(.teams-directory-page, .team-page) .lineup-public-card > :is(.directory-lineup-hidden, .lineup-hidden-state) {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  min-block-size: 0;
  block-size: auto;
}

@media (max-width: 1023px) {
  body:is(.teams-directory-page, .team-page) .lineup-public-card {
    --lineup-card-width: 100px;
    /* Narrow pitches align more cards vertically. Budget collisions, labels
       and the captain badge before reserving provenance and substitutes. */
    --team-lineup-pitch-height: var(--team-lineup-collision-height);
    --team-lineup-chrome-height: 274px;
  }
}

@media (max-width: 760px) {
  body:is(.teams-directory-page, .team-page) .lineup-public-card {
    /* Phone provenance and status controls wrap onto additional lines. */
    --team-lineup-chrome-height: 330px;
  }
}

@media (min-width: 1200px) and (max-height: 1250px) {
  body:is(.teams-directory-page, .team-page) .lineup-public-card {
    --team-lineup-chrome-height: 250px;
  }
}

@media (min-width: 2400px) {
  body:is(.teams-directory-page, .team-page) .lineup-public-card {
    --lineup-card-width: 116px;
    --team-lineup-chrome-height: 290px;
  }
}

/* Give tablet pitches the full width before five defenders are squeezed. */
@media (min-width: 761px) and (max-width: 1199px) {
  body.teams-directory-page .site-main { width: calc(100% - 16px); }
  .teams-directory-page .team-selector-panels { width: calc(100% - 8px); margin: 4px; }
  .teams-directory-page .team-selector-workspace { grid-template-columns: minmax(0, 1fr); }
  .teams-directory-page .team-selector-rail { height: auto; }
  .teams-directory-page .team-selector-rail nav {
    display: flex; max-height: none; gap: 6px; overflow-x: auto; padding: 8px;
  }
  .teams-directory-page .team-selector-rail nav > a { flex: 0 0 170px; }
}
