/*
 * Phone layout adjustments.
 * Everything that changes the layout is inside a max-width query, so the
 * desktop layout (768px and wider) stays exactly as before.
 */

/* Media and embeds never grow wider than their container. */
img,
video,
canvas,
iframe,
embed,
object {
  max-width: 100%;
}

#position-filters .pos-btn,
#trophy-cat-filters .tcat-btn {
  transform: translateY(0);
  transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.22s ease, transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}

#position-filters .pos-btn[aria-pressed="true"],
#trophy-cat-filters .tcat-btn[aria-pressed="true"] {
  box-shadow: 0 4px 14px rgba(108, 171, 221, 0.32), inset 0 0 0 1px rgba(255, 255, 255, 0.2);
  transform: translateY(-1px) scale(1.03);
}

#position-filters .pos-btn:not([aria-pressed="true"]):hover,
#trophy-cat-filters .tcat-btn:not([aria-pressed="true"]):hover {
  background-color: rgba(255, 255, 255, 0.16);
  color: #fff;
  transform: translateY(-1px);
}

#position-filters .pos-btn:active,
#trophy-cat-filters .tcat-btn:active {
  transform: scale(0.96);
}

#position-filters .pos-btn:focus-visible,
#trophy-cat-filters .tcat-btn:focus-visible {
  outline: 2px solid rgba(108, 171, 221, 0.9);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  #position-filters .pos-btn,
  #trophy-cat-filters .tcat-btn {
    transition: none;
  }

  #position-filters .pos-btn[aria-pressed="true"],
  #position-filters .pos-btn:not([aria-pressed="true"]):hover,
  #position-filters .pos-btn:active,
  #trophy-cat-filters .tcat-btn[aria-pressed="true"],
  #trophy-cat-filters .tcat-btn:not([aria-pressed="true"]):hover,
  #trophy-cat-filters .tcat-btn:active {
    transform: none;
  }
}

.season-dropdown-menu {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-0.4rem) scale(0.98);
  transform-origin: top center;
  visibility: hidden;
  transition: opacity 0.16s ease, transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 0.2s;
}

.season-dropdown-menu.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
  visibility: visible;
  transition-delay: 0s;
}

.formation-dropdown-menu {
  width: 8rem;
  max-width: calc(100vw - 2rem);
}

.formation-dropdown-menu .formation-option-btn {
  white-space: nowrap;
}

.season-dropdown-btn svg:last-child {
  transition: transform 0.2s ease;
}

.season-dropdown-btn[aria-expanded="true"] svg:last-child {
  transform: rotate(180deg);
}

@media (min-width: 1024px) {
  #squad-grid {
    max-height: 620px;
    grid-auto-rows: max-content;
    align-content: start;
  }
}

select {
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.18s ease;
}

select:focus {
  box-shadow: 0 0 0 3px rgba(108, 171, 221, 0.14);
  transform: translateY(-1px);
}

@media (prefers-reduced-motion: reduce) {
  .season-dropdown-menu,
  .season-dropdown-btn svg:last-child,
  select,
  .formation-dropdown-menu {
    transition: none;
    animation: none;
  }

  .season-dropdown-menu,
  .season-dropdown-menu.is-open,
  .formation-dropdown-menu,
  .formation-dropdown-menu.is-open,
  .season-dropdown-btn[aria-expanded="true"] svg:last-child,
  select:focus {
    transform: none;
  }
}

/* The menu toggle exists only on small screens. */
.nav-toggle {
  display: none;
}

@media (max-width: 767.98px) {
  html,
  body {
    max-width: 100%;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  body {
    font-size: 1rem;
    line-height: 1.5;
  }

  main,
  footer,
  header {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  /* ---------- Collapsible navigation ---------- */
  .nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-width: 2.75rem;
    min-height: 2.75rem;
    padding: 0.5rem 0.875rem;
    border: 1px solid rgba(108, 171, 221, 0.45);
    border-radius: 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    color: #f8fafc;
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.25rem;
    white-space: nowrap;
    flex-shrink: 0;
    overflow-wrap: normal;
    transition: background-color 0.22s ease, border-color 0.22s ease, box-shadow 0.22s ease, transform 0.18s ease;
  }

  .nav-toggle:active {
    transform: scale(0.96);
  }

  .nav-toggle[aria-expanded="true"] {
    border-color: rgba(108, 171, 221, 0.8);
    background: rgba(108, 171, 221, 0.16);
    box-shadow: 0 0 0 3px rgba(108, 171, 221, 0.12);
  }

  .nav-toggle-icon {
    position: relative;
    display: inline-block;
    width: 1.25rem;
    height: 1.25rem;
    flex: 0 0 1.25rem;
  }

  .nav-toggle svg {
    position: absolute;
    inset: 0;
    width: 1.25rem;
    height: 1.25rem;
    transition: opacity 0.18s ease, transform 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
  }

  .nav-toggle .nav-toggle-open {
    opacity: 1;
    transform: rotate(0) scale(1);
  }

  .nav-toggle[aria-expanded="true"] .nav-toggle-close {
    opacity: 1;
    transform: rotate(0) scale(1);
  }

  .nav-toggle .nav-toggle-close {
    opacity: 0;
    transform: rotate(-90deg) scale(0.7);
  }

  .nav-toggle[aria-expanded="true"] .nav-toggle-open {
    opacity: 0;
    transform: rotate(90deg) scale(0.7);
  }

  #site-header .main-nav {
    display: flex;
    flex-direction: column;
    gap: 0;
    max-height: 0;
    overflow: hidden;
    padding-bottom: 0;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-0.4rem);
    visibility: hidden;
    transition: max-height 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.18s ease, transform 0.24s ease, gap 0.22s ease, padding-bottom 0.22s ease, visibility 0s linear 0.3s;
  }

  #site-header.nav-open .main-nav {
    max-height: 24rem;
    gap: 0.375rem;
    padding-bottom: 0.25rem;
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
    visibility: visible;
    transition-delay: 0s;
  }

  #site-header .main-nav .tab-btn {
    opacity: 0;
    transform: translateY(-0.35rem);
    transition: opacity 0.2s ease, transform 0.22s ease, background-color 0.2s ease;
  }

  #site-header.nav-open .main-nav .tab-btn {
    opacity: 1;
    transform: translateY(0);
  }

  #site-header.nav-open .main-nav .tab-btn:nth-child(2) {
    transition-delay: 0.03s;
  }

  #site-header.nav-open .main-nav .tab-btn:nth-child(3) {
    transition-delay: 0.06s;
  }

  #site-header.nav-open .main-nav .tab-btn:nth-child(4) {
    transition-delay: 0.09s;
  }

  #site-header.nav-open .main-nav .tab-btn:nth-child(5) {
    transition-delay: 0.12s;
  }

  #site-header .main-nav .tab-btn {
    width: 100%;
    min-height: 2.75rem;
    padding: 0.625rem 0.875rem;
    font-size: 1rem;
    line-height: 1.5rem;
  }

  #site-header .main-nav .tab-btn svg {
    width: 1.25rem;
    height: 1.25rem;
  }

  #site-header .main-nav .tab-btn[aria-current="page"]::after {
    display: none;
  }

  @media (prefers-reduced-motion: reduce) {
    .nav-toggle,
    .nav-toggle svg,
    #site-header .main-nav,
    #site-header .main-nav .tab-btn {
      transition: none;
    }

    .nav-toggle:active {
      transform: none;
    }
  }

  /* ---------- Readable text (16px minimum) ---------- */
  main .text-xs,
  main .text-sm,
  main .text-\[10px\],
  main .text-\[11px\],
  footer .text-xs,
  footer .text-sm,
  footer p,
  footer span {
    font-size: 1rem;
    line-height: 1.5rem;
  }

  /* Pitch labels sit on a fixed-size board; keep them compact so they fit. */
  #pitch-slots .text-xs,
  #pitch-slots .text-\[10px\] {
    font-size: 0.75rem;
    line-height: 1rem;
  }

  /* Form fields at 16px also stop iOS from zooming in on focus. */
  input,
  select,
  textarea {
    font-size: 1rem;
  }

  /* ---------- Tap targets (44 × 44px minimum) ---------- */
  main button,
  main select,
  main input,
  main [role="button"],
  footer button {
    min-height: 2.75rem;
  }

  main button,
  footer button {
    min-width: 2.75rem;
  }

  /* Text-only buttons keep their label centred once they grow taller. */
  main button:not(.flex):not(.pitch-slot):not(.hidden) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  main button.text-left:not(.flex) {
    justify-content: flex-start;
  }

  #btn-reset-quiz,
  #btn-clear-slot {
    min-height: 2.75rem;
    font-size: 1rem;
  }

  main a:not(.hidden),
  footer a:not(.hidden) {
    display: inline-flex;
    align-items: center;
    min-height: 2.75rem;
  }

  /* Pitch slots keep their 44px circle; give the whole button a 44px box. */
  #pitch-slots .pitch-slot {
    min-width: 2.75rem;
    min-height: 2.75rem;
  }

  /* ---------- Overflow fixes ---------- */
  .hero {
    display: flex;
    flex-direction: column;
    min-height: 18rem;
  }

  .hero picture,
  .hero picture img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
  }

  /* Let the hero grow with its text instead of clipping it. */
  .hero .hero-content {
    position: relative;
    margin-top: auto;
    padding-top: 7rem;
  }

  .hero .hero-content > .flex {
    width: 100%;
  }

  .hero .hero-content button {
    flex: 1 1 10rem;
  }

  .quiz-round-actions {
    flex-wrap: wrap;
  }

  .quiz-mode-options button,
  .quiz-difficulty-button,
  #btn-next-question,
  #btn-play-again,
  #btn-start-quiz {
    min-width: 0;
    white-space: normal;
  }

  .quiz-difficulty-button {
    flex: 1 1 6rem;
    font-size: 1rem;
  }

  .site-footer-sources p {
    white-space: normal;
  }

  .season-dropdown-menu {
    max-width: calc(100vw - 2.5rem);
  }

  /* Cards grow with their text, and historical variants stay grouped per player. */
  #squad-grid {
    height: 500px;
    max-height: 500px;
    min-height: 300px;
    grid-auto-rows: max-content;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  #squad-grid > article {
    min-width: 0;
    height: auto;
    min-height: 6rem;
    padding: 0.75rem;
    overflow: visible;
  }

  #squad-grid > article > button {
    min-width: 0;
    padding: 0;
  }

  #squad-grid > article > button > div:first-child {
    flex: 1 1 0%;
    min-width: 0;
  }

  #squad-grid > article p {
    line-height: 1.3;
    overflow-wrap: anywhere;
  }

  #squad-grid > article > button p:first-child {
    min-width: 0;
  }

  #squad-grid > article > button p:first-child {
    overflow: visible;
    white-space: normal;
    text-overflow: clip;
  }

  #squad-grid > article > button > span {
    white-space: nowrap;
  }

  #kpi-scorer-season {
    width: 100%;
  }

  /* KPI headings wrap rather than pushing their icon out of the card. */
  .glass-card .justify-between > .uppercase {
    min-width: 0;
  }

  pre,
  table {
    max-width: 100%;
    overflow-x: auto;
  }

  video {
    height: auto;
  }
}
