/*
 * One class per row of the spec.md §10 component inventory.
 * (`.shell`, `.prose`, `pre`, `code` and `kbd` are element/layout defaults and
 * live in base.css; every other inventory row is here.)
 *
 * Every colour MUST be a var(--…) from tokens.css — enforced by
 * test/unit/tokens.test.js. Flat surfaces only: one hairline border, radii of
 * 4/8/12px, and at most --shadow-hover. No gradients. --radius-pill is used
 * only on tag pills, never on a container.
 *
 * Breakpoints: 48rem and 64rem only. Motion is behind
 * @media (prefers-reduced-motion: no-preference).
 */

/* ---- Icons ------------------------------------------------------------- */

/* Every glyph from templates/partials/icons.ejs. Uniform 1.75 stroke, sized in
   `em` so an icon always matches the type size of its context. */
.icon {
  display: inline-block;
  width: 1em;
  height: 1em;
  flex: none;
  color: currentColor;
  vertical-align: -0.125em;
}

/* ---- Site header and nav (§10 row 3) ----------------------------------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  /* The single blur the skill permits, and only here. */
  background: color-mix(in srgb, var(--color-canvas) 85%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: var(--border-hairline);
}

.site-header > .shell {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3) var(--space-6);
  padding-block: var(--space-4);
}

.site-header__title {
  font-family: var(--font-serif);
  font-size: var(--text-xl);
  font-weight: var(--weight-normal);
  letter-spacing: var(--tracking-tight);
  color: var(--color-text-strong);
  text-decoration: none;
}

.site-nav {
  display: flex;
  align-items: baseline;
  gap: var(--space-4);
  font-size: var(--text-sm);
}

.site-nav a {
  color: var(--color-text-muted);
  text-decoration: none;
}

.site-nav a:hover,
.site-nav a[aria-current='page'] {
  color: var(--color-text-strong);
}

/* ---- Footer (§10 row 4) ------------------------------------------------ */

.site-footer {
  margin-block-start: var(--space-24);
  border-top: var(--border-hairline);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.site-footer > .shell {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding-block: var(--space-12);
}

.site-footer a {
  color: var(--color-text-muted);
}

.site-footer a:hover {
  color: var(--color-text-strong);
}

.site-footer__links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-5);
  margin: 0;
  padding: 0;
  list-style: none;
}

@media (min-width: 48rem) {
  .site-footer > .shell {
    flex-direction: row;
    align-items: baseline;
    justify-content: space-between;
  }
}

/* ---- Homepage hero (§10 row 5) ----------------------------------------- */

.hero {
  padding-block: var(--space-24) var(--space-16);
}

.hero h1 {
  font-family: var(--font-serif);
  font-size: var(--text-4xl);
  font-weight: var(--weight-normal);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
}

.hero__description {
  max-width: var(--width-prose);
  margin-block-start: var(--space-5);
  font-size: var(--text-lg);
  color: var(--color-text-muted);
}

/* ---- Section header (§10 row 6) ---------------------------------------- */

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
  margin-block: var(--space-16) var(--space-6);
  padding-bottom: var(--space-2);
  border-bottom: var(--border-hairline);
}

.section-head h2 {
  font-size: var(--text-2xl);
}

.section-head__action {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-decoration: none;
}

.section-head__action:hover {
  color: var(--color-text-strong);
}

/* ---- Homepage random block (§10 row 7) --------------------------------- */

/* The random block is a shared `.note-list` with the script hooks on its `<ul>`
   (see partials/note-list.ejs); `.random-block` exists as a hook class only and
   carries no styling of its own, so the list rows stay identical to the recent
   list's. */

/* Icon-only control (the homepage shuffle button). Its accessible name comes
   from a .visually-hidden span, never from an emoji or a bare glyph. */
.btn-icon {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  border: var(--border-hairline);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.btn-icon:hover {
  color: var(--color-text-strong);
}

.btn-icon:active {
  transform: scale(0.98);
}

/* ---- Shared note list (§10 row 8, partial note-list.ejs) --------------- */

.note-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.note-list > li {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--space-2);
  padding-block: var(--space-3);
  border-bottom: var(--border-hairline);
}

.note-list__content {
  min-width: 0;
  flex: 1 1 auto;
  overflow-wrap: anywhere;
}

.note-list__title {
  color: var(--color-text-strong);
  line-height: var(--leading-snug);
  text-decoration: none;
}

.note-list__title:hover {
  text-decoration-line: underline;
}

.note-list__dates {
  display: flex;
  flex-wrap: nowrap;
  align-items: baseline;
  gap: var(--space-4);
  width: 100%;
}

.note-list__date-item {
  display: inline-flex;
  align-items: baseline;
  gap: var(--space-2);
  white-space: nowrap;
}

.note-list__date-label {
  color: var(--color-text);
  font-size: var(--text-2xs);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

.note-list__date {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}

.note-list__date-item--updated .note-list__date-label,
.note-list__date--updated {
  color: var(--color-text-strong);
  font-weight: var(--weight-medium);
}

@media (min-width: 48rem) {
  .note-list > li {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
  }

  .note-list__dates {
    display: grid;
    width: auto;
    min-width: max-content;
    flex: none;
    justify-items: end;
    gap: var(--space-1);
  }

  .note-list__date-item {
    justify-content: flex-end;
  }
}

/* The row's clickable tag pills wrap beneath the title. */
.note-list__tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-block-start: var(--space-2);
}

/* ---- Note page (§10 row 9) --------------------------------------------- */

.note {
  padding-block: var(--space-12) var(--space-16);
}

.note > * + * {
  margin-block-start: var(--space-6);
}

.note h1 {
  font-family: var(--font-serif);
  font-size: var(--text-3xl);
}

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1);
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.breadcrumb a {
  color: var(--color-text-muted);
  text-decoration: none;
}

.breadcrumb a:hover {
  color: var(--color-text-strong);
}

.breadcrumb .icon {
  color: var(--color-border-strong);
}

.note-meta {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.note-meta time {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* No background box, per the skill's flat-surface rule: a single rule marks
   the contents list. */
.toc {
  padding-inline-start: var(--space-4);
  border-inline-start: 2px solid var(--color-border);
  font-size: var(--text-sm);
}

.toc > summary {
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  font-size: var(--text-2xs);
  color: var(--color-text-muted);
}

.toc ol {
  margin-block-start: var(--space-2);
  padding-inline-start: var(--space-4);
  list-style: none;
}

.toc li {
  padding-block: var(--space-1);
}

.toc a {
  color: var(--color-text-muted);
  text-decoration: none;
}

.toc a:hover {
  color: var(--color-text-strong);
}

.note-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: 0;
  padding-block-start: var(--space-6);
  padding-inline: 0;
  border-top: var(--border-hairline);
  list-style: none;
}

/* Links / Backlinks accordions. Stripped of container boxes: hairlines only,
   with +/- glyphs (skill §5). */
.note-links {
  display: grid;
  gap: 0;
  border-top: var(--border-hairline);
}

.note-links > details {
  padding-block: var(--space-4);
  border-bottom: var(--border-hairline);
}

.note-links > details > summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  font-size: var(--text-2xs);
  color: var(--color-text-muted);
  list-style: none;
}

.note-links > details > summary::-webkit-details-marker {
  display: none;
}

/* The template emits both glyphs; CSS decides which one is visible, so the
   toggle state needs no JavaScript. */
.note-links > details > summary .icon-minus,
.note-links > details[open] > summary .icon-plus {
  display: none;
}

.note-links > details[open] > summary .icon-minus {
  display: inline-block;
}

.note-links ul {
  margin-block-start: var(--space-3);
  padding: 0;
  list-style: none;
  font-size: var(--text-sm);
}

.note-links li + li {
  margin-block-start: var(--space-2);
}

@media (min-width: 48rem) {
  .note-links {
    grid-template-columns: 1fr 1fr;
    column-gap: var(--space-8);
  }
}

/* ---- Callouts (§10 row 10) --------------------------------------------- */

.callout {
  padding: var(--space-4) var(--space-5);
  border: var(--border-hairline);
  border-radius: var(--radius-md);
  background: var(--color-surface-subtle);
  border-inline-start: 3px solid var(--color-border-strong);
}

.callout__title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-snug);
}

/* Foldable callouts render as <details>; the title row is the <summary>. */
.callout > summary.callout__title {
  cursor: pointer;
  list-style: none;
}

.callout > summary.callout__title::-webkit-details-marker {
  display: none;
}

.callout__body {
  margin-block-start: var(--space-3);
  font-size: var(--text-sm);
}

.callout__body > * + * {
  margin-block-start: var(--space-3);
}

/*
 * 13 Obsidian callout types mapped onto the 4 pastels (spec.md §10 table).
 * Aliases are listed alongside their canonical type so a template may pass the
 * author's raw spelling straight through. Unknown types fall back to `note`
 * styling via the .callout base plus .callout--note (assumption 20).
 */

/* blue: note, info, abstract/summary/tldr, todo, question/help/faq */
.callout--note,
.callout--info,
.callout--abstract,
.callout--summary,
.callout--tldr,
.callout--todo,
.callout--question,
.callout--help,
.callout--faq {
  background: var(--accent-blue-bg);
  border-inline-start-color: var(--accent-blue-fg);
}

.callout--note .callout__title,
.callout--info .callout__title,
.callout--abstract .callout__title,
.callout--summary .callout__title,
.callout--tldr .callout__title,
.callout--todo .callout__title,
.callout--question .callout__title,
.callout--help .callout__title,
.callout--faq .callout__title {
  color: var(--accent-blue-fg);
}

/* green: success/check/done, tip/hint/important */
.callout--success,
.callout--check,
.callout--done,
.callout--tip,
.callout--hint,
.callout--important {
  background: var(--accent-green-bg);
  border-inline-start-color: var(--accent-green-fg);
}

.callout--success .callout__title,
.callout--check .callout__title,
.callout--done .callout__title,
.callout--tip .callout__title,
.callout--hint .callout__title,
.callout--important .callout__title {
  color: var(--accent-green-fg);
}

/* yellow: warning/caution/attention, example */
.callout--warning,
.callout--caution,
.callout--attention,
.callout--example {
  background: var(--accent-yellow-bg);
  border-inline-start-color: var(--accent-yellow-fg);
}

.callout--warning .callout__title,
.callout--caution .callout__title,
.callout--attention .callout__title,
.callout--example .callout__title {
  color: var(--accent-yellow-fg);
}

/* red: danger/error, failure/fail/missing, bug */
.callout--danger,
.callout--error,
.callout--failure,
.callout--fail,
.callout--missing,
.callout--bug {
  background: var(--accent-red-bg);
  border-inline-start-color: var(--accent-red-fg);
}

.callout--danger .callout__title,
.callout--error .callout__title,
.callout--failure .callout__title,
.callout--fail .callout__title,
.callout--missing .callout__title,
.callout--bug .callout__title {
  color: var(--accent-red-fg);
}

/* neutral: quote/cite — no accent, subtle surface only */
.callout--quote,
.callout--cite {
  background: var(--color-surface-subtle);
  border-inline-start-color: var(--color-border-strong);
}

.callout--quote .callout__title,
.callout--cite .callout__title {
  color: var(--color-text-muted);
}

.callout--quote .callout__body,
.callout--cite .callout__body {
  font-family: var(--font-serif);
  font-size: var(--text-lg);
}

/* ---- Code blocks (§10 row 11) ------------------------------------------ */

/* Shiki emits its own inline colours on the spans it generates. It also writes
   a background onto .shiki itself; that is overridden here so highlighted code
   keeps the site's warm surface rather than the theme's. */
.shiki {
  background: var(--color-surface-subtle);
}

.shiki code {
  display: block;
  background: none;
  color: inherit;
}

/* Client-rendered mermaid diagrams. Centred, no border while the script is
   still resolving so there is no empty box on the page. */
pre.mermaid {
  padding: var(--space-5);
  border: 0;
  background: none;
  text-align: center;
  overflow-x: auto;
}

/* ---- Tag pill (§10 row 12, partial tag-pills.ejs) --------------------- */

.tag-pill {
  display: inline-block;
  overflow-wrap: anywhere;
  padding: 2px var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--accent-blue-bg);
  color: var(--accent-blue-fg);
  font-size: var(--text-2xs);
  line-height: var(--leading-snug);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  text-decoration: none;
}

.tag-pill:hover {
  color: var(--color-text-strong);
}

/* ---- Tag index (§10 row 13) ------------------------------------------- */

.tag-index {
  max-width: var(--width-prose);
  margin-block-start: var(--space-8);
  padding: 0;
  border-top: var(--border-hairline);
  list-style: none;
}

.tag-index > li {
  border-bottom: var(--border-hairline);
}

.tag-index__link {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-2);
  color: var(--color-text-strong);
  text-decoration: none;
}

.tag-index__link:hover .tag-index__name {
  text-decoration-color: currentColor;
}

.tag-index__name {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: var(--weight-medium);
  text-decoration-line: underline;
  text-decoration-color: var(--color-border-strong);
  text-underline-offset: 0.2em;
}

.tag-index__count {
  flex: none;
  color: var(--color-text-muted);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---- Tag page (§10 row 14) -------------------------------------------- */

.tag-page {
  padding-block: var(--space-12) var(--space-16);
}

.tag-page h1 {
  font-family: var(--font-mono);
  font-size: var(--text-2xl);
  letter-spacing: normal;
}

.tag-page__count {
  margin-block-start: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.tag-page__children {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  padding-block: var(--space-6);
  list-style: none;
}

/* ---- Recent, infinite scroll (§10 row 15) ----------------------------- */

.recent-page {
  padding-block: var(--space-12) var(--space-16);
}

/* IntersectionObserver target. Zero-height and inert; it must never be the
   thing a keyboard user lands on. */
#sentinel {
  height: 1px;
}

.load-status {
  padding-block: var(--space-6);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-align: center;
}

.recent-page noscript {
  display: block;
  padding-block: var(--space-6);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* ---- Search (§10 row 16) ---------------------------------------------- */

.search-page {
  padding-block: var(--space-12) var(--space-16);
}

/*
 * Pagefind ships its own visual language: `pagefind-ui.css` declares these
 * properties on `:root`. Re-declaring them on our own wrapper re-points them at
 * our tokens for everything inside it — a custom property declared closer to the
 * element wins over an inherited one, so this does not depend on stylesheet order
 * or on which class name Pagefind's widget container happens to carry. These are
 * declarations of Pagefind's variables, not new design tokens; the widget is
 * styled entirely through them and none of its own selectors is overridden.
 */
.search-page,
.pagefind-ui {
  --pagefind-ui-primary: var(--color-text-strong);
  --pagefind-ui-text: var(--color-text);
  --pagefind-ui-background: var(--color-canvas);
  --pagefind-ui-border: var(--color-border);
  --pagefind-ui-tag: var(--color-surface-subtle);
  --pagefind-ui-border-width: 1px;
  --pagefind-ui-border-radius: var(--radius-sm);
  --pagefind-ui-image-border-radius: var(--radius-md);
  --pagefind-ui-font: var(--font-sans);
  --pagefind-ui-scale: 0.9;
}

.pagefind-ui {
  margin-block-start: var(--space-6);
}

/* Search is the one page with nothing to server-render: the query does not exist
   until the reader types it. The fallback routes are therefore not a nicety. */
.search-page noscript {
  display: block;
  padding-block: var(--space-6);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* ---- 404 (§10 row 17) ------------------------------------------------- */

.error-page {
  padding-block: var(--space-24);
}

.error-page h1 {
  font-family: var(--font-serif);
  font-size: var(--text-4xl);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
}

.error-page p {
  max-width: var(--width-prose);
  margin-block-start: var(--space-4);
  font-size: var(--text-lg);
  color: var(--color-text-muted);
}

.error-page ul {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-5);
  margin-block-start: var(--space-8);
  padding: 0;
  list-style: none;
  font-size: var(--text-sm);
}

/* ---- Embed card (§10 row 18) ------------------------------------------ */

.embed-card {
  margin: 0;
  padding: var(--space-5);
  border: var(--border-hairline);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

/* Caption comes first: the reader needs to know whose content is being quoted
   before reading it. */
.embed-card > figcaption {
  margin: 0;
  margin-block-end: var(--space-3);
  padding-block-end: var(--space-3);
  border-bottom: var(--border-hairline);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
}

.embed-card > figcaption a {
  color: var(--color-text-strong);
  text-decoration: none;
}

/* ---- Unresolved link, missing embed (§10 row 19) ---------------------- */

/* Deliberately visible. A broken link is information, not something to hide. */
.link-unresolved,
.embed-missing {
  color: var(--color-text-muted);
  border-bottom: 1px dashed var(--color-border-strong);
  cursor: help;
}

.embed-missing {
  display: block;
  padding: var(--space-4);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
}

/* ---- Attachment link (§10 row 20) ------------------------------------- */

.attachment-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: var(--border-hairline);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text-strong);
  font-size: var(--text-sm);
  text-decoration: none;
}

.attachment-link:hover {
  box-shadow: var(--shadow-hover);
}

.attachment-link__ext {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-transform: uppercase;
}

/* ---- Motion ----------------------------------------------------------- */

@media (prefers-reduced-motion: no-preference) {
  .attachment-link {
    transition: box-shadow var(--dur-fast) var(--ease-out);
  }

  .btn-icon {
    transition:
      color var(--dur-fast) var(--ease-out),
      transform var(--dur-fast) var(--ease-out);
  }

  /* Staggered list entry. --index is set per item by the template that renders
     the batch; the 0 fallback keeps the list visible if it is ever omitted.

     A transition-delay, not an animation-delay: the reveal itself is the
     `[data-reveal]` opacity/transform transition in base.css, and an
     `animation-delay` with no `animation-name` — which is what this rule used to
     declare — delays nothing at all. Inside the reduced-motion guard, so a reader
     who asked for no motion gets no delay either. */
  .note-list > li[data-reveal] {
    transition-delay: calc(var(--index, 0) * var(--stagger-step));
  }
}
