/* Blog post specific styles */
#main.post .post-title {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 38px;
  max-width: 900px;
  margin: 1.25rem auto 0.15rem;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

/* Link styling for blog post content - explicitly gray not blue */
#main.post article.content a:not(.heading-anchor):not(.footnote-ref) {
  color: #555;
  text-decoration-color: #999;
}

#main.post article.content a:not(.heading-anchor):not(.footnote-ref):hover {
  color: #333;
  text-decoration-color: #666;
}

#main.post .post-subtitle {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 24px;
  color: var(--fg4);
  margin-top: 0.5rem;
  margin-bottom: 1rem;
  font-style: italic;
}

#in-the-news .news-outlets-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 3rem;
  align-items: center;
}

#in-the-news .news-outlet-link {
  display: block;
}

#in-the-news .news-outlet-logo {
  height: 50px;
  width: auto;
  display: block;
  opacity: 0.6;
  filter: grayscale(100%) brightness(0);
  transition: all 0.2s ease-in-out;
}

#in-the-news .news-outlet-logo:hover,
#in-the-news .news-outlet-link:focus-visible .news-outlet-logo {
  opacity: 1;
  filter: grayscale(0%) brightness(1);
}

#main.post .post-heading {
  text-align: center;
}

#main.post .post-heading .publish-metadata {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: var(--fg3);
  font-size: 15px;
  line-height: 20px;
  margin-top: 0.25rem;
  margin-bottom: 1.25rem;
  font-family: var(--font-sans);
}

/* If a cover exists after the heading, remove extra bottom margin on metadata */
#main.post .post-heading:has(~ .post-cover) .publish-metadata {
  margin-bottom: 0rem;
}

#main.post .post-heading .publish-metadata .author {
  font-size: 15px;
  line-height: 21px;
  letter-spacing: 0.24px;
  color: var(--fg);
  font-family: var(--font-sans);
  text-transform: none;
  display: block;
}

/* Author link styling on single post only */
#main.post .post-heading .publish-metadata .author a {
  color: inherit;
  text-decoration: none;
}

#main.post .post-heading .publish-metadata .author a:hover {
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--fg) 20%, transparent);
  text-underline-offset: 2px;
}

#main.post .post-heading .publish-metadata svg {
  display: inline-block;
  margin: auto;
}

#main.post .post-heading .publish-metadata > span {
  display: inline-block;
  padding-top: 0.6em;
  font-family: var(--font-sans);
}

#main.post article h1,
#main.post article.content h2,
#main.post article.content h3,
#main.post article.content h4,
#main.post article.content h5,
#main.post article.content h6 {
  font-family: var(--font-heading);
}

#main.post article h1 {
  font-weight: 700;
  font-size: 30px;
  line-height: 1.35;
  text-align: left;
}

/* Post cover image styling */
#main.post .post-cover {
  text-align: center;
  margin: 1.25rem 0;
}

#main.post .post-cover svg {
  display: block;
  width: 80%;
  max-width: min(80%, 100vw);
  height: auto;
  margin-left: auto;
  margin-right: auto;
}

#main.post .post-cover .cover-image {
  max-width: 100%;
  height: auto;
  border-radius: 0;
  box-shadow: none;
}

#main.post--the-poetics-nobody-taught .post-cover {
  margin: 1rem auto 1.5rem;
}

#main.post--the-poetics-nobody-taught .post-cover .cover-image {
  display: block;
  width: min(100%, 920px);
  margin: 0 auto;
  aspect-ratio: 1518 / 682;
  object-fit: cover;
  object-position: center;
}

/* Post cover buttons */
#main.post .post-paper-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  margin: 0.25rem 0 1.25rem;
}

#main.post .post-paper-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem 0.9rem;
  border: 1px solid color-mix(in srgb, var(--fg) 70%, var(--bg) 30%);
  border-radius: 999px;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--bg);
  background-color: color-mix(in srgb, var(--fg) 88%, var(--bg) 12%);
  text-decoration: none;
  transition: color 0.2s ease-in-out, border-color 0.2s ease-in-out, background-color 0.2s ease-in-out;
}

#main.post .post-paper-button:hover {
  color: var(--bg);
  border-color: color-mix(in srgb, var(--fg) 80%, var(--bg) 20%);
  background-color: color-mix(in srgb, var(--fg) 95%, var(--bg) 5%);
}

/* End-of-post CTA block (optional; driven by post frontmatter) */
#main.post .post-cta {
  /* Keep CTA subtle and consistent with the blog's minimal callout style */
  max-width: 680px;
  margin: 2.25rem auto 1.75rem;
  padding: 1.1rem 1.25rem;
  border: 1px solid color-mix(in srgb, var(--fg4) 18%, var(--bg) 82%);
  border-radius: 12px;
  background: color-mix(in srgb, var(--fg4) 6%, var(--bg) 94%);
  font-family: var(--font-sans);
}

#main.post .post-cta-title {
  margin: 0 0 0.55rem;
  font-family: var(--font-heading);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

#main.post .post-cta-body {
  margin: 0 0 0.9rem;
  font-size: 16px;
  line-height: 1.7;
  color: var(--fg3);
}

/* CTA form layout */
#main.post .post-cta--form .post-cta-body {
  margin-bottom: 1.1rem;
}

#main.post .post-cta--form .input {
  /* Inputs should read as "paper" sitting on top of the CTA panel. */
  background: #fff;
}

.darkmode #main.post .post-cta--form .input {
  background: color-mix(in srgb, var(--bg) 86%, var(--fg) 14%);
}

#main.post .collab-form {
  display: grid;
  gap: 0.9rem;
}

#main.post .collab-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem;
}

#main.post .collab-interests {
  border: 0;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.7rem;
}

#main.post .collab-interests legend {
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--fg2);
  margin-bottom: 0.2rem;
}

#main.post .collab-interest-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem 0.95rem;
}

#main.post .collab-checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--fg2);
  cursor: pointer;
  user-select: none;
}

#main.post .collab-checkbox input[type="checkbox"] {
  position: static;
  opacity: 1;
  width: 16px;
  height: 16px;
  accent-color: color-mix(in srgb, var(--fg) 85%, var(--bg) 15%);
}

#main.post .collab-checkbox span {
  display: inline-block;
}

#main.post .collab-honey {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

#main.post .collab-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

#main.post .collab-status {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--fg4);
  text-align: center;
}

#main.post .collab-status a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--fg4) 40%, transparent);
  text-underline-offset: 2px;
}

#main.post .collab-status a:hover {
  color: var(--fg2);
  text-decoration-color: color-mix(in srgb, var(--fg2) 35%, transparent);
}

#main.post .collab-status:empty {
  display: none;
}

#main.post .collab-status.is-info {
  color: var(--fg4);
}

#main.post .collab-status.is-error {
  color: var(--red);
}

#main.post .collab-status.is-success {
  color: color-mix(in srgb, var(--green) 70%, var(--fg) 30%);
}

@media (max-width: 700px) {
  #main.post .collab-grid {
    grid-template-columns: 1fr;
  }
  #main.post .collab-interest-list {
    grid-template-columns: 1fr;
  }
}

/* Inline figure images inside posts */
#main.post article.content .post-figure {
  margin: 1.5rem 0;
}

#main.post article.content .post-figure img {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 auto;
}

#main.post article.content .post-figure__link {
  display: block;
}

#main.post article.content .post-figure--enlarge img {
  cursor: zoom-in;
}

#main.post article.content .post-figure__caption {
  margin-top: 0.5rem;
  font-family: var(--font-serif);
  font-size: 14px;
  line-height: 1.5;
  color: var(--fg4);
  text-align: center;
}

#main.post article.content .post-figure__caption-text + .post-figure__credit::before {
  content: " — ";
}

#main.post article.content .post-figure__credit a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--fg4) 40%, transparent);
  text-underline-offset: 2px;
}

#main.post article.content .post-figure--full {
  width: 100%;
}

#main.post article.content .post-figure--wide {
  width: min(1100px, calc(100vw - 2rem));
  max-width: none;
  margin-left: 50%;
  transform: translateX(-50%);
}

#main.post article.content .post-figure--center {
  max-width: 640px;
  margin-left: auto;
  margin-right: auto;
}

#main.post article.content .post-figure--left,
#main.post article.content .post-figure--right {
  width: 55%;
  margin-top: 0.4rem;
  margin-bottom: 0.8rem;
}

#main.post article.content .post-figure--left {
  float: left;
  margin-right: 1.25rem;
}

#main.post article.content .post-figure--right {
  float: right;
  margin-left: 1.25rem;
}

@media (max-width: 900px) {
  #main.post article.content .post-figure--wide {
    width: 100%;
    max-width: 100%;
    margin-left: 0;
    transform: none;
  }

  #main.post article.content .post-figure--left,
  #main.post article.content .post-figure--right {
    float: none;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
  }
}

/* Blog post specific layout adjustments */
#main.post {
  margin-left: auto;
  margin-right: auto;
  max-width: 950px; /* Base width for smaller viewports */
  position: relative;
  /* Shared margin variables for sidenotes and left TOC */
  --sidenote-width: 200px;
  --sidenote-gap: 28px;
  /* Slightly narrower TOC than sidenotes */
  --toc-width: var(--sidenote-width);
  /* Make TOC gap a bit wider than sidenote gap */
  --toc-gap: calc(var(--sidenote-gap) + 6px);
}

/* Increase container width as sidenotes grow */
@media (min-width: 1200px) {
  #main.post {
    max-width: 970px;
    --sidenote-width: 210px;
  }
}

@media (min-width: 1400px) {
  #main.post {
    max-width: 990px;
    --sidenote-width: 220px;
  }
}

@media (min-width: 1600px) {
  #main.post {
    max-width: 1010px;
    --sidenote-width: 250px;
  }
}

@media (min-width: 1800px) {
  #main.post {
    max-width: 1030px;
    --sidenote-width: 280px;
  }
}

/* Center the article content independently */
#main.post article.content {
  margin-left: auto;
  margin-right: auto;
  max-width: 680px;
  position: relative; /* Anchor for absolute-positioned left toc */
  overflow: visible;
}

/* Counter for figures and sidenotes */
#main.post {
  counter-reset: sidenote-counter figure-counter;
}

/* Sidenotes and margin notes - use float for automatic stacking */
#main.post .sidenote,
#main.post .marginnote {
  float: right;
  clear: right; /* Each note clears previous right-floated elements */
  /* Base values for smaller viewports */
  --sidenote-width: 200px;
  --sidenote-gap: 28px; /* Gap between content and sidenote */
  width: var(--sidenote-width);
  margin-right: calc(-1 * var(--sidenote-width) - var(--sidenote-gap));
  margin-left: var(--sidenote-gap);
  margin-top: 0.3rem;
  margin-bottom: 14px; /* Space between stacked notes */
  font-size: 0.9rem;
  line-height: 1.4;
  vertical-align: baseline;
  position: relative;
}

/* Reduce gap between lists followed by a heading while still clearing floats */
#main.post article.content ul + h3,
#main.post article.content ol + h3,
#main.post article.content ul + h2,
#main.post article.content ol + h2 {
  margin-top: 0.8rem;
  clear: none; /* allow flowing near floats unless heading has its own reasons to clear */
}

/* Left margin Table of Contents (TOC) */
#main.post .left-toc {
  position: absolute;
  top: 10px;
  left: calc(-1 * var(--toc-width) - var(--toc-gap));
  width: var(--toc-width);
  margin: 0;
  font-family: var(--font-serif);
  font-size: 14px;
  line-height: 1.4;
  color: var(--fg2);
}

#main.post .left-toc .toc-list {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

#main.post .left-toc .toc-item {
  margin: 0 0 0.25rem 0;
}

#main.post .left-toc a {
  display: block;
  color: var(--fg5);
  text-decoration: none;
  transition: color 0.2s ease-in-out, opacity 0.2s ease-in-out;
  position: relative;
}

#main.post .left-toc a:hover {
  color: var(--fg1);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--fg1) 20%, var(--bg) 20%);
  text-underline-offset: 2px;
}

#main.post .left-toc .toc-level-2 {
  padding-left: 0.75rem;
}

#main.post .left-toc .toc-level-3 {
  padding-left: 1.25rem;
  color: var(--fg5);
}

#main.post .left-toc .toc-level-4 {
  padding-left: 1.75rem;
  color: var(--fg5);
  font-size: 13px;
}

#main.post .left-toc .toc-level-5 {
  padding-left: 2.25rem;
  color: var(--fg5);
  font-size: 13px;
}

/* Right margin Footnotes (mirroring TOC styling) */
#main.post .right-footnotes {
  position: absolute;
  top: 10px;
  right: calc(-1 * var(--toc-width) - var(--toc-gap));
  width: var(--toc-width);
  margin: 0;
  font-family: var(--font-serif);
  font-size: 14px;
  line-height: 1.4;
  color: var(--fg2);
}

#main.post .right-footnotes .footnote-list {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

#main.post .right-footnotes .footnote-item {
  margin: 0 0 0.5rem 0;
}

#main.post .right-footnotes .footnote-item:last-child {
  margin-bottom: 0;
}

#main.post .right-footnotes .footnote-number {
  color: var(--fg4);
  font-weight: 600;
  margin-right: 0.25rem;
}

#main.post .right-footnotes .footnote-content {
  color: var(--fg5);
  font-size: 13px;
  line-height: 1.5;
}

/* Inline footnotes positioned at reference height */
#main.post article.content .inline-footnote {
  position: absolute;
  right: calc(-1 * var(--toc-width) - var(--toc-gap));
  width: var(--toc-width);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.5;
  color: var(--fg5);
  pointer-events: auto;
}

#main.post article.content .inline-footnote .footnote-number {
  color: var(--fg4);
  font-weight: 600;
  margin-right: 0.25rem;
}

#main.post article.content .inline-footnote .footnote-content {
  color: var(--fg5);
  font-size: 13px;
  line-height: 1.5;
}

/* Hide inline footnotes on mobile */
@media (max-width: 1170px) {
  #main.post article.content .inline-footnote {
    display: none;
  }
}

/* Footnote references in content */
#main.post article.content .footnote-ref {
  color: var(--fg4);
  font-weight: 600;
  text-decoration: none;
  font-size: 0.85em;
  vertical-align: super;
  line-height: 0;
  margin-left: 0.15rem;
  cursor: pointer;
  transition: color 0.2s ease-in-out;
}

#main.post article.content .footnote-ref:hover {
  color: var(--fg1);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--fg1) 20%, var(--bg) 20%);
  text-underline-offset: 2px;
}

/* Mobile: Footnote popup */
.footnote-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.2s ease-in-out;
  backdrop-filter: blur(2px);
}

.footnote-overlay.active {
  opacity: 1;
}

.footnote-popup {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 70vh;
  background: var(--bg);
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
  z-index: 1001;
  transform: translateY(100%);
  transition: transform 0.3s ease-out;
  display: flex;
  flex-direction: column;
  font-family: var(--font-sans);
}

.footnote-popup.active {
  transform: translateY(0);
}

.footnote-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid color-mix(in srgb, var(--fg4) 20%, var(--bg) 80%);
}

.footnote-popup-number {
  color: var(--fg4);
  font-weight: 600;
  font-size: 1rem;
}

.footnote-popup-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--fg4);
  cursor: pointer;
  padding: 0;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.25rem;
  transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out;
}

.footnote-popup-close:hover {
  background-color: color-mix(in srgb, var(--fg4) 10%, var(--bg) 90%);
  color: var(--fg1);
}

.footnote-popup-content {
  padding: 1.25rem;
  overflow-y: auto;
  color: var(--fg5);
  font-size: 13px;
  line-height: 1.5;
  flex: 1;
}

/* Hide section footnotes completely */
#main.post article.content .section-footnotes {
  display: none !important;
}

#main.post .sidenote-number {
  counter-increment: sidenote-counter;
  pointer-events: none;
}

#main.post .sidenote-number:after,
#main.post .sidenote:before {
  font-family: var(--font-body);
  position: relative;
  vertical-align: baseline;
  color: var(--fg4);
}

#main.post .sidenote-number:after {
  content: counter(sidenote-counter);
  font-size: 0.8rem;
  top: -0.5rem;
  left: -0.05rem;
  color: var(--fg4);
}

#main.post .sidenote:before {
  content: counter(sidenote-counter);
  padding-right: 0.2rem;
  font-size: 0.8rem;
  top: -0.4rem;
  left: -0.1rem;
  color: var(--fg4);
}

/* Adjust margin notes in blockquotes - positioned with the new absolute layout */
#main.post blockquote .sidenote,
#main.post blockquote .marginnote {
  /* Blockquotes inherit the dynamic width and positioning */
  text-align: left;
}

#main.post--the-poetics-nobody-taught article.content blockquote:not(.epigraph) {
  margin: 1rem 0 1.15rem;
  padding: 0.95rem 1.2rem;
  background: #f5f2ed;
  border-left: 3px solid #d4cfc6;
  border-radius: 0 6px 6px 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.7;
  color: #3a3a3a;
  font-style: italic;
}

#main.post--the-poetics-nobody-taught article.content blockquote:not(.epigraph) p {
  margin: 0;
}

.darkmode #main.post--the-poetics-nobody-taught article.content blockquote:not(.epigraph) {
  background: color-mix(in srgb, var(--bg) 88%, #f5f2ed 12%);
  border-left-color: color-mix(in srgb, var(--fg4) 60%, #d4cfc6 40%);
  color: color-mix(in srgb, var(--fg) 84%, #3a3a3a 16%);
}

/* Figure caption styling - positioned in margin like sidenotes */
#main.post figure {
  position: relative;
  counter-increment: figure-counter;
  /* Clear floats to ensure proper layout */
  overflow: visible;
  /* Ensure figure establishes a block formatting context */
  display: block;
}

/* Very light border variant for specific figures */
#main.post figure.figure-light-border .figure-box {
  border: 1px solid color-mix(in srgb, var(--fg4) 20%, var(--bg) 80%);
  border-radius: 0.2rem; /* match code block radius */
  padding: 0.75rem;
}

#main.post figure figcaption {
  /* Always place captions below figures (not in margin) */
  position: static;
  display: block;
  width: 100%;
  /* Put spacing above the caption (between image and caption),
     and reduce spacing below the caption */
  margin: 0.4rem 0 1.2rem;
  font-size: 0.9rem;
  line-height: 1.4;
  font-family: var(--font-body);
  text-align: left;
  color: var(--fg3);
}

#main.post figure figcaption:before {
  content: "Figure " counter(figure-counter) ": ";
  font-weight: 600;
}

/* Half-width figures: scale contained images to 50% and center */
#main.post figure.half-width img {
  display: block;
  width: 70%;
  height: auto;
  margin-left: auto;
  margin-right: auto;
}

/* Slightly larger Matmul figures */
#main.post figure.half-width.matmul img {
  width: 90%;
}

/* Prevent image dragging/selection within blog post content */
#main.post article.content img {
  -webkit-user-drag: none;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

/* Margin note toggle for mobile */
input.margin-toggle {
  display: none;
}

label.sidenote-number {
  display: inline-block;
  max-height: 2rem;
  cursor: pointer;
}

label.margin-toggle:not(.sidenote-number) {
  display: none;
}

/* Canvas styling for JS figures */
#main.post canvas {
  display: block;
  width: 100%;
  max-width: 100%;
}

/* Make inline SVGs responsive within post content */
#main.post article.content svg {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Do not override KaTeX's internal SVG used for radicals/underbraces. */
#main.post article.content .katex svg {
  height: inherit;
  width: 100%;
  position: absolute;
}

/* Paginator (prev/next/back to top) — align to content column and use GT America */
#main.post .paginator {
  max-width: 660px;
  margin-left: auto;
  margin-right: auto;
  font-family: var(--font-sans);
  display: grid;               /* Three equal boxes */
  grid-template-columns: repeat(3, 1fr);
  align-items: center;
  font-size: 15px;
  width: 100%;                 /* Match top nav size */
}

#main.post .paginator a {
  font-family: var(--font-sans) !important;
  color: var(--fg4);
  text-decoration: none;
  transition: color 0.2s ease-in-out, opacity 0.2s ease-in-out;
  position: relative;
  display: block;              /* Make the whole cell clickable */
  padding: 0.4rem 0;
  text-align: center;
}

#main.post .paginator a:hover {
  color: var(--fg1);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--fg1) 20%, var(--bg) 20%);
  text-underline-offset: 2px;
}

/* Align text within each equal-width box */
#main.post .paginator a:first-child { text-align: left; }
#main.post .paginator a:nth-child(2) { text-align: center; }
#main.post .paginator a:last-child { text-align: right; }

/* Disable interaction for empty placeholders */
#main.post .paginator a:not([href]) {
  pointer-events: none;
}

/* Ensure back-to-top hover matches prev/next underline styling */
#main.post .paginator #back-to-top:hover {
  color: var(--fg1);
  text-decoration: underline !important;
  text-decoration-color: color-mix(in srgb, var(--fg1) 20%, var(--bg) 20%) !important;
  text-underline-offset: 2px !important;
}

/* Center link should be in the middle cell, not absolutely positioned */
#main.post .paginator #back-to-top {
  position: static;
  left: auto;
  transform: none;
}

/* Heading anchor link: show a light grey hash on hover; anchor is click target */
#main.post article.content h2,
#main.post article.content h3,
#main.post article.content h4,
#main.post article.content h5,
#main.post article.content h6 {
  position: relative;           /* anchor is positioned relative to the heading */
}

#main.post article.content .heading-text {
  position: static;            /* let the heading element be the positioned ancestor */
  display: inline;             /* behave like normal inline text */
}

#main.post article.content .heading-anchor {
  position: absolute;           /* Sit in the left margin of the heading */
  top: 50%;
  transform: translateY(-50%);
  left: -1.2rem;                /* offset into the left margin */
  opacity: 0;                   /* hidden by default but still hoverable */
  visibility: visible;
  pointer-events: auto;
  width: 1rem;                  /* comfortable hover target */
  text-align: center;
  color: color-mix(in srgb, var(--fg4) 65%, transparent);
  text-decoration: none;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 1em;
  transition: opacity 150ms ease-in-out, color 150ms ease-in-out;
}

#main.post article.content h2:hover .heading-anchor,
#main.post article.content h3:hover .heading-anchor,
#main.post article.content h4:hover .heading-anchor,
#main.post article.content h5:hover .heading-anchor,
#main.post article.content h6:hover .heading-anchor {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

#main.post article.content .heading-anchor:hover {
  color: color-mix(in srgb, var(--fg4) 80%, transparent);
  outline: none;
}

/* Keep visible when hovering over the hash itself */
#main.post article.content .heading-anchor:hover,
#main.post article.content .heading-anchor:focus {
  opacity: 1;
  color: color-mix(in srgb, var(--fg4) 80%, transparent);
}

/* Mobile responsive adjustments for blog posts only */
@media (max-width: 1170px) {
  #main.post .post-title {
    font-size: 30px;
  }

  #main.post .sidenote,
  #main.post .marginnote {
    /* Show by default on mobile */
    display: block !important;
    position: static; /* Reset absolute positioning */
    float: none; /* Ensure notes do not shrink following blocks (e.g., lists) */
    width: 95%;
    margin: 1rem 2.5%;
    clear: both;
  }

  /* Hide left TOC on narrow viewports to match margin note behavior */
  #main.post .left-toc {
    display: none;
  }

  /* Hide right footnotes on mobile */
  #main.post .right-footnotes {
    display: none;
  }

  /* Override any checkbox-based hiding - always show */
  #main.post .margin-toggle:checked + .sidenote,
  #main.post .margin-toggle:checked + .marginnote,
  #main.post .margin-toggle:not(:checked) + .sidenote,
  #main.post .margin-toggle:not(:checked) + .marginnote {
    display: block !important;
  }

  #main.post .sidenote-number {
    pointer-events: none; /* Disable clicking since notes are expanded by default */
    cursor: default;
  }

  label.margin-toggle:not(.sidenote-number) {
    display: none; /* Hide toggle labels since notes are expanded by default */
  }

  /* Show figure captions below figures on mobile */
  #main.post figure figcaption {
    font-size: 0.85rem;
    margin: 0.5rem 0 1rem;
    color: var(--fg3);
  }

  /* Adjust main content for mobile on blog posts only */
  #main.post {
    margin-left: 0;
    margin-right: 0;
    padding-left: 1.3rem;
    padding-right: 1.3rem;
    max-width: 100%;
  }
  
  /* Ensure 17px font size for paragraphs in blog posts on mobile */
  #main.post article.content {
    font-size: 17px;
  }
  
  #main.post article.content p {
    font-size: 17px;
  }

  /* Keep content width fixed but center it when sidenotes disappear */
  #main.post article.content,
  #main.post .post-cover {
    margin-left: auto;
    margin-right: auto;
    max-width: min(100%, 660px);
  }

  /* Reset cover SVG zoom on small screens to avoid overflow */
  #main.post .post-cover svg {
    width: 100%;
    max-width: 100%;
    height: auto;
    position: static;
    left: auto;
    transform: none;
    padding-left: 0;
    padding-right: 0;
    margin-top: 0;
  }
}

/* Tweet embed styling - for custom shortcode */
#main.post .tweet-embed {
  margin: 1.25rem auto;
  display: flex;
  justify-content: center;
  max-width: 420px !important;
}

#main.post .tweet-embed .twitter-tweet {
  margin: 0 !important;
  max-width: 420px !important;
  width: 420px !important;
}

/* Hugo's built-in twitter/x shortcode styling */
#main.post twitter-widget {
  margin: 1.25rem auto !important;
  max-width: 420px !important;
  width: 420px !important;
  display: block !important;
}

/* Force Twitter iframe sizing */
#main.post .tweet-embed iframe,
#main.post .twitter-tweet-rendered,
#main.post .twitter-tweet iframe,
#main.post twitter-widget iframe {
  max-width: 420px !important;
  width: 420px !important;
  min-width: auto !important;
  margin: 0 auto !important;
}

/* Override Twitter's default sizing on the container */
#main.post .twitter-tweet {
  max-width: 420px !important;
  width: 420px !important;
  margin: 0 auto 1.1rem !important;
}

/* Direct targeting of Hugo's output */
#main.post > twitter-widget,
#main.post article.content twitter-widget {
  margin-left: auto !important;
  margin-right: auto !important;
  display: block !important;
}

/* Table styling - center tables and make them look good */
#main.post article.content table {
  display: table !important; /* Override display: block from typography.css */
  overflow-x: visible !important; /* Override overflow-x: auto from typography.css */
  margin: 1.25rem auto;
  border-collapse: collapse;
  font-size: 0.95rem;
  line-height: 1.5;
  width: auto; /* Let table size to its content */
  max-width: 100%; /* But don't exceed container width */
}

#main.post article.content th,
#main.post article.content td {
  padding: 0.4rem 0.75rem;
  text-align: left;
  border: 1px solid color-mix(in srgb, var(--fg4) 25%, var(--bg) 75%);
}

#main.post article.content th {
  font-weight: 600;
  background-color: color-mix(in srgb, var(--fg4) 5%, var(--bg) 95%);
  color: var(--fg);
}

#main.post article.content tbody tr:hover {
  background-color: color-mix(in srgb, var(--fg4) 3%, var(--bg) 97%);
}

/* Center align table content if needed */
#main.post article.content table.center-content th,
#main.post article.content table.center-content td {
  text-align: center;
}

#main.post--the-poetics-nobody-taught .poetics-table-wrap {
  overflow-x: auto;
  margin: 1.2rem 0 0.55rem;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--fg4) 16%, var(--bg) 84%);
  border-radius: 0;
  background:
    linear-gradient(180deg,
      color-mix(in srgb, var(--fg4) 4%, var(--bg) 96%) 0%,
      color-mix(in srgb, var(--fg4) 1.5%, var(--bg) 98.5%) 100%);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.03);
}

#main.post--the-poetics-nobody-taught table.poetics-recap {
  width: 100%;
  margin: 0 auto !important;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.94rem;
  line-height: 1.55;
  background: transparent;
}

#main.post--the-poetics-nobody-taught table.poetics-recap thead tr {
  background: color-mix(in srgb, var(--fg4) 6%, var(--bg) 94%);
}

#main.post--the-poetics-nobody-taught table.poetics-recap th {
  text-align: left;
  padding: 0.85rem 1rem;
  color: var(--fg3);
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: transparent;
  border-bottom: 1px solid color-mix(in srgb, var(--fg4) 16%, transparent);
}

#main.post--the-poetics-nobody-taught table.poetics-recap td {
  padding: 0.9rem 1rem;
  color: var(--fg2);
  border-left: none;
  border-right: none;
  border-bottom: 1px solid color-mix(in srgb, var(--fg4) 10%, transparent);
  border-top: none;
  vertical-align: top;
}

#main.post--the-poetics-nobody-taught table.poetics-recap td:first-child,
#main.post--the-poetics-nobody-taught table.poetics-recap th:first-child {
  width: 34%;
}

#main.post--the-poetics-nobody-taught table.poetics-recap td:first-child {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.35;
  letter-spacing: -0.01em;
  color: var(--fg);
}

#main.post--the-poetics-nobody-taught .poetics-jump-link {
  color: inherit !important;
  text-decoration: none !important;
  display: inline-block;
}

#main.post--the-poetics-nobody-taught .poetics-jump-link:hover,
#main.post--the-poetics-nobody-taught .poetics-jump-link:focus-visible {
  text-decoration: underline !important;
  text-decoration-color: color-mix(in srgb, var(--fg) 28%, transparent) !important;
  text-underline-offset: 3px;
}

#main.post--the-poetics-nobody-taught table.poetics-recap tr.poetics-jump-row {
  cursor: pointer;
  transition: background-color 0.18s ease-in-out;
}

#main.post--the-poetics-nobody-taught table.poetics-recap tr.poetics-jump-row:hover td,
#main.post--the-poetics-nobody-taught table.poetics-recap tr.poetics-jump-row:focus td,
#main.post--the-poetics-nobody-taught table.poetics-recap tr.poetics-jump-row:focus-visible td {
  background: color-mix(in srgb, var(--fg4) 6%, var(--bg) 94%);
}

#main.post--the-poetics-nobody-taught table.poetics-recap tr.poetics-jump-row:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--fg3) 24%, transparent);
  outline-offset: 3px;
}

#main.post--the-poetics-nobody-taught .poetics-table-note {
  margin: 0 0 1.6rem;
  font-family: var(--font-sans);
  font-size: 0.82rem;
  color: var(--fg3);
  letter-spacing: 0.01em;
}

.darkmode #main.post--the-poetics-nobody-taught table.poetics-recap thead tr {
  background: color-mix(in srgb, var(--fg4) 16%, var(--bg) 84%);
}

.darkmode #main.post--the-poetics-nobody-taught table.poetics-recap th {
  color: color-mix(in srgb, var(--fg2) 92%, var(--bg) 8%);
  border-bottom-color: color-mix(in srgb, var(--fg4) 24%, transparent);
}

.darkmode #main.post--the-poetics-nobody-taught table.poetics-recap td {
  color: color-mix(in srgb, var(--fg2) 94%, var(--bg) 6%);
  border-bottom-color: color-mix(in srgb, var(--fg4) 18%, transparent);
}

.darkmode #main.post--the-poetics-nobody-taught table.poetics-recap td:first-child {
  color: var(--fg);
}

.darkmode #main.post--the-poetics-nobody-taught table.poetics-recap tr.poetics-jump-row:hover td,
.darkmode #main.post--the-poetics-nobody-taught table.poetics-recap tr.poetics-jump-row:focus td,
.darkmode #main.post--the-poetics-nobody-taught table.poetics-recap tr.poetics-jump-row:focus-visible td {
  background: color-mix(in srgb, var(--fg4) 14%, var(--bg) 86%);
}

.darkmode #main.post--the-poetics-nobody-taught .poetics-table-wrap {
  border-color: color-mix(in srgb, var(--fg4) 24%, transparent);
  background:
    linear-gradient(180deg,
      color-mix(in srgb, var(--fg4) 10%, var(--bg) 90%) 0%,
      color-mix(in srgb, var(--fg4) 4%, var(--bg) 96%) 100%);
}

.darkmode #main.post--the-poetics-nobody-taught .poetics-table-note {
  color: color-mix(in srgb, var(--fg3) 92%, var(--bg) 8%);
}

/* LoRA table color indicators */
.lora-color-square {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 8px;
  vertical-align: middle;
  border-radius: 2px;
}

.lora-color-square.green {
  background-color: green;
}

.lora-color-square.red {
  background-color: red;
}

.lora-color-square.blue {
  background-color: blue;
}

.lora-color-square.gold {
  background-color: #B8860B;
}
