/* Deck detail screen (T-011 / R-009; v3.1 focus pass, T4-004 / R-008 / R-012).

   Screen-scoped only: every rule is under #tab-insights so nothing here can leak
   into another screen, and no token or component class from tokens.css /
   components.css is redefined. The screen composes .card / .art / .art-row /
   .meter / .seg(.views) / .chip / .eyebrow / .card-head / .info-tip; what
   follows is layout plus the two things the components layer deliberately
   leaves to the consumer: the win%-vs-baseline colouring of a meter fill, and
   the muted rendering of a lowSample percentage (R-010).

   Shape (v3.1): a header card (picker, the 8 cards, the deck's record), then a
   Matchups | Combos switch, then ONE sub-view. Cards never nest: rows inside a
   card are separated by a hairline, not by another bordered box.

   Mobile first (390px): the 8 deck cards are a responsive 8-column grid so every
   require toggle stays >=36px wide down to a 360px viewport; a combo block keeps
   the card art on its first line and lets it wrap when the combo size grows, so
   an 8-card core never pushes the numbers off screen.

   Width (T4-014): the screen takes the full content width on BOTH sub-views, so
   the header card is the same width on Matchups and Combos and the same width
   as the Decks grid it came from. The old 1040px / 720px caps are gone; from
   1024px the header becomes a two-column grid and the combo list two columns,
   which is what keeps a row from stretching one meter across the screen. */

/* ---------- deck header ---------- */

#tab-insights .ins-head {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px 14px 14px;
}
#tab-insights .ins-head-top { display: flex; align-items: center; }
#tab-insights .ins-head-pick { display: inline-flex; align-items: center; gap: 6px; }
#tab-insights .ins-step {
  width: 36px; height: 36px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--s2);
  border: 1px solid var(--line);
  color: var(--ink-2);
}
#tab-insights .ins-step:hover:not(:disabled) { color: var(--ink); border-color: var(--line-2); }
#tab-insights .ins-step:disabled { opacity: .35; }
#tab-insights .ins-step:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* One row of 8, whatever the viewport: the cards scale, the row never wraps and
   never overflows. Measured: 390px viewport -> 39px per toggle; at 360px a 3px
   gap would give 35px, one pixel under the R-005 hit-target floor, so the gap
   tightens to 2px below 380px and the toggle stays at 36px. */
#tab-insights .ins-deck-row {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 3px;
}
@media (max-width: 379px) {
  #tab-insights .ins-deck-row { gap: 2px; }
}
#tab-insights .ins-card {
  display: block;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 8px;
  min-width: 0;
}
#tab-insights .ins-card .art {
  width: 100%;
  height: auto;
  aspect-ratio: 40 / 48;
}

#tab-insights .ins-head-stats {
  display: flex;
  align-items: center;
  gap: 4px 14px;
}
#tab-insights .ins-head-detail {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  font-size: 12px;
}
#tab-insights .ins-head-stats .pct {
  font-family: var(--display);
  font-size: 32px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
}
#tab-insights .ins-wld { display: inline-flex; gap: 6px; }
#tab-insights .ins-wld b { font-weight: 800; }
#tab-insights .ins-elixir {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-variant-numeric: tabular-nums;
}
#tab-insights .ins-elixir .i { color: var(--elixir); }

/* ---------- INV-6 explainer ----------
   Restyled to a quiet one-line disclosure at the top of the Combos card: no
   surface of its own, the sentence is a muted link, and the two paragraphs open
   under it behind a hairline. Its text lives in TEMPLATE, unchanged. */

#tab-insights .ins-explainer { margin: -2px 0 8px; }
/* NOT display:flex - a flex container drops the white space between the inline
   children of the sentence ("Why card combos instead of ..."), so the 36px hit
   target (R-005) comes from padding + min-height, not from centring in a flex
   box. 12px x 1.4 line-height + 9px x 2 padding = 34.8px, lifted to 36px. */
#tab-insights .ins-explainer summary {
  cursor: pointer;
  list-style: none;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
  color: var(--ink-2);
  padding: 9px 0;
  min-height: 36px;
}
#tab-insights .ins-explainer summary::-webkit-details-marker { display: none; }
#tab-insights .ins-explainer summary::marker { content: ""; }
#tab-insights .ins-explainer summary:hover { color: var(--ink); }
#tab-insights .ins-explainer[open] summary { color: var(--ink); }
#tab-insights .ins-explainer p,
#tab-insights .ins-explainer .ins-hint {
  font-size: 12px;
  line-height: 1.5;
  color: var(--ink-2);
  margin: 0 0 10px;
  padding-left: 10px;
  border-left: 2px solid var(--line-2);
}
#tab-insights .ins-explainer strong, #tab-insights .ins-explainer em { color: var(--ink); }

/* ---------- controls ---------- */

#tab-insights .ins-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}
#tab-insights .ins-ctl-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
/* R-005 floor: components.css ships .seg buttons at min-height 32px; the combo
   size and sort segs are this view's primary controls, so they get the 36px
   floor here. (The view tabs keep their own 40px from `.seg.views`.) */
#tab-insights .ins-controls .seg button { min-height: 36px; min-width: 36px; justify-content: center; }

/* The two lines of meta between the controls and the first combo: what the
   cores are (scope) and the numbers (summary). The "tap cards to require
   them" hint lives inside the explainer disclosure above. */
#tab-insights .ins-scope { padding: 2px 0 0; }
#tab-insights .ins-summary { padding: 2px 0 6px; }
#tab-insights .ins-req-name { color: var(--ink); font-weight: 800; }

/* ---------- sections ---------- */

#tab-insights .ins-matchups { align-items: start; }
/* `.grid-2` is `1fr` on a phone, and a `1fr` track will not shrink below its
   widest child: one long card name (or the eight-chip opponent-deck row) made
   the whole card wider than the gutter at 320-360px. The sections shrink and
   their rows ellipsize / wrap instead. */
#tab-insights .ins-sec { min-width: 0; }
#tab-insights .ins-sec .card-head { margin-bottom: 4px; }
#tab-insights .ins-list { display: flex; flex-direction: column; }
#tab-insights .ins-none { padding: 10px 0; font-size: 13px; }

#tab-insights .ins-error {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 6px 0;
}
#tab-insights .ins-error .error-text { margin-top: 0; }

/* The answer line over the opponent cards ("Hardest: ... · Easiest: ...") and
   its two sort chips. On a phone each half is its own line (the " · " between
   them is hidden); from 768px they share one. */
#tab-insights .ins-answer { padding: 2px 0 8px; font-size: 13px; line-height: 1.5; }
#tab-insights .ins-answer-part { display: block; min-width: 0; overflow-wrap: anywhere; }
#tab-insights .ins-answer-sep { display: none; }
#tab-insights .ins-answer-card { color: var(--ink); font-weight: 800; }
/* Cards that tie for Hardest / Easiest: ", Bomber (+2)" right behind the first
   name (R1-15) - the same names, one step quieter than the headline card. */
#tab-insights .ins-answer-tied { color: var(--ink-2); font-weight: 700; }
#tab-insights .ins-sortrow { display: flex; gap: 8px; padding: 0 0 6px; }
@media (min-width: 768px) {
  #tab-insights .ins-answer-part { display: inline; }
  #tab-insights .ins-answer-sep { display: inline; }
}

/* The in-list "Show all (n)" / "Show more (n)" / "Show less" button is the
   shared `.list-more` (components.css) - no screen-local style. */

/* ---------- a matchup row: art | name | games | meter | pct ---------- */

#tab-insights .ins-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-top: 1px solid var(--line);
  min-height: 36px;
}
#tab-insights .ins-list > .ins-row:first-child { border-top: 0; }
#tab-insights .ins-row .art-row { flex: 0 1 auto; min-width: 0; }
#tab-insights .ins-vs-name {
  flex: 1 1 84px;
  min-width: 0;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#tab-insights .ins-games { flex: none; width: 34px; text-align: right; }
#tab-insights .ins-row .meter { flex: 1 1 56px; min-width: 44px; height: 6px; }
#tab-insights .ins-row .pct { flex: none; width: 44px; text-align: right; }

/* Opponent decks: eight xs chips, then the numbers pushed to the right edge
   exactly as the artboard lays them out. 8 x 22 + 7 x 3 = 197px of art leaves
   room for games + win% on one 390px line; below 380px the chip gap tightens by
   a pixel rather than letting the deck wrap onto a second row. */
#tab-insights .ins-vs-deck .art-row { flex: 0 1 auto; }
#tab-insights .ins-vs-deck .ins-games { margin-left: auto; }
@media (max-width: 379px) {
  #tab-insights .ins-vs-deck .art-row { gap: 2px; }
}

/* ---------- percentages (R-010 honesty rendering) ---------- */

#tab-insights .pct {
  font-weight: 800;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
#tab-insights .pct.good { color: var(--good); }
#tab-insights .pct.bad { color: var(--bad); }
/* Small sample: muted + italic + the asterisk pctSpan already appends. Shown,
   never hidden - the number is real, there is just little behind it. */
#tab-insights .pct.low-sample {
  color: var(--ink-3);
  font-style: italic;
  font-weight: 700;
}
#tab-insights .meter .fill.is-good { background: var(--good); }
#tab-insights .meter .fill.is-bad { background: var(--bad); }
#tab-insights .meter .fill.is-low { background: var(--ink-3); }

/* ---------- a combo: cards + win % / complement + games / one meter ---------- */

#tab-insights .ins-combo { border-top: 1px solid var(--line); }
#tab-insights .ins-list > .ins-combo:first-child { border-top: 0; }
#tab-insights .ins-combo-main {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 11px 0;
}
#tab-insights details.ins-combo > summary.ins-combo-main {
  cursor: pointer;
  list-style: none;
}
#tab-insights details.ins-combo > summary.ins-combo-main::-webkit-details-marker { display: none; }
#tab-insights details.ins-combo > summary.ins-combo-main::marker { content: ""; }
#tab-insights .ins-combo-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
#tab-insights .ins-combo-top .art-row { flex: 0 1 auto; min-width: 0; }
#tab-insights .ins-combo-top .pct { flex: none; font-size: 15px; }
#tab-insights .ins-combo-sub {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 12px;
  color: var(--ink-3);
}
/* The complement is ONE muted line that ellipsizes - never wraps. */
#tab-insights .ins-combo-with {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#tab-insights .ins-combo-games { flex: none; }
#tab-insights .ins-combo-sub .i { color: var(--ink-3); transition: transform .12s ease; }
#tab-insights details.ins-combo[open] .ins-combo-sub .i { transform: rotate(180deg); }
#tab-insights .ins-combo-main .meter { height: 5px; }
#tab-insights .ins-combo.low .ins-combo-with,
#tab-insights .ins-combo.low .ins-combo-games { font-style: italic; }

/* The per-variant records behind an expandable combo: indented, no surface. */
#tab-insights .ins-variants {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 0 12px 12px;
}
#tab-insights .ins-variant {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
#tab-insights .ins-variant-cards { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#tab-insights .ins-variant-nums { flex: none; display: inline-flex; align-items: baseline; }
#tab-insights .ins-variant-nums .pct { width: auto; font-size: 12px; }

#tab-insights .ins-singles { border-top: 1px solid var(--line); padding: 2px 0 0; }
/* One text run, so flex centring is safe here (no inter-child white space to
   lose) - and the 36px floor is the R-005 hit target, not decoration. */
#tab-insights .ins-singles summary {
  cursor: pointer;
  padding: 8px 0;
  min-height: 36px;
  display: flex;
  align-items: center;
}
#tab-insights .ins-singles-note { padding: 0 0 4px; }
#tab-insights .ins-singles .ins-combo:first-of-type { border-top: 0; }

#tab-insights .ins-empty { color: var(--ink-2); }

/* The screen's loading state (first visit, a player switch, a Retry): a few
   shimmering bars - no figure of any player or window (R1-04). */
#tab-insights .ins-loading { display: flex; flex-direction: column; gap: 12px; padding: 6px 0; }
#tab-insights .ins-skel { height: 14px; border-radius: 7px; }
#tab-insights .ins-skel-head { height: 56px; border-radius: 12px; }
#tab-insights .ins-skel-short { width: 60%; }

/* ---------- wider viewports ---------- */

@media (min-width: 768px) {
  #tab-insights .ins-deck-row { gap: 6px; }
  #tab-insights .ins-head { padding: 14px 16px 16px; }
  #tab-insights .ins-vs-name { flex-basis: 120px; }
  #tab-insights .ins-row .meter { flex-basis: 120px; }
  #tab-insights .ins-controls { flex-direction: row; flex-wrap: wrap; gap: 8px 28px; }
  #tab-insights .ins-ctl-row { justify-content: flex-start; }
}

/* Desktop. The screen takes the whole content width (the same width as the
   Decks grid), so the two things that would otherwise stretch are laid out in
   columns: the header is [8 cards | the deck's record] under the picker, and the
   combo list runs two columns - a row stays a readable measure with its
   percentage next to its own bar. */
@media (min-width: 1024px) {
  #tab-insights .ins-head {
    display: grid;
    /* The 8 cards take up to 8 x 72px, but never the room the record needs:
       the second column keeps a 220px floor and the cards shrink to fit. */
    grid-template-columns: minmax(0, 620px) minmax(220px, 1fr);
    grid-template-areas: "top top" "cards stats";
    align-items: center;
    column-gap: 32px;
    row-gap: 12px;
  }
  #tab-insights .ins-head-top { grid-area: top; }
  #tab-insights .ins-deck-row {
    grid-area: cards;
    grid-template-columns: repeat(8, minmax(0, 72px));
    justify-content: start;
  }
  #tab-insights .ins-head-stats { grid-area: stats; flex-wrap: wrap; }
  #tab-insights .ins-head-stats .pct { font-size: 36px; }

  #tab-insights .ins-combos .ins-list,
  #tab-insights .ins-singles-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 24px;
    align-items: start;
  }
  #tab-insights .ins-combos .ins-list > .ins-combo:nth-child(2),
  #tab-insights .ins-singles-list > .ins-combo:nth-child(2) { border-top: 0; }
  /* Everything that is not a combo row spans both columns. */
  #tab-insights .ins-combos .ins-list > :not(.ins-combo),
  #tab-insights .ins-singles-list > :not(.ins-combo) { grid-column: 1 / -1; }
}
