/* Project page (plate), sheet part: head (colour chip, plate no., name, tagline), the margin with the
   lettered notes and an optional aside, and the measured spec. This layer also places .exhibit and
   .spec; p-exhibit.css styles the figure inside. Anatomy and fill-ins: riffs/specimen-v2/TEMPLATE.md (design record, in the repo) */
@layer plate {
  .plate__sheet {
    display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); column-gap: var(--col-gap);
    row-gap: clamp(1.5rem, 3vw, 2.5rem);
    padding-block-start: clamp(2.5rem, 6vw, 5.5rem);
  }

  /* Example pages (placeholder projects): a band above the sheet says so before anything else. Dashed, as
     every Example mark is; frame ink, never red. */
  .plate__example {
    max-inline-size: var(--page-max); margin: clamp(1rem, 2.5vw, 1.75rem) auto 0; padding: 0.8rem 1rem;
    display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.35rem 1rem;
    border: 1px dashed var(--hair-strong);
    font: 400 var(--fs-mono) / 1.55 var(--mono); color: var(--ink-2); text-wrap: pretty;
    & b { font-size: var(--fs-label); font-weight: 500; letter-spacing: var(--track-label); text-transform: uppercase; color: var(--ink); }
    & a { color: var(--ink); }
  }

  .plate__head {
    grid-column: 1 / -1;
    display: grid; grid-template-columns: subgrid; align-items: end; row-gap: 0.9rem;
    padding-block-end: clamp(1.5rem, 3vw, 2.5rem);
    border-bottom: 1px solid var(--hair-strong);
  }

  /* The colour-reference chip: the plate's own accent, set like an element in a periodic table.
     One of the four places the frame reads --skin-accent (SPEC §6). Capped at 12rem so it never sets
     the head's height (the name and tagline do); on phones it shrinks to the 2.75rem row symbol. */
  .plate__chip {
    --on-skin: oklch(from var(--skin-accent) clamp(0.08, (0.545 - l) * 1000, 0.95) 0 0);
    grid-column: 1 / 4; grid-row: 1 / span 3; align-self: end;
    container-type: inline-size;
    display: grid; grid-template-rows: auto 1fr auto;
    aspect-ratio: 1; inline-size: 100%; max-inline-size: 12rem;
    padding: 0.75rem 0.85rem;
    background: var(--skin-accent); color: var(--on-skin);
    font: 500 var(--fs-label) / 1 var(--mono); letter-spacing: var(--track-label); text-transform: uppercase;

    & > span:first-child { display: flex; justify-content: space-between; }
    & b {
      align-self: end; margin-inline-start: -0.05em;
      padding-block-end: 0.24em; /* room for a descender ("Hp") above the rule */
      font: 400 64cqi / 0.74 var(--serif); letter-spacing: -0.06em; text-transform: none;
    }
    & > span:last-child { margin-block-start: 0.7rem; padding-block-start: 0.55rem; border-top: 1px solid currentColor; }
  }

  /* With a logomark (tools/site/marks.mjs) the mark is the chip's hero and the chip is its ground: Signal black
     in a hairline, the accent kept as the 5px tag along the foot (as a tile window wears it), No. and class
     numeral above, the name on its rule below. The mark is capped at 8rem: mark-dark's lit edge is drawn for
     32-128px and reads heavy past that. */
  .plate__chip:has(> .plate__mark) {
    background: var(--black); color: var(--ink-3);
    border: 1px solid var(--hair-strong); border-block-end: 5px solid var(--skin-accent);
    & > span:last-child { margin-block-start: 0.6rem; border-top-color: var(--hair-strong); color: var(--ink); }
  }
  .plate__mark { align-self: center; justify-self: center; inline-size: min(76cqi, 8rem); block-size: auto; aspect-ratio: 1; }

  /* "Project page · Plate 002", then one outlined tag per class or state, then the date it was added */
  .plate__no {
    grid-column: 4 / -1; align-self: start;
    display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem;
    font: 500 var(--fs-label) / 1 var(--mono); letter-spacing: var(--track-label); text-transform: uppercase;
    color: var(--ink-2);

    & b { color: var(--accent-text); font-weight: 500; }
    & span { padding: 0.35rem 0.5rem; border: 1px solid var(--hair-strong); color: var(--ink-3); }
    & small { font: inherit; color: var(--ink-3); }
  }
  .plate__name {
    grid-column: 4 / -1;
    font-size: var(--fs-plate); line-height: 0.82; letter-spacing: -0.045em;
    margin-inline-start: -0.05em;
    overflow-wrap: anywhere;
    /* A name may italicise part of itself (<em>hyper</em>plot). That part is set in the project's
       own accent, lifted to L >= 0.6 so display type keeps 3:1 on black: never Signal red, which
       belongs to the frame. The fourth place the frame reads --skin-accent (SPEC §6). */
    & em { font-style: italic; color: oklch(from var(--skin-accent) max(l, 0.6) c h); }
  }
  .plate__tagline {
    grid-column: 4 / span 7;
    font-size: var(--fs-lede); line-height: 1.05; font-style: italic; color: var(--ink-2);
    text-wrap: balance;
  }

  /* The margin: notes A–D, and optionally an aside that a note points at (a request slip, say) */
  .plate__margin {
    grid-column: 1 / 4; grid-row: 2 / span 2; align-self: start;
    display: flex; flex-direction: column; gap: 2rem;
  }

  /* Annotations A–D: Signal mono, red leaders pointing into the exhibit window */
  .plate__notes {
    counter-reset: note;
    font: 400 var(--fs-mono) / 1.55 var(--mono); color: var(--ink-2);

    & li {
      counter-increment: note;
      position: relative;
      padding-block: 0.8rem 1rem;
      border-top: 1px solid var(--hair);
      text-wrap: pretty;

      &::before {
        content: counter(note, upper-alpha);
        display: block; margin-block-end: 0.35rem;
        font: italic 400 1.5rem / 1 var(--serif); color: var(--accent);
      }
      &::after {
        content: ''; position: absolute; top: 1.55rem; left: calc(100% + 0.5rem);
        inline-size: calc(var(--col-gap) - 0.5rem); border-top: 1px solid var(--accent);
      }
    }
    & b { color: var(--ink); font-weight: 500; }
    & kbd { font: 500 var(--fs-label) / 1 var(--mono); padding: 0.1rem 0.3rem; border: 1px solid var(--hair-strong); color: var(--ink); }
  }

  /* Optional aside under the notes: a frame-styled slip that a stage can target (hx-target) */
  .plate__aside {
    position: sticky; top: calc(var(--rail-h) + 1.5rem);
    padding: 0.9rem 1rem 1rem; border: 1px solid var(--hair-strong); border-top: 2px solid var(--accent);
    font: 400 var(--fs-mono) / 1.45 var(--mono); color: var(--ink-2);
  }
  .plate__aside-head { display: flex; justify-content: space-between; gap: 1rem; margin-block-end: 0.6rem; }
  .plate__aside-body {
    overflow-wrap: anywhere;
    &:empty::before { content: attr(data-empty); color: var(--ink-3); }
    & b { color: var(--accent-text); font-weight: 500; }
    & p:first-child { color: var(--ink); }
    & dl { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0.2rem 0.8rem; margin-block: 0.7rem 0.6rem; }
    & dt { color: var(--ink-3); }
    & dd { color: var(--ink); }
    & small { font-size: var(--fs-label); color: var(--ink-3); }
  }

  .exhibit { grid-column: 4 / -1; grid-row: 2; align-self: start; }

  /* The measured spec: six cells, hairlines as clipped box-shadows. Long values wrap in their cell. */
  .spec {
    grid-column: 4 / -1; grid-row: 3; align-self: start;
    display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 7.5rem), 1fr));
    border-block: 1px solid var(--hair-strong);
    overflow: clip;

    & div { min-inline-size: 0; padding: 0.8rem 0.9rem 0.9rem; box-shadow: -1px 0 0 var(--hair), 0 -1px 0 var(--hair); }
    & dt { font: 500 var(--fs-label) / 1 var(--mono); letter-spacing: var(--track-label); text-transform: uppercase; color: var(--ink-3); }
    & dd { margin-block-start: 0.45rem; font-size: 1.35rem; line-height: 1.05; overflow-wrap: anywhere; hyphens: auto; }
    & small { display: block; margin-block-start: 0.3rem; font: 400 var(--fs-label) / 1.3 var(--mono); color: var(--ink-3); }
  }

  /* One column below 64rem: head, exhibit, aside, spec, then notes */
  @media (width < 64rem) {
    .plate__chip { grid-column: 1 / span 4; grid-row: 1; }
    .plate__no { grid-column: 5 / -1; grid-row: 1; align-self: end; }
    .plate__name, .plate__tagline { grid-column: 1 / -1; }
    .plate__margin { display: contents; }
    .plate__notes, .plate__aside, .exhibit, .spec { grid-column: 1 / -1; grid-row: auto; }
    .exhibit { order: 1; margin-block: 0.75rem; }
    .plate__aside { order: 2; position: static; }
    .spec { order: 3; }
    .plate__notes {
      order: 4;
      display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); column-gap: var(--col-gap);
      & li::after { display: none; }
    }
  }
  /* Phones: the chip is the row symbol (2.75rem, symbol only) beside the plate line, so Fig. 1 starts sooner */
  @media (width < 40rem) {
    .plate__chip {
      grid-column: 1 / span 2; align-self: start;
      inline-size: 2.75rem; place-content: center; padding: 0;
      & > span:is(:first-child, :last-child) { display: none; }
      & b { align-self: center; justify-self: center; margin: 0; padding: 0; font-size: 1.35rem; line-height: 1; letter-spacing: -0.03em; }
    }
    .plate__chip:has(> .plate__mark) { border: 0; background: none; }
    .plate__mark { justify-self: center; inline-size: 2.75rem; }
    .plate__no { grid-column: 3 / -1; align-self: center; }
  }
}
