:root {
  --bg-primary: #faf5ec;
  --bg-secondary: #f0e8d8;
  --bg-deep: #2a1e14;
  --text-primary: #3a2a1a;
  --text-secondary: #4a3828;
  --text-tertiary: #8a7460;
  --text-dust: #a08a70;
  --accent-primary: #c4a882;
  --accent-warm: #c87a52;
  --accent-soft: #d4a0a0;
  --bubble-tint: #e8d8c4;
  --shadow: rgba(42, 30, 20, 0.12);
  --edge-cream: #ede5d5;
  --font-display: 'Bebas Neue', sans-serif;
  --font-body: 'Libre Baskerville', serif;
  --font-annotation: 'Caveat', cursive;
  --font-meta: 'DM Mono', monospace;
}

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

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: clamp(1rem, 1.1vw, 1.15rem);
  line-height: 1.78;
  overflow-x: hidden;
  position: relative;
}

/* Deckled Paper Edge */
#deckled-edge {
  position: fixed;
  top: 0;
  left: 0;
  width: 30px;
  height: 100vh;
  z-index: 10;
  background: var(--edge-cream);
  clip-path: polygon(
    0% 0%, 100% 0%, 95% 2%, 100% 4%, 92% 6%, 100% 8%, 97% 10%,
    100% 12%, 93% 14%, 100% 16%, 96% 18%, 100% 20%, 94% 22%,
    100% 24%, 98% 26%, 100% 28%, 91% 30%, 100% 32%, 95% 34%,
    100% 36%, 93% 38%, 100% 40%, 97% 42%, 100% 44%, 92% 46%,
    100% 48%, 96% 50%, 100% 52%, 94% 54%, 100% 56%, 98% 58%,
    100% 60%, 91% 62%, 100% 64%, 95% 66%, 100% 68%, 93% 70%,
    100% 72%, 97% 74%, 100% 76%, 92% 78%, 100% 80%, 96% 82%,
    100% 84%, 94% 86%, 100% 88%, 98% 90%, 100% 92%, 91% 94%,
    100% 96%, 95% 98%, 100% 100%, 0% 100%
  );
  pointer-events: none;
}

/* Bubble Field */
#bubble-field {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
  overflow: hidden;
}

.bubble {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
}

.bubble-outer {
  border-radius: 50%;
  position: relative;
}

.bubble-highlight {
  position: absolute;
  border-radius: 50%;
  background: var(--bg-primary);
  opacity: 0.6;
}

@keyframes bubbleRise {
  0% {
    transform: translateY(100vh) translateX(0);
    opacity: 0;
  }
  10% {
    opacity: 1;
  }
  90% {
    opacity: 1;
  }
  100% {
    transform: translateY(-120px) translateX(var(--drift-x, 20px));
    opacity: 0;
  }
}

/* Chapter Dots Navigation */
#chapter-dots {
  position: fixed;
  top: 50%;
  right: 28px;
  transform: translateY(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 8px;
  background: rgba(42, 30, 20, 0.06);
  border-radius: 20px;
  backdrop-filter: blur(4px);
}

.chapter-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1.5px solid var(--accent-primary);
  background: transparent;
  cursor: pointer;
  transition: background-color 0.4s ease, transform 0.3s ease, border-color 0.4s ease;
  padding: 0;
}

.chapter-dot:hover {
  transform: scale(1.4);
  border-color: var(--accent-warm);
}

.chapter-dot.active {
  background-color: var(--accent-warm);
  border-color: var(--accent-warm);
}

/* Main Journal */
#journal {
  position: relative;
  z-index: 3;
}

/* Chapter Sections */
.chapter {
  position: relative;
  display: flex;
  align-items: flex-start;
  min-height: 80vh;
  padding: 80px 0 120px;
}

#chapter-0 {
  min-height: 100vh;
  display: flex;
  align-items: center;
  padding-top: 0;
}

/* Section Transition Zones */
.section-transition-zone {
  position: absolute;
  top: -60px;
  left: 0;
  right: 0;
  height: 120px;
  background: linear-gradient(to bottom, var(--bg-primary), var(--bg-secondary));
  opacity: 0.5;
  z-index: -1;
  pointer-events: none;
}

#chapter-0 .section-transition-zone {
  display: none;
}

.chapter:nth-child(odd) {
  background-color: var(--bg-primary);
}

.chapter:nth-child(even) {
  background-color: var(--bg-secondary);
}

/* Reading Column */
.reading-column {
  max-width: 680px;
  margin-left: 38%;
  transform: translateX(-50%);
  padding: 0 24px;
  position: relative;
  z-index: 3;
}

/* Ink Blots */
.ink-blot {
  margin-bottom: 24px;
  opacity: 0;
  transform: scale(0.3) rotate(15deg);
  transition: opacity 0.8s ease, transform 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.ink-blot.visible {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

/* Meta Labels */
.meta-label {
  display: block;
  font-family: var(--font-meta);
  font-weight: 300;
  font-size: 0.8rem;
  color: #a08a70;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 12px;
}

.meta-date {
  margin-top: 32px;
  margin-bottom: 0;
}

/* Title */
.chapter-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(3rem, 7vw, 6rem);
  color: var(--text-primary);
  letter-spacing: 0.08em;
  line-height: 1.05;
  margin-bottom: 28px;
  text-transform: uppercase;
}

.chapter-subtitle {
  font-family: var(--font-body);
  font-size: clamp(1rem, 1.2vw, 1.2rem);
  color: var(--text-tertiary);
  line-height: 1.7;
  max-width: 560px;
}

/* Section Headings */
.section-heading {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(1.8rem, 4vw, 3rem);
  color: var(--text-primary);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  line-height: 1.1;
  margin-bottom: 6px;
  opacity: 0;
  transform: translateX(-20px);
  transition: opacity 0.7s ease, transform 0.7s ease;
}

.section-heading.visible {
  opacity: 1;
  transform: translateX(0);
}

.heading-underline {
  width: 0;
  height: 2px;
  background-color: var(--accent-primary);
  margin-bottom: 32px;
  transition: width 0.8s ease 0.2s;
}

.heading-underline.visible {
  width: 80px;
}

/* Body Paragraphs */
.reading-column p {
  margin-bottom: 24px;
  color: var(--text-secondary);
}

.reading-column p em {
  color: var(--text-primary);
  font-style: italic;
}

.closing-note {
  font-size: 1.15em;
  margin-top: 48px;
  text-align: center;
  color: var(--text-primary);
}

/* Journal End */
.journal-end {
  text-align: center;
  margin-top: 64px;
  padding-top: 32px;
}

.journal-end .meta-label {
  display: inline-block;
  margin-bottom: 20px;
}

.end-ornament {
  display: flex;
  justify-content: center;
}

/* Marginalia */
.marginalia {
  position: sticky;
  top: 20vh;
  width: 240px;
  margin-left: auto;
  margin-right: 80px;
  flex-shrink: 0;
  z-index: 2;
  opacity: 0;
  transform: translateX(60px);
  transition: opacity 0.7s ease, transform 0.7s ease;
}

.marginalia.visible {
  opacity: 1;
  transform: translateX(0);
}

.marginalia-card {
  width: 200px;
  padding: 16px 18px;
  border: 1.5px solid var(--accent-primary);
  border-radius: 2px;
  background: rgba(250, 245, 236, 0.85);
  box-shadow: 0 4px 20px var(--shadow);
  margin-bottom: 20px;
}

.annotation {
  font-family: var(--font-annotation);
  font-size: 0.95rem;
  color: var(--text-tertiary);
  line-height: 1.5;
  margin-bottom: 8px;
}

.annotation-source {
  display: block;
  font-family: var(--font-meta);
  font-weight: 300;
  font-size: 0.7rem;
  color: var(--text-tertiary);
  opacity: 0.7;
}

/* Connecting Threads */
.connecting-thread {
  display: block;
  margin-top: 16px;
}

.thread-path {
  stroke-dasharray: 300;
  stroke-dashoffset: 300;
  transition: stroke-dashoffset 1.2s ease;
}

.connecting-thread.visible .thread-path {
  stroke-dashoffset: 0;
}

/* Bubble Cluster Small */
.bubble-cluster-small {
  margin-top: 16px;
  opacity: 0.7;
}

/* Layered Depth */
.chapter {
  box-shadow: 0 4px 40px rgba(31, 22, 14, 0.08);
}

/* Responsive: Below 1200px */
@media (max-width: 1200px) {
  .marginalia {
    position: relative;
    top: auto;
    width: 100%;
    max-width: 680px;
    margin: 0;
    padding: 0 24px;
    opacity: 1;
    transform: none;
    margin-left: 38%;
    transform: translateX(-50%);
  }

  .marginalia-card {
    width: 100%;
    border-left: 3px solid var(--accent-primary);
    border-top: none;
    border-right: none;
    border-bottom: none;
    border-radius: 0;
    padding-left: 20px;
    margin: 16px 0 32px 20px;
  }

  .chapter {
    flex-direction: column;
  }

  .connecting-thread {
    display: none;
  }

  .bubble-cluster-small {
    display: none;
  }
}

/* Responsive: Below 768px */
@media (max-width: 768px) {
  .reading-column {
    max-width: 90%;
    margin-left: 50%;
    transform: translateX(-50%);
    padding: 0 20px;
  }

  .chapter-title {
    font-size: clamp(2rem, 8vw, 3rem);
  }

  #chapter-dots {
    top: auto;
    bottom: 16px;
    right: 50%;
    transform: translateX(50%);
    flex-direction: row;
    padding: 8px 16px;
  }

  #deckled-edge {
    display: none;
  }

  .marginalia {
    margin-left: 50%;
    transform: translateX(-50%);
    max-width: 90%;
    padding: 0 20px;
  }
}

/* Responsive: Below 480px */
@media (max-width: 480px) {
  .reading-column {
    max-width: 95%;
    padding: 0 16px;
  }

  .bubble-cluster-small {
    display: none;
  }

  .connecting-thread {
    display: none;
  }

  .chapter {
    padding: 60px 0 80px;
  }
}