/* LSDB Field Guide — one hand-written stylesheet, no build step. */

:root {
  --bg:        #fbfaf8;
  --surface:   #ffffff;
  --text:      #1c1c1a;
  --muted:     #5f5e59;
  --border:    #e4e1da;
  --accent:    #1f5f8b;
  --accent-bg: #eaf2f8;
  --code-bg:   #f5f3ef;
  --code-text: #23252a;
  --warn-bg:   #fdf3e7;
  --warn-bd:   #d98324;
  --warn-tx:   #7a4a10;
  --on-accent: #ffffff;
  --hot-bg:    #fbeadb;
  --hot-tx:    #8a4b12;
  --radius: 7px;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

/* Dark tokens live in two places on purpose: the media query serves viewers who
   never touch the toggle, the attribute rule serves those who do. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #16171a;
    --surface:   #1d1f23;
    --text:      #e8e6e1;
    --muted:     #9b988f;
    --border:    #2f323a;
    --accent:    #84b6dd;
    --accent-bg: #1a2530;
    --code-bg:   #202329;
    --code-text: #e2e0da;
    --warn-bg:   #2b2116;
    --warn-bd:   #c07a2a;
    --warn-tx:   #f0c088;
    --hot-bg:    #33241a;
    --hot-tx:    #e0a065;
    --on-accent: #10161c;
  }
}

:root[data-theme="dark"] {
    --bg:        #16171a;
    --surface:   #1d1f23;
    --text:      #e8e6e1;
    --muted:     #9b988f;
    --border:    #2f323a;
    --accent:    #84b6dd;
    --accent-bg: #1a2530;
    --code-bg:   #202329;
    --code-text: #e2e0da;
    --warn-bg:   #2b2116;
    --warn-bd:   #c07a2a;
    --warn-tx:   #f0c088;
    --hot-bg:    #33241a;
    --hot-tx:    #e0a065;
    --on-accent: #10161c;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 5rem; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 50;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 1rem;
  padding: 0.7rem 1.5rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar__brand {
  justify-self: start; display: flex; align-items: center; gap: 0.55rem;
  font-weight: 650; letter-spacing: -0.01em; text-decoration: none; color: var(--text);
}
.topbar__brand img { width: 26px; height: 26px; display: block; }
.topbar__brand span { color: var(--muted); font-weight: 400; }

.topbar__nav {
  justify-self: center; display: flex; gap: 0.2rem;
  padding: 0.2rem; border: 1px solid var(--border); border-radius: 100px;
  background: var(--surface);
}
.topbar__nav a {
  padding: 0.35rem 1.5rem; border-radius: 100px; text-decoration: none;
  color: var(--muted); font-weight: 600; font-size: 0.95rem;
}
.topbar__nav a:hover { color: var(--text); }
.topbar__nav a[aria-current="page"] { background: var(--accent); color: var(--on-accent); }

.topbar__actions { justify-self: end; }
.themetoggle {
  display: grid; place-items: center; width: 2rem; height: 2rem;
  border: 1px solid var(--border); border-radius: 50%;
  background: var(--surface); color: var(--muted); cursor: pointer;
}
.themetoggle:hover { color: var(--accent); border-color: var(--accent); }
.themetoggle svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.themetoggle .sun { display: none; }
:root[data-theme="dark"] .themetoggle .sun { display: block; }
:root[data-theme="dark"] .themetoggle .moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .themetoggle .sun { display: block; }
  :root:not([data-theme="light"]) .themetoggle .moon { display: none; }
}

/* ---------- layout ---------- */

.shell {
  display: grid;
  grid-template-columns: 15rem minmax(0, 1fr);
  gap: 3rem;
  max-width: 68rem;
  margin: 0 auto;
  padding: 2rem 1.5rem 6rem;
}

.sidebar { position: sticky; top: 4.5rem; align-self: start; max-height: calc(100vh - 6rem); overflow-y: auto; }
.sidebar h2 {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.09em;
  color: var(--muted); margin: 0 0 0.75rem;
}
.sidebar ol { list-style: none; margin: 0; padding: 0; }
.sidebar li { margin: 0; }
/* Air between groups, so the eye lands on sections rather than scanning 31 lines. */
.sidebar li:not(.is-sub) { margin-top: 1.15rem; }
.sidebar li:first-child { margin-top: 0; }
.sidebar a { display: block; text-decoration: none; }

/* Section entries carry no rail: they are the things you scan for. */
.sidebar li:not(.is-sub) > a {
  padding: 0.2rem 0;
  color: var(--text); font-weight: 650; font-size: 0.93rem;
  letter-spacing: -0.005em;
}
.sidebar li:not(.is-sub) > a:hover,
.sidebar li:not(.is-sub) > a.is-active { color: var(--accent); }

/* Subsections hang off a rail, which now marks what belongs to what. */
.sidebar .is-sub > a {
  padding: 0.26rem 0 0.26rem 0.8rem;
  border-left: 2px solid var(--border);
  color: var(--muted); font-size: 0.85rem;
}
.sidebar .is-sub > a:hover { color: var(--text); border-left-color: var(--muted); }
.sidebar .is-sub > a.is-active { color: var(--accent); border-left-color: var(--accent); font-weight: 550; }

.content { min-width: 0; }

/* Start has no sidebar: one narrower column, centred. */
.shell--solo { grid-template-columns: minmax(0, 1fr); max-width: 48rem; }

/* ---------- doors into Do and Ask ---------- */

.doors { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem; margin: 2.75rem 0 3rem; }
.door {
  padding: 1.15rem 1.3rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.door h2 { margin: 0 0 0.45rem; font-size: 1.15rem; letter-spacing: -0.01em; }
.door h2 a { text-decoration: none; }
.door > p { margin: 0 0 0.85rem; color: var(--muted); font-size: 0.92rem; }
.door ul { margin: 0; padding: 0; list-style: none; }
.door li { margin-bottom: 0.3rem; }
.door li a { color: var(--muted); font-size: 0.9rem; text-decoration: none; }
.door li a::before { content: "\2192"; opacity: 0.5; margin-right: 0.4rem; }
.door li a:hover { color: var(--accent); }

@media (max-width: 40rem) {
  .doors { grid-template-columns: 1fr; }
}

/* ---------- page head ---------- */

.pagehead { margin-bottom: 2.5rem; }
.pagehead h1 { font-size: 2rem; letter-spacing: -0.02em; margin: 0 0 0.4rem; }
.pagehead p { color: var(--muted); margin: 0; max-width: 42rem; }
.pagehead p + p { margin-top: 0.7rem; }
.pagehead ul { margin: 1rem 0 0; padding: 0; list-style: none; max-width: 44rem; color: var(--muted); }
.pagehead li { position: relative; padding-left: 1.15rem; margin-bottom: 0.5rem; }
.pagehead li::before { content: "\2014"; position: absolute; left: 0; opacity: 0.45; }

/* ---------- sections ---------- */

/* The rule sits above the heading so it separates sections, rather than
   underlining a title. h2 doubles its size gap over h3 (1.7 vs 1.1). */
.section {
  border-top: 1px solid var(--border);
  padding-top: 2.25rem;
  margin-bottom: 4.5rem;
}
.section > h2 {
  font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em;
  margin: 0 0 1.25rem;
}
/* Bind the heading to its own content: big space above the rule, less below
   the title, so the section reads as one block rather than a floating label. */
.section > h2 + h3 { margin-top: 1.5rem; }
.section h3 {
  font-size: 1.1rem; font-weight: 650; letter-spacing: -0.005em;
  margin: 2.75rem 0 0.6rem;
}
.section p { max-width: 44rem; }
.section ul { max-width: 44rem; }

.anchor { color: var(--border); text-decoration: none; font-weight: 400; font-size: 0.65em; margin-left: 0.5rem; }
.section > h2:hover .anchor { color: var(--accent); }

/* ---------- snippets ---------- */

.snippet { margin: 1rem 0 1.25rem; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.snippet__bar {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.4rem 0.6rem 0.4rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.snippet__label { font-size: 0.8rem; color: var(--muted); margin-right: auto; }
.snippet pre { margin: 0; padding: 0.9rem 1rem; overflow-x: auto; background: var(--code-bg); }
.snippet code { font: 0.86rem/1.65 var(--mono); color: var(--code-text); }

/* Marks the line inside a snippet that actually costs something. The badge in the
   bar says a snippet computes; this says where. Used only when some lines in the
   snippet are cool -- if everything computes, the badge already told the whole
   story and tinting every line just looks like a rendering fault.
   The bolt is a pseudo-element, so it never lands in the clipboard or the a11y
   tree, and it declares .badge's font outright: inside <code> it would otherwise
   inherit --mono and resolve a different glyph than the badge it echoes. */
.snippet pre code { display: block; width: max-content; min-width: 100%; }

.snippet .hot {
  display: block; position: relative;
  margin-inline: -1rem;
  padding-left: calc(1rem - 2px); padding-right: 2.4rem;
  border-left: 2px solid var(--hot-tx);
  background: var(--hot-bg);
}
.snippet .hot::after {
  content: "\26A1";
  position: absolute; top: 0.1rem; right: 0.5rem;
  background: var(--surface); color: var(--hot-tx);
  border-radius: 100px; padding: 0.1rem 0.4rem;
  font-family: var(--sans); font-size: 0.72rem; font-weight: 550;
  line-height: 1.5; letter-spacing: 0.01em;
}

.copy {
  border: 1px solid var(--border); background: var(--surface);
  color: var(--muted); border-radius: 5px; padding: 0.2rem 0.55rem;
  font: 0.76rem var(--sans); cursor: pointer;
}
.copy:hover { color: var(--text); border-color: var(--accent); }

/* Points at a notebook where this operation is used. Deliberately says "used in"
   rather than "from": these snippets were written and run for this site, not
   lifted out of the notebooks. */
.snippet__src {
  display: inline-flex; align-items: center; gap: 0.35rem;
  color: var(--muted); font-size: 0.76rem; text-decoration: none; white-space: nowrap;
}
.snippet__src::before { content: "\25C6"; opacity: 0.5; font-size: 0.85em; }
.snippet__src:hover { color: var(--accent); }

@media (max-width: 40rem) { .snippet__src { display: none; } }
.copy.is-done { color: var(--accent); border-color: var(--accent); }

.output {
  margin: -0.9rem 0 1.25rem; padding: 0.7rem 1rem;
  border: 1px solid var(--border); border-top: 0;
  border-radius: 0 0 var(--radius) var(--radius);
  background: var(--bg); color: var(--muted);
  font: 0.8rem/1.55 var(--mono); white-space: pre; overflow-x: auto;
}

/* ---------- badges ---------- */

.badge {
  display: inline-block; padding: 0.1rem 0.5rem; border-radius: 100px;
  font: 550 0.72rem/1.5 var(--sans); letter-spacing: 0.01em; white-space: nowrap;
}
.badge--hot  { background: var(--hot-bg);  color: var(--hot-tx); }

/* ---------- callouts ---------- */

.callout {
  margin: 1.5rem 0; padding: 0.9rem 1.1rem;
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: var(--radius); background: var(--surface);
}
.callout p:first-child { margin-top: 0; }
.callout p:last-child { margin-bottom: 0; }
.callout__title {
  display: block; margin-bottom: 0.5rem;
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.09em;
  text-transform: uppercase; color: var(--muted);
}
.callout--warn { background: var(--warn-bg); border-color: var(--warn-bd); border-left-width: 3px; color: var(--warn-tx); }
.callout--warn .callout__title { color: var(--warn-tx); opacity: 0.95; }
.callout--warn code { background: color-mix(in srgb, var(--warn-bd) 18%, transparent); }

/* ---------- links out ---------- */

.links { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1.25rem; }
.links a {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.3rem 0.7rem; border: 1px solid var(--border); border-radius: 100px;
  background: var(--surface); color: var(--muted);
  font-size: 0.83rem; text-decoration: none;
}
.links a:hover { color: var(--accent); border-color: var(--accent); }
.links a::before { content: "→"; opacity: 0.55; }
.links a.link--nb::before { content: "◆"; }

/* ---------- starter strip ---------- */

.starter {
  margin-bottom: 3rem; padding: 1.25rem 1.4rem;
  border: 1px solid var(--accent); border-radius: var(--radius);
  background: var(--accent-bg);
}
.starter h2 { margin: 0 0 0.2rem; font-size: 1.1rem; }
.starter > p { margin: 0 0 0.9rem; color: var(--muted); font-size: 0.92rem; }
.starter .snippet { background: var(--surface); }

/* ---------- cards (Ask page) ---------- */

.figure { margin: 1.5rem 0; }
.figure svg { display: block; width: 100%; height: auto; }
.figure figcaption { margin-top: 0.6rem; color: var(--muted); font-size: 0.85rem; }

/* ---------- comparison tables ---------- */

.tablewrap { overflow-x: auto; margin: 1.25rem 0; }
.tablewrap table { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
.tablewrap th, .tablewrap td {
  text-align: left; padding: 0.55rem 0.8rem 0.55rem 0;
  border-bottom: 1px solid var(--border); vertical-align: top;
}
.tablewrap th {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); font-weight: 700;
}
.tablewrap td:first-child { font-weight: 600; white-space: nowrap; }

/* ---------- inline bits ---------- */

a { color: var(--accent); }
p code, li code, td code {
  background: var(--code-bg); padding: 0.1em 0.35em;
  border-radius: 4px; font: 0.88em var(--mono);
}

.footer { border-top: 1px solid var(--border); padding-top: 1.5rem; color: var(--muted); font-size: 0.9rem; }

/* ---------- responsive ---------- */

@media (max-width: 40rem) {
  .topbar { grid-template-columns: auto 1fr auto; padding: 0.6rem 0.9rem; gap: 0.6rem; }
  .topbar__brand span { display: none; }
  .topbar__nav a { padding: 0.35rem 1.1rem; }
}

@media (max-width: 52rem) {
  .shell { grid-template-columns: 1fr; gap: 1.5rem; padding-top: 1.25rem; }
  .sidebar { position: static; max-height: none; padding-bottom: 1rem; border-bottom: 1px solid var(--border); }
  .sidebar ol { display: flex; flex-wrap: wrap; gap: 0.3rem; }
  .sidebar li:not(.is-sub) { margin-top: 0; }
  .sidebar li:not(.is-sub) > a {
    padding: 0.25rem 0.7rem; font-size: 0.85rem;
    border: 1px solid var(--border); border-radius: 100px;
  }
  .sidebar li:not(.is-sub) > a.is-active { border-color: var(--accent); }
  .sidebar .is-sub { display: none; }
}
