/* ds-prose-rs site. Tokens first; the dark palette is declared twice (system
   preference and forced) and a test keeps the two identical. */
:root {
  color-scheme: light dark;
  --bg: #f6f8fa;
  --surface: #ffffff;
  --surface-2: #eef2f6;
  --border: #cfd8e1;
  --text: #16202b;
  --text-muted: #435263;
  --link: #0b5f8a;
  --accent: #0b5f8a;
  --focus: #0b5f8a;
  --permission: #15803d;
  --prohibition: #b91c1c;
  --obligation: #1d4ed8;
  --warning: #92400e;
  --font-text: "Charter", "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-code: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 40px;
  --s7: 64px;
  --nav-h: 3.5rem;
}
:root[data-theme="light"] {
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1720;
    --surface: #16212d;
    --surface-2: #1c2937;
    --border: #2c3b4c;
    --text: #e6edf3;
    --text-muted: #a3b1c0;
    --link: #6cb6e0;
    --accent: #6cb6e0;
    --focus: #6cb6e0;
    --permission: #4ade80;
    --prohibition: #f87171;
    --obligation: #7aa7ff;
    --warning: #fbbf24;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1720;
  --surface: #16212d;
  --surface-2: #1c2937;
  --border: #2c3b4c;
  --text: #e6edf3;
  --text-muted: #a3b1c0;
  --link: #6cb6e0;
  --accent: #6cb6e0;
  --focus: #6cb6e0;
  --permission: #4ade80;
  --prohibition: #f87171;
  --obligation: #7aa7ff;
  --warning: #fbbf24;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--nav-h) + var(--s4));
  -webkit-text-size-adjust: 100%;
}
body.site {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-text);
  font-size: 1.0625rem;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
body.site > main,
body.site > .layout {
  flex: 1 0 auto;
  width: 100%;
}
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
a {
  color: var(--link);
  text-underline-offset: 0.18em;
  transition: color 120ms;
}
a:hover {
  text-decoration-thickness: 2px;
}

/* Skip link */
.skip-link {
  position: absolute;
  inset-inline-start: var(--s4);
  top: 0;
  z-index: 30;
  padding: var(--s2) var(--s4);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  font-family: var(--font-ui);
  transform: translateY(-120%);
}
.skip-link:focus {
  transform: translateY(var(--s2));
}

/* Top navigation. Everything is scoped under .topnav so the stamped demos keep their own styles. */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topnav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s2) var(--s5);
  max-width: 80rem;
  margin-inline: auto;
  padding: var(--s2) max(var(--s4), env(safe-area-inset-left));
  min-height: var(--nav-h);
  font-family: var(--font-ui);
  font-size: 0.9375rem;
  line-height: 1.3;
  color: var(--text);
}
.topnav .brand {
  font-weight: 700;
  font-family: var(--font-code);
  color: var(--text);
  text-decoration: none;
}
.topnav .topnav-links {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s2) var(--s5);
}
.topnav .topnav-links[hidden] {
  display: none;
}
.topnav .topnav-list {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s1) var(--s4);
  margin: 0;
  padding: 0;
  list-style: none;
}
.topnav .topnav-list > li > a,
.topnav .pkg-group summary {
  display: inline-block;
  padding: var(--s2) 0;
  color: var(--text);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}
.topnav .topnav-list > li > a:hover,
.topnav .pkg-group summary:hover {
  border-bottom-color: var(--border);
}
.topnav .topnav-list a[aria-current] {
  color: var(--link);
  font-weight: 600;
  border-bottom-color: var(--accent);
}
.topnav .pkg {
  position: relative;
}
.topnav .pkg-group ul {
  margin: 0;
  padding: var(--s2) var(--s4);
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.topnav .pkg-group li {
  padding: var(--s1) 0;
  white-space: nowrap;
}
.topnav .pkg-group li a {
  color: var(--link);
}
.topnav .menu-toggle,
.topnav .theme-toggle,
.copy {
  font: inherit;
  font-family: var(--font-ui);
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: var(--s1) var(--s3);
  cursor: pointer;
}
.topnav .menu-toggle {
  margin-inline-start: auto;
}
.topnav .menu-toggle[hidden] {
  display: none;
}

@media (min-width: 48rem) {
  .topnav .pkg-group ul {
    position: absolute;
    inset-inline-start: 0;
    top: 100%;
    z-index: 25;
  }
}
@media (max-width: 47.99rem) {
  .topnav .topnav-links,
  .topnav .topnav-list {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }
  .topnav .topnav-links {
    gap: var(--s2);
  }
  .topnav .theme-toggle {
    align-self: flex-start;
  }
  .topnav .topnav-list > li > a,
  .topnav .pkg-group summary {
    padding: var(--s2) 0;
  }
}

/* Page layout */
.layout {
  display: grid;
  grid-template-columns: 13rem minmax(0, 1fr);
  gap: var(--s6);
  max-width: 80rem;
  margin-inline: auto;
  padding-inline: max(var(--s4), env(safe-area-inset-left));
}
.site > main,
.layout > main {
  display: block;
  min-width: 0;
  padding-block: var(--s6) var(--s7);
}
.site > main {
  max-width: 80rem;
  margin-inline: auto;
  padding-inline: max(var(--s4), env(safe-area-inset-left));
}
.subnav {
  align-self: start;
  position: sticky;
  top: calc(var(--nav-h) + var(--s4));
  padding-block: var(--s6);
  font-family: var(--font-ui);
  font-size: 0.9375rem;
}
.subnav ul {
  margin: 0;
  padding: 0;
  list-style: none;
  border-inline-start: 1px solid var(--border);
}
.subnav a {
  display: block;
  padding: var(--s2) var(--s3);
  color: var(--text-muted);
  text-decoration: none;
}
.subnav a[aria-current="page"] {
  color: var(--link);
  font-weight: 600;
  border-inline-start: 3px solid var(--accent);
  margin-inline-start: -2px;
}
@media (max-width: 47.99rem) {
  .layout {
    display: block;
  }
  .subnav {
    position: static;
    padding-block: var(--s4) 0;
  }
  .subnav ul {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s1) var(--s3);
    border-inline-start: 0;
  }
  .subnav a[aria-current="page"] {
    border-inline-start: 0;
    margin-inline-start: 0;
    border-bottom: 2px solid var(--accent);
  }
  .layout > main {
    padding-block: var(--s5) var(--s6);
  }
}

/* Running text */
main h1,
main h2,
main h3,
main h4 {
  font-family: var(--font-ui);
  line-height: 1.25;
  scroll-margin-top: calc(var(--nav-h) + var(--s4));
}
main h1 {
  font-size: 2rem;
  margin: 0 0 var(--s5);
  max-width: 40ch;
}
main h2 {
  font-size: 1.5rem;
  margin: var(--s6) 0 var(--s3);
}
main h3 {
  font-size: 1.1875rem;
  margin: var(--s5) 0 var(--s2);
}
main p,
main ul,
main ol,
main blockquote {
  max-width: 65ch;
}
main h1,
main h2,
main h3,
main p,
main li,
main blockquote {
  overflow-wrap: anywhere;
}
main li + li {
  margin-top: var(--s1);
}
main blockquote {
  margin-inline: 0;
  padding: var(--s1) var(--s4);
  border-inline-start: 4px solid var(--border);
  color: var(--text-muted);
}
main hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin-block: var(--s6);
}
.anchor {
  margin-inline-start: var(--s2);
  font-weight: 400;
  text-decoration: none;
  color: var(--text-muted);
  opacity: 0;
}
h2:hover .anchor,
h3:hover .anchor,
.anchor:focus-visible {
  opacity: 1;
}
code {
  font-family: var(--font-code);
  font-size: 0.875em;
  font-variant-numeric: tabular-nums;
  background: var(--surface-2);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  overflow-wrap: anywhere;
}

/* Code blocks */
.code {
  display: flex;
  flex-direction: column;
  margin-block: var(--s4);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.copy {
  align-self: flex-end;
  margin: var(--s2) var(--s2) 0;
  font-size: 0.8125rem;
}
.code pre {
  margin: 0;
  padding: var(--s2) var(--s4) var(--s4);
  overflow: auto;
  font-family: var(--font-code);
  font-size: 0.875rem;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}
.code code {
  padding: 0;
  background: none;
  font-size: inherit;
  overflow-wrap: normal;
}

/* Tables */
.table-scroll {
  overflow-x: auto;
  margin-block: var(--s4);
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
}
.table-scroll table {
  width: 100%;
  min-width: 40rem;
  border-collapse: collapse;
  font-family: var(--font-ui);
  font-size: 0.9375rem;
  font-variant-numeric: tabular-nums;
}
.table-scroll th,
.table-scroll td {
  padding: var(--s2) var(--s3);
  text-align: start;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}
.table-scroll th {
  background: var(--surface-2);
}
.table-scroll td:last-child {
  min-width: 16rem;
}
.table-scroll code {
  white-space: nowrap;
  overflow-wrap: normal;
}
.table-scroll tr:last-child td {
  border-bottom: 0;
}
.align-right {
  text-align: end;
}
.align-center {
  text-align: center;
}

.site-footer {
  width: 100%;
  max-width: 80rem;
  margin-inline: auto;
  padding: var(--s5) max(var(--s4), env(safe-area-inset-left));
  border-top: 1px solid var(--border);
  font-family: var(--font-ui);
  font-size: 0.875rem;
  color: var(--text-muted);
}
.site-footer p {
  margin: 0;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

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

/* Renderer output embedded in a page (the home page, the validation page). */
.rendered {
  margin: 0 0 var(--space-4, 16px);
  padding: 16px;
  background: var(--ds-bg, var(--surface));
  color: var(--ds-fg, var(--text));
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: auto;
}
.rendered:focus-visible { outline-offset: 2px; }
.source-note {
  margin: -8px 0 16px;
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* The stylesheet switch under the navigation in the two demos. */
.sheet-switch {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s1) var(--s4);
  padding: var(--s2) max(var(--s4), env(safe-area-inset-left));
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.875rem;
  line-height: 1.4;
}
.sheet-switch > span:first-child {
  font-weight: 600;
}
.sheet-switch label {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s1) 0;
}
.sheet-switch .hint {
  flex: 1 1 18rem;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}
