/* Styles for the landing page and docs (not needed to use tangle.js). */

:root {
  color-scheme: light dark;
  --ink: #25221d;
  --muted: #706a60;
  --paper: #fffdf9;
  --panel: #f7f4ee;
  --line: #e6e0d6;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Dark by OS preference, unless the theme toggle (site.js) picked light. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #f2ede4;
    --muted: #a8a094;
    --paper: #1b1a18;
    --panel: #232120;
    --line: #36322d;
  }
}

:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #f2ede4;
  --muted: #a8a094;
  --paper: #1b1a18;
  --panel: #232120;
  --line: #36322d;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 19px/1.6 "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}

a { color: var(--tangle-accent); }
h1 { font-size: 2.1rem; line-height: 1.15; margin: 0 0 0.3rem; }
h2 { font-size: 1.35rem; margin: 2.8rem 0 0.5rem; }
h3 { font-size: 1.05rem; margin: 2rem 0 0.4rem; }
.lede { color: var(--muted); margin-top: 0; }

code { font: 0.84em var(--mono); }
:not(pre) > code {
  padding: 0.05em 0.3em;
  border-radius: 4px;
  background: var(--panel);
}
h1 > code { padding: 0; background: none; }

kbd {
  padding: 0.05em 0.4em;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  font: 0.78em var(--sans);
}

pre {
  overflow-x: auto;
  margin: 0.8rem 0;
  padding: 0.8rem 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  font: 0.78rem/1.55 var(--mono);
  white-space: pre;
}
pre code { font: inherit; }

details { margin: 0.4rem 0 0; font-size: 0.8rem; }
details pre { font-size: 0.78rem; }
summary { cursor: pointer; color: var(--muted); font-family: var(--sans); }

table {
  width: 100%;
  margin: 0.8rem 0 1.2rem;
  border-collapse: collapse;
  font: 0.8rem/1.5 var(--sans);
}
th, td {
  padding: 0.45rem 0.6rem 0.45rem 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
th { color: var(--muted); font-weight: 600; }
td:first-child { white-space: nowrap; }

/* Arrow crossings in a <t-flow> cut gaps in the page's own background. */
.tangle-flow { --tangle-flow-bg: var(--paper); }

/* A live example, with its source panel attached underneath. */
.example {
  display: block;
  margin: 1.2rem 0 0;
  padding: 0.2rem 1.25rem;
  border: 1px solid var(--line);
  border-radius: 10px;
}
/* An example's source panels (markup, script, stylesheet) stack tightly, and the
   gap to the next paragraph comes after the last one. */
/* A board has no margin of its own: keep it off the box's edges. */
.example > t-sketch { margin: 1rem 0 1.25rem; }
.example ~ details.source { margin-bottom: 1.4rem; }
.example ~ details.source:has(+ [data-show-source]) { margin-bottom: 0; }
.example button {
  margin-bottom: 1rem;
  padding: 0.25rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  font: 0.85rem var(--sans);
  cursor: pointer;
}
.example button:hover { border-color: var(--muted); }
details.source pre { margin-top: 0.4rem; }

.callout {
  margin: 1.2rem 0;
  padding: 0.6rem 1rem;
  border-left: 3px solid var(--tangle-accent);
  background: var(--panel);
  border-radius: 0 8px 8px 0;
  font-size: 0.92em;
}
.callout > :first-child { margin-top: 0; }
.callout > :last-child { margin-bottom: 0; }

canvas.plot {
  display: block;
  width: 100%;
  height: 220px;
  margin: 1rem 0;
  border: 1px solid var(--line);
  border-radius: 8px;
}

/* Landing page: links and the theme toggle above the title, level with the sidebar's top row. */
.topbar {
  display: flex;
  justify-content: flex-end;
  align-items: baseline;
  gap: 1.2rem;
  margin-bottom: 1.5rem;
  font: 0.9rem var(--sans);
}

.theme-toggle {
  padding: 0.1rem 0.45rem;
  border: 0;
  border-radius: 5px;
  background: none;
  color: var(--muted);
  font: 1rem/1.4 var(--sans);
  cursor: pointer;
}
.theme-toggle:hover { background: var(--panel); color: var(--ink); }
footer { margin-top: 4rem; color: var(--muted); font-size: 0.85rem; }

/* Docs layout */
body.docs {
  display: grid;
  grid-template-columns: 210px minmax(0, 700px);
  gap: 3.5rem;
  justify-content: center;
  padding: 2.5rem 1.5rem 6rem;
}
body.docs main { min-width: 0; }

/* The sidebar scrolls on its own when it's taller than the window. The padding
   keeps room for the links' hover background, which hangs left of the text. */
.docs-nav {
  position: sticky;
  top: 0;
  align-self: start;
  max-height: 100vh;
  box-sizing: border-box;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  margin: -2.5rem -0.5rem 0;
  padding: 2.5rem 0.5rem 2rem;
  font: 0.86rem/1.5 var(--sans);
}
.docs-nav-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.docs-nav .brand { color: var(--ink); font-weight: 700; font-size: 1rem; text-decoration: none; }
/* Nav groups are <details>: click a heading to fold its links away. */
.docs-nav details { margin: 1.1rem 0 0; font-size: inherit; }
.docs-nav summary {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.3rem;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  list-style: none;
  user-select: none;
}
.docs-nav summary::-webkit-details-marker { display: none; }
.docs-nav summary::before {
  content: "";
  width: 0.35em;
  height: 0.35em;
  border: solid currentColor;
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(-45deg);
  transition: transform 0.15s;
}
.docs-nav details[open] > summary::before { transform: rotate(45deg); }
.docs-nav summary:hover { color: var(--ink); }
.docs-nav ul { margin: 0; padding: 0; list-style: none; }
.docs-nav a {
  display: block;
  padding: 0.12rem 0.5rem;
  margin-left: -0.5rem;
  border-radius: 5px;
  color: var(--ink);
  text-decoration: none;
}
.docs-nav a:hover { background: var(--panel); }
.docs-nav a[aria-current="page"] { background: var(--panel); color: var(--tangle-accent); font-weight: 600; }
.docs-nav code { background: none; padding: 0; }

.pager {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 4rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  font: 0.9rem var(--sans);
}
.pager a { text-decoration: none; }
.pager .next { margin-left: auto; text-align: right; }
.pager small { display: block; color: var(--muted); font-size: 0.75rem; }

@media (max-width: 900px) {
  body.docs { display: block; padding-top: 1.5rem; }
  .docs-nav { position: static; max-height: none; overflow: visible; margin: 0 0 2rem; padding: 0 0 1rem; border-bottom: 1px solid var(--line); }
  .docs-nav ul { display: flex; flex-wrap: wrap; gap: 0 1rem; }
}

/* Syntax highlighting */
.hl-punct, .hl-comment { color: var(--muted); }
.hl-comment { font-style: italic; }
.hl-tag { color: light-dark(#6f5cbd, #b9a8ff); }
.hl-tangle-tag { color: light-dark(#246bce, #75a7ff); font-weight: 600; }
.hl-attr, .hl-number, .hl-prop { color: light-dark(#b45b1b, #ffad66); }
.hl-string { color: light-dark(#147a68, #5ed5bd); }
.hl-tex, .hl-keyword, .hl-selector { color: light-dark(#a23b78, #f08bc2); }
.hl-marker { color: light-dark(#246bce, #75a7ff); font-weight: 700; }
.hl-call { color: light-dark(#246bce, #75a7ff); }
