/* PEGO site: shared styles. Colors are tokens on :root, redefined for the dark theme. */

:root {
  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --bg-sunken: #eef0f3;
  --fg: #1d2330;
  --fg-soft: #4a5263;
  --fg-faint: #7a8294;
  --border: #dde1e7;
  --accent: #2f6fde;
  --accent-fg: #ffffff;
  --accent-soft: #e6eefc;
  --link: #2459c4;
  --code-bg: #f4f5f8;
  --mark-hover: rgba(47, 111, 222, 0.18);
  --mark-select: rgba(47, 111, 222, 0.30);
  --error: #c8322b;
  --error-soft: rgba(200, 50, 43, 0.12);
  --warn: #a35d00;
  --ok: #1f7a43;
  --shadow: 0 6px 24px rgba(20, 30, 50, 0.12);
  --tok-comment: #6b7385;
  --tok-keyword: #a3239c;
  --tok-string: #1f7a43;
  --tok-number: #b35c00;
  --tok-type: #2459c4;
  --tok-rule: #6639ba;
  --tok-label: #b3261e;
  --tok-class: #0b7a8a;
  --tok-punct: #4a5263;
  --tok-attr: #a35d00;
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --topbar-h: 56px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11151c;
    --bg-soft: #171c25;
    --bg-sunken: #0c1016;
    --fg: #e4e8ef;
    --fg-soft: #b3bac7;
    --fg-faint: #858d9c;
    --border: #2a313d;
    --accent: #5b93f0;
    --accent-fg: #0b1220;
    --accent-soft: #1b2a45;
    --link: #7eaaf5;
    --code-bg: #181e28;
    --mark-hover: rgba(91, 147, 240, 0.25);
    --mark-select: rgba(91, 147, 240, 0.40);
    --error: #f0736b;
    --error-soft: rgba(240, 115, 107, 0.16);
    --warn: #e0a24a;
    --ok: #5cc48a;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
    --tok-comment: #7f8899;
    --tok-keyword: #e08ad9;
    --tok-string: #8fd19e;
    --tok-number: #f0b273;
    --tok-type: #7eaaf5;
    --tok-rule: #b9a0f5;
    --tok-label: #f58e86;
    --tok-class: #6ccfdc;
    --tok-punct: #b3bac7;
    --tok-attr: #e8b45c;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #11151c;
  --bg-soft: #171c25;
  --bg-sunken: #0c1016;
  --fg: #e4e8ef;
  --fg-soft: #b3bac7;
  --fg-faint: #858d9c;
  --border: #2a313d;
  --accent: #5b93f0;
  --accent-fg: #0b1220;
  --accent-soft: #1b2a45;
  --link: #7eaaf5;
  --code-bg: #181e28;
  --mark-hover: rgba(91, 147, 240, 0.25);
  --mark-select: rgba(91, 147, 240, 0.40);
  --error: #f0736b;
  --error-soft: rgba(240, 115, 107, 0.16);
  --warn: #e0a24a;
  --ok: #5cc48a;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  --tok-comment: #7f8899;
  --tok-keyword: #e08ad9;
  --tok-string: #8fd19e;
  --tok-number: #f0b273;
  --tok-type: #7eaaf5;
  --tok-rule: #b9a0f5;
  --tok-label: #f58e86;
  --tok-class: #6ccfdc;
  --tok-punct: #b3bac7;
  --tok-attr: #e8b45c;
  color-scheme: dark;
}

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

html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--topbar-h) + 12px); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.6 var(--font);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
code, kbd, pre { font-family: var(--mono); font-size: 0.9em; }

.skip { position: absolute; left: -999px; top: 0; }
.skip:focus { left: 8px; top: 8px; z-index: 100; background: var(--bg); padding: 4px 8px; }

/* Top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 18px;
  color: var(--fg);
  letter-spacing: 0.02em;
}
.brand:hover { text-decoration: none; }

.topnav { display: flex; gap: 4px; margin-left: 8px; }
.topnav a {
  color: var(--fg-soft);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 15px;
}
.topnav a:hover { background: var(--bg-soft); text-decoration: none; color: var(--fg); }
.topnav a[aria-current] { color: var(--accent); font-weight: 600; }

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--fg-soft);
  cursor: pointer;
}
.icon-button:hover { background: var(--bg-soft); color: var(--fg); text-decoration: none; }

.theme-toggle .moon { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .moon { display: block; }
}

.menu-toggle { display: none; }

/* Search */

.search { position: relative; margin-left: auto; }
.search input {
  width: 220px;
  height: 34px;
  padding: 0 28px 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-soft);
  color: var(--fg);
  font: inherit;
  font-size: 14px;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--bg); }
.search-key {
  position: absolute;
  right: 8px;
  top: 7px;
  font-size: 12px;
  color: var(--fg-faint);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 5px;
  pointer-events: none;
}
.search input:focus + .search-key { display: none; }
.search-results {
  position: absolute;
  right: 0;
  top: 42px;
  width: min(520px, calc(100vw - 32px));
  max-height: min(70vh, 560px);
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 6px;
}
.search-results a {
  display: block;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--fg);
}
.search-results a:hover, .search-results a[aria-selected="true"] { background: var(--accent-soft); text-decoration: none; }
.search-results .r-title { font-weight: 600; }
.search-results .r-section { color: var(--fg-faint); font-size: 12px; margin-left: 6px; }
.search-results .r-heading { color: var(--accent); font-size: 13px; }
.search-results .r-snippet { color: var(--fg-soft); font-size: 13px; line-height: 1.45; margin-top: 2px; }
.search-results mark { background: var(--mark-select); color: inherit; border-radius: 2px; }
.search-results .r-empty { padding: 10px; color: var(--fg-faint); }

/* Buttons */

.button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.button:hover { background: var(--bg-soft); text-decoration: none; }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.button.primary:hover { filter: brightness(1.08); }
.button.small { height: 30px; padding: 0 10px; font-size: 13px; font-weight: 600; }
.link-button { border: 0; background: none; color: var(--link); font: inherit; font-size: 13px; cursor: pointer; padding: 0; }
.link-button:hover { text-decoration: underline; }

/* Documentation layout */

.doc-layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 220px;
  gap: 0;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  flex: 1;
}

.sidebar {
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 20px 12px 40px 16px;
  border-right: 1px solid var(--border);
  font-size: 14px;
}
.nav-section h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-faint);
  margin: 18px 8px 6px;
}
.nav-section:first-child h2 { margin-top: 0; }
.nav-section ul { list-style: none; margin: 0; padding: 0; }
.nav-section a {
  display: block;
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--fg-soft);
  line-height: 1.4;
}
.nav-section a:hover { background: var(--bg-soft); color: var(--fg); text-decoration: none; }
.nav-section a[aria-current] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* A collapsible section (details in the navigation): its heading is the summary, with a chevron that
   turns when the section is open. The heading keeps its style and margins. */
.nav-fold > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 18px 8px 6px;
  border-radius: 6px;
  cursor: pointer;
  list-style: none;
}
.nav-fold > summary::-webkit-details-marker { display: none; }
.nav-fold > summary h2 { margin: 0; }
.nav-fold > summary::after {
  content: "";
  flex: none;
  width: 6px;
  height: 6px;
  margin: 0 4px 0 auto;
  border-right: 2px solid var(--fg-faint);
  border-bottom: 2px solid var(--fg-faint);
  transform: rotate(-45deg);
  transition: transform 0.15s;
}
.nav-fold[open] > summary::after { transform: rotate(45deg); }
.nav-fold > summary:hover h2 { color: var(--fg-soft); }
.nav-fold > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .nav-fold > summary::after { transition: none; } }

.doc-main { min-width: 0; padding: 32px 48px 64px; }

.toc {
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 28px 16px 40px 8px;
  font-size: 13px;
}
.toc h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--fg-faint); margin: 0 0 8px; }
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0; }
.toc a { display: block; padding: 3px 0; color: var(--fg-soft); line-height: 1.35; }
.toc a:hover { color: var(--fg); }
.toc a.active { color: var(--accent); font-weight: 600; }
.toc .toc-3 a { padding-left: 12px; }
.toc .toc-4 a { padding-left: 24px; font-size: 12px; }

.doc-footer { max-width: 820px; margin-top: 48px; border-top: 1px solid var(--border); padding-top: 16px; }
.source-link { font-size: 14px; margin: 0 0 16px; }
.pager { display: flex; justify-content: space-between; gap: 12px; }
.pager a {
  flex: 1;
  max-width: 48%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--fg);
  font-weight: 600;
}
.pager a:hover { border-color: var(--accent); text-decoration: none; }
.pager a span { display: block; font-size: 12px; font-weight: 400; color: var(--fg-faint); }
.pager .next { margin-left: auto; text-align: right; }

/* Prose */

.prose { max-width: 820px; }
.prose h1 { font-size: 2.1em; line-height: 1.2; margin: 0 0 0.6em; letter-spacing: -0.01em; }
.prose h2 { font-size: 1.5em; line-height: 1.3; margin: 2em 0 0.6em; padding-bottom: 0.25em; border-bottom: 1px solid var(--border); }
.prose h3 { font-size: 1.2em; margin: 1.6em 0 0.5em; }
.prose h4 { font-size: 1.05em; margin: 1.4em 0 0.4em; }
.prose h1, .prose h2, .prose h3, .prose h4 { position: relative; }
.prose .anchor {
  position: absolute;
  left: -1em;
  width: 1em;
  color: var(--fg-faint);
  opacity: 0;
  text-decoration: none;
  font-weight: 400;
}
.prose :is(h1, h2, h3, h4):hover .anchor, .symbol h3:hover .anchor, .symbol h4:hover .anchor { opacity: 1; }
.prose p, .prose ul, .prose ol, .prose table, .prose pre, .prose blockquote, .prose details { margin: 0 0 1em; }
.prose li { margin: 0.2em 0; }
.prose li > p { margin: 0.3em 0; }
.prose img { max-width: 100%; }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 2em 0; }

.prose :not(pre) > code {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.05em 0.3em;
  font-size: 0.86em;
  overflow-wrap: anywhere;
}
.prose pre, pre.code-block {
  position: relative;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  overflow-x: auto;
  line-height: 1.5;
  font-size: 14px;
}
.prose pre code { font-size: inherit; background: none; border: 0; padding: 0; }
.code-actions {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}
pre:hover .code-actions, pre:focus-within .code-actions { opacity: 1; }
@media (hover: none) { .code-actions { opacity: 1; } }
.code-actions button, .code-actions a {
  font: 12px/1 var(--font);
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg-soft);
  cursor: pointer;
}
.code-actions button:hover, .code-actions a:hover { color: var(--fg); border-color: var(--accent); text-decoration: none; }

.prose table { border-collapse: collapse; display: block; overflow-x: auto; max-width: 100%; font-size: 15px; }
.prose th, .prose td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
.prose th { background: var(--bg-soft); }

.prose blockquote {
  margin-left: 0;
  padding: 2px 16px;
  border-left: 4px solid var(--border);
  color: var(--fg-soft);
}
.prose .callout { border-left-color: var(--accent); background: var(--accent-soft); border-radius: 0 var(--radius) var(--radius) 0; color: var(--fg); padding: 10px 16px; }
.prose .callout-warning, .prose .callout-caution { border-left-color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent); }
.prose .callout-title { font-weight: 700; margin: 0 0 4px; }
.prose details { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 14px; }
.prose summary { cursor: pointer; font-weight: 600; }

/* Reference */

.ref-links { color: var(--fg-soft); font-size: 14px; }
.ref-index { font-size: 14px; columns: 2; column-gap: 32px; }
.ref-index ul { padding-left: 18px; }
.symbol { margin: 1.6em 0; }
.symbol h3, .symbol h4 { display: flex; align-items: baseline; gap: 8px; font-family: var(--mono); font-size: 1em; position: relative; }
.symbol .source { margin-left: auto; font: 12px var(--font); color: var(--fg-faint); }
pre.decl { font-size: 13.5px; }
.alias-target { border-left: 3px solid var(--border); padding-left: 14px; margin: 0 0 1.6em; }
.alias-note { color: var(--fg-soft); font-size: 14px; }
.alias-note .source { margin-left: 4px; }

/* Syntax highlighting */

.tok-comment { color: var(--tok-comment); font-style: italic; }
.tok-keyword { color: var(--tok-keyword); }
.tok-string { color: var(--tok-string); }
.tok-number { color: var(--tok-number); }
.tok-type { color: var(--tok-type); }
.tok-rule { color: var(--tok-rule); font-weight: 600; }
.tok-label { color: var(--tok-label); }
.tok-class { color: var(--tok-class); }
.tok-capture { color: var(--tok-label); }
.tok-attr { color: var(--tok-attr); }
.tok-punct { color: var(--tok-punct); }
.tok-prompt { color: var(--fg-faint); user-select: none; }
.tok-key { color: var(--tok-type); }

/* Footer */

.site-footer {
  border-top: 1px solid var(--border);
  padding: 20px 16px;
  text-align: center;
  font-size: 14px;
  color: var(--fg-faint);
}
.site-footer p { margin: 0; }

/* Landing */

.landing-main { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 24px 48px; }
.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  gap: 40px;
  align-items: center;
  padding: 56px 0 32px;
}
.tagline { font-size: clamp(2.2rem, 4.6vw, 3.4rem); line-height: 1.08; margin: 0 0 16px; letter-spacing: -0.02em; }
.subtitle { font-size: 1.25rem; color: var(--accent); font-weight: 600; margin: 0 0 16px; }
.intro p { color: var(--fg-soft); font-size: 1.05rem; margin: 0 0 16px; }
.cta { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 24px; }

.live {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-soft);
  box-shadow: var(--shadow);
  padding: 14px;
  min-width: 0;
}
.live-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 14px; margin-bottom: 8px; flex-wrap: wrap; }
.live-title { font-weight: 600; }
.live-grammar { margin: 0 0 10px; max-height: 260px; overflow: auto; font-size: 12.5px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; line-height: 1.45; }
.live-input-label, .live-output-label { display: block; font-size: 12px; font-weight: 600; color: var(--fg-faint); text-transform: uppercase; letter-spacing: 0.05em; margin: 4px 0; }
.live-input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 10px;
  font: 15px var(--mono);
  background: var(--bg);
  color: var(--fg);
}
.live-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.live-status { font-weight: 400; text-transform: none; letter-spacing: 0; margin-left: 6px; }
.live-status.ok { color: var(--ok); }
.live-status.error { color: var(--error); }
.live-output { margin: 0; min-height: 64px; max-height: 200px; overflow: auto; white-space: pre-wrap; word-break: break-word; font-size: 12.5px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }

.snippets { max-width: 860px; margin: 0 auto; }
.snippets pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; overflow-x: auto; font-size: 14px; position: relative; }
.snippets blockquote { border-left: 4px solid var(--accent); background: var(--accent-soft); margin: 16px 0; padding: 8px 16px; border-radius: 0 8px 8px 0; }
.snippets .callout-title { font-weight: 700; margin: 4px 0; }

.features h2, .doc-cards h2 { font-size: 1.8rem; text-align: center; margin: 56px 0 24px; }
.feature-grid, .card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.feature, .card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  background: var(--bg-soft);
}
.feature h3, .card h3 { margin: 0 0 6px; font-size: 1.05rem; }
.feature p, .card p { margin: 0; color: var(--fg-soft); font-size: 15px; }
.feature code { font-size: 0.85em; }
.card { color: var(--fg); transition: border-color 0.15s, transform 0.15s; }
.card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-2px); }
.readme { max-width: 860px; margin: 24px auto 0; }

/* Small screens */

@media (max-width: 1180px) {
  .doc-layout { grid-template-columns: 240px minmax(0, 1fr); }
  .toc { display: none; }
}

@media (max-width: 860px) {
  .topnav { display: none; }
  .menu-toggle { display: inline-flex; }
  .doc-layout { display: block; }
  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    width: min(300px, 85vw);
    height: auto;
    z-index: 15;
    background: var(--bg);
    transform: translateX(-100%);
    transition: transform 0.2s;
  }
  body.nav-open .sidebar { transform: none; box-shadow: var(--shadow); }
  .sidebar .mobile-links { display: block; }
  .doc-main { padding: 24px 16px 48px; }
  .prose .anchor { display: none; }
  .hero { grid-template-columns: minmax(0, 1fr); padding-top: 32px; gap: 24px; }
  .landing-main { padding: 0 16px 40px; }
  .search { margin-left: auto; }
  .search input { width: 140px; }
  .search-key { display: none; }
  .ref-index { columns: 1; }
}

@media (max-width: 480px) {
  .topbar { gap: 6px; padding: 0 10px; }
  .search input { width: 110px; }
  .brand { font-size: 16px; }
}

.sidebar .mobile-links { display: none; margin-bottom: 12px; }
.mobile-menu { display: none; }
@media (max-width: 860px) {
  body.nav-open .mobile-menu {
    display: block;
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    right: 0;
    z-index: 15;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 8px 12px;
  }
}
