/* series — the series page's own chrome and the SHARED read-card grid (.b-read-cards) */

/* the shared mono-label voice: meta, section strip */
.b-series .series-meta,
.b-series .series-sections {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

/*** custom-series.hbs — the series page's own chrome ***/
@scope (.b-series) {
  /* full content width — the card grid spans like every read list */
  :scope {
    inline-size: 100%;
    padding-block-end: clamp(4rem, 8vi, 6rem); /* the sections' shared footer clamp */
  }
  /* hero meta: LEVEL · CATEGORY · N SECTIONS · N READS, CSS middots, centered */
  .series-meta {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.625rem;
    color: var(--text-tertiary);
    font-size: 0.75rem;
  }
  .series-meta span + span::before {
    content: "· ";
    color: var(--fg-quaternary);
  }
  /* the two groups (level · category, sections · reads) run inline; an empty group leaves no stray middot */
  .meta-group {
    display: contents;
  }
  .meta-group:not(:has(span)) {
    display: none;
  }
  /* phones: one group per line */
  @media (width <= 480px) {
    .series-meta {
      flex-direction: column;
      align-items: center;
      gap: 0.375rem;
    }
    .meta-group {
      display: flex;
      align-items: baseline;
      gap: 0.625rem;
    }
    .series-meta span.meta-group::before {
      content: none; /* outweighs the middot rule */
    }
  }
  /* the section strip: series.js filter buttons; the active pick goes brand and underlines; it sits in the list's centered 56rem measure (the list's own rule lives in the is-list block: this scope's margins lose to .b-read-cards's root) */
  .series-sections {
    max-inline-size: 56rem;
    margin-inline: auto;
    margin-block-start: clamp(2rem, 5vi, 3rem);
    display: flex;
    align-items: baseline;
    column-gap: 1.75rem;
    row-gap: 0.5rem;
    flex-wrap: wrap;
    border-block-end: 1px solid var(--border-secondary);
    padding-block: 0.375rem;
    font-size: 0.75rem;
  }
  .series-sections button {
    position: relative;
    border: 0;
    background: none;
    /* block padding lives on the buttons for tap room */
    padding: 0.5rem 0;
    cursor: pointer;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    color: var(--text-primary);
    white-space: nowrap;
  }
  .series-sections button::after {
    content: "";
    position: absolute;
    inset: -0.375rem -0.5625rem; /* the 44px hit box; the strip's 1.75rem gaps leave the room (All is 27.5px wide) */
  }
  .series-sections button:hover {
    color: var(--text-brand-secondary);
  }
  .series-sections [aria-current] {
    color: var(--text-brand-secondary);
    text-decoration: underline;
    text-underline-offset: 0.375em;
  }
  .section-number {
    color: var(--text-brand-secondary);
  }
  .series-list {
    margin-block-end: clamp(3rem, 7vi, 5rem);
  }
  /* a section group: mono "NN NAME" head */
  .series-section {
    padding-block-start: 2.5rem;
  }
  .series-section > header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-block-end: 1rem;
  }
  .series-section > header .section-number,
  .series-section > header h2 {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.09em;
  }
  .series-section > header h2 {
    text-transform: uppercase;
    color: var(--text-primary);
  }
  /* phones: the strip scrolls sideways; the narrowest wrap instead (a scroll with no cue cut the last tab) */
  @media (width <= 44rem) {
    .series-sections {
      flex-wrap: nowrap;
      overflow-x: auto;
      scrollbar-width: none;
    }
    @media (width <= 30rem) {
      .series-sections {
        flex-wrap: wrap;
        overflow-x: visible;
      }
    }
    .series-section {
      padding-block-start: 2rem;
    }
  }
}

/*** the shared read-card grid (.b-read-cards): series, collection, tag + author lists ***/
@scope (.b-read-cards) {
  :scope {
    list-style: none;
    margin: 0;
    padding: 0;
    inline-size: 100%;
  }
  /* the grid: fixed 3/2/1 tracks down the breakpoints */
  :scope:not(:has(.series-section)),
  .section-reads {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1.25rem;
  }
  @media (width <= 64rem) {
    :scope:not(:has(.series-section)),
    .section-reads {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
  }
  /* the numbered collection ol: CSS counters, the server order is the numbering */
  :scope.is-numbered {
    counter-reset: reads;
  }
  :scope.is-numbered .read-card {
    counter-increment: reads;
  }
  :scope.is-numbered .read-number::before {
    content: counter(reads, decimal-leading-zero);
  }
  /* a read's own number (read-cards.js writes it off the #order-NN stamp) replaces the counter */
  :scope.is-numbered .read-number:not(:empty)::before {
    content: none;
  }
  /* one read card; the whole card is the door: the title link's ::after covers it, so a right click and a new-tab click reach the link */
  .read-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-block-size: 8.5rem;
    padding: 1.125rem;
    border: 1px solid var(--border-secondary);
    border-radius: 0.875rem;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease,
      transform 0.15s ease, box-shadow 0.15s ease;
  }
  /* hover lifts the card: shadow + a nudge up, the face unchanged */
  .read-card:hover {
    transform: translateY(-2px);
    box-shadow:
      0 4px 6px -2px light-dark(rgb(var(--shadow-rgb) / 0.03), rgb(var(--shadow-rgb) / 0.2)),
      0 12px 16px -4px light-dark(rgb(var(--shadow-rgb) / 0.08), rgb(var(--shadow-rgb) / 0.45));
  }
  /* top row: the read number */
  .read-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.75rem;
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    letter-spacing: 0.06em;
    color: var(--text-tertiary);
  }
  /* the parent ref in the number's seat (tag/author cards) */
  .read-parent {
    min-inline-size: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .card-ref {
    font-family: var(--font-mono);
    text-transform: uppercase;
    color: var(--utility-blue-light-700);
    text-decoration: none;
  }
  .card-ref:hover,
  .card-ref:focus-visible {
    text-decoration: underline;
  }
  .read-card h3 {
    font-size: 1.125rem;
    font-weight: 700;
    line-height: 1.25;
  }
  .read-card h3 a {
    color: var(--text-primary);
    text-decoration: none;
    transition: color 0.15s ease;
  }
  .read-card h3 a:hover {
    color: var(--text-brand-secondary);
  }
  .read-card h3 a::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
  }
  /* the card's other links sit over the title link's cover */
  .read-card :is(a, button):not(h3 a) {
    position: relative;
    z-index: 1;
  }
  .read-tags {
    margin-block-start: auto;
    display: flex;
    flex-wrap: wrap;
    align-content: end;
    gap: 0.5rem;
    /* two chip rows reserved; chips past row two hide (read-cards.js) */
    min-block-size: 3.5rem;
  }
  .read-tags:empty {
    display: none;
  }
  /* a tag chip: bordered pill, the badges.js hash tint on the dot */
  .card-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0.625rem;
    border: 1px solid var(--border-secondary);
    border-radius: 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: lowercase;
    color: var(--text-secondary);
    text-decoration: none;
    transition: border-color 0.15s ease, color 0.15s ease;
  }
  .card-tag::before {
    content: "";
    inline-size: 0.375rem;
    block-size: 0.375rem;
    border-radius: 50%;
    background: color-mix(in oklch,
      var(--utility-brand-700) var(--badge-mix, 100%),
      var(--badge-to, var(--utility-brand-700)));
  }
  .card-tag:hover,
  .card-tag:focus-visible {
    border-color: var(--fg-quaternary);
    color: var(--text-primary);
  }
  /* the /series/ index's seats: the LEVEL word in the number's place, the ↗ door on the end edge */
  .read-level {
    text-transform: uppercase;
    letter-spacing: 0.1em;
  }
  .read-top .card-external {
    display: inline-grid;
    place-items: center;
    color: var(--fg-quaternary);
    transition: color 0.15s ease;
  }
  .read-top .card-external:hover {
    color: var(--text-brand-secondary);
  }
  /* the category marker: the chip box in uppercase, no tag dot */
  .card-tag[data-category] {
    text-transform: uppercase;
    letter-spacing: 0.1em;
  }
  .card-tag[data-category]::before {
    content: none;
  }
  /* a marker, not a door: no hover answer */
  .card-tag[data-category]:hover {
    border-color: var(--border-secondary);
    color: var(--text-secondary);
  }
  /* phones: one column at a tighter scale */
  @media (width <= 44rem) {
    :scope:not(:has(.series-section)),
    .section-reads {
      grid-template-columns: minmax(0, 1fr);
      gap: 0.75rem;
    }
    .read-card {
      min-block-size: 7.75rem;
      padding: 1rem;
    }
    .read-card h3 {
      font-size: 1.0625rem;
    }
  }

  /* ---- the LIST face (series pages, is-list): the same card DOM as rows under hairlines, no boxes ---- */
  :scope.is-list,
  :scope.is-list .section-reads {
    display: block;
  }
  /* the list face sits in a centered 56rem measure: full width left the title-to-tags gap hollow once reads stopped wearing tags */
  :scope.is-list {
    max-inline-size: 56rem;
    margin-inline: auto;
  }
  /* one row: number · title · tags; the whole row stays the door, hover is the home rows' pill */
  :scope.is-list .read-card {
    display: flex;
    flex-direction: row;
    align-items: baseline;
    gap: 1.5rem;
    min-block-size: 0;
    padding-block: 1.25rem;
    padding-inline: 0.5rem;
    margin-inline: -0.5rem;
    border: 0;
    border-block-end: 1px solid var(--border-secondary);
    border-radius: 0.5rem;
  }
  :scope.is-list .read-card:hover {
    transform: none;
    box-shadow: none;
    background-color: color-mix(in srgb, var(--fg-quaternary) 7%, transparent);
  }
  /* the top row dissolves into the flex row: the number leads */
  :scope.is-list .read-top {
    display: contents;
  }
  :scope.is-list .read-number {
    order: -1;
    flex-shrink: 0;
    inline-size: 1.75rem;
    font-size: 0.8125rem;
  }
  :scope.is-list h3 {
    flex: 1;
    min-inline-size: 0;
    font-size: 1.25rem;
    line-height: 1.35;
  }
  /* tags on the end edge in the "# " voice (badges.js tint), one line */
  :scope.is-list .read-tags {
    order: 1;
    margin-block-start: 0;
    min-block-size: 0;
    flex-shrink: 0;
    flex-wrap: nowrap;
    gap: 0.75rem;
    white-space: nowrap;
  }
  :scope.is-list .card-tag {
    gap: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    font-size: 0.8125rem;
    color: color-mix(in oklch,
      var(--utility-brand-700) var(--badge-mix, 100%),
      var(--badge-to, var(--utility-brand-700)));
  }
  :scope.is-list .card-tag::before {
    content: "# ";
    white-space: pre; /* the flex item would drop the trailing space */
    inline-size: auto;
    block-size: auto;
    border-radius: 0;
    background: none;
  }
  :scope.is-list .card-tag:hover,
  :scope.is-list .card-tag:focus-visible {
    text-decoration: underline;
  }
  /* phones: number · title on one line, the tags under the title */
  @media (width <= 44rem) {
    :scope.is-list .read-card {
      display: grid;
      grid-template-columns: auto minmax(0, 1fr);
      column-gap: 0.875rem;
      row-gap: 0.375rem;
      align-items: baseline;
      padding-block: 1rem;
    }
    :scope.is-list .read-number {
      grid-area: 1 / 1;
    }
    :scope.is-list h3 {
      grid-area: 1 / 2;
      font-size: 1.0625rem;
    }
    :scope.is-list .read-tags {
      grid-area: 2 / 2;
      flex-wrap: wrap;
      white-space: normal;
    }
  }
}
