/* NOBSDL_YT_FORMAT_GRID_V1 — shared compact grid presentation for the
 * YouTube video/audio format-choice consumers only:
 *   /youtube-downloader, /youtube-to-mp3, /youtube-shorts-downloader
 * DOM is built by NobsdlFormatCards.renderGrid() in youtube-format-cards.js.
 * Class names are yt-fmt-* and intentionally do not reuse/override
 * format-list, format-download-btn, format-card-*, or v3-format-btn —
 * those remain exactly as-is for every non-YouTube platform page.
 * Falls back to literal colors when a host page's design-token variables
 * (--text-primary/--text-muted/--border-glass/--accent-primary) are
 * unset, but nobsdl.css/core.css both already define matching ones.
 *
 * NOBSDL_YT_FORMAT_GRID_DESKTOP_POLISH_V1 (owner refinement pass,
 * 2026-09-11): widens the result/media panel and grows the grid to 4
 * (video) / 3 (audio) columns on wide desktop, using flexbox wrap +
 * justify-content:center instead of CSS grid — this makes "N columns,
 * centered, never stretched" and "odd/short count still centers" fall
 * out of the layout model itself instead of needing per-count CSS
 * hacks, and keeps the exact same mobile geometry (2-col, centered odd
 * final card) as the previous grid-based implementation. The panel/
 * thumbnail/media-header widening is scoped via body[data-page="..."]
 * (set by each of the 3 consumer pages already) so it can never leak
 * onto #uniInfoSection/#uniThumbnail (universal downloader) or any
 * other page that happens to share nobsdl.css's generic result-panel
 * rule.
 */

.yt-fmt-grid {
  --yt-fmt-cols: 2;
  --yt-fmt-gap: 10px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: stretch;
  gap: var(--yt-fmt-gap);
  width: 100%;
  max-width: 380px;
  margin: 0 auto 0.25rem;
}

.yt-fmt-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  flex: 0 1 calc((100% - (var(--yt-fmt-cols) - 1) * var(--yt-fmt-gap)) / var(--yt-fmt-cols));
  min-width: 0;
  min-height: 60px;
  padding: 0.7rem 0.5rem;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(99, 102, 241, 0.32);
  border-radius: 14px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
  color: var(--text-primary, #f1f5f9);
  cursor: pointer;
  font-family: inherit;
  text-align: center;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.yt-fmt-card:hover {
  border-color: var(--accent-primary, #6366f1);
  background: rgba(99, 102, 241, 0.12);
}

.yt-fmt-card:focus-visible {
  outline: 2px solid var(--accent-primary, #6366f1);
  outline-offset: 2px;
}

.yt-fmt-card-quality {
  font-weight: 700;
  font-size: 0.92rem;
  line-height: 1.3;
  color: var(--text-primary, #f1f5f9);
}

.yt-fmt-card-size {
  font-weight: 400;
  font-size: 0.76rem;
  line-height: 1.3;
  color: var(--text-muted, #64748b);
}

.yt-fmt-card-supporter {
  display: block;
  margin-top: 2px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #f59e0b;
}

.yt-fmt-card--locked {
  border-color: rgba(245, 158, 11, 0.46);
  background: rgba(245, 158, 11, 0.06);
}

.yt-fmt-card--locked:hover {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, 0.14);
}

.yt-fmt-card--locked .yt-fmt-card-quality {
  color: var(--text-primary, #f1f5f9);
}

/* Optional section label above a grid (used where a page has no static
   heading of its own, e.g. the Shorts page's JS-rendered groups). */
.yt-fmt-group-label {
  text-align: center;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted, #64748b);
  margin-bottom: 0.5rem;
}

/* Only below a genuinely tiny viewport does the grid collapse to one
   column - 390/412px (the primary acceptance viewports) must stay
   2-column. */
@media (max-width: 340px) {
  .yt-fmt-grid {
    --yt-fmt-cols: 1;
    max-width: 220px;
  }
}

/* ── Tablet / small desktop (768–1199px): still 2 columns everywhere -
   just a little more breathing room, never tiny forced columns. ── */
@media (min-width: 768px) {
  .yt-fmt-grid {
    --yt-fmt-gap: 12px;
    max-width: 460px;
    margin-bottom: 0.75rem;
  }

  /* Result/media panel: nobsdl.css's shared #videoInfoSection rule (also
     used by #uniInfoSection on the universal downloader) caps this at a
     mobile-scale 640px. Scoped to the 3 YouTube pages via body[data-page]
     (already set by each page) so #uniInfoSection is never touched.
     text-align:center here also centers the thumbnail/title/meta as a
     stacked, deliberate media header instead of the left-biased default -
     the Shorts page's .v3-media-meta is already centered, untouched. */
  body[data-page="youtube"] #videoInfoSection,
  body[data-page="youtube-mp3"] #videoInfoSection {
    max-width: 900px;
    padding: 2rem;
    text-align: center;
  }
  body[data-page="youtube"] #videoDLThumbnail,
  body[data-page="youtube-mp3"] #videoDLThumbnail {
    max-width: 420px;
    margin: 0 auto 1rem;
  }
  body[data-page="youtube"] #videoDLMeta,
  body[data-page="youtube-mp3"] #videoDLMeta {
    margin-bottom: 1.4rem;
  }
}

/* ── Wide desktop (>=1200px): VIDEO grows to 4 columns, AUDIO to 3 -
   using flex-wrap so a shorter/odd count still centers itself instead
   of stretching to fill the row. ── */
@media (min-width: 1200px) {
  body[data-page="youtube"] #videoInfoSection,
  body[data-page="youtube-mp3"] #videoInfoSection {
    max-width: 960px;
  }

  .yt-fmt-grid--video {
    --yt-fmt-cols: 4;
    --yt-fmt-gap: 14px;
    max-width: 760px;
  }

  .yt-fmt-grid--audio {
    --yt-fmt-cols: 3;
    --yt-fmt-gap: 14px;
    max-width: 580px;
  }

  .yt-fmt-grid--video .yt-fmt-card,
  .yt-fmt-grid--audio .yt-fmt-card {
    min-height: 68px;
    padding: 0.8rem 0.6rem;
  }
}
