/* =========================================================================
   Lab notebook — stylesheet
   Design: refined, writing-first reading pages (nat.org-leaning) + a dense,
   scannable index/tag list (Damodaran-leaning). Light + dark, no web fonts.
   ========================================================================= */

/* ---- Design tokens ------------------------------------------------------ */
:root {
  --serif: Charter, "Iowan Old Style", "Palatino Linotype", Palatino,
    "Book Antiqua", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial,
    "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "Cascadia Mono",
    "Liberation Mono", Menlo, Consolas, monospace;

  color-scheme: light dark;

  --bg: #fbfbf9;
  --surface: #ffffff;
  --text: #1a1a18;
  --muted: #63635d;
  --faint: #6f6f69; /* darkened for WCAG AA (≈4.9:1 on --bg) */
  --rule: #e5e4dd;
  --rule-strong: #d3d2c8;
  --link: #1c4fb0;
  --link-hover: #0f2f74;
  --accent: #b5451f;
  --code-bg: #f4f3ee;
  --mark: #fdf3c4;

  --measure: 42rem; /* reading width */
  --wrap: 46rem; /* page frame width */
  --gap: clamp(1.1rem, 4vw, 1.6rem);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #191c21;
    --text: #e4e5e1;
    --muted: #a2a49c;
    --faint: #7f8179;
    --rule: #2a2e34;
    --rule-strong: #3a3f47;
    --link: #8fb6ff;
    --link-hover: #b8d1ff;
    --accent: #e8825b;
    --code-bg: #1f2329;
    --mark: #4a4327;
  }
}

/* Theming is driven entirely by prefers-color-scheme above (no JS toggle), so
   there is no data-theme override to keep in sync. */

/* ---- Reset-ish ---------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 18px;
  line-height: 1.65;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}
img,
svg,
video {
  max-width: 100%;
  height: auto;
}
a {
  color: var(--link);
  text-decoration-line: underline;
  text-decoration-thickness: 0.06em;
  text-underline-offset: 0.15em;
  text-decoration-color: color-mix(in srgb, var(--link) 40%, transparent);
}
a:hover {
  color: var(--link-hover);
  text-decoration-color: currentColor;
}
::selection {
  background: var(--mark);
  color: var(--text);
}
:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
  border-radius: 2px;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---- Layout frame ------------------------------------------------------- */
.wrap,
main {
  width: 100%;
  max-width: var(--wrap);
  margin-inline: auto;
  padding-inline: var(--gap);
}
main {
  padding-block: clamp(1.6rem, 5vw, 3rem);
  min-height: 60vh;
}
/* Reading pages get a slightly narrower, more comfortable measure. */
main.reading .post-body,
main.reading .page-head,
main.reading .post-header,
main.reading .post-footer,
main.reading > .about,
main.reading > p {
  max-width: var(--measure);
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--text);
  color: var(--bg);
  padding: 0.5rem 0.8rem;
  z-index: 10;
}
.skip-link:focus {
  left: 0.5rem;
  top: 0.5rem;
}

/* ---- Header ------------------------------------------------------------- */
.site-header {
  border-bottom: 1px solid var(--rule);
}
.site-header .wrap {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding-block: 1.05rem;
}
.site-title {
  font-family: var(--sans);
  font-weight: 650;
  font-size: 1.02rem;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
}
.site-title:hover {
  color: var(--accent);
}
.site-nav {
  display: flex;
  gap: 1.1rem;
  font-size: 0.95rem;
}
.site-nav a {
  color: var(--muted);
  text-decoration: none;
}
.site-nav a:hover {
  color: var(--text);
}
.site-nav a[aria-current="page"] {
  color: var(--text);
  font-weight: 600;
}

/* ---- Footer ------------------------------------------------------------- */
.site-footer {
  border-top: 1px solid var(--rule);
  margin-top: 3rem;
  padding-block: 1.6rem 2.4rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.footer-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
  margin-bottom: 0.6rem;
}
.footer-nav a {
  color: var(--muted);
  text-decoration: none;
}
.footer-nav a:hover {
  color: var(--text);
  text-decoration: underline;
}
.colophon {
  margin: 0;
  color: var(--faint);
}
.colophon a {
  color: inherit;
}

/* ---- Headings ----------------------------------------------------------- */
h1,
h2,
h3,
h4 {
  font-family: var(--sans);
  line-height: 1.2;
  letter-spacing: -0.015em;
  font-weight: 650;
}
h1 {
  font-size: clamp(1.7rem, 4.5vw, 2.15rem);
}
h2 {
  font-size: 1.4rem;
}
h3 {
  font-size: 1.12rem;
}

/* ---- Home / about ------------------------------------------------------- */
.home-name {
  margin: 0.2rem 0 0.6rem;
}
.lede {
  font-family: var(--serif);
  font-size: 1.18rem;
  line-height: 1.55;
  color: var(--text);
  margin: 0 0 1rem;
}
.bio {
  font-family: var(--serif);
  font-size: 1.06rem;
  line-height: 1.65;
  color: var(--text);
  margin: 0 0 1rem;
}
.contact {
  color: var(--muted);
  font-size: 0.98rem;
}
.home-writing {
  margin-top: 2.6rem;
  padding-top: 1.6rem;
  border-top: 1px solid var(--rule);
}
.home-writing-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}
.home-writing-head h2 {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}
.all-link {
  font-size: 0.9rem;
  text-decoration: none;
  color: var(--muted);
}
.all-link:hover {
  color: var(--link);
}

/* ---- Page heads (Writing, Tags) ---------------------------------------- */
.page-head {
  margin-bottom: 1.8rem;
}
.page-head h1 {
  margin: 0 0 0.4rem;
}
.page-intro {
  color: var(--muted);
  font-size: 0.98rem;
  margin: 0;
}
.crumb {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--faint);
  margin: 0 0 0.5rem;
}
.crumb a {
  color: inherit;
  text-decoration: none;
}
.crumb a:hover {
  color: var(--link);
}

/* ---- Post index (dense, scannable) ------------------------------------- */
.year-group {
  margin-bottom: 1.8rem;
}
.year-heading {
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--faint);
  letter-spacing: 0.03em;
  padding-bottom: 0.35rem;
  margin: 0 0 0.6rem;
  border-bottom: 1px solid var(--rule);
}
.post-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.post-row {
  display: grid;
  grid-template-columns: 6.2rem 1fr;
  gap: 0 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--rule);
}
.post-row:last-child {
  border-bottom: none;
}
.post-row-date {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--faint);
  padding-top: 0.28em;
  white-space: nowrap;
}
.post-row-title {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 1.02rem;
  color: var(--text);
  text-decoration: none;
  margin-right: 0.5rem;
}
.post-row-title:hover {
  color: var(--link);
  text-decoration: underline;
}
.post-row-summary {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

/* ---- Tags --------------------------------------------------------------- */
.tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.02em;
  text-transform: lowercase;
  color: var(--muted);
  background: color-mix(in srgb, var(--muted) 10%, transparent);
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  text-decoration: none;
  vertical-align: 0.08em;
  margin-right: 0.25rem;
  white-space: nowrap;
}
.tag:hover {
  color: var(--surface);
  background: var(--accent);
  border-color: var(--accent);
}

/* ---- Post page ---------------------------------------------------------- */
.post-header {
  margin-bottom: 1.7rem;
}
.post-title {
  margin: 0 0 0.55rem;
  line-height: 1.15;
}
.post-meta {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem 0.8rem;
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--faint);
}
.post-summary {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.1rem;
  color: var(--muted);
  margin: 0.9rem 0 0;
  padding-left: 0.9rem;
  border-left: 2px solid var(--rule-strong);
}

/* ---- Long-form body (the reading experience) --------------------------- */
.post-body {
  font-family: var(--serif);
  font-size: 1.09rem;
  line-height: 1.72;
}
.post-body > *:first-child {
  margin-top: 0;
}
.post-body p,
.post-body ul,
.post-body ol,
.post-body blockquote,
.post-body pre,
.post-body table,
.post-body details,
.post-body .katex-display {
  margin: 0 0 1.15rem;
}
.post-body h2,
.post-body h3,
.post-body h4 {
  font-family: var(--sans);
  margin: 2rem 0 0.7rem;
  scroll-margin-top: 1rem;
}
.post-body h2 {
  padding-bottom: 0.2rem;
  border-bottom: 1px solid var(--rule);
}
.post-body a {
  text-decoration-thickness: 0.05em;
}
.post-body ul,
.post-body ol {
  padding-left: 1.4rem;
}
.post-body li {
  margin-bottom: 0.35rem;
}
.post-body li > ul,
.post-body li > ol {
  margin: 0.35rem 0 0.35rem;
}
.post-body hr {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 2.2rem 0;
}
.post-body img {
  display: block;
  border-radius: 4px;
}
.post-body figure {
  margin: 1.6rem 0;
}
.post-body figcaption {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
  margin-top: 0.5rem;
}
.post-body strong {
  font-weight: 650;
}
.post-body mark {
  background: var(--mark);
  color: inherit;
  padding: 0 0.15em;
  border-radius: 2px;
}

/* Plain blockquotes (not callouts) */
.post-body blockquote {
  margin-inline: 0;
  padding: 0.1rem 0 0.1rem 1.1rem;
  border-left: 3px solid var(--rule-strong);
  color: var(--muted);
  font-style: italic;
}
.post-body blockquote p:last-child {
  margin-bottom: 0;
}

/* ---- Inline + block code (self-hosted Prism theme) --------------------- */
:not(pre) > code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--code-bg);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 0.08em 0.35em;
  overflow-wrap: break-word;
}
pre {
  font-family: var(--mono);
  font-size: 0.83rem;
  line-height: 1.55;
  background: var(--code-bg);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.9rem 1rem;
  overflow-x: auto;
}
pre[class*="language-"] {
  tab-size: 2;
}
pre > code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
  color: var(--text);
}

/* Prism tokens — tuned for both themes via variables. */
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
  color: var(--faint);
  font-style: italic;
}
.token.punctuation {
  color: var(--muted);
}
.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol,
.token.deleted {
  color: #b5451f;
}
.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
  color: #2f7d4f;
}
.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string {
  color: var(--muted);
}
.token.atrule,
.token.attr-value,
.token.keyword {
  color: #1c4fb0;
}
.token.function,
.token.class-name {
  color: #7a48b8; /* darkened for WCAG AA on --code-bg */
}
.token.regex,
.token.important,
.token.variable {
  color: var(--accent);
}
@media (prefers-color-scheme: dark) {
  .token.property,
  .token.tag,
  .token.boolean,
  .token.number,
  .token.constant,
  .token.symbol,
  .token.deleted {
    color: #e8956b;
  }
  .token.selector,
  .token.attr-name,
  .token.string,
  .token.char,
  .token.builtin,
  .token.inserted {
    color: #7fc99a;
  }
  .token.atrule,
  .token.attr-value,
  .token.keyword {
    color: #8fb6ff;
  }
  .token.function,
  .token.class-name {
    color: #c9a5ea;
  }
}

/* ---- Tables (valuation-friendly) --------------------------------------- */
.post-body table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: 0.9rem;
  display: block;
  overflow-x: auto;
}
.post-body thead th {
  text-align: left;
  border-bottom: 2px solid var(--rule-strong);
  padding: 0.45rem 0.7rem;
  font-weight: 650;
  white-space: nowrap;
}
.post-body tbody td {
  border-bottom: 1px solid var(--rule);
  padding: 0.4rem 0.7rem;
  vertical-align: top;
}
.post-body tbody tr:hover {
  background: color-mix(in srgb, var(--muted) 6%, transparent);
}
/* Right-align columns of numbers: mark them with align in Markdown ( ---: ).
   markdown-it emits this as inline style="text-align:right", so match that. */
.post-body td[style*="right"],
.post-body th[style*="right"] {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  font-size: 0.85rem;
}

/* ---- Callouts (Obsidian style) ----------------------------------------- */
.callout {
  --callout: #6b7280;
  background: var(--surface); /* fallback if color-mix() unsupported */
  background: color-mix(in srgb, var(--callout) 9%, var(--surface));
  border: 1px solid var(--rule); /* fallback */
  border: 1px solid color-mix(in srgb, var(--callout) 28%, var(--rule));
  border-left: 3px solid var(--callout);
  border-radius: 6px;
  padding: 0.7rem 0.95rem;
  font-family: var(--sans);
  font-size: 0.95rem;
  line-height: 1.6;
}
.callout > .callout-title {
  font-weight: 650;
  color: var(--callout);
  letter-spacing: 0.01em;
  margin-bottom: 0.35rem;
}
details.callout > summary.callout-title {
  cursor: pointer;
  list-style: none;
  margin-bottom: 0;
}
details.callout[open] > summary.callout-title {
  margin-bottom: 0.35rem;
}
details.callout > summary::-webkit-details-marker {
  display: none;
}
details.callout > summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 0.4em;
  font-size: 0.8em;
  transition: transform 0.15s ease;
}
details.callout[open] > summary::before {
  transform: rotate(90deg);
}
.callout > :last-child {
  margin-bottom: 0;
}
.callout p {
  margin: 0 0 0.6rem;
}
/* Type colours */
.callout-note,
.callout-info {
  --callout: #1c6fb0;
}
.callout-tip,
.callout-hint,
.callout-success,
.callout-check,
.callout-done {
  --callout: #2f8f57;
}
.callout-warning,
.callout-caution,
.callout-attention {
  --callout: #c88a12;
}
.callout-danger,
.callout-error,
.callout-fail,
.callout-failure,
.callout-bug {
  --callout: #c0392b;
}
.callout-question,
.callout-help,
.callout-faq {
  --callout: #8a5cc4;
}
.callout-quote,
.callout-cite,
.callout-example,
.callout-abstract,
.callout-summary,
.callout-tldr {
  --callout: #6b7280;
}
@media (prefers-color-scheme: dark) {
  .callout-note,
  .callout-info {
    --callout: #6aa9e8;
  }
  .callout-tip,
  .callout-hint,
  .callout-success,
  .callout-check,
  .callout-done {
    --callout: #6ec48d;
  }
  .callout-warning,
  .callout-caution,
  .callout-attention {
    --callout: #e0b452;
  }
  .callout-danger,
  .callout-error,
  .callout-fail,
  .callout-failure,
  .callout-bug {
    --callout: #e8776a;
  }
  .callout-question,
  .callout-help,
  .callout-faq {
    --callout: #c1a0e6;
  }
  .callout {
    --callout: #8b90a0;
  }
  .callout-quote,
  .callout-cite,
  .callout-example,
  .callout-abstract,
  .callout-summary,
  .callout-tldr {
    --callout: #9aa0ab;
  }
}

/* ---- Wikilinks ---------------------------------------------------------- */
.wikilink {
  text-decoration-style: dotted;
  text-decoration-thickness: 0.05em;
}

/* ---- Footnotes ---------------------------------------------------------- */
/* markdown-it-footnote emits its own <hr>; .footnotes already draws a top
   border, so hide the extra rule to avoid a double divider. */
.footnotes-sep {
  display: none;
}
.footnotes {
  margin-top: 2.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--muted);
}
.footnotes ol {
  padding-left: 1.2rem;
}
.footnote-ref a {
  text-decoration: none;
  font-size: 0.8em;
  vertical-align: super;
  padding: 0 0.1em;
}
.footnote-backref {
  text-decoration: none;
}

/* ---- KaTeX -------------------------------------------------------------- */
.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.4rem 0;
}
.katex {
  font-size: 1.03em;
}
/* A very long inline formula shouldn't force horizontal page scroll on mobile. */
.post-body :not(.katex-display) > .katex {
  display: inline-block;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}

/* ---- Post footer / prev-next ------------------------------------------- */
.post-footer {
  margin-top: 2.6rem;
  padding-top: 1.4rem;
  border-top: 1px solid var(--rule);
}
.post-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.2rem;
}
.post-nav a {
  display: block;
  font-family: var(--sans);
  font-size: 0.95rem;
  text-decoration: none;
  color: var(--text);
  line-height: 1.3;
}
.post-nav a:hover {
  color: var(--link);
}
.post-nav-next {
  text-align: right;
}
.post-nav-label {
  display: block;
  font-family: var(--mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--faint);
  margin-bottom: 0.15rem;
}
.post-back a {
  font-family: var(--sans);
  font-size: 0.9rem;
  color: var(--muted);
  text-decoration: none;
}
.post-back a:hover {
  color: var(--link);
}

.empty {
  color: var(--muted);
  font-style: italic;
}

/* ---- Responsive --------------------------------------------------------- */
@media (max-width: 34rem) {
  body {
    font-size: 17px;
  }
  .post-row {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }
  .post-row-date {
    padding-top: 0;
  }
  .post-nav {
    grid-template-columns: 1fr;
  }
  .post-nav-next {
    text-align: left;
  }
}

/* ---- Print -------------------------------------------------------------- */
@media print {
  .site-header,
  .site-footer,
  .post-nav,
  .post-back,
  .skip-link {
    display: none;
  }
  body {
    color: #000;
    background: #fff;
  }
  a {
    color: #000;
    text-decoration: underline;
  }
}
