/*
 * HAWK-EYE Battle Report mobile hardening.
 * Desktop/fine-pointer Battle Reports intentionally keep their existing layout.
 */
@media (max-width: 767px), (hover: none) and (pointer: coarse) {
  /* Scope every rule to the BattleReplay root by its unique round transport. */
  :where(main div.relative:has(> div > button[title="First round"])) > div.flex.items-center.justify-between.mb-4 {
    gap: 0.5rem;
    align-items: flex-start;
    margin-bottom: 0.75rem !important;
  }

  :where(main div.relative:has(> div > button[title="First round"])) > div.panel.p-4.mb-4 {
    padding: 0.75rem !important;
    margin-bottom: 0.75rem !important;
  }

  /* RobotPlate art is authored to a fixed aspect ratio. Never stretch it. */
  :where(main div.relative:has(> div > button[title="First round"])) > div.panel.p-4.mb-4 button[aria-label^="Open "][aria-label$=" profile"] > div.relative {
    width: min(320px, 100%) !important;
    max-width: 320px !important;
    height: auto !important;
    aspect-ratio: 5 / 1;
  }

  :where(main div.relative:has(> div > button[title="First round"])) > div.panel.p-4.mb-4 button[aria-label^="Open "][aria-label$=" profile"] > div.relative > img {
    object-fit: contain !important;
  }

  /* Replay transport stays in normal document flow; controls remain thumb-sized. */
  :where(main div.relative:has(> div > button[title="First round"])) > div:has(> button[title="First round"]) {
    display: grid !important;
    grid-template-columns: repeat(5, minmax(44px, 1fr));
    gap: 0.375rem !important;
    width: 100%;
    margin: 0 0 0.75rem !important;
    padding: 0.375rem !important;
    border: 1px solid rgba(72, 72, 96, 0.9);
    border-radius: 0.5rem;
    background: rgba(18, 18, 28, 0.96);
  }

  :where(main div.relative:has(> div > button[title="First round"])) > div:has(> button[title="First round"]) > button {
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 100%;
    min-width: 44px;
    min-height: 44px;
    padding: 0.5rem !important;
    line-height: 1;
  }

  /* Keep Play/Pause emphasized, but use an even inset ring instead of a lopsided border. */
  :where(main div.relative:has(> div > button[title="First round"])) > div:has(> button[title="First round"]) > button.btn-primary {
    border-color: transparent !important;
    background: rgba(255, 182, 39, 0.1) !important;
    box-shadow: inset 0 0 0 1px rgba(255, 182, 39, 0.7) !important;
  }

  :where(main div.relative:has(> div > button[title="First round"])) > div:has(> button[title="First round"]) > span {
    grid-column: 1 / -1;
    margin-left: 0 !important;
    text-align: center;
    line-height: 1.2;
  }

  /* Battle state and round panels stay dense without shrinking their text. */
  :where(main div.relative:has(> div > button[title="First round"])) div.panel.p-4 {
    padding: 0.75rem !important;
  }

  :where(main div.relative:has(> div > button[title="First round"])) button.card-frame {
    min-height: 44px;
  }

  /* Teaching moments should read as touch interactions, not hover instructions. */
  :where(main div.relative:has(> div > button[title="First round"])) aside.panel.border-arcade-amber > p:last-of-type {
    font-size: 0 !important;
  }

  :where(main div.relative:has(> div > button[title="First round"])) aside.panel.border-arcade-amber > p:last-of-type::after {
    content: "Tap the highlighted card to expand its rules text.";
    font-size: 10px;
    line-height: 1.4;
  }

  /* Active teaching callouts remain visible instead of appearing below a long round. */
  :where(main div.relative:has(> div > button[title="First round"])) aside.panel.border-arcade-amber {
    position: fixed !important;
    left: calc(0.75rem + var(--bbo-safe-left));
    right: calc(0.75rem + var(--bbo-safe-right));
    bottom: calc(5.25rem + var(--bbo-safe-bottom));
    z-index: 55;
    max-height: min(42dvh, 22rem);
    overflow-y: auto;
    box-shadow: 0 0 28px rgba(0, 0, 0, 0.55);
  }

  /* The report guide must also clear the app bottom navigation. */
  :where(main div.relative:has(> div > button[title="First round"])) > div.fixed.inset-x-0[class~="bottom-4"] {
    bottom: calc(5.75rem + var(--bbo-safe-bottom)) !important;
  }
}

/*
 * Landscape phones have horizontal room but very little height. Use that width
 * for side-by-side identities/state/cards rather than forcing desktop chrome.
 */
@media (orientation: landscape) and (hover: none) and (pointer: coarse) {
  :where(main div.relative:has(> div > button[title="First round"])) > div.panel.p-4.mb-4 > div:first-child {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) !important;
    gap: 0.5rem !important;
  }

  :where(main div.relative:has(> div > button[title="First round"])) div.grid.grid-cols-1[class*="lg:grid-cols-2"],
  :where(main div.relative:has(> div > button[title="First round"])) div.grid.grid-cols-1[class*="md:grid-cols-2"] {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.5rem !important;
  }

  :where(main div.relative:has(> div > button[title="First round"])) > div:has(> button[title="First round"]) {
    grid-template-columns: repeat(5, 44px) auto;
    width: max-content;
    max-width: 100%;
    margin-right: auto !important;
    margin-left: auto !important;
  }

  :where(main div.relative:has(> div > button[title="First round"])) > div:has(> button[title="First round"]) > span {
    grid-column: auto;
    align-self: center;
    padding: 0 0.375rem;
    white-space: nowrap;
  }

  :where(main div.relative:has(> div > button[title="First round"])) aside.panel.border-arcade-amber {
    max-height: min(55dvh, 18rem);
  }
}
