/* ==========================================================================
   SOFT ERROR — Design System
   UCL Bartlett RC6 | Material Architecture Lab
   ========================================================================== */

/* --- Custom Font --- */
@font-face {
  font-family: 'Letterform Variations';
  src: url('../fonts/LLDCL-1.ttf') format('truetype');
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Didot';
  src: url('../webpics/Didot.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Didot';
  src: url('../webpics/Didot Bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Didot';
  src: url('../webpics/Didot Italic.ttf') format('truetype');
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: 'Montserrat';
  src: url('../webpics/Montserrat Light.otf') format('opentype');
  font-weight: 300;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Montserrat';
  src: url('../webpics/Montserrat Semi Bold.otf') format('opentype');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

/* --- Variables --- */
:root {
  --bg: #ffffff;
  --text: #111111;
  --text-secondary: #666666;
  --red: #e00000;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-stencil: 'Letterform Variations', 'Stardos Stencil', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
}

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

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
}

a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; height: auto; }

/* ==========================================================================
   HOME PAGE
   ========================================================================== */

/* --- Scroll Spacer --- */
.scroll-spacer {
  height: 800vh;           /* extended for box curtain + phases + gaps */
  pointer-events: none;
}

/* --- Canvas Hero --- */
.hero-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 1;
  cursor: crosshair;
  will-change: opacity;
}

/* --- Red Multiply Overlay --- */
.red-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100vw;
  height: 100vh;
  background: #e00000;
  mix-blend-mode: multiply;
  opacity: 0;
  pointer-events: none;
  z-index: 2;
  will-change: opacity;
  transition: opacity 0.3s ease-out;
}

/* --- Box Curtain --- */
.box-curtain {
  position: fixed;
  top: 0; left: 0;
  width: 100vw;
  height: 100vh;
  object-fit: cover;
  object-position: center bottom;
  z-index: 5;
  cursor: pointer;
  will-change: transform;
}

/* --- Corner Labels --- */
.corner-label {
  position: fixed;
  z-index: 8;
  font-family: var(--font-stencil);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  pointer-events: none;
  user-select: none;
  will-change: opacity, color;
  transition: opacity 0.5s, color 0.5s;
}

.corner-tl {
  top: 28px;
  left: 36px;
  color: #ffd500;
}

.corner-tr {
  top: 28px;
  right: 36px;
  color: #000;
}

.corner-tc {
  top: 28px;
  left: 50%;
  transform: translateX(-50%);
  color: #ffd500;
}

/* --- Main Title --- */
.hero-title {
  position: fixed;
  top: 44%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 4;
  font-family: var(--font-stencil);
  font-size: clamp(4rem, 10vw, 10rem);
  font-weight: 700;
  color: #ffd500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: center;
  line-height: 1;
  pointer-events: none;
  user-select: none;
  will-change: transform, opacity;
}

/* --- Chapter Links --- */
.chapter-list {
  position: fixed;
  bottom: 12%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

.chapter-link {
  font-family: var(--font-stencil);
  font-size: clamp(1.4rem, 2.5vw, 2.4rem);
  font-weight: 700;
  white-space: nowrap;
  color: #fff;
  text-decoration: none;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0;
  visibility: hidden;
  transform: translateY(24px);
  transition:
    opacity 0.7s cubic-bezier(0.23, 1, 0.32, 1),
    transform 0.7s cubic-bezier(0.23, 1, 0.32, 1),
    color 0.3s;
  will-change: transform, opacity;
  pointer-events: none;
}

.chapter-link.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

.chapter-link:hover {
  color: #ffd500;
}

/* --- Scroll Hint --- */
.scroll-hint {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: rgba(255,255,255,0.6);
  font-family: var(--font-stencil);
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  pointer-events: none;
  transition: opacity 0.5s;
}

.scroll-hint.faded {
  opacity: 0;
}

.scroll-arrow {
  animation: bob 2s ease-in-out infinite;
  font-size: 0.9rem;
}

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(6px); }
}

/* --- Credits Panel (phase 2) --- */
.credits-panel {
  position: fixed;
  inset: 0;
  z-index: 7;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 60px;
  opacity: 0;
  pointer-events: none;
  will-change: opacity;
  background: #000;
  padding: 40px;
}

.credits-left,
.credits-right {
  flex: 0 0 auto;
  max-width: 240px;
}

.credits-label {
  display: block;
  font-family: var(--font-stencil);
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #fff;
  margin-bottom: 12px;
}

.credits-left {
  text-align: right;
}

.credits-left p {
  font-family: var(--font-stencil);
  font-size: 0.75rem;
  line-height: 1.9;
  color: rgba(255,255,255,0.75);
  letter-spacing: 0.04em;
}

.credits-right {
  text-align: left;
}

/* --- Team List --- */
.team-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.team-member {
  font-family: var(--font-stencil);
  font-size: 0.75rem;
  line-height: 1.9;
  color: rgba(255,255,255,0.75);
  letter-spacing: 0.04em;
  cursor: default;
  position: relative;
  white-space: nowrap;
}

.team-name {
  transition: color 0.25s, background 0.25s;
  position: relative;
  padding: 2px 6px;
  margin: -2px -6px;
}

/* Email slide-out */
.team-email {
  position: absolute;
  left: calc(100% + 14px);
  top: 50%;
  transform: translateY(-50%) translateX(-10px);
  white-space: nowrap;
  color: rgba(255,255,255,0.8);
  font-family: var(--font-stencil);
  font-size: 0.7rem;
  letter-spacing: 0.03em;
  transition: opacity 0.3s, transform 0.4s cubic-bezier(0.23, 1, 0.32, 1);
  opacity: 0;
  pointer-events: none;
}

.team-member:hover .team-email:not(:empty) {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

.team-member:hover .team-name {
  color: #000;
  background: #fff;
}

/* --- Credits cursor --- */
.credits-panel.active {
  pointer-events: auto;
  cursor: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cline x1='12' y1='2' x2='12' y2='22' stroke='white' stroke-width='1'/%3E%3Cline x1='2' y1='12' x2='22' y2='12' stroke='white' stroke-width='1'/%3E%3C/svg%3E") 12 12, crosshair;
}

.credits-center {
  flex: 0 0 auto;
}

.credits-img-wrap {
  position: relative;
  transform: translateX(-20px);
  perspective: 800px;
}

.credits-img-wrap .credits-img {
  transition: opacity 0.25s ease, transform 0.15s ease-out;
  transform-style: preserve-3d;
}

.credits-img {
  max-height: 65vh;
  width: auto;
  display: block;
  transition: opacity 0.25s ease;
}

.credits-img-overlay {
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0;
}

/* --- Back to content link --- */
.credits-back {
  position: absolute;
  bottom: 36px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-stencil);
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.6);
  text-decoration: none;
  transition: color 0.25s;
  pointer-events: auto;
}

.credits-back:hover {
  color: #fff;
}

/* --- Responsive: stack on mobile --- */
@media (max-width: 768px) {
  .credits-panel {
    flex-direction: column;
    gap: 32px;
    padding: 24px;
  }
  .credits-left,
  .credits-right {
    text-align: center;
    max-width: none;
  }
  .credits-center {
    order: -1;
  }
  .credits-img {
    max-height: 30vh;
  }
}

/* ==========================================================================
   CHAPTER PAGES
   ========================================================================== */

.chapter-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.chapter-header {
  display: none;
}

.chapter-hero {
  display: none;
}

.chapter-title {
  font-family: var(--font-stencil);
  font-size: clamp(1.45rem, 2.7vw, 2.7rem);
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  line-height: 1.1;
  color: var(--text);
  margin-bottom: 48px;
}

.chapter-content {
  display: flex;
  min-height: 100vh;
  padding: 0 0 0 460px;  /* offset for fixed sidebar */
}

/* --- Left Sidebar --- */
.chapter-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 460px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: stretch;
  padding: 28px 48px;
  border-right: 1px solid #d0d0d0;
  z-index: 5;
  background: #fff;
}

.sidebar-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 60px;
}

.sidebar-logo {
  font-family: var(--font-stencil);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--text-secondary);
  text-transform: uppercase;
  text-decoration: none;
  transition: color 0.2s;
}

.sidebar-logo:hover {
  color: var(--red);
}

.sidebar-chap {
  font-family: var(--font-stencil);
  font-size: 0.7rem;
  color: var(--text-secondary);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* --- View Toggle --- */
.view-toggle {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  margin: auto 0;
}

.view-btn {
  min-width: 160px;
  height: 44px;
  border: 1px solid #ccc;
  background: #fff;
  cursor: pointer;
  font-family: var(--font-stencil);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #999;
  transition: background 0.3s, color 0.3s, border-color 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.2;
  padding: 8px 16px;
  white-space: nowrap;
}

.view-btn:hover {
  border-color: #333;
  color: #333;
}

.view-btn.active {
  background: #000;
  color: #fff;
  border-color: #000;
}

.scroll-top-btn {
  min-width: auto;
  width: 44px;
  padding: 8px;
}

.scroll-top-btn svg {
  display: block;
}

/* --- Sidebar Nav Arrows --- */
.sidebar-nav {
  display: flex;
  justify-content: space-between;
  width: 100%;
  margin-top: auto;
  padding-top: 48px;
}

.nav-arrow {
  display: inline-flex;
  align-items: center;
  color: var(--text);
  text-decoration: none;
  transition: color 0.2s;
  cursor: pointer;
  user-select: none;
}

.nav-arrow svg {
  display: block;
}

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

.nav-arrow.disabled {
  color: #ccc;
  pointer-events: none;
}

/* Page arrows (chapters 2-5, fixed on left) */
.page-arrows {
  position: fixed;
  left: 40px;
  right: 40px;
  bottom: 40px;
  display: flex;
  justify-content: space-between;
  z-index: 20;
  pointer-events: none;
}

.page-arrows .nav-arrow {
  pointer-events: auto;
}

/* --- Main Content Area --- */
.chapter-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

/* --- Card Reference Text --- */
.card-reference {
  position: absolute;
  left: 60px;
  top: 50%;
  transform: translateY(-50%);
  max-width: 260px;
}

.view-traditional.chapter-main {
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  padding-top: 50px;
}

.view-traditional .image-stack {
  order: 1;
}

.view-traditional .card-reference {
  position: relative;
  left: auto;
  top: auto;
  bottom: auto;
  transform: none;
  max-width: none;
  text-align: center;
  margin-top: 8px;
  order: 2;
  width: 100%;
}

.ref-label {
  font-family: 'Montserrat', sans-serif;
  font-size: 1rem;
  line-height: 1.4;
  color: var(--text);
  font-weight: 600;
  text-transform: uppercase;
  display: block;
  margin-bottom: 6px;
}

.ref-text {
  font-family: 'Montserrat', sans-serif;
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
  font-weight: 300;
  margin: 0;
}

/* --- Image Stack --- */
.image-stack {
  display: grid;
  place-items: center;
  min-height: 700px;
  padding-top: 160px;
  flex: 1;
}

.stack-card {
  grid-area: 1 / 1;            /* all cards in the same grid cell */
  width: clamp(160px, 20vw, 240px);
  height: auto;
  display: block;
  cursor: pointer;
  transform-origin: center center;
  --lift: 0px;
  transform: translate(var(--x), calc(var(--y) + var(--lift)));
  transition:
    transform 0.8s cubic-bezier(0.23, 1, 0.32, 1),
    opacity  0.8s cubic-bezier(0.23, 1, 0.32, 1);
  box-shadow: 0 4px 24px rgba(0,0,0,0.12);
}

/* Stack — diagonal offset (upper-right), no rotation. */
/* C1d1 (index 0) = top/centered; C1d6 (index 5) = furthest upper-right */
.stack-card[data-index="0"] { z-index: 6; --x: 0px;    --y: 0px;    }
.stack-card[data-index="1"] { z-index: 5; --x: 40px;   --y: -30px;  }
.stack-card[data-index="2"] { z-index: 4; --x: 80px;   --y: -60px;  }
.stack-card[data-index="3"] { z-index: 3; --x: 120px;  --y: -90px;  }
.stack-card[data-index="4"] { z-index: 2; --x: 160px;  --y: -120px; }
.stack-card[data-index="5"] { z-index: 1; --x: 200px;  --y: -150px; }

/* Hover — rise up 80px, stay in own layer */
.stack-card:hover {
  --lift: -80px;
}

/* Selected: non-active cards dim */
.image-stack.selected .stack-card {
  opacity: 0.25;
}

.image-stack.selected .stack-card.active {
  opacity: 1;
  --lift: -120px;
}

/* Hover in selected state still previews */
.image-stack.selected .stack-card:hover {
  opacity: 1;
  --lift: -80px;
}

/* --- 3D Model Section --- */
.model-section {
  display: none;
  width: 100%;
  padding-left: 460px;
  background: #fff;
  box-sizing: border-box;
}

.model-viewer {
  flex: 0 0 75%;
  height: 900px;
  overflow: hidden;
  background: #fff;
}

.model-viewer canvas {
  display: block;
}

.model-panel {
  flex: 1;
  padding: 48px 48px 40px 32px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
}

.model-panel p {
  margin: 0;
  font-family: 'Montserrat', sans-serif;
  font-weight: 300;
  font-size: 0.72rem;
  line-height: 1.7;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #666;
}

/* --- Traditional View (grid, max 4 per row) --- */
.image-stack.traditional {
  position: static;
  top: auto;
  left: auto;
  transform: none;
  display: grid;
  grid-template-columns: repeat(4, auto);
  justify-content: space-evenly;
  row-gap: 24px;
  min-height: auto;
  flex: none;
  padding: 24px 0;
  width: 100%;
  margin: 0 auto;
}

.image-stack.traditional .stack-card {
  position: static;
  grid-area: auto;
  width: clamp(160px, 20vw, 240px);
  min-width: 0;
  transform: translateY(0);
  --x: 0;
  --y: 0;
  --lift: 0;
  z-index: auto;
  cursor: pointer;
  transition:
    transform 0.3s cubic-bezier(0.23, 1, 0.32, 1),
    opacity 0.3s cubic-bezier(0.23, 1, 0.32, 1);
}

.image-stack.traditional .stack-card:hover {
  transform: translateY(-5px);
}

.image-stack.traditional.selected .stack-card {
  opacity: 0.25;
}

.image-stack.traditional.selected .stack-card.active {
  opacity: 1;
  transform: translateY(-5px);
}

.image-stack.traditional.selected .stack-card:hover {
  opacity: 1;
}

/* Chapter Responsive */
@media (max-width: 768px) {
  .chapter-content {
    flex-direction: column;
    padding: 0;
  }
  .chapter-sidebar {
    position: relative;
    top: auto;
    left: auto;
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 24px;
    padding: 24px 24px 0;
    border-right: none;
    border-bottom: 1px solid #d0d0d0;
    background: #fff;
  }
  .sidebar-top {
    width: 100%;
    margin-bottom: 24px;
  }
  .sidebar-logo {
    font-size: 0.7rem;
  }
  .sidebar-chap {
    font-size: 0.65rem;
  }
  .chapter-title {
    margin-bottom: 24px;
  }
  .view-toggle {
    flex-direction: row;
    gap: 8px;
  }
  .view-btn {
    min-width: auto;
    height: 34px;
    font-size: 0.6rem;
    padding: 6px 10px;
  }
  .image-stack {
    min-height: 500px;
    padding-top: 60px;
    width: 100%;
  }
  .stack-card {
    width: clamp(120px, 30vw, 180px);
  }
  .stack-card[data-index="0"] { --x: 0px;    --y: 0px;    }
  .stack-card[data-index="1"] { --x: 25px;   --y: -20px;  }
  .stack-card[data-index="2"] { --x: 50px;   --y: -40px;  }
  .stack-card[data-index="3"] { --x: 75px;   --y: -60px;  }
  .stack-card[data-index="4"] { --x: 100px;  --y: -80px;  }
  .stack-card[data-index="5"] { --x: 125px;  --y: -100px; }
  .stack-card:hover,
  .image-stack.selected .stack-card.active,
  .image-stack.selected .stack-card:hover {
    --lift: -130px;
  }
}

/* --- Chapter Navigation --- */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 60px 48px 100px;
  border-top: 1px solid #e8e8e8;
}

.chapter-nav-left,
.chapter-nav-right {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 40%;
}

.chapter-nav-left {
  align-items: flex-start;
  text-align: left;
}

.chapter-nav-right {
  align-items: flex-end;
  text-align: right;
}

.chapter-nav-label {
  font-family: var(--font-stencil);
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.chapter-nav-title {
  font-family: var(--font-stencil);
  font-size: 1.1rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text);
  text-decoration: none;
  transition: color 0.25s;
  line-height: 1.3;
}

.chapter-nav-title:hover {
  color: var(--red);
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .hero-title {
    font-size: clamp(2.2rem, 6vw, 4rem);
    top: 40%;
  }

  .chapter-link {
    font-size: clamp(1rem, 4vw, 1.5rem);
    gap: 8px;
  }

  .chapter-list { bottom: 10%; }

  .sidebar-chap {
    margin-bottom: 24px;
  }

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