:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #16181d;
  --muted: #5d6573;
  --border: #e1e4ea;
  --accent: #4338ca;
  --accent-text: #ffffff;
  --link: #1f5fd1;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --radius: 14px;
  --font: "Vazirmatn", "Estedad", system-ui, -apple-system, "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --text: #e8eaee;
    --muted: #9aa3b2;
    --border: #2a2f3a;
    --accent: #4f46e5;
    --link: #8fb4ff;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.7;
}

a { color: var(--link); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* header / footer */
.site-header, main, .site-footer {
  width: min(1180px, 100% - 32px);
  margin-inline: auto;
}

.site-header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding-block: 20px; flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand strong { display: block; font-size: 1.25rem; letter-spacing: -0.01em; }
.brand small { display: block; color: var(--muted); font-size: 0.85rem; }
.updated { margin: 0; color: var(--muted); font-size: 0.85rem; }

.site-footer {
  margin-block: 40px 28px; padding-top: 20px;
  border-top: 1px solid var(--border);
  color: var(--muted); font-size: 0.85rem;
}
.site-footer nav { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-block: 8px; }
.copyright { margin: 0; }

/* consent */
.consent { max-width: 640px; margin: 48px auto; padding: 28px; }
.consent h1 { margin-top: 0; font-size: 1.3rem; }

button {
  font: inherit; cursor: pointer; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: 8px 18px;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--link); outline-offset: 2px;
}

/* stats */
.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 12px; }
.stat { padding: 14px 18px; display: flex; flex-direction: column; gap: 2px; }
.stat-label { color: var(--muted); font-size: 0.8rem; }
.stat-value { font-size: 1.35rem; font-weight: 700; }

/* toolbar */
.toolbar { display: flex; gap: 12px; align-items: center; padding: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.search { flex: 1 1 260px; }
.search input, .sort select {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; width: 100%;
}
.sort { display: flex; align-items: center; gap: 8px; color: var(--muted); white-space: nowrap; }
.sort select { width: auto; }

/* table */
.table-wrap { overflow-x: auto; }
.channels { width: 100%; border-collapse: collapse; }
.channels th, .channels td { padding: 10px 14px; text-align: start; border-bottom: 1px solid var(--border); }
.channels thead th { color: var(--muted); font-size: 0.8rem; font-weight: 600; background: var(--surface-2); }
.channels tbody tr:last-child td { border-bottom: 0; }
.channels .num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
.channels .rank { width: 3.5em; color: var(--muted); }
.channels .dim { color: var(--muted); }
.channels .approx { color: var(--muted); font-style: italic; }
.page-title { font-size: 1.15rem; margin: 4px 0 12px; }
.page-title:focus { outline: none; }

.channel { display: flex; align-items: center; gap: 12px; min-width: 0; }
.channel img, .channel .avatar-placeholder {
  width: 40px; height: 40px; border-radius: 50%; flex: none; background: var(--surface-2); object-fit: cover;
}
.channel a { color: inherit; text-decoration: none; font-weight: 600; }
.channel a:hover { text-decoration: underline; }
.channel .handle { display: block; color: var(--muted); font-size: 0.8rem; direction: ltr; text-align: end; unicode-bidi: plaintext; }
.channel .names { min-width: 0; overflow: hidden; }
.channel .title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 34ch; }

.empty { padding: 32px; text-align: center; color: var(--muted); margin: 0; }
.more-wrap { display: flex; justify-content: center; }
.more-wrap button { margin: 14px; }
.note { color: var(--muted); font-size: 0.82rem; margin-top: 12px; }
.notice { padding: 16px; }

/* legal pages */
.prose { max-width: 760px; margin: 24px auto; padding: 24px 28px; }
.prose h1 { margin-top: 0; font-size: 1.4rem; }
.prose h2 { font-size: 1.05rem; margin-top: 1.6em; }

/* narrow screens: rows become cards */
@media (max-width: 760px) {
  .stats-row { grid-template-columns: 1fr; }
  .channels thead { display: none; }
  .channels, .channels tbody, .channels tr, .channels td { display: block; width: 100%; }
  .channels tr { padding: 10px 6px; border-bottom: 1px solid var(--border); display: grid; grid-template-columns: repeat(3, 1fr); }
  .channels td { border: 0; padding: 4px 8px; }
  .channels td.rank { display: none; }
  .channels td.cell-channel { grid-column: 1 / -1; }
  .channels td.num { text-align: start; }
  .channels td.num::before { content: attr(data-label); display: block; color: var(--muted); font-size: 0.75rem; }
  .channel .title { max-width: 100%; }
}
