/* ============================================================
   Complete-muE blog post — stylesheet
   Academic-magazine inspired: Newsreader serif body, Inter
   sans headings/UI, warm-cream surfaces with deep-teal accent.
   ============================================================ */

:root {
  /* Text */
  --fg: #1f1d1a;             /* warm near-black */
  --fg-muted: #6a6155;       /* warm muted gray */
  --fg-faint: #8a8275;       /* warm light gray, for captions */

  /* Surfaces */
  --bg: #fbfaf6;             /* page bg — warm off-white */
  --bg-soft: #f0ecdf;        /* warm beige-cream */
  --bg-soft-2: #f3efe3;      /* slightly lighter warm */
  --bg-callout: #e8efee;     /* pale teal-tinted neutral, harmonizes with accent */
  --bg-callout-headline: #f6e8c5; /* warm sand for TL;DR headline */
  --bg-hood: #efe9d8;        /* warm hood for "Under the hood" math */
  --bg-code: #ede7d8;        /* warm tan for inline code */

  /* Accent — deep teal */
  --accent: #1f5f5b;
  --accent-soft: #3a8a85;
  --accent-deep: #134541;
  --accent-warm: #b67b30;    /* caramel, complementary to teal */
  --accent-warm-light: #d6a45a;

  /* Structure */
  --rule: #d8d2c2;
  --rule-soft: #e6e0d0;

  /* Typography */
  --serif: "Newsreader", "Iowan Old Style BT", Georgia, "Times New Roman", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* Layout */
  --max: 720px;          /* main reading column width */
  --max-figure: 1100px;
  --max-layout: 1280px;  /* outer 2-col container */
  --toc-w: 210px;        /* fits double-digit "10."/"11." markers */
  --col-gap: 2.25rem;
  --sticky-top: 1.25rem;

  /* Sidenote area inside main column */
  --sidenote-w: 240px;
  --sidenote-area: 280px;  /* sidenote-w + gutter */
  --sidenote-gutter: 32px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--serif);
  color: var(--fg);
  background: var(--bg);
  line-height: 1.65;
  font-size: 18px;
  font-weight: 400;
  font-feature-settings: "kern" 1, "liga" 1;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid rgba(31, 95, 91, 0.28);
  transition: border-color 0.15s, color 0.15s;
}

a:hover {
  color: var(--accent-deep);
  border-bottom-color: var(--accent-deep);
}

/* ---------------- Post heading (centered, academic) ---------------- */

.post-heading {
  max-width: var(--max);
  margin: 4rem auto 1.5rem;
  padding: 0 1.25rem;
  text-align: center;
}

.post-heading .eyebrow {
  margin: 0;
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--accent);
}

.post-heading .post-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(2.4rem, 6vw, 3.4rem);
  letter-spacing: -0.015em;
  line-height: 1.08;
  margin: 0.7rem 0 0.4rem;
  color: var(--fg);
}

.post-heading .post-subtitle {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.15rem, 2.4vw, 1.4rem);
  color: var(--fg-muted);
  margin: 0 0 1.4rem;
  line-height: 1.4;
}

.post-heading .post-subtitle em {
  font-style: italic;
}

.publish-metadata {
  font-family: var(--sans);
  color: var(--fg-muted);
  margin: 0;
}

.publish-metadata .authors {
  margin: 0 0 0.25rem;
  font-size: 0.95rem;
  line-height: 1.7;
}

.publish-metadata .authors a {
  color: var(--fg);
  border-bottom: 1px dotted var(--rule);
  white-space: nowrap;
  margin: 0 0.35rem;
  font-weight: 500;
}

.publish-metadata .authors a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.publish-metadata .affil {
  margin: 0;
  font-size: 0.9rem;
  font-style: italic;
  color: var(--fg-faint);
}

/* Tagline below the cover figure */
.post-subtitle-tagline {
  max-width: var(--max);
  margin: 1.5rem auto 0;
  padding: 0 1.25rem;
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.18rem;
  color: var(--accent-deep);
  line-height: 1.5;
}

.post-subtitle-tagline em {
  font-style: italic;
  color: var(--accent-warm);
  font-weight: 500;
  font-style: normal;
}

/* ---------------- Cover figure (inline SVG) ---------------- */

figure.post-cover {
  max-width: var(--max-figure);
  margin: 2rem auto 0;
  padding: 0 1.25rem;
}

figure.post-cover svg {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
  border-radius: 8px;
  border: 1px solid var(--rule);
  box-shadow: 0 1px 3px rgba(31, 29, 26, 0.04);
}

figure.post-cover svg text {
  font-family: var(--sans);
}

figure.post-cover .label-italic {
  font-family: var(--serif);
  font-style: italic;
}

figure.post-cover figcaption {
  max-width: var(--max);
  margin: 0.8rem auto 0;
  color: var(--fg-muted);
  font-size: 0.92rem;
  text-align: center;
  line-height: 1.55;
  font-family: var(--serif);
  font-style: italic;
}

/* ---------------- 2-column layout: TOC | main (with reserved right margin for sidenotes) ---------------- */

.layout {
  max-width: var(--max-layout);
  margin: 1.5rem auto 0;
  padding: 0 1.25rem;
  display: grid;
  grid-template-columns: var(--toc-w) minmax(0, 1fr);
  gap: var(--col-gap);
  align-items: start;
}

.layout > main {
  /* Reserve right padding for sidenotes that float into it */
  padding: 0 var(--sidenote-area) 4rem 0;
  min-width: 0;
}

/* Left sidebar — sticky TOC */

.layout > aside.layout-toc {
  position: sticky;
  top: var(--sticky-top);
  align-self: start;
  max-height: calc(100vh - 2 * var(--sticky-top));
  overflow-y: auto;
  font-family: var(--sans);
  padding-right: 0.4rem;
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
}

.layout > aside.layout-toc::-webkit-scrollbar {
  width: 8px;
}

.layout > aside.layout-toc::-webkit-scrollbar-thumb {
  background: var(--rule);
  border-radius: 4px;
}

.sidebar-heading {
  margin: 0 0 0.7rem;
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-deep);
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--rule);
}

.layout-toc .toc {
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
}

.layout-toc .toc ol {
  margin: 0;
  padding-left: 1.9rem;     /* enough room for "10." "11." markers */
  columns: 1;
  list-style: decimal;
}

.layout-toc .toc li {
  margin: 0.32rem 0;
  font-size: 0.86rem;
  line-height: 1.4;
  padding-left: 0.15rem;
  break-inside: auto;
}

.layout-toc .toc li::marker {
  color: var(--fg-faint);
  font-variant-numeric: tabular-nums;
}

.layout-toc .toc li a {
  border-bottom-color: transparent;
  color: var(--fg-muted);
}

.layout-toc .toc li a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ---------------- Sidenotes (Tufte-style margin notes) ---------------- */

.sidenote {
  float: right;
  clear: right;
  width: var(--sidenote-w);
  /* Push into the reserved right padding of <main>. The negative margin
     equals -(sidenote-area), so the sidenote starts in the gutter and
     extends to the right edge of <main>. */
  margin-right: calc(-1 * var(--sidenote-area));
  margin-top: 0.15rem;
  margin-bottom: 0.9rem;
  margin-left: var(--sidenote-gutter);
  padding: 0 0 0 0.85rem;
  border-left: 2px solid var(--accent-soft);
  font-family: var(--sans);
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--fg-muted);
}

.sidenote em {
  color: var(--fg);
  font-style: italic;
}

.sidenote a {
  border-bottom: 1px dotted rgba(31, 95, 91, 0.4);
  white-space: nowrap;
}

.sn-num {
  display: inline-block;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  margin-right: 0.35em;
}

/* Inline superscript citation marker [N] becomes a small sans-serif sup */
sup.cite-mark {
  font-family: var(--sans);
  font-size: 0.7em;
  font-weight: 700;
  color: var(--accent);
  vertical-align: super;
  line-height: 0;
  margin-left: 0.05em;
  white-space: nowrap;
}

/* ---------------- Bottom References section ---------------- */

#references .references-intro {
  color: var(--fg-muted);
  font-size: 0.95rem;
  margin-bottom: 1rem;
  font-style: italic;
}

ol.references {
  list-style: decimal;
  padding-left: 1.6rem;
  margin-top: 1rem;
  font-size: 0.9rem;
  line-height: 1.55;
  font-family: var(--sans);
  color: var(--fg-muted);
}

ol.references li {
  margin-bottom: 0.65rem;
  padding-left: 0.25rem;
}

ol.references li::marker {
  color: var(--accent);
  font-weight: 600;
}

ol.references em {
  color: var(--fg);
  font-style: italic;
}

ol.references a {
  border-bottom: 1px dotted rgba(31, 95, 91, 0.35);
}

/* Responsive: collapse to single column, sidenotes display inline */

@media (max-width: 1180px) {
  .layout {
    display: block;
    max-width: var(--max);
    padding: 0 1.25rem;
  }
  .layout > main {
    padding: 0 0 2rem;
  }
  .layout > aside.layout-toc {
    position: static;
    max-height: none;
    overflow-y: visible;
    padding-right: 0;
    margin: 1.5rem 0;
    background: var(--bg-soft);
    border: 1px solid var(--rule);
    border-radius: 8px;
    padding: 1rem 1.25rem;
  }
  .layout-toc .toc ol {
    columns: 2;
    column-gap: 1.75rem;
    padding-left: 2rem;
  }
  .layout-toc .toc li {
    break-inside: avoid;
  }
  /* Sidenotes drop inline as styled callout boxes */
  .sidenote {
    float: none;
    clear: none;
    width: auto;
    margin: 0.7rem 0;
    padding: 0.55rem 0.9rem;
    background: var(--bg-soft-2);
    border-left: 3px solid var(--accent-soft);
    border-radius: 0 4px 4px 0;
    font-size: 0.86rem;
    display: block;
  }
}

@media (max-width: 600px) {
  .layout-toc .toc ol {
    columns: 1;
  }
}

section {
  margin: 3rem 0;
  scroll-margin-top: 1rem;
}

section:first-of-type {
  margin-top: 2rem;
}

h2 {
  font-family: var(--sans);
  font-size: 1.55rem;
  font-weight: 600;
  margin: 0 0 1rem;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.5rem;
  letter-spacing: -0.01em;
  color: var(--fg);
}

h3 {
  font-family: var(--sans);
  font-size: 1.12rem;
  font-weight: 600;
  margin: 1.9rem 0 0.65rem;
  color: var(--fg);
  letter-spacing: -0.005em;
}

p {
  margin: 0.9rem 0;
}

strong {
  font-weight: 600;
  color: var(--fg);
}

em {
  font-style: italic;
}

ul, ol {
  padding-left: 1.4rem;
}

ul li, ol li {
  margin: 0.4rem 0;
}

code {
  font-family: "SF Mono", "Menlo", Consolas, monospace;
  font-size: 0.9em;
  background: var(--bg-code);
  padding: 0.1em 0.35em;
  border-radius: 3px;
  color: var(--accent-deep);
}

/* Citation code blocks (natural-language citation + BibTeX) */
pre.citation-text,
pre.bibtex {
  background: var(--bg-hood);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 0.95rem 1.1rem;
  margin: 0.5rem 0 1.1rem;
  font-size: 0.82rem;
  line-height: 1.55;
  font-family: "SF Mono", "Menlo", Consolas, monospace;
  color: var(--fg);
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
}

/* Natural-language citation: prose, so wrap softly */
pre.citation-text {
  white-space: pre-wrap;
  word-break: break-word;
}

/* BibTeX: preserve indentation and let long lines scroll horizontally */
pre.bibtex {
  white-space: pre;
  overflow-x: auto;
}

pre.citation-text code,
pre.bibtex code {
  background: transparent;
  padding: 0;
  border-radius: 0;
  color: inherit;
  font-size: inherit;
  font-family: inherit;
}

pre.bibtex::-webkit-scrollbar {
  height: 8px;
}

pre.bibtex::-webkit-scrollbar-thumb {
  background: var(--rule);
  border-radius: 4px;
}

/* ---------------- Callouts ---------------- */

.callout {
  background: var(--bg-callout);
  border-left: 4px solid var(--accent);
  padding: 1rem 1.2rem;
  border-radius: 4px;
  margin: 1.3rem 0;
}

.callout p {
  margin: 0.5rem 0;
}

.callout.headline {
  background: var(--bg-callout-headline);
  border-left-color: var(--accent-warm);
  font-size: 1.04rem;
}

.under-hood {
  background: var(--bg-hood);
  border: 1px solid #d6cdb6;
  border-radius: 6px;
  padding: 0.9rem 1.1rem;
  margin: 1rem 0;
  font-size: 0.96rem;
}

.under-hood .hood-label {
  margin: 0 0 0.4rem;
  font-family: var(--sans);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-deep);
}

.audience-note {
  background: var(--bg-soft-2);
  border-left: 3px solid var(--accent-warm);
  padding: 0.8rem 1rem;
  border-radius: 4px;
  font-size: 0.94rem;
  margin-top: 1rem;
  font-family: var(--sans);
}

/* ---------------- Layout helpers ---------------- */

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin: 1.3rem 0;
}

.two-col > div {
  background: var(--bg-soft-2);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 1rem 1.1rem;
}

.two-col h3 {
  margin-top: 0;
  font-size: 1.02rem;
  color: var(--accent);
}

@media (max-width: 700px) {
  .two-col {
    grid-template-columns: 1fr;
  }
  .toc ol {
    columns: 1;
  }
}

/* ---------------- Figures with images ---------------- */

main figure {
  margin: 1.5rem 0;
}

main figure img {
  width: 100%;
  height: auto;
  display: block;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: #fff;
}

main figure figcaption {
  margin-top: 0.6rem;
  color: var(--fg-muted);
  font-size: 0.9rem;
  line-height: 1.55;
  font-style: italic;
}

.img-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.img-pair img {
  margin: 0;
}

.img-grid-4x2 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem;
}

.img-grid-4x2 img {
  margin: 0;
}

.img-trio {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.img-trio img {
  margin: 0;
}

@media (max-width: 800px) {
  .img-grid-4x2 {
    grid-template-columns: repeat(2, 1fr);
  }
  .img-trio {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .img-pair {
    grid-template-columns: 1fr;
  }
  .img-grid-4x2 {
    grid-template-columns: 1fr;
  }
}

/* ---------------- Tables ---------------- */

.table-scroll {
  overflow-x: auto;
  margin: 1rem 0;
}

table {
  border-collapse: collapse;
  font-size: 0.88rem;
  width: 100%;
  background: #fff;
  font-family: var(--sans);
}

table caption {
  caption-side: top;
  text-align: left;
  font-style: italic;
  color: var(--fg-muted);
  font-size: 0.9rem;
  padding-bottom: 0.5rem;
  font-family: var(--serif);
}

table th, table td {
  border: 1px solid var(--rule);
  padding: 0.5rem 0.7rem;
  text-align: left;
}

table th {
  background: var(--bg-soft);
  font-weight: 600;
  white-space: nowrap;
  color: var(--fg);
}

table.benchmark td:not(:first-child) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

table.benchmark th:not(:first-child) {
  text-align: right;
}

table.benchmark tbody tr:nth-child(even) {
  background: var(--bg-soft-2);
}

/* ---------------- Tuning menu ---------------- */

.menu-block {
  background: var(--bg-soft-2);
  border-left: 4px solid var(--accent-soft);
  border-radius: 0 6px 6px 0;
  padding: 0.95rem 1.2rem;
  margin: 1.1rem 0;
}

.menu-section-label {
  margin: 0 0 0.5rem;
  font-family: var(--sans);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-deep);
}

.menu-tight {
  margin: 0;
  padding-left: 1.25rem;
}

.menu-tight li {
  margin: 0.27rem 0;
}

.menu-tight.keep li {
  list-style-type: '✓ ';
  padding-left: 0.2rem;
}

table.tuning-menu {
  background: #fff;
}

table.tuning-menu code {
  background: transparent;
  padding: 0;
  font-size: 0.95em;
  color: var(--accent-deep);
}

table.tuning-menu td:nth-child(2) {
  white-space: nowrap;
}

.menu-takeaway {
  background: var(--bg-callout);
  border-left: 4px solid var(--accent);
  padding: 0.8rem 1rem;
  border-radius: 0 4px 4px 0;
  margin-top: 1.2rem;
  font-style: italic;
  color: var(--fg);
}

.menu-sub {
  color: var(--fg-muted);
  font-size: 0.85em;
  font-style: italic;
}

.menu-note {
  margin: 0.75rem 0 0;
  font-size: 0.9rem;
  color: var(--fg);
  line-height: 1.55;
}

@media (max-width: 600px) {
  table.tuning-menu td:nth-child(2) {
    white-space: normal;
  }
  table {
    font-size: 0.8rem;
  }
  table th, table td {
    padding: 0.35rem 0.45rem;
  }
}

/* ---------------- Badges ---------------- */

.badge {
  display: inline-block;
  font-family: var(--sans);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.18rem 0.5rem;
  border-radius: 3px;
  white-space: nowrap;
}

.badge.exact {
  background: #d4dec7;
  color: #2c4519;
}

.badge.approx {
  background: #f0dba7;
  color: #5e4310;
}

/* ---------------- Recipe block ---------------- */

.recipe {
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 8px;
  padding: 1.35rem 1.5rem;
  margin: 1.5rem 0;
  box-shadow: 0 1px 3px rgba(31, 95, 91, 0.06);
}

.recipe ol {
  margin: 0;
  padding-left: 1.4rem;
}

.recipe li {
  margin: 0.7rem 0;
}

/* ---------------- Takeaways ---------------- */

.takeaway-list {
  list-style: none;
  padding-left: 0;
}

.takeaway-list li {
  background: var(--bg-soft-2);
  border-left: 4px solid var(--accent-soft);
  padding: 0.8rem 1rem;
  margin: 0.6rem 0;
  border-radius: 0 4px 4px 0;
}

/* ---------------- Inline reference links [1], [2] etc ---------------- */

section ul li a[href^="#ref-"],
section p a[href^="#ref-"],
section ol li a[href^="#ref-"] {
  border-bottom: none;
  color: var(--accent);
  font-family: var(--sans);
  font-size: 0.78em;
  font-weight: 600;
  vertical-align: baseline;
  padding: 0 0.05em;
}

section a[href^="#ref-"]:hover {
  color: var(--accent-deep);
  text-decoration: underline;
}

.contact {
  margin-top: 1rem;
  color: var(--fg-muted);
  font-size: 0.95rem;
}

/* ---------------- Math ---------------- */

mjx-container {
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
}

mjx-container[display="true"] {
  margin: 0.5rem 0;
}

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

footer {
  max-width: var(--max);
  margin: 2rem auto 3rem;
  padding: 1rem 1.25rem;
  font-family: var(--sans);
  font-size: 0.88rem;
  color: var(--fg-muted);
  border-top: 1px solid var(--rule);
  text-align: center;
}
