/* =====================================================
   VARIABLES — light by default, dark opt-in
   ===================================================== */
:root {
  counter-reset: sidenote-counter;

  /* Primary palette */
  --bg:      #faf5ec;
  --text:    #1c1c1c;
  --muted:   #4a7a6a;
  --accent:  #7a1a1a;
  --crimson: #7a1a1a;
  --border:  #d4c4a8;

  /* Aliases for backward-compat (sidenotes, footnotes, etc.) */
  --color-bg:           var(--bg);
  --color-text:         var(--text);
  --color-text-muted:   var(--muted);
  --color-accent:       var(--accent);
  --color-border:       var(--border);
  --color-bg-secondary: #f0ebe0;
  --color-surface:      #f5f0e4;

  /* Typography */
  --font-serif: Palatino, 'Palatino Linotype', 'Book Antiqua', serif;
  --font-mono:  'Courier New', Courier, monospace;
  --font-sans:  -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
  /* Aliases */
  --font-heading: var(--font-serif);

  /* Spacing */
  --spacing-xs:  0.25rem;
  --spacing-sm:  0.5rem;
  --spacing-md:  1rem;
  --spacing-lg:  1.5rem;
  --spacing-xl:  2rem;
  --spacing-2xl: 3rem;
  --spacing-3xl: 4rem;
  /* Aliases */
  --space-xs:  var(--spacing-xs);
  --space-sm:  var(--spacing-sm);
  --space-md:  var(--spacing-md);
  --space-lg:  var(--spacing-lg);
  --space-xl:  var(--spacing-xl);
  --space-2xl: var(--spacing-2xl);
  --space-3xl: var(--spacing-3xl);

  /* Layout */
  --max-width:      46rem;
  --max-width-wide: 72rem;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
}

[data-theme="dark"] {
  --bg:      #1a1208;
  --text:    #f5e6c8;
  --muted:   #4a7a6a;
  --accent:  #c9a84c;
  --crimson: #c04848;
  --border:  #2a1e0e;

  --color-bg-secondary: #241a0e;
  --color-surface:      #2e2212;
}

/* System dark mode — applies unless user has explicitly chosen light */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:      #1a1208;
    --text:    #f5e6c8;
    --muted:   #4a7a6a;
    --accent:  #c9a84c;
    --crimson: #c04848;
    --border:  #2a1e0e;

    --color-bg-secondary: #241a0e;
    --color-surface:      #2e2212;
  }
}

/* =====================================================
   RESET
   ===================================================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; overflow-x: hidden; }

/* =====================================================
   BASE
   ===================================================== */
body {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  line-height: 1.75;
  color: var(--text);
  background: var(--bg);
  transition: background 180ms ease, color 180ms ease;
}

a { color: var(--accent); text-decoration: none; }
a:visited { color: #b87a30; }
a:hover { color: #6b1515; }

/* =====================================================
   READING PROGRESS BAR
   ===================================================== */
.reading-progress {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  width: 100%;
  background: var(--bg);
  z-index: 100;
}
.reading-progress::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  height: 100%;
  width: var(--p, 0%);
  background: var(--crimson);
  transition: width 60ms linear;
}

/* =====================================================
   HEADER / NAV
   ===================================================== */
.site-header {
  padding: 0 1.75rem;
}

.nav-wrapper {
  max-width: var(--max-width-wide);
  margin: 0 auto;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 2rem;
  padding: 1.75rem 0 1.5rem;
}

.site-name {
  font-family: var(--font-serif);
  font-size: 1.6rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1;
}
.site-name:hover { color: var(--accent); }

.nav-menu {
  display: flex;
  align-items: baseline;
  gap: 1.25rem;
  list-style: none;
  flex-wrap: wrap;
  justify-content: center;
}

.nav-menu a,
.nav-menu button {
  font-family: var(--font-serif);
  font-variant: small-caps;
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  transition: color 140ms ease;
  text-decoration: none;
}
.nav-menu a:hover,
.nav-menu button:hover { color: var(--accent); }

.nav-menu a.active {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* =====================================================
   CONTAINERS
   ===================================================== */
.wrap {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.75rem;
}

.wrap-wide {
  max-width: var(--max-width-wide);
  margin: 0 auto;
  padding: 0 1.75rem;
}

main { padding: 2rem 0 4rem; }

/* =====================================================
   POST LIST — vertical timeline
   ===================================================== */
.post-list {
  list-style: none;
  border-left: 1px solid rgba(122, 26, 26, 0.4);
  padding-left: 1.75rem;
  margin-left: 0.4rem;
}

[data-theme="dark"] .post-list {
  border-left-color: rgba(192, 72, 72, 0.35);
}

.post-item {
  position: relative;
  padding-bottom: 2.4rem;
}

.post-item:last-child { padding-bottom: 0; }

/* Square crimson marker */
.post-item::before {
  content: '';
  position: absolute;
  left: calc(-1.75rem - 3px);
  top: 0.5rem;
  width: 5px;
  height: 5px;
  background: var(--crimson);
}

.post-meta {
  display: flex;
  align-items: baseline;
  gap: 0.9rem;
  margin-bottom: 0.25rem;
  flex-wrap: wrap;
}

.post-date {
  font-family: var(--font-mono);
  font-size: 0.63rem;
  letter-spacing: 0.1em;
  color: var(--crimson);
  font-variant: small-caps;
  text-transform: uppercase;
}

.post-theme {
  font-family: var(--font-mono);
  font-size: 0.63rem;
  letter-spacing: 0.04em;
  color: var(--accent);
  opacity: 0.75;
}

.post-wordcount {
  font-family: var(--font-mono);
  font-size: 0.63rem;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.post-sep {
  font-family: var(--font-mono);
  font-size: 0.63rem;
  color: var(--muted);
  opacity: 0.4;
}

.post-title {
  font-size: 1.35rem;
  font-weight: 400;
  line-height: 1.3;
  margin-bottom: 0.35rem;
}

.post-title a {
  color: var(--text);
  text-decoration: none;
}
.post-title a:hover { color: #6b1515; }

.post-desc {
  font-size: 0.95rem;
  color: var(--muted);
  line-height: 1.6;
  margin-bottom: 0.5rem;
}

/* =====================================================
   TAGS
   ===================================================== */
.post-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  list-style: none;
}

.tag {
  display: inline-block;
  font-family: var(--font-serif);
  font-size: 0.62rem;
  font-variant: small-caps;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--accent);
  padding: 0.2em 0.7em 0.18em;
  border-radius: 0;
  opacity: 0.85;
  text-decoration: none;
}
.tag:hover { opacity: 1; }

/* =====================================================
   POST PAGE LAYOUT — TOC + content grid
   ===================================================== */
.post-layout {
  max-width: var(--max-width-wide);
  margin: 0 auto;
  padding: 0 1.75rem 4rem;
  display: grid;
  grid-template-columns: 12rem 1fr 14rem;
  gap: 0 2.5rem;
  align-items: start;
  padding-top: 2rem;
}

/* =====================================================
   TABLE OF CONTENTS
   ===================================================== */
.toc {
  position: sticky;
  top: 2rem;
  padding-top: 0.25rem;
}

.toc-label {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.6;
  display: block;
  margin-bottom: 0.75rem;
}

.toc-list { list-style: none; }

.toc-item { margin-bottom: 0.1rem; }

.toc-link {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  line-height: 1.45;
  color: var(--muted);
  text-decoration: none;
  padding: 0.2rem 0 0.2rem 0.6rem;
  border-left: 2px solid transparent;
  transition: color 120ms ease, border-color 120ms ease;
}
.toc-link:hover { color: var(--text); }

.toc-link.active {
  color: var(--text);
  border-left-color: var(--crimson);
}

.toc-item.sub .toc-link {
  padding-left: 1.4rem;
  font-size: 0.62rem;
  opacity: 0.8;
}

/* =====================================================
   MOBILE TOC BAR — sticky section indicator, ≤900px only
   ===================================================== */
.toc-mobile {
  display: none; /* shown by JS only on small screens */
  position: sticky;
  top: 3px; /* sits just below the progress bar */
  z-index: 50;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.toc-mobile-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.55rem 1.75rem;
  gap: 0.5rem;
}

.toc-mobile-current {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: left;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toc-mobile-chevron {
  font-size: 0.65rem;
  color: var(--muted);
  transition: transform 180ms ease;
  flex-shrink: 0;
}
.toc-mobile.open .toc-mobile-chevron { transform: rotate(180deg); }

.toc-mobile-list {
  display: none;
  list-style: none;
  padding: 0.35rem 1.75rem 0.65rem;
  border-top: 1px solid var(--border);
}
.toc-mobile.open .toc-mobile-list { display: block; }

.toc-mobile-list li { margin-bottom: 0; }
.toc-mobile-list a {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  color: var(--muted);
  text-decoration: none;
  padding: 0.3rem 0;
  border-left: 2px solid transparent;
  padding-left: 0.5rem;
  transition: color 120ms;
}
.toc-mobile-list a:hover { color: var(--text); }
.toc-mobile-list a.active {
  color: var(--text);
  border-left-color: var(--crimson);
}
.toc-mobile-list li.sub a { padding-left: 1.2rem; font-size: 0.62rem; opacity: 0.8; }

/* =====================================================
   POST CONTENT
   ===================================================== */
.post-content {
  grid-column: 2;
  min-width: 0;
  position: relative;
}

.post-header { margin-bottom: 2rem; }

.post-title-main {
  font-size: 2rem;
  font-weight: 400;
  line-height: 1.2;
  color: var(--text);
  margin-bottom: 0.6rem;
}

.post-meta-row {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  flex-wrap: wrap;
}

/* Tags inline in meta row (display: contents flattens into parent flex) */
.post-meta-row .post-tags { display: contents; }

.post-body { font-size: 1.05rem; line-height: 1.75; max-width: 38rem; }

.post-body img,
.post-body figure img {
  max-width: 100%;
  height: auto;
  display: block;
}

.post-body h2 {
  font-size: 1.3rem;
  font-weight: 400;
  margin: 2.2rem 0 0.6rem;
  line-height: 1.3;
}

.post-body h3 {
  font-size: 1.1rem;
  font-weight: 400;
  margin: 1.6rem 0 0.4rem;
  line-height: 1.3;
}

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

.post-body ul,
.post-body ol {
  padding-left: 1.5rem;
  margin-bottom: 1rem;
}

.post-body li { margin-bottom: 0.25rem; }

.post-body blockquote {
  border-left: 2px solid var(--crimson);
  margin: 1.5rem 0;
  padding: 0.5rem 0 0.5rem 1.25rem;
  color: var(--muted);
  font-size: 1rem;
}

.post-body code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  color: var(--accent);
  background: rgba(201, 168, 76, 0.08);
  padding: 0.1em 0.3em;
}

.post-body pre {
  background: var(--color-bg-secondary);
  border: 1px solid var(--border);
  padding: 1rem 1.25rem;
  overflow-x: auto;
  margin: 1.25rem 0;
  font-size: 0.875em;
  line-height: 1.5;
}

.post-body pre code {
  background: none;
  padding: 0;
  color: var(--text);
}

.post-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

.post-body .table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1.5rem 0;
}

.post-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 0;
  font-size: 0.9rem;
}

.post-body th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  padding: 0.4rem 1.25rem 0.4rem 0;
  font-weight: 400;
}

.post-body td {
  padding: 0.35rem 1.25rem 0.35rem 0;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  color: var(--text);
}

.post-body tr:last-child td { border-bottom: none; }
.post-body td:last-child,
.post-body th:last-child { padding-right: 0; }

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

/* External link indicator */
.post-body a[target="_blank"]::after {
  content: ' ↗';
  font-size: 0.7em;
  opacity: 0.6;
}

.post-back {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.post-back a { color: var(--muted); }
.post-back a:hover { color: var(--accent); }

/* =====================================================
   SECTION LABELS
   ===================================================== */
.section-label {
  font-family: var(--font-serif);
  font-size: 0.75rem;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  font-variant: small-caps;
  color: var(--muted);
  margin: 2.5rem 0 1rem;
  display: block;
}

/* =====================================================
   BOOK COVER GRID
   ===================================================== */
.book-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 0.75rem;
}

.book-card {
  display: block;
  position: relative;
  overflow: hidden;
  width: 8.5rem;
  cursor: pointer;
  text-decoration: none;
  flex-shrink: 0;
}

.book-cover {
  width: 8.5rem;
  height: 12.75rem;
  object-fit: cover;
  display: block;
  border-radius: 0;
  opacity: 0.88;
  transition: opacity 200ms ease;
}
.book-card:hover .book-cover { opacity: 0.55; }

.book-cover-placeholder {
  width: 8.5rem;
  height: 12.75rem;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-serif);
  font-size: 0.72rem;
  color: var(--text);
  text-align: center;
  padding: 0.75rem;
  line-height: 1.4;
}

/* Hover overlay — always dark background so text colors are hardcoded light */
.book-card-overlay {
  position: absolute;
  inset: 0;
  background: rgba(4, 6, 8, 0.88);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 0.25rem;
  padding: 0.65rem 0.55rem;
  opacity: 0;
  transition: opacity 180ms ease;
  overflow-y: auto;
}
.book-card:hover .book-card-overlay { opacity: 1; }

.bco-title {
  font-family: var(--font-serif);
  font-size: 0.78rem;
  color: #e8e2d8;
  line-height: 1.3;
}
.bco-author {
  font-family: var(--font-serif);
  font-size: 0.67rem;
  color: rgba(200, 190, 175, 0.8);
  margin-bottom: 0.05rem;
}
.bco-note {
  font-family: var(--font-serif);
  font-size: 0.58rem;
  font-style: italic;
  color: rgba(200, 190, 175, 0.65);
  line-height: 1.35;
  margin-bottom: 0.1rem;
}
.bco-rating {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: #c9a84c;
  letter-spacing: 0.06em;
}
.bco-tags {
  font-family: var(--font-mono);
  font-size: 0.52rem;
  color: rgba(190, 182, 168, 0.65);
  letter-spacing: 0.04em;
  line-height: 1.4;
}
.bco-status {
  font-family: var(--font-mono);
  font-size: 0.52rem;
  color: rgba(190, 182, 168, 0.5);
  letter-spacing: 0.08em;
  text-transform: lowercase;
}

/* =====================================================
   RECENT READING CARDS (home page)
   ===================================================== */
@keyframes bob {
  from { transform: translateY(0); }
  to   { transform: translateY(-6px); }
}

.reading-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.75rem;
  align-items: flex-end;
}

.reading-card {
  width: 13rem;
  padding: 0.6rem 0.7rem;
  text-decoration: none;
  display: block;
  animation: bob 3s ease-in-out infinite alternate;
  border-width: 1px;
  border-style: solid;
}

.reading-card:nth-child(1) { animation-delay:    0s; animation-duration: 3.2s; }
.reading-card:nth-child(2) { animation-delay: -1.1s; animation-duration: 2.8s; }
.reading-card:nth-child(3) { animation-delay: -2.3s; animation-duration: 3.5s; }
.reading-card:nth-child(4) { animation-delay: -0.7s; animation-duration: 3.0s; }
.reading-card:nth-child(5) { animation-delay: -1.8s; animation-duration: 3.3s; }
.reading-card:nth-child(6) { animation-delay: -0.4s; animation-duration: 2.9s; }
.reading-card:nth-child(7) { animation-delay: -2.6s; animation-duration: 3.1s; }
.reading-card:nth-child(8) { animation-delay: -1.4s; animation-duration: 3.6s; }

.reading-card-book    { border-color: rgba(122, 26, 26, 0.5); }
.reading-card-paper   { border-color: rgba(30, 100, 60, 0.5); }
.reading-card-article { border-color: rgba(140, 110, 10, 0.6); }

.reading-card-book:hover    { border-color: rgba(122, 26, 26, 0.9); }
.reading-card-paper:hover   { border-color: rgba(30, 100, 60, 0.9); }
.reading-card-article:hover { border-color: rgba(140, 110, 10, 0.95); }

[data-theme="dark"] .reading-card-book    { border-color: rgba(192, 72, 72, 0.5); }
[data-theme="dark"] .reading-card-paper   { border-color: rgba(50, 150, 90, 0.5); }
[data-theme="dark"] .reading-card-article { border-color: rgba(201, 168, 76, 0.45); }
[data-theme="dark"] .reading-card-book:hover    { border-color: rgba(192, 72, 72, 0.9); }
[data-theme="dark"] .reading-card-paper:hover   { border-color: rgba(50, 150, 90, 0.9); }
[data-theme="dark"] .reading-card-article:hover { border-color: rgba(201, 168, 76, 0.9); }

.reading-card-title {
  font-size: 0.88rem;
  font-weight: 400;
  color: var(--text);
  line-height: 1.3;
  margin-bottom: 0.2rem;
}

.reading-card-byline {
  font-family: var(--font-mono);
  font-size: 0.58rem;
  color: var(--muted);
  letter-spacing: 0.03em;
  margin-bottom: 0.35rem;
}

.reading-card-note {
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.4;
  opacity: 0.8;
}

/* =====================================================
   PAPER CARDS
   ===================================================== */
.paper-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
  align-items: flex-end;
}

.paper-card {
  border: 1px solid var(--border);
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  animation: bob 2.8s ease-in-out infinite alternate;
  max-width: 16rem;
  text-decoration: none;
  display: block;
}
.paper-card:hover { border-color: var(--crimson); }

.paper-card:nth-child(1) { animation-delay:    0s; animation-duration: 3.1s; }
.paper-card:nth-child(2) { animation-delay: -1.2s; animation-duration: 2.7s; }
.paper-card:nth-child(3) { animation-delay: -0.5s; animation-duration: 3.4s; }
.paper-card:nth-child(4) { animation-delay: -2.1s; animation-duration: 2.9s; }
.paper-card:nth-child(5) { animation-delay: -0.9s; animation-duration: 3.2s; }

.paper-card-title {
  font-size: 0.88rem;
  font-weight: 400;
  color: var(--text);
  line-height: 1.35;
  margin-bottom: 0.3rem;
}

.paper-card-meta {
  font-family: var(--font-mono);
  font-size: 0.58rem;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.paper-card-venue {
  color: var(--crimson);
  opacity: 0.8;
}

/* =====================================================
   TOPICS
   ===================================================== */
.topic-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  margin-top: 1.5rem;
}

.topic-tag {
  font-family: var(--font-mono);
  color: var(--muted);
  cursor: pointer;
  letter-spacing: 0.05em;
  text-decoration: none;
}
.topic-tag:hover { color: var(--accent); }
.topic-tag.lg { font-size: 1rem; color: var(--text); }
.topic-tag.md { font-size: 0.85rem; }
.topic-tag.sm { font-size: 0.7rem; opacity: 0.7; }

.topic-count { opacity: 0.45; font-size: 0.7em; margin-left: 0.2em; }

.topic-group { margin-bottom: 1.75rem; }

.topic-group-label {
  font-family: var(--font-mono);
  font-size: 0.63rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--crimson);
  margin-bottom: 0.6rem;
  display: block;
}

/* =====================================================
   SEARCH
   ===================================================== */
.search-input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-serif);
  font-size: 1.2rem;
  color: var(--text);
  padding: 0.4rem 0;
  outline: none;
  margin-bottom: 2rem;
}
.search-input::placeholder { color: var(--muted); opacity: 0.5; }

/* =====================================================
   FOOTER (removed)
   ===================================================== */

.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--accent); }

/* =====================================================
   SIDENOTES / FOOTNOTES (preserved from original)
   ===================================================== */
input.margin-toggle { display: none; }

.margin-toggle:checked + .sidenote,
.margin-toggle:checked + .marginnote {
  display: block;
  float: left;
  left: 1rem;
  clear: both;
  width: 95%;
  margin: var(--spacing-sm) 2.5%;
  position: relative;
}

.sidenote-number {
  counter-increment: sidenote-counter;
  display: inline;
}

.sidenote-number::after {
  content: counter(sidenote-counter);
  font-size: 0.55em;
  position: relative;
  top: -0.5em;
  color: var(--accent);
  cursor: pointer;
  margin-left: 1px;
}

label.margin-toggle:not(.sidenote-number) {
  display: inline;
  color: var(--accent);
  cursor: pointer;
}

.sidenote,
.marginnote {
  width: 13.5rem;
  font-size: 0.875rem;
  line-height: 1.4;
  color: var(--muted);
}

.sidenote::before {
  position: relative;
}

.sidenote::before {
  content: counter(sidenote-counter) " ";
  font-size: 0.75rem;
  color: var(--accent);
}

.footnotes {
  margin-top: var(--spacing-2xl);
  padding-top: var(--spacing-xl);
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
}

.footnotes ol { padding-left: var(--spacing-lg); }

.footnotes li {
  margin-bottom: var(--spacing-sm);
  color: var(--muted);
}

.footnotes li:target {
  background: var(--color-bg-secondary);
  padding: var(--spacing-xs);
  margin-left: calc(-1 * var(--spacing-xs));
}

.sidenote-ref,
.footnote-ref {
  font-size: 0.8rem;
  vertical-align: super;
  line-height: 0;
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
}
.sidenote-ref:hover,
.footnote-ref:hover { text-decoration: underline; }

.footnote-inline { display: none; }
.footnote-inline.visible {
  display: block;
  font-size: 0.875rem;
  color: var(--muted);
  border-left: 2px solid var(--accent);
  padding: var(--spacing-sm) var(--spacing-md);
  margin: var(--spacing-sm) 0;
}

.footnote-tooltip {
  position: absolute;
  z-index: 1000;
  max-width: 300px;
  padding: var(--spacing-md);
  background: var(--color-surface);
  border: 1px solid var(--border);
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--text);
}

@media (max-width: 999px) {
  .post-layout { grid-template-columns: 10rem 1fr; }
  .post-content { grid-column: 2; }
  label.margin-toggle:not(.sidenote-number) { display: inline; }
  .sidenote, .marginnote { display: none; }
  .margin-toggle:checked + .sidenote,
  .margin-toggle:checked + .marginnote {
    display: block;
    float: none;
    left: 0;
    width: 100%;
    margin: var(--spacing-sm) 0;
    padding: var(--spacing-sm);
    background: var(--color-bg-secondary);
    border-left: 2px solid var(--accent);
  }
}
@media (min-width: 1000px) {
  label.margin-toggle:not(.sidenote-number) { display: none; }
  label.sidenote-number { pointer-events: none; }
  .sidenote, .marginnote,
  .margin-toggle:checked + .sidenote,
  .margin-toggle:checked + .marginnote {
    display: block;
    position: absolute;
    left: calc(100% + 2rem);
    top: auto;
    width: 12rem;
    margin: 0;
    float: none;
    padding: 0;
    background: none;
    border-left: none;
  }
}

/* =====================================================
   KaTeX — inherit palette
   ===================================================== */
.katex { color: var(--text); }

/* =====================================================
   BOOK TOOLTIP (Tippy lunacleon theme)
   ===================================================== */
.tippy-box[data-theme~='lunacleon'] {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-serif);
  font-size: 0.82rem;
  border-radius: 0;
}
.tippy-box[data-theme~='lunacleon'] .tippy-arrow::before {
  border-top-color: var(--border);
}
.btt-wrap   { display: flex; flex-direction: column; gap: 0.25rem; padding: 0.1rem; }
.btt-title  { font-family: var(--font-serif); font-size: 0.88rem; color: var(--text); line-height: 1.3; }
.btt-author { font-family: var(--font-serif); color: var(--muted); font-size: 0.78rem; }
.btt-rating { font-family: var(--font-mono); font-size: 0.68rem; color: var(--accent); letter-spacing: 0.06em; }
.btt-meta   { font-family: var(--font-mono); font-size: 0.62rem; color: var(--muted); opacity: 0.7; letter-spacing: 0.04em; text-transform: lowercase; }
.btt-tags   { font-family: var(--font-mono); font-size: 0.6rem; color: var(--muted); opacity: 0.6; letter-spacing: 0.04em; }
.btt-desc   { font-style: italic; color: var(--muted); font-size: 0.78rem; line-height: 1.4; margin-top: 0.1rem; }
.btt-link   { font-family: var(--font-mono); font-size: 0.65rem; color: var(--accent); text-decoration: none; margin-top: 0.15rem; }
.btt-link:hover { text-decoration: underline; }
.btt-link   { font-family: var(--font-mono); font-size: 0.62rem; color: var(--accent); letter-spacing: 0.04em; }
.btt-link:hover { color: var(--text); }

/* =====================================================
   LINK PREVIEW (Tippy)
   ===================================================== */
.tippy-box { border-radius: 0 !important; }

/* =====================================================
   RESPONSIVE
   ===================================================== */

/* Collapse TOC at 900px — gives content more room before the 720px single-column switch */
@media (max-width: 900px) {
  .post-layout { grid-template-columns: 1fr; }
  .post-content { grid-column: 1; }
  .toc { display: none; }
}

@media (max-width: 720px) {
  .post-layout { padding-top: 1.5rem; }
}

/* Tag bar: collapse to thin texture strip on mobile (text too small to read) */
@media (max-width: 600px) {
  .tag-bar  { height: 5px; gap: 1px; }
  .tag-seg  { font-size: 0; padding: 0; }
}

/* Reading log entries: tighten at very small screens */
@media (max-width: 480px) {
  .nav-wrapper { padding: 1.25rem 0 1rem; }
  .post-title { font-size: 1.15rem; }
  .reading-card { width: calc(50% - 0.3rem); }
  .reading-entry { grid-template-columns: 2.75rem 1fr auto; gap: 0.25rem 0.35rem; }
  .entry-date { font-size: 0.5rem; }
  .entry-body { font-size: 0.82rem; }
}
