/* ============================================================
   EXAMPLE DOMAIN — "The Reserved Page"
   Brutalist Oversized Type Design
   ============================================================ */

/* --- CSS Custom Properties --- */
:root {
  /* Color Palette */
  --bg:            #EEEEEE;
  --text:          #111111;
  --link:          #334488;
  --link-hover:    #223366;
  --warning:       #F25C05;
  --surface:       #F7F7F7;
  --grid:          #C8C8C8;
  --grid-opacity:  0.25;

  /* Brutalist Elevation System */
  --elev-1:        0 0 0 1px #111;
  --elev-2:        4px 4px 0 #111;
  --elev-3:        8px 8px 0 #334488;
  --elev-warning:  6px 6px 0 #F25C05;

  /* 8pt Spacing Scale */
  --sp-0:   0;
  --sp-05:  0.25rem;
  --sp-1:   0.5rem;
  --sp-15:  0.75rem;
  --sp-2:   1rem;
  --sp-3:   1.5rem;
  --sp-4:   2rem;
  --sp-6:   3rem;
  --sp-8:   4rem;
  --sp-12:  6rem;
  --sp-16:  8rem;

  /* Typography */
  --font-mono:   'IBM Plex Mono', 'Courier New', monospace;
  --font-sans:   'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  --fs-micro:    0.64rem;
  --fs-small:    0.8rem;
  --fs-body:     1rem;
  --fs-h6:       1.25rem;
  --fs-h5:       1.5625rem;
  --fs-h4:       1.953rem;
  --fs-h3:       2.441rem;
  --fs-h2:       3.052rem;
  --fs-h1:       3.815rem;
  --fs-display2: clamp(3rem, 8vw, 5.96rem);
  --fs-display1: clamp(4rem, 12vw, 7.45rem);
  --fs-specimen: clamp(5rem, 18vw, 10rem);
  --fs-massive:  clamp(4rem, 15vw, 8rem);
  --fs-mega:     clamp(6rem, 22vw, 14rem);

  /* Grid */
  --grid-columns: 12;
  --grid-gap:     1px;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: 1.6;
  color: var(--text);
  background-color: var(--bg);
  overflow-x: hidden;
  position: relative;
}

/* --- Noise Overlay --- */
.noise-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1000;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 256px 256px;
}

/* --- 12-Column Grid Guide --- */
.grid-guide {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 0;
  pointer-events: none;
  z-index: 1;
  padding: 0 var(--sp-4);
  max-width: 1400px;
  margin: 0 auto;
}

.grid-col {
  border-left: 1px solid rgba(200, 200, 200, var(--grid-opacity));
  border-right: 1px solid rgba(200, 200, 200, var(--grid-opacity));
  height: 100%;
}

.grid-col:first-child {
  border-left: 1px solid rgba(200, 200, 200, var(--grid-opacity));
}

.grid-col:last-child {
  border-right: 1px solid rgba(200, 200, 200, var(--grid-opacity));
}

/* --- Progress Bar --- */
.progress-track {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(200, 200, 200, 0.3);
  z-index: 2000;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--warning);
  transition: width 0.1s linear;
}

/* --- Chapter Base --- */
.chapter {
  position: relative;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: var(--sp-8) var(--sp-4);
  z-index: 2;
  overflow: hidden;
}

.chapter__number {
  position: absolute;
  top: var(--sp-3);
  left: var(--sp-4);
  font-family: var(--font-mono);
  font-size: var(--fs-small);
  font-weight: 400;
  color: var(--grid);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.chapter__number--warning {
  color: var(--warning);
}

.chapter__content {
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  position: relative;
}

.chapter__body {
  max-width: 1400px;
  margin: var(--sp-6) auto 0;
  width: 100%;
  padding: 0 var(--sp-4);
}

/* --- Display Words (Oversized Type) --- */
.display-word {
  font-family: var(--font-mono);
  font-weight: 700;
  line-height: 0.85;
  letter-spacing: -0.03em;
  color: var(--text);
  position: relative;
}

.display-word--massive {
  font-size: var(--fs-mega);
  margin-left: -0.04em;
}

.display-word--large {
  font-size: var(--fs-massive);
  margin-left: -0.03em;
}

.display-word--specimen {
  font-size: var(--fs-specimen);
  margin-left: -0.02em;
  color: var(--link);
  letter-spacing: -0.05em;
}

.display-word--warning {
  font-size: var(--fs-mega);
  color: var(--text);
  position: relative;
  z-index: 5;
}

/* --- Annotations --- */
.annotation {
  font-family: var(--font-mono);
  font-size: var(--fs-small);
  line-height: 1.5;
  color: var(--grid);
  margin-top: var(--sp-3);
  letter-spacing: 0.02em;
}

.annotation--right {
  text-align: right;
  margin-left: auto;
  max-width: 40ch;
}

.annotation--left {
  text-align: left;
  max-width: 40ch;
}

.annotation--center {
  text-align: center;
  max-width: 40ch;
  margin-left: auto;
  margin-right: auto;
  margin-top: var(--sp-6);
}

/* --- Body Text --- */
.body-text {
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: 1.7;
  color: var(--text);
  max-width: 60ch;
}

.body-text--narrow {
  max-width: 45ch;
}

.body-text--offset-right {
  margin-left: auto;
}

.body-text--offset-left {
  margin-right: auto;
}

.body-text--warning {
  font-size: var(--fs-h5);
  line-height: 1.5;
  color: var(--text);
}

.body-text--warning strong {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--fs-h4);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--sp-2);
}

/* --- Elevated Panels (Brutalist Shadows) --- */
.elevated-panel {
  padding: var(--sp-4) var(--sp-6);
  max-width: 600px;
  position: relative;
}

.elevated-panel--primary {
  background: var(--surface);
  box-shadow: var(--elev-3);
}

.elevated-panel--warning {
  background: var(--surface);
  box-shadow: var(--elev-warning);
  border-left: 4px solid var(--warning);
}

/* --- Code Block --- */
.code-annotation {
  position: absolute;
  right: var(--sp-4);
  top: 50%;
  transform: translateY(-50%);
  max-width: 400px;
}

.code-block {
  font-family: var(--font-mono);
  font-size: var(--fs-small);
  line-height: 1.6;
  background: var(--surface);
  padding: var(--sp-3) var(--sp-4);
  box-shadow: var(--elev-2);
  border: 1px solid var(--grid);
  overflow-x: auto;
  white-space: pre;
  color: var(--link);
}

/* --- Use Grid (Chapter 04) --- */
.use-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--sp-4);
  max-width: 900px;
}

.use-card {
  padding: var(--sp-4);
  background: var(--surface);
  box-shadow: var(--elev-1);
  border-top: 2px solid var(--text);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.use-card:hover {
  box-shadow: var(--elev-2);
  transform: translate(-2px, -2px);
}

.use-card__label {
  font-family: var(--font-mono);
  font-size: var(--fs-h2);
  font-weight: 700;
  color: var(--grid);
  display: block;
  margin-bottom: var(--sp-2);
  line-height: 1;
}

.use-card__text {
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: 1.6;
  color: var(--text);
}

/* --- Section Dividers --- */
.section-divider {
  position: relative;
  height: 1px;
  z-index: 2;
  padding: 0 var(--sp-4);
  max-width: 1400px;
  margin: 0 auto;
}

.section-divider__line {
  height: 1px;
  background: var(--grid);
}

.section-divider--angled {
  height: 40px;
  overflow: visible;
}

.section-divider__svg {
  width: 100%;
  height: 40px;
  display: block;
}

.section-divider--flip .section-divider__svg {
  transform: scaleY(-1);
}

/* --- Warning Blend Band (mix-blend-mode) --- */
.warning-blend-band {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  z-index: 3;
  pointer-events: none;
}

.warning-blend-band__text {
  font-family: var(--font-mono);
  font-size: clamp(3rem, 8vw, 6rem);
  font-weight: 700;
  white-space: nowrap;
  color: var(--warning);
  mix-blend-mode: multiply;
  opacity: 0.12;
  letter-spacing: 0.1em;
  animation: scrollBand 20s linear infinite;
}

@keyframes scrollBand {
  0%   { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}

/* --- CTA Link (Chapter 06) --- */
.chapter--learn .chapter__content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
}

.cta-link {
  display: inline-flex;
  align-items: baseline;
  gap: var(--sp-2);
  text-decoration: none;
  color: var(--link);
  font-family: var(--font-mono);
  font-size: clamp(3rem, 10vw, 7rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
  border-bottom: 4px solid var(--link);
  padding-bottom: var(--sp-1);
  transition: color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
  position: relative;
}

.cta-link:hover {
  color: var(--warning);
  border-color: var(--warning);
  transform: translate(-3px, -3px);
}

.cta-link:active {
  transform: translate(0, 0);
}

.cta-link__arrow {
  font-size: 0.6em;
  transition: transform 0.2s ease;
}

.cta-link:hover .cta-link__arrow {
  transform: translateX(6px);
}

/* --- Warning Chapter Special Background --- */
.chapter--warning {
  background: var(--bg);
  position: relative;
}

.chapter--warning::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 120%;
  height: 200px;
  background: var(--warning);
  opacity: 0.06;
  z-index: 0;
}

/* --- Footer --- */
.site-footer {
  position: relative;
  z-index: 2;
  padding: var(--sp-8) var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--grid);
  max-width: 1400px;
  margin: 0 auto;
}

.footer-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
}

.footer-text {
  font-family: var(--font-mono);
  font-size: var(--fs-small);
  color: var(--grid);
  letter-spacing: 0.05em;
  text-align: center;
}

.footer-text--micro {
  font-size: var(--fs-micro);
  color: var(--grid);
  opacity: 0.6;
}

/* --- Scroll Reveal Animations --- */
.chapter__content,
.chapter__body,
.use-card,
.code-annotation {
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 0.8s ease, transform 0.8s ease;
}

.chapter__content.visible,
.chapter__body.visible,
.use-card.visible,
.code-annotation.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Stagger use cards */
.use-card:nth-child(1) { transition-delay: 0s; }
.use-card:nth-child(2) { transition-delay: 0.1s; }
.use-card:nth-child(3) { transition-delay: 0.2s; }
.use-card:nth-child(4) { transition-delay: 0.3s; }

/* --- Chapter-specific positioning tweaks --- */
.chapter--reserved .chapter__body {
  text-align: right;
}

.chapter--blank .chapter__body {
  padding-left: 10%;
}

.chapter--example .chapter__content {
  padding-right: 42%;
}

.chapter--documentation .chapter__body {
  padding-left: 5%;
}

/* --- Link base style --- */
a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--warning);
}

/* --- Selection --- */
::selection {
  background: var(--link);
  color: var(--bg);
}

::-moz-selection {
  background: var(--link);
  color: var(--bg);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 900px) {
  .chapter {
    padding: var(--sp-6) var(--sp-3);
  }

  .grid-guide {
    padding: 0 var(--sp-2);
  }

  .code-annotation {
    position: relative;
    right: auto;
    top: auto;
    transform: none;
    max-width: 100%;
    margin-top: var(--sp-4);
  }

  .chapter--example .chapter__content {
    padding-right: 0;
  }

  .use-grid {
    grid-template-columns: 1fr;
  }

  .elevated-panel {
    padding: var(--sp-3);
  }

  .body-text--offset-right {
    margin-left: 0;
  }

  .body-text--offset-left {
    margin-right: 0;
  }

  .annotation--right {
    text-align: left;
    margin-left: 0;
  }
}

@media (max-width: 600px) {
  :root {
    --fs-mega:    clamp(3rem, 18vw, 6rem);
    --fs-massive: clamp(2.5rem, 14vw, 4rem);
    --fs-specimen: clamp(3rem, 16vw, 5rem);
  }

  .chapter {
    min-height: 80vh;
    padding: var(--sp-8) var(--sp-3) var(--sp-4);
  }

  .grid-guide {
    display: none;
  }

  .chapter__number {
    position: relative;
    top: auto;
    left: auto;
    margin-bottom: var(--sp-2);
  }

  .cta-link {
    font-size: clamp(2rem, 10vw, 4rem);
  }

  .body-text--warning {
    font-size: var(--fs-body);
  }

  .body-text--warning strong {
    font-size: var(--fs-h5);
  }

  .use-card__label {
    font-size: var(--fs-h3);
  }
}

/* --- Prefers reduced motion --- */
@media (prefers-reduced-motion: reduce) {
  .warning-blend-band__text {
    animation: none;
  }

  .chapter__content,
  .chapter__body,
  .use-card,
  .code-annotation {
    opacity: 1;
    transform: none;
    transition: none;
  }

  html {
    scroll-behavior: auto;
  }
}

/* --- High contrast mode --- */
@media (forced-colors: active) {
  .elevated-panel--primary,
  .elevated-panel--warning {
    border: 2px solid ButtonText;
  }

  .use-card {
    border: 1px solid ButtonText;
  }
}
