/* =============================================================================
   Digest PAGE  (body[data-page="digest"])
   Page-specific rules only - resets, tokens, topbar/nav, .page, .page-header/
   .page-title/.page-sub, .state-box/.spinner/.state-msg/.state-err,
   .ctrl-item/.ctrl-label/.ctrl-select, .section-label, .btn are already
   defined in /assets/css/styles.css and reused as-is.
   ============================================================================= */

/* ── Period bar — full width, one panel for period-type + date nav ── */
.period-bar {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: 20px 26px; margin-bottom: 28px;
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  flex-wrap: wrap;
}
.period-bar-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }

/* ── Type toggle ── */
.type-toggle {
  display: flex; gap: 3px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; padding: 3px;
}
.type-btn {
  font-family: var(--mono); font-size: .8rem; color: var(--muted);
  background: transparent; border: none; border-radius: 6px;
  padding: 9px 18px; cursor: pointer; transition: color .15s, background .15s;
}
.type-btn:hover { color: var(--text); }
.type-btn.active { color: var(--text); background: var(--surface); font-weight: 500; }

/* ── Period nav ── */
.period-nav {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.period-arrow {
  width: 38px; height: 38px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 8px;
  color: var(--muted); cursor: pointer; transition: color .15s, border-color .15s, background .15s;
}
.period-arrow:hover:not(:disabled) { color: var(--text); border-color: rgba(255,255,255,.15); background: var(--surface); }
.period-arrow:disabled { opacity: .3; cursor: not-allowed; }
.period-label-wrap { display: flex; flex-direction: column; gap: 3px; min-width: 110px; }
.period-label { font-size: 1.15rem; font-weight: 600; color: var(--text); white-space: nowrap; }
.period-label.is-month { font-size: 1.5rem; letter-spacing: -.01em; }
.period-sub { font-family: var(--mono); font-size: .82rem; font-weight: 500; color: var(--text); opacity: .65; }
.period-live {
  font-family: var(--mono); font-size: .6rem; text-transform: uppercase; letter-spacing: .1em;
  color: var(--green); border: 1px solid rgba(111,207,151,.3); background: rgba(111,207,151,.1);
  padding: 2px 7px; border-radius: 3px; align-self: flex-start; white-space: nowrap; margin-bottom: 1px;
}
@media (max-width: 700px) {
  .period-bar { flex-direction: column; align-items: stretch; padding: 18px; }
}


/* ── Icon sprite base ── */
.icon { width: 15px; height: 15px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ── Hero strip ── */
.hero-strip {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 2px;
  margin-bottom: 28px; border-radius: var(--r); overflow: hidden;
}
@media (max-width: 980px) { .hero-strip { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 560px) { .hero-strip { grid-template-columns: repeat(2, 1fr); } }
.hero-tile {
  background: var(--surface); border: 1px solid var(--border); margin: -1px;
  padding: 16px 16px; display: flex; flex-direction: column; gap: 8px;
  position: relative; overflow: hidden;
}
.hero-tile::before {
  content: ''; position: absolute; top: 0; left: 0; width: 3px; height: 100%;
  background: var(--accent); opacity: .55;
}
.hero-tile-icon {
  width: 26px; height: 26px; border-radius: 6px;
  background: var(--accent-dim); border: 1px solid var(--accent-border);
  color: var(--accent); display: flex; align-items: center; justify-content: center;
}
.hero-tile-icon .icon { width: 14px; height: 14px; }
.hero-tile-label {
  font-family: var(--mono); font-size: .6rem; text-transform: uppercase;
  letter-spacing: .07em; color: var(--muted2);
}
.hero-tile-val {
  font-family: var(--mono); font-size: 1.5rem; font-weight: 500;
  letter-spacing: -.02em; color: var(--text); line-height: 1;
}
.hero-tile-val.na { color: var(--muted2); font-size: 1.05rem; font-weight: 400; }
.hero-tile-sub { font-family: var(--mono); font-size: .64rem; color: var(--muted); }
@media (max-width: 640px) { .hero-tile-val { font-size: 1.3rem; } }

/* ── Category tabs ── */
.cat-tabs {
  display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.cat-tab {
  font-family: var(--mono); font-size: .72rem; color: var(--muted);
  background: transparent; border: none; white-space: nowrap;
  padding: 11px 14px; cursor: pointer; position: relative; transition: color .15s;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  flex: 1 1 0; min-width: 120px;
}
.cat-tab .icon { width: 13px; height: 13px; opacity: .7; }
.cat-tab:hover { color: var(--text); }
.cat-tab.active { color: var(--text); font-weight: 500; }
.cat-tab.active .icon { opacity: 1; }
.cat-tab.active::after {
  content: ''; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px;
  background: var(--accent); border-radius: 2px 2px 0 0;
}
@media (max-width: 700px) {
  .cat-tab { flex: 1 1 33%; }
}

/* ── Stat grid ── */
.digest-section { margin-bottom: 8px; }
.stat-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px;
}
@media (max-width: 980px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 860px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .stat-grid { grid-template-columns: 1fr; } }

/* ── Leader grid — player-record cards are the "hero" content of the
   section, so instead of sitting in fixed quarter-width slots (leaving a
   dead gap whenever there are fewer than 4 records), the row sizes its
   columns to however many leader tiles actually exist, so each card
   stretches to fill the row like the 4-up totals row above it. Content
   inside gets a matching size bump so the extra width is used, not just
   empty padding. ── */
/* Flexbox instead of grid: with flex-wrap + flex-grow, whatever cards
   land on the last row automatically stretch to fill the full row width
   (grid can't do this — its columns are fixed, so a lone leftover card
   sits at 1/Nth width with empty space beside it). This way every row,
   in every tab, always fills edge-to-edge regardless of how many leader
   tiles that tab happens to have. */
.leader-grid { display: flex; flex-wrap: wrap; gap: 2px; }
.leader-grid + .leader-grid { margin-top: 2px; }
.leader-grid .stat-tile.is-leader { flex: 1 1 calc(100% / var(--cols, 4) - 2px); padding: 18px 20px; min-width: 190px; }
/* Wide cards — records that carry more content than a name + number
   (a duo relationship with two identities, or a K/D card stacking a
   ratio, a K:A:D breakdown, and a map link) get roughly double the row
   share so that content lays out instead of being squeezed into the
   same slot as a plain single-value record. */
/* Wide cards get a dedicated full-width row instead of a fractional
   flex-basis. A partial-width wide card sitting next to normal cards is
   what caused the staggered/asymmetric look — every row's column edges
   shifted depending on what happened to land next to the wide card. Making
   it flex-basis:100% forces a clean row break before and after it, so
   normal cards always pack into their own evenly-filled rows and the wide
   card always gets a full row to lay its extra content (ratio + K:A:D +
   map link, or the two duo faces) out horizontally. */
.leader-grid .stat-tile.is-leader.is-wide { flex: 1 1 100%; }
.leader-grid .stat-tile.is-leader.is-nemesis { padding: 22px 28px; }
.leader-grid .stat-tile.is-leader.is-nemesis .stat-tile-hd { margin-bottom: 14px; }

/* ── Fun group forced to a real 2-column grid ──────────────────────────────
   The flex-basis-from-percentage trick above is meant for groups whose
   record count varies unpredictably (hence needing the leftover-row
   stretch behavior). "Fun" is always capped at 2-per-row by design (see
   maxCols in renderSection()), so instead of trusting that same
   percentage math to land on exactly 2 every time, this locks it down
   explicitly with real CSS grid columns - guaranteed 2-per-row, no
   dependence on flex-basis/gap arithmetic. Two classes here beats
   .leader-grid's single class on specificity, so this always wins
   regardless of source order. */
.leader-grid.fun-grid {
  display: grid !important;
  grid-template-columns: repeat(2, 1fr) !important;
}
.leader-grid.fun-grid .stat-tile.is-leader { flex: none; min-width: 0; }
@media (max-width: 560px) {
  .leader-grid.fun-grid { grid-template-columns: 1fr !important; }
}
@media (max-width: 560px) {
  .leader-grid .stat-tile.is-leader { flex-basis: 100%; }
  .leader-grid .stat-tile.is-leader { padding: 18px 20px; }
  .leader-grid .lt-badge { font-size: 1.8rem; }
}

.stat-tile {
  background: var(--surface); border: 1px solid var(--border);
  padding: 16px 18px; margin: -1px;
  display: flex; flex-direction: column; gap: 8px;
}

/* Counter tiles — plain totals, no attributed player */
.stat-tile.is-counter .stat-tile-hd { color: var(--muted); }
.stat-tile.is-counter .icon { color: var(--muted); }
.stat-tile.is-counter .stat-tile-val { font-family: var(--mono); font-weight: 500; }

/* Leader tiles — records tied to a specific player/weapon/map result */
.stat-tile.is-leader { position: relative; padding-left: 21px; }
.stat-tile.is-leader::before {
  content: ''; position: absolute; top: 14px; bottom: 14px; left: 0; width: 3px;
  background: var(--gold); opacity: .45; border-radius: 2px;
}
.stat-tile.is-leader .icon { color: var(--gold); }
.stat-tile.is-leader .stat-tile-val { font-weight: 600; }

.stat-tile-hd {
  display: flex; align-items: center; gap: 7px;
  padding-bottom: 8px; margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.stat-tile-label {
  font-family: var(--mono); font-size: .62rem; text-transform: uppercase;
  letter-spacing: .07em; color: var(--muted2);
}
.stat-tile-val { font-size: .92rem; color: var(--text); letter-spacing: -.01em; line-height: 1.4; }
.stat-tile-val.na { color: var(--muted2); font-weight: 400 !important; }
/* ── Group label — separates "who did this" from plain totals ── */
.group-label {
  display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px;
}
.group-label > span:first-child {
  display: flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: .68rem; font-weight: 500;
  text-transform: uppercase; letter-spacing: .07em; color: var(--text);
}
.group-label .icon { width: 12px; height: 12px; color: var(--gold); }
.group-sub { font-family: var(--mono); font-size: .64rem; color: var(--muted2); }
.digest-section + .digest-section { margin-top: 22px; }

/* ── Leader tile — parsed name / detail / breakdown, laid out with real
   spacing instead of a cramped pill so it reads like a sentence, not a
   tag cloud. Name carries the weight; detail sits as a plain colored
   value beneath it; breakdown is a quiet caption. ── */
/* ── Leader-card head — avatar sits next to the name so the whole
   identity (face + name + ID) reads as one unit instead of a name
   floating above an ID line two rows down. Mirrors .player-cell /
   .list-av / .player-id-block from the profiles page. ── */
.lt-head { display: flex; align-items: center; gap: 10px; }
.lt-avatar {
  width: 38px; height: 38px; flex-shrink: 0;
  border-radius: 0; /* no rounded corners on avatars anywhere in the product */
  border: 1px solid rgba(255,255,255,.1);
  background: var(--surface2);
  object-fit: cover; display: block;
}
.lt-text-block { display: flex; flex-direction: column; gap: 0; min-width: 0; }
.lt-name { font-size: 1rem; font-weight: 600; color: var(--text); letter-spacing: -.01em; display: inline-block; line-height: 1.25; }
.lt-name.lt-link { text-decoration: none; cursor: pointer; transition: color .15s; }
.lt-name.lt-link:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
/* Pulled right up under the name (was margin-top: 2px with a shrunken,
   easy-to-miss platform icon) so the ID reads as part of the same
   identity line, and the platform icon is legible at a glance instead
   of a near-invisible speck. */
.lt-id-row { display: flex; align-items: center; gap: 6px; margin-top: 1px; }
.lt-id-row .pid-mini-wrap { width: auto; }
.lt-id-row .act-btn-mini { width: 26px; height: 26px; padding: 4px; }
.lt-id-row .act-btn-mini svg, .lt-id-row .act-btn-mini img { width: 16px; height: 16px; }
.lt-id-row .pid-mini { font-size: .64rem; padding: 1px 5px; }
.lt-detail-row { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.lt-badge {
  font-family: var(--mono); font-size: 1.6rem; font-weight: 700; color: var(--gold);
  letter-spacing: -.02em; line-height: 1;
}
.lt-breakdown { font-family: var(--mono); font-size: .72rem; color: var(--muted); }
/* ── Two-line badge variant (most-loyal-weapon) ──────────────────────────
   Same font/color/weight as .lt-badge, but stacked as two block lines
   instead of one wrapping inline run - see fmtLeaderVal()'s
   loyalWeaponLines handling for why this needs an intentional break
   rather than relying on soft-wrap. */
.lt-badge-lines { display: flex; flex-direction: column; gap: 2px; }
.lt-badge-line { display: block; }
/* ── Duo card variant — records about a RELATIONSHIP between two players
   (best duo, nemesis + victim) are a different kind of thing than a solo
   leaderboard record, so they get their own layout: two faces side by
   side with a connector between them, badge moved below both names.
   Color stays the same gold as every other leader tile (inherited from
   .stat-tile.is-leader::before / .icon above) so the page keeps one
   consistent accent instead of a red/blue/gold mix. ── */
.lt-duo-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.lt-duo-person { display: flex; align-items: center; gap: 8px; min-width: 0; }
.lt-duo-person .lt-avatar { width: 32px; height: 32px; }
.lt-duo-person .lt-name { font-size: .88rem; }
.lt-connector {
  font-family: var(--mono); font-size: .64rem; text-transform: uppercase;
  letter-spacing: .05em; color: var(--muted2); flex-shrink: 0;
}
.lt-duo-ids { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 4px; }
.lt-duo-ids .lt-id-row { margin-top: 0; }

/* ── Nemesis card — a full-width relationship record gets a completely
   dedicated layout instead of reusing the compact duo-face pattern: each
   player gets their own clearly labeled half (KILLER / VICTIM) so the
   extra width of a wide card is actually spent on identity, not just a
   bigger gap between two small faces. A center column holds the shared
   kill count, with a divider on each side instead of a single skinny
   connector word. ── */
.nemesis-panel {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  gap: 28px; padding: 4px 8px;
}
.nemesis-side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.nemesis-side.nemesis-victim { align-items: flex-end; text-align: right; }
.nemesis-side.nemesis-victim .lt-head { flex-direction: row-reverse; }
.nemesis-side.nemesis-victim .lt-text-block { align-items: flex-end; }
.nemesis-side.nemesis-victim .lt-id-row { flex-direction: row-reverse; }
.nemesis-tag {
  display: inline-flex; align-items: center; gap: 6px; align-self: flex-start;
  font-family: var(--mono); font-size: .62rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .1em; padding: 3px 9px; border-radius: 4px; width: fit-content;
}
.nemesis-side.nemesis-victim .nemesis-tag { align-self: flex-end; }
.nemesis-tag.is-killer { color: var(--gold); background: rgba(230,180,80,.1); border: 1px solid rgba(230,180,80,.3); }
.nemesis-tag.is-victim { color: var(--muted); background: var(--surface2); border: 1px solid var(--border); }
.nemesis-side .lt-avatar { width: 46px; height: 46px; }
.nemesis-side .lt-name { font-size: 1.05rem; }
.nemesis-center {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: 0 20px; position: relative;
}
.nemesis-center::before, .nemesis-center::after {
  content: ''; position: absolute; top: 50%; width: 1px; height: 60px;
  transform: translateY(-50%); background: var(--border);
}
.nemesis-center::before { left: 0; }
.nemesis-center::after { right: 0; }
.nemesis-center-val { font-family: var(--mono); font-size: 1.9rem; font-weight: 700; color: var(--gold); letter-spacing: -.02em; line-height: 1; white-space: nowrap; margin-top: 6px; }
.nemesis-center .icon { width: 18px; height: 18px; opacity: .8; }
.nemesis-tag .icon { width: 11px; height: 11px; }
@media (max-width: 700px) {
  .nemesis-panel { grid-template-columns: 1fr; gap: 14px; }
  .nemesis-side.nemesis-victim { align-items: flex-start; text-align: left; }
  .nemesis-side.nemesis-victim .lt-head { flex-direction: row; }
  .nemesis-side.nemesis-victim .lt-text-block { align-items: flex-start; }
  .nemesis-side.nemesis-victim .lt-id-row { flex-direction: row; }
  .nemesis-side.nemesis-victim .nemesis-tag { align-self: flex-start; }
  .nemesis-center { flex-direction: row; justify-content: flex-start; gap: 10px; padding: 8px 0; }
  .nemesis-center::before, .nemesis-center::after { width: 60px; height: 1px; top: 0; transform: none; }
  .nemesis-center::before { left: 50%; transform: translateX(-50%); top: -7px; }
  .nemesis-center::after { display: none; }
  .nemesis-center-label { margin-top: 0; }
}

.stat-tile-sub { font-family: var(--mono); font-size: .66rem; color: var(--muted); }
.stat-tile-meta {
  display: flex; align-items: center; gap: 12px; margin-top: 2px;
  font-family: var(--mono); font-size: .64rem; color: var(--muted2);
}
.stat-tile-meta span { display: inline-flex; align-items: center; gap: 4px; }
.stat-tile-meta .icon { width: 11px; height: 11px; }

a.stat-tile-meta-link { text-decoration: none; cursor: pointer; transition: color .15s; }
a.stat-tile-meta-link:hover { color: var(--text); }
a.stat-tile-meta-link:hover .icon { color: var(--accent); }


@media (max-width: 640px) {
  .stat-tile-val { font-size: .86rem; }
}

/* ── Media tiles — map / mode / team-win-rate stats carry a thumbnail,
   so they read as "a picture of a thing" rather than a line of text like
   every other counter. Pulled into their own row above the plain tiles
   (own background tint + border) so a scan of the page separates "things
   with art" from "things that are just numbers" at a glance. ── */
.media-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px;
}
@media (max-width: 860px) { .media-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .media-grid { grid-template-columns: 1fr; } }
.media-tile {
  background: var(--surface2); border: 1px solid var(--border);
  margin: -1px; padding: 14px 16px;
  display: flex; align-items: center; gap: 12px;
}
.media-thumb {
  width: 84px; height: 44px; border-radius: 6px; object-fit: cover; object-position: center;
  flex-shrink: 0; display: block;
}
.media-thumb-ph { width: 84px; height: 44px; border-radius: 6px; flex-shrink: 0; background: var(--surface); border: 1px solid var(--border2); }
.media-thumb.team-thumb { width: 44px; object-fit: contain; }
.media-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.media-label {
  font-family: var(--mono); font-size: .6rem; text-transform: uppercase;
  letter-spacing: .07em; color: var(--muted2);
}
.media-val { font-size: .92rem; font-weight: 600; color: var(--text); letter-spacing: -.01em; line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-val.na { color: var(--muted2); font-weight: 400; }
.media-sub { font-family: var(--mono); font-size: .64rem; color: var(--muted); }
.digest-section + .media-grid,
.media-grid + .digest-section { margin-top: 22px; }

/* ── Rounds tab hero rows — "Maps in rotation" / "Most-used mutator" and
   the shortest/longest round records lead the Modes, Maps & Rounds tab as
   bigger, 2-up panels rather than sitting in the standard 4-up totals
   grid, since they carry more to show (the round-record tiles in
   particular need room for the round number + mode + map-link meta row
   below the headline value). ── */
.rounds-hero-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 2px;
}
.rounds-hero-grid .stat-tile { padding: 24px 26px; }
.rounds-hero-grid .stat-tile-label { font-size: .68rem; }
.rounds-hero-grid .stat-tile-val { font-size: 1.15rem; }
.rounds-hero-grid .stat-tile-meta {
  font-size: .7rem; gap: 16px; margin-top: 8px; padding-top: 10px;
  border-top: 1px solid var(--border);
}
.rounds-hero-grid .stat-tile-meta .icon { width: 12px; height: 12px; }
@media (max-width: 640px) {
  .rounds-hero-grid { grid-template-columns: 1fr; }
}

/* ── Combat tab — explicit, hardcoded layout. No row/col math, no
   flex-grow guessing at how many tiles happen to exist: every row below
   is a fixed, named grid with a fixed number of columns, and each stat
   is placed into it by hand. Wide records (Best K/D x2, Nemesis) get
   their own full-width row so their extra content (ratio + K:A:D +
   map link, or a duo face-off) always has room to lay out horizontally
   instead of being squeezed into a shared fractional slot. ── */
.combat-grid { display: flex; flex-direction: column; gap: 2px; }
.combat-row { display: grid; gap: 2px; }
.combat-row.cols-1 { grid-template-columns: 1fr; }
.combat-row.cols-2 { grid-template-columns: repeat(2, 1fr); }
.combat-row.cols-3 { grid-template-columns: repeat(3, 1fr); }
.combat-row.cols-4 { grid-template-columns: repeat(4, 1fr); }
.combat-grid .stat-tile { padding: 18px 20px; }
.combat-grid .stat-tile.is-wide { padding-left: 23px; }
@media (max-width: 860px) {
  .combat-row.cols-3, .combat-row.cols-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .combat-row.cols-2, .combat-row.cols-3, .combat-row.cols-4 { grid-template-columns: 1fr; }
  .combat-grid .stat-tile { padding: 18px 20px; }
  .combat-grid .lt-badge { font-size: 1.8rem; }
}
