/* ===========================================================================
   Channel directory
   ---------------------------------------------------------------------------
   Everything the directory's pages draw, on the design-system tokens. It lives
   here rather than in an include because a partial cannot set a flag that
   survives back to its parent: styles inside the card partial would ship once
   per card. Prefixes: .ch-* card, .cat-* topic tile, .dl-* listing, .chd-* one
   channel's page, .ud-* "My channels", .dir-* directory home.
   ======================================================================== */

/* ---- channel card -------------------------------------------------------- */
.ch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 17rem), 1fr));
  gap: 1rem;
}
/* Three across, for a short list that would leave a hole in a row of four. */
.ch-grid.is-3 { grid-template-columns: repeat(auto-fill, minmax(min(100%, 22rem), 1fr)); }
.ch-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: .7rem;
  min-width: 0;
  padding: 1.1rem;
  border: 1px solid var(--ds-line);
  border-radius: var(--ds-r-lg);
  background: var(--ds-surface);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.ch-card:hover { border-color: var(--ds-accent-300); box-shadow: var(--ds-shadow); }

.ch-main { display: flex; align-items: center; gap: .75rem; min-width: 0; }
/* The avatar is a fixed box with an initial painted behind the image: if the
   image 404s its onerror removes it and the initial shows through. */
.ch-avatar {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  overflow: hidden;
  background: var(--ds-accent-wash);
}
.ch-initial {
  font-family: var(--ds-font-display);
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--ds-accent-700);
}
.ch-avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

.ch-text { min-width: 0; }
.ch-name {
  margin: 0;
  font-family: var(--ds-font-display);
  font-size: .975rem;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -.01em;
  display: flex;
  align-items: center;
  gap: .3rem;
  min-width: 0;
}
.ch-name a {
  color: var(--ds-ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ch-name a:hover { text-decoration: none; }
.ch-name a::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.ch-name a:focus-visible { outline: none; }
.ch-name a:focus-visible::after { outline: 3px solid var(--ds-accent-300); outline-offset: -2px; border-radius: var(--ds-r-lg); }
.ch-verified { flex: 0 0 auto; color: var(--ds-accent); font-size: .9em; }
.ch-meta { margin: .1rem 0 0; font-size: .82rem; color: var(--ds-muted); }
.ch-meta b { color: var(--ds-body); font-weight: 700; font-variant-numeric: tabular-nums; }

.ch-desc {
  margin: 0;
  font-size: .86rem;
  line-height: 1.5;
  color: var(--ds-body);
  /* Two lines, then ellipsis, so cards in a row stay the same height. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.ch-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  margin-top: auto;
  padding-top: .6rem;
  border-top: 1px solid var(--ds-line-2);
}
.ch-tag { font-size: .78rem; color: var(--ds-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-open {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  font-family: var(--ds-font-display);
  font-size: .85rem;
  font-weight: 700;
  color: var(--ds-accent-700);
}
.ch-open:hover { color: #095E8F; }

/* ---- topic tile ------------------------------------------------------------ */
.cat-grid {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 15.5rem), 1fr));
  gap: .75rem;
}
.cat-tile {
  --c: var(--ds-accent-700);
  --w: var(--ds-accent-wash);
  display: flex;
  align-items: center;
  gap: .8rem;
  height: 100%;
  padding: .85rem 1rem;
  border: 1px solid var(--ds-line);
  border-radius: var(--ds-r);
  background: var(--ds-surface);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.cat-tile:hover { border-color: var(--ds-accent-300); box-shadow: var(--ds-shadow-sm); text-decoration: none; }
.cat-ico {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: .7rem;
  background: var(--w);
  color: var(--c);
  font-size: 1.15rem;
}
.cat-text { display: grid; line-height: 1.3; min-width: 0; }
.cat-name { font-family: var(--ds-font-display); font-weight: 700; font-size: .95rem; color: var(--ds-ink); }
.cat-count { font-size: .78rem; color: var(--ds-muted); }
.cat-all .cat-ico { background: var(--ds-surface-2); color: var(--ds-body); }
.cat-empty { grid-column: 1 / -1; color: var(--ds-muted); }
/* Each topic keeps its own tint, so the row can be scanned by colour. */
.cat-tile[data-cat="crypto"]        { --c: #B9640E; --w: #FEF2E3; }
.cat-tile[data-cat="education"]     { --c: #5B4FD1; --w: #F1EFFD; }
.cat-tile[data-cat="finance"]       { --c: #0F7A53; --w: #E6F6EE; }
.cat-tile[data-cat="entertainment"] { --c: #B23350; --w: #FDEDF1; }
.cat-tile[data-cat="news"]          { --c: #0B6FAB; --w: #E8F4FD; }
.cat-tile[data-cat="business"]      { --c: #33475F; --w: #EDF1F6; }
.cat-tile[data-cat="science"]       { --c: #0A7E79; --w: #E2FAF7; }
.cat-tile[data-cat="art"]           { --c: #A23FB5; --w: #F9EEFB; }
.cat-tile[data-cat="lifestyle"]     { --c: #C2451E; --w: #FDEEE8; }
.cat-tile[data-cat="social"]        { --c: #1D62C9; --w: #EAF1FC; }
.cat-tile[data-cat="technology"]    { --c: #2F5FA8; --w: #EBF1FA; }

/* ---- directory home -------------------------------------------------------- */
.dir-hero { padding-block: clamp(2.5rem, 2rem + 2.5vw, 4rem); background: var(--ds-surface); border-bottom: 1px solid var(--ds-line-2); }
.dir-hero-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, .85fr); align-items: center; gap: 3rem; }
.dir-hero h1 {
  margin: 0 0 .75rem;
  font-family: var(--ds-font-display);
  font-weight: 800;
  letter-spacing: -.03em;
  line-height: 1.1;
  font-size: clamp(2rem, 1.4rem + 2.4vw, 3.1rem);
  color: var(--ds-ink);
  text-wrap: balance;
}
.dir-hero .lede { margin-bottom: 1.5rem; color: var(--ds-body); }
.dir-hero-art img { display: block; width: 100%; height: auto; aspect-ratio: 3 / 2; object-fit: cover; border-radius: var(--ds-r-lg); }
.dir-hero-links { display: flex; flex-wrap: wrap; gap: .4rem 1.25rem; margin: .9rem 0 0; padding: 0; list-style: none; font-size: .92rem; }
.dir-hero-links a { font-weight: 600; }

.dir-cta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem 2rem;
  margin-top: 2.5rem;
  padding: clamp(1.25rem, 1rem + 1vw, 1.75rem);
  border: 1px solid var(--ds-line);
  border-radius: var(--ds-r-lg);
  background: var(--ds-surface-2);
}
.dir-cta h2 { margin: 0 0 .2rem; font-size: 1.15rem; }
.dir-cta p { margin: 0; color: var(--ds-muted); }
.dir-cta-actions { display: flex; flex-wrap: wrap; gap: .6rem; }

/* ---- search box, shared by the home and the listing ------------------------- */
.dl-search {
  display: flex;
  align-items: center;
  gap: .5rem;
  max-width: 38rem;
  padding: .35rem .35rem .35rem 1rem;
  border: 1px solid var(--ds-line);
  border-radius: .9rem;
  background: var(--ds-surface);
  box-shadow: var(--ds-shadow-sm);
}
.dl-search:focus-within { border-color: var(--ds-accent-300); box-shadow: 0 0 0 4px rgba(34, 158, 217, .14); }
.dl-search > i { color: var(--ds-muted); }
.dl-search input { flex: 1 1 auto; min-width: 0; border: 0; outline: 0; background: transparent; padding: .55rem 0; font-size: 1rem; color: var(--ds-ink); }
.dl-search .btn { flex: 0 0 auto; }

/* ---- listing ---------------------------------------------------------------- */
.dl-head { padding-block: 2rem 1.75rem; background: var(--ds-surface-2); border-bottom: 1px solid var(--ds-line-2); }
.dl-crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: .4rem; margin-bottom: .9rem; font-size: .84rem; color: var(--ds-muted); }
.dl-crumbs a { color: var(--ds-muted); }
.dl-crumbs a:hover { color: var(--ds-accent-700); }
.dl-crumbs i { font-size: .7rem; color: var(--ds-faint); }
.dl-title {
  margin: 0;
  font-family: var(--ds-font-display);
  font-weight: 800;
  letter-spacing: -.025em;
  line-height: 1.15;
  font-size: clamp(1.6rem, 1.25rem + 1.5vw, 2.3rem);
  color: var(--ds-ink);
  text-wrap: balance;
}
.dl-sub { margin: .4rem 0 1.1rem; color: var(--ds-muted); }
.dl-head > .container > .dl-sub:last-child { margin-bottom: 0; }
.dl-body { padding-block: 1.5rem 4rem; }

/* A rail rather than wrapped rows: on a phone it scrolls inside itself. */
.dl-topics {
  display: flex;
  gap: .4rem;
  margin-bottom: 1rem;
  padding-bottom: .25rem;
  overflow-x: auto;
  scrollbar-width: none;
}
.dl-topics::-webkit-scrollbar { display: none; }
.dl-topic {
  flex: 0 0 auto;
  padding: .42rem .85rem;
  border: 1px solid var(--ds-line);
  border-radius: var(--ds-r-pill);
  background: var(--ds-surface);
  font-size: .87rem;
  font-weight: 600;
  color: var(--ds-body);
}
.dl-topic:hover { border-color: var(--ds-accent-300); color: var(--ds-accent-700); text-decoration: none; }
.dl-topic.is-on { background: var(--ds-ink); border-color: var(--ds-ink); color: #fff; }

.dl-filters { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1rem; margin-bottom: 1.25rem; }
.dl-seg { display: inline-flex; padding: .2rem; margin: 0; border: 0; border-radius: .7rem; background: var(--ds-surface-2); }
.dl-seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.dl-seg label { padding: .35rem .8rem; border-radius: .55rem; font-size: .87rem; font-weight: 600; color: var(--ds-muted); cursor: pointer; }
.dl-seg input:checked + label { background: var(--ds-surface); color: var(--ds-ink); box-shadow: var(--ds-shadow-sm); }
.dl-seg input:focus-visible + label { outline: 3px solid var(--ds-accent-300); }
.dl-sort { display: inline-flex; align-items: center; gap: .5rem; font-size: .87rem; color: var(--ds-muted); }
.dl-sort label { margin: 0; }
.dl-sort .form-select { width: auto; border-radius: .6rem; font-size: .87rem; }
.dl-add { margin-inline-start: auto; font-size: .9rem; font-weight: 600; display: inline-flex; align-items: center; gap: .3rem; }
.dl-pager { margin-top: 2rem; }
.dl-pager .pagination { flex-wrap: wrap; gap: .3rem; }
.dl-pager .page-link { min-width: 2.4rem; text-align: center; border: 1px solid var(--ds-line); border-radius: .6rem !important; color: var(--ds-ink); font-weight: 600; }

/* ---- one channel ------------------------------------------------------------ */
.cd { padding-block: 1.5rem 4rem; }
.chd-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 1.25rem 1.5rem;
  padding: clamp(1.25rem, 1rem + 1vw, 1.75rem);
  border: 1px solid var(--ds-line);
  border-radius: var(--ds-r-lg);
  background: var(--ds-surface);
}
.chd-avatar { width: 6rem; height: 6rem; }
.chd-avatar .ch-initial { font-size: 2.2rem; }
.chd-name {
  margin: 0;
  font-family: var(--ds-font-display);
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1.15;
  font-size: clamp(1.4rem, 1.15rem + 1.1vw, 2rem);
  color: var(--ds-ink);
  overflow-wrap: anywhere;
}
.chd-handle { margin: .2rem 0 0; color: var(--ds-muted); font-size: .95rem; overflow-wrap: anywhere; }
.chd-facts { list-style: none; display: flex; flex-wrap: wrap; align-items: center; gap: .3rem 1.1rem; margin: .7rem 0 0; padding: 0; font-size: .92rem; color: var(--ds-body); }
.chd-facts b { color: var(--ds-ink); font-variant-numeric: tabular-nums; }
.chd-online { display: inline-block; width: .5rem; height: .5rem; margin-inline-end: .35rem; border-radius: 50%; background: var(--ds-success); vertical-align: .08em; }
.chd-actions { display: flex; flex-direction: column; gap: .5rem; }
#chd-save.is-on { color: var(--ds-danger); }

.chd-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 20rem); gap: 1.25rem; align-items: start; margin-top: 1.25rem; }
.chd-main { display: grid; gap: 1.25rem; min-width: 0; }
.chd-card { padding: 1.4rem 1.5rem; border: 1px solid var(--ds-line); border-radius: var(--ds-r-lg); background: var(--ds-surface); }
.chd-card h2 { margin: 0 0 .75rem; font-size: 1.1rem; }
.chd-count { display: inline-block; padding: 0 .45rem; border-radius: var(--ds-r-pill); background: var(--ds-surface-2); font-size: .8rem; font-weight: 600; color: var(--ds-muted); vertical-align: .1em; }
.chd-about { color: var(--ds-body); overflow-wrap: anywhere; unicode-bidi: plaintext; }
.chd-about p:last-child { margin-bottom: 0; }
.chd-muted { margin: 0; color: var(--ds-muted); }
.chd-tags { list-style: none; display: flex; flex-wrap: wrap; gap: .35rem; margin: 1rem 0 0; padding: 0; }
.chd-tags a { display: inline-block; padding: .22rem .65rem; border-radius: var(--ds-r-pill); background: var(--ds-surface-2); font-size: .82rem; font-weight: 600; color: var(--ds-body); }
.chd-tags a:hover { background: var(--ds-accent-wash); color: var(--ds-accent-700); text-decoration: none; }

.chd-review { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .75rem; padding-block: .9rem; border-top: 1px solid var(--ds-line-2); }
.chd-review:first-of-type { border-top: 0; padding-top: 0; }
.chd-review-ava { display: inline-flex; align-items: center; justify-content: center; width: 2.25rem; height: 2.25rem; border-radius: 50%; background: var(--ds-accent-wash); color: var(--ds-accent-700); font-weight: 700; }
.chd-review-head { display: flex; flex-wrap: wrap; align-items: center; gap: .15rem .6rem; margin: 0 0 .2rem; font-size: .88rem; color: var(--ds-muted); }
.chd-review-head b { color: var(--ds-ink); }
.chd-stars-read { color: #E0A106; font-size: .8rem; }
.chd-review-text p:last-child { margin-bottom: 0; }
.chd-write { margin-top: 1rem; }
.chd-write summary { cursor: pointer; font-weight: 600; color: var(--ds-accent-700); }
.chd-write form { display: grid; gap: .6rem; margin-top: .75rem; justify-items: start; }
.chd-write textarea { width: 100%; }
.chd-write .form-label { margin: 0; }
.chd-stars { display: inline-flex; gap: .1rem; }
.chd-star { padding: .1rem; border: 0; background: none; color: #d5dde6; font-size: 1.35rem; line-height: 1; cursor: pointer; }
.chd-star.is-on { color: #E0A106; }
.chd-signin { margin: .9rem 0 0; color: var(--ds-muted); }

.chd-side { display: grid; gap: 1rem; }
.chd-grow { padding: 1.4rem; border: 1px solid #d4ebf9; border-radius: var(--ds-r-lg); background: var(--ds-accent-wash-2); }
.chd-grow-ico { display: inline-flex; align-items: center; justify-content: center; width: 2.5rem; height: 2.5rem; margin-bottom: .75rem; border-radius: .7rem; background: var(--ds-surface); color: var(--ds-accent-700); font-size: 1.15rem; }
.chd-grow h2 { margin: 0 0 .35rem; font-size: 1.05rem; }
.chd-grow p { margin: 0 0 1rem; font-size: .92rem; color: var(--ds-body); }
.chd-grow-link { display: block; margin-top: .7rem; text-align: center; font-size: .87rem; font-weight: 600; }
.chd-report { margin: 0; padding-inline: .25rem; font-size: .84rem; color: var(--ds-muted); }
.chd-report button { padding: 0; border: 0; background: none; color: var(--ds-accent-700); font-weight: 600; cursor: pointer; }
.chd-report button:hover { text-decoration: underline; }

.chd-related { margin-top: 2.5rem; padding: 0; }
.chd-related-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.chd-related-head h2 { margin: 0; font-size: 1.25rem; }
.chd-related-all { font-weight: 600; font-size: .92rem; white-space: nowrap; }

/* ---- my channels ------------------------------------------------------------ */
.ud { padding-block: .5rem 4rem; }
.ud-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.75rem; }
.ud-head h1 { margin: 0; font-size: clamp(1.6rem, 1.25rem + 1.5vw, 2.25rem); letter-spacing: -.025em; }
.ud-head p { margin: .3rem 0 0; color: var(--ds-muted); }
.ud-block { padding: 0; }
.ud-block + .ud-block { margin-top: 2.5rem; }
.ud-block .tj-empty { padding-block: 1rem; }
.ud-block h2 { display: flex; align-items: center; gap: .5rem; margin: 0 0 1rem; font-size: 1.15rem; }
.ud-count { padding: 0 .5rem; border-radius: var(--ds-r-pill); background: var(--ds-surface-2); font-size: .8rem; font-weight: 600; color: var(--ds-muted); }
.ud-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--ds-line); border-radius: var(--ds-r-lg); background: var(--ds-surface); }
.ud-row { display: flex; align-items: center; gap: .9rem; padding: .9rem 1.1rem; border-top: 1px solid var(--ds-line-2); }
.ud-row:first-child { border-top: 0; }
.ud-row-main { flex: 1 1 auto; min-width: 0; }
.ud-row-name { margin: 0; font-weight: 700; color: var(--ds-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ud-row-name a { color: inherit; }
.ud-row-meta { margin: .1rem 0 0; font-size: .84rem; color: var(--ds-muted); }
.ud-row-why { margin: .25rem 0 0; font-size: .84rem; color: var(--ds-danger); }
.ud-status { flex: 0 0 auto; padding: .18rem .6rem; border-radius: var(--ds-r-pill); background: var(--ds-surface-2); font-size: .76rem; font-weight: 700; color: var(--ds-muted); }
.ud-status.is-approved, .ud-status.is-featured { background: var(--ds-success-wash); color: #0F7A53; }
.ud-status.is-pending { background: var(--ds-warn-wash); color: #9A5B00; }
.ud-status.is-rejected, .ud-status.is-suspended { background: var(--ds-danger-wash); color: #B42318; }
.ud-pager { display: flex; justify-content: center; gap: 1rem; margin: 1rem 0 0; font-size: .9rem; color: var(--ds-muted); }
.ud-none { margin: 0; padding: 1.1rem 1.25rem; border: 1px dashed var(--ds-line); border-radius: var(--ds-r); color: var(--ds-muted); }

/* ---- narrow ------------------------------------------------------------------ */
@media (max-width: 991.98px) {
  .dir-hero-grid { grid-template-columns: 1fr; gap: 2rem; }
  .dir-hero-art { display: none; }
  .chd-grid { grid-template-columns: 1fr; }
}
@media (max-width: 767.98px) {
  .chd-head { grid-template-columns: auto minmax(0, 1fr); align-items: start; }
  .chd-avatar { width: 4rem; height: 4rem; }
  .chd-avatar .ch-initial { font-size: 1.5rem; }
  .chd-actions { grid-column: 1 / -1; flex-direction: row; }
  .chd-actions .btn-primary { flex: 1 1 auto; }
  .dl-add { margin-inline-start: 0; width: 100%; }
  .dl-sort { margin-inline-start: auto; }
}
@media (max-width: 575.98px) {
  .dl-search { flex-wrap: wrap; padding: .5rem; }
  .dl-search > i { display: none; }
  .dl-search input { flex-basis: 100%; padding: .45rem .5rem; }
  .dl-search .btn { width: 100%; }
  .ud-row { flex-wrap: wrap; }
  .ud-row-main { flex-basis: calc(100% - 4rem); }
}
@media (prefers-reduced-motion: reduce) {
  .ch-card, .cat-tile { transition: none; }
}
