@import url('https://fonts.googleapis.com/css2?family=Handlee&family=Kalam:wght@300;400;700&family=Caveat:wght@400;700&family=LXGW+WenKai+Mono+TC&family=EB+Garamond:ital,wght@0,400;0,500;1,400&family=Cinzel:wght@400;500&family=Lora:ital,wght@0,400;1,400&display=swap');

[id] { scroll-margin-top: 300px; }

/* ─── DARK NOTEBOOK THEME (default) ─── */
:root {
  --bg:         #1a1a2e;
  --bg-card:    #222244;
  --text:       #e8e6f0;
  --text-muted: #a0a0c8;
  --text-faint: #5a5a7a;
  --accent:     #8090d8;
  --accent-lt:  #a0b0e8;
  --gold:       #c9a84c;
  --gold-lt:    #e0c870;
  --border:     rgba(160, 160, 200, 0.18);
  --terra:      #c07050;
  --blue-tile:  #6080c0;
  --blue-deep:  #404090;
  --teal-lt:    #60a8b8;

  --serif:      'Handlee', 'Kalam', 'LXGW WenKai Mono TC', 'Caveat', cursive;
  --titling:    'Handlee', 'Kalam', 'LXGW WenKai Mono TC', 'Caveat', cursive;
  --body-serif: 'Handlee', 'Kalam', 'LXGW WenKai Mono TC', 'Caveat', cursive;

  --toc-width:     220px;
  --content-width: 680px;
  --title-h:       0px;
  --h2-h:          0px;

  --tile-img:  none;
  --tile-size: auto;
  --tile-pos:  0 0;

  --pen-h1: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='14' preserveAspectRatio='none'%3E%3Cpath d='M2,10 C60,5 120,13 180,8 C240,4 300,11 360,7 C385,5 395,8 398,8' stroke='%23a0a0c8' stroke-width='2.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  --pen-h2: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='10' preserveAspectRatio='none'%3E%3Cpath d='M1,7 C40,3 80,9 120,6 C160,3 200,8 240,5 C270,4 285,7 299,6' stroke='%23a0a0c8' stroke-width='1.8' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
}

/* ─── LIGHT NOTEBOOK THEME ─── */
[data-theme="notebook"] {
  --bg:         #f7f4ec;
  --bg-card:    #f9f7f2;
  --text:       #1c1c4a;
  --text-muted: #3d3d6b;
  --text-faint: #8888a8;
  --accent:     #2c3e8c;
  --accent-lt:  #4a5fbd;
  --gold:       #a07020;
  --gold-lt:    #c89a40;
  --border:     rgba(28, 28, 74, 0.16);
  --terra:      #8c3a1e;
  --blue-tile:  #2c3e8c;
  --blue-deep:  #1a1a4a;
  --teal-lt:    #4a7a8c;

  --serif:      'Handlee', 'Kalam', 'LXGW WenKai Mono TC', 'Caveat', cursive;
  --titling:    'Handlee', 'Kalam', 'LXGW WenKai Mono TC', 'Caveat', cursive;
  --body-serif: 'Handlee', 'Kalam', 'LXGW WenKai Mono TC', 'Caveat', cursive;

  --tile-img:  none;
  --tile-size: auto;
  --tile-pos:  0 0;

  --pen-h1: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='14' preserveAspectRatio='none'%3E%3Cpath d='M2,10 C60,5 120,13 180,8 C240,4 300,11 360,7 C385,5 395,8 398,8' stroke='%231c1c4a' stroke-width='2.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  --pen-h2: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='10' preserveAspectRatio='none'%3E%3Cpath d='M1,7 C40,3 80,9 120,6 C160,3 200,8 240,5 C270,4 285,7 299,6' stroke='%231c1c4a' stroke-width='1.8' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
}

/* ─── MOSAIC THEME ─── */
[data-theme="mosaic"] {
  --mosaic-bone:      #F7F5F0;
  --mosaic-amber:     #D98218;
  --mosaic-amber-lt:  #F0B054;
  --mosaic-teal-deep: #185B5D;
  --mosaic-teal-mid:  #2C8A8C;
  --mosaic-teal-lt:   #67BDBD;
  --mosaic-blue-tile: #5B8EA6;
  --mosaic-blue-deep: #1E4057;
  --mosaic-terra:     #C44D29;
  --mosaic-dark:      #1A2121;
  --mosaic-grout:     #D8D3C7;
  --mosaic-yellow:    #25413987;

  --bg:         #121616;
  --bg-card:    #1A2020;
  --text:       #EAE6DC;
  --text-muted: #AFA8C8;
  --text-faint: #7D7970;
  --accent:     var(--mosaic-teal-lt);
  --accent-lt:  var(--mosaic-teal-mid);
  --gold:       var(--mosaic-amber);
  --gold-lt:    var(--mosaic-amber-lt);
  --border:     #2D3838;
  --terra:      var(--mosaic-terra);
  --blue-tile:  var(--mosaic-blue-tile);
  --blue-deep:  var(--mosaic-blue-deep);
  --teal-lt:    var(--mosaic-teal-lt);

  --serif:      'EB Garamond', Georgia, serif;
  --titling:    'Cinzel', 'Trajan Pro', serif;
  --body-serif: 'Lora', Georgia, serif;

  --tile-img:
    linear-gradient(45deg, rgba(0,0,0,0.03) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(0,0,0,0.03) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(0,0,0,0.03) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(0,0,0,0.03) 75%);
  --tile-size: 6px 6px;
  --tile-pos:  0 0, 0 3px, 3px -3px, -3px 0px;
}


/* ─── Scrollbar ─── */
html { scrollbar-width: none; -ms-overflow-style: none; }
html::-webkit-scrollbar { display: none; }

/* ─── Base ─── */
body {
  margin: 0;
  font-family: var(--body-serif);
  background-color: var(--bg);
  background-image: var(--tile-img);
  background-size: var(--tile-size);
  background-position: var(--tile-pos);
  color: var(--text);
  line-height: 1.85;
  font-size: 1.15rem;
}

a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}

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

a[href^="http"]::after {
  content: '➚';
  font-size: 0.62em;
  vertical-align: super;
  margin-left: 0.12em;
  opacity: 0.55;
  font-style: normal;
  display: inline-block;
}

[data-theme="mosaic"] a { transition: border-color 0.2s; }

[data-theme="mosaic"] a[href^="http"]::after {
  color: var(--gold);
  opacity: 0.7;
}

/* ─── Layout ─── */
#content {
  display: grid;
  grid-template-columns: var(--toc-width) 1fr;
  align-items: start;
  gap: 3rem;
  max-width: calc(var(--toc-width) + var(--content-width) + 7rem);
  margin: 0 auto;
  padding: 3rem;
  padding-top: 0;
}

#content.no-toc {
  grid-template-columns: 1fr;
  max-width: calc(var(--content-width) + 6rem);
}

#content.no-toc > * { grid-column: 1; }

/* ─── Sticky title wrapper ─── */
.title-sticky-wrap {
  grid-column: 1 / -1;
  grid-row: 1;
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: var(--bg);
  background-image: var(--tile-img);
  background-size: var(--tile-size);
  background-position: var(--tile-pos);
  padding: 1.6rem 0 0;
  margin: 0 0 -2rem;
}

/* ─── h1.title — NOTEBOOK/DARK: handwritten with pen underline ─── */
h1.title {
  font-family: var(--titling);
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-transform: none;
  color: var(--text);
  margin: 0;
  padding-bottom: 1.2rem;
  position: relative;
}

h1.title::before { display: none; }

h1.title::after {
  content: '';
  display: block;
  position: absolute;
  bottom: 0; left: 0; right: 0;
  width: 100%;
  height: 14px;
  background: var(--pen-h1) no-repeat;
  background-size: 100% 100%;
  transition: none;
}

/* ─── h1.title — MOSAIC: progress bar ─── */
[data-theme="mosaic"] h1.title {
  font-size: 1.7rem;
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding-bottom: 1rem;
}

[data-theme="mosaic"] h1.title::before {
  display: block;
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 6px;
  background: var(--mosaic-dark);
}

[data-theme="mosaic"] h1.title::after {
  width: var(--title-progress, 0%);
  height: 6px;
  background: var(--gold);
  background-image: none;
  transition: width 0.05s linear;
}

/* ─── TOC ─── */
#table-of-contents {
  position: sticky;
  top: 12rem;
  align-self: start;
  max-height: calc(60vh - var(--title-h, 2rem) - 2rem);
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: 1rem 1.2rem 1rem 0;
  font-size: 0.85rem;
  border-right: 2px solid var(--border);
}

#table-of-contents::-webkit-scrollbar { display: none; }

#table-of-contents h2 {
  position: sticky;
  top: -25px;
  z-index: 90;
  font-family: var(--titling);
  font-size: 0.95rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  margin: 0;
  padding: 0;
  height: 45px;
  background-color: var(--bg);
  background-image: var(--tile-img);
  background-size: var(--tile-size);
  background-position: var(--tile-pos);
}

#table-of-contents h2::before { display: none !important; }
#table-of-contents h2::after  { display: none !important; }

#table-of-contents ul {
  list-style: none;
  padding: 0;
}

#table-of-contents ul ul { padding-left: 1rem; }

#table-of-contents ul ul a {
  font-size: 0.78rem;
  color: var(--text-faint);
  font-style: normal;
}

#table-of-contents a {
  display: block;
  padding: 3px 0;
  color: var(--text-muted);
  font-family: var(--serif);
  font-style: normal;
  transition: color 0.2s;
  border-bottom: none;
}

#table-of-contents a:hover {
  color: var(--accent);
  border-bottom: none;
}

#text-table-of-contents a.toc-active {
  color: var(--accent);
  font-weight: 600;
  border-left: 2px solid var(--accent);
  border-bottom: none;
  padding-left: 6px;
  margin-left: -6px;
}

[data-theme="mosaic"] #table-of-contents {
  border-right: 6px solid transparent;
  border-image:
    repeating-linear-gradient(
      to bottom,
      var(--mosaic-yellow) 0px, var(--mosaic-yellow) 6px,
      var(--bg) 6px, var(--bg) 10px
    ) 1;
}

[data-theme="mosaic"] #table-of-contents h2 {
  font-family: 'Cinzel', serif;
  font-size: 0.79rem;
  height: 70px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--gold);
}

[data-theme="mosaic"] #table-of-contents a {
  font-family: 'EB Garamond', serif;
  font-style: italic;
  position: relative;
  overflow: hidden;
}

[data-theme="mosaic"] #table-of-contents a::before {
  content: '';
  position: absolute;
  left: -100%;
  top: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(to right,
    color-mix(in srgb, var(--gold) 12%, transparent),
    transparent
  );
  transition: left 0.3s ease;
  pointer-events: none;
}

[data-theme="mosaic"] #table-of-contents a:hover { color: var(--accent); border-left: 3px solid var(--gold); }
[data-theme="mosaic"] #table-of-contents a:hover::before { left: 0; }

[data-theme="mosaic"] #text-table-of-contents a.toc-active {
  color: var(--accent);
  font-weight: 500;
  border-left: 3px solid var(--blue-tile);
  padding-left: 6px;
  margin-left: -6px;
}

/* ─── Content area ─── */
#content > div[id^="outline-container"] { grid-column: 2; min-width: 0; }

#content > div[id^="outline-container"] > div[id^="outline-text"],
#content > div[id^="outline-container"] > div[id^="outline-container"] {
  max-width: var(--content-width);
}

/* ─── h2 — NOTEBOOK/DARK: pen underline ─── */
h2 {
  font-family: var(--titling);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-transform: none;
  margin-top: 0;
  margin-bottom: 1.2rem;
  padding-bottom: 0.8rem;
  color: var(--text);
  position: relative;
}

h2::before { display: none; }

h2::after {
  content: '';
  display: block;
  position: absolute;
  bottom: 0; left: 0; right: 0;
  width: 100%;
  height: 10px;
  background: var(--pen-h2) no-repeat;
  background-size: 100% 100%;
  transition: none;
}

/* ─── h2 — MOSAIC: progress bar ─── */
[data-theme="mosaic"] h2 {
  font-family: 'Cinzel', serif;
  font-size: 1.1rem;
  font-weight: 400;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 1.2rem;
  padding-bottom: 0.6rem;
}

[data-theme="mosaic"] h2::before {
  display: block;
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 4px;
  background: var(--mosaic-dark);
}

[data-theme="mosaic"] h2::after {
  width: var(--h2-progress, 0%);
  height: 4px;
  background: var(--mosaic-yellow);
  background-image: none;
  transition: width 0.05s linear;
}

/* ─── h2-sticky-wrap ─── */
.h2-sticky-wrap {
  position: sticky;
  top: var(--title-h, 0px);
  z-index: 90;
  background-color: var(--bg);
  background-image: var(--tile-img);
  background-size: var(--tile-size);
  background-position: var(--tile-pos);
  padding: 0.8rem 0.1rem 0.1rem;
  margin: 0.5rem 0 0.4rem;
}

[data-theme="mosaic"] .h2-sticky-wrap {
  box-shadow: 0 10px 16px -6px rgb(from var(--bg) r g b / 0.7);
}

/* ─── h3 ─── */
h3 {
  font-family: var(--serif);
  font-size: 1.3rem;
  font-weight: 600;
  font-style: normal;
  color: var(--text-muted);
  margin-top: 2rem;
  margin-bottom: 0.5rem;
  letter-spacing: 0.01em;
  display: inline-block;
  position: relative;
  transition: color 0.3s ease 0.1s;
}

h3::after {
  content: '';
  position: absolute;
  bottom: -2px; left: 0;
  width: 0%;
  height: 2px;
  background: var(--gold);
  border-radius: 1px;
}

h3.ink-draw::after { animation: inkBounce 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards; }
h3.ink-draw { color: var(--accent); }

[data-theme="mosaic"] h3 {
  font-family: 'EB Garamond', serif;
  font-size: 1.25rem;
  font-weight: bolder;
  font-style: italic;
}

/* ─── h4 ─── */
h4 {
  font-family: var(--titling);
  font-size: 0.95rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0.04em;
  color: var(--terra);
  margin-top: 1.8rem;
  margin-bottom: 0.5rem;
}

[data-theme="mosaic"] h4 {
  font-family: 'Cinzel', serif;
  font-size: 0.68rem;
  font-weight: bolder;
  text-transform: uppercase;
  letter-spacing: 0.18em;
}

/* ─── Body text ─── */
p {
  margin-bottom: 1.1rem;
  max-width: 65ch;
  font-size: 1.1rem;
}

/* ─── Center panel ─── */
.org-center {
  text-align: center;
  font-family: var(--titling);
  font-size: 1rem;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 0.8rem 1.2rem;
  margin: 1.5rem 0;
  position: relative;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

[data-theme="mosaic"] .org-center {
  font-family: 'Cinzel', serif;
  font-size: 0.85rem;
  letter-spacing: 0.12em;
  overflow: hidden;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-image: linear-gradient(to right,
    var(--border) 0%, var(--border) 1px,
    var(--border) 1px, var(--border) 3px,
    var(--border) 3px, var(--border) 4px
  ) 1;
}

[data-theme="mosaic"] .org-center::before {
  content: '';
  position: absolute;
  top: 0; left: -60%;
  width: 50%;
  height: 100%;
  background: linear-gradient(
    to right,
    transparent 0%,
    color-mix(in srgb, var(--gold) 18%, transparent) 50%,
    transparent 100%
  );
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s;
}

[data-theme="mosaic"] .org-center:hover::before {
  opacity: 1;
  animation: shimmerSweep 0.9s ease-in-out forwards;
}

/* ─── Blockquote ─── */
blockquote {
  position: relative;
  margin: 2rem 0 2rem 0.4rem;
  padding: 1.1rem 1.4rem 1.1rem 2.2rem;
  background: color-mix(in srgb, var(--gold) 7%, var(--bg));
  border-left: 2px solid color-mix(in srgb, var(--gold) 50%, transparent);
  border-radius: 0 8px 8px 0;
  font-style: italic;
  color: var(--text-muted);
  transform: rotate(-0.3deg);
}

blockquote > p {
  max-width: 100%;
  font-size: 1.05rem;
}

blockquote::before {
  content: '\201C';
  position: absolute;
  top: -0.5rem;
  left: 0.3rem;
  font-size: 5rem;
  line-height: 1;
  color: var(--gold);
  opacity: 0.2;
  font-family: Georgia, serif;
  pointer-events: none;
}

blockquote > p:last-child {
  font-style: normal;
  font-size: 0.85em;
  color: var(--text-faint);
  text-align: right;
  margin-bottom: 0;
  margin-top: 0.6rem;
  letter-spacing: 0.02em;
}

[data-theme="mosaic"] blockquote {
  transform: none;
  background: color-mix(in srgb, var(--mosaic-teal-deep) 10%, var(--bg));
  border-left: 4px solid var(--gold);
  border-radius: 0;
}

[data-theme="mosaic"] blockquote::before {
  font-family: 'EB Garamond', Georgia, serif;
  color: var(--gold);
  opacity: 0.35;
  font-size: 6rem;
  top: -1.1rem;
  left: 0.2rem;
}

[data-theme="mosaic"] blockquote > p:last-child {
  font-family: 'EB Garamond', serif;
  font-style: italic;
  color: var(--teal-lt);
}

/* ─── Images & Figures ─── */
.figure img {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: 4px;
  border: 1px solid var(--border);
  box-shadow: 0 4px 14px -4px rgba(0, 0, 0, 0.45);
}

.figure {
  margin: 2rem auto;
  text-align: center;
  max-width: fit-content;
  transform: rotate(-0.2deg);
}

.figure p:first-child {
  margin: 0;
}

.figure p:last-child {
  margin: 0.5rem 0 0;
  font-size: 0.82em;
  color: var(--text-faint);
  font-style: italic;
  letter-spacing: 0.02em;
}

.figure-number {
  color: var(--gold);
  font-style: normal;
}

[data-theme="mosaic"] .figure {
  transform: none;
  border: 1px solid var(--border);
  padding: 0.6rem;
  background: var(--bg-card);
  background-image: var(--tile-img);
  background-size: var(--tile-size);
  background-position: var(--tile-pos);
}

[data-theme="mosaic"] .figure img {
  border-radius: 0;
  border: none;
  box-shadow: none;
}

[data-theme="mosaic"] .figure p:last-child {
  color: var(--teal-lt);
  font-family: 'EB Garamond', serif;
}

/* ─── Lists ─── */
ul.org-ul {
  list-style: none;
  padding-left: 0;
}

ul.org-ul li {
  padding-left: 1.5rem;
  position: relative;
  margin: 0.35rem 0;
  font-size: 1.05rem;
  opacity: 0;
  transform: translateX(-10px);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

ul.org-ul li::before {
  content: '—';
  position: absolute;
  left: 0;
  color: var(--text-faint);
  font-size: 0.9rem;
  top: 0.05em;
}

ul.org-ul li.list-visible { opacity: 1; transform: translateX(0); }

[data-theme="mosaic"] ul.org-ul li::before {
  content: '◆';
  color: var(--mosaic-teal-deep);
  font-size: 0.55rem;
  top: 0.55rem;
  display: inline-block;
  transition: transform 0.15s ease, color 0.2s;
  cursor: default;
}

[data-theme="mosaic"] ul.org-ul li:hover { padding-left: 1.8rem; }
[data-theme="mosaic"] ul.org-ul li:hover::before {
  animation: diamondPop 0.6s cubic-bezier(0.36, 0.07, 0.19, 0.97) forwards;
  color: var(--gold);
}

ol.org-ol { padding-left: 1.4rem; }

ol.org-ol li {
  margin: 0.9rem 0;
  padding-left: 0.3rem;
  position: relative;
  opacity: 0;
  transform: translateX(-10px);
  transition: opacity 0.35s ease, transform 0.35s ease, padding-left 0.2s ease;
}

ol.org-ol li.list-visible { opacity: 1; transform: translateX(0); }

ol.org-ol > li:hover { padding-left: 0.6rem; }
ol.org-ol > li:hover > p:first-child { color: var(--accent); }

ol.org-ol > li > p:first-child {
  font-family: var(--titling);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
  transition: color 0.25s ease;
}

[data-theme="mosaic"] ol.org-ol > li:hover > p:first-child { letter-spacing: 0.07em; }
[data-theme="mosaic"] ol.org-ol > li > p:first-child {
  font-family: 'Cinzel', serif;
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  transition: color 0.25s ease, letter-spacing 0.25s ease;
}

/* ─── Inline code ─── */
code {
  background: color-mix(in srgb, var(--blue-tile) 12%, transparent);
  color: var(--blue-deep);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.88em;
  font-family: monospace;
}

/* ─── Backlinks ─── */
.backlinks {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.backlinks-heading {
  font-family: var(--titling);
  font-size: 0.9rem;
  text-transform: none;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  margin-bottom: 0.8rem;
  display: block;
}

.backlinks ul.org-ul li::before {
  content: '←';
  color: var(--text-faint);
  font-size: 0.85rem;
  top: 0.1em;
}

.backlinks ul.org-ul li:hover::before {
  transform: translateX(-4px);
  animation: none;
}

.backlinks a {
  color: var(--accent);
  font-family: var(--serif);
  font-size: 1rem;
  border-bottom: none;
  display: inline-block;
  transition: transform 0.2s ease, color 0.2s;
}

.backlinks a:hover {
  transform: translateX(4px);
  color: var(--gold);
  border-bottom: none;
}

[data-theme="mosaic"] .backlinks {
  border-top: 4px solid transparent;
  border-image: linear-gradient(to right,
    var(--border) 0%, var(--border) 1px,
    var(--border) 1px, var(--border) 3px,
    var(--border) 3px, var(--border) 4px
  ) 1;
}

[data-theme="mosaic"] .backlinks-heading {
  font-family: 'Cinzel', serif;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--gold);
}

[data-theme="mosaic"] .backlinks ul.org-ul li::before {
  content: '←';
  color: var(--teal-lt);
  font-size: 0.75rem;
  top: 0.35rem;
  animation: none;
}

[data-theme="mosaic"] .backlinks ul.org-ul li:hover::before {
  transform: translateX(-4px);
  animation: none;
}

[data-theme="mosaic"] .backlinks a {
  font-family: 'EB Garamond', serif;
  font-style: italic;
  font-size: 0.95rem;
}

/* ─── Giscus Comments ─── */
#content > .giscus {
  grid-column: 2;
  min-width: 0;
  max-width: var(--content-width);
}

#content.no-toc > .giscus {
  grid-column: 1;
}

.giscus {
  position: relative;
}

.giscus-frame {
  border-radius: 4px;
  border: none;
  width: 100%;
}

[data-theme="mosaic"] .giscus {
  border-top: 4px solid transparent;
  border-image:
    linear-gradient(to right,
      var(--border) 0%, var(--border) 1px,
      var(--border) 1px, var(--border) 3px,
      var(--border) 3px, var(--border) 4px
    ) 1;
}


/* ─── Postamble ─── */
#postamble { display: none; }

/* ─── Colophon ─── */
.colophon {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.6rem;
  font-family: var(--serif);
  font-style: normal;
  font-size: 0.95rem;
  color: var(--text-faint);
  margin: 12px 0;
  border-top: none;
}

[data-theme="mosaic"] .colophon {
  font-family: 'EB Garamond', serif;
  font-style: italic;
  font-size: 0.82rem;
}

.colophon .colophon-sep {
  color: var(--text-faint);
  font-style: normal;
  font-size: 0.8rem;
  display: inline-block;
}

[data-theme="mosaic"] .colophon .colophon-sep {
  color: var(--gold);
  font-size: 0.7rem;
  animation: continuousRotation 2s linear infinite;
}

/* ─── Shimmer layers (mosaic only) ─── */
.h2-shimmer-layer,
.title-shimmer-layer { display: none; }

[data-theme="mosaic"] .h2-shimmer-layer {
  display: block;
  position: absolute;
  bottom: 0; left: 0;
  width: var(--h2-progress, 0%);
  height: 4px;
  overflow: hidden;
  pointer-events: none;
  z-index: 1;
}

[data-theme="mosaic"] .h2-shimmer-layer::after {
  content: '';
  position: absolute;
  top: 0; left: -50%;
  width: 45%;
  height: 100%;
  background: linear-gradient(to right, transparent 0%, rgba(255,255,255,0.5) 50%, transparent 100%);
  animation: shimmerPass 2.4s ease-in-out infinite;
}

[data-theme="mosaic"] .title-shimmer-layer {
  display: block;
  position: absolute;
  bottom: 0; left: 0;
  width: var(--title-progress, 0%);
  height: 6px;
  overflow: hidden;
  pointer-events: none;
  z-index: 1;
}

[data-theme="mosaic"] .title-shimmer-layer::after {
  content: '';
  position: absolute;
  top: 0; left: -50%;
  width: 60%;
  height: 100%;
  background: linear-gradient(to right, transparent 0%, rgba(255,255,255,0.5) 50%, transparent 100%);
  animation: shimmerPass 3s ease-in-out infinite;
}

/* ─── Mosaic corner (desktop only) ─── */
@media (min-width: 861px) {
  #mosaic-corner {
    position: fixed;
    bottom: 0; right: 0;
    width: 80px;
    z-index: 500;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  #mosaic-corner-label {
    font-family: var(--titling);
    font-size: 0.42rem;
    text-transform: uppercase;
    letter-spacing: 0.22em;
    color: var(--text-faint);
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    padding: 8px 0 4px;
    opacity: 0.4;
    transition: opacity 0.3s;
    cursor: default;
    user-select: none;
    align-self: flex-end;
    margin-right: 6px;
  }

  #mosaic-corner:hover #mosaic-corner-label { opacity: 0.9; }

  #mosaic-grid {
    display: grid;
    grid-template-columns: repeat(3, 22px);
    gap: 2px;
    padding: 6px;
    background: var(--bg);
    border-top: 1px solid var(--border);
    border-left: 1px solid var(--border);
    border-top-left-radius: 8px;
  }

  .mc-tile {
    width: 22px;
    height: 22px;
    border-radius: 3px;
    cursor: pointer;
    animation: mcFloat var(--dur, 3s) ease-in-out infinite;
    animation-delay: var(--delay, 0s);
    transition: border-radius 0.25s ease;
    position: relative;
  }

  .mc-tile:hover { border-radius: 3px; }

  .mc-tile.mc-active {
    animation: none;
    outline: 2px solid var(--text-faint);
    outline-offset: -1px;
    border-radius: 4px;
  }
}

/* ─── Animations ─── */
@keyframes diamondPop {
  0%   { transform: scale(1) rotate(0deg); }
  30%  { transform: scale(2.2) rotate(25deg); }
  60%  { transform: scale(0.8) rotate(-10deg); }
  100% { transform: scale(1) rotate(0deg); }
}

@keyframes shimmerPass {
  0%   { left: -50%; }
  100% { left: 150%; }
}

@keyframes shimmerSweep {
  0%   { left: -60%; }
  100% { left: 110%; }
}

@keyframes inkBounce {
  0%   { width: 0%; }
  65%  { width: 115%; }
  80%  { width: 92%; }
  90%  { width: 104%; }
  100% { width: 100%; }
}

@keyframes continuousRotation {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

@keyframes mcFloat {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  33%       { transform: translateY(-3px) rotate(2deg); }
  66%       { transform: translateY(2px) rotate(-1deg); }
}

@keyframes mcPop {
  0%   { transform: scale(1) rotate(0deg); }
  30%  { transform: scale(1.7) rotate(20deg); }
  60%  { transform: scale(0.85) rotate(-10deg); }
  100% { transform: scale(1) rotate(0deg); }
}

/* ─── Tables ─── */

/* Enable horizontal scroll on narrow content containers */
div[class^="outline-text"] { overflow-x: auto; scrollbar-width: none; -ms-overflow-style: none; }
div[class^="outline-text"]::-webkit-scrollbar { display: none; }

table {
  border-collapse: collapse;
  font-size: clamp(0.8rem, 1.1vw, 1rem);
  font-family: var(--body-serif);
  width: max-content;
  max-width: none;
  margin: 1.5rem 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
}

thead {
  background: color-mix(in srgb, var(--text) 8%, var(--bg-card));
  border-bottom: 2px solid var(--accent);
}

thead th {
  font-family: var(--titling);
  font-weight: 600;
  font-size: 0.83em;
  letter-spacing: 0.05em;
  padding: 0.65em 1.1em;
  color: var(--text);
  border-right: 1px solid var(--border);
  white-space: nowrap;
  vertical-align: bottom;
}

thead th:last-child { border-right: none; }

tbody tr:nth-child(even) {
  background: color-mix(in srgb, var(--border) 28%, transparent);
}

tbody tr:hover {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

tbody td {
  padding: 0.45em 1.1em;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 55%, transparent);
  border-right: 1px solid color-mix(in srgb, var(--border) 40%, transparent);
  color: var(--text);
  vertical-align: middle;
}

tbody td:last-child { border-right: none; }
tbody tr:last-child td { border-bottom: none; }

tbody td:first-child {
  font-family: var(--titling);
  font-size: 0.8em;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  border-right: 2px solid var(--border);
  white-space: nowrap;
  background: color-mix(in srgb, var(--text) 4%, var(--bg-card));
}

/* Column alignment — also resets any div.org-center bleed into cells */
td.org-left,   th.org-left   { text-align: left; }
td.org-right,  th.org-right  { text-align: right; }
td.org-center, th.org-center {
  text-align: center;
  font-family: inherit;
  font-size: inherit;
  letter-spacing: inherit;
  padding: 0.45em 1.1em;
  margin: 0;
  border-top: none;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 40%, transparent);
  border-image: none;
  position: static;
  overflow: visible;
  background: none;
}
td.org-center:last-child { border-right: none; }

/* ─── Mosaic table overrides ─── */
[data-theme="mosaic"] table {
  border: 2px solid var(--border);
  border-radius: 2px;
}

[data-theme="mosaic"] thead {
  background: var(--mosaic-dark);
  border-bottom: 3px solid var(--gold);
}

[data-theme="mosaic"] thead th {
  font-family: 'Cinzel', serif;
  font-size: 0.72em;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: #EAE6DC;
  border-right-color: rgba(255,255,255,0.07);
}

[data-theme="mosaic"] thead th:last-child { border-right: none; }

[data-theme="mosaic"] tbody tr:hover {
  background: color-mix(in srgb, var(--mosaic-teal-deep) 16%, transparent);
}

[data-theme="mosaic"] tbody td:first-child {
  font-family: 'Cinzel', serif;
  font-size: 0.72em;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: color-mix(in srgb, var(--mosaic-teal-deep) 7%, var(--bg-card));
}

[data-theme="mosaic"] td.org-center,
[data-theme="mosaic"] th.org-center {
  font-family: 'EB Garamond', serif;
  font-size: inherit;
}

/* ─── Mobile (≤ 860px) ─── */
@media (max-width: 860px) {
  body { font-size: 1.05rem; }

  ul.org-ul li,
  ol.org-ol li { opacity: 1 !important; transform: none !important; }

  h3 { display: block; }

  #mosaic-corner { display: none !important; }

  #content { display: block; padding: 0 1.2rem 3rem; }

  .title-sticky-wrap { position: static; padding: 1.4rem 0 0; margin: 0; }

  h1.title {
    font-size: 1.7rem;
    padding-bottom: 1rem;
  }

  [data-theme="mosaic"] h1.title { font-size: 1.5rem; letter-spacing: 0.04em; }
  [data-theme="mosaic"] h1.title::after { width: 100%; background: var(--accent); transition: none; }

  #table-of-contents {
    position: sticky;
    top: 0.6rem;
    z-index: 200;
    max-height: 13vh;
    width: 92%;
    margin: 0.8rem auto 1.6rem;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.6rem 0.8rem;
    border-radius: 18px;
    border-right: none;
    border-image: none;
    scrollbar-width: none;
    background: rgb(from var(--bg-card) r g b / 0.88);
    background-image: none;
    backdrop-filter: blur(8px);
    box-shadow: 0 10px 25px -10px rgb(0 0 0 / 0.2), 0 2px 6px rgb(0 0 0 / 0.1);
  }

  #table-of-contents::-webkit-scrollbar { display: none; }

  #table-of-contents h2 {
    font-size: 0.95rem;
    letter-spacing: 0.1em;
    text-align: center;
    margin: 0 0 2rem;
    padding-top: 25px;
    padding-bottom: 40px;
    top: -15px;
    background-color: var(--bg-card);
    background-image: none;
    height: 0px;
  }

  #table-of-contents ul {
    width: 100%;
    padding: 0;
    margin: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  #table-of-contents li { width: 100%; }

  #table-of-contents a {
    padding: 0.25rem 0;
    font-size: 0.75rem;
    font-style: normal;
    color: var(--text-faint);
    white-space: normal;
    word-break: break-word;
    transition: all 0.2s ease;
  }

  #table-of-contents a:hover { color: var(--accent); }
  #text-table-of-contents a.toc-active { color: var(--accent); font-weight: 600; }

  h2::before, h2::after { display: none; }

  .h2-sticky-wrap { position: unset; padding-top: 0.6rem; margin: 0 0 1rem; }

  h2 { font-size: 1.3rem; letter-spacing: 0.01em; margin-bottom: 0.8rem; }
  h3 { font-size: 1.2rem; margin-top: 1.5rem; }
  h4 { font-size: 0.8rem; }

  p { font-size: 1rem; max-width: 100%; }

  .colophon {
    flex-wrap: wrap;
    gap: 0.4rem 1rem;
    margin-top: 0.1rem;
    padding-top: 0.6rem;
    padding-bottom: 0.1rem;
    line-height: 1.5;
  }

  .colophon .colophon-sep { display: none; }
  .colophon span, .colophon p, .colophon a { display: block; width: 100%; }

  .org-center { font-size: 0.9rem; padding: 0.6rem 0.8rem; margin: 1rem 0; }

  ul.org-ul li, ol.org-ol li { font-size: 0.95rem; }

  table { font-size: 0.78rem; }
  thead th, tbody td { padding: 0.4em 0.75em; }
}

/* ─── Very small screens ─── */
@media (max-width: 400px) {
  #content { padding: 0 1rem 2.5rem; }
  #table-of-contents { width: 94%; max-height: 18vh; }
  h1.title { font-size: 1.4rem; }
  h2       { font-size: 1.15rem; }
}
