/*
 * Guide theme control plane.
 * Change the semantic tokens in :root to retheme every generated guide,
 * bundle, index, and custom tool shell at once.
 */
:root {
  --color-bg: oklch(23% 0.015 165);
  --color-surface: oklch(27% 0.014 160);
  --color-surface-raised: oklch(30% 0.014 160);
  --color-ink: oklch(93% 0.008 120);
  --color-muted: oklch(72% 0.012 140);
  --color-accent: oklch(84% 0.11 90);
  --color-info: oklch(80% 0.07 235);
  --color-danger: oklch(72% 0.13 25);
  --color-success: oklch(78% 0.1 155);
  --color-rule: oklch(93% 0.008 120 / 0.16);
  --color-rule-soft: oklch(93% 0.008 120 / 0.09);
  --color-wash: oklch(93% 0.008 120 / 0.06);
  --color-focus: var(--color-accent);

  --font-text: "STIX Two Text", "Times New Roman", serif;
  --font-code: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --text-small: 0.875rem;
  --text-body: 1.125rem;
  --text-lead: 1.25rem;
  --text-subhead: 1.375rem;
  --text-display: clamp(2.2rem, 7vw, 3.5rem);

  --space-2xs: 0.25rem;
  --space-xs: 0.5rem;
  --space-sm: 0.75rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4.5rem;
  --measure-index: 41rem;
  --measure-page: 54rem;
  --measure-prose: 70ch;
  --radius: 0.15rem;
  --transition: 150ms ease-out;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; color-scheme: dark; }
body {
  margin: 0;
  min-width: 20rem;
  background: var(--color-bg);
  color: var(--color-ink);
  font-family: var(--font-text);
  font-size: var(--text-body);
  line-height: 1.68;
  font-kerning: normal;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a, button, input, textarea, select { font: inherit; }
a {
  color: var(--color-accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  transition: color var(--transition), opacity var(--transition);
}
a:hover { opacity: 0.76; }
button { color: inherit; }
img, svg { max-width: 100%; }
::selection { color: var(--color-bg); background: var(--color-accent); }
:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 4px; }

.skip-link {
  position: fixed;
  z-index: 20;
  top: var(--space-md);
  left: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  color: var(--color-bg);
  background: var(--color-accent);
  transform: translateY(-200%);
}
.skip-link:focus { transform: none; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.page-shell {
  width: min(var(--measure-page), calc(100% - 2.5rem));
  margin: 0 auto;
}
.guide-index .page-shell { max-width: var(--measure-index); }
.site-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-md);
  padding: clamp(1.5rem, 4vw, 2.5rem) 0 0;
}
.wordmark {
  color: var(--color-ink);
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-decoration: none;
}
.site-header nav { display: flex; gap: clamp(0.7rem, 3vw, 1.25rem); font-size: 0.9375rem; }
.site-header nav a { min-height: 2.75rem; display: inline-flex; align-items: center; color: var(--color-muted); text-decoration: none; }
.site-header nav a[aria-current="page"] { color: var(--color-ink); }
.site-header nav a:hover { color: var(--color-accent); opacity: 1; }
.site-footer {
  display: flex;
  justify-content: space-between;
  gap: var(--space-md);
  flex-wrap: wrap;
  padding: var(--space-xl) 0 max(var(--space-2xl), env(safe-area-inset-bottom));
  border-top: 1px solid var(--color-rule);
  color: var(--color-muted);
  font-size: 0.9375rem;
}

.index-intro { padding: clamp(4rem, 12vh, 7rem) 0 clamp(3rem, 8vh, 4.5rem); }
.index-intro h1, .guide-hero h1 {
  margin: 0 0 var(--space-md);
  font-size: var(--text-display);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.08;
  text-wrap: balance;
}
.index-intro p, .guide-hero > p:not(.guide-meta) { max-width: 52ch; margin: 0; color: var(--color-muted); text-wrap: pretty; }
.experiment {
  margin-bottom: clamp(3rem, 9vh, 5rem);
  padding: 1.2rem 1.35rem 1.35rem;
  background: var(--color-wash);
  border-top: 1px solid var(--color-danger);
}
.experiment-label { margin: 0 0 0.55rem; color: var(--color-muted); font-size: 0.98rem; }
.experiment-label strong { color: var(--color-danger); font-weight: 600; }
.experiment h2 { margin: 0 0 0.45rem; font-size: var(--text-subhead); font-weight: 600; }
.experiment p { max-width: 52ch; margin: 0 0 var(--space-sm); }
.experiment a { font-size: 1rem; }
.catalogue { border-top: 1px solid var(--color-rule); }
.catalogue > h2 { margin: 0; padding: 2.25rem 0 var(--space-md); font-size: var(--text-subhead); font-weight: 600; }
.catalogue-group { padding: 1.2rem 0 1.85rem; }
.catalogue-group + .catalogue-group { border-top: 1px solid var(--color-rule); }
.catalogue-group h3 { margin: 0 0 var(--space-xs); color: var(--color-info); font-size: 1rem; font-weight: 500; }
.catalogue-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-sm) 1.25rem;
  padding: var(--space-md) 0;
  border-top: 1px solid var(--color-rule-soft);
}
.catalogue-entry:first-of-type { border-top: 0; }
.entry-title { color: var(--color-ink); font-size: 1.13rem; font-weight: 500; text-decoration-color: transparent; }
.entry-title:hover { color: var(--color-accent); opacity: 1; text-decoration-color: currentColor; }
.catalogue-entry p, .resource-row p { margin: 0.16rem 0 0; color: var(--color-muted); font-size: 0.96rem; line-height: 1.45; text-wrap: pretty; }
.entry-tools, .resource-actions { display: flex; align-items: flex-start; justify-content: flex-end; gap: 0.2rem; }
.notation, .text-action {
  min-height: 2.75rem;
  padding: 0.42rem 0.48rem;
  border: 0;
  background: none;
  color: var(--color-muted);
  font-family: var(--font-code);
  font-size: 0.72rem;
  line-height: 1.2;
  white-space: nowrap;
}
.notation { display: inline-flex; align-items: center; }
.text-action { cursor: pointer; text-decoration: underline; text-underline-offset: 0.22em; }
.text-action:hover, .text-action[data-state="copied"] { color: var(--color-accent); }
.action-primary { color: var(--color-accent); }
.community { margin-top: clamp(2.5rem, 8vh, 4.5rem); padding: var(--space-lg) 0 clamp(2.5rem, 7vh, 4rem); border-top: 1px solid var(--color-rule); }
.community h2 { margin: 0 0 0.45rem; font-size: 1.2rem; font-weight: 600; }
.community p { margin: 0; max-width: 53ch; color: var(--color-muted); font-size: 1.02rem; }

.guide-hero { padding: clamp(4rem, 11vh, 7rem) 0 clamp(2.5rem, 7vh, 4rem); border-bottom: 1px solid var(--color-rule); }
.guide-meta { margin: 0 0 var(--space-sm); color: var(--color-info); font-size: 1rem; }
.guide-actions { display: flex; flex-wrap: wrap; gap: var(--space-xs); margin: var(--space-lg) 0 0 -0.48rem; }
.toc { margin: var(--space-xl) 0 var(--space-2xl); padding: var(--space-md) var(--space-lg); background: var(--color-wash); }
.toc summary { cursor: pointer; font-weight: 600; }
.toc summary span { margin-left: var(--space-xs); color: var(--color-muted); font-size: var(--text-small); font-weight: 400; }
.toc ol { columns: 2; column-gap: var(--space-xl); margin: var(--space-md) 0 0; padding-left: 1.2rem; }
.toc li { break-inside: avoid; margin-bottom: var(--space-xs); color: var(--color-muted); }
.toc-level-3 { margin-left: var(--space-md); font-size: 0.95rem; }
.toc a { color: inherit; }

.prose { max-width: var(--measure-prose); padding: clamp(2.5rem, 7vh, 4rem) 0; }
.prose > *:first-child { margin-top: 0; }
.prose h1 { font-size: 2rem; }
.prose h2, .resource-section h2, .install-block h2 {
  margin: 3rem 0 var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px solid var(--color-rule);
  font-size: 1.55rem;
  font-weight: 600;
  line-height: 1.25;
  text-wrap: balance;
}
.prose h3 { margin: 2.2rem 0 var(--space-sm); font-size: 1.25rem; font-weight: 600; line-height: 1.3; text-wrap: pretty; }
.prose h4 { margin: 1.75rem 0 var(--space-xs); font-size: 1.05rem; font-weight: 600; }
.prose p { margin: 0 0 1.1em; text-wrap: pretty; }
.prose ul, .prose ol { margin: 0 0 1.2em; padding-left: 1.4rem; }
.prose li { margin: 0.35em 0; padding-left: 0.15rem; }
.prose li > ul, .prose li > ol { margin: 0.35em 0 0; }
.prose blockquote {
  margin: var(--space-lg) 0;
  padding: var(--space-md) var(--space-lg);
  background: var(--color-wash);
  border: 1px solid var(--color-rule);
}
.prose blockquote p { margin: 0; }
.prose hr { margin: var(--space-2xl) 0; border: 0; border-top: 1px solid var(--color-rule); }
.prose strong { font-weight: 600; }
.prose code, .resource-section code { font-family: var(--font-code); font-size: 0.84em; color: var(--color-ink); font-variant-ligatures: none; }
.heading-anchor { margin-left: var(--space-xs); color: var(--color-muted); font-family: var(--font-code); font-size: 0.7em; font-weight: 400; text-decoration: none; opacity: 0; }
.prose h2:hover .heading-anchor, .prose h3:hover .heading-anchor, .heading-anchor:focus { opacity: 1; }
.section-copy {
  float: right;
  min-height: 2.75rem;
  margin: -0.55rem 0 0 var(--space-md);
  padding: 0 var(--space-sm);
  border: 0;
  background: none;
  color: var(--color-muted);
  cursor: pointer;
  font-family: var(--font-code);
  font-size: 0.68rem;
  font-weight: 400;
  text-decoration: underline;
  text-underline-offset: 0.22em;
}
.section-copy:hover, .section-copy[data-state="copied"] { color: var(--color-accent); }
.tabs { margin: var(--space-lg) 0 var(--space-2xl); }
.tab-list {
  display: flex;
  gap: var(--space-xs);
  overflow-x: auto;
  padding-bottom: var(--space-xs);
  border-bottom: 1px solid var(--color-rule);
}
.tab-list [role="tab"] {
  min-height: 2.75rem;
  padding: var(--space-xs) var(--space-md);
  border: 1px solid transparent;
  border-bottom: 0;
  background: transparent;
  color: var(--color-muted);
  cursor: pointer;
  white-space: nowrap;
}
.tab-list [role="tab"][aria-selected="true"] { border-color: var(--color-rule); background: var(--color-wash); color: var(--color-ink); }
.tabs [role="tabpanel"] { padding: var(--space-md) 0 0; }
.tabs [role="tabpanel"][hidden] { display: none; }
.code-block { position: relative; margin: var(--space-lg) 0; background: var(--color-wash); border: 1px solid var(--color-rule); }
.code-block pre { margin: 0; padding: 1.1rem 1.25rem; overflow-x: auto; }
.code-block pre code { display: block; min-width: max-content; font-size: 0.82rem; line-height: 1.65; white-space: pre; }
.code-copy { position: absolute; top: var(--space-xs); right: var(--space-xs); min-width: 2.75rem; min-height: 2.75rem; padding: 0 var(--space-sm); border: 1px solid var(--color-rule); background: var(--color-surface); color: var(--color-muted); cursor: pointer; font-family: var(--font-code); font-size: 0.72rem; }
.code-copy:hover, .code-copy[data-state="copied"] { color: var(--color-accent); border-color: var(--color-accent); }
.table-wrap { max-width: 100%; margin: var(--space-lg) 0; overflow-x: auto; border-top: 1px solid var(--color-rule); border-bottom: 1px solid var(--color-rule); }
table { width: 100%; border-collapse: collapse; font-size: 0.98rem; }
th, td { padding: var(--space-sm) var(--space-md); border-bottom: 1px solid var(--color-rule-soft); text-align: left; vertical-align: top; }
th { color: var(--color-info); font-weight: 600; }
tr:last-child td { border-bottom: 0; }

.install-block, .resource-section { margin: 0 0 var(--space-3xl); }
.install-block h2, .resource-section h2 { margin-top: 0; }
.resource-section > p { color: var(--color-muted); }
.resource-list { border-top: 1px solid var(--color-rule); }
.resource-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--space-md); padding: var(--space-md) 0; border-bottom: 1px solid var(--color-rule-soft); }
.resource-row > div:first-child > a { color: var(--color-ink); font-weight: 500; }
.guide-return { padding: var(--space-xl) 0 var(--space-3xl); border-top: 1px solid var(--color-rule); }

input, textarea, select {
  width: 100%;
  min-height: 2.75rem;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-rule);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-ink);
}
textarea { min-height: 9rem; resize: vertical; }
label { display: block; margin-bottom: var(--space-xs); font-weight: 600; }
button:disabled, [aria-disabled="true"] { cursor: not-allowed; opacity: 0.5; }

@media (prefers-reduced-motion: no-preference) {
  .site-header, .index-intro, .guide-hero, .experiment { animation: guide-settle 700ms cubic-bezier(0.16, 1, 0.3, 1) both; }
  .index-intro, .guide-hero { animation-delay: 70ms; }
  .experiment { animation-delay: 130ms; }
  @keyframes guide-settle { from { opacity: 0; transform: translateY(0.5rem); } to { opacity: 1; transform: none; } }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
@media (pointer: coarse) {
  .text-action, .site-header nav a, .code-copy { min-height: 2.75rem; }
}
@media (max-width: 44rem) {
  .toc ol { columns: 1; }
  .resource-row { grid-template-columns: 1fr; }
  .resource-actions { justify-content: flex-start; margin-left: -0.48rem; }
}
@media (max-width: 35rem) {
  .page-shell { width: min(100% - 1.5rem, var(--measure-page)); }
  .site-header { align-items: flex-start; flex-direction: column; gap: 0.25rem; }
  .site-header nav { width: 100%; justify-content: space-between; gap: 0.4rem; }
  .catalogue-entry { grid-template-columns: 1fr; gap: 0.15rem; }
  .entry-tools { justify-content: flex-start; margin-left: -0.48rem; }
  .guide-actions { margin-top: var(--space-md); }
  .prose h2 { font-size: 1.4rem; }
  .section-copy { float: none; display: block; margin: var(--space-xs) 0 0 -0.5rem; }
  th, td { padding: var(--space-sm); }
}
@media print {
  :root { --color-bg: white; --color-ink: black; --color-muted: #333; --color-rule: #aaa; --color-rule-soft: #ddd; --color-wash: #f4f4f4; }
  html { color-scheme: light; }
  .site-header, .site-footer, .guide-actions, .toc, .guide-return, .code-copy, .section-copy, .resource-actions, .skip-link { display: none !important; }
  .page-shell, .prose { width: 100%; max-width: none; }
  .guide-hero { padding: 0 0 1rem; }
  .prose h2, .prose h3 { break-after: avoid; }
  .code-block, table, blockquote { break-inside: avoid; }
  a { color: black; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 0.8em; }
}
