/* =========================================================
   University Lab Notes — global stylesheet
   Reading-first layout: narrow measure, generous line-height,
   code/formula friendly, mobile-first, light+dark aware.
   ========================================================= */

:root {
  --color-bg: #ffffff;
  --color-bg-alt: #f4f6f8;
  --color-text: #1c2128;
  --color-text-muted: #57606a;
  --color-border: #d0d7de;
  --color-accent: #0b5fff;
  --color-accent-contrast: #ffffff;
  --color-code-bg: #f6f8fa;
  --color-ad-bg: #fafafa;
  --color-ad-border: #c9ccd1;
  --color-coffee-bg: #fff6e5;
  --color-coffee-border: #f0c869;

  --font-body: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;

  --measure: 42rem; /* ~720px, optimal reading line length */
  --header-height: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0d1117;
    --color-bg-alt: #161b22;
    --color-text: #e6edf3;
    --color-text-muted: #9aa4b2;
    --color-border: #30363d;
    --color-accent: #58a6ff;
    --color-accent-contrast: #0d1117;
    --color-code-bg: #161b22;
    --color-ad-bg: #12161c;
    --color-ad-border: #30363d;
    --color-coffee-bg: #241d0e;
    --color-coffee-border: #5c4a1a;
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--color-accent); }

img, video { max-width: 100%; }

/* ---------- Site header / nav (injected fragment lives here) ---------- */

#site-header {
  min-height: var(--header-height); /* reserves space to avoid layout shift while fetch() resolves */
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 1.25rem;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}

.site-brand {
  font-weight: 700;
  font-size: 1.1rem;
  text-decoration: none;
  color: var(--color-text);
}

.nav-toggle {
  display: inline-flex;
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  font-size: 1rem;
  color: var(--color-text);
}

.site-nav {
  display: none;
  position: absolute;
  top: var(--header-height);
  left: 0;
  right: 0;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  flex-direction: column;
  padding: 0.5rem 1.25rem 1rem;
}

.site-nav.is-open { display: flex; }

.site-nav a {
  padding: 0.6rem 0;
  text-decoration: none;
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
}

.site-nav a:last-child { border-bottom: none; }

.site-nav a.is-active { color: var(--color-accent); font-weight: 600; }

@media (min-width: 768px) {
  .nav-toggle { display: none; }

  .site-nav {
    display: flex;
    position: static;
    flex-direction: row;
    gap: 1.5rem;
    padding: 0;
    border: none;
    background: none;
  }

  .site-nav a { padding: 0; border: none; }
}

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

.page-shell {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

@media (min-width: 1100px) {
  .page-shell.with-toc {
    grid-template-columns: minmax(0, var(--measure)) 240px;
    justify-content: center;
  }
}

main.content {
  max-width: var(--measure);
  width: 100%;
  min-width: 0;
  margin: 0 auto;
}

@media (min-width: 1100px) {
  .page-shell.with-toc main.content { margin: 0; }
}

/* Table of contents (auto-generated by script.js, desktop only) */

.toc {
  display: none;
}

@media (min-width: 1100px) {
  .toc {
    display: block;
    align-self: start;
    position: sticky;
    top: calc(var(--header-height) + 1.5rem);
    font-size: 0.9rem;
    border-left: 2px solid var(--color-border);
    padding-left: 1rem;
  }

  .toc h2 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    margin: 0 0 0.5rem;
  }

  .toc ul { list-style: none; margin: 0; padding: 0; }
  .toc li { margin-bottom: 0.4rem; }
  .toc a { text-decoration: none; color: var(--color-text-muted); }
  .toc a:hover { color: var(--color-accent); }
}

/* ---------- Typography inside lab content ---------- */

.content h1 { font-size: 1.9rem; line-height: 1.3; margin-bottom: 0.25rem; }
.content h2 { font-size: 1.4rem; margin-top: 2.5rem; }
.content h3 { font-size: 1.15rem; margin-top: 2rem; }
.content p, .content ul, .content ol { margin: 1rem 0; }

.item-meta {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.breadcrumbs {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-bottom: 1rem;
}
.breadcrumbs a { color: inherit; }

pre {
  position: relative;
  background: var(--color-code-bg);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  font-size: 0.9rem;
}

code {
  font-family: var(--font-mono);
}

:not(pre) > code {
  background: var(--color-code-bg);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-size: 0.9em;
}

.copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  font-size: 0.75rem;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text-muted);
  cursor: pointer;
}
.copy-btn:hover { color: var(--color-text); }

blockquote {
  margin: 1.5rem 0;
  padding: 0.25rem 1rem;
  border-left: 3px solid var(--color-accent);
  color: var(--color-text-muted);
}

/* ---------- Ad slots ----------
   Kept in static HTML (not JS-injected) so crawlers see them
   on first paint. Swap the placeholder <div> contents for the
   real <ins class="adsbygoogle"> unit after AdSense approval. */

.ad-slot {
  margin: 2.5rem auto;
  max-width: var(--measure);
  min-height: 100px;
  background: var(--color-ad-bg);
  border: 1px dashed var(--color-ad-border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.ad-slot--banner { min-height: 100px; }
.ad-slot--rectangle { min-height: 250px; }
.ad-slot--multiplex { min-height: 300px; }

.ad-slot__label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
}

/* ---------- Support / tip widget ---------- */

.support-callout {
  margin: 2.5rem auto;
  max-width: var(--measure);
  padding: 1.5rem;
  border: 1px solid var(--color-coffee-border);
  background: var(--color-coffee-bg);
  border-radius: 10px;
  text-align: center;
}

.support-callout h2 {
  margin-top: 0;
  font-size: 1.1rem;
}

.support-btn {
  display: inline-block;
  margin-top: 0.75rem;
  padding: 0.7rem 1.4rem;
  background: #111;
  color: #fff;
  text-decoration: none;
  border-radius: 8px;
  font-weight: 600;
}

/* ---------- Content index cards (homepage + section landing pages) ---------- */

.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  max-width: var(--measure);
  margin: 2rem auto;
}

@media (min-width: 600px) {
  .card-grid { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 800px) {
  .card-grid--categories { grid-template-columns: repeat(3, 1fr); }
}

.item-card {
  display: block;
  padding: 1.25rem;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
  background: var(--color-bg-alt);
}

.item-card h3 { margin: 0 0 0.4rem; color: var(--color-text); }
.item-card p { margin: 0; color: var(--color-text-muted); font-size: 0.9rem; }

/* ---------- Footer ---------- */

.site-footer {
  border-top: 1px solid var(--color-border);
  padding: 2rem 1.25rem;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.85rem;
}

.site-footer a { color: var(--color-text-muted); }

.site-footer nav {
  margin-bottom: 0.5rem;
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}
