/* Reference rooms (history, library, every article page).
   Contract: docs/DESIGN_SYSTEM_2026.md. Tokens and shared components come from atlas.css. */
@layer pages {
  .ref { overflow-wrap: anywhere; }
  .ref [tabindex="-1"]:focus { outline: none; }
  .tl-item, .record, .card { min-width: 0; }

  /* ── page head ─────────────────────────────────────────────── */
  .ref .page-head { padding-bottom: clamp(1.25rem, 0.8rem + 1.8vw, 2rem); margin-bottom: clamp(1.25rem, 0.8rem + 2vw, 2.25rem); }
  .ref .page-head h1 { font-size: clamp(2.4rem, 1.2rem + 4.4vw, 4.5rem); max-width: 22ch; }
  .ref .page-head .lede { font-size: var(--step-0); max-width: 52rem; }

  /* ── two-column reading layout ─────────────────────────────── */
  .ref-layout {
    display: grid;
    gap: 1.5rem;
    padding-bottom: var(--section);
  }

  /* TOC: compact disclosure on small screens, sticky rail on desktop. */
  .ref-toc > .disclosure {
    border: 1px solid var(--rule);
    border-radius: var(--radius-sm);
    background: var(--surface);
    padding-inline: 1rem;
  }
  .ref-toc > .disclosure > summary { min-height: 2.75rem; padding-block: 0.6rem; font-size: 0.95rem; }
  .ref-toc ol { margin-top: 0.25rem; }
  .ref-toc a { padding-block: 0.6rem; }

  @media (min-width: 64rem) {
    .ref-layout {
      grid-template-columns: 15rem minmax(0, 1fr);
      gap: clamp(2.5rem, 5vw, 5rem);
      align-items: start;
    }
    .ref-toc {
      position: sticky;
      top: calc(var(--masthead-h) + 1.5rem);
      max-height: calc(100vh - var(--masthead-h) - 3rem);
      overflow-y: auto;
    }
    .ref-toc > .disclosure { border: 0; background: none; padding-inline: 0; border-radius: 0; }
    .ref-toc > .disclosure > summary {
      min-height: 0;
      padding: 0 0 0.6rem;
      pointer-events: none;
      cursor: default;
      font-family: var(--font-mono);
      font-size: 0.7rem;
      font-weight: 500;
      letter-spacing: 0.12em;
      text-transform: uppercase;
      color: var(--ink-3);
    }
    .ref-toc > .disclosure > summary::after { display: none; }
    .ref-toc > .disclosure { border-top: 0; }
    .ref-toc a { padding-block: 0.3rem; }
  }

  .ref-body { min-width: 0; max-width: 56rem; }

  /* ── sections ──────────────────────────────────────────────── */
  .ref-section { padding-block: clamp(1.75rem, 1.2rem + 2vw, 2.75rem); border-top: 1px solid var(--rule); }
  .ref-section:first-child { border-top: 0; padding-top: 0; }
  .ref-section-head { display: grid; gap: 0.75rem; justify-items: start; margin-bottom: 1rem; }
  .ref-section-head h2 { font-size: var(--step-2); line-height: 1.05; max-width: 32ch; }
  .ref-section > .sources { margin-top: 1rem; }

  .ref-tags { display: flex; flex-wrap: wrap; gap: 0.4rem; }

  .ref .sources a { display: inline-block; padding-block: 0.3rem; }

  /* ── records (default) ─────────────────────────────────────── */
  .records { display: grid; margin-top: 1.25rem; }
  .record { display: grid; gap: 0.75rem; padding-block: 1.4rem; border-top: 1px solid var(--rule); }
  .record:first-child { border-top: 0; padding-top: 0.25rem; }
  .record-head { display: grid; gap: 0.5rem; justify-items: start; }
  .record-head h3 { font-size: var(--step-1); font-stretch: 70%; line-height: 1.12; max-width: 40ch; }
  .record .prose { font-size: 0.98rem; line-height: 1.65; }
  .record .sources { margin-top: 0.15rem; }

  .record .disclosure { margin-top: 0.25rem; }
  .record .disclosure > summary { padding-block: 0.7rem; min-height: 2.75rem; font-size: 0.92rem; }

  /* Long lists stay visible: lay them out as a two-column board of panels. */
  .records--compact {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 19rem), 1fr));
    gap: 0.9rem;
    align-items: start;
  }
  .records--compact .record,
  .records--compact .record:first-child { border-top: 1px solid var(--rule); padding: 1.1rem 1.15rem 1.2rem; }
  .records--compact .record-head h3 { font-size: 1.12rem; }
  .records--compact .record .prose { font-size: 0.92rem; }

  /* ── timeline (history) ────────────────────────────────────── */
  .timeline {
    list-style: none;
    margin: 1.75rem 0 0 0.35rem;
    padding: 0 0 0 1.6rem;
    border-left: 2px solid var(--rule-strong);
  }
  .tl-item { position: relative; display: grid; gap: 0.7rem; padding-bottom: 2.4rem; }
  .tl-item:last-child { padding-bottom: 0.5rem; }
  .tl-item::before {
    content: "";
    position: absolute;
    left: calc(-1.6rem - 1px - 0.42rem);
    top: 0.2rem;
    width: 0.82rem;
    height: 0.82rem;
    border-radius: 50%;
    background: var(--paper);
    border: 2px solid var(--ink-3);
  }
  .tl-item[data-ev="onchain"]::before,
  .tl-item[data-ev="verified"]::before { background: var(--ink); border-color: var(--ink); }
  .tl-item[data-ev="forum"]::before,
  .tl-item[data-ev="self"]::before,
  .tl-item[data-ev="community"]::before { border-color: var(--ink-2); }
  .tl-item[data-ev="speculation"]::before,
  .tl-item[data-ev="unknown"]::before { border-style: dashed; }
  .tl-head { display: grid; gap: 0.4rem; justify-items: start; }
  .tl-date {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    font-weight: 500;
    letter-spacing: 0.06em;
    color: var(--open-ink);
  }
  .tl-head h3 { font-size: var(--step-2); font-stretch: 62%; line-height: 1.05; max-width: 30ch; }
  .tl-item .prose { font-size: 0.98rem; line-height: 1.65; }
  .tl-item .sources { margin-top: 0.1rem; }

  /* ── frontier by date (history timeline section) ─────────────── */
  .frontier { margin-top: 1.75rem; }
  .frontier-title { font-size: var(--step-1); font-stretch: 70%; line-height: 1.1; margin-bottom: 1rem; }
  .frontier-plot { display: block; width: 100%; height: auto; overflow: visible; }
  .frontier-plot--tall { display: none; }
  @media (max-width: 40rem) {
    .frontier-plot--wide { display: none; }
    .frontier-plot--tall { display: block; }
  }
  .fr-grid line { stroke: var(--rule); stroke-dasharray: 2 6; }
  .fr-grid .fr-tick { stroke-dasharray: none; }
  .fr-grid text { font-family: var(--font-mono); fill: var(--ink-3); }
  .fr-line { fill: none; stroke-width: 2.5; stroke-linejoin: round; }
  .frontier-plot--tall .fr-line { stroke-width: 4; }
  .fr-series--scan .fr-line { stroke: var(--ink); }
  .fr-series--kangaroo .fr-line { stroke: var(--ink-3); stroke-dasharray: 8 5; }
  .fr-series--scan circle { fill: var(--ink); }
  .fr-series--kangaroo circle { fill: var(--paper); stroke: var(--ink-3); stroke-width: 2; }
  .fr-end { font-family: var(--font-mono); font-weight: 500; fill: var(--ink); }
  .fr-next { stroke-width: 5; }
  .fr-next--scan { stroke: var(--open); }
  .fr-next--kangaroo { stroke: var(--key); }
  .fr-legend { list-style: none; padding: 0; margin: 1rem 0 0.6rem; display: flex; flex-wrap: wrap; gap: 0.4rem 1.5rem; font-size: 0.88rem; color: var(--ink-2); }
  .fr-legend li { display: flex; align-items: center; gap: 0.5rem; }
  .fr-swatch { flex: none; width: 1.6rem; height: 0; border-top: 3px solid var(--ink); }
  .fr-swatch--kangaroo { border-top: 3px dashed var(--ink-3); }
  .fr-swatch--next-scan { width: 0.9rem; border-top: 5px solid var(--open); }
  .fr-swatch--next-kangaroo { width: 0.9rem; border-top: 5px solid var(--key); }
  .frontier-table { margin-top: 1.25rem; }

  /* ── library cards ─────────────────────────────────────────── */
  .records--card {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 17.5rem), 1fr));
    gap: 0.9rem;
    align-items: stretch;
  }
  .card {
    position: relative;
    display: grid;
    align-content: start;
    gap: 0.6rem;
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    padding: 1.15rem 1.2rem 1.25rem;
    transition: border-color 0.15s;
  }
  .card:hover,
  .card:focus-within { border-color: var(--ink-3); }
  .card h3 { font-size: 1.3rem; font-stretch: 70%; line-height: 1.1; }
  .card-link { text-decoration: none; }
  .card-link::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
  .card-link:focus-visible { outline: none; }
  .card:has(.card-link:focus-visible) { outline: 2px solid var(--focus); outline-offset: 3px; }
  .card:hover .card-link { text-decoration: underline; text-decoration-color: var(--open); text-decoration-thickness: 2px; text-underline-offset: 0.2em; }
  .card-body { font-size: 0.92rem; line-height: 1.55; color: var(--ink-2); }
  .card .sources { position: relative; z-index: 1; margin-top: 0.25rem; }

  @media (max-width: 39.99rem) {
    .timeline { padding-left: 1.25rem; }
    .tl-item::before { left: calc(-1.25rem - 1px - 0.42rem); }
  }
}
