/* ── Decorative page border (header & footer) ───────────────────────────── */

:root {
  --border-w: 38px;
  --page-border: url("/assets/borders/border.png"); /* overridden at runtime by JS */
}

body,
article,
article p,
article li,
article td,
article th,
article blockquote,
article section,
.footer-nav,
.copyright {
  font-family: et-book, Palatino, "Palatino Linotype", "Palatino LT STD",
    "Book Antiqua", Georgia, serif;
}

article h1,
article h2,
article h3,
article h4,
article h5,
article h6,
.header-nav,
.footer-nav a,
.theme-toggle {
  font-family: et-book, Palatino, "Palatino Linotype", "Palatino LT STD",
    "Book Antiqua", Georgia, serif;
}

body {
  overflow-x: hidden;
  width: 100%;
  max-width: none;
  margin: 0;
  padding-left: 0;
}

.page {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0;
  box-sizing: border-box;
}

.header-border,
.footer-border {
  width: 100vw;
  height: var(--border-w);
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  overflow: hidden;
}

/* Horizontal image — tile directly */
html.border-h .header-border,
html.border-h .footer-border {
  background-image: var(--page-border);
  background-repeat: repeat-x;
  background-size: auto 100%;
}

/* Vertical image — rotate a tall strip into a horizontal one */
html.border-v .header-border::before,
html.border-v .footer-border::before {
  content: "";
  position: absolute;
  top: var(--border-w);
  left: 0;
  width: var(--border-w);
  height: 100vw;
  background-image: var(--page-border);
  background-repeat: repeat-y;
  background-size: 100% auto;
  transform: rotate(-90deg);
  transform-origin: top left;
}

/* ── Site header ─────────────────────────────────────────────────────────── */

.page > article {
  width: 87.5%;
  margin: 0 auto;
}

.page .header-nav {
  width: 87.5%;
  margin: 0 auto;
  display: flex;
  align-items: baseline;
  gap: 1.5rem;
  padding: 0.8rem 0;
  font-size: 1.2rem;
}

.header-nav .site-name {
  font-family: "Cinzel", "Playfair Display", "Georgia", serif;
  font-weight: 600;
  font-size: 1.8rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-right: auto;
  color: #111 !important;
  text-decoration: none !important;
  background: none !important;
  text-shadow: none !important;
}

.header-nav a {
  color: #666;
  text-decoration: none;
  background: none;
  text-shadow: none;
}

.header-nav a:hover {
  color: #111;
}

.theme-toggle {
  border: none;
  background: none;
  color: #666;
  cursor: pointer;
  font: inherit;
  padding: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.theme-toggle:hover {
  color: #111;
}

.theme-toggle__icon {
  font-size: 1.1em;
  line-height: 1;
}

/* ── Display math — center across full text column ─────────────────────── */

/* The parent <p> in tufte-css is capped at 55% width, so "center" looks
   left-biased. Widen the paragraph when it only holds a display equation. */
section > p:has(> mjx-container[display="true"]),
section > p:has(> span > mjx-container[display="true"]) {
  width: 100% !important;
  text-align: center !important;
}

mjx-container[display="true"] {
  display: block !important;
  text-align: center !important;
  margin: 1.5rem auto !important;
  overflow-x: auto;
}

/* Handle inline span wrapper that MathJax creates */
section > p > span:has(> mjx-container[display="true"]) {
  display: block;
  width: 100%;
  text-align: center;
}

/* ── Table of contents — top of article, full width ───────────────────────── */

nav.toc {
  width: 55%;
  margin: 1rem 0 2rem 0;
  font-size: 1.1rem;
  line-height: 1.6;
  border-left: 3px solid #ddd;
  padding-left: 1rem;
}

nav.toc::before {
  content: "Contents";
  display: block;
  font-variant: small-caps;
  font-size: 1rem;
  letter-spacing: 0.05em;
  color: #555;
  margin-bottom: 0.4rem;
}

nav.toc ol,
nav.toc ul {
  margin: 0;
  padding-left: 0;
  list-style: none;
}

nav.toc li {
  margin: 0.2rem 0;
  padding-left: 0.8em;
}

/* nested sub-items */
nav.toc li li {
  padding-left: 1.4em;
  font-size: 0.95em;
}

nav.toc a {
  text-decoration: none;
  background: none !important;
  text-shadow: none !important;
}

nav.toc a:hover {
  text-decoration: underline;
}

@media (max-width: 760px) {
  nav.toc {
    float: none;
    width: 100%;
    margin: 0 0 1.5rem;
    border-left: 2px solid #ddd;
    padding-left: 1rem;
  }
}

/* ── Link color — dark red throughout ──────────────────────────────────── */

a:link,
a:visited {
  color: #a00000 !important;
  text-decoration: none !important;
  background: none !important;
  text-shadow: none !important;
}

/* ── Heading anchor symbol (§ before h2/h3) ─────────────────────────────── */

.header-anchor {
  font-size: 0.7em;
  margin-right: 0.4em;
  opacity: 0.35;
  text-decoration: none !important;
  background: none !important;
  text-shadow: none !important;
  vertical-align: middle;
  transition: opacity 0.15s;
}

h2:hover .header-anchor,
h3:hover .header-anchor {
  opacity: 1;
}

/* ── Force light mode when system prefers dark but site theme not dark ──── */

@media (prefers-color-scheme: dark) {
  html:not([data-theme="dark"]) body {
    background-color: #fffff8 !important;
    color: #111 !important;
  }
}

/* ── Code blocks — full content-column width ────────────────────────────── */

.shiki code,
pre > code {
  width: auto !important;
  margin-left: 0 !important;
  display: block;
  overflow-x: auto;
}

pre,
.shiki {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0))
      var(--shiki-light-bg);
  border: 1px solid rgba(139, 121, 91, 0.18);
  border-left: 5px solid #ccb58e;
  border-radius: 0 0.45rem 0.45rem 0;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.55),
    0 1px 0 rgba(255, 255, 255, 0.7),
    0 10px 24px rgba(77, 61, 33, 0.05);
  padding: 1rem 1.4rem;
  margin: 1.4rem 0;
  font-size: 0.85rem;
  line-height: 1.55;
  overflow-x: auto;
  width: 55%; /* match tufte text column */
  box-sizing: border-box;
}

@media (max-width: 760px) {
  pre,
  .shiki {
    width: 100%;
  }
}

.shiki,
.shiki code,
.shiki span {
  font-family: "Consolas", "Menlo", "Monaco", monospace;
  background: transparent !important;
}

:not(pre) > code {
  background: #f8f5ee;
  padding: 0.1em 0.3em;
  border-radius: 2px;
  font-size: 0.85em;
  font-family: "Consolas", "Menlo", "Monaco", monospace;
}

.shiki,
.shiki span {
  color: var(--shiki-light);
  font-style: var(--shiki-light-font-style);
  font-weight: var(--shiki-light-font-weight);
  text-decoration: var(--shiki-light-text-decoration);
}

/* ── Post date ──────────────────────────────────────────────────────────── */

.post-date {
  font-style: italic;
  color: #888;
  margin-top: -0.8rem;
  font-size: 1.2rem;
}

@media (max-width: 760px) {
  .page > article {
    width: 90%;
  }

  article {
    padding: 1.25rem 0 2rem;
  }

  article > h1 {
    margin-top: 1rem;
    margin-bottom: 1rem;
    font-size: clamp(2.6rem, 10vw, 3.6rem);
    line-height: 0.98;
    text-wrap: balance;
  }

  article > p,
  article > footer,
  article > table,
  article > dl,
  article > ol,
  article > ul,
  article > blockquote,
  article > pre,
  article > figure,
  article > .table-wrapper,
  article > .code-block-wrapper {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  article > p,
  article > li,
  article > blockquote p,
  article > ul,
  article > ol,
  article > dl {
    font-size: 1.28rem;
    line-height: 1.8rem;
  }

  article > ul,
  article > ol,
  article > dl {
    padding-left: 1.4rem;
    -webkit-padding-start: 1.4rem;
  }

  article > blockquote {
    margin-left: 1rem;
    margin-right: 0;
  }

  article > blockquote p,
  article > blockquote footer {
    width: 100%;
    margin-right: 0;
  }

  .post-date {
    margin-top: -0.35rem;
    margin-bottom: 1.25rem;
    font-size: 1.05rem;
  }
}

/* ── Explicit dark theme overrides ──────────────────────────────────────── */

html[data-theme="dark"] body {
  background-color: #111111 !important;
  color: #f8f5ee !important;
}

html[data-theme="dark"] article,
html[data-theme="dark"] article p,
html[data-theme="dark"] article li,
html[data-theme="dark"] article td,
html[data-theme="dark"] article th,
html[data-theme="dark"] article section,
html[data-theme="dark"] article h1,
html[data-theme="dark"] article h2,
html[data-theme="dark"] article h3,
html[data-theme="dark"] article h4,
html[data-theme="dark"] article h5,
html[data-theme="dark"] article h6 {
  color: #f8f5ee;
}

html[data-theme="dark"] .header-nav .site-name {
  color: #f8f5ee !important;
}

html[data-theme="dark"] .header-nav a,
html[data-theme="dark"] .theme-toggle {
  color: #dddddd;
}

html[data-theme="dark"] .header-nav a:hover,
html[data-theme="dark"] .theme-toggle:hover {
  color: #ffffff;
}

html[data-theme="dark"] .post-date {
  color: #bbbbbb;
}

html[data-theme="dark"] a:link,
html[data-theme="dark"] a:visited {
  color: #ffb3b3 !important;
  text-decoration: none !important;
  background: none !important;
  text-shadow: none !important;
}

html[data-theme="dark"] pre,
html[data-theme="dark"] .shiki {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0))
      var(--shiki-dark-bg);
  border-color: rgba(255, 241, 214, 0.12);
  border-left-color: #8a6d49;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    0 12px 26px rgba(0, 0, 0, 0.22);
}

html[data-theme="dark"] :not(pre) > code {
  background: #1e1b18;
  color: #d4d4d4;
}

html[data-theme="dark"] .shiki,
html[data-theme="dark"] .shiki span {
  color: var(--shiki-dark);
  font-style: var(--shiki-dark-font-style);
  font-weight: var(--shiki-dark-font-weight);
  text-decoration: var(--shiki-dark-text-decoration);
}

/* ── Dark mode blockquotes ──────────────────────────────────────────────── */

html[data-theme="dark"] blockquote {
  border-left-color: #555555;
  color: #cccccc;
}

html[data-theme="dark"] blockquote footer {
  color: #999999;
}

html[data-theme="dark"] .epigraph blockquote {
  color: #dddddd;
}

/* ── Posts list ─────────────────────────────────────────────────────────── */

.home-intro {
  margin-bottom: 3rem;
}

.home-lead {
  font-size: 1.35rem;
  line-height: 1.7;
  margin-bottom: 0.6rem;
}

.home-kicker {
  margin: 1.8rem 0 0.6rem;
  font-style: italic;
  color: #666;
}

.home-list {
  list-style: none;
  padding-left: 0;
  margin: 0 0 1rem;
}

.home-list li {
  position: relative;
  padding-left: 1.4rem;
  margin-bottom: 0.6rem;
  font-size: 1.15rem;
  line-height: 1.6;
}

.home-list li::before {
  content: "§";
  position: absolute;
  left: 0;
  top: 0;
  color: #a00000;
  opacity: 0.75;
}

.home-cta {
  margin-top: 1.8rem;
  font-size: 1.15rem;
}

.home-rotating-copy {
  margin-top: 0.4rem;
}

.rotating-phrase {
  display: inline-block;
  min-width: 9ch;
  color: #a00000;
  transition: opacity 0.2s ease;
}

.rotating-phrase.is-fading {
  opacity: 0.35;
}

.home-columns {
  display: flex;
  gap: 3rem;
  align-items: flex-start;
}

.home-column {
  flex: 1 1 0;
  min-width: 0;
}

.home-columns--intro {
  margin-top: 0;
}

.home-columns--intro > .home-column {
  padding-top: 0;
  padding-bottom: 0;
}

.home-column > h2,
.home-column > p,
.home-column > ul,
.home-column > ol,
.home-column > dl,
.home-column > table,
.home-column > footer {
  width: 100%;
  max-width: 100%;
}

.home-column > ul,
.home-column > ol,
.home-column > dl {
  padding-left: 0;
  -webkit-padding-start: 0;
}

html[data-theme="dark"] .home-kicker {
  color: #bbbbbb;
}

html[data-theme="dark"] .home-list li::before {
  color: #ffb3b3;
}

html[data-theme="dark"] .rotating-phrase {
  color: #ffb3b3;
}

.post-item {
  display: flex;
  gap: 2rem;
  margin-bottom: 0.5rem;
  align-items: baseline;
  font-size: 1.3rem;
}

.post-item time {
  font-size: 1rem;
  color: #999;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  min-width: 6.5rem;
  flex-shrink: 0;
}

.post-item a {
  flex: 1 1 auto;
  min-width: 0;
}

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

.post-list li {
  display: flex;
  align-items: baseline;
  gap: 2rem;
  margin-bottom: 0.5rem;
}

.post-list time {
  color: #999;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  min-width: 6.5rem;
  flex-shrink: 0;
}

.post-list a {
  flex: 1 1 auto;
  min-width: 0;
}

.readings-list {
  list-style: none;
  padding-left: 0;
  margin: 0 0 1rem;
}

.readings-list--ornate li {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.7rem;
  font-size: 1.2rem;
  line-height: 1.5;
  list-style: none;
}

.readings-list--ornate li::marker {
  content: "";
}

.readings-bullet {
  color: #a00000;
  opacity: 0.8;
  flex: 0 0 auto;
  font-size: 0.95rem;
}

html[data-theme="dark"] .readings-bullet {
  color: #ffb3b3;
}

@media (max-width: 760px) {
  .home-columns {
    flex-direction: column;
    gap: 2rem;
  }

  .post-item,
  .post-list li {
    gap: 1rem;
    align-items: flex-start;
  }

  .post-item time,
  .post-list time {
    min-width: 4.5rem;
    font-size: 0.95rem;
  }

  .readings-list--ornate li {
    font-size: 1.1rem;
  }

  .home-lead,
  .home-list li,
  .home-cta {
    font-size: 1.08rem;
  }
}

/* ── Footer ─────────────────────────────────────────────────────────────── */

.page > footer {
  margin-top: 4rem;
  width: 100%;
}

.footer-inner {
  width: 87.5%;
  margin: 0 auto;
  padding: 1.5rem 0 3rem;
}

.copyright {
  color: #bbb;
  font-size: 1rem;
  margin: 0;
}

html[data-theme="dark"] .copyright {
  color: #666666;
}

/* ── Figure / inline images — consistent width ───────────────────────────── */

figure img {
  display: block;
  width: 100%;
  max-width: 100%;
}

article img {
  cursor: zoom-in;
}

body.lightbox-open {
  overflow: hidden;
}

.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
}

.image-lightbox.is-open {
  display: block;
}

.image-lightbox__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 17, 17, 0.86);
  backdrop-filter: blur(4px);
}

.image-lightbox__dialog {
  position: relative;
  z-index: 1;
  width: min(92vw, 1100px);
  margin: 4vh auto;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.image-lightbox__close {
  align-self: flex-end;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(17, 17, 17, 0.6);
  color: #f8f5ee;
  padding: 0.45rem 0.8rem;
  font: inherit;
  cursor: pointer;
}

.image-lightbox__image {
  display: block;
  max-width: 100%;
  max-height: calc(92vh - 4rem);
  width: auto;
  height: auto;
  object-fit: contain;
  box-shadow: 0 1.25rem 3rem rgba(0, 0, 0, 0.3);
}

.image-lightbox__caption {
  margin: 0;
  max-width: min(92vw, 900px);
  color: #f8f5ee;
  text-align: center;
  font-size: 1rem;
  line-height: 1.5;
}

html[data-theme="dark"] .image-lightbox__close {
  border-color: rgba(248, 245, 238, 0.35);
  background: rgba(17, 17, 17, 0.72);
}

/* ── Margin note images ──────────────────────────────────────────────────── */

span.marginnote img {
  display: block;
  width: 100%;
  margin-bottom: 0.4rem;
}

/* ── Epigraph ────────────────────────────────────────────────────────────── */

.epigraph > blockquote > footer {
  border: none;
  margin: 0;
  padding: 0;
}

/* ── Mobile: Fix broken header/footer borders ───────────────────────────── */

@media (max-width: 760px) {
  /* Pull borders outside body padding to span full viewport width */
  .header-border,
  .footer-border {
    margin-left: -8%;
    margin-right: -8%;
    width: calc(100% + 16%);
    left: 0;
    transform: none;
  }

  /* Vertical borders: make pseudo-element longer to cover full width */
  html.border-v .header-border::before,
  html.border-v .footer-border::before {
    height: 150vw;
  }
}

/* ── Footer navigation ──────────────────────────────────────────────────── */

.footer-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 1.4rem;
  margin-bottom: 0.6rem;
  font-size: 1.2rem;
}

.footer-nav-main {
  display: flex;
  gap: 1.4rem;
}

.footer-nav-social {
  display: flex;
  gap: 2rem;
  margin-left: auto;
}

.footer-nav a {
  color: #666;
  text-decoration: none;
  background: none;
  text-shadow: none;
}

.footer-nav a:hover {
  color: #111;
}

html[data-theme="dark"] .footer-nav a {
  color: #dddddd;
}

html[data-theme="dark"] .footer-nav a:hover {
  color: #ffffff;
}

@media (max-width: 760px) {
  .footer-nav {
    flex-direction: column;
    gap: 0.8rem;
  }

  .footer-nav-social {
    margin-left: 0;
    padding-top: 0.5rem;
    border-top: 1px solid #ddd;
    gap: 1.5rem;
  }

  html[data-theme="dark"] .footer-nav-social {
    border-top-color: #444;
  }
}

/* ── Post header image ───────────────────────────────────────────────────── */

.post-header-image {
  margin: 1.5rem 0 2rem 0;
  width: 100%;
}

.post-header-image img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}

/* ── Poetry list with artistic bullets ─────────────────────────────────── */

.poetry-list {
  margin-top: 2rem;
}

.poetry-item {
  display: flex;
  align-items: baseline;
  gap: 0.8rem;
  margin-bottom: 0.8rem;
  font-size: 1.3rem;
}

.poetry-bullet {
  color: #a00000;
  font-size: 1.1rem;
  opacity: 0.8;
}

.poetry-item a {
  text-decoration: none;
}

.poetry-item a:hover {
  text-decoration: underline;
}

html[data-theme="dark"] .poetry-bullet {
  color: #ffb3b3;
}
