/* ========================================
   haskell.quest - The Tower of Abstraction
   Medieval manuscript meets lambda calculus
   ======================================== */

/* CSS Custom Properties */
:root {
  --deep-umber: #1A1209;
  --walnut: #2B2118;
  --oxidized-copper: #5E4B3B;
  --burnished-gold: #C9A96E;
  --aged-vellum: #E8DCC8;
  --parchment-cream: #D4CBBA;
  --sage-green: #7EAA92;
  --terracotta: #D4856A;
  --steel-blue: #8B9EB7;
  --midnight-indigo: #1E2A3A;
  --crimson-seal: #8B2F2F;
}

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

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

body {
  background-color: var(--deep-umber);
  color: var(--parchment-cream);
  font-family: 'Lora', serif;
  font-size: clamp(1rem, 1.3vw, 1.15rem);
  line-height: 1.75;
  letter-spacing: 0.005em;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ========================================
   Parchment Texture Overlay
   ======================================== */
#parchment-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1000;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23noise)' opacity='1'/%3E%3C/svg%3E");
}

/* ========================================
   Lambda Runes (marginalia)
   ======================================== */
#lambda-runes {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
  overflow: hidden;
}

.lambda-rune {
  position: absolute;
  font-family: 'MedievalSharp', cursive;
  color: var(--oxidized-copper);
  user-select: none;
  pointer-events: none;
}

/* ========================================
   Tower Navigation (right edge)
   ======================================== */
#tower-nav {
  position: fixed;
  right: 24px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  mix-blend-mode: difference;
}

.nav-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background-color: #8B7355;
  z-index: -1;
}

.nav-dot {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  margin: 12px 0;
  border-radius: 50%;
  border: 1.5px solid #8B7355;
  background: transparent;
  position: relative;
  text-decoration: none;
  transition: background-color 0.4s ease, border-color 0.4s ease;
  cursor: pointer;
}

.nav-dot.active {
  background-color: var(--burnished-gold);
  border-color: var(--burnished-gold);
}

.nav-tooltip {
  position: absolute;
  right: 24px;
  white-space: nowrap;
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 0.85rem;
  color: var(--aged-vellum);
  opacity: 0;
  transform: translateX(8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}

.nav-dot:hover .nav-tooltip {
  opacity: 1;
  transform: translateX(0);
}

/* ========================================
   Chambers (General)
   ======================================== */
.chamber {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
}

.chamber-content {
  position: relative;
  z-index: 5;
  padding: 80px 40px;
  max-width: 1200px;
  margin: 0 auto;
}

.chamber-title {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 600;
  font-size: clamp(2.5rem, 6vw, 5rem);
  letter-spacing: 0.03em;
  line-height: 1.1;
  color: var(--aged-vellum);
  margin-bottom: 48px;
  font-feature-settings: "liga" 1, "onum" 1;
}

.drop-cap {
  font-family: 'MedievalSharp', cursive;
  font-size: 4.5em;
  float: left;
  line-height: 0.8;
  margin-right: 0.08em;
  color: var(--burnished-gold);
}

/* Chamber transitions (diagonal clip) */
.chamber-transition {
  position: relative;
  width: 100%;
  height: 40px;
  z-index: 10;
  margin-bottom: 24px;
}

/* ========================================
   Knotwork Borders
   ======================================== */
.knotwork-border {
  width: 100%;
  height: 40px;
  display: block;
}

.knot-path {
  fill: none;
  stroke: var(--oxidized-copper);
  stroke-width: 1.5;
  stroke-opacity: 0.4;
  stroke-dasharray: 2000;
  stroke-dashoffset: 2000;
  transition: stroke-dashoffset 1.5s ease-out;
}

.knot-path.animated {
  stroke-dashoffset: 0;
}

/* ========================================
   Chamber 1: The Gate
   ======================================== */
.chamber-gate {
  background-color: var(--deep-umber);
  display: flex;
  align-items: center;
  justify-content: center;
}

.gate-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 100vh;
  padding: 40px;
}

.sigil-container {
  width: clamp(200px, 40vw, 320px);
  height: clamp(200px, 40vw, 320px);
  margin-bottom: 32px;
}

.sigil-svg {
  width: 100%;
  height: 100%;
}

.sigil-path {
  fill: none;
  stroke: var(--burnished-gold);
  stroke-width: 2;
  stroke-dasharray: 1000;
  stroke-dashoffset: 1000;
}

.sigil-fill {
  fill: var(--burnished-gold);
  stroke: none;
  opacity: 0;
}

.lambda-stroke {
  stroke-width: 3;
}

.sigil-label {
  font-family: 'Cormorant Garamond', serif;
  font-size: 10px;
  fill: var(--burnished-gold);
  text-anchor: middle;
  dominant-baseline: middle;
  opacity: 0;
  letter-spacing: 0.05em;
}

.sigil-label-e {
  text-anchor: start;
}

.sigil-label-w {
  text-anchor: end;
}

.sigil-animated .sigil-path {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 3s ease-out;
}

.sigil-animated .sigil-fill {
  opacity: 1;
  transition: opacity 0.8s ease-out 2.5s;
}

.sigil-animated .sigil-label {
  opacity: 0.7;
  transition: opacity 1s ease-out 2.8s;
}

.site-title {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 700;
  font-size: clamp(2.5rem, 5vw, 4rem);
  color: var(--burnished-gold);
  letter-spacing: 0.03em;
  line-height: 1.1;
  opacity: 0;
  transition: opacity 1.2s ease-out;
  font-feature-settings: "liga" 1, "onum" 1;
}

.site-title.visible {
  opacity: 1;
}

.site-subtitle {
  font-family: 'Lora', serif;
  font-style: italic;
  font-size: clamp(1rem, 1.5vw, 1.2rem);
  color: var(--parchment-cream);
  margin-top: 16px;
  min-height: 1.75em;
  opacity: 0.85;
}

.site-subtitle .cursor {
  display: inline-block;
  width: 2px;
  height: 1.2em;
  background-color: var(--burnished-gold);
  vertical-align: text-bottom;
  margin-left: 2px;
  animation: blink-cursor 0.8s steps(1) infinite;
}

@keyframes blink-cursor {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.scroll-chevron {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--parchment-cream);
  animation: pulse-chevron 2s ease-in-out infinite;
}

@keyframes pulse-chevron {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.7; }
}

/* ========================================
   Chamber 2: The Foundation
   ======================================== */
.chamber-foundation {
  background-color: var(--walnut);
  clip-path: polygon(0 0, 100% 2vh, 100% 100%, 0 98vh);
}

.split-layout {
  display: flex;
  gap: 0;
  align-items: flex-start;
}

.split-left {
  flex: 0 0 58%;
  padding-right: 32px;
}

.split-divider {
  width: 2px;
  background-color: var(--oxidized-copper);
  align-self: stretch;
  flex-shrink: 0;
}

.split-right {
  flex: 0 0 40%;
  padding-left: 32px;
}

.split-right p {
  margin-bottom: 1.25em;
  hyphens: auto;
  text-align: justify;
}

.split-right p:last-child {
  margin-bottom: 0;
}

/* Code Block */
.code-block {
  font-family: 'Fira Code', monospace;
  font-size: clamp(0.85rem, 1.2vw, 1.05rem);
  line-height: 1.65;
  letter-spacing: 0.01em;
  font-feature-settings: "calt" 1;
  background-color: rgba(26, 18, 9, 0.5);
  border: 1px solid var(--oxidized-copper);
  border-radius: 4px;
  padding: 24px;
  overflow-x: auto;
}

.code-line {
  display: block;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.4s ease-out, transform 0.4s ease-out;
}

.code-line.visible {
  opacity: 1;
  transform: translateY(0);
}

.code-keyword { color: var(--burnished-gold); font-weight: 500; }
.code-type { color: var(--sage-green); }
.code-literal { color: var(--terracotta); }
.code-comment { color: var(--steel-blue); font-style: italic; }
.code-operator { color: var(--burnished-gold); }
.code-name { color: var(--aged-vellum); }

/* ========================================
   Chamber 3: The Pattern Hall
   ======================================== */
.chamber-patterns {
  background-color: var(--deep-umber);
  clip-path: polygon(0 3vh, 100% 0, 100% 97vh, 0 100%);
}

.patterns-content {
  padding-top: 100px;
  padding-bottom: 100px;
}

.bento-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.bento-card {
  background-color: var(--walnut);
  border: 1px solid var(--oxidized-copper);
  border-radius: 4px;
  padding: 28px 24px;
  aspect-ratio: 4 / 3;
  display: flex;
  flex-direction: column;
  justify-content: center;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.5s ease-out, transform 0.5s ease-out, border-color 0.3s ease, box-shadow 0.3s ease;
  cursor: default;
}

.bento-card.visible {
  opacity: 1;
  transform: translateY(0);
}

.bento-card:hover {
  border-color: var(--burnished-gold);
  transform: translateY(-4px);
  box-shadow: 0 8px 32px rgba(26, 18, 9, 0.6);
}

.bento-card.visible:hover {
  transform: translateY(-4px);
}

.card-name {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 600;
  font-size: clamp(1.2rem, 1.8vw, 1.5rem);
  color: var(--aged-vellum);
  margin-bottom: 8px;
  letter-spacing: 0.02em;
}

.card-signature {
  font-family: 'Fira Code', monospace;
  font-size: clamp(0.75rem, 1vw, 0.9rem);
  color: var(--burnished-gold);
  font-feature-settings: "calt" 1;
  margin-bottom: 12px;
  display: block;
}

.card-desc {
  font-family: 'Lora', serif;
  font-size: clamp(0.85rem, 1.1vw, 0.95rem);
  color: var(--parchment-cream);
  line-height: 1.6;
  opacity: 0.85;
}

/* ========================================
   Chamber 4: The Monad Labyrinth
   ======================================== */
.chamber-labyrinth {
  background-color: var(--midnight-indigo);
  clip-path: polygon(0 0, 100% 2vh, 100% 100%, 0 98vh);
  position: relative;
}

.labyrinth-content {
  max-width: 42ch;
  margin: 0 auto;
  padding-top: 100px;
  padding-bottom: 100px;
}

.labyrinth-text p {
  font-size: clamp(1.05rem, 1.4vw, 1.25rem);
  margin-bottom: 1.5em;
  hyphens: auto;
  text-align: justify;
}

.labyrinth-text code {
  font-family: 'Fira Code', monospace;
  font-size: 0.9em;
  color: var(--burnished-gold);
  font-feature-settings: "calt" 1;
}

.labyrinth-code {
  border-left: 3px solid var(--burnished-gold);
  padding-left: 16px;
  margin: 1.5em 0;
  font-family: 'Fira Code', monospace;
  font-size: clamp(0.85rem, 1.1vw, 1rem);
  line-height: 1.8;
  font-feature-settings: "calt" 1;
}

/* Background maze pattern */
.maze-background {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.maze-path {
  fill: none;
  stroke: var(--steel-blue);
  stroke-width: 0.5;
  stroke-opacity: 0.06;
}

/* ========================================
   Chamber 5: The Type Forge
   ======================================== */
.chamber-forge {
  background-color: var(--walnut);
  clip-path: polygon(0 3vh, 100% 0, 100% 97vh, 0 100%);
  position: relative;
}

.forge-content {
  padding-top: 100px;
  padding-bottom: 100px;
  position: relative;
}

/* Constellation backgrounds */
.constellation-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.constellation-star {
  fill: var(--oxidized-copper);
  opacity: 0.2;
}

.constellation-line {
  stroke: var(--oxidized-copper);
  stroke-width: 0.5;
  stroke-opacity: 0.15;
}

.constellation-drift {
  animation: drift 8s ease-in-out infinite alternate;
}

@keyframes drift {
  0% { transform: translateY(0); }
  100% { transform: translateY(-2px); }
}

/* Timeline */
.timeline {
  position: relative;
  max-width: 900px;
  margin: 0 auto;
  padding: 40px 0;
}

.timeline-spine {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  background-color: var(--oxidized-copper);
  transform: translateX(-50%);
}

.timeline-entry {
  position: relative;
  width: 50%;
  padding: 16px 0;
  opacity: 0;
  transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.timeline-left {
  padding-right: 48px;
  text-align: right;
  transform: translateX(-30px);
}

.timeline-left.visible {
  opacity: 1;
  transform: translateX(0);
}

.timeline-right {
  margin-left: 50%;
  padding-left: 48px;
  text-align: left;
  transform: translateX(30px);
}

.timeline-right.visible {
  opacity: 1;
  transform: translateX(0);
}

.timeline-connector {
  position: absolute;
  top: 24px;
  width: 48px;
  height: 1px;
  background-color: var(--oxidized-copper);
}

.timeline-left .timeline-connector {
  right: 0;
}

.timeline-right .timeline-connector {
  left: 0;
}

.timeline-dot {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--burnished-gold);
  top: 50%;
  transform: translateY(-50%);
}

.timeline-left .timeline-dot {
  right: -5px;
}

.timeline-right .timeline-dot {
  left: -5px;
}

.timeline-year {
  font-family: 'Fira Code', monospace;
  font-size: 1.1rem;
  color: var(--burnished-gold);
  font-weight: 500;
  margin-bottom: 4px;
  font-feature-settings: "calt" 1;
}

.timeline-label {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 600;
  font-size: 1.4rem;
  color: var(--aged-vellum);
  margin-bottom: 8px;
  letter-spacing: 0.02em;
}

.timeline-block p {
  font-family: 'Lora', serif;
  font-size: 0.95rem;
  line-height: 1.65;
  color: var(--parchment-cream);
  opacity: 0.9;
}

.timeline-block code {
  font-family: 'Fira Code', monospace;
  font-size: 0.85em;
  color: var(--sage-green);
  font-feature-settings: "calt" 1;
}

/* ========================================
   Chamber 6: The Library
   ======================================== */
.chamber-library {
  background-color: var(--walnut);
  clip-path: polygon(0 0, 100% 2vh, 100% 100%, 0 98vh);
}

.library-content {
  padding-top: 100px;
  padding-bottom: 100px;
}

.masonry-grid {
  columns: 3;
  column-gap: 16px;
}

.masonry-card {
  break-inside: avoid;
  background-color: var(--aged-vellum);
  color: var(--walnut);
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: 2px 2px 0 var(--oxidized-copper);
  border-radius: 2px;
  opacity: 0;
  transform: scale(0.95);
  transition: opacity 0.4s ease-out, transform 0.4s ease-out;
}

.masonry-card.visible {
  opacity: 1;
  transform: scale(1);
}

.card-category {
  display: inline-block;
  font-family: 'Fira Code', monospace;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--oxidized-copper);
  border: 1px solid var(--oxidized-copper);
  border-radius: 2px;
  padding: 2px 8px;
  margin-bottom: 8px;
  font-feature-settings: "calt" 1;
}

.card-resource-name {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 600;
  font-size: 1.15rem;
  color: var(--walnut);
  margin-bottom: 4px;
  line-height: 1.3;
}

.card-author {
  font-family: 'Lora', serif;
  font-style: italic;
  font-size: 0.85rem;
  color: var(--oxidized-copper);
  margin-bottom: 10px;
}

.card-excerpt {
  font-family: 'Lora', serif;
  font-size: 0.88rem;
  line-height: 1.6;
  color: #3D2E22;
}

/* ========================================
   Chamber 7: The Summit
   ======================================== */
.chamber-summit {
  background: radial-gradient(ellipse at 50% 40%, #2B2118 0%, #1A1209 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  position: relative;
  clip-path: polygon(0 3vh, 100% 0, 100% 100%, 0 100%);
}

.summit-constellation {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.summit-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 680px;
  padding: 80px 40px;
  z-index: 5;
  position: relative;
}

.summit-text {
  margin-bottom: 48px;
}

.summit-statement {
  font-family: 'Lora', serif;
  font-size: clamp(1.05rem, 1.4vw, 1.2rem);
  line-height: 1.85;
  color: var(--parchment-cream);
  margin-bottom: 1.5em;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.8s ease-out, transform 0.8s ease-out;
}

.summit-statement.visible {
  opacity: 1;
  transform: translateY(0);
}

.summit-sigil {
  width: clamp(140px, 25vw, 200px);
  height: clamp(140px, 25vw, 200px);
  margin-bottom: 32px;
}

.sigil-summit {
  width: 100%;
  height: 100%;
}

.sigil-summit .sigil-path {
  stroke-dasharray: 1000;
  stroke-dashoffset: 0;
}

.sigil-summit .sigil-fill {
  fill: var(--burnished-gold);
  stroke: none;
  opacity: 0.7;
}

.sigil-summit .sigil-label {
  opacity: 0.6;
}

.summit-sigil-rotate {
  animation: slow-rotate 120s linear infinite;
}

@keyframes slow-rotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.summit-closing {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: clamp(1.2rem, 2vw, 1.6rem);
  color: var(--burnished-gold);
  opacity: 0;
  transition: opacity 1.2s ease-out;
  letter-spacing: 0.03em;
}

.summit-closing.visible {
  opacity: 0.6;
  animation: gentle-pulse 4s ease-in-out infinite;
}

@keyframes gentle-pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 0.7; }
}

/* ========================================
   Responsive Design
   ======================================== */

/* Tablet */
@media (max-width: 1024px) {
  .bento-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .bento-card {
    aspect-ratio: auto;
  }

  .masonry-grid {
    columns: 2;
  }

  .timeline-entry {
    width: 100%;
    padding-left: 48px;
    padding-right: 0;
    text-align: left;
  }

  .timeline-left {
    padding-right: 0;
    padding-left: 48px;
    text-align: left;
    transform: translateX(-20px);
  }

  .timeline-right {
    margin-left: 0;
    padding-left: 48px;
    transform: translateX(-20px);
  }

  .timeline-spine {
    left: 16px;
  }

  .timeline-left .timeline-connector,
  .timeline-right .timeline-connector {
    left: 0;
    right: auto;
    width: 32px;
  }

  .timeline-left .timeline-dot,
  .timeline-right .timeline-dot {
    left: -5px;
    right: auto;
  }

  #tower-nav {
    right: 12px;
  }
}

/* Mobile */
@media (max-width: 680px) {
  .chamber-content {
    padding: 60px 20px;
  }

  .split-layout {
    flex-direction: column;
  }

  .split-left {
    flex: 1 1 auto;
    padding-right: 0;
    margin-bottom: 32px;
  }

  .split-divider {
    width: 100%;
    height: 2px;
    margin-bottom: 32px;
  }

  .split-right {
    flex: 1 1 auto;
    padding-left: 0;
  }

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

  .masonry-grid {
    columns: 1;
  }

  .chamber-foundation,
  .chamber-patterns,
  .chamber-labyrinth,
  .chamber-forge,
  .chamber-library,
  .chamber-summit {
    clip-path: none;
  }

  .labyrinth-content {
    max-width: 100%;
  }

  #tower-nav {
    right: 8px;
  }

  .nav-dot {
    width: 10px;
    height: 10px;
    margin: 8px 0;
  }

  .nav-tooltip {
    display: none;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .sigil-path {
    stroke-dashoffset: 0 !important;
  }

  .sigil-fill, .sigil-label {
    opacity: 1 !important;
  }

  .code-line, .bento-card, .timeline-entry, .masonry-card, .summit-statement {
    opacity: 1 !important;
    transform: none !important;
  }

  .knot-path {
    stroke-dashoffset: 0 !important;
  }

  .summit-closing.visible {
    opacity: 0.6 !important;
    animation: none !important;
  }

  .site-title {
    opacity: 1 !important;
  }
}
