/* Full-screen and viewport-fit mode shared by both player screens and local training. */
.fullscreen-toggle {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  border: 1px solid rgba(216, 164, 72, 0.52);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(89, 58, 26, 0.3), rgba(14, 11, 8, 0.76));
  color: #f2d590;
  padding: 7px 12px;
  font-size: 0.62rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  box-shadow: inset 0 1px rgba(255, 225, 158, 0.09);
}

.fullscreen-toggle:hover,
.fullscreen-toggle:focus-visible,
.fullscreen-toggle.is-active {
  border-color: #e6b75f;
  background: linear-gradient(180deg, rgba(135, 87, 34, 0.42), rgba(19, 13, 8, 0.9));
  color: #fff2c9;
}

.fullscreen-toggle svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: square;
  stroke-linejoin: miter;
}

.ability-window-controls .ability-card-display {
  display: block;
  width: 100%;
  opacity: 1;
}

.ability-window-controls .ability-card-display img {
  opacity: 1;
}

.ability-window-controls :is(.ability-option-label, .ability-validation-note, .ability-actions) {
  border-radius: 8px;
  background: rgba(13, 10, 8, 0.82);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
}

.ability-window-controls .ability-option-label,
.ability-window-controls .ability-validation-note {
  padding: 10px;
}

.ability-window-controls .ability-actions {
  padding: 10px;
}

html[data-fit-screen="true"],
html[data-fit-screen="true"] body {
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

html[data-fit-screen="true"] .app-shell {
  display: grid;
  width: calc(100% - 12px);
  height: 100dvh;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

html[data-fit-screen="true"] .character-sheet {
  width: calc(100vw - 24px);
}

html[data-fit-screen="true"] .site-header {
  min-height: 58px;
  margin-top: 4px;
  padding-block: 6px;
}

html[data-fit-screen="true"] .brand-mark {
  width: 42px;
  height: 42px;
}

html[data-fit-screen="true"] .brand strong {
  font-size: 1rem;
}

html[data-fit-screen="true"] .brand small,
html[data-fit-screen="true"] .build-badge,
html[data-fit-screen="true"] .site-footer {
  display: none !important;
}

html[data-fit-screen="true"] main,
html[data-fit-screen="true"] body.battle-active main {
  min-height: 0;
  overflow: hidden;
  padding: 6px 0;
}

html[data-fit-screen="true"] .battle-screen {
  display: grid;
  height: 100%;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 5px;
  overflow: hidden;
}

html[data-fit-screen="true"] .battle-screen:has(> #fighters-status) {
  grid-template-rows: auto auto minmax(0, 1fr);
}

html[data-fit-screen="true"] :is(
  #loading-screen,
  #setup-screen,
  #join-screen,
  #resume-section
) {
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: #a8712d rgba(15, 11, 8, 0.56);
  scrollbar-width: thin;
}

html[data-fit-screen="true"] .fighter-lane {
  min-height: 0;
  margin-block: 2px;
}

html[data-fit-screen="true"] .fighter-lane .fighter-status {
  padding-block: 3px;
}

html[data-fit-screen="true"] .phase-panel {
  display: flex;
  height: 100%;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: 5px;
}

html[data-fit-screen="true"] .battle-screen:has(> #fighters-status) .phase-panel {
  grid-row: 3;
}

html[data-fit-screen="true"] .phase-heading,
html[data-fit-screen="true"] .combat-phase-heading {
  flex: 0 0 auto;
  min-height: 68px;
  margin-bottom: 7px;
  padding-block: 8px;
}

html[data-fit-screen="true"] .phase-heading h2,
html[data-fit-screen="true"] .dominant-combat-heading h2 {
  font-size: clamp(1.35rem, 2.3vw, 2.25rem);
}

html[data-fit-screen="true"] .phase-workflow {
  min-height: 90px;
  margin-bottom: 4px;
}

html[data-fit-screen="true"] .workflow-track {
  min-height: 55px;
  padding-block: 1px;
}

html[data-fit-screen="true"] .workflow-track::before { top: 27px; }
html[data-fit-screen="true"] .workflow-medallion { width: 42px; height: 42px; }
html[data-fit-screen="true"] .workflow-step:is(.is-active,.is-waiting,.is-special) .workflow-medallion { width: 49px; height: 49px; }
html[data-fit-screen="true"] .workflow-active-card { min-height: 34px; padding-block: 3px; }

html[data-fit-screen="true"] .combat-flow {
  flex: 0 0 auto;
  margin-block: 0 6px;
}

html[data-fit-screen="true"] :is(
  .selection-grid,
  .ability-choice-grid,
  .skill-hand-grid,
  .merchant-unified-catalog,
  .equipment-inventory,
  .results-list
) {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: #a8712d rgba(15, 11, 8, 0.56);
  scrollbar-width: thin;
}

html[data-fit-screen="true"] :is(
  .selection-grid,
  .ability-choice-grid,
  .skill-hand-grid,
  .merchant-unified-catalog,
  .equipment-inventory,
  .results-list
)::-webkit-scrollbar {
  width: 8px;
}

html[data-fit-screen="true"] :is(
  .selection-grid,
  .ability-choice-grid,
  .skill-hand-grid,
  .merchant-unified-catalog,
  .equipment-inventory,
  .results-list
)::-webkit-scrollbar-track {
  background: rgba(15, 11, 8, 0.56);
}

html[data-fit-screen="true"] :is(
  .selection-grid,
  .ability-choice-grid,
  .skill-hand-grid,
  .merchant-unified-catalog,
  .equipment-inventory,
  .results-list
)::-webkit-scrollbar-thumb {
  border: 2px solid rgba(15, 11, 8, 0.56);
  border-radius: 999px;
  background: linear-gradient(#d29a43, #70451f);
}

html[data-fit-screen="true"] .selection-grid,
html[data-fit-screen="true"] .ability-choice-grid,
html[data-fit-screen="true"] .skill-hand-grid,
html[data-fit-screen="true"] .results-list {
  flex: 1 1 auto;
}

html[data-fit-screen="true"] .selection-footer,
html[data-fit-screen="true"] .equipment-ready-footer,
html[data-fit-screen="true"] .round-ability-section {
  flex: 0 0 auto;
  margin-top: 6px;
}

html[data-fit-screen="true"] .selection-grid .card-only-choice .card-art,
html[data-fit-screen="true"] .ability-choice-grid .ability-card.card-only-choice img,
html[data-fit-screen="true"] .skill-hand-grid .ability-card.card-only-choice img {
  height: clamp(190px, 29dvh, 330px);
}

html[data-fit-screen="true"] :is(
  [data-testid="talent-choices"],
  [data-testid="skill-choices"],
  [data-testid="ability-choices"]
) {
  display: grid;
  min-height: 0;
  flex: 1 1 auto;
  align-content: center;
  align-items: center;
  justify-items: center;
  overflow: hidden;
  padding-block: clamp(8px, 1.5dvh, 20px);
}

html[data-fit-screen="true"] :is(
  [data-testid="talent-choices"],
  [data-testid="skill-choices"],
  [data-testid="ability-choices"]
) .ability-card.card-only-choice {
  width: auto;
  height: clamp(340px, 52dvh, 580px);
  max-height: calc(100% - 16px);
  aspect-ratio: 5 / 7;
  align-self: center;
  justify-self: center;
}

html[data-fit-screen="true"] :is(
  [data-testid="talent-choices"],
  [data-testid="skill-choices"],
  [data-testid="ability-choices"]
) .ability-card.card-only-choice > button:not(.card-zoom-control) {
  display: block;
  width: 100%;
  height: 100%;
}

html[data-fit-screen="true"] :is(
  [data-testid="talent-choices"],
  [data-testid="skill-choices"],
  [data-testid="ability-choices"]
) .ability-card.card-only-choice img {
  width: 100%;
  height: 100%;
  max-height: 100%;
  object-fit: contain;
}

@media (max-height: 760px) and (min-width: 721px) {
  html[data-fit-screen="true"] :is(
    [data-testid="talent-choices"],
    [data-testid="skill-choices"],
    [data-testid="ability-choices"]
  ) .ability-card.card-only-choice {
    height: clamp(250px, 46dvh, 350px);
  }
}

html[data-fit-screen="true"] .round-ability-tray .ability-card.card-only-choice img {
  height: clamp(145px, 20dvh, 220px);
}

/* Selection uses the remaining viewport as two equal stages. */
html[data-fit-screen="true"] body.battle-active
  .phase-panel:has(> .selection-grid + .round-ability-section) {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) minmax(0, 1fr) auto;
}

html[data-fit-screen="true"] body.battle-active
  .phase-panel:has(> .selection-grid + .round-ability-section)
  > :is(.selection-grid, .round-ability-section) {
  width: 100%;
  height: auto;
  min-height: 0;
  flex: none;
}

html[data-fit-screen="true"] body.battle-active
  .phase-panel:has(> .selection-grid + .round-ability-section)
  > .round-ability-section {
  margin-top: 0;
}

@media (max-width: 1000px) {
  html[data-fit-screen="true"] body.battle-active
    .phase-panel:has(> .selection-grid + .round-ability-section)
    > :is(.selection-grid, .round-ability-section) {
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-color: #a8712d rgba(15, 11, 8, 0.56);
    scrollbar-width: thin;
  }
}

html[data-fit-screen="true"] .ability-window-controls {
  display: grid;
  grid-template-columns: minmax(190px, 0.38fr) minmax(280px, 1fr);
  grid-template-rows: minmax(0, auto) minmax(0, auto);
  align-content: center;
  min-height: 0;
  flex: 1 1 auto;
  overflow: hidden;
}

html[data-fit-screen="true"] .ability-window-controls > .ability-card {
  grid-row: 1 / -1;
  align-self: center;
}

html[data-fit-screen="true"] .ability-window-controls > :not(.ability-card) {
  grid-column: 2;
}

html[data-fit-screen="true"] .ability-window-controls .ability-card img {
  height: min(30dvh, 260px);
}

html[data-fit-screen="true"] .duel-grid {
  min-height: 0;
  flex: 1 1 auto;
  align-items: stretch;
  overflow: hidden;
}

html[data-fit-screen="true"] .duel-side {
  display: flex;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
}

html[data-fit-screen="true"] .duel-side > .combatant-identity {
  display: none;
}

html[data-fit-screen="true"] .duel-side > .hand-heading {
  flex: 0 0 auto;
  margin-bottom: 4px;
}

html[data-fit-screen="true"] .duel-side > :is(.weapon-profile, .defense-timing) {
  min-height: 56px;
  flex: 0 0 auto;
  margin-bottom: 6px;
  padding-block: 7px;
}

html[data-fit-screen="true"] .duel-side .revealed-card {
  min-height: 0;
  flex: 1 1 auto;
  overflow: hidden;
  padding: 9px;
}

html[data-fit-screen="true"] .duel-side .revealed-card-visual {
  display: grid;
  height: 100%;
  min-height: 0;
  place-items: center;
  overflow: hidden;
}

html[data-fit-screen="true"] .duel-side .card-stage {
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: 100%;
}

html[data-fit-screen="true"] .duel-side .card-art {
  width: auto;
  height: 100%;
  min-height: 0;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

@media (max-width: 1000px) {
  html[data-fit-screen="true"] .duel-grid {
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: none;
  }

  html[data-fit-screen="true"] .duel-grid::-webkit-scrollbar {
    display: none;
  }
}

html[data-fit-screen="true"] .merchant-rules {
  flex: 0 0 auto;
  margin-block: 4px 7px;
}

html[data-fit-screen="true"] .merchant-unified-catalog {
  flex: 1 1 auto;
  align-content: start;
  padding-right: 5px;
}

html[data-fit-screen="true"] .merchant-workspace {
  min-height: 0;
  flex: 1 1 auto;
  overflow: hidden;
}

html[data-fit-screen="true"] .merchant-workspace > .merchant-owned,
html[data-fit-screen="true"] .merchant-workspace > .merchant-unified-catalog {
  max-height: none;
  overflow-y: auto;
  scrollbar-width: thin;
}

html[data-fit-screen="true"] .merchant-card-grid.unified {
  grid-template-columns: repeat(auto-fill, minmax(120px, 160px));
}

@media (max-height: 800px) and (min-width: 721px) {
  html[data-fit-screen="true"] .phase-heading.merchant-heading {
    min-height: 58px;
    margin-bottom: 5px;
    padding-block: 5px;
  }

  html[data-fit-screen="true"] .merchant-heading h2 {
    font-size: 1.55rem;
  }

  html[data-fit-screen="true"] .merchant-wallet {
    padding: 0.3rem 0.75rem;
  }

  html[data-fit-screen="true"] .merchant-wallet strong {
    font-size: 1.3rem;
  }

  html[data-fit-screen="true"] .merchant-rules {
    margin-block: 2px 4px;
  }

  html[data-fit-screen="true"] .merchant-rules > span:not(.winner-chip) {
    padding-block: 0.28rem;
  }

  html[data-fit-screen="true"] .merchant-catalog-toolbar {
    margin-bottom: 4px;
  }

  html[data-fit-screen="true"] .merchant-catalog-toolbar h3 {
    font-size: 1rem;
  }

  html[data-fit-screen="true"] .merchant-card-grid.unified {
    grid-template-columns: repeat(auto-fill, minmax(100px, 120px));
    gap: 8px;
    margin-top: 7px;
  }

  html[data-fit-screen="true"] .merchant-unified-catalog {
    padding-block: 9px;
  }

  html[data-fit-screen="true"] .merchant-filters {
    padding-block: 4px;
  }

  html[data-fit-screen="true"] .merchant-filter,
  html[data-fit-screen="true"] .merchant-filter-reset {
    min-height: 26px;
    padding-block: 3px;
  }

  html[data-fit-screen="true"] .merchant-owned:not(.merchant-workspace .merchant-owned):has(.sheet-note) {
    max-height: 70px;
    padding-block: 5px;
  }
}

html[data-fit-screen="true"] .merchant-owned:not(.merchant-workspace .merchant-owned) {
  flex: 0 0 auto;
  max-height: 25dvh;
  overflow-y: auto;
  scrollbar-width: thin;
}

html[data-fit-screen="true"] .merchant-owned:not(.merchant-workspace .merchant-owned):has(.sheet-note) {
  max-height: 105px;
  padding-block: 8px;
}

html[data-fit-screen="true"] .equipment-loadout {
  flex: 0 1 auto;
  min-height: 0;
  padding-block: 8px;
}

html[data-fit-screen="true"] .managed-equipment-grid {
  grid-template-columns: repeat(3, minmax(0, 140px));
}

html[data-fit-screen="true"] .managed-equipment-slot {
  min-height: 145px;
}

html[data-fit-screen="true"] .equipment-inventory {
  flex: 1 1 auto;
  padding-block: 8px;
}

html[data-fit-screen="true"] .resolution-stage {
  height: 100%;
  min-height: 0;
}

html[data-fit-screen="true"] .handoff-screen {
  min-height: 0;
  margin-block: auto;
}

html[data-fit-screen="true"] .character-sheet-overlay,
html[data-fit-screen="true"] .card-inspector-overlay {
  height: 100dvh;
  overflow: hidden;
}

html[data-fit-screen="true"] .character-sheet {
  max-height: calc(100dvh - 20px);
  overflow: auto;
}

html[data-fit-screen="true"] .card-inspector {
  max-width: min(calc(100vw - 20px), 620px);
  max-height: calc(100dvh - 20px);
  overflow: hidden;
}

html[data-fit-screen="true"] .card-inspector > img {
  max-width: 100%;
  max-height: calc(100dvh - 20px);
}

html[data-fit-screen="true"] .character-sheet-columns {
  grid-template-columns: minmax(0, 1.18fr) minmax(520px, 0.82fr);
}

html[data-fit-screen="true"] .equipment-body {
  min-height: 560px;
  grid-template-rows: minmax(125px, auto) minmax(160px, auto) minmax(170px, auto);
}

@media (max-width: 960px) {
  .fullscreen-toggle span { display: none; }
  .fullscreen-toggle { width: 38px; padding-inline: 0; }

  html[data-fit-screen="true"] .site-header {
    flex-wrap: nowrap;
  }

  html[data-fit-screen="true"] .site-header .battle-command-bar {
    flex-basis: auto;
    order: initial;
  }

  html[data-fit-screen="true"] .site-header .battle-command-bar .battle-toolbar {
    grid-template-columns: minmax(120px, 1fr) auto;
  }

  html[data-fit-screen="true"] .site-header .battle-command-bar .deck-status {
    display: none;
  }
}

@media (max-width: 720px) {
  html[data-fit-screen="true"] .app-shell { width: calc(100% - 6px); }
  html[data-fit-screen="true"] .brand > span:last-child { display: none; }
  html[data-fit-screen="true"] .phase-heading { min-height: 58px; }
  html[data-fit-screen="true"] .combat-flow { display: none; }
  html[data-fit-screen="true"] .battle-screen { gap: 2px; }

  html[data-fit-screen="true"] .ability-window-controls {
    grid-template-columns: minmax(120px, 0.7fr) minmax(150px, 1fr);
    gap: 10px;
  }

  html[data-fit-screen="true"] .ability-window-controls .ability-card img {
    height: min(28dvh, 230px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .fullscreen-toggle { transition: none; }
}
