/* ==========================================================================
   EVOLVING SOFTWARE — Design System
   Shared across all pages. Black / White / Grey / Red only.
   ========================================================================== */

/* --- Custom Properties --- */
:root {
  /* Palette */
  --white: #fafafa;
  --white-pure: #ffffff;
  --black: #111111;
  --black-deep: #0a0a0a;
  --grey-100: #f0f0f0;
  --grey-200: #e0e0e0;
  --grey-300: #cccccc;
  --grey-400: #999999;
  --grey-500: #777777;
  --grey-600: #555555;
  --grey-700: #333333;
  --grey-800: #1a1a1a;
  --red: #c41e1e;
  --red-light: #e63333;
  --red-dark: #8b1515;
  --red-glow: rgba(196, 30, 30, 0.3);

  /* Typography */
  --font-heading: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Spacing Scale */
  --space-xs: 0.5rem;
  --space-sm: 1rem;
  --space-md: 2rem;
  --space-lg: 4rem;
  --space-xl: 6rem;
  --space-2xl: 10rem;

  /* Layout */
  --max-width: 800px;
  --max-width-wide: 1100px;

  /* Transitions */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --duration-fast: 200ms;
  --duration-normal: 400ms;
  --duration-slow: 800ms;
}

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

html {
  scroll-behavior: smooth;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background-color: var(--white);
}

body {
  font-family: var(--font-body);
  font-size: 1.125rem;
  line-height: 1.75;
  color: var(--black);
  background-color: transparent;
  overflow-x: hidden;
  position: relative;
}

::selection {
  background-color: var(--red);
  color: var(--white-pure);
}

/* --- Reading Progress Bar --- */
.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0%;
  background: var(--red);
  z-index: 10000;
  transition: none;
}

/* --- Canvas Background --- */
#bg-canvas {
  position: absolute;
  top: 0;
  left: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.25;
}

/* --- Typography --- */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-heading);
  font-weight: 700;
  line-height: 1.2;
  color: var(--black);
}

h1 {
  font-size: clamp(2.5rem, 6vw, 5rem);
  letter-spacing: -0.02em;
}

h2 {
  font-size: clamp(1.8rem, 4vw, 3rem);
  letter-spacing: -0.01em;
  margin-bottom: var(--space-md);
}

h3 {
  font-size: clamp(1.3rem, 2.5vw, 1.75rem);
  margin-bottom: var(--space-sm);
}

p {
  margin-bottom: 1.25em;
  color: var(--grey-700);
}

strong {
  color: var(--black);
  font-weight: 600;
}

em {
  font-style: italic;
}

a {
  color: var(--red);
  text-decoration: none;
  transition: color var(--duration-fast) ease;
}

a:hover {
  color: var(--red-light);
}

blockquote {
  border-left: 3px solid var(--red);
  padding-left: var(--space-md);
  margin: var(--space-md) 0;
  font-style: italic;
  color: var(--grey-600);
  font-size: 1.2rem;
}

/* --- Layout --- */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--space-md);
  position: relative;
  z-index: 1;
}

.container--wide {
  max-width: var(--max-width-wide);
}

section {
  padding: var(--space-xl) 0;
  position: relative;
}

/* --- Hero --- */
.hero {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  position: relative;
  padding: var(--space-lg);
}

.hero__title-container {
  position: relative;
  width: 100%;
  max-width: 900px;
  margin-bottom: var(--space-md);
}

.hero__title {
  font-family: var(--font-heading);
  font-size: clamp(3rem, 8vw, 6rem);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
  text-align: center;
  margin: 0;
  position: relative;
  z-index: 1;
}

.hero__title-line {
  display: block;
}

.hero__title-line--dark {
  color: var(--black);
}

.hero__title-line--red {
  color: var(--red);
}

.morph-char {
  display: inline-block;
  transition: none; /* prevent any CSS transition interfering with scramble */
  min-width: 0.55em; /* prevents layout jump when narrow glyphs appear */
}

.title-branch-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
  /* Above text and everything else in hero */
}

.hero__subtitle {
  font-family: var(--font-body);
  font-size: clamp(1rem, 2.5vw, 1.35rem);
  font-weight: 300;
  color: var(--grey-500);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-bottom: var(--space-lg);
  max-width: 700px;
}

.hero__scroll-cta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xs);
  color: var(--grey-400);
  font-size: 0.85rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  animation: float 3s ease-in-out infinite;
}

.hero__scroll-cta svg {
  width: 24px;
  height: 24px;
  stroke: var(--red);
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(8px);
  }
}

/* --- Section Headers --- */
.section-header {
  text-align: center;
  margin-bottom: var(--space-xl);
}

.section-header__label {
  display: inline-block;
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--red);
  margin-bottom: var(--space-sm);
}

.section-header__rule {
  width: 60px;
  height: 2px;
  background: var(--red);
  margin: var(--space-md) auto 0;
  border: none;
}

/* --- Prologue --- */
.prologue {
  background: transparent;
}

.prologue__text {
  font-size: 1.25rem;
  line-height: 1.9;
  color: var(--grey-700);
  max-width: 720px;
  margin: 0 auto;
}

.prologue__text--emphasis {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  color: var(--black);
  line-height: 1.6;
  text-align: center;
  margin: var(--space-lg) auto;
  max-width: 600px;
}

/* --- Layer Cards --- */
.layers {
  background: transparent;
  padding: var(--space-xl) 0;
}

.layer-card {
  background: var(--white-pure);
  border: 1px solid var(--grey-200);
  border-left: 4px solid var(--red);
  margin-bottom: var(--space-md);
  cursor: pointer;
  transition: box-shadow var(--duration-normal) var(--ease-out),
    transform var(--duration-normal) var(--ease-out);
  position: relative;
  overflow: hidden;
}

.layer-card:hover {
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.08);
  transform: translateY(-2px);
}

.layer-card__header {
  display: flex;
  align-items: baseline;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-md);
}

.layer-card__number {
  font-family: var(--font-heading);
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--red);
  line-height: 1;
  flex-shrink: 0;
  min-width: 50px;
}

.layer-card__title-group {
  flex: 1;
}

.layer-card__title {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  color: var(--black);
  margin-bottom: 0.25rem;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.layer-card__teaser {
  font-size: 1rem;
  color: var(--grey-500);
  font-style: italic;
  margin: 0;
}

.layer-card__toggle {
  font-size: 1.5rem;
  color: var(--red);
  transition: transform var(--duration-normal) var(--ease-out);
  flex-shrink: 0;
}

.layer-card.expanded .layer-card__toggle {
  transform: rotate(45deg);
}

.layer-card__body {
  max-height: 0;
  overflow: hidden;
  transition: max-height var(--duration-slow) var(--ease-out),
    padding var(--duration-normal) var(--ease-out);
  padding: 0 var(--space-md);
}

.layer-card.expanded .layer-card__body {
  max-height: 2000px;
  padding: 0 var(--space-md) var(--space-md);
}

.layer-card__content {
  padding-top: var(--space-md);
  border-top: 1px solid var(--grey-200);
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity var(--duration-normal) var(--ease-out) 100ms,
    transform var(--duration-normal) var(--ease-out) 100ms;
}

.layer-card.expanded .layer-card__content {
  opacity: 1;
  transform: translateY(0);
}

.layer-card__content p {
  margin-bottom: 1em;
}

.layer-card__content ul {
  list-style: none;
  padding: 0;
  margin-bottom: 1.5em;
}

.layer-card__content li {
  padding-left: 1.5em;
  position: relative;
  margin-bottom: 0.5em;
  color: var(--grey-700);
}

.layer-card__content li::before {
  content: '>';
  position: absolute;
  left: 0;
  color: var(--red);
  font-weight: 700;
}

.layer-card__reflection {
  font-style: italic;
  color: var(--grey-600);
  border-left: 2px solid var(--red);
  padding-left: var(--space-sm);
  margin-top: var(--space-md);
}

.layer-card__explore {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  margin-top: var(--space-md);
  padding: 0.75em 1.5em;
  background: var(--black);
  color: var(--white);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-decoration: none;
  transition: background var(--duration-fast) ease,
    transform var(--duration-fast) ease;
}

.layer-card__explore:hover {
  background: var(--red);
  color: var(--white-pure);
  transform: translateX(4px);
}

/* --- Treatise Section --- */
.treatise {
  background: var(--black);
  color: var(--white);
  padding: var(--space-xl) 0;
}

.treatise h2 {
  color: var(--white);
}

.treatise p {
  color: var(--grey-300);
}

.treatise .section-header__label {
  color: var(--red-light);
}

.treatise__declaration {
  font-family: var(--font-heading);
  font-size: clamp(1.2rem, 2.5vw, 1.6rem);
  color: var(--white);
  line-height: 1.8;
  text-align: center;
  max-width: 700px;
  margin: 0 auto var(--space-lg);
}

.treatise__list {
  list-style: none;
  padding: 0;
  max-width: 600px;
  margin: 0 auto var(--space-lg);
}

.treatise__list li {
  padding: 0.75em 0;
  padding-left: 2em;
  position: relative;
  color: var(--grey-300);
  border-bottom: 1px solid var(--grey-800);
}

.treatise__list li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  width: 8px;
  height: 8px;
  background: var(--red);
  border-radius: 50%;
  transform: translateY(-50%);
}

/* --- Position / Author Section --- */
.position {
  background: transparent;
  text-align: center;
}

.position__statement {
  font-family: var(--font-heading);
  font-size: clamp(1.3rem, 3vw, 1.8rem);
  color: var(--black);
  line-height: 1.6;
  max-width: 650px;
  margin: 0 auto var(--space-md);
}

/* --- Closing / Footer --- */
.closing {
  text-align: center;
  padding: var(--space-xl) 0 var(--space-lg);
}

.closing__quote {
  font-family: var(--font-heading);
  font-size: clamp(1.2rem, 2.5vw, 1.5rem);
  font-style: italic;
  color: var(--grey-600);
  max-width: 650px;
  margin: 0 auto var(--space-lg);
  line-height: 1.7;
}

.footer {
  border-top: 1px solid var(--grey-200);
  padding: var(--space-md) 0;
  text-align: center;
}

.footer__content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xs);
}

.footer__brand {
  font-family: var(--font-heading);
  font-size: 1rem;
  color: var(--black);
  font-weight: 700;
}

.footer__legal {
  font-size: 0.8rem;
  color: var(--grey-400);
}

.footer__legal a {
  color: var(--grey-500);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.footer__legal a:hover {
  color: var(--red);
}

/* --- Scroll Animation --- */
.reveal {
  opacity: 0;
  transform: translateY(30px);
  transition: opacity var(--duration-slow) var(--ease-out),
    transform var(--duration-slow) var(--ease-out);
}

.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

/* --- Red Divider --- */
.divider {
  width: 60px;
  height: 3px;
  background: var(--red);
  border: none;
  margin: var(--space-lg) auto;
}

/* --- Layer Page Styles --- */
.layer-page-hero {
  min-height: 50vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-2xl) var(--space-md) var(--space-lg);
  position: relative;
}

.layer-page-hero__number {
  font-family: var(--font-heading);
  font-size: clamp(4rem, 12vw, 8rem);
  font-weight: 700;
  color: var(--red);
  line-height: 1;
  opacity: 0.15;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -60%);
  z-index: 0;
}

.layer-page-hero__title {
  position: relative;
  z-index: 1;
}

.layer-page-hero__teaser {
  font-size: 1.2rem;
  color: var(--grey-500);
  font-style: italic;
  margin-top: var(--space-sm);
  position: relative;
  z-index: 1;
}

.layer-page__body {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--space-md) var(--space-xl);
}

.layer-page__body h3 {
  margin-top: var(--space-lg);
  color: var(--red-dark);
}

.layer-page__body ul {
  list-style: none;
  padding: 0;
}

.layer-page__body li {
  padding-left: 1.5em;
  position: relative;
  margin-bottom: 0.75em;
  color: var(--grey-700);
}

.layer-page__body li::before {
  content: '>';
  position: absolute;
  left: 0;
  color: var(--red);
  font-weight: 700;
}

/* Layer Nav */
.layer-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md);
  max-width: var(--max-width);
  margin: 0 auto;
  border-top: 1px solid var(--grey-200);
}

.layer-nav a {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--grey-600);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: color var(--duration-fast) ease;
}

.layer-nav a:hover {
  color: var(--red);
}

/* --- Terms Page --- */
.terms {
  padding: var(--space-2xl) 0 var(--space-xl);
}

.terms h1 {
  font-size: clamp(2rem, 4vw, 3rem);
  margin-bottom: var(--space-lg);
}

.terms h2 {
  font-size: 1.3rem;
  margin-top: var(--space-lg);
  margin-bottom: var(--space-sm);
  color: var(--black);
}

.terms p {
  font-size: 1rem;
  line-height: 1.7;
  color: var(--grey-600);
}

/* --- Back to Top Link --- */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--grey-500);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: var(--space-md) 0;
}

.back-link:hover {
  color: var(--red);
}

/* --- Responsive --- */
@media (max-width: 768px) {
  body {
    font-size: 1rem;
  }

  section {
    padding: var(--space-lg) 0;
  }

  .container {
    padding: 0 var(--space-sm);
  }

  .hero {
    padding: var(--space-md);
  }

  .hero__subtitle {
    letter-spacing: 0.08em;
    font-size: 0.9rem;
  }

  .layer-card__header {
    flex-direction: column;
    gap: var(--space-xs);
    padding: var(--space-sm);
  }

  .layer-card__number {
    font-size: 1.5rem;
  }

  .layer-card__title {
    font-size: 1.2rem;
  }

  .layer-card__body {
    padding-left: var(--space-sm);
    padding-right: var(--space-sm);
  }

  .layer-card.expanded .layer-card__body {
    padding: 0 var(--space-sm) var(--space-sm);
  }

  .treatise__declaration {
    font-size: 1.1rem;
  }

  .layer-nav {
    flex-direction: column;
    gap: var(--space-sm);
    text-align: center;
  }

  .prologue__text--emphasis {
    font-size: 1.2rem;
  }
}

@media (max-width: 480px) {
  .hero__title-container {
    padding: 0 var(--space-xs);
  }

  .layer-card__header {
    padding: var(--space-sm);
  }

  .footer__content {
    padding: 0 var(--space-sm);
  }
}