/* =========================================================
   Diggaj Niraula — portfolio
   A dawn-to-night traverse. Day palette is glacial haze,
   night palette is deep ink. JS lerps the four live tokens
   (--bg --fg --muted --line) as you scroll.
   ========================================================= */

/* ---------- 1. TOKENS ---------- */
:root {
  /* fixed palette */
  --haze:     #d9dedb;   /* day ground   */
  --ink:      #12171a;   /* day type     */
  --night:    #080c10;   /* night ground */
  --paper:    #eceeeb;   /* night type   */
  --copper:   #c2662f;   /* warm signal — carbon, conductors */
  --glacier:  #4a9aa8;   /* cold signal — hydro, data        */

  /* live tokens, overwritten by script.js */
  --bg:    #d9dedb;
  --fg:    #12171a;
  --muted: #5d6764;
  --line:  rgba(18,23,26,.16);
  --hinge: #8f4418;

  /* type */
  --sans: "Archivo", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Newsreader", ui-serif, Georgia, "Times New Roman", serif;

  /* scale — 1.25 minor third off 17px */
  --t--2: .72rem;
  --t--1: .855rem;
  --t-0:  1.0625rem;
  --t-1:  1.33rem;
  --t-2:  1.66rem;
  --t-3:  2.07rem;
  --t-4:  2.59rem;

  /* rhythm */
  --gut: clamp(1.25rem, 4.5vw, 3.5rem);
  --band: clamp(4.25rem, 10.5vh, 7.5rem);

  --edge-top: env(safe-area-inset-top, 0px);
  --edge-bot: env(safe-area-inset-bottom, 0px);

  color-scheme: dark light;
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: calc(4.5rem + var(--edge-top)); }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: var(--t-0);
  font-variation-settings: "wdth" 100, "wght" 400;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  transition: background-color .12s linear, color .12s linear;
}

img { max-width: 100%; height: auto; display: block; }

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

a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--copper);
  outline-offset: 3px;
  border-radius: 2px;
}

.skip {
  position: fixed; left: var(--gut); top: calc(.5rem + var(--edge-top));
  z-index: 80; padding: .5rem .85rem;
  background: var(--copper); color: #fff;
  font-size: var(--t--1); text-decoration: none;
  transform: translateY(-160%);
}
.skip:focus { transform: none; }


/* ---------- 2. THE 3D STAGE ---------- */
.stage {
  position: fixed; inset: 0;
  z-index: 0;
  pointer-events: none;
}
#terrain {
  width: 100%; height: 100%;
  display: block;
  opacity: 0;
  transition: opacity 1.4s ease .2s;
}
#terrain.is-live { opacity: 1; }

/* shown only if WebGL or the library is unavailable */
.stage__fallback {
  position: absolute; inset: 0;
  display: none;
  background:
    radial-gradient(120% 70% at 50% 108%, rgba(74,154,168,.35), transparent 60%),
    linear-gradient(180deg, transparent 40%, rgba(194,102,47,.18) 100%);
}
.stage__fallback.is-on { display: block; }

/* a little tooth so flat colour fields don't look plastic */
.grain {
  position: absolute; inset: -50%;
  opacity: .5;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.35'/%3E%3C/svg%3E");
}


/* ---------- 3. TOP RAIL ---------- */
.rail {
  position: fixed; top: 0; left: 0; right: 0;
  z-index: 60;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem;
  padding: calc(1rem + var(--edge-top)) var(--gut) 1rem;
  font-size: var(--t--1);
  mix-blend-mode: difference;
  color: #fff;
}
.rail__mark {
  display: inline-flex; align-items: center; gap: .55rem;
  text-decoration: none;
  font-variation-settings: "wdth" 88, "wght" 500;
  letter-spacing: .01em;
}
.rail__dot {
  width: .5rem; height: .5rem; border-radius: 50%;
  background: var(--copper);
  flex: none;
}
.rail__nav { display: flex; gap: clamp(.9rem, 2.4vw, 2rem); }
.rail__nav a {
  text-decoration: none;
  font-variation-settings: "wdth" 88, "wght" 400;
  opacity: .78;
  transition: opacity .2s;
}
.rail__nav a:hover { opacity: 1; }

@media (max-width: 34rem) {
  .rail__nav a:nth-child(3) { display: none; }
}


/* ---------- 4. ALTITUDE READOUT ---------- */
.altitude {
  position: fixed;
  right: var(--gut); bottom: calc(1.6rem + var(--edge-bot));
  z-index: 55;
  display: flex; align-items: flex-end; gap: .4rem;
  color: var(--muted);
  font-size: var(--t--2);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.altitude__num {
  font-size: var(--t-1);
  line-height: 1;
  font-variation-settings: "wdth" 76, "wght" 500;
  color: var(--fg);
}
.altitude__unit { padding-bottom: .1rem; }
.altitude__track {
  display: block; width: 1px; height: 4.5rem;
  margin-left: .5rem;
  background: var(--line);
  position: relative;
}
.altitude__track i {
  position: absolute; left: -1px; top: 0;
  width: 3px; height: 0%;
  background: var(--copper);
}
@media (max-width: 46rem) { .altitude { display: none; } }


/* ---------- 5. HERO ---------- */
.hero {
  position: relative; z-index: 10;
  min-height: 100svh;
  display: grid;
  grid-template-rows: 1fr auto;
  padding: calc(6rem + var(--edge-top)) var(--gut) calc(3.5rem + var(--edge-bot));
}
.hero__type { align-self: end; max-width: 60rem; }

.hero__name {
  margin: 0;
  font-size: clamp(3.1rem, 13vw, 9.5rem);
  line-height: .96;
  letter-spacing: -.035em;
  font-variation-settings: "wdth" 118, "wght" 600;
  text-transform: none;
}
.hero__name span { display: block; }
.hero__name span:last-child { padding-left: .06em; }

/* the load reveal: two lines rise into place, once */
.hero__name span {
  opacity: 0;
  transform: translateY(.34em);
  animation: rise .95s cubic-bezier(.16,.84,.34,1) forwards;
}
.hero__name span:nth-child(1) { animation-delay: .25s; }
.hero__name span:nth-child(2) { animation-delay: .38s; }

@keyframes rise { to { opacity: 1; transform: none; } }

.hero__line {
  max-width: 34ch;
  margin: 1.75rem 0 0;
  font-family: var(--serif);
  font-size: clamp(var(--t-0), 1.9vw, var(--t-1));
  line-height: 1.55;
  color: var(--muted);
  opacity: 0;
  animation: rise .9s cubic-bezier(.16,.84,.34,1) .58s forwards;
}

.hud {
  position: absolute;
  top: calc(6.5rem + var(--edge-top)); right: var(--gut);
  width: min(20rem, 46vw);
  display: grid; gap: .4rem;
  font-size: var(--t--2);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  opacity: 0;
  animation: fade 1.2s ease 1.1s forwards;
}
@keyframes fade { to { opacity: 1; } }

.hud__row {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: .45rem;
  padding-bottom: .4rem;
  border-bottom: 1px solid var(--line);
}
.hud__row span { flex: none; width: 5.2rem; }
.hud__row b {
  font-weight: 400;
  font-variation-settings: "wdth" 80, "wght" 500;
  color: var(--fg);
}
.hud__row i { font-style: normal; opacity: .6; }

@media (max-width: 46rem) { .hud { display: none; } }

.hero__cue {
  justify-self: start; align-self: end;
  width: 1px; height: 3.2rem;
  background: var(--line);
  position: relative; overflow: hidden;
  margin-top: 2.5rem;
}
.hero__cue i {
  position: absolute; inset: 0;
  background: var(--copper);
  transform: translateY(-100%);
  animation: drip 2.6s cubic-bezier(.6,0,.4,1) infinite 1.6s;
}
@keyframes drip {
  0%   { transform: translateY(-100%); }
  55%  { transform: translateY(0); }
  100% { transform: translateY(100%); }
}


/* ---------- 6. SECTION SHELL ---------- */
.section {
  position: relative; z-index: 10;
  padding: var(--band) var(--gut);
  max-width: 82rem;
  margin-inline: auto;
}

.h-section {
  margin: 0 0 clamp(2rem, 5vw, 3.5rem);
  font-size: var(--t-1);
  font-variation-settings: "wdth" 82, "wght" 500;
  letter-spacing: .005em;
  color: var(--muted);
  display: flex; align-items: center; gap: 1rem;
}
.h-section::after {
  content: ""; flex: 1; height: 1px; background: var(--line);
}


/* ---------- 7. ABOUT ---------- */
.section--about {
  display: grid;
  grid-template-columns: minmax(0, 15rem) minmax(0, 1fr);
  gap: clamp(2rem, 6vw, 5rem);
  align-items: start;
}
@media (max-width: 52rem) {
  .section--about { grid-template-columns: 1fr; }
}

.portrait { margin: 0; position: sticky; top: 7rem; }
.portrait img {
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  filter: grayscale(.25) contrast(1.04);
}
.portrait figcaption {
  margin-top: .65rem;
  font-size: var(--t--2);
  color: var(--muted);
}
@media (max-width: 52rem) {
  .portrait { position: static; max-width: 16rem; }
}

.about__body p {
  font-family: var(--serif);
  font-size: clamp(var(--t-0), 1.55vw, var(--t-1));
  line-height: 1.68;
  max-width: 62ch;
  margin: 0 0 1.35em;
}
.about__body p:first-of-type { margin-top: 0; }

.facts {
  margin: clamp(2rem, 5vw, 3rem) 0 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 1.4rem 2rem;
  border-top: 1px solid var(--line);
  padding-top: 1.5rem;
}
.facts div { display: grid; gap: .3rem; }
.facts dt { font-size: var(--t--2); color: var(--muted); }
.facts dd {
  margin: 0;
  font-size: var(--t--1);
  font-variation-settings: "wdth" 88, "wght" 500;
}


/* ---------- 8. DUSK HINGE ---------- */
.hinge {
  position: relative; z-index: 10;
  min-height: 112svh;
  display: grid; place-items: center;
  padding: var(--band) var(--gut);
  text-align: center;
}
.hinge__line {
  margin: 0;
  max-width: 24ch;
  font-size: clamp(1.7rem, 5.4vw, 4.1rem);
  line-height: 1.12;
  letter-spacing: -.02em;
  font-variation-settings: "wdth" 104, "wght" 500;
  color: var(--hinge);
  text-wrap: balance;
}


/* ---------- 9. RESEARCH ---------- */
.flagship {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: clamp(1.75rem, 5vw, 4rem);
  align-items: start;
}
@media (max-width: 56rem) { .flagship { grid-template-columns: 1fr; } }

.flagship__fig { margin: 0; }
.flagship__fig img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border: 1px solid var(--line);
}

.flagship__title {
  margin: 0 0 1rem;
  font-size: clamp(var(--t-2), 3.6vw, var(--t-4));
  line-height: 1.06;
  letter-spacing: -.022em;
  font-variation-settings: "wdth" 96, "wght" 600;
}
.flagship__body p {
  font-family: var(--serif);
  font-size: var(--t-0);
  line-height: 1.66;
  max-width: 58ch;
  margin: 0 0 1.15em;
}
.flagship__body .lede {
  font-family: var(--sans);
  font-size: var(--t--1);
  line-height: 1.55;
  color: var(--glacier);
  border-left: 2px solid var(--glacier);
  padding-left: .9rem;
  margin-bottom: 1.5em;
}

.threads {
  list-style: none;
  margin: clamp(3rem, 7vw, 5rem) 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 0;
  border-top: 1px solid var(--line);
}
.threads li {
  padding: 1.75rem 1.5rem 1.75rem 0;
  border-bottom: 1px solid var(--line);
}
.threads h4 {
  margin: 0 0 .5rem;
  font-size: var(--t-0);
  font-variation-settings: "wdth" 92, "wght" 600;
}
.threads p {
  margin: 0;
  font-size: var(--t--1);
  line-height: 1.55;
  color: var(--muted);
  max-width: 34ch;
}


/* ---------- 10. WORK PLATES ---------- */
.plates { display: grid; gap: clamp(3rem, 8vw, 6rem); }

.plate { perspective: 1100px; }
.plate--offset { justify-self: end; }
@media (min-width: 62rem) {
  .plate { width: 78%; }
  .plate--offset { width: 72%; }
}

.plate__inner {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: clamp(1.25rem, 3vw, 2.5rem);
  align-items: center;
  transform-style: preserve-3d;
  transition: transform .5s cubic-bezier(.2,.7,.3,1);
  will-change: transform;
}
@media (max-width: 46rem) {
  .plate__inner { grid-template-columns: 1fr; }
}

.plate__fig { margin: 0; overflow: hidden; }
.plate__fig img {
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  transform: scale(1.02);
  transition: transform .7s cubic-bezier(.2,.7,.3,1), filter .5s;
  filter: saturate(.85);
}
.plate:hover .plate__fig img { transform: scale(1.06); filter: saturate(1); }

.plate__meta { transform: translateZ(45px); }
.plate__meta h3 {
  margin: 0 0 .7rem;
  font-size: var(--t-2);
  line-height: 1.12;
  letter-spacing: -.018em;
  font-variation-settings: "wdth" 94, "wght" 600;
}
.plate__meta p {
  margin: 0 0 .8em;
  font-size: var(--t--1);
  line-height: 1.6;
  color: var(--muted);
  max-width: 38ch;
}
.plate__tags {
  font-size: var(--t--2);
  color: var(--glacier);
  margin-bottom: 0;
}


/* ---------- 11. PATH ---------- */
.path {
  list-style: none;
  margin: 0; padding: 0;
  counter-reset: none;
  border-top: 1px solid var(--line);
}
.path li {
  display: grid;
  grid-template-columns: 6.5rem minmax(0, 1fr);
  gap: clamp(1rem, 3vw, 2.5rem);
  padding: 1.9rem 0;
  border-bottom: 1px solid var(--line);
  align-items: baseline;
}
@media (max-width: 40rem) {
  .path li { grid-template-columns: 1fr; gap: .5rem; }
}
.path__when {
  font-size: var(--t--1);
  font-variant-numeric: tabular-nums;
  font-variation-settings: "wdth" 76, "wght" 500;
  color: var(--copper);
}
.path__what h3 {
  margin: 0 0 .4rem;
  font-size: var(--t-1);
  line-height: 1.2;
  font-variation-settings: "wdth" 92, "wght" 600;
}
.path__what p {
  margin: 0;
  font-family: var(--serif);
  font-size: var(--t--1);
  line-height: 1.6;
  color: var(--muted);
  max-width: 56ch;
}
.path__what em { color: var(--copper); font-style: italic; }


/* ---------- 12. FIELD ---------- */
.field {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: minmax(8rem, auto);
  gap: clamp(.5rem, 1.6vw, 1.1rem);
}
.field figure { margin: 0; }
.field img { width: 100%; height: 100%; object-fit: cover; }
.field figcaption {
  margin-top: .5rem;
  font-size: var(--t--2);
  color: var(--muted);
}
.field__a { grid-column: span 2; }
.field__b { grid-column: span 1; margin-top: 2.5rem; }
.field__c { grid-column: span 1; }
.field__d { grid-column: span 2; margin-top: -1.5rem; }

@media (max-width: 46rem) {
  .field { grid-template-columns: repeat(2, 1fr); }
  .field__a, .field__d { grid-column: span 2; }
  .field__b, .field__c { margin-top: 0; }
  .field__d { margin-top: 0; }
}


/* ---------- 13. CONTACT ---------- */
.section--contact { padding-bottom: calc(var(--band) * 1.2); }

.contact__head {
  margin: 0 0 1rem;
  font-size: clamp(2.4rem, 9vw, 6.5rem);
  line-height: .95;
  letter-spacing: -.035em;
  font-variation-settings: "wdth" 112, "wght" 600;
}
.contact__note {
  margin: 0 0 clamp(2.5rem, 6vw, 4rem);
  max-width: 40ch;
  font-family: var(--serif);
  font-size: var(--t-1);
  line-height: 1.55;
  color: var(--muted);
}

.links { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.links a {
  display: flex; align-items: baseline; gap: 1rem;
  padding: 1.35rem 0;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  position: relative;
}
.links span {
  flex: none; width: 10rem;
  font-size: var(--t--1);
  color: var(--muted);
}
.links b {
  font-weight: 400;
  font-size: clamp(var(--t-1), 3vw, var(--t-2));
  font-variation-settings: "wdth" 92, "wght" 500;
  letter-spacing: -.012em;
  transition: color .25s, transform .35s cubic-bezier(.2,.7,.3,1);
}
.links a:hover b { color: var(--copper); transform: translateX(.35rem); }

@media (max-width: 34rem) {
  .links a { flex-direction: column; gap: .25rem; }
  .links span { width: auto; }
}


/* ---------- 14. FOOT ---------- */
.foot {
  position: relative; z-index: 10;
  display: flex; justify-content: space-between; gap: 1rem;
  padding: 1.5rem var(--gut) calc(1.5rem + var(--edge-bot));
  border-top: 1px solid var(--line);
  font-size: var(--t--2);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}


/* ---------- 15. IMAGE PLACEHOLDER STATE ---------- */
img[data-missing] {
  filter: none;
  outline: 1px dashed var(--line);
  outline-offset: -1px;
}


/* ---------- 16. REDUCED MOTION ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
  .hero__name span, .hero__line, .hud { opacity: 1; transform: none; }
}
