/* =============================================
   renai.wiki — Styles
   Palette:
     #FAF6F0 — background base (warm off-white)
     #F0EAE2 — surface secondary (code blocks, cards)
     #E8DDD2 — border/hairline
     #D4C5B2 — accent neutral
     #9BB5A8 — sage mid
     #C8DDD6 — spring mint
     #F2C4C4 — blush petal
     #3D2E22 — display type
     #4A3C32 — body type
     #2C5F4A — code type / links
     #C47F6C — syntax string color
   Fonts:
     DM Serif Display — display/headlines
     DM Sans         — body/tutorial text
     JetBrains Mono  — code
============================================= */

/* ---- Reset & Base ---- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  background-color: #FAF6F0;
  color: #4A3C32;
  font-family: 'DM Sans', sans-serif;
  font-weight: 400;
  line-height: 1.75;
  letter-spacing: 0.005em;
  overflow-x: hidden;
  position: relative;
}

/* ---- Gradient Mesh Background ---- */
.mesh-bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 20% 30%, rgba(200, 221, 214, 0.22) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 70%, rgba(242, 196, 196, 0.18) 0%, transparent 55%),
    radial-gradient(ellipse at 50% 50%, rgba(212, 197, 178, 0.14) 0%, transparent 80%),
    #FAF6F0;
  background-size: 100% 100%, 100% 100%, 100% 100%;
  animation: mesh-drift 12s ease-in-out infinite;
}

@keyframes mesh-drift {
  0%   { background-position: 0% 0%, 100% 100%, 50% 50%; }
  50%  { background-position: 8% 12%, 88% 82%, 42% 58%; }
  100% { background-position: 0% 0%, 100% 100%, 50% 50%; }
}

/* ---- Nav Pill ---- */
.nav-pill {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(250, 246, 240, 0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid #E8DDD2;
  border-radius: 100px;
  padding: 8px 24px;
  display: flex;
  gap: 2rem;
  align-items: center;
  z-index: 100;
  transition: box-shadow 0.3s ease;
  white-space: nowrap;
}

.nav-pill.scrolled {
  box-shadow: 0 2px 12px rgba(61, 46, 34, 0.08);
}

.nav-pill a {
  font-family: 'DM Sans', sans-serif;
  font-weight: 400;
  font-size: 13px;
  color: #4A3C32;
  text-decoration: none;
  letter-spacing: 0.01em;
  transition: color 0.2s;
}

.nav-pill a:hover {
  color: #2C5F4A;
}

/* ---- Sections / Chapters ---- */
.chapter {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 80px 0;
}

.chapter-content {
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
  padding: 0 40px;
}

/* ---- Chapter I: Emergence ---- */
.chapter-1 {
  align-items: center;
  text-align: center;
}

.chapter-1-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.hero-title {
  font-family: 'DM Serif Display', serif;
  font-style: italic;
  font-weight: 400;
  font-size: 5vw;
  color: #3D2E22;
  letter-spacing: -0.01em;
  line-height: 1.1;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0;
}

.hero-title .char {
  display: inline-block;
  opacity: 0;
  transform: translateY(10px);
  animation: char-emerge 400ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
  animation-delay: calc(var(--i) * 0.04s);
}

.hero-title .char.space {
  width: 0.3em;
}

@keyframes char-emerge {
  from {
    transform: translateY(10px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.hero-definition {
  font-family: 'DM Sans', sans-serif;
  font-weight: 300;
  font-size: 1.125rem;
  color: #4A3C32;
  max-width: 560px;
  line-height: 1.75;
}

.hero-rule {
  width: 0;
  height: 1px;
  background-color: #D4C5B2;
  animation: rule-draw 0.8s ease-out 1.8s forwards;
  max-width: 400px;
}

@keyframes rule-draw {
  from { width: 0; }
  to   { width: 400px; }
}

/* ---- Chapter II: Foundation ---- */
.chapter-2 {
  background: rgba(250, 246, 240, 0.6);
}

.chapter-2-content {
  display: grid;
  grid-template-columns: 38% 62%;
  gap: 4rem;
  align-items: center;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 40px;
}

.two-col-left {
  display: flex;
  justify-content: center;
  align-items: center;
}

.topology-svg {
  width: 100%;
  max-width: 320px;
  height: auto;
}

/* Node animation — triggered when .is-visible is added */
.topology-svg .topology-nodes circle {
  transform-origin: center;
  transform-box: fill-box;
  transform: scale(0);
  opacity: 0;
}

.topology-svg.is-visible .topology-nodes circle {
  animation: node-pop 300ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  animation-delay: calc(var(--node-index) * 60ms);
}

@keyframes node-pop {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.two-col-right {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ---- Section Titles (kinetic words) ---- */
.section-title {
  font-family: 'DM Serif Display', serif;
  font-style: italic;
  font-weight: 400;
  font-size: 3.2rem;
  color: #3D2E22;
  letter-spacing: -0.01em;
  line-height: 1.1;
}

.section-title .word {
  display: inline-block;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 500ms ease, transform 500ms ease;
  margin-right: 0.25em;
}

.section-title.words-visible .word {
  opacity: 1;
  transform: translateY(0);
}

/* stagger words via nth-child */
.section-title .word:nth-child(1) { transition-delay: 0ms; }
.section-title .word:nth-child(2) { transition-delay: 80ms; }
.section-title .word:nth-child(3) { transition-delay: 160ms; }
.section-title .word:nth-child(4) { transition-delay: 240ms; }
.section-title .word:nth-child(5) { transition-delay: 320ms; }

.lead-paragraph {
  font-family: 'DM Sans', sans-serif;
  font-weight: 400;
  font-size: 1.125rem;
  color: #4A3C32;
  line-height: 1.75;
}

p {
  font-family: 'DM Sans', sans-serif;
  font-weight: 300;
  font-size: 1rem;
  color: #4A3C32;
  line-height: 1.75;
}

/* Concept list */
.concept-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 8px;
}

.concept-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-left: 16px;
  border-left: 2px solid #D4C5B2;
}

.concept-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.875rem;
  color: #2C5F4A;
  font-weight: 400;
}

.concept-desc {
  font-family: 'DM Sans', sans-serif;
  font-weight: 300;
  font-size: 0.9rem;
  color: #4A3C32;
  line-height: 1.6;
}

/* ---- Chapter III: Mechanics ---- */
.chapter-3 {
  padding: 80px 0 60px;
  overflow: hidden;
}

.chapter-3-header {
  max-width: 960px;
  margin: 0 auto 40px;
  padding: 0 40px;
}

.chapter-3-intro {
  font-family: 'DM Sans', sans-serif;
  font-weight: 300;
  font-size: 1rem;
  color: #9BB5A8;
  margin-top: 8px;
}

.scroll-strip-wrapper {
  width: 100%;
  overflow: hidden;
  position: relative;
}

.scroll-strip {
  display: flex;
  overflow-x: scroll;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  gap: 0;
  padding: 0 calc((100vw - 80vw) / 2);
  scrollbar-width: none;
}

.scroll-strip::-webkit-scrollbar {
  display: none;
}

.concept-panel {
  flex: 0 0 80vw;
  scroll-snap-align: start;
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  margin: 0 8px;
  min-height: 460px;
  display: flex;
  align-items: center;
}

.panel-mesh-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 30%, rgba(200, 221, 214, 0.28) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 70%, rgba(242, 196, 196, 0.22) 0%, transparent 55%),
    radial-gradient(ellipse at 50% 50%, rgba(212, 197, 178, 0.16) 0%, transparent 80%),
    #FAF6F0;
  background-size: 100% 100%, 100% 100%, 100% 100%;
  transform: rotate(calc(var(--panel-gradient-angle, 135deg) - 135deg));
}

.panel-content {
  position: relative;
  z-index: 1;
  padding: 48px 40px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
}

.panel-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  color: #9BB5A8;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 400ms ease, transform 400ms ease;
}

.chapter-3.is-visible .panel-label {
  opacity: 1;
  transform: translateY(0);
}

.concept-panel:nth-child(1) .panel-label { transition-delay: 0ms; }
.concept-panel:nth-child(2) .panel-label { transition-delay: 150ms; }
.concept-panel:nth-child(3) .panel-label { transition-delay: 300ms; }

.panel-title {
  font-family: 'DM Serif Display', serif;
  font-style: italic;
  font-weight: 400;
  font-size: 1.8rem;
  color: #3D2E22;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.panel-body {
  font-family: 'DM Sans', sans-serif;
  font-weight: 300;
  font-size: 0.95rem;
  color: #4A3C32;
  line-height: 1.75;
}

/* ---- Code Blocks ---- */
.code-block {
  background: #F0EAE2;
  border-left: 4px solid #9BB5A8;
  border-radius: 0 4px 4px 0;
  padding: 16px 20px;
  overflow-x: auto;
}

.code-block pre {
  margin: 0;
}

.code-block code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  color: #2C5F4A;
  line-height: 1.6;
  display: block;
}

/* Syntax highlight classes */
.code-block .kw  { color: #2C5F4A; font-weight: 400; }
.code-block .str { color: #C47F6C; }
.code-block .cm  { color: #9BB5A8; }
.code-block .ln  { color: #D4C5B2; user-select: none; }

/* Strip Dots */
.strip-dots {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 28px;
  padding-bottom: 16px;
}

.strip-dot {
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #D4C5B2;
  cursor: pointer;
  transition: transform 0.2s ease, background-color 0.2s ease;
}

.strip-dot.active {
  transform: scale(1.3);
  background: #2C5F4A;
}

/* ---- Chapter IV: Application ---- */
.chapter-4-content {
  display: grid;
  grid-template-columns: 62% 38%;
  gap: 4rem;
  align-items: center;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 40px;
}

.two-col-left-wide {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.two-col-right-narrow {
  display: flex;
  justify-content: center;
  align-items: center;
}

.dot-grid-svg {
  width: 100%;
  max-width: 220px;
  height: auto;
}

/* Dot grid base dots */
.grid-dot {
  fill: #9BB5A8;
  opacity: 0.4;
  transition: r 0.3s ease, opacity 0.3s ease;
}

/* Activated dots */
.grid-dot.active {
  fill: #2C5F4A;
  opacity: 1;
  r: 7px;
}

/* Trace lines */
.trace-line {
  stroke-dasharray: 200;
  stroke-dashoffset: 200;
  transition: stroke-dashoffset 600ms ease;
}

.dot-grid-svg.is-visible .trace-line {
  stroke-dashoffset: 0;
}

.dot-grid-svg.is-visible {
  opacity: 1 !important;
}

/* Application steps */
.application-steps {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 16px;
}

.step-item {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  padding: 16px 0;
  border-bottom: 1px solid #E8DDD2;
}

.step-item:last-child {
  border-bottom: none;
}

.step-number {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  color: #D4C5B2;
  font-weight: 400;
  letter-spacing: 0.05em;
  min-width: 28px;
  padding-top: 3px;
}

.step-body {
  font-family: 'DM Sans', sans-serif;
  font-weight: 300;
  font-size: 0.95rem;
  color: #4A3C32;
  line-height: 1.65;
}

.step-body strong {
  font-weight: 500;
  color: #3D2E22;
}

/* ---- Chapter V: Reference ---- */
.chapter-5-content {
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.chapter-5-intro {
  font-family: 'DM Sans', sans-serif;
  font-weight: 300;
  font-size: 1rem;
  color: #9BB5A8;
}

.reference-table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'DM Sans', sans-serif;
}

.reference-table thead tr {
  background: #F0EAE2;
}

.reference-table th {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  font-weight: 400;
  color: #9BB5A8;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid #E8DDD2;
}

.reference-table td {
  padding: 14px 16px;
  border-bottom: 1px solid #E8DDD2;
  font-size: 0.9rem;
  vertical-align: top;
  line-height: 1.65;
}

.reference-table tbody tr {
  transition: background 0.2s ease;
}

.reference-table tbody tr:hover {
  background:
    radial-gradient(ellipse at 20% 50%, rgba(200, 221, 214, 0.3) 0%, transparent 70%),
    radial-gradient(ellipse at 80% 50%, rgba(242, 196, 196, 0.2) 0%, transparent 70%),
    #FAF6F0;
}

.term-cell {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  color: #2C5F4A;
  font-weight: 400;
  white-space: nowrap;
}

.domain-cell {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8rem;
  color: #9BB5A8;
  white-space: nowrap;
}

/* ---- Footer ---- */
.site-footer {
  margin-top: 80px;
  text-align: center;
  padding: 40px 0 32px;
  border-top: 1px solid #E8DDD2;
}

.footer-domain {
  font-family: 'DM Serif Display', serif;
  font-style: italic;
  font-size: 2.4rem;
  color: #3D2E22;
  letter-spacing: -0.01em;
  margin-bottom: 8px;
}

.footer-copy {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8rem;
  font-weight: 300;
  color: #D4C5B2;
}

/* ---- Spring Micro-ornaments ---- */
.spring-ornaments {
  position: absolute;
  bottom: -24px;
  right: 40px;
  display: flex;
  gap: 16px;
  align-items: flex-end;
  pointer-events: none;
  z-index: 2;
}

.ornament {
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 600ms ease, transform 600ms ease;
  transition-delay: 300ms;
}

.chapter.is-visible .ornament {
  opacity: 0.4;
  transform: translateY(0);
}

/* Also show ornaments when chapter 1 loads */
.chapter-1 .ornament {
  animation: ornament-appear 600ms ease 2.5s forwards;
}

@keyframes ornament-appear {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 0.4; transform: translateY(0); }
}

/* ---- Links ---- */
a {
  color: #2C5F4A;
  text-decoration: none;
  transition: color 0.2s;
}

a:hover {
  color: #9BB5A8;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .hero-title {
    font-size: 8vw;
  }

  .chapter-2-content,
  .chapter-4-content {
    grid-template-columns: 1fr;
    gap: 2rem;
  }

  .two-col-left,
  .two-col-right-narrow {
    order: 2;
  }

  .two-col-right,
  .two-col-left-wide {
    order: 1;
  }

  .nav-pill {
    gap: 1rem;
    padding: 8px 16px;
    font-size: 11px;
  }

  .nav-pill a {
    font-size: 11px;
  }

  .concept-panel {
    flex: 0 0 90vw;
  }

  .section-title {
    font-size: 2.4rem;
  }

  .chapter-content,
  .chapter-2-content,
  .chapter-4-content,
  .chapter-3-header,
  .chapter-5-content {
    padding-left: 24px;
    padding-right: 24px;
  }
}

@media (max-width: 480px) {
  .nav-pill {
    gap: 0.75rem;
  }

  .nav-pill a:not(:first-child):not(:last-child) {
    display: none;
  }
}
