/* ============================================================
   BLOG POST LAYOUT
   ============================================================ */

.post-layout {
  display: grid;
  grid-template-columns: 1fr 200px;
  gap: 3rem;
  align-items: start;
}

.post-main { min-width: 0; }

/* Post header */
.post-header { margin-bottom: 2.5rem; padding-bottom: 2rem; border-bottom: 1px solid var(--border); }
.post-title {
  font-family: var(--font-mono);
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.25;
  margin-bottom: 0.75rem;
}
.post-meta {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

/* Post body — uses serif for body text */
.post-body {
  font-family: var(--font-serif);
  font-size: 1rem;
  line-height: 1.85;
  color: var(--text);
}

.post-body h1,
.post-body h2,
.post-body h3,
.post-body h4 {
  font-family: var(--font-mono);
  margin-top: 2.5rem;
  margin-bottom: 0.75rem;
  line-height: 1.3;
}
.post-body h2 { font-size: 1.15rem; }
.post-body h3 { font-size: 1rem; }

.post-body p { margin-bottom: 1.25rem; }

.post-body ul, .post-body ol {
  margin: 0 0 1.25rem 1.5rem;
}
.post-body li { margin-bottom: 0.4rem; }

.post-body a { color: var(--accent); }
.post-body a:hover { color: var(--accent-hover); }

.post-body img {
  border-radius: var(--radius);
  margin: 1.5rem auto;
  border: 1px solid var(--border);
}

.post-body table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  margin: 1.5rem 0;
}
.post-body th, .post-body td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  text-align: left;
}
.post-body th { background: var(--surface); font-family: var(--font-mono); font-size: 0.78rem; }

/* Footnotes */
.post-body .footnotes {
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  color: var(--text-muted);
}
.post-body .footnotes ol { margin-left: 1.25rem; }
.post-body sup a {
  font-family: var(--font-mono);
  font-size: 0.7em;
  color: var(--accent);
  text-decoration: none;
  padding: 0 0.1em;
}

/* Sidenotes (right column) */
.post-sidenotes {
  font-family: var(--font-sans);
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.6;
}
.sidenote {
  border-left: 2px solid var(--border);
  padding-left: 0.75rem;
  margin-bottom: 1.25rem;
}
.sidenote-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--accent);
  display: block;
  margin-bottom: 0.2rem;
}

/* KaTeX overrides for theme */
.katex { font-size: 1em; }
.post-body .katex-display {
  display: block;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.5rem 0.25rem;
  margin: 1.25rem 0;
  max-width: 100%;
}
.post-body .katex-display > .katex {
  display: block;
  max-width: 100%;
  text-align: center;
}

/* ============================================================
   INLINE CITATION MARKERS  {% cite N %}
   ============================================================ */

.cite-marker {
  font-family: var(--font-mono);
  font-size: 0.7em;
  vertical-align: super;
  line-height: 0;
}
.cite-link {
  color: var(--accent);
  text-decoration: none;
}
.cite-link::before { content: "["; }
.cite-link::after  { content: "]"; }
.cite-link:hover { text-decoration: underline; }

/* ============================================================
   REFERENCES SECTION  (visually distinct from footnotes)
   Footnotes: explanatory asides, very small, plain text
   References: bibliographic entries, slightly larger, structured
   ============================================================ */

.post-references {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 2px solid var(--border);
}
.ref-heading {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 1rem;
}
.ref-list {
  list-style: none;
  padding: 0;
  margin: 0;
  counter-reset: ref-counter;
}
.ref-item {
  font-family: var(--font-sans);
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--text);
  padding: 0.5rem 0 0.5rem 2rem;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.ref-item:last-child { border-bottom: none; }
.ref-item::before {
  content: "[" counter(ref-counter) "]";
  counter-increment: ref-counter;
  position: absolute;
  left: 0;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent);
  top: 0.55rem;
}
.ref-authors {
  font-weight: 600;
  color: var(--text);
}
.ref-title {
  color: var(--text);
  font-style: italic;
}
a.ref-title {
  color: var(--accent);
  text-decoration: none;
}
a.ref-title:hover { text-decoration: underline; }
.ref-venue {
  color: var(--text-muted);
}

/* Post footer */
.post-footer {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}
.post-nav-link {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--accent);
  text-decoration: none;
}
.post-nav-link:hover { text-decoration: underline; }

/* Responsive: collapse sidenotes on small screens */
@media (max-width: 860px) {
  .post-layout {
    grid-template-columns: 1fr;
  }
  .post-sidenotes {
    position: static;
    border-top: 1px solid var(--border);
    padding-top: 1.5rem;
    margin-top: 2rem;
  }
  .post-title { font-size: 1.3rem; }
}

/* ============================================================
   INLINE MARGIN NOTES
   Float next to the paragraph they're defined in.
   ============================================================ */

.marginnote {
  /* On wide screens: hidden until JS moves it into the sidebar column.
     visibility:hidden keeps layout stable; JS switches to visible + absolute. */
  visibility: hidden;
  float: right;
  clear: right;
  width: 0;
  height: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
  /* Sidebar appearance (applied once JS sets position:absolute) */
  font-family: var(--font-sans);
  font-size: 0.75rem;
  line-height: 1.55;
  color: var(--text-muted);
  border-left: 2px solid var(--border);
  padding-left: 0.65rem;
}
/* JS adds position:absolute — restore normal sizing */
.marginnote[style*="position: absolute"] {
  visibility: visible;
  width: 100% !important;
  height: auto;
  overflow: visible;
  padding-left: 0.65rem;
  margin: 0;
  float: none;
}
.marginnote-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--accent);
  margin-bottom: 0.2rem;
}
/* Mobile: show inline, no sidebar column */
@media (max-width: 860px) {
  .marginnote {
    visibility: visible;
    float: none;
    position: static !important;
    width: auto !important;
    height: auto;
    overflow: visible;
    margin: 1rem 0 0.5rem;
    padding: 0.5rem 0 0 0.65rem;
    border-left: none;
    border-top: 1px solid var(--border);
  }
}

/* ============================================================
   DEMO EMBED (iframe-based)
   ============================================================ */

.demo-embed {
  margin: 1.5rem 0 2rem;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
.demo-embed iframe {
  display: block;
  width: 100%;
  height: 520px;
  border: none;
}
.demo-caption {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0.4rem 0.75rem;
  background: var(--surface);
}
