:root {
  --paper: #F2EBDA;
  --ink: #2C2C2C;
  --ink-light: #8A8578;
  --ink-faint: #C4BDB0;
  --accent: #B85C38;
  --accent-light: #D4A089;
  --margin-line: #D4A89A;
  --dot-gap: 22px;
  --margin-left: 48px;
  --content-max: 640px;
  --pattern-color: #C8C0B4;
}

html.dark {
  --paper: #000000;
  --ink: #E8E0D0;
  --ink-light: #A09488;
  --ink-faint: #3E3830;
  --margin-line: #5A4A44;
  --pattern-color: #B85C38;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Outfit', sans-serif;
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ============================
   PATTERN LAYER
   Always has solid paper background.
   Opacity of the ENTIRE layer is controlled by JS.
   ============================ */
.pattern-layer {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  background: var(--paper);
  /* opacity controlled entirely by JS */
}

.pattern-layer pre {
  font-family: 'Courier New', monospace;
  font-size: 11px;
  line-height: 1.15;
  color: var(--pattern-color);
  letter-spacing: 0.5px;
  white-space: pre;
  text-align: center;
  user-select: none;
}

@media (max-width: 768px) {
  .pattern-layer pre {
    font-size: 7px;
    line-height: 1.1;
    letter-spacing: 0;
  }
}

/* ============================
   HOME OVERLAY
   ============================ */
.home-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 600;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 48px 32px;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.home-overlay.hidden { opacity: 0; pointer-events: none; }

.home-title {
  font-family: 'Caveat', cursive;
  font-size: 28px;
  font-weight: 500;
  color: var(--accent);
  letter-spacing: 1px;
  opacity: 0.8;
  cursor: pointer;
  pointer-events: auto;
  transition: opacity 0.2s ease;
}
.home-title:hover { opacity: 1; }

.home-nav {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.home-nav-item {
  font-size: 14px;
  font-weight: 300;
  color: var(--ink);
  letter-spacing: 0.5px;
  cursor: pointer;
  padding: 10px 28px;
  transition: all 0.2s ease;
  background: rgba(245, 240, 232, 0.5);
  border-radius: 2px;
}

.home-nav-item:hover {
  color: var(--accent);
  background: rgba(245, 240, 232, 0.8);
  letter-spacing: 1.2px;
}

html.dark .home-nav-item { background: rgba(232, 224, 208, 0.06); }
html.dark .home-nav-item:hover { background: rgba(232, 224, 208, 0.12); }

.home-email {
  font-size: 12px;
  font-weight: 300;
  color: var(--ink-light);
  letter-spacing: 0.5px;
  opacity: 0.6;
  cursor: pointer;
  position: relative;
  pointer-events: auto;
}
.home-email:hover { opacity: 1; }

.email-toast {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%) translateY(6px);
  font-family: 'Caveat', cursive;
  font-size: 16px;
  color: var(--accent);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.email-toast.show {
  opacity: 0.85;
  transform: translateX(-50%) translateY(0);
}


/* Dark mode toggle — fixed top-right, aligned with home overlay padding */
.dark-toggle {
  position: fixed;
  top: 48px;
  right: 32px;
  z-index: 700;
  background: rgba(242, 235, 218, 0.55);
  border: none;
  border-radius: 20px;
  cursor: pointer;
  color: var(--accent);
  padding: 9px 11px;
  opacity: 0.75;
  transition: opacity 0.2s ease, background 0.2s ease;
  line-height: 0;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.dark-toggle:hover { opacity: 1; }
html.dark .dark-toggle { background: rgba(20, 16, 12, 0.55); }

@media (max-width: 768px) {
  .dark-toggle { top: 36px; right: 20px; }
}

/* Show moon in light mode (click to go dark), sun in dark mode (click to go light) */
.dark-toggle .icon-sun  { display: none; }
.dark-toggle .icon-moon { display: block; }
html.dark .dark-toggle .icon-sun  { display: block; }
html.dark .dark-toggle .icon-moon { display: none; }

@media (max-width: 768px) {
  .home-overlay { padding: 36px 20px; }
  .home-title { font-size: 22px; }
  .home-nav { flex-wrap: wrap; justify-content: center; gap: 6px; }
  .home-nav-item { font-size: 13px; padding: 8px 20px; }
  .home-email { font-size: 11px; }
}

/* ============================
   MARGIN LINE + PROGRESS
   ============================ */
.margin-line-bg {
  position: fixed;
  left: var(--margin-left);
  top: 0; bottom: 0;
  width: 1.5px;
  background: var(--margin-line);
  opacity: 0;
  z-index: 100;
  pointer-events: none;
  transition: opacity 0.4s ease;
}
.margin-line-bg.visible { opacity: 0.25; }

.margin-progress {
  position: fixed;
  left: var(--margin-left);
  top: 0;
  width: 1.5px;
  height: 0%;
  background: var(--accent);
  opacity: 0;
  z-index: 101;
  pointer-events: none;
  transition: opacity 0.4s ease;
}
.margin-progress.visible { opacity: 0.6; }

@media (max-width: 768px) {
  :root { --margin-left: 20px; }
}

/* ============================
   CONTENT PAGES
   ============================ */
.content-layer {
  position: relative;
  z-index: 5;
  min-height: 100vh;
  display: none;
}

.content-layer.ready {
  display: block;
}

.page {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 60px 32px 120px calc(var(--margin-left) + 32px);
}

@media (max-width: 768px) {
  .page { padding: 40px 24px 80px calc(var(--margin-left) + 20px); }
}

/* === CONTENT NAV === */
.content-nav {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: calc(var(--dot-gap) * 2);
  padding-bottom: calc(var(--dot-gap));
  border-bottom: 1px dotted var(--ink-faint);
}

.nav-back {
  font-size: 12px;
  color: var(--ink-faint);
  cursor: pointer;
  transition: color 0.2s ease;
  letter-spacing: 0.3px;
}
.nav-back:hover { color: var(--accent); }

.nav-links {
  display: flex;
  gap: 14px;
  margin-left: auto;
}

.nav-link {
  font-size: 11px;
  color: var(--ink-faint);
  cursor: pointer;
  letter-spacing: 0.3px;
  transition: color 0.2s ease;
  padding: 2px 0;
}
.nav-link:hover { color: var(--ink-light); }
.nav-link.active { color: var(--accent); border-bottom: 1px solid var(--accent); }

@media (max-width: 768px) {
  .nav-links { gap: 10px; }
  .nav-link { font-size: 10px; }
}

/* === SECTION HEADERS === */
.section-header { margin-bottom: calc(var(--dot-gap) * 2); }

.section-header h1 {
  font-size: 28px;
  font-weight: 300;
  line-height: 1.4;
}

.section-desc {
  font-size: 13px;
  color: var(--ink-light);
  font-weight: 300;
  line-height: var(--dot-gap);
  margin-top: 4px;
}

.header-annotation {
  font-family: 'Caveat', cursive;
  color: var(--accent);
  font-size: 14px;
  opacity: 0.5;
  display: block;
  margin-top: 6px;
}

/* === INDEX === */
.index-list { list-style: none; }

.index-item {
  display: flex;
  align-items: baseline;
  padding: calc(var(--dot-gap) * 0.6) 0;
  border-bottom: 1px dotted var(--ink-faint);
  cursor: pointer;
  transition: all 0.2s ease;
  line-height: var(--dot-gap);
}
.index-item:last-child { border-bottom: none; }
.index-item { -webkit-tap-highlight-color: transparent; }
/* hover only on real pointer devices — prevents tap state freezing in BFCache on mobile */
@media (hover: hover) {
  .index-item:hover { padding-left: 6px; }
  .index-item:hover .index-title { color: var(--accent); }
}

.index-num { font-size: 11px; color: var(--ink-faint); width: 28px; flex-shrink: 0; }

.index-bullet {
  width: 8px; height: 8px;
  border: 1.5px solid var(--ink-faint);
  border-radius: 1px;
  flex-shrink: 0;
  margin-right: 10px;
  position: relative; top: 1px;
}
.index-bullet.done::after {
  content: '×'; position: absolute; top: -5px; left: 0;
  font-size: 10px; color: var(--ink-light);
}

.index-title { font-size: 14px; font-weight: 400; color: var(--ink); flex-grow: 1; transition: color 0.2s ease; }
.index-date { font-size: 11px; color: var(--ink-faint); margin-left: 16px; white-space: nowrap; font-weight: 300; }

.index-tag {
  font-size: 9px; letter-spacing: 1px; text-transform: uppercase;
  color: var(--ink-faint); margin-left: 12px; padding: 1px 6px;
  border: 1px solid rgba(196,189,176,0.5); border-radius: 2px; white-space: nowrap;
}
@media (max-width: 768px) { .index-tag { display: none; } }

/* === POST === */
.print-header { display: none; }

.print-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  padding: 0;
  margin-top: 10px;
  color: var(--ink-faint);
  cursor: pointer;
  font-family: 'Outfit', sans-serif;
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 0.3px;
  transition: color 0.2s ease;
  opacity: 0.6;
}
.print-btn:hover { color: var(--ink-light); opacity: 1; }

.post-title { font-size: 26px; font-weight: 400; line-height: 1.4; margin-bottom: 8px; }

/* Scroll offset for TOC anchor links — keeps headings from snapping flush to the top */
.section-heading, .post-body h3, .post-body h4 {
  scroll-margin-top: 52px;
}
.post-meta { font-size: 11px; color: var(--ink-faint); letter-spacing: 0.8px; text-transform: uppercase; line-height: var(--dot-gap); }
.post-readtime { font-family: 'Caveat', cursive; font-size: 15px; color: var(--accent); opacity: 0.6; text-transform: none; letter-spacing: 0; margin-left: 6px; }
.post-divider { border: none; border-top: 1px dotted var(--ink-faint); margin: calc(var(--dot-gap)) 0 calc(var(--dot-gap) * 2); }

.post-body p { font-size: 14.5px; line-height: var(--dot-gap); color: var(--ink); font-weight: 300; margin-bottom: var(--dot-gap); }

.pull-quote { font-size: 16px; font-weight: 300; color: var(--ink-light); border-left: 2px solid var(--accent); padding-left: 20px; margin: calc(var(--dot-gap) * 1.5) 0; line-height: 1.5; font-style: italic; }
.pq-annotation { font-family: 'Caveat', cursive; color: var(--accent); font-size: 14px; font-style: normal; display: block; margin-top: 8px; opacity: 0.5; }

.ascii-break { text-align: center; padding: 28px 0; overflow: hidden; }
.ascii-break pre { font-family: 'Courier New', monospace; font-size: 9px; line-height: 1.15; color: var(--ink-faint); display: inline-block; opacity: 0.3; }
@media (max-width: 768px) { .ascii-break pre { font-size: 6px; } }

.connects-to { margin-top: calc(var(--dot-gap) * 3); padding-top: calc(var(--dot-gap)); border-top: 1px dotted var(--ink-faint); }
.connects-to-label { font-family: 'Caveat', cursive; font-size: 15px; color: var(--accent); opacity: 0.5; margin-bottom: 10px; }
.connects-to-item { font-size: 13px; color: var(--ink-light); padding: 5px 0; cursor: pointer; transition: color 0.2s ease; }
.connects-to-item:hover { color: var(--accent); }
.connects-to-item .conn-type { font-size: 9px; letter-spacing: 1px; text-transform: uppercase; color: var(--ink-faint); margin-left: 6px; padding: 1px 5px; border: 1px solid rgba(196,189,176,0.5); border-radius: 2px; }

.page-footer { margin-top: calc(var(--dot-gap) * 4); padding-top: var(--dot-gap); border-top: 1px dotted var(--ink-faint); font-size: 11px; color: var(--ink-faint); font-weight: 300; display: flex; justify-content: space-between; align-items: baseline; }
.footer-right { display: flex; align-items: baseline; gap: 16px; }
.footer-sig { font-family: 'Caveat', cursive; font-size: 16px; color: var(--accent); opacity: 0.4; }
.footer-colophon { font-size: 11px; color: var(--ink-faint); font-weight: 300; cursor: pointer; transition: color 0.2s ease; }
.footer-colophon:hover { color: var(--ink-light); }

/* ============================
   FULLSCREEN / SCREENSAVER
   ============================ */
.fullscreen-btn {
  position: fixed;
  top: 48px;
  left: 32px;
  z-index: 700;
  background: rgba(242, 235, 218, 0.55);
  border: none;
  border-radius: 20px;
  cursor: pointer;
  color: var(--accent);
  padding: 9px 11px;
  opacity: 0.75;
  transition: opacity 0.2s ease, background 0.2s ease;
  line-height: 0;
  display: none;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.fullscreen-btn:hover { opacity: 1; }
html.dark .fullscreen-btn { background: rgba(20, 16, 12, 0.55); }

@media (max-width: 768px) {
  .fullscreen-btn { top: 36px; left: 20px; }
}

.screensaver-exit {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,0.35);
  font-size: 22px;
  font-family: 'Outfit', sans-serif;
  font-weight: 300;
  padding: 10px;
  line-height: 1;
  display: none;
  transition: color 0.2s;
}
.screensaver-exit:hover { color: rgba(255,255,255,0.75); }

/* ============================
   SCREENSAVER CONTROLS PANEL
   ============================ */
.screensaver-controls {
  position: fixed;
  bottom: 28px;
  left: 28px;
  z-index: 1000;
  display: none;
}

.sc-panel {
  background: rgba(0,0,0,0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.07);
  padding: 0 18px;
  min-width: 200px;
  margin-bottom: 8px;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.25s ease, opacity 0.2s ease, padding 0.25s ease;
}
.sc-panel.open {
  max-height: 300px;
  opacity: 1;
  padding: 16px 18px;
}

.sc-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 11px;
}
.sc-row:last-child { margin-bottom: 0; }

.sc-label {
  font-size: 9px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.38);
  font-family: 'Outfit', sans-serif;
  flex-shrink: 0;
  width: 58px;
}

.sc-slider {
  -webkit-appearance: none;
  width: 96px;
  height: 2px;
  background: rgba(255,255,255,0.15);
  outline: none;
  border-radius: 1px;
  cursor: pointer;
}
.sc-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: rgba(255,255,255,0.55);
  cursor: pointer;
}
.sc-slider::-moz-range-thumb {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: rgba(255,255,255,0.55);
  border: none;
  cursor: pointer;
}

.sc-colors {
  display: flex;
  gap: 5px;
}
.sc-color {
  width: 14px; height: 14px;
  border-radius: 2px;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: border-color 0.15s;
}
.sc-color.active { border-color: rgba(255,255,255,0.65); }

.sc-btn-row {
  display: flex;
  gap: 6px;
  margin-top: 13px;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,0.07);
}

.sc-btn {
  flex: 1;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.45);
  font-family: 'Outfit', sans-serif;
  font-size: 9px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  padding: 6px 8px;
  cursor: pointer;
  transition: all 0.2s;
}
.sc-btn:hover { background: rgba(255,255,255,0.11); color: rgba(255,255,255,0.8); }
.sc-btn.active { background: rgba(255,255,255,0.14); color: rgba(255,255,255,0.9); border-color: rgba(255,255,255,0.25); }

.sc-toggle-btn {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 20px;
  cursor: pointer;
  color: #B85C38;
  padding: 9px 11px;
  line-height: 0;
  display: flex;
  align-items: center;
  gap: 0;
  opacity: 0.65;
  overflow: hidden;
  white-space: nowrap;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: opacity 0.2s, gap 0.2s ease, padding 0.2s ease, background 0.2s;
}
.sc-toggle-btn:hover {
  opacity: 1;
  gap: 7px;
  padding: 9px 14px 9px 11px;
  background: rgba(255, 255, 255, 0.16);
}

.sc-toggle-label {
  font-family: 'Outfit', sans-serif;
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #B85C38;
  max-width: 0;
  opacity: 0;
  overflow: hidden;
  line-height: 1;
  transition: max-width 0.2s ease, opacity 0.15s ease;
}
.sc-toggle-btn:hover .sc-toggle-label {
  max-width: 60px;
  opacity: 1;
}

/* ============================
   SCREENSAVER INFO (bottom-right)
   ============================ */
.screensaver-info {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 1000;
  display: none;
  align-items: flex-end;
  flex-direction: column;
}

.sc-info-panel {
  background: rgba(0,0,0,0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.07);
  padding: 0 18px;
  width: 300px;
  margin-bottom: 8px;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.3s ease, opacity 0.2s ease, padding 0.25s ease;
}
.sc-info-panel.open {
  max-height: 500px;
  opacity: 1;
  padding: 16px 18px;
}

.sc-info-title {
  font-family: 'Caveat', cursive;
  font-size: 17px;
  color: #B85C38;
  margin-bottom: 10px;
  display: block;
}

.sc-info-text {
  font-family: 'Outfit', sans-serif;
  font-size: 13px;
  font-weight: 300;
  color: rgba(255,255,255,0.6);
  line-height: 1.75;
  margin-bottom: 12px;
}
.sc-info-text:last-child { margin-bottom: 0; }

.sc-info-text code {
  font-family: 'Courier New', monospace;
  font-size: 12px;
  color: rgba(255,255,255,0.4);
  background: rgba(255,255,255,0.07);
  padding: 1px 5px;
  border-radius: 2px;
}

.sc-info-btn {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 20px;
  cursor: pointer;
  color: #B85C38;
  padding: 9px 11px;
  line-height: 0;
  display: flex;
  align-items: center;
  gap: 0;
  opacity: 0.65;
  overflow: hidden;
  white-space: nowrap;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: opacity 0.2s, gap 0.2s ease, padding 0.2s ease, background 0.2s;
}
.sc-info-btn:hover {
  opacity: 1;
  gap: 7px;
  padding: 9px 11px 9px 14px;
  background: rgba(255, 255, 255, 0.16);
}

.sc-info-label {
  font-family: 'Outfit', sans-serif;
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #B85C38;
  max-width: 0;
  opacity: 0;
  overflow: hidden;
  line-height: 1;
  transition: max-width 0.2s ease, opacity 0.15s ease;
}
.sc-info-btn:hover .sc-info-label {
  max-width: 50px;
  opacity: 1;
}

/* ============================
   COLOPHON OVERLAY
   ============================ */
.colophon-overlay {
  position: fixed;
  inset: 0;
  z-index: 650;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  background: rgba(0,0,0,0.18);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
html.dark .colophon-overlay { background: rgba(0,0,0,0.5); }
.colophon-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.colophon-card {
  background: var(--paper);
  max-width: 400px;
  width: 100%;
  padding: 32px 36px;
  border: 1px solid var(--ink-faint);
  position: relative;
  transform: translateY(10px);
  transition: transform 0.3s ease;
}
.colophon-overlay.visible .colophon-card { transform: translateY(0); }

.colophon-card-title {
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 400;
  margin-bottom: 18px;
}

.colophon-card p {
  font-size: 13px;
  font-weight: 300;
  line-height: 1.8;
  color: var(--ink-light);
  margin-bottom: 10px;
}
.colophon-card p:last-of-type {
  font-family: 'Caveat', cursive;
  font-size: 20px;
  color: var(--ink);
  margin-top: 14px;
  margin-bottom: 0;
}

.colophon-card-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ink-faint);
  font-size: 18px;
  font-family: 'Outfit', sans-serif;
  font-weight: 300;
  line-height: 1;
  padding: 4px 6px;
  transition: color 0.2s;
}
.colophon-card-close:hover { color: var(--ink); }

/* ============================
   TABLE OF CONTENTS
   ============================ */
.toc {
  margin-bottom: calc(var(--dot-gap) * 1.5);
}

.toc-toggle {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: 'Caveat', cursive;
  font-size: 17px;
  color: var(--accent);
  opacity: 0.5;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: opacity 0.2s;
}
.toc-toggle:hover { opacity: 0.85; }

.toc-arrow {
  font-size: 14px;
  transition: transform 0.2s ease;
  display: inline-block;
  line-height: 1;
  position: relative;
  top: 1px;
}
.toc-toggle.open .toc-arrow { transform: rotate(90deg); }

.toc-list {
  margin-top: 10px;
  padding: 0 0 0 14px;
  list-style: none;
  border-left: 1.5px solid var(--ink-faint);
}

.toc-entry { padding: 2px 0; }

.toc-link {
  font-size: 12px;
  font-weight: 300;
  color: var(--ink-light);
  cursor: pointer;
  transition: color 0.2s ease;
  line-height: 1.6;
  display: block;
}
.toc-link:hover { color: var(--accent); }

.toc-link.toc-h3 {
  font-size: 11px;
  color: var(--ink-faint);
  padding-left: 10px;
}
.toc-link.toc-h3:hover { color: var(--ink-light); }
