/* Hallmark · genre: editorial · macrostructure: Map / Diagram (How it works) + Q/A transcript tool (Ask) · theme: Almanac · enrichment: none (typography only) · nav: N1a · footer: Ft2
 * tone: calm, utilitarian · anchor hue: 85 (oat paper) · accent: green 165
 */

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html, body { overflow-x: clip; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* Keep scrolled-to content clear of the sticky composer (height set by app.js). */
  scroll-padding-block: var(--space-md) calc(var(--composer-height, 0px) + var(--space-md));
}

body {
  margin: 0;
  background: var(--color-paper);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  font-kerning: normal;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

main { flex: 1; }

h1, h2, h3, p, ol, ul { margin: 0; }
ol, ul { padding: 0; list-style: none; }

a { color: var(--color-accent); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { color: var(--color-accent-hover); text-decoration-thickness: 2px; }

:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.nowrap { white-space: nowrap; }

.skip {
  position: absolute;
  left: var(--space-md);
  top: -3rem;
  padding: var(--space-xs) var(--space-md);
  background: var(--color-ink);
  color: var(--color-paper);
  z-index: var(--z-sticky);
}
.skip:focus-visible { top: var(--space-md); }

/* Page gutters shared by header, views and footer. */
.masthead,
.view,
.foot-line {
  width: 100%;
  max-width: 72rem;
  margin-inline: auto;
  padding-inline: max(var(--space-md), env(safe-area-inset-left)) max(var(--space-md), env(safe-area-inset-right));
}

@media (min-width: 40rem) {
  .masthead, .view, .foot-line { padding-inline: var(--space-xl); }
}

.display {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-display);
  line-height: var(--leading-display);
  letter-spacing: -0.02em;
  font-variation-settings: "opsz" 72;
  overflow-wrap: anywhere;
  min-width: 0;
  max-width: 18ch;
}

.lede {
  margin-top: var(--space-md);
  max-width: 52ch;
  color: var(--color-muted);
  font-size: var(--text-md);
  line-height: 1.5;
}

/* ---------- Masthead (N1a: wordmark + two destinations) ---------- */

.masthead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-md);
  padding-block: var(--space-lg) var(--space-md);
  border-bottom: var(--rule-hair);
}

.wordmark {
  font-family: var(--font-outlier);
  font-weight: 500;
  font-size: var(--text-sm);
  letter-spacing: 0.02em;
  color: var(--color-ink);
  text-decoration: none;
  white-space: nowrap;
}
.wordmark:hover { color: var(--color-ink); }

.tabs {
  display: flex;
  gap: var(--space-lg);
}

.tabs__link {
  display: inline-block;
  padding-block: var(--space-xs);
  color: var(--color-muted);
  text-decoration: none;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: color var(--dur-micro) var(--ease-out), border-color var(--dur-micro) var(--ease-out);
}
.tabs__link:hover { color: var(--color-ink); }
.tabs__link[aria-current="page"] {
  color: var(--color-ink);
  font-weight: 600;
  border-bottom-color: var(--color-accent);
}

/* ---------- Ask ---------- */

.ask {
  display: grid;
  gap: var(--space-2xl);
  padding-block: var(--space-xl) var(--space-2xl);
}

@media (min-width: 60rem) {
  .ask {
    grid-template-columns: minmax(0, 1fr) 16rem;
    gap: var(--space-3xl);
    padding-top: var(--space-2xl);
  }
}

.ask__main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 44rem;
}

/* Transcript: questions set as headings, answers as prose. No bubbles. */

.thread { margin-top: var(--space-xl); }
.thread:empty { display: none; }

.entry {
  padding-block: var(--space-lg);
  border-top: var(--rule-hair);
  animation: entry-in var(--dur-long) var(--ease-out) both;
}

@keyframes entry-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.entry__q {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-md);
  line-height: 1.3;
  font-variation-settings: "opsz" 24;
  overflow-wrap: anywhere;
  white-space: pre-line;
}

.entry__a {
  margin-top: var(--space-sm);
  max-width: 65ch;
}
.entry__a > p + p { margin-top: var(--space-sm); }

.answer p { white-space: pre-line; overflow-wrap: anywhere; }

.source {
  margin-top: var(--space-md);
  padding-top: var(--space-sm);
  border-top: 1px dashed var(--color-rule);
  display: grid;
  gap: var(--space-2xs);
  font-size: var(--text-sm);
}
.source__label {
  color: var(--color-neutral);
  font-weight: 600;
}
.source__link { overflow-wrap: anywhere; }
.source__host {
  color: var(--color-neutral);
  font-size: var(--text-xs);
}

.pending {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  color: var(--color-muted);
  font-size: var(--text-sm);
  min-height: 1.6em;
}
.pending[data-visible="false"] { visibility: hidden; }

.spinner {
  flex: none;
  width: 0.9rem;
  height: 0.9rem;
  border: 2px solid var(--color-rule);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

@keyframes spin { to { transform: rotate(1turn); } }

.problem {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--space-2xs) var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--color-error-wash);
  border: 1px solid var(--color-error);
  border-radius: var(--radius-md);
  color: var(--color-ink);
  font-size: var(--text-sm);
}
.problem__glyph {
  grid-row: span 2;
  color: var(--color-error);
  font-weight: 600;
  line-height: var(--leading-body);
}
.problem__retry {
  justify-self: start;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-weight: 600;
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 0.18em;
  cursor: pointer;
  white-space: nowrap;
}
.problem__retry:hover { color: var(--color-accent-hover); text-decoration-thickness: 2px; }

/* Starters: shown until the first question. */

.starters { margin-top: var(--space-xl); }
.starters[hidden] { display: none; }

.starters__label {
  color: var(--color-neutral);
  font-size: var(--text-sm);
}

.starters__list {
  margin-top: var(--space-xs);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
}

.starter {
  min-height: var(--control-height);
  padding: var(--space-xs) var(--space-md);
  border: var(--rule-strong);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-ink);
  font: inherit;
  font-size: var(--text-sm);
  text-align: left;
  cursor: pointer;
  transition: background-color var(--dur-micro) var(--ease-out), border-color var(--dur-micro) var(--ease-out);
}
.starter:hover { background: var(--color-paper-2); border-color: var(--color-ink); }
.starter:active { background: var(--color-paper-3); }
.starter:disabled { opacity: 0.5; cursor: not-allowed; }

/* Composer: sticks to the bottom of the viewport once the transcript is long. */

.composer {
  position: sticky;
  bottom: 0;
  z-index: var(--z-raised);
  margin-top: var(--space-xl);
  padding-block: var(--space-md) max(var(--space-md), env(safe-area-inset-bottom));
  background: var(--color-paper);
  border-top: var(--rule-hair);
}

.composer__label {
  display: block;
  margin-bottom: var(--space-xs);
  font-weight: 600;
  font-size: var(--text-sm);
}

.composer__row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-xs);
}

.composer__input {
  flex: 1;
  min-width: 0;
  min-height: var(--control-height);
  max-height: 12rem;
  padding: calc((var(--control-height) - 1.5em - 2px) / 2) var(--space-sm);
  border: var(--rule-strong);
  border-radius: var(--radius-md);
  background: var(--color-paper);
  color: var(--color-ink);
  font: inherit;
  line-height: 1.5;
  resize: vertical;
  transition: border-color var(--dur-micro) var(--ease-out), background-color var(--dur-micro) var(--ease-out);
}
.composer__input:hover { border-color: var(--color-ink); }
.composer__input:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 1px;
  border-color: var(--color-focus);
}
.composer__input[aria-invalid="true"] { border-color: var(--color-error); }
.composer__input:disabled { background: var(--color-paper-2); cursor: not-allowed; }

.composer__meta {
  display: flex;
  justify-content: space-between;
  gap: var(--space-md);
  margin-top: var(--space-2xs);
  min-height: 1lh;
  font-size: var(--text-xs);
  color: var(--color-neutral);
}
.composer__help[data-tone="error"] { color: var(--color-error); font-weight: 600; }
.composer__count {
  flex: none;
  font-variant-numeric: tabular-nums;
}
.composer__count[data-over="true"] { color: var(--color-error); font-weight: 600; }

@media (pointer: coarse) {
  .composer__help { visibility: hidden; }
}

/* Primary button: eight states. idle · hover · focus · active · disabled · loading · error · success(silent). */

.btn {
  position: relative;
  flex: none;
  display: inline-grid;
  place-items: center;
  min-width: 5.5rem;
  height: var(--control-height);
  padding-inline: var(--space-lg);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-md);
  background: var(--color-accent);
  color: var(--color-on-accent);
  font: inherit;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--dur-micro) var(--ease-out), transform var(--dur-micro) var(--ease-out);
}
.btn > * { grid-area: 1 / 1; }
.btn:hover { background: var(--color-accent-hover); border-color: var(--color-accent-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled {
  background: var(--color-paper-3);
  border-color: var(--color-rule);
  color: var(--color-neutral);
  cursor: not-allowed;
  transform: none;
}
.btn__spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--color-rule);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  opacity: 0;
}
.btn[data-state="loading"] { cursor: progress; }
.btn[data-state="loading"] .btn__label { opacity: 0; }
.btn[data-state="loading"] .btn__spinner {
  opacity: 1;
  animation: spin 800ms linear infinite;
}
.btn[data-state="error"]:not(:disabled) { background: var(--color-error); border-color: var(--color-error); }

/* Scope aside */

.scope {
  align-self: start;
  padding-top: var(--space-lg);
  border-top: var(--rule-strong);
  font-size: var(--text-sm);
}
@media (min-width: 60rem) {
  /* The list is long enough to exceed a short laptop viewport, and a sticky
     box taller than the viewport hides its own tail, so it scrolls inside. */
  .scope {
    position: sticky;
    top: var(--space-lg);
    max-height: calc(100dvh - 2 * var(--space-lg));
    overflow-y: auto;
  }
}

.scope__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-md);
  line-height: 1.3;
}

.scope__list {
  margin-top: var(--space-sm);
  display: grid;
  gap: var(--space-2xs);
}
.scope__list a { color: var(--color-ink); text-decoration-color: var(--color-rule-strong); }
.scope__list a:hover { color: var(--color-accent); text-decoration-color: currentColor; }

.scope__note {
  margin-top: var(--space-md);
  color: var(--color-muted);
}

/* ---------- How it works (Map / Diagram) ---------- */

.how { padding-block: var(--space-xl) var(--space-3xl); }
@media (min-width: 60rem) { .how { padding-top: var(--space-2xl); } }

/* The pipeline reads top-to-bottom on narrow screens and left-to-right on
   wide ones. The connecting line is one rule behind the nodes. */
.pipeline {
  position: relative;
  margin-top: var(--space-2xl);
  display: grid;
  gap: var(--space-lg);
  counter-reset: node;
}

.node {
  position: relative;
  padding-left: var(--space-xl);
  min-width: 0;
}
.node::before {
  content: "";
  position: absolute;
  left: 0.3rem;
  top: 0.45rem;
  width: 0.75rem;
  height: 0.75rem;
  border: 2px solid var(--color-accent);
  border-radius: 50%;
  background: var(--color-paper);
  z-index: var(--z-base);
}
.node:last-child::before { background: var(--color-accent); }
.node:not(:last-child)::after {
  content: "";
  position: absolute;
  left: calc(0.3rem + 0.375rem - 1px);
  top: 1.35rem;
  bottom: calc(-1 * var(--space-lg) + 0.25rem);
  border-left: 2px solid var(--color-rule);
}

.node__code {
  font-family: var(--font-outlier);
  font-size: var(--text-xs);
  color: var(--color-accent);
  white-space: nowrap;
}
.node__title {
  margin-top: var(--space-2xs);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-lg);
  line-height: 1.2;
}
.node p {
  margin-top: var(--space-xs);
  color: var(--color-muted);
  font-size: var(--text-sm);
  max-width: 34ch;
}

@media (min-width: 60rem) {
  .pipeline {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: var(--space-lg);
  }
  .node { padding-left: 0; padding-top: var(--space-xl); }
  .node::before { left: 0; top: 0; }
  .node:not(:last-child)::after {
    left: 1rem;
    right: calc(-1 * var(--space-lg));
    top: calc(0.375rem - 1px);
    bottom: auto;
    border-left: 0;
    border-top: 2px solid var(--color-rule);
  }
}

.notes {
  margin-top: var(--space-3xl);
  padding-top: var(--space-xl);
  border-top: var(--rule-hair);
  display: grid;
  gap: var(--space-xl);
}
@media (min-width: 60rem) {
  .notes { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: var(--space-2xl); }
}

.note__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-md);
  line-height: 1.3;
}
.note p { margin-top: var(--space-sm); max-width: 60ch; }
.link { font-weight: 600; white-space: nowrap; }

/* ---------- Footer (Ft2: inline single line) ---------- */

.foot-line {
  padding-block: var(--space-lg) max(var(--space-lg), env(safe-area-inset-bottom));
  border-top: var(--rule-hair);
  color: var(--color-neutral);
  font-size: var(--text-xs);
}
.foot-line p { max-width: 80ch; }

/* ---------- Views ---------- */

.view[hidden] { display: none; }

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 150ms !important;
    transition-duration: 150ms !important;
  }
  .entry { animation: entry-fade 150ms linear both; }
  @keyframes entry-fade { from { opacity: 0; } to { opacity: 1; } }
  .spinner, .btn[data-state="loading"] .btn__spinner {
    animation-duration: 1600ms !important;
    animation-iteration-count: infinite !important;
  }
}
