/* =====================================================================
   Telluris Labs — shared documentation styles
   Single source of truth for all package guide pages. Edit here once and
   every page updates. Palette and tokens follow the home page (index.html).
   ===================================================================== */

/* ---------- Design tokens ---------- */
:root {
  --brand: #11925c;            /* constant brand green (header), both themes */
  --brand-deep: #0c6f45;
  --radius: 8px;
  --maxw-content: 820px;
  --sidebar-w: 270px;
  --toc-w: 220px;
  --header-h: 96px;
  --subnav-h: 52px;
  --font-display: 'MuseoModerno', sans-serif;
  --font-body: 'Roboto', sans-serif;
  --font-mono: 'Roboto Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #F8F9FA;
  --surface: #F8F9FA;
  --surface-2: #eee;
  --surface-3: #F8F9FA;
  --text: #222222;
  --text-2: #8fbfd3; 
  --muted: #5a5f5c;
  --border: #e3e6e4;
  --accent: #11925c;
  --accent-soft: rgba(17, 146, 92, 0.10);
  --code-bg: #f4f6f5;
  --code-text: #1d3b2c;
  --code-border: #e3e6e4;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 8px 24px rgba(0, 0, 0, 0.04);
  --table-stripe: #fafbfa;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1411;
  --surface: #151c18;
  --surface-2: #1b2420;
  --surface-3: #1b2420;
  --text: #e7eae8;
  --text-2: #b8deec;
  --muted: #98a39d;
  --border: #27322c;
  --accent: #34c585;
  --accent-soft: rgba(52, 197, 133, 0.14);
  --code-bg: #121a15;
  --code-text: #b9e7cf;
  --code-border: #27322c;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 30px rgba(0, 0, 0, 0.35);
  --table-stripe: #18201c;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  min-height: 100%;
  background-color: var(--bg);
  transition: background-color 0.25s ease;
}

body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-weight: 300;
  line-height: 1.65;
  color: var(--text);
  background-color: var(--bg);
  transition: background-color 0.25s ease, color 0.25s ease;
  scroll-padding-top: calc(var(--subnav-h) + 16px);
}

a {
  font-family: var(--font-body);
  color: var(--accent);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

/* ---------- Header (matches index.html) ---------- */
header.site {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--brand);
  color: #ffffff;
  padding: 1rem 2rem;
  min-height: var(--header-h);
}
header.site img.logo { height: 64px; margin-right: 1rem; }
header.site .header-text {
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: left;
}
header.site h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 2.5rem;
  letter-spacing: 0.05em;
  margin: 0;
  line-height: 1.05;
}
header.site p {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 1.2rem;
  margin: 0;
  line-height: 1.05;
}
header.site a { color: #fff; font-family: var(--font-display); }
header.site a:hover { text-decoration: none; opacity: 0.9; }

/* ---------- Top navigation bar ---------- */
nav.subnav {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--subnav-h);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.25rem;
  background-color: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: saturate(140%);
}
nav.subnav .topnav-links {
  display: flex;
  align-items: center;
  gap: 0.15rem;
}
nav.subnav .topnav-links a {
  font-size: 0.95rem;
  color: var(--text);
  padding: 0.35rem 0.7rem;
  border-radius: var(--radius);
  transition: background 0.15s ease, color 0.15s ease;
}
nav.subnav .topnav-links a:hover { background: var(--surface-2); text-decoration: none; }
nav.subnav .topnav-links a.active { color: var(--accent); font-weight: 500; }
nav.subnav .spacer { flex: 1; }
.version-pill {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
  letter-spacing: 0.02em;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-3);
  color: var(--text);
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.1s ease;
}
.theme-toggle:hover { border-color: var(--accent); }
.theme-toggle:active { transform: scale(0.94); }
.theme-toggle svg { width: 18px; height: 18px; }
html[data-theme="light"] .theme-toggle .icon-moon { display: block; }
html[data-theme="light"] .theme-toggle .icon-sun { display: none; }
html[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
html[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

/* ---------- Layout grid (package pages with rails) ---------- */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  gap: 2rem;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1.5rem;
  align-items: start;
}

/* ---------- Left sidebar ---------- */
aside.sidebar {
  position: sticky;
  top: var(--subnav-h);
  height: calc(100vh - var(--subnav-h));
  overflow-y: auto;
  padding: 1.5rem 0.5rem 2rem 0;
  border-right: 1px solid var(--border);
}

.filter-wrap { padding: 0 0.5rem 1rem 0.25rem; }

.filter-input {
  width: 100%;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.7rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.filter-input::placeholder { color: var(--muted); }

.filter-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.filter-empty {
  display: none;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
}

/* ---------- TOC ---------- */

nav.toc-nav .nav-group {
  margin-bottom: 0.4rem;
}

/* Group headers */
nav.toc-nav .nav-group > a.group-label {
  display: block;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  padding: 0.85rem 0.75rem 0.3rem;
  text-decoration: none;
}

/* Subsection links */
nav.toc-nav .nav-group > a:not(.group-label) {
  display: block;
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--text-2);
  padding: 0.32rem 0.75rem;
  border-left: 2px solid transparent;
  border-radius: 0 var(--radius) var(--radius) 0;
  text-decoration: none;
  transition: background 0.15s ease,
              color 0.15s ease,
              border-color 0.15s ease;
}

/* Hover action */
nav.toc-nav .nav-group > a.group-label:hover,
nav.toc-nav .nav-group > a:not(.group-label):hover {
  background: var(--surface-2);
  text-decoration: none;
}

/* Active subsection indicator */
nav.toc-nav .nav-group > a:not(.group-label).active {
  color: var(--text-2);
  font-weight: 500;
  border-left-color: var(--accent);
  background: transparent;
}

nav.toc-nav a.hidden {
  display: none;
}

/* ---------- Main content ---------- */
main {
  min-width: 0;
  max-width: var(--maxw-content);
  padding: 2.25rem 0 4rem;
}
main section { scroll-margin-top: calc(var(--subnav-h) + 16px); }

main h1.page-title {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 2.5rem;
  letter-spacing: 0.03em;
  margin: 0 0 0.4rem;
  line-height: 1.1;
}
.lede {
  font-size: 1.12rem;
  color: var(--muted);
  margin: 0 0 2.25rem;
  max-width: 62ch;
}

main h2 {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 1.6rem;
  margin: 2.75rem 0 0.4rem;
  padding-left: 0.7rem;
  border-left: 4px solid var(--accent);
  scroll-margin-top: calc(var(--subnav-h) + 16px);
}
main h3 {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 1.12rem;
  margin: 1.8rem 0 0.3rem;
  color: var(--text);
}
main h3 code { font-size: 0.98rem; }
main p { margin: 0.6rem 0 1rem; max-width: 70ch; }
main ul, main ol { max-width: 70ch; }
main li { margin: 0.3rem 0; }

/* anchor link affordance on headings */
.anchor {
  margin-left: 0.4rem;
  font-size: 0.85em;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.15s ease;
}
h2:hover .anchor, h3:hover .anchor { opacity: 1; }

code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--code-border);
  border-radius: 5px;
  padding: 0.1rem 0.35rem;
}

.codeblock { position: relative; margin: 1rem 0 1.4rem; }
.codeblock pre {
  font-family: var(--font-mono);
  font-size: 0.84rem;
  line-height: 1.6;
  background: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin: 0;
  overflow-x: auto;
}
.codeblock pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
  color: inherit;
}
.codeblock .prompt { color: var(--accent); user-select: none; }
.codeblock .out { color: var(--muted); }
.copy-btn {
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  font-family: var(--font-body);
  font-size: 0.72rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.22rem 0.5rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.codeblock:hover .copy-btn { opacity: 1; }
.copy-btn:hover { color: var(--accent); border-color: var(--accent); }
.copy-btn.copied { color: var(--accent); border-color: var(--accent); }

/* function reference tables */
.fn-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0 1.4rem;
  font-size: 0.92rem;
}
.fn-table th, .fn-table td {
  text-align: left;
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.fn-table th {
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.fn-table tbody tr:nth-child(even) { background: var(--table-stripe); }
.fn-table td code { white-space: nowrap; }

/* callout / note box */
.note {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.85rem 1.1rem;
  margin: 1.2rem 0;
  font-size: 0.95rem;
}
.note strong { color: var(--accent); }

.pill-row { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0 1rem; }
.mod-pill {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
}

/* ---------- Function detail blocks (module pages) ---------- */
.fn-detail { padding-top: 0.4rem; }
.fn-detail h3 {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.1rem;
  border-top: 1px solid var(--border);
  padding-top: 1.4rem;
}
.eqn-meta {
  display: inline-block;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.72rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.05rem 0.55rem;
  margin-left: 0.55rem;
  letter-spacing: 0.01em;
}
.signature {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.84rem;
  color: var(--code-text);
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  padding: 0.55rem 0.8rem;
  margin: 0.5rem 0 0.8rem;
  overflow-x: auto;
}
dl.kv { margin: 0.4rem 0 1rem; }
dl.kv dt {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
  margin-top: 0.45rem;
}
dl.kv dd {
  margin: 0.05rem 0 0 1.1rem;
  color: var(--muted);
  font-size: 0.92rem;
}

/* ---------- Right "On this page" TOC ---------- */
aside.onthispage {
  position: sticky;
  top: var(--subnav-h);
  height: calc(100vh - var(--subnav-h));
  overflow-y: auto;
  padding: 2.25rem 0.25rem 2rem;
  font-size: 0.85rem;
}
aside.onthispage .otp-label {
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.6rem;
}
aside.onthispage a {
  display: block;
  color: var(--muted);
  padding: 0.22rem 0 0.22rem 0.7rem;
  border-left: 2px solid var(--border);
  transition: color 0.15s ease, border-color 0.15s ease;
}
aside.onthispage a:hover { color: var(--text); text-decoration: none; }
aside.onthispage a.active { color: var(--text); border-left-color: var(--accent); }
aside.onthispage a code { font-size: 0.82rem; background: none; border: none; padding: 0; color: inherit; }

/* ---------- Footer (matches index.html) ---------- */
footer.site {
  font-family: var(--font-body);
  font-weight: 300;
  font-size: 0.9rem;
  color: var(--muted);
  background-color: var(--surface-2);
  text-align: center;
  padding: 1rem;
  margin-top: 2rem;
}
footer.site div { margin: 0.2rem 0; }

/* Full-bleed wrapper paints the themed background itself, so it never
   depends on root/canvas background propagation (which an embedding
   iframe can interfere with). */
.page {
  background-color: var(--bg);
  min-height: 100vh;
  transition: background-color 0.25s ease;
}

/* ---------- Simple pages (home / about) — no rails ---------- */
.page.simple main {
  max-width: 820px;
  margin: 0 auto;
  padding: 2.25rem 1.5rem 3rem;
}
.page.simple .intro {
  font-size: 1.12rem;
  color: var(--text);
  margin-bottom: 1.5rem;
  max-width: 72ch;
}
.proj-list, .contact-list { list-style: none; padding-left: 0; }
.proj-list > li { margin-bottom: 1.4rem; }
.contact-list li { margin-bottom: 0.5rem; }

/* Source equation shown below each function signature (rendered with KaTeX) */
.equation {
  margin: 0.4rem 0 1.2rem;
  padding: 0.7rem 0.9rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  color: var(--text);
  overflow-x: auto;
}
.equation .eqn-name {
  display: block;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.8rem;
  color: var(--accent);
  margin-bottom: 0.4rem;
}
.equation .katex-eq {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--muted);
}
.equation .katex-display { margin: 0.2rem 0; text-align: left; }

/* Sections-menu toggle in the top nav (mobile, documentation pages only) */
.rail-toggle-nav {
  display: none;
  align-items: center;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 0.3rem 0.45rem;
  line-height: 1;
}
.rail-toggle-nav:hover { color: var(--accent); }
.rail-toggle-nav .caret {
  display: inline-block;
  font-size: 0.85rem;
  transition: transform 0.2s ease;
}
.rail-toggle-nav[aria-expanded="true"] .caret { transform: rotate(180deg); }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  .layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  aside.onthispage { display: none; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; padding: 0 1.1rem; }
  aside.sidebar {
    position: static;
    height: auto;
    overflow: visible;
    border-right: none;
    padding: 0;
  }
  .rail-toggle-nav { display: inline-flex; }
  .rail-body { display: none; }
  aside.sidebar.rail-open { border-bottom: 1px solid var(--border); padding: 0.7rem 0; }
  aside.sidebar.rail-open .rail-body { display: block; }
  header.site h1 { font-size: 2rem; letter-spacing: 0.03em; }
  header.site p { font-size: 1rem; margin-top: 0; }
  main { padding-top: 1.5rem; }
}

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