/* The Scribe guide: the layout of the sibling guides (Formwright, Marquetry, Benchdog). */
:root {
  --g-font: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --g-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --g-bg: #ffffff;
  --g-surface: #f5f7f5;
  --g-fg: #1a1f1c;
  --g-muted: #56605a;
  --g-border: #e1e6e2;
  --g-accent: #15803d;
  --g-accent-soft: rgb(21 128 61 / 0.1);
  /* Amber-700: the brand amber (#f59e0b) is too light for small text on white. */
  --g-amber: #a16207;
  --g-coral: #b91c1c;
  --g-code-bg: #f7f8f7;
  --g-gutter: 16px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not(.light) {
    --g-bg: #0e120f;
    --g-surface: #151b17;
    --g-fg: #e6ebe7;
    --g-muted: #9ba59e;
    --g-border: #253029;
    --g-accent: #4ade80;
    --g-accent-soft: rgb(74 222 128 / 0.12);
    --g-amber: #f59e0b;
    --g-coral: #fb7185;
    --g-code-bg: #111612;
  }
}

/* The tests audit the light colours (tests/helpers). */
:root.light {
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--g-bg);
  color: var(--g-fg);
  font: 16px/1.65 var(--g-font);
}

a {
  color: var(--g-accent);
}

/* Anchor jumps land below the sticky header. */
html {
  scroll-padding-top: 5rem;
}

/* ---- header and layout --------------------------------------------------------------- */

.guide-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem clamp(var(--g-gutter), 3vw, 2rem);
  background: color-mix(in srgb, var(--g-bg) 85%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--g-border);
}

.guide-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: inherit;
  text-decoration: none;
}

.guide-tag {
  padding: 0.05rem 0.5rem;
  border-radius: 999px;
  background: var(--g-accent-soft);
  color: var(--g-accent);
  font-size: 0.75rem;
  font-weight: 700;
}

.guide-header nav {
  display: flex;
  gap: 1.25rem;
}

.guide-header nav a {
  color: var(--g-muted);
  font-weight: 500;
  text-decoration: none;
}

.guide-header nav a:hover {
  color: var(--g-fg);
}

.guide-layout {
  display: grid;
  grid-template-columns: 15rem minmax(0, 1fr);
  gap: clamp(1.5rem, 4vw, 3.5rem);
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 clamp(var(--g-gutter), 3vw, 2rem);
}

.guide-sidebar {
  position: sticky;
  top: 4rem;
  align-self: start;
  max-height: calc(100vh - 4rem);
  overflow-y: auto;
  padding: 1.5rem 0;
}

.guide-sidebar summary {
  display: none;
}

.guide-sidebar ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.guide-sidebar li {
  margin: 0;
}

.guide-sidebar nav > ul > li {
  margin-bottom: 1.1rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--g-muted);
}

.guide-sidebar nav > ul > li > ul {
  margin-top: 0.35rem;
  font-size: 0.92rem;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}

.guide-sidebar a {
  display: block;
  padding: 0.28rem 0.7rem;
  border-radius: 8px;
  color: var(--g-fg);
  text-decoration: none;
}

.guide-sidebar a:hover {
  background: var(--g-surface);
}

.guide-sidebar a.active {
  background: var(--g-accent-soft);
  color: var(--g-accent);
  font-weight: 600;
}

.guide-main {
  min-width: 0;
  padding: 1.5rem 0 5rem;
}

/* The sibling projects, as on the project site's footer. */
.guide-footer {
  padding: 1.5rem clamp(var(--g-gutter), 3vw, 2rem);
  border-top: 1px solid var(--g-border);
  color: var(--g-muted);
  font-size: 0.875rem;
}

.guide-footer p {
  margin: 0.25rem 0;
}

.guide-footer a {
  color: inherit;
}

.guide-footer [aria-current='page'] {
  font-weight: 600;
  text-decoration: none;
}

@media (max-width: 860px) {
  .guide-layout {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .guide-sidebar {
    position: static;
    max-height: none;
    padding: 0.75rem 0 0;
  }

  .guide-sidebar summary {
    display: block;
    cursor: pointer;
    font-weight: 600;
    padding: 0.4rem 0;
  }

  .guide-sidebar:not([open]) nav {
    display: none;
  }
}

/* ---- prose --------------------------------------------------------------------------- */

.guide-prose {
  max-width: 50rem;
}

.guide-prose h1 {
  margin: 0.5rem 0 0.75rem;
  font-size: clamp(2rem, 4vw, 2.6rem);
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.1;
}

.guide-prose h1 + p {
  font-size: 1.12rem;
  color: var(--g-muted);
}

.guide-prose h2 {
  margin: 3rem 0 0.75rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--g-border);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.015em;
}

/* The "#" link a heading gets for sharing; shown on hover or focus. */
.heading-anchor {
  margin-left: 0.4rem;
  color: var(--g-muted);
  text-decoration: none;
  font-weight: 400;
  opacity: 0;
  transition: opacity 0.15s;
}

:is(h2, h3):hover > .heading-anchor,
.heading-anchor:focus-visible {
  opacity: 1;
}

@media (hover: none) {
  .heading-anchor {
    opacity: 0.6;
  }
}

.guide-prose h3 {
  margin: 2rem 0 0.5rem;
  font-size: 1.15rem;
}

.guide-prose :not(pre) > code {
  padding: 0.1em 0.35em;
  border-radius: 5px;
  background: var(--g-accent-soft);
  font: 0.88em var(--g-mono);
}

.guide-prose pre:not(.example pre) {
  margin: 1.25rem 0;
  padding: 1rem 1.25rem;
  overflow-x: auto;
  border: 1px solid var(--g-border);
  border-radius: 12px;
  background: var(--g-code-bg) !important;
  font: 0.86rem/1.6 var(--g-mono);
}

.guide-prose table {
  display: block;
  width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  margin: 1.25rem 0;
  font-size: 0.93rem;
}

.guide-prose th,
.guide-prose td {
  padding: 0.55rem 0.8rem;
  border-bottom: 1px solid var(--g-border);
  text-align: left;
  vertical-align: top;
}

.guide-prose th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--g-muted);
}

.guide-prose td:first-child code {
  white-space: nowrap;
}

.guide-loading,
.guide-error {
  padding: 1rem;
  border-radius: 10px;
}

.guide-error {
  border: 1px solid var(--g-coral);
  color: var(--g-coral);
}

/* ---- live example --------------------------------------------------------------------- */

.example {
  margin: 1.75rem 0;
  border: 1px solid var(--g-border);
  border-radius: 16px;
  overflow: hidden;
  background: var(--g-surface);
  box-shadow: 0 18px 50px -30px rgb(21 128 61 / 0.45);
}

.example-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--g-border);
  background: var(--g-bg);
}

.example-title {
  font-weight: 700;
  font-size: 0.95rem;
}

.example-note {
  color: var(--g-amber);
  font: 600 0.78rem var(--g-mono);
}

.example-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.9rem;
  padding: 0.9rem;
}

@media (max-width: 760px) {
  .example-stage {
    grid-template-columns: 1fr;
  }
}

.example-preview {
  display: grid;
  gap: 0.9rem;
  align-content: start;
  padding: 1.25rem;
  border: 1px solid var(--g-border);
  border-radius: 12px;
  background: var(--g-bg);
  font-size: 0.93rem;
}

.example-preview label {
  display: grid;
  gap: 0.3rem;
  font-weight: 500;
}

.example-preview input[type='text'] {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--g-border);
  border-radius: 8px;
  background: var(--g-bg);
  color: var(--g-fg);
  font: 0.9rem var(--g-mono);
}

.example-preview input:focus-visible {
  outline: 2px solid var(--g-accent);
  outline-offset: 1px;
}

.example-preview input[type='range'],
.example-preview input[type='checkbox'] {
  accent-color: var(--g-accent);
}

.example-preview .example-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.example-bucket {
  margin: 0;
  color: var(--g-muted);
}

.example-model {
  min-width: 0;
  padding: 0.8rem;
  border-radius: 12px;
  background: var(--g-bg);
  border: 1px dashed var(--g-border);
}

.example-model-label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--g-muted);
}

.example-model pre {
  margin: 0 0 0.9rem;
  overflow: auto;
  font: 0.78rem/1.5 var(--g-mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.example-source {
  border-top: 1px solid var(--g-border);
  background: var(--g-bg);
}

.example-source summary {
  padding: 0.6rem 0.9rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
}

.example-code {
  max-height: 34rem;
  overflow: auto;
  background: var(--g-code-bg);
}

.example-code pre {
  margin: 0;
  padding: 1rem 1.25rem;
  background: transparent !important;
  font: 0.84rem/1.6 var(--g-mono);
}
