/* Hub first screen: the opening (band, Featured, then the list), the band with its htmx primer, and the
   colophon's metric-line gag. Registered so 1ex / 1em resolve at the wordmark's size and inherit as lengths. */
@property --xh { syntax: '<length>'; inherits: true; initial-value: 0px; }
@property --em { syntax: '<length>'; inherits: true; initial-value: 0px; }

@layer masthead {
  /* The opening: the band, Featured and the project list, in that DOM order. From 64rem the band takes
     cols 1-5 and Featured (a self-contained demo: stage, notes, actions) cols 6-12, then the list below.
     Featured reserves its tallest fragment (featured.css), so a rotation never moves the list. The list
     sits in the same box so phones can move Featured below it while reading-flow keeps focus order with
     what is shown: reading-flow only reorders direct children of the flex box. */
  .opening {
    max-inline-size: var(--page-max); margin-inline: auto;
    padding-block-start: clamp(1rem, 2vw, 1.25rem);
  }
  .opening > .collection { min-inline-size: 0; margin-block-start: clamp(1.5rem, 3vw, 1.75rem); }
  @media (width >= 64rem) {
    .opening { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); column-gap: var(--col-gap); align-items: start; }
    .opening > .masthead { grid-column: 1 / span 5; padding-inline-end: clamp(0.5rem, 2vw, 2rem); padding-block-end: 0; }
    .opening > .featured { grid-column: 6 / -1; }
    .opening > .collection { grid-column: 1 / -1; margin-block-start: clamp(2rem, 4vw, 3rem); }
  }

  /* Phones: list first. The band, Browse and Add yours, then All projects, then Featured (still live, it
     loads as it nears the viewport). The skip link (#main) and Browse (#collection) land as before. */
  @media (width < 40rem) {
    .opening { display: flex; flex-direction: column; reading-flow: flex-visual; }
    .opening > .collection { margin-block-start: 0; }
    .opening > .featured { order: 1; margin-block-start: clamp(2.5rem, 10vw, 3.5rem); }
  }

  /* The band: what the site is (a plain h1, one line of scope, real counts), then what htmx is, then the
     two actions and the disclaimer. htmx is a labelled sub-section, a step quieter than the h1. */
  .masthead {
    container: masthead / inline-size;
    display: grid; align-content: start; gap: 0.85rem;
    padding-block-end: 1.75rem;
  }
  .masthead__title {
    font-size: clamp(2rem, 1.2rem + 2vw, 2.75rem); line-height: 0.98; letter-spacing: -0.025em;
    text-wrap: balance;
  }
  .masthead__intro { font-size: 1.25rem; line-height: 1.2; font-style: italic; color: var(--ink-2); text-wrap: pretty; }
  .masthead__counts {
    font: 400 0.75rem / 1.5 var(--mono); color: var(--ink-3);
    font-variant-numeric: tabular-nums;
    & b { font-weight: 500; color: var(--ink); }
    & span { white-space: nowrap; }
  }

  .about {
    display: grid; gap: 0.85rem; align-items: start;
    margin-block-start: 0.4rem; padding-block-start: 0.8rem; border-top: 1px solid var(--hair-strong);
  }
  .about__label {
    font: 500 var(--fs-label) / 1.3 var(--mono); letter-spacing: var(--track-label); text-transform: uppercase;
    color: var(--ink);
  }
  .about__code {
    padding: 0.65rem 0.85rem; border: 1px solid var(--hair-strong); overflow-x: auto;
    font: 400 0.75rem / 1.55 var(--mono); color: var(--ink-3);
    & code { font: inherit; color: var(--ink-2); }
    & b { font-weight: 500; color: var(--ink); }
  }
  .about__gist { font-size: 1.1875rem; line-height: 1.3; text-wrap: pretty; }
  .about__why {
    font: 400 var(--fs-mono) / 1.5 var(--mono); color: var(--ink-2);
    & li { padding-block: 0.5rem 0.55rem; border-top: 1px solid var(--hair); text-wrap: pretty; }
    & b { font-weight: 500; color: var(--ink); }
    & code { font-size: 1em; color: var(--ink-2); }
  }
  /* Why htmx · Get it · Learn · Follow: the three reasons and the links fold into one disclosure on phones
     (the code and its one sentence stay out), so the list starts sooner; always open from 40rem (where
     ::details-content is supported; elsewhere it stays a disclosure everywhere) */
  .about__summary {
    display: flex; align-items: center; gap: 0.6rem; min-block-size: 44px;
    border-block: 1px solid var(--hair);
    font: 500 var(--fs-label) / 1 var(--mono); letter-spacing: var(--track-label); text-transform: uppercase;
    color: var(--ink-2); cursor: pointer; list-style: none;
    &::-webkit-details-marker { display: none; }
    &::before { content: '+'; inline-size: 1ch; font-size: 0.875rem; color: var(--accent-text); }
    &:hover { color: var(--ink); }
  }
  .about__more[open] > .about__summary::before { content: '\2212'; }
  @media (width >= 40rem) {
    @supports selector(::details-content) {
      .about__summary { display: none; }
      .about__more::details-content { content-visibility: visible; }
    }
  }
  .about__more > .about__why { padding-block-start: 0.35rem; }
  @media (width >= 40rem) { .about__more > .about__why { padding-block-start: 0; } }
  .about__links {
    display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0.45rem 1rem; align-items: baseline;
    padding-block: 0.6rem 0.1rem;
    font: 400 0.75rem / 1.55 var(--mono); color: var(--ink-3);
    & dt { font-weight: 500; font-size: var(--fs-label); letter-spacing: var(--track-label); text-transform: uppercase; }
    & dd { color: var(--ink-3); }
    & a, & code { color: var(--ink); }
    & code { font-size: 1em; }
    & small { font-size: 1em; }
  }
  @media (pointer: coarse) { .about__links a { display: inline-flex; align-items: center; min-block-size: 44px; } }

  /* A wide band (40-64rem, full width): code and gist beside the three reasons and the links */
  @container masthead (inline-size >= 40rem) {
    /* the third row takes the disclosure's extra height, so the gist sits right under the code */
    .about { grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); grid-template-rows: auto auto 1fr; column-gap: var(--col-gap); }
    .about__label { grid-column: 1 / -1; }
    .about__more { grid-column: 2; grid-row: 2 / span 2; }
    .about__gist { grid-column: 1; }
  }

  .masthead__actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-block-start: 0.35rem; }
  .masthead__action {
    display: inline-flex; align-items: center; min-block-size: 44px; padding-inline: 1rem;
    border: 1px solid var(--hair-strong);
    font: 500 var(--fs-label) / 1 var(--mono); letter-spacing: var(--track-label); text-transform: uppercase;
    text-decoration: none; color: var(--ink);
    transition: border-color 0.2s, background-color 0.2s, color 0.2s;
    &:hover { border-color: var(--ink); color: var(--ink); }
  }
  .masthead__action--primary {
    background: var(--white); border-color: var(--white); color: var(--black);
    &:hover { background: var(--black); color: var(--ink); border-color: var(--white); }
  }
  /* Set quietly, lower case as written */
  .masthead__disclaimer { font: 400 var(--fs-label) / 1.55 var(--mono); letter-spacing: 0.02em; color: var(--ink-3); text-wrap: pretty; }
  @media (width < 40rem) {
    .masthead { gap: 0.7rem; padding-block-end: 1.25rem; }
    .about { gap: 0.7rem; }
    .masthead__action { padding-inline: 0.8rem; letter-spacing: 0.1em; }
  }

  /* Colophon gag: the wordmark's cap height, x-height, baseline and descender, drawn through it.
     Hub only (the spans exist only in index.html). Inset to the gutter: the lines never leave the page. */
  .colophon__mark:has(.metrics) {
    position: relative;
    --xh: 1ex;
    --em: 1em;
  }
  .metrics {
    position: absolute; inset: 0; pointer-events: none;

    & i {
      position: absolute; inset-inline: 0; block-size: 0;
      border-top: 1px solid var(--accent);
      transform-origin: left;

      /* labels sit at the right end, past the word: from 64rem the word leaves 170px+ free there */
      &::after {
        content: attr(data-m);
        position: absolute; inset-inline-end: 0; bottom: 0.35rem;
        font: 500 0.625rem / 1 var(--mono); letter-spacing: var(--track-label); text-transform: uppercase;
        color: var(--accent-text);
      }
    }
    & i:nth-child(1) { top: 0; }
    & i:nth-child(2) { bottom: var(--xh); border-top-style: dashed; }
    & i:nth-child(3) { bottom: 0; }
    & i:nth-child(4) { bottom: calc(var(--em) * -0.205); border-top-style: dotted; opacity: 0.7; }
  }
  /* Without text-box-trim the lines would sit on the wrong metrics, so they don't appear at all. */
  .metrics { display: none; }
  @supports (text-box: trim-both cap alphabetic) {
    .colophon__mark:has(.metrics) { text-box: trim-both cap alphabetic; }
    .metrics { display: block; }
  }
  /* Below 64rem the word runs close to the right edge (768: BASELINE fell on the final letter): no labels */
  @media (width < 64rem) {
    .metrics i::after { display: none; }
  }
}
