/* Heimdall tapped-game panel: fit the Stadium mini field, last play, chips, and
   full graph on an iPhone Duo cover (closed) and on the unfolded inner screen.
   Scoped to #heimdall only. League fields, Tecmo, and Modern skins are unchanged.

   Load after hd-graph.css and hd-mini.css (and after center-stats.css if present).

   Breakpoints reuse the Mock B Duo-safe idea (touch fold / mid width):
   - Closed cover and other narrow phones: max-width 699px (352 CSS px is the tight target).
   - Unfolded inner screen: 700–999px wide and taller than 520px.
   - Short landscape fold: same gate as the Mock B X-breakers rail
     (landscape, 740–1099px wide, max-height 520px). */

/* ---------- Closed cover / narrow portrait (~352×800) ---------- */
@media (max-width: 699px) {
  #heimdall.hd-port.stats-open .hd-sheet,
  #heimdall.hd-land.stats-open .hd-sheet {
    padding-bottom: max(6px, env(safe-area-inset-bottom, 0px));
  }

  #heimdall .hd-field-slot { padding: 4px 6px 0; }

  /* Shrink the mini field a little so the graph keeps its axes on screen. */
  #heimdall .hd-sf-mini .sf-fieldwrap { height: 116px; }
  #heimdall .hd-sf-mini .sf-field {
    height: 218px;
    left: 6px;
    right: 6px;
    bottom: 4px;
  }

  /* Last play on one line under the mini field (sf-cap is what the panel shows). */
  #heimdall .hd-sf-mini .sf-cap {
    display: flex !important;
    align-items: center;
    gap: 8px;
    margin: 2px 6px 4px;
    padding: 4px 8px;
    border-radius: 14px;
  }
  #heimdall .hd-sf-mini .sf-cap-ico {
    width: 22px;
    height: 22px;
    font-size: 7px;
  }
  #heimdall .hd-sf-mini .sf-cap-body {
    display: flex;
    align-items: baseline;
    gap: 6px;
    min-width: 0;
  }
  #heimdall .hd-sf-mini .sf-cap-k {
    margin: 0;
    flex: 0 0 auto;
  }
  #heimdall .hd-sf-mini .sf-cap-t {
    flex: 1;
    min-width: 0;
    font-size: 11.5px;
    line-height: 1.2;
  }
  #heimdall .hd-sf-mini .sf-key { display: none; }
  #heimdall .hd-sf-mini .sf-cap-k { white-space: nowrap; }

  #heimdall .hd-graph-slot,
  #heimdall.hd-port .hd-graph-slot,
  #heimdall.hd-land .hd-graph-slot { padding: 2px 6px 4px; }
  #heimdall .hdg-bubbles { padding: 4px 6px 2px; }
  #heimdall .hdg-ghead { padding: 0 8px; min-height: 18px; }
  #heimdall .hdg-plot { padding: 0 4px 0 22px; }
  #heimdall .hdg-ylabels { width: 20px; }
  /* Fixed, shorter aspect so Q1 and the final label stay in the first view. */
  #heimdall .hdg-plot svg,
  #heimdall.hd-port .hdg-plot svg,
  #heimdall.hd-land .hdg-plot svg {
    height: auto !important;
    aspect-ratio: 2.7 / 1;
    max-height: 88px;
    min-height: 70px;
  }
  #heimdall .hdg-qlabels { height: 14px; }
}

/* Tighter still on the Duo cover (352 CSS px) and other sub-360 phones. */
@media (max-width: 360px) {
  #heimdall .hd-stop { padding: 4px 8px 3px; }
  #heimdall .hd-sf-mini .sf-fieldwrap { height: 104px; }
  #heimdall .hd-sf-mini .sf-field { height: 196px; }
  #heimdall .hdg-plot svg,
  #heimdall.hd-port .hdg-plot svg,
  #heimdall.hd-land .hdg-plot svg {
    max-height: 80px;
    aspect-ratio: 2.9 / 1;
  }
}

/* ---------- Unfolded inner screen (~700–900 × 800) ---------- */
@media (min-width: 700px) and (max-width: 999px) and (min-height: 521px) {
  /* Wide bottom sheet. Do not use the 430px landscape side panel on a tall fold. */
  #heimdall.hd-port.stats-open .hd-sheet,
  #heimdall.hd-land.stats-open .hd-sheet {
    left: var(--pad);
    right: var(--pad);
    top: auto;
    bottom: var(--pad);
    width: auto;
    height: min(72%, 640px);
    max-height: calc(100dvh - 72px);
    padding-bottom: max(8px, env(safe-area-inset-bottom, 0px));
  }

  #heimdall .hd-main {
    display: grid !important;
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.2fr);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 4px 12px;
    overflow: hidden;
  }
  #heimdall .hd-field-slot {
    grid-column: 1;
    grid-row: 1;
    padding: 6px 8px 4px;
    min-width: 0;
  }
  #heimdall .hd-graph-slot,
  #heimdall.hd-port .hd-graph-slot,
  #heimdall.hd-land .hd-graph-slot {
    grid-column: 2;
    grid-row: 1;
    padding: 4px 10px 6px 0;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
  }
  #heimdall .hd-sbody {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  #heimdall .hd-sf-mini .sf-fieldwrap { height: 168px; }
  #heimdall .hd-sf-mini .sf-field {
    height: 310px;
    left: 8px;
    right: 8px;
    bottom: 6px;
  }
  #heimdall .hd-sf-mini .sf-cap {
    display: flex !important;
    align-items: center;
    gap: 8px;
    margin: 4px 8px 6px;
    padding: 5px 10px;
  }
  #heimdall .hd-sf-mini .sf-cap-body {
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
  }
  #heimdall .hd-sf-mini .sf-key { display: none !important; }
  #heimdall .hd-sf-mini .sf-cap-k { margin: 0; flex: 0 0 auto; white-space: nowrap; }
  #heimdall .hd-sf-mini .sf-cap-t {
    flex: 1; min-width: 0;
    white-space: normal;
    overflow: hidden;
    text-overflow: unset;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    line-height: 1.25;
  }

  #heimdall .hdg-panel {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }
  #heimdall .hdg-plot { flex: 1; min-height: 0; }
  /* Wider graph; keep a fixed aspect so both end labels stay on the plot. */
  #heimdall .hdg-plot svg,
  #heimdall.hd-port .hdg-plot svg,
  #heimdall.hd-land .hdg-plot svg {
    flex: 1;
    height: auto !important;
    min-height: 148px;
    aspect-ratio: 2.2 / 1;
    max-height: 220px;
  }
}

/* ---------- Short landscape fold (same gate as Mock B X-breakers) ---------- */
@media (orientation: landscape)
  and (min-width: 740px)
  and (max-width: 1099px)
  and (max-height: 520px) {
  #heimdall.hd-port.stats-open .hd-sheet,
  #heimdall.hd-land.stats-open .hd-sheet {
    left: var(--pad);
    right: var(--pad);
    top: auto;
    bottom: var(--pad);
    width: auto;
    height: calc(100dvh - 56px);
    max-height: none;
  }
  #heimdall .hd-main {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 4px 10px;
    overflow: hidden;
  }
  #heimdall .hd-field-slot { grid-column: 1; grid-row: 1; padding: 4px 6px; }
  #heimdall .hd-graph-slot,
  #heimdall.hd-port .hd-graph-slot,
  #heimdall.hd-land .hd-graph-slot {
    grid-column: 2;
    grid-row: 1;
    padding: 2px 8px 4px 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
  #heimdall .hd-sbody { grid-column: 1 / -1; grid-row: 2; }
  #heimdall .hd-sf-mini .sf-fieldwrap { height: 132px; }
  #heimdall .hd-sf-mini .sf-field { height: 250px; left: 6px; right: 6px; bottom: 4px; }
  #heimdall .hd-sf-mini .sf-cap {
    display: flex !important;
    align-items: center;
    margin: 2px 6px 2px;
    padding: 3px 8px;
  }
  #heimdall .hd-sf-mini .sf-cap-body {
    display: flex;
    align-items: baseline;
    gap: 6px;
    min-width: 0;
  }
  #heimdall .hd-sf-mini .sf-key { display: none !important; }
  #heimdall .hd-sf-mini .sf-cap-k { margin: 0; white-space: nowrap; }
  #heimdall .hd-sf-mini .sf-cap-t {
    flex: 1; min-width: 0;
    white-space: normal;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    line-height: 1.25;
  }
  #heimdall .hdg-plot svg,
  #heimdall.hd-port .hdg-plot svg,
  #heimdall.hd-land .hdg-plot svg {
    height: auto !important;
    min-height: 110px;
    aspect-ratio: 2.4 / 1;
    max-height: 160px;
  }
}


/* Short yellow hint at the right edge of the chip row.
   Never covers chips or the legend. Shown by JS for ~2s; this file only styles it. */
#heimdall .hdg-bubblerow {
  display: flex;
  align-items: center;
  gap: 4px;
}
#heimdall .hdg-bubblerow > .hdg-bubbles {
  flex: 1 1 auto;
  min-width: 0;
}
#heimdall .hdg-hint {
  position: relative !important;
  right: auto !important;
  top: auto !important;
  left: auto !important;
  transform: none !important;
  flex: 0 0 auto;
  z-index: 3;
  margin: 2px 6px 0 0;
  padding: 3px 7px;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: .04em;
  line-height: 1;
  max-width: 64px;
  overflow: hidden;
  text-overflow: clip;
  white-space: nowrap;
}
#heimdall .hdg-bubblerow:has(> .hdg-hint:not([hidden])) > .hdg-fade.r,
#heimdall .hdg-bubblerow:has(> .hdg-hint:not([hidden])) > .hdg-more {
  opacity: 0;
}
@media (prefers-reduced-motion: reduce) {
  #heimdall .hdg-hint.nudge,
  #heimdall .hdg-bubblerow:has(> .hdg-hint:not([hidden])) > .hdg-hint.nudge {
    animation: none !important;
  }
  #heimdall .hdg-hint { transition: none !important; }
}
