:root {
  --surface: #f4efe5;
  --surface-alt: #e7dfd0;
  --ink: #202824;
  --muted: #62675e;
  --charcoal: #19221e;
  --accent: #8a3c27;
  --olive: #465f41;
  --border: #b5ad9d;
  --serif: Georgia, 'Times New Roman', serif;
  --sans: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.65;
  letter-spacing: 0;
}
@media (min-width: 720px) {
  body { font-size: 18px; }
}

h1, h2, h3 {
  font-family: var(--serif);
  letter-spacing: 0;
  color: var(--charcoal);
}
h1 { font-size: clamp(2rem, 4.2vw, 3.8rem); line-height: 1.06; margin: 0 0 24px; }
h2 { font-size: clamp(1.5rem, 2.3vw, 2.2rem); line-height: 1.2; margin: 48px 0 16px; }
h3 { font-size: 1.15rem; line-height: 1.35; margin: 32px 0 12px; }

p { margin: 0 0 16px; }

a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: #6f2f1f; }

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

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0);
  overflow: hidden;
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: 8px; top: -48px;
  background: var(--charcoal);
  color: var(--surface);
  padding: 10px 16px;
  border-radius: 4px;
  z-index: 10;
}
.skip-link:focus-visible { top: 8px; }

.preview-notice {
  background: var(--accent);
  color: var(--surface);
  font-family: var(--mono);
  font-size: 12px;
  text-align: center;
  padding: 4px 8px;
}

.site-header {
  background: var(--charcoal);
  border-bottom: 3px solid var(--accent);
}
.header-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  color: var(--surface);
  text-decoration: none;
  font-family: var(--serif);
  font-size: 1.05rem;
  padding: 6px 0;
}
.brand img { display: block; }
.brand-subtitle { color: var(--border); margin-left: 6px; font-size: 0.85em; }
.site-nav { display: flex; flex-wrap: wrap; gap: 4px; }
.site-nav a {
  color: var(--surface);
  text-decoration: none;
  padding: 10px 14px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  border-radius: 4px;
  font-size: 0.95rem;
}
.site-nav a:hover { background: #253029; }
.site-nav a[aria-current="page"] { background: var(--accent); }

main { padding: 24px 16px 64px; }
main.wide { max-width: 1180px; margin: 0 auto; }
main.prose { max-width: 72ch; margin: 0 auto; }
.breadcrumbs { display: flex; flex-wrap: wrap; gap: 6px 10px; margin-bottom: 20px; font-size: 0.85rem; color: var(--muted); }
.breadcrumbs a { min-height: 44px; display: inline-flex; align-items: center; }
.breadcrumbs > span { display: inline-flex; align-items: center; }
.task-entries { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 32px; margin: 32px 0; }
.task-entries article { border-top: 3px solid var(--olive); padding-top: 16px; }
.task-entries h2 { margin: 0 0 12px; font-size: 1.55rem; }
.task-entries h2 a { color: var(--charcoal); }
.text-action { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; font-weight: 600; }
.primary-action { display: inline-flex; align-items: center; gap: 12px; min-height: 44px; padding: 10px 18px; color: var(--surface); background: var(--accent); border-radius: 4px; font-weight: 600; text-decoration: none; }
.primary-action:hover { background: #6f2f1f; color: var(--surface); }
.home-context img { max-height: 360px; object-fit: cover; }
.home-note { max-width: 72ch; }
.updated { font-size: 0.85rem; color: var(--muted); }
.next-guide { padding-top: 24px; border-top: 1px solid var(--border); margin-top: 40px; max-width: 72ch; }
.process-flow, .save-timeline { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr; gap: 12px; align-items: center; padding: 24px 16px; background: var(--surface-alt); border: 1px solid var(--border); }
.flow-stage, .save-stage { display: flex; align-items: center; flex-direction: column; text-align: center; gap: 12px; }
.flow-stage > span:last-child, .save-stage > span { font-size: 0.85rem; line-height: 1.5; }
.objective-symbol { width: 84px; height: 84px; display: grid; place-items: center; font-family: var(--serif); font-size: 3.3rem; line-height: 1; color: var(--accent); border: 2px solid var(--accent); border-radius: 50%; }
.encounter-symbol { color: var(--accent); }
.confirmation-symbol { color: var(--olive); }
.flow-arrow { font-size: 2rem; color: var(--accent); }
.save-boundary { display: flex; flex-direction: column; align-items: center; text-align: center; font-size: 0.7rem; color: var(--accent); }
.save-boundary > span { font-size: 2.5rem; line-height: 1.2; }
.save-stage { padding: 16px 8px; background: var(--surface); border: 1px solid var(--border); }
.behaviour-matrix { display: grid; grid-template-columns: minmax(0, 0.7fr) repeat(2, minmax(0, 1fr)); border: 1px solid var(--border); background: var(--surface-alt); }
.behaviour-matrix > div { padding: 16px 12px; border-bottom: 1px solid var(--border); }
.matrix-heading, .matrix-corner { font-weight: 600; text-align: center; }
.matrix-label { display: flex; flex-direction: column; justify-content: center; gap: 8px; }
.matrix-label span { font-size: 0.8rem; color: var(--muted); }
.behaviour-cell { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; background: var(--surface); }
.behaviour-cell > span { font-size: 0.8rem; line-height: 1.5; }
.behaviour-symbol { max-width: 100%; }
.motion-player { fill: var(--charcoal); }
.motion-orbit { fill: none; stroke: var(--accent); stroke-width: 3; }
.motion-orbit--fast { stroke-width: 6; }
.motion-head { fill: var(--accent); }
.motion-travel { fill: none; stroke: var(--olive); stroke-width: 3; }
.relation-flow { display: flex; align-items: stretch; gap: 12px; background: var(--surface-alt); border: 1px solid var(--border); padding: 20px 16px; }
.relation-node { flex: 1 1 0; display: flex; flex-direction: column; gap: 10px; padding: 16px 12px; border: 1px solid var(--border); background: var(--surface); text-align: center; }
.relation-node > span { font-size: 0.85rem; line-height: 1.5; }
.relation-flow > .flow-arrow { align-self: center; }
.scope-note { color: var(--muted); font-size: 0.9rem; }
.universe-groups { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-top: 3px solid var(--olive); gap: 32px; padding: 16px 0; }
.universe-groups h2 { margin-top: 0; }
.universe-groups h3 { font-family: var(--sans); font-size: 0.9rem; color: var(--muted); }
.universe-groups li { margin-bottom: 8px; }
.sweep-diagram { display: flex; flex-direction: column; align-items: center; padding: 24px 16px; border: 1px solid var(--border); background: var(--surface-alt); font-size: 0.85rem; text-align: center; }
.sweep-diagram svg { width: 100%; max-width: 360px; height: auto; }
.identity-branches { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; padding: 20px; border: 1px solid var(--border); background: var(--surface-alt); }
.identity-branches > div { display: flex; flex-direction: column; gap: 10px; border-top: 3px solid var(--olive); padding-top: 16px; }
.identity-branches span { font-size: 0.85rem; line-height: 1.5; }
.effect-map { border: 1px solid var(--border); background: var(--surface-alt); }
.effect-row { display: grid; grid-template-columns: minmax(0, 0.7fr) repeat(2, minmax(0, 1fr)); gap: 12px; align-items: center; padding: 16px 12px; border-bottom: 1px solid var(--border); }
.effect-row:last-child { border-bottom: 0; }
.effect-row > div { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; font-size: 0.8rem; }
.effect-symbol { color: var(--accent); font-size: 2.2rem; font-weight: 700; line-height: 1; }
.response-lanes { border: 1px solid var(--border); padding: 16px; background: var(--surface-alt); }
.response-lanes > div { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1.5fr); gap: 16px; align-items: center; padding: 16px 0; border-bottom: 1px solid var(--border); }
.response-lanes > div:last-child { border-bottom: 0; }
.response-lanes > div > span:nth-child(2) { font-size: 2rem; color: var(--accent); }
.response-lanes > div > span:last-child { font-size: 0.9rem; }
.access-groups { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; border-top: 3px solid var(--olive); }
.access-groups h2 { font-size: 1.4rem; margin: 16px 0; }
.access-groups ul { padding-left: 24px; }
.access-groups li { margin-bottom: 10px; }
.goal-navigation { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 32px; }
.goal-navigation > a { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1.2fr); gap: 16px; align-items: center; border-bottom: 1px solid var(--border); padding: 16px 0; min-height: 44px; text-decoration: none; }
.goal-navigation > a > span:first-child { color: var(--ink); font-size: 0.9rem; }
.goal-navigation > a > span:nth-child(2) { font-size: 1.6rem; }
.goal-navigation > a > strong { font-size: 0.9rem; text-decoration: underline; }
.branching-cause { padding: 24px 16px; background: var(--surface-alt); border: 1px solid var(--border); }
.branch-source { display: flex; flex-direction: column; gap: 8px; text-align: center; max-width: 320px; margin: 0 auto; padding: 16px; background: var(--surface); border: 1px solid var(--border); }
.branch-source > span { font-size: 0.85rem; }
.branching-cause > svg { display: block; width: 100%; height: auto; max-width: 320px; margin: 0 auto; }
.branch-targets { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; max-width: 640px; margin: 0 auto; }
.branch-targets > div { display: flex; flex-direction: column; gap: 10px; text-align: center; padding: 16px 10px; border: 1px solid var(--accent); background: var(--surface); }
.branch-targets > div > span { font-size: 0.85rem; line-height: 1.5; }
.footer-inner nav { display: flex; flex-wrap: wrap; gap: 8px 24px; margin-bottom: 12px; }
.footer-inner nav a { min-height: 44px; display: inline-flex; align-items: center; }
@media (max-width: 719px) {
  .task-entries { grid-template-columns: 1fr; gap: 24px; }
  .header-inner { align-items: flex-start; }
  .site-nav { width: 100%; padding-bottom: 6px; }
  .site-nav a { padding: 8px 10px; }
  .process-flow, .save-timeline { grid-template-columns: 1fr; gap: 16px; padding: 24px 16px; }
  .flow-arrow { justify-self: center; transform: rotate(90deg); line-height: 1; }
  .save-boundary > span { transform: rotate(90deg); margin: 4px 0 12px; }
  .save-boundary { font-size: 0.85rem; }
  .save-stage { width: 100%; }
  .behaviour-matrix { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .matrix-corner { display: none; }
  .matrix-label { grid-column: 1 / -1; background: var(--charcoal); color: var(--surface); padding: 12px !important; }
  .matrix-label span { color: var(--border); }
  .matrix-heading { font-size: 0.9rem; }
  .relation-flow { flex-direction: column; }
  .relation-flow > .flow-arrow { align-self: center; }
  .universe-groups { grid-template-columns: 1fr; }
  .access-groups, .goal-navigation { grid-template-columns: 1fr; }
  .effect-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .effect-row > strong { grid-column: 1 / -1; }
  .response-lanes > div { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1.1fr); gap: 12px; }
}

.lede p { font-size: 1.06em; max-width: 72ch; }

/* Lookup controls */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
  margin: 0 0 12px;
}
.control-search { display: flex; flex-direction: column; gap: 4px; flex: 1 1 260px; }
.control-search label { font-size: 0.85rem; color: var(--muted); }
.control-search input {
  font: inherit;
  padding: 10px 12px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  width: 100%;
}
.control-filter { display: flex; }
.filter-button {
  font: inherit;
  font-size: 0.9rem;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-left-width: 0;
  background: var(--surface-alt);
  color: var(--ink);
  cursor: pointer;
}
.filter-button:first-child { border-left-width: 1px; border-radius: 4px 0 0 4px; }
.filter-button:last-child { border-radius: 0 4px 4px 0; }
.filter-button[aria-pressed="true"] {
  background: var(--charcoal);
  color: var(--surface);
  border-color: var(--charcoal);
}
.clear-button {
  font: inherit;
  font-size: 0.9rem;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.clear-button:hover { color: var(--ink); border-color: var(--muted); }

.result-count { color: var(--muted); font-size: 0.9rem; margin: 0 0 8px; }

/* Recipe table */
.table-wrap { border: 1px solid var(--border); border-radius: 2px; background: #fff; }
.recipe-table { width: 100%; border-collapse: collapse; }
.recipe-table th, .recipe-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.recipe-table thead th {
  font-family: var(--mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface-alt);
}
.recipe-table tbody tr:last-child th, .recipe-table tbody tr:last-child td { border-bottom: 0; }
.recipe-table tbody tr:hover { background: var(--surface); }
.result-cell { font-weight: 600; }

.tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 2px;
  color: var(--surface);
}
.tag-aos { background: var(--olive); }
.tag-wh40k { background: var(--accent); }

.diagram-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 0.85rem;
  min-height: 44px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}
.diagram-button:hover { border-color: var(--accent); color: var(--accent); }
tr.is-selected .diagram-button { border-color: var(--accent); color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

.no-results {
  border: 1px dashed var(--border);
  border-radius: 2px;
  padding: 16px;
  color: var(--muted);
  background: var(--surface-alt);
}
.table-note { color: var(--muted); font-size: 0.9rem; margin-top: 12px; max-width: 72ch; }

/* Diagrams */
.diagram { margin: 40px 0; }
.diagram figcaption { max-width: 72ch; margin-bottom: 12px; }
.diagram-canvas {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 16px;
  overflow-x: auto;
}
.diagram-canvas svg { display: block; width: 100%; height: auto; max-width: 680px; margin: 0 auto; }
/* Variant switching must beat the generic svg display rule above. */
.diagram-canvas svg.variant-narrow { display: none; }
@media (max-width: 719px) {
  .diagram-canvas svg.variant-wide { display: none; }
  .diagram-canvas svg.variant-narrow { display: block; max-width: 380px; }
}
.diagram-box { fill: var(--surface); stroke: var(--border); stroke-width: 1.5; }
.diagram-box--result { fill: #fff; stroke: var(--accent); stroke-width: 2; }
.diagram-arrow { fill: none; stroke: var(--accent); stroke-width: 2; }
.diagram-head { fill: var(--accent); }
.diagram-text { font-family: var(--sans); font-size: 14px; fill: var(--ink); }
.diagram-text--result { font-weight: 700; }
.diagram-label { font-family: var(--mono); font-size: 11px; text-transform: uppercase; fill: var(--muted); }
.diagram-note { font-family: var(--mono); font-size: 11px; fill: var(--muted); }
/* Narrow (mobile) variants render near 1:1 at 320px, so text must stay readable. */
.variant-narrow .diagram-text { font-size: 16px; }
.variant-narrow .diagram-text--branch { font-size: 14px; }
.variant-narrow .diagram-label, .variant-narrow .diagram-note { font-size: 12px; }

/* Version differences */
.diff-list { padding-left: 24px; }
.diff-list li { margin-bottom: 8px; }
.diff-old { color: var(--muted); text-decoration: line-through; }
.diff-new { color: var(--olive); font-weight: 600; }

/* Context image */
.context-figure { margin: 40px 0; }
.context-figure img {
  width: 100%;
  height: auto;
  display: block;
  border: 1px solid var(--border);
  border-radius: 2px;
}
.context-figure figcaption { color: var(--muted); font-size: 0.85rem; margin-top: 8px; max-width: 72ch; }

/* Sources */
.sources ul { padding-left: 24px; }
.sources li { margin-bottom: 8px; font-size: 0.95rem; }

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface-alt);
}
.footer-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 16px;
  color: var(--muted);
  font-size: 0.85rem;
}

/* Mobile: recipe table becomes stacked cards */
@media (max-width: 719px) {
  .recipe-table thead { display: none; }
  .recipe-table, .recipe-table tbody { display: block; }
  .recipe-table tr {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2px 12px;
    padding: 12px;
    border-bottom: 1px solid var(--border);
  }
  .recipe-table tbody tr:last-child { border-bottom: 0; }
  .recipe-table th, .recipe-table td { display: block; border: 0; padding: 0; }
  .recipe-table th { font-family: var(--serif); font-size: 1.05rem; grid-column: 1 / -1; }
  .recipe-table td::before {
    content: attr(data-label) ": ";
    font-family: var(--mono);
    font-size: 0.72rem;
    text-transform: uppercase;
    color: var(--muted);
  }
  .recipe-table .diagram-cell { grid-column: 1 / -1; margin-top: 8px; }
  .recipe-table .diagram-cell::before { content: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
