:root {
  --graphite: #0a0d12;
  --graphite-2: #0d1117;
  --panel: rgba(255, 255, 255, 0.018);
  --panel-hover: rgba(127, 176, 201, 0.05);
  --hair: rgba(255, 255, 255, 0.09);
  --hair-2: rgba(255, 255, 255, 0.045);
  --text: #ecebe6;          /* warm white */
  --text-soft: #9aa4b0;     /* muted slate */
  --muted: #5d6874;
  --accent: #7fb0c9;        /* desaturated icy blue */
  --accent-dim: rgba(127, 176, 201, 0.45);
  --sans: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --maxw: 1080px;
  --pad: clamp(1.25rem, 5vw, 3rem);
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--graphite);
  color: var(--text);
  font-family: var(--sans);
  font-weight: 300;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

::selection { background: var(--accent-dim); color: #061018; }

/* Coordinate-grid background */
.grid-bg {
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(80rem 50rem at 70% -10%, rgba(127, 176, 201, 0.06), transparent 60%),
    linear-gradient(180deg, var(--graphite-2), var(--graphite) 55%);
}
.grid-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--hair-2) 1px, transparent 1px),
    linear-gradient(90deg, var(--hair-2) 1px, transparent 1px);
  background-size: 88px 88px;
  mask-image: radial-gradient(130% 100% at 50% 0%, #000 35%, transparent 82%);
  -webkit-mask-image: radial-gradient(130% 100% at 50% 0%, #000 35%, transparent 82%);
}

/* Corner crosshair ticks (technical-drawing accent) */
.crosshair {
  position: fixed;
  width: 14px;
  height: 14px;
  z-index: -1;
  pointer-events: none;
}
.crosshair::before, .crosshair::after {
  content: "";
  position: absolute;
  background: var(--accent-dim);
}
.crosshair::before { left: 6px; top: 0; width: 1px; height: 14px; }
.crosshair::after { top: 6px; left: 0; height: 1px; width: 14px; }
.crosshair--tl { left: calc(var(--pad) - 7px); top: calc(var(--pad) - 7px); }
.crosshair--br { right: calc(var(--pad) - 7px); bottom: calc(var(--pad) - 7px); }
@media (max-width: 640px) { .crosshair { display: none; } }

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 1.1rem var(--pad);
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
  border-bottom: 1px solid var(--hair-2);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  color: var(--text);
}
.brand-mark { width: 22px; height: 22px; color: var(--accent); }
.brand-word {
  font-family: var(--mono);
  font-size: 0.9rem;
  letter-spacing: 0.22em;
  font-weight: 500;
}
.nav { display: flex; gap: clamp(1rem, 3vw, 2rem); }
.nav a {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-soft);
  text-decoration: none;
  transition: color 0.18s ease;
}
.nav a:hover { color: var(--accent); }
@media (max-width: 520px) { .nav a:nth-child(2), .nav a:nth-child(3) { display: none; } }

/* Shared section frame */
main { max-width: var(--maxw); margin: 0 auto; padding: 0 var(--pad); }
section { padding: clamp(3.5rem, 9vw, 7rem) 0; }

.section-head {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: clamp(2rem, 5vw, 3.5rem);
}
.section-index {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  color: var(--accent);
}
.section-title {
  margin: 0;
  font-size: clamp(1.1rem, 2.5vw, 1.35rem);
  font-weight: 500;
  letter-spacing: -0.01em;
}
.section-rule {
  flex: 1;
  height: 1px;
  background: var(--hair);
  align-self: center;
}

/* HERO */
.hero {
  position: relative;
  padding-top: clamp(4.5rem, 12vw, 9rem);
  padding-bottom: clamp(4.5rem, 12vw, 8rem);
}
.hero-plot {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  opacity: 0.5;
}
.plot-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.2;
  opacity: 0.55;
  stroke-dasharray: 2400;
  stroke-dashoffset: 2400;
  animation: draw 3s ease forwards 0.2s;
}
.plot-nodes circle { fill: var(--accent); opacity: 0; animation: fade 0.5s ease forwards 2.4s; }

.meta-line {
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  color: var(--text-soft);
  text-transform: uppercase;
  margin: 0 0 1.6rem;
}
.meta-line .tick { color: var(--accent); }
.meta-line .sep { color: var(--muted); margin: 0 0.5rem; }

h1 {
  margin: 0;
  font-size: clamp(3.2rem, 13vw, 8.5rem);
  font-weight: 600;
  line-height: 0.92;
  letter-spacing: -0.04em;
}
.hero-sub {
  margin: 1.2rem 0 0;
  font-size: clamp(1.2rem, 3.5vw, 1.9rem);
  font-weight: 300;
  color: var(--text);
  letter-spacing: -0.01em;
}
.hero-lede {
  margin: 1.6rem 0 0;
  max-width: 44ch;
  color: var(--text-soft);
  font-size: clamp(1rem, 2.2vw, 1.12rem);
}

/* WORK / case studies */
.case {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: clamp(1.5rem, 5vw, 4rem);
  align-items: center;
  padding: clamp(2rem, 5vw, 3.5rem) 0;
  border-top: 1px solid var(--hair);
}
.case:last-of-type { border-bottom: 1px solid var(--hair); }
.case--rev .case-text { order: 2; }
.case--rev .case-figure { order: 1; }
@media (max-width: 760px) {
  .case { grid-template-columns: 1fr; }
  .case--rev .case-text { order: 1; }
  .case--rev .case-figure { order: 2; }
}

.case-head {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.case-no {
  font-family: var(--mono);
  font-size: 0.9rem;
  color: var(--accent);
  padding-top: 0.35rem;
}
.case-name {
  margin: 0;
  font-size: clamp(1.7rem, 4.5vw, 2.5rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1;
}
.case-domain {
  margin: 0.5rem 0 0;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.case-blurb {
  margin: 0;
  color: var(--text-soft);
  max-width: 52ch;
  font-size: 1.02rem;
}
.case-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  margin: 1.75rem 0;
  background: var(--hair-2);
  border: 1px solid var(--hair-2);
}
.case-stats > div {
  background: var(--graphite);
  padding: 0.75rem 0.85rem;
}
.case-stats dt {
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.25rem;
}
.case-stats dd {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--text);
}
@media (max-width: 400px) { .case-stats { grid-template-columns: repeat(2, 1fr); } }

.case-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--mono);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s ease;
}
.case-link:hover { border-color: var(--accent-dim); }
.case-link .arrow { transition: transform 0.2s ease; }
.case-link:hover .arrow { transform: translate(2px, -2px); }

/* Schematic figures */
.case-figure { width: 100%; }
.schematic {
  margin: 0;
  border: 1px solid var(--hair);
  border-radius: 6px;
  background:
    linear-gradient(var(--hair-2) 1px, transparent 1px) 0 0 / 100% 24px,
    var(--panel);
  padding: 1rem 1rem 0.6rem;
}
.schematic svg { width: 100%; height: auto; display: block; }
.schematic figcaption {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 0.75rem 0.2rem 0.4rem;
  border-top: 1px solid var(--hair-2);
  margin-top: 0.5rem;
}
.schematic text {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  fill: var(--text-soft);
}
.sch-links path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1;
  opacity: 0.5;
}
.sch-src circle, .sch-ends circle { fill: var(--accent); }
.sch-flow rect { fill: none; stroke: var(--text-soft); stroke-width: 1; }
.sch-flow text { fill: var(--text); }
.hub-ring { fill: none; stroke: var(--accent); stroke-width: 1.4; }
.hub-dot { fill: var(--accent); }
.hub-label { fill: var(--accent); }

/* Line-draw animation for schematics when revealed */
.schematic .sch-links path {
  stroke-dasharray: 320;
  stroke-dashoffset: 320;
}
.reveal.is-visible .schematic .sch-links path {
  animation: draw 1.4s ease forwards;
}
.reveal.is-visible .schematic .sch-links path:nth-child(2) { animation-delay: 0.12s; }
.reveal.is-visible .schematic .sch-links path:nth-child(3) { animation-delay: 0.24s; }
.reveal.is-visible .schematic .sch-links path:nth-child(4) { animation-delay: 0.36s; }
.reveal.is-visible .schematic .sch-links path:nth-child(5) { animation-delay: 0.48s; }

/* LAB */
.lab-intro { margin: 0 0 2rem; color: var(--text-soft); }
.lab-list { list-style: none; margin: 0; padding: 0; }
.lab-list li {
  display: grid;
  grid-template-columns: 5rem 1fr;
  gap: 0.5rem 1.5rem;
  align-items: baseline;
  padding: 1.1rem 0;
  border-top: 1px solid var(--hair-2);
}
.lab-list li:last-child { border-bottom: 1px solid var(--hair-2); }
.lab-key {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  color: var(--accent);
}
.lab-name { font-size: 1.05rem; font-weight: 400; }
.lab-desc { grid-column: 2; color: var(--muted); font-size: 0.9rem; }

/* ABOUT */
.about-body {
  margin: 0;
  max-width: 62ch;
  font-size: clamp(1.15rem, 2.6vw, 1.5rem);
  font-weight: 300;
  line-height: 1.55;
  color: var(--text);
}

/* CONTACT */
.contact-email {
  display: inline-block;
  font-size: clamp(1.8rem, 7vw, 3.6rem);
  font-weight: 500;
  letter-spacing: -0.03em;
  color: var(--text);
  text-decoration: none;
  transition: color 0.2s ease;
}
.contact-email:hover { color: var(--accent); }

/* Footer */
.foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 2rem 0 3rem;
  border-top: 1px solid var(--hair);
  color: var(--muted);
  font-size: 0.8rem;
}
.foot-coord { font-family: var(--mono); letter-spacing: 0.06em; }
@media (max-width: 480px) { .foot-coord { display: none; } }

/* Reveal on scroll */
.reveal {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.7s ease, transform 0.7s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.reveal.is-visible { opacity: 1; transform: none; }

/* Keyframes */
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes fade { to { opacity: 0.9; } }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .reveal { opacity: 1; transform: none; }
  .plot-line { stroke-dashoffset: 0; }
  .plot-nodes circle { opacity: 0.9; }
  .schematic .sch-links path { stroke-dashoffset: 0; }
}
