/* ---------- Design tokens ---------- */
:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --bg-tint: #eceef2;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --text: #11151b;
  --text-2: #39414d;
  --muted: #646e7d;
  --border: #dfe3e9;
  --border-strong: #c9cfd8;
  --accent: #0a6b3d;
  --accent-hover: #075530;
  --accent-soft: #e7f2ec;
  --accent-text: #0a5c35;
  --accent-contrast: #ffffff;
  --chip-bg: #ffffff;
  --chip-border: #dfe3e9;
  --tag-bg: #eef1f5;
  --tag-text: #4a5462;
  --focus: #1a5fd0;
  --live: #c62828;
  --live-strong: #a41d1d;
  --live-soft: #fdeaea;
  --live-contrast: #ffffff;
  --skeleton: #e6e9ee;
  --skeleton-hi: #f3f5f8;
  --shadow-sm: 0 1px 2px rgba(17, 21, 27, .05), 0 0 0 1px rgba(17, 21, 27, .02);
  --shadow-md: 0 4px 14px -4px rgba(17, 21, 27, .14), 0 1px 3px rgba(17, 21, 27, .06);
  --rail-fade: #f4f5f7;

  /* One reading column, widened only once the screen is genuinely large. */
  --maxw: 940px;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: Newsreader, Georgia, "Times New Roman", serif;
  /* Persian-capable stack; the system fallbacks cover macOS, Windows and Linux. */
  --fa: Vazirmatn, "Iran Sans", "Segoe UI", Tahoma, "Geeza Pro", system-ui, sans-serif;
}

/* Farsi interface: one Persian-capable family for body and display text alike
   (Newsreader has no Persian glyphs, so keeping it would fall back unevenly). */
html[lang="fa"] {
  --sans: var(--fa);
  --serif: var(--fa);
}

/* Explicit dark tokens: system preference, unless a theme is pinned. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0c0f13;
    --bg-tint: #12161c;
    --surface: #14191f;
    --surface-2: #1a2027;
    --text: #edeff3;
    --text-2: #c2c9d3;
    --muted: #8e99a8;
    --border: #232a33;
    --border-strong: #333c47;
    --accent: #45c98a;
    --accent-hover: #63d79d;
    --accent-soft: #14281f;
    --accent-text: #6fdba5;
    --accent-contrast: #05150d;
    --chip-bg: #171d24;
    --chip-border: #262e38;
    --tag-bg: #1d242c;
    --tag-text: #a6b0bd;
    --focus: #7cb2ff;
    --live: #ff6b6b;
    --live-strong: #ff8f8f;
    --live-soft: #3a1618;
    --live-contrast: #1a0708;
    --skeleton: #1c222a;
    --skeleton-hi: #262e37;
    --shadow-sm: 0 0 0 1px rgba(255, 255, 255, .02);
    --shadow-md: 0 6px 18px -8px rgba(0, 0, 0, .7);
    --rail-fade: #0c0f13;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c0f13;
  --bg-tint: #12161c;
  --surface: #14191f;
  --surface-2: #1a2027;
  --text: #edeff3;
  --text-2: #c2c9d3;
  --muted: #8e99a8;
  --border: #232a33;
  --border-strong: #333c47;
  --accent: #45c98a;
  --accent-hover: #63d79d;
  --accent-soft: #14281f;
  --accent-text: #6fdba5;
  --accent-contrast: #05150d;
  --chip-bg: #171d24;
  --chip-border: #262e38;
  --tag-bg: #1d242c;
  --tag-text: #a6b0bd;
  --focus: #7cb2ff;
  --live: #ff6b6b;
  --live-strong: #ff8f8f;
  --live-soft: #3a1618;
  --live-contrast: #1a0708;
  --skeleton: #1c222a;
  --skeleton-hi: #262e37;
  --shadow-sm: 0 0 0 1px rgba(255, 255, 255, .02);
  --shadow-md: 0 6px 18px -8px rgba(0, 0, 0, .7);
  --rail-fade: #0c0f13;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* Text for screen readers only: still rendered, so it stays in the
   accessibility tree and contributes to an element's accessible name. */
.vh {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  border: 0; clip: rect(0 0 0 0); clip-path: inset(50%);
  overflow: hidden; white-space: nowrap;
}
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
  text-align: start;
}
img { max-width: 100%; }
.wrap {
  width: 100%; max-width: var(--maxw); margin-inline: auto;
  padding-inline: var(--s4);
  padding-inline: max(var(--s4), env(safe-area-inset-left)) max(var(--s4), env(safe-area-inset-right));
}

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }

.skip {
  position: absolute; inset-inline-start: -9999px; top: 0; z-index: 20;
  background: var(--accent); color: var(--accent-contrast);
  padding: 10px 14px; border-end-end-radius: var(--r-sm); font-weight: 600;
}
.skip:focus { inset-inline-start: 0; }

/* Persian text inside an English interface (and vice versa) still needs a
   Persian-capable face and a slightly taller line box. */
[lang="fa"] { font-family: var(--fa); }
.card h2[lang="fa"], .card .summary[lang="fa"] { font-family: var(--fa); line-height: 1.7; }
.card h2[lang="fa"] { line-height: 1.5; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 8;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
  transition: box-shadow .16s ease;
}
.site-header.scrolled { box-shadow: var(--shadow-md); }
/* While the dialog is open the page behind it is pinned (see lockBody). */
html.modal-open { overflow: hidden; }
.header-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s3); padding-block: var(--s3); flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo {
  flex: 0 0 auto; width: auto; height: 30px; /* 800x458 -> ~52px wide */
  border-radius: 3px; border: 1px solid var(--border);
  box-shadow: var(--shadow-sm); display: block;
}
.brand-text { min-width: 0; }
h1 {
  margin: 0; font-family: var(--serif); font-weight: 600;
  font-size: clamp(1.25rem, 1.1rem + 1vw, 1.6rem);
  line-height: 1.15; letter-spacing: -.015em;
}
html[lang="fa"] h1 { letter-spacing: normal; }
.updated {
  margin: 1px 0 0; color: var(--muted);
  font-size: .78rem; font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
@media (max-width: 460px) { .updated .clock { display: none; } }
.header-actions { display: flex; align-items: center; gap: var(--s2); flex: 0 0 auto; }

/* Interface language switch */
.uilang {
  display: inline-flex; align-items: stretch; flex: 0 0 auto;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--r-sm); overflow: hidden;
}
.uilang-btn {
  appearance: none; background: transparent; color: var(--muted);
  border: 0; cursor: pointer; font: inherit; font-size: .8rem; font-weight: 600;
  padding: 0 10px; min-height: 2.75rem; white-space: nowrap;
  transition: background-color .14s ease, color .14s ease;
}
.uilang-btn + .uilang-btn { border-inline-start: 1px solid var(--border-strong); }
.uilang-btn[lang="fa"] { font-family: var(--fa); }
@media (hover: hover) { .uilang-btn:hover { background: var(--surface-2); color: var(--text); } }
.uilang-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-contrast); }
.uilang-btn:focus-visible { outline-offset: -2px; border-radius: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); color: var(--accent-contrast);
  border: 1px solid transparent; border-radius: var(--r-sm);
  padding: 9px 14px; min-height: 2.75rem;
  font: inherit; font-weight: 600; font-size: .875rem; cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
@media (hover: hover) { .btn:hover { background: var(--accent-hover); } }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.spin svg { animation: spin 1s linear infinite; }
/* The refresh arrow reads as "go around again", not a direction: mirror it in
   RTL so the arrowhead keeps pointing the way the text flows. */
[dir="rtl"] .btn svg { transform: scaleX(-1); }
[dir="rtl"] .btn.spin svg { animation: spin-rtl 1s linear infinite; }
.btn.ghost {
  background: var(--surface); color: var(--text-2); border-color: var(--border-strong);
}
@media (hover: hover) { .btn.ghost:hover { background: var(--surface-2); color: var(--text); } }
.btn.sm { min-height: 2.75rem; padding: 6px 14px; font-size: .8rem; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes spin-rtl { to { transform: scaleX(-1) rotate(360deg); } }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 2.75rem; height: 2.75rem; padding: 0;
  background: var(--surface); color: var(--text-2);
  border: 1px solid var(--border-strong); border-radius: var(--r-sm); cursor: pointer;
}
@media (hover: hover) { .icon-btn:hover { background: var(--surface-2); color: var(--text); } }
.icon-btn .i-moon { display: none; }
.icon-btn[aria-pressed="true"] .i-moon { display: block; }
.icon-btn[aria-pressed="true"] .i-sun { display: none; }

main { padding-top: var(--s5); padding-bottom: var(--s4); }

/* ---------- Controls ---------- */
.controls {
  display: grid; gap: var(--s3); grid-template-columns: 1fr; align-items: end;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: var(--s4); box-shadow: var(--shadow-sm);
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label:not(.switch), .affil-head > label, .label-like {
  font-size: .7rem; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .07em;
}
html[lang="fa"] .field > label:not(.switch),
html[lang="fa"] .affil-head > label,
html[lang="fa"] .label-like {
  text-transform: none; letter-spacing: normal; font-size: .75rem;
}
.input-wrap { position: relative; display: block; }
.input-icon {
  position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%);
  color: var(--muted); pointer-events: none;
}
input[type="search"], select {
  width: 100%; min-height: 44px; padding-block: 10px; padding-inline: 12px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  font: inherit; font-size: .95rem; text-align: start;
}
input[type="search"] { padding-inline-start: 36px; }
input[type="search"]::placeholder { color: var(--muted); }
@media (hover: hover) { input[type="search"]:hover, select:hover { border-color: var(--muted); } }
select { appearance: none; padding-inline-end: 34px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}
[dir="rtl"] select { background-position: 13px 50%, 18px 50%; }

/* Switch */
.switch { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
/* Visually hidden but still rendered, so it stays focusable and in the
   accessibility tree (0x0 / opacity:0 would remove it from both). */
.switch input {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  border: 0; clip: rect(0 0 0 0); clip-path: inset(50%);
  overflow: hidden; white-space: nowrap;
}
.switch .track {
  position: relative; flex: 0 0 auto; width: 40px; height: 24px;
  background: var(--bg-tint); border: 1px solid var(--border-strong);
  border-radius: 999px; transition: background-color .16s ease, border-color .16s ease;
}
.switch .knob {
  position: absolute; top: 2px; inset-inline-start: 2px; width: 18px; height: 18px;
  background: var(--surface); border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
  transition: transform .16s ease;
}
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track .knob { transform: translateX(16px); }
[dir="rtl"] .switch input:checked + .track .knob { transform: translateX(-16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--focus); outline-offset: 2px; }
.switch-text { font-size: .9rem; font-weight: 500; color: var(--text-2); }
.switch input:checked ~ .switch-text { color: var(--text); }
.switch-count {
  margin-inline-start: 6px; color: var(--muted); font-size: .72rem; font-weight: 600;
  font-variant-numeric: tabular-nums; background: var(--tag-bg);
  padding: 1px 6px; border-radius: 999px;
}

/* Segmented control (article language) */
.segmented {
  display: inline-flex; align-items: stretch; align-self: start;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--r-sm); overflow: hidden; min-height: 44px; max-width: 100%;
}
.seg-btn {
  appearance: none; background: transparent; color: var(--text-2);
  border: 0; cursor: pointer; font: inherit; font-size: .84rem; font-weight: 600;
  padding: 0 12px; white-space: nowrap; flex: 1 1 auto;
  transition: background-color .14s ease, color .14s ease;
}
.seg-btn + .seg-btn { border-inline-start: 1px solid var(--border-strong); }
.seg-btn[lang="fa"] { font-family: var(--fa); }
@media (hover: hover) { .seg-btn:hover { background: var(--surface-2); color: var(--text); } }
.seg-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-contrast); }
.seg-btn:focus-visible { outline-offset: -2px; border-radius: 0; }

.hint { margin: var(--s2) 0 0; color: var(--muted); font-size: .8rem; }

/* ---------- Affiliation filter ---------- */
/* Its own full-width row in the controls grid: a select plus the disclosure
   that explains the vocabulary, which needs the horizontal room on one line. */
.field-affil { grid-column: 1 / -1; }
.affil-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s2); flex-wrap: wrap;
}
.field-affil select { max-width: 26rem; }
.affil-info {
  display: inline-flex; align-items: center; gap: 5px; flex: 0 0 auto;
  appearance: none; background: transparent; color: var(--accent-text);
  border: 0; border-radius: var(--r-sm); cursor: pointer;
  font: inherit; font-size: .78rem; font-weight: 600;
  padding: 4px 2px; min-height: 2rem;
}
@media (hover: hover) { .affil-info:hover { color: var(--text); } }
.affil-info svg { flex: 0 0 auto; }
.affil-legend {
  margin-top: var(--s3); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--s3) var(--s4);
}
.affil-legend h3 { margin: 0; }
.affil-note { margin: 4px 0 var(--s3); color: var(--text-2); font-size: .82rem; }
.affil-dl { margin: 0; display: grid; grid-template-columns: 1fr; font-size: .82rem; }
.affil-dl dt { font-weight: 700; color: var(--text); }
.affil-dl dd { margin: 0 0 var(--s2); color: var(--muted); }
.affil-dl dd:last-child { margin-bottom: 0; }
@media (min-width: 620px) {
  .affil-dl { grid-template-columns: 14rem 1fr; column-gap: var(--s4); row-gap: 5px; }
  .affil-dl dd { margin-bottom: 0; }
}

/* ---------- Source picker ---------- */
/* A compact rail of the busiest outlets plus an expandable, searchable panel
   holding every source grouped by kind and language. The rail is the only thing
   that ever scrolls sideways; the panel wraps, so 375px never gets a
   horizontal page scrollbar. */
.sources { margin-top: var(--s5); }
.sources-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s3); margin-bottom: 6px;
}
.sources-head h2 { margin: 0; }
.src-toggle {
  display: inline-flex; align-items: center; gap: 6px; flex: 0 0 auto;
  appearance: none; background: transparent; color: var(--accent-text);
  border: 0; border-radius: var(--r-sm); cursor: pointer;
  font: inherit; font-size: .8rem; font-weight: 600;
  padding: 6px 4px; min-height: 2.25rem;
}
@media (hover: hover) { .src-toggle:hover { color: var(--text); } }
.src-toggle .n {
  color: var(--muted); font-size: .72rem; font-weight: 600;
  font-variant-numeric: tabular-nums; background: var(--tag-bg);
  padding: 1px 6px; border-radius: 999px;
}
.src-toggle .src-caret { transition: transform .16s ease; }
.src-toggle[aria-expanded="true"] .src-caret { transform: rotate(180deg); }

.src-panel {
  margin-top: var(--s3); padding: var(--s3);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); box-shadow: var(--shadow-sm);
}
.src-find { margin-bottom: var(--s3); }
.src-find input[type="search"] { font-size: .9rem; }
.src-groups { max-height: 48vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
@supports (max-height: 48dvh) { .src-groups { max-height: 48dvh; } }
.src-group + .src-group { margin-top: var(--s4); }
.src-group-head {
  display: flex; align-items: center; gap: 8px; margin: 0 0 var(--s2);
  font-size: .7rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .07em;
}
html[lang="fa"] .src-group-head {
  text-transform: none; letter-spacing: normal; font-size: .78rem;
}
.src-group-head .n {
  color: var(--muted); font-size: .68rem; font-weight: 600;
  font-variant-numeric: tabular-nums; background: var(--tag-bg);
  padding: 1px 6px; border-radius: 999px; text-transform: none; letter-spacing: normal;
}
/* Wrapping, not scrolling: the panel grows downward instead of sideways. */
.src-chips {
  display: flex; flex-wrap: wrap; gap: var(--s2);
  overflow: visible; padding: 2px; margin: -2px;
  scroll-snap-type: none;
}
.src-chips .chip { max-width: 100%; min-height: 2.5rem; }
.src-none { margin: var(--s3) 0 0; color: var(--muted); font-size: .85rem; }

.chips-rail { position: relative; }
.chips-rail::after {
  content: ""; position: absolute; inset-block: 0; inset-inline-end: 0; width: 28px;
  background: linear-gradient(to right, transparent, var(--rail-fade));
  pointer-events: none;
}
[dir="rtl"] .chips-rail::after {
  background: linear-gradient(to left, transparent, var(--rail-fade));
}
.chips {
  display: flex; gap: var(--s2); overflow-x: auto;
  padding-block: 2px 8px; padding-inline: 2px 28px;
  margin-block: -2px 0; margin-inline: -2px;
  scrollbar-width: thin; scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}
.chip {
  flex: 0 0 auto; scroll-snap-align: start;
  display: inline-flex; align-items: center; gap: 7px; max-width: 15rem;
  background: var(--chip-bg); color: var(--text-2);
  border: 1px solid var(--chip-border); border-radius: 999px;
  padding-block: 8px; padding-inline: 14px; min-height: 2.75rem;
  font: inherit; font-size: .84rem; font-weight: 500; cursor: pointer;
  white-space: nowrap; transition: background-color .14s ease, color .14s ease, border-color .14s ease;
}
.chip > span:first-child { overflow: hidden; text-overflow: ellipsis; }
@media (hover: hover) { .chip:hover { border-color: var(--muted); color: var(--text); } }
.chip .n {
  color: var(--muted); font-size: .72rem; font-weight: 600;
  font-variant-numeric: tabular-nums; background: var(--tag-bg);
  padding: 1px 6px; border-radius: 999px;
}
.chip[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent); color: var(--accent-contrast);
}
.chip[aria-pressed="true"] .n { background: rgba(255, 255, 255, .22); color: inherit; }

/* ---------- Result bar ---------- */
.resultbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s3); margin: var(--s4) 0 var(--s3);
  padding-bottom: var(--s3); border-bottom: 1px solid var(--border);
}
.count {
  margin: 0; color: var(--muted); font-size: .82rem; font-weight: 500;
  letter-spacing: .01em; min-height: 1.25em; font-variant-numeric: tabular-nums;
}
.count strong { color: var(--text); font-weight: 700; }
/* <bdi> already isolates; this only guards against a UA stylesheet reset. */
.count .seg { unicode-bidi: isolate; }
.count .sep, .updated .clock::before { margin-inline: .45em; opacity: .55; }
.updated .clock::before { content: "\00b7"; }

/* ---------- Cards ---------- */
.list { display: grid; gap: var(--s3); }
.card {
  display: grid; grid-template-columns: 1fr; gap: var(--s3);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: var(--s4);
  box-shadow: var(--shadow-sm); min-width: 0;
  transition: box-shadow .16s ease, border-color .16s ease, transform .16s ease;
}
@media (hover: hover) { .card:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); } }
.card:focus-within { border-color: var(--focus); }
.card .thumb {
  width: 100%; aspect-ratio: 16 / 10; object-fit: cover;
  border-radius: var(--r-sm); background: var(--skeleton); display: block;
}
.card .body { min-width: 0; display: flex; flex-direction: column; }
.meta {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline;
  color: var(--muted); font-size: .76rem; margin-bottom: 7px;
}
.meta .src {
  color: var(--accent-text); font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em;
}
.meta .dot { opacity: .5; }
.meta time { font-variant-numeric: tabular-nums; }
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  border-radius: 999px; padding: 1px 7px;
  font-size: .68rem; font-weight: 700; letter-spacing: .03em;
  background: var(--tag-bg); color: var(--tag-text);
}
.badge.lang { text-transform: none; letter-spacing: normal; }
.badge.video { background: var(--accent-soft); color: var(--accent-text); }
/* Affiliation is provenance, not a verdict, so every id gets the same quiet
   outline: no colour coding that could read as approval or warning. The label
   text does the distinguishing, so the badge is never colour-only. */
.badge.affil {
  background: transparent; color: var(--text-2);
  border: 1px solid var(--border-strong);
  max-width: 100%; text-transform: none; letter-spacing: normal;
  font-weight: 600; padding: 0 7px;
}
.badge.affil[title] { cursor: help; }
/* "Affiliation unclear": a dashed, quieter outline so a source we could not
   place does not read like one more confident category. */
.badge.affil.unclear { border-style: dashed; color: var(--muted); }
/* Long affiliation labels ("State-linked commercial press") have to wrap inside
   the pill at 320px rather than push the card sideways. */
.badge.affil { white-space: normal; overflow-wrap: break-word; min-width: 0; }
.badge.affil > span { min-width: 0; }
/* The play triangle is a playback symbol, not a direction: never mirror it. */
.badge.video svg { flex: 0 0 auto; }
.card h2 {
  margin: 0 0 7px; font-family: var(--serif); font-weight: 600;
  font-size: 1.14rem; line-height: 1.3; letter-spacing: -.01em;
}
.card h2 a { color: var(--text); text-decoration: none; }
@media (hover: hover) { .card h2 a:hover { color: var(--accent-text); text-decoration: underline; text-underline-offset: 2px; } }
/* A video headline is a button, not a link, but it has to read like a headline. */
.card h2 .title-btn {
  appearance: none; background: none; border: 0; padding: 0; margin: 0;
  font: inherit; color: var(--text); text-align: start; cursor: pointer;
  display: block; width: 100%; min-width: 0;
}
@media (hover: hover) {
  .card h2 .title-btn:hover { color: var(--accent-text); text-decoration: underline; text-underline-offset: 2px; }
}
.summary {
  margin: 0 0 var(--s3); color: var(--text-2); font-size: .9rem; line-height: 1.55;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.tags { display: flex; flex-wrap: wrap; gap: 6px; padding: 0; margin: auto 0 0; list-style: none; }
.tags li {
  background: var(--tag-bg); color: var(--tag-text);
  font-size: .7rem; font-weight: 600; letter-spacing: .02em;
  padding: 3px 8px; border-radius: var(--r-sm);
}

/* ---------- Video ---------- */
/* Video cards go full width so the 16:9 player is not squeezed into a thumb. */
.card.is-video { grid-template-columns: 1fr; }
.media {
  position: relative; grid-column: 1 / -1;
  aspect-ratio: 16 / 9; width: 100%;
  background: #000; border-radius: var(--r-sm); overflow: hidden;
}
@supports not (aspect-ratio: 16 / 9) {
  .media { height: 0; padding-bottom: 56.25%; }
  .card .thumb, .sk.img { height: 0; padding-bottom: 62.5%; }
}
.media .facade {
  position: absolute; inset: 0; width: 100%; height: 100%;
  display: block; padding: 0; border: 0; cursor: pointer;
  background: #000; color: #fff;
}
.media .facade img {
  width: 100%; height: 100%; object-fit: cover; display: block; opacity: .82;
  transition: opacity .16s ease, transform .3s ease;
}
@media (hover: hover) { .media .facade:hover img { opacity: 1; transform: scale(1.02); } }
.media .play {
  position: absolute; inset-inline-start: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 62px; height: 62px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(12, 15, 19, .62); color: #fff;
  border: 2px solid rgba(255, 255, 255, .86);
  backdrop-filter: blur(2px);
  transition: background-color .16s ease, transform .16s ease;
}
[dir="rtl"] .media .play { transform: translate(50%, -50%); }
@media (hover: hover) { .media .facade:hover .play { background: var(--accent); border-color: var(--accent); } }
/* The play triangle is a direction-free symbol: never mirror it. */
.media .play svg { transform: none; margin-inline-start: 3px; }
[dir="rtl"] .media .play svg { margin-inline-start: 0; margin-inline-end: 3px; }
.media .facade:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
.media iframe, .media video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  border: 0; display: block; background: #000;
}

/* ---------- Live ---------- */
/* Live is carried by three cues at once -- colour, a pulsing dot and the word
   itself -- so it survives colour blindness, greyscale and a screen reader. */
.badge.live {
  background: var(--live-soft); color: var(--live-strong);
  border: 1px solid var(--live); padding: 1px 7px 1px 5px;
  text-transform: uppercase; letter-spacing: .06em;
}
html[lang="fa"] .badge.live { text-transform: none; letter-spacing: normal; }
.live-dot {
  flex: 0 0 auto; width: .5rem; height: .5rem; border-radius: 50%;
  background: var(--live); display: inline-block;
  animation: live-pulse 1.8s ease-in-out infinite;
}
@keyframes live-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none; } }

/* Live card emphasis: a red edge, not a red background. */
.card.is-live { border-color: var(--live); box-shadow: var(--shadow-sm); }
.card.is-live::before {
  content: ""; position: absolute; inset-block: -1px; inset-inline-start: -1px;
  width: 3px; background: var(--live);
  border-start-start-radius: var(--r-md); border-end-start-radius: var(--r-md);
}
.card { position: relative; }
.badge.live.on-thumb {
  position: absolute; inset-block-start: 8px; inset-inline-start: 8px; z-index: 2;
  background: var(--live); color: var(--live-contrast); border-color: var(--live);
  font-size: .66rem;
}
.badge.live.on-thumb .live-dot { background: currentColor; }

/* Live filter chip, sitting beside the videos-only switch. */
.live-toggle {
  display: inline-flex; align-items: center; gap: 7px; align-self: start;
  min-height: 2.75rem; padding-block: 6px; padding-inline: 14px;
  background: var(--chip-bg); color: var(--text-2);
  border: 1px solid var(--live); border-radius: 999px;
  font: inherit; font-size: .84rem; font-weight: 600; cursor: pointer;
  white-space: nowrap;
}
.live-toggle[aria-pressed="true"] {
  background: var(--live); border-color: var(--live); color: var(--live-contrast);
}
.live-toggle[aria-pressed="true"] .live-dot { background: currentColor; }
.live-toggle[aria-pressed="true"] .switch-count { background: rgba(255, 255, 255, .24); color: inherit; }
.live-toggle:disabled { opacity: .5; cursor: default; border-color: var(--border-strong); }
.live-toggle:disabled .live-dot { animation: none; background: var(--muted); }
@media (hover: hover) { .live-toggle:not(:disabled):hover { border-color: var(--live-strong); color: var(--text); } }

/* Live strip: the streams running right now, above the listing. */
.live-strip { margin-bottom: var(--s4); }
.live-strip-title {
  display: flex; align-items: center; gap: 7px; margin: 0 0 var(--s2);
  font-family: var(--serif); font-size: .95rem; font-weight: 600; color: var(--text);
}
html[lang="fa"] .live-strip-title { font-family: var(--fa); }
.live-rail {
  display: flex; gap: var(--s3); overflow-x: auto;
  padding-bottom: var(--s2); scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}
.live-mini {
  flex: 0 0 auto; scroll-snap-align: start; width: 14rem;
  display: flex; flex-direction: column; gap: 6px; text-align: start;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--live); border-radius: var(--r-md);
  padding: 8px; font: inherit; cursor: pointer;
}
.live-mini-shot {
  position: relative; display: block; width: 100%;
  aspect-ratio: 16 / 9; background: #000;
  border-radius: var(--r-sm); overflow: hidden;
}
@supports not (aspect-ratio: 16 / 9) { .live-mini-shot { height: 0; padding-bottom: 56.25%; } }
.live-mini-shot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.live-mini-text { display: block; min-width: 0; }
.live-mini-title {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; font-size: .85rem; font-weight: 600; line-height: 1.35;
}
.live-mini-src {
  display: block; margin-top: 3px; color: var(--accent-text);
  font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
}
html[lang="fa"] .live-mini-src { text-transform: none; letter-spacing: normal; }
@media (hover: hover) { .live-mini:hover { box-shadow: var(--shadow-md); } }
/* "on air since ..." next to a LIVE pill: the start date, never a stale age. */
.meta .live-since { color: var(--live-strong); font-weight: 600; }
.live-mini-since { display: block; margin-top: 2px; color: var(--muted); font-size: .72rem; }

/* ---------- In-page video dialog ---------- */
/* Videos never open a tab: this dialog is the only player. A plain <div> with
   role="dialog" (not <dialog>) keeps older Safari and Android WebView working. */
.vmodal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: var(--s4);
  padding: max(var(--s4), env(safe-area-inset-top)) max(var(--s4), env(safe-area-inset-right))
           max(var(--s4), env(safe-area-inset-bottom)) max(var(--s4), env(safe-area-inset-left));
}
.vmodal-backdrop { position: absolute; inset: 0; background: rgba(6, 8, 11, .78); }
.vmodal-panel {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; gap: var(--s3);
  width: 100%; max-width: 62rem;
  max-height: 100vh;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: var(--s4); box-shadow: var(--shadow-md);
}
@supports (max-height: 100dvh) { .vmodal-panel { max-height: 100dvh; } }

.vmodal-head { display: flex; align-items: flex-start; gap: var(--s3); }
.vmodal-titles { min-width: 0; flex: 1 1 auto; }
.vmodal-title {
  margin: 0; font-family: var(--serif); font-weight: 600;
  font-size: 1.05rem; line-height: 1.35; letter-spacing: -.01em;
}
.vmodal-title[lang="fa"] { font-family: var(--fa); line-height: 1.6; letter-spacing: normal; }
.vmodal-live { margin-bottom: 5px; }
.vmodal-src { margin: 4px 0 0; color: var(--muted); font-size: .78rem; }
.vmodal-srcname { color: var(--accent-text); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
html[lang="fa"] .vmodal-srcname { text-transform: none; letter-spacing: normal; }
.vmodal-dot { margin-inline: .4em; opacity: .55; }
.vmodal-close {
  flex: 0 0 auto; display: grid; place-items: center;
  width: 2.75rem; height: 2.75rem; padding: 0; cursor: pointer;
  background: var(--surface-2); color: var(--text-2);
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
}
@media (hover: hover) { .vmodal-close:hover { background: var(--bg-tint); color: var(--text); } }

/* 16:9 by default; the width cap is what limits the height, so the stage
   always fits the viewport without letterboxing. */
.vmodal-stage {
  position: relative; width: min(100%, 124vh); margin-inline: auto;
  aspect-ratio: 16 / 9; background: #000;
  border-radius: var(--r-sm); overflow: hidden;
}
/* YouTube Shorts are portrait: give them a tall 9:16 stage instead. */
.vmodal-stage.is-tall { width: min(100%, 42vh); aspect-ratio: 9 / 16; }
@supports (height: 100dvh) {
  .vmodal-stage { width: min(100%, 124dvh); }
  .vmodal-stage.is-tall { width: min(100%, 42dvh); }
}
/* Older engines without aspect-ratio still get a correctly proportioned box. */
@supports not (aspect-ratio: 16 / 9) {
  .vmodal-stage { height: 0; padding-bottom: 56.25%; }
  .vmodal-stage.is-tall { padding-bottom: 177.78%; }
}
.vmodal-stage iframe, .vmodal-stage video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  border: 0; display: block; background: #000;
}
.vmodal-msg {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: var(--s3);
  padding: var(--s4); text-align: center;
  background: var(--surface-2); color: var(--text-2); font-size: .9rem;
}
.vmodal-msg p { margin: 0; max-width: 34ch; }
.vmodal-out {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 2.75rem; padding: 8px 16px; border-radius: var(--r-sm);
  background: var(--accent); color: var(--accent-contrast);
  font-weight: 600; text-decoration: none;
}
@media (hover: hover) { .vmodal-out:hover { background: var(--accent-hover); } }

/* The permanent escape hatch under the stage: quiet, but always there, so a
   reader is never stuck with a player that refuses to start. */
.vmodal-escape {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 4px 8px; margin: 0; color: var(--muted); font-size: .78rem; text-align: center;
}
.vmodal-escape-link {
  color: var(--accent-text); font-weight: 600; text-decoration: underline;
  text-underline-offset: 2px; border-radius: var(--r-sm);
  padding: 4px 2px; min-height: 1.5rem;
}
@media (hover: hover) { .vmodal-escape-link:hover { color: var(--text); } }

.vmodal-nav { display: flex; align-items: center; justify-content: center; gap: var(--s4); }
.vmodal-nav-btn {
  display: grid; place-items: center; cursor: pointer;
  width: 2.75rem; height: 2.75rem; padding: 0;
  background: var(--surface-2); color: var(--text-2);
  border: 1px solid var(--border-strong); border-radius: 999px;
}
.vmodal-nav-btn { position: relative; }
.vmodal-nav-btn:disabled { opacity: .4; cursor: default; }
/* A neighbouring live stream gets a dot; the word rides in the aria-label. */
.vmodal-nav-btn .nav-dot { display: none; position: absolute; top: 4px; inset-inline-end: 4px; }
.vmodal-nav-btn.is-live { border-color: var(--live); }
.vmodal-nav-btn.is-live .nav-dot { display: block; }
@media (hover: hover) { .vmodal-nav-btn:not(:disabled):hover { background: var(--bg-tint); color: var(--text); } }
/* Chevrons point the way the text runs. */
[dir="rtl"] .vmodal-nav-btn svg { transform: scaleX(-1); }
.vmodal-counter {
  color: var(--muted); font-size: .8rem; font-weight: 600;
  font-variant-numeric: tabular-nums; min-width: 4rem; text-align: center;
  unicode-bidi: isolate;
}

/* Short viewports (landscape phones): trim the chrome so the stage survives. */
@media (max-height: 30rem) {
  .vmodal { padding: var(--s2); }
  .vmodal-panel { gap: var(--s2); padding: var(--s2) var(--s3); }
  .vmodal-title { font-size: .95rem; }
  .vmodal-src { display: none; }
  .vmodal-stage { width: min(100%, 100vh); }
  .vmodal-stage.is-tall { width: min(100%, 34vh); }
  @supports (height: 100dvh) {
    .vmodal-stage { width: min(100%, 100dvh); }
    .vmodal-stage.is-tall { width: min(100%, 34dvh); }
  }
}

/* ---------- Skeletons ---------- */
.skeleton { pointer-events: none; }
.sk {
  background: linear-gradient(90deg, var(--skeleton) 25%, var(--skeleton-hi) 50%, var(--skeleton) 75%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 6px;
}
.sk.img { width: 100%; aspect-ratio: 16 / 10; border-radius: var(--r-sm); }
.sk.l1 { height: 10px; width: 32%; margin-bottom: 12px; }
.sk.l2 { height: 17px; width: 92%; margin-bottom: 9px; }
.sk.l3 { height: 13px; width: 100%; margin-bottom: 7px; }
.sk.l4 { height: 13px; width: 64%; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Empty / error ---------- */
.state {
  text-align: center; padding: var(--s7) var(--s4); color: var(--muted);
  background: var(--surface); border: 1px dashed var(--border-strong);
  border-radius: var(--r-lg);
}
.state h2 {
  color: var(--text); margin: 0 0 6px;
  font-family: var(--serif); font-weight: 600; font-size: 1.15rem;
}
.state p { margin: 0 auto var(--s4); max-width: 42ch; font-size: .9rem; }
.state .btn { margin-inline: auto; }
.state .state-note { margin: 0 auto; }
.live-strip + .list:empty + .state { padding: var(--s5) var(--s4); }

.foot {
  color: var(--muted); font-size: .78rem;
  padding-top: var(--s5);
  padding-bottom: var(--s6);
  padding-bottom: calc(var(--s6) + env(safe-area-inset-bottom));
}
.foot p { margin: 0; border-top: 1px solid var(--border); padding-top: var(--s4); }

/* ---------- Responsive ---------- */
/* 320px is the narrowest target: keep the header on one line and let the
   chip rail, not the page, be the thing that scrolls sideways. */
@media (max-width: 22.5rem) {
  :root { --s4: 12px; --s5: 16px; }
  .header-row { padding-block: var(--s2); }
  .brand-logo { height: 26px; }
  .uilang-btn { padding-inline: 6px; font-size: .72rem; }
  .chip { max-width: 11rem; }
}
@media (max-width: 560px) {
  .header-row { gap: var(--s2); }
  .uilang-btn { padding-inline: 8px; font-size: .75rem; }
  .btn .btn-label { display: none; }
  .btn { padding-inline: 11px; }
}
/* Landscape phones: a sticky header would eat most of the screen. */
@media (max-height: 30rem) and (orientation: landscape) {
  .site-header { position: static; }
  main { padding-top: var(--s4); }
  .header-row { padding-block: var(--s2); }
}
@media (min-width: 620px) {
  .wrap { padding-inline: var(--s5); }
  .controls { grid-template-columns: 1fr 12.5rem auto; padding: var(--s4) var(--s5); }
  .card.has-img { grid-template-columns: 11rem 1fr; gap: var(--s4); }
  .card.has-img .thumb { height: 100%; min-height: 7.5rem; aspect-ratio: auto; }
  .card.skeleton { grid-template-columns: 11rem 1fr; gap: var(--s4); }
  .card.is-video { grid-template-columns: 1fr; }
  .card h2 { font-size: 1.22rem; }
}
@media (min-width: 900px) {
  .card.has-img { grid-template-columns: 13rem 1fr; }
  .card.is-video { grid-template-columns: 1fr; }
}
/* Large and ultrawide displays (1440/1920/2560) and TVs: the column grows a
   little and then stops, so a headline is never a full screen wide. */
@media (min-width: 90rem) {
  :root { --maxw: 1080px; }
  body { font-size: 17px; }
}
@media (min-width: 120rem) {
  :root { --maxw: 1180px; }
  body { font-size: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
  .media .facade img { transition: none; }
}
/* Higher-contrast mode: firmer edges and a heavier focus ring. */
@media (prefers-contrast: more) {
  :root { --border: #9aa3ae; --border-strong: #5d6774; --muted: #454e5a; }
  :root[data-theme="dark"] { --border: #6b7684; --border-strong: #93a0af; --muted: #b9c3cf; }
  .card, .controls, .chip { border-width: 2px; }
  :focus-visible { outline-width: 3px; }
}
/* Windows high-contrast / forced colors: never lose the focus ring. */
@media (forced-colors: active) {
  :focus-visible { outline: 3px solid Highlight; }
  .vmodal-panel { border: 2px solid CanvasText; }
}
