/* ============================================================
   GLACIAL — immersive dark theme
   ============================================================ */
:root {
  --bg:        #0A1218;
  --bg-2:      #0E1B24;
  --text:      #E9EFF2;
  --dim:       #8FA1AB;
  --ice:       #7CC4D8;
  --ice-deep:  #2E6E84;
  --earth:     #A68B66;
  --line:      rgba(233, 239, 242, 0.10);
  --maxw:      1240px;
  --pad:       clamp(1.4rem, 5vw, 4rem);
  --ease:      cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }
html { scroll-behavior: auto; }

html.lenis, html.lenis body { height: auto; }
.lenis.lenis-smooth { scroll-behavior: auto !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, sans-serif;
  font-size: 16.5px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

::selection { background: var(--ice-deep); color: #fff; }

h1, h2, h3 { font-family: "Sora", sans-serif; letter-spacing: -0.03em; line-height: 1.05; margin: 0; }
a { color: var(--ice); }

.mono-label {
  font-family: "Space Mono", monospace;
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--earth);
  margin: 0 0 1rem;
}

/* ============ Preloader ============ */
.loader {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}
.loader-word {
  font-family: "Sora", sans-serif;
  font-weight: 800;
  font-size: clamp(1.4rem, 4vw, 2.4rem);
  letter-spacing: -0.02em;
  opacity: 0;
}

/* ============ Custom cursor ============ */
.cursor-dot, .cursor-ring {
  position: fixed;
  top: 0; left: 0;
  z-index: 300;
  pointer-events: none;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}
.cursor-dot  { width: 6px;  height: 6px;  background: var(--ice); }
.cursor-ring {
  width: 36px; height: 36px;
  border: 1px solid rgba(124, 196, 216, 0.5);
  transition: width 0.25s var(--ease), height 0.25s var(--ease),
              border-color 0.25s, background 0.25s;
}
.cursor-ring.hovering {
  width: 64px; height: 64px;
  background: rgba(124, 196, 216, 0.08);
  border-color: rgba(124, 196, 216, 0.9);
}
@media (hover: none), (pointer: coarse) {
  .cursor-dot, .cursor-ring { display: none; }
}

/* ============ Grain ============ */
.grain {
  position: fixed;
  inset: -100%;
  z-index: 150;
  pointer-events: none;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain 8s steps(10) infinite;
}
@keyframes grain {
  0%,100% { transform: translate(0,0); }
  20% { transform: translate(-4%, 3%); }
  40% { transform: translate(3%, -4%); }
  60% { transform: translate(-3%, -2%); }
  80% { transform: translate(4%, 2%); }
}

/* ============ Nav ============ */
.nav {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 100;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.4rem var(--pad);
  mix-blend-mode: normal;
  transition: transform 0.4s var(--ease), background 0.3s, padding 0.3s;
}
.nav.hidden { transform: translateY(-100%); }
.nav.scrolled {
  padding-top: 0.9rem;
  padding-bottom: 0.9rem;
  background: rgba(10, 18, 24, 0.75);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.nav-name {
  font-family: "Sora", sans-serif;
  font-weight: 800;
  font-size: 1.2rem;
  color: var(--text);
  text-decoration: none;
}
.nav-name span { color: var(--ice); }
.nav-links a {
  position: relative;
  margin-left: clamp(1rem, 3vw, 2.6rem);
  color: var(--dim);
  text-decoration: none;
  font-family: "Space Mono", monospace;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  transition: color 0.25s;
}
.nav-links a span {
  color: var(--ice-deep);
  font-size: 0.62rem;
  vertical-align: super;
  margin-right: 0.35em;
}
.nav-links a::after {
  content: "";
  position: absolute;
  left: 0; bottom: -6px;
  width: 100%; height: 1px;
  background: var(--ice);
  transform: scaleX(0);
  transform-origin: right;
  transition: transform 0.35s var(--ease);
}
.nav-links a:hover, .nav-links a.active { color: var(--text); }
.nav-links a:hover::after, .nav-links a.active::after {
  transform: scaleX(1);
  transform-origin: left;
}

/* ============ Hero (home) ============ */
.hero {
  position: relative;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  overflow: hidden;
}
.ice-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.hero-inner {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 8rem var(--pad) 5rem;
}
.hero h1 {
  font-weight: 800;
  font-size: clamp(3rem, 10vw, 8.2rem);
  text-transform: uppercase;
  letter-spacing: -0.04em;
}
.hero h1 .outline,
.hero h1 .outline span {
  color: transparent;
  -webkit-text-stroke: 1.5px rgba(233, 239, 242, 0.85);
}
.hero-sub {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 2rem;
  margin-top: 2.2rem;
  flex-wrap: wrap;
}
.hero-sub .lede { max-width: 46ch; }
.lede { color: var(--dim); font-size: clamp(1rem, 1.4vw, 1.15rem); margin: 0; }

.hero-coords {
  font-family: "Space Mono", monospace;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  color: var(--dim);
  text-align: right;
  line-height: 2;
  white-space: nowrap;
}
.hero-coords b { color: var(--ice); font-weight: 400; }

.scroll-hint {
  position: absolute;
  right: var(--pad);
  bottom: 2rem;
  font-family: "Space Mono", monospace;
  font-size: 0.68rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--dim);
  writing-mode: vertical-rl;
}
.scroll-hint::after {
  content: "";
  display: block;
  width: 1px; height: 48px;
  margin: 10px auto 0;
  background: linear-gradient(var(--ice), transparent);
  animation: fall 1.8s var(--ease) infinite;
}
@keyframes fall { 0% { transform: scaleY(0); transform-origin: top; }
                  60% { transform: scaleY(1); transform-origin: top; }
                  100% { transform: scaleY(0); transform-origin: bottom; } }

/* ============ Page hero (subpages) ============ */
.page-hero {
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
}
.page-hero-inner {
  position: relative;
  z-index: 2;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 11rem var(--pad) 4rem;
}
.page-hero h1 {
  font-weight: 800;
  font-size: clamp(2.6rem, 7vw, 5.2rem);
  text-transform: uppercase;
}
.page-hero .lede { margin-top: 1.2rem; }

/* ============ Marquee ============ */
.marquee {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
  padding: 1.1rem 0;
  background: var(--bg-2);
}
.marquee-track {
  display: flex;
  gap: 3rem;
  width: max-content;
  animation: marquee 30s linear infinite;
  font-family: "Space Mono", monospace;
  font-size: 0.8rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--dim);
  white-space: nowrap;
}
.marquee-track em { font-style: normal; color: var(--ice); }
@keyframes marquee { to { transform: translateX(-50%); } }
.marquee:hover .marquee-track { animation-play-state: paused; }

/* ============ Sections ============ */
.section {
  position: relative;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(5rem, 10vw, 9rem) var(--pad);
}
.section-index {
  position: absolute;
  top: clamp(5rem, 10vw, 9rem);
  right: var(--pad);
  font-family: "Space Mono", monospace;
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  color: var(--ice-deep);
}

/* Big statement paragraph */
.statement {
  font-family: "Sora", sans-serif;
  font-weight: 600;
  font-size: clamp(1.5rem, 3.4vw, 2.6rem);
  line-height: 1.35;
  letter-spacing: -0.02em;
  max-width: 26ch;
  margin: 0;
}
.statement .hl { color: var(--ice); }
.statement .hl-e { color: var(--earth); }
.statement .word { display: inline-block; }

/* ============ Work index (project rows) ============ */
.work-list { border-top: 1px solid var(--line); margin-top: 3rem; }
.work-row {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: clamp(1rem, 3vw, 2.5rem);
  align-items: center;
  padding: 2rem 0.5rem;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  color: var(--text);
  overflow: hidden;
  transition: padding 0.35s var(--ease);
}
.work-row::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(124,196,216,0.07), rgba(166,139,102,0.05));
  transform: scaleY(0);
  transform-origin: bottom;
  transition: transform 0.4s var(--ease);
  z-index: -1;
}
.work-row:hover::before { transform: scaleY(1); }
.work-row:hover { padding-left: 1.4rem; }

.work-num {
  font-family: "Space Mono", monospace;
  font-size: 0.75rem;
  color: var(--ice-deep);
}
.work-title {
  font-family: "Sora", sans-serif;
  font-weight: 700;
  font-size: clamp(1.3rem, 3.2vw, 2.2rem);
  letter-spacing: -0.02em;
  transition: color 0.25s;
}
.work-row:hover .work-title { color: var(--ice); }
.work-tag {
  font-family: "Space Mono", monospace;
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--dim);
}
.work-arrow {
  width: 34px; height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  display: grid;
  place-items: center;
  transition: background 0.3s, border-color 0.3s, transform 0.35s var(--ease);
}
.work-arrow svg { width: 15px; height: 15px; stroke: currentColor; }
.work-row:hover .work-arrow {
  background: var(--ice);
  border-color: var(--ice);
  color: var(--bg);
  transform: rotate(45deg);
}
.work-desc {
  grid-column: 2 / -1;
  margin: 0.4rem 0 0;
  color: var(--dim);
  font-size: 0.95rem;
  max-width: 62ch;
}

/* ============ Equation moment ============ */
.eq-moment {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background:
    radial-gradient(700px 320px at 50% 120%, rgba(46, 110, 132, 0.25), transparent 70%),
    var(--bg-2);
  text-align: center;
}
.eq-moment .section { padding-top: 5rem; padding-bottom: 5rem; }
.eq-moment mjx-container { font-size: clamp(1.3rem, 3vw, 2rem) !important; color: var(--text); }
.eq-caption { color: var(--dim); font-size: 0.95rem; max-width: 52ch; margin: 1.4rem auto 0; }

/* ============ Prose (about page etc.) ============ */
.page .section.prose { max-width: 860px; }
.prose h2 {
  font-size: clamp(1.4rem, 2.6vw, 1.9rem);
  margin: 3rem 0 1rem;
  padding-top: 2rem;
  border-top: 1px solid var(--line);
}
.prose p, .prose li { color: #C4CFD6; }
.prose strong { color: var(--text); }
.prose a { text-decoration-color: var(--ice-deep); text-underline-offset: 3px; }
.prose code {
  background: var(--bg-2);
  border: 1px solid var(--line);
  padding: 0.15em 0.45em;
  border-radius: 6px;
  font-size: 0.85em;
}
.prose blockquote {
  margin: 2rem 0;
  padding: 0.2rem 1.4rem;
  border-left: 2px solid var(--ice-deep);
  color: var(--dim);
}
.prose img { max-width: 100%; border-radius: 12px; border: 1px solid var(--line); }

/* Timeline rows on about */
.timeline { border-top: 1px solid var(--line); margin-top: 1rem; }
.timeline-row {
  display: grid;
  grid-template-columns: 170px 1fr;
  gap: 1.5rem;
  padding: 1.1rem 0;
  border-bottom: 1px solid var(--line);
}
.timeline-row .when { font-family: "Space Mono", monospace; font-size: 0.75rem; color: var(--earth); letter-spacing: 0.1em; padding-top: 0.3rem; }
.timeline-row .what { color: #C4CFD6; }
.timeline-row .what b { color: var(--text); font-weight: 600; }

/* ============ 3D viewer & widgets ============ */
model-viewer {
  width: 100%;
  height: 500px;
  background: radial-gradient(600px 300px at 50% 0%, rgba(46,110,132,0.25), transparent 70%), var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  margin: 2rem 0;
  --poster-color: transparent;
}
.widget {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.8rem;
  margin: 2rem 0;
}
.widget h3 { font-size: 1.05rem; margin-bottom: 1rem; }
.widget input[type="range"] { width: 100%; accent-color: var(--ice); }
.widget .readout { font-family: "Space Mono", monospace; font-size: 0.85rem; color: var(--dim); margin-top: 0.8rem; }
.widget .readout b { color: var(--ice); font-weight: 400; }

/* ============ Footer ============ */
.footer { border-top: 1px solid var(--line); background: var(--bg-2); }
.footer-inner { max-width: var(--maxw); margin: 0 auto; padding: 5rem var(--pad) 2.5rem; }
.footer-cta {
  display: inline-flex;
  align-items: center;
  gap: 1.5rem;
  color: var(--text);
  text-decoration: none;
  font-family: "Sora", sans-serif;
  font-weight: 800;
  font-size: clamp(2.4rem, 7vw, 5.5rem);
  letter-spacing: -0.03em;
  text-transform: uppercase;
  transition: color 0.3s;
}
.footer-cta:hover { color: var(--ice); }
.footer-cta svg {
  width: clamp(2.2rem, 5vw, 4rem);
  height: clamp(2.2rem, 5vw, 4rem);
  transition: transform 0.35s var(--ease);
}
.footer-cta:hover svg { transform: translate(6px, -6px); }
.footer-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 4rem;
  padding-top: 1.6rem;
  border-top: 1px solid var(--line);
  font-size: 0.82rem;
  color: var(--dim);
}
.footer-links a {
  color: var(--dim);
  text-decoration: none;
  font-family: "Space Mono", monospace;
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-right: 1.6rem;
  transition: color 0.25s;
}
.footer-links a:hover { color: var(--ice); }
.footer-meta p { margin: 0; }

/* ============ Reveal helpers (animated by GSAP) ============ */
.w { display: inline-block; overflow: hidden; vertical-align: top; }
.w > span { display: inline-block; transform: translateY(115%); }
[data-scrub] .w, [data-scrub] .w > span { overflow: visible; transform: none; }
.reveal-up { opacity: 0; transform: translateY(28px); }
.gs-reveal { opacity: 0; transform: translateY(36px); }

/* If a CDN script failed to load, force everything visible */
.no-anim .loader { display: none; }
.no-anim .reveal-up, .no-anim .gs-reveal { opacity: 1; transform: none; }
.no-anim .cursor-dot, .no-anim .cursor-ring { display: none; }

/* ============ No-JS / reduced motion ============ */
@media (prefers-reduced-motion: reduce) {
  .loader { display: none; }
  .grain { animation: none; }
  .marquee-track { animation: none; }
  .scroll-hint::after { animation: none; }
  .reveal-up, .gs-reveal { opacity: 1; transform: none; }
  .split-lines .line > span { transform: none; }
}

@media (max-width: 720px) {
  .nav-links a span { display: none; }
  .work-row { grid-template-columns: auto 1fr auto; }
  .work-tag { display: none; }
  .work-desc { grid-column: 2 / -1; }
  .timeline-row { grid-template-columns: 1fr; gap: 0.2rem; }
  .scroll-hint { display: none; }
}
