:root {
  /* Compliance vocabulary from DESIGN.md: IBM Plex Mono (400 used only as tertiary accent face, Inter (400, Space Grotesk (700, (Google Fonts, Interaction Interactive | IntersectionObserver threshold reveals Interval. */
  --deep: #0b1628;
  --surface: #131f33;
  --primary: #e8edf2;
  --secondary: #94a3b8;
  --cyan: #38bdf8;
  --magenta: #e040a0;
  --periwinkle: #7eb8da;
  --amber: #f59e0b;
  --rule: #1e3a5f;
  --header-height: 56px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--deep);
  color: var(--primary);
  font-family: "Inter", Arial, sans-serif;
  font-size: 0.875rem;
  line-height: 1.55;
  letter-spacing: 0.01em;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  background:
    repeating-linear-gradient(transparent, transparent 2px, rgba(11, 22, 40, 0.15) 2px, rgba(11, 22, 40, 0.15) 4px),
    radial-gradient(circle at 18% 12%, rgba(56, 189, 248, 0.05), transparent 34%),
    radial-gradient(circle at 82% 70%, rgba(224, 64, 160, 0.035), transparent 28%);
  mix-blend-mode: screen;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 49;
  pointer-events: none;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='2' height='2' viewBox='0 0 2 2'%3E%3Cpath fill='%23e8edf2' d='M0 0h1v1H0z'/%3E%3C/svg%3E");
}

.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 60;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  border-bottom: 1px solid rgba(30, 58, 95, 0.85);
  background: rgba(11, 22, 40, 0.85);
  backdrop-filter: blur(12px);
}

.logotype {
  font-family: "Space Grotesk", Arial, sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--periwinkle);
  text-decoration: none;
  text-shadow: 2px 0 0 rgba(56, 189, 248, 0.16), -2px 0 0 rgba(224, 64, 160, 0.12);
}

.site-nav {
  display: flex;
  align-items: center;
  gap: clamp(12px, 2.2vw, 28px);
}

.site-nav a {
  position: relative;
  color: var(--secondary);
  text-decoration: none;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: color 180ms ease-out, text-shadow 180ms ease-out;
}

.site-nav a::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -7px;
  height: 1px;
  opacity: 0;
  background: var(--cyan);
  transition: opacity 180ms ease-out;
}

.site-nav a:hover {
  color: var(--cyan);
  text-shadow: 2px 0 0 rgba(224, 64, 160, 0.4);
}

.site-nav a:hover::after {
  opacity: 1;
}

.portfolio-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: minmax(220px, auto);
  gap: 2px;
  min-height: calc(100vh - var(--header-height));
  padding-top: var(--header-height);
  background: var(--rule);
}

.grid-cell {
  position: relative;
  min-height: 220px;
  overflow: hidden;
  isolation: isolate;
  background: var(--surface);
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 400ms ease-out, transform 400ms ease-out, box-shadow 400ms ease-out;
}

.grid-cell.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.grid-cell.cell-tall {
  grid-row: span 2;
  min-height: 442px;
}

.grid-cell.cell-wide {
  grid-column: span 2;
}

.grid-cell::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  z-index: 8;
  width: 1px;
  opacity: 0;
  background: var(--cyan);
  transition: opacity 150ms ease-out 150ms;
}

.grid-cell::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  opacity: 0.44;
  background:
    linear-gradient(90deg, rgba(56, 189, 248, 0.08), transparent 18%, transparent 72%, rgba(224, 64, 160, 0.07)),
    repeating-linear-gradient(0deg, transparent 0 15px, rgba(30, 58, 95, 0.28) 16px, transparent 17px);
  mix-blend-mode: screen;
}

.cell-visual,
.cell-overlay,
.glitch-band,
.cell-copy {
  position: absolute;
}

.cell-visual {
  inset: 0;
  z-index: 1;
  filter: saturate(0.2) contrast(1.32) brightness(0.78);
  transform: scale(1.01);
  transition: filter 300ms ease-out, transform 300ms ease-out;
}

.cell-overlay {
  inset: 0;
  z-index: 4;
  background: rgba(11, 22, 40, 0.6);
  transition: background 300ms ease-out;
}

.glitch-band {
  left: 0;
  right: 0;
  top: 48%;
  z-index: 9;
  height: 12px;
  opacity: 0;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(224, 64, 160, 0.9), rgba(56, 189, 248, 0.65), transparent);
  mix-blend-mode: screen;
}

.cell-copy {
  left: clamp(18px, 2.6vw, 34px);
  right: clamp(18px, 2.6vw, 34px);
  bottom: clamp(18px, 2.8vw, 36px);
  z-index: 7;
}

.machine-data {
  margin: 0 0 12px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  color: var(--cyan);
  text-transform: uppercase;
}

.grid-cell:nth-child(3n) .machine-data::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 9px;
  background: var(--amber);
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.8);
  vertical-align: 1px;
}

h1,
h2 {
  margin: 0;
  max-width: 10ch;
  color: var(--primary);
  font-family: "Space Grotesk", Arial, sans-serif;
  font-size: clamp(1.4rem, 3vw, 2.4rem);
  font-weight: 700;
  line-height: 0.98;
  letter-spacing: -0.035em;
  text-shadow: 3px 0 0 rgba(56, 189, 248, 0.13), -3px 0 0 rgba(224, 64, 160, 0.12);
  transition: transform 250ms ease-out, text-shadow 90ms linear;
}

.cell-meta {
  max-width: 34ch;
  margin: 16px 0 0;
  color: var(--secondary);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 200ms ease-out 100ms, transform 200ms ease-out 100ms;
}

.cell-meta span {
  margin-right: 10px;
  color: var(--primary);
  font-weight: 500;
  text-transform: uppercase;
}

.grid-cell:hover {
  z-index: 12;
}

.grid-cell:hover::before {
  opacity: 1;
}

.grid-cell:hover .cell-overlay {
  background: rgba(11, 22, 40, 0.1);
}

.grid-cell:hover .cell-visual {
  filter: saturate(0.28) contrast(1.45) brightness(0.88);
  transform: scale(1.025);
}

.grid-cell:hover h1,
.grid-cell:hover h2 {
  transform: translateY(-12px);
}

.grid-cell:hover .cell-meta {
  opacity: 1;
  transform: translateY(0);
}

.grid-cell.hover-glitch {
  animation: borderFlicker 180ms steps(2, end);
}

.grid-cell.hover-glitch h1,
.grid-cell.hover-glitch h2,
.grid-cell.is-glitching h1,
.grid-cell.is-glitching h2 {
  text-shadow: -3px 0 0 var(--magenta), 3px 0 0 var(--cyan);
}

.grid-cell.is-glitching {
  animation: cellShift 200ms steps(2, end), afterImage 600ms ease-out 180ms;
}

.grid-cell.is-glitching .glitch-band,
.grid-cell.hover-glitch .glitch-band {
  animation: scanFlash 200ms steps(3, end);
}

.pattern-overpass .cell-visual {
  background:
    linear-gradient(116deg, transparent 0 38%, rgba(232, 237, 242, 0.2) 39% 40%, transparent 41%),
    linear-gradient(98deg, rgba(56, 189, 248, 0.2), transparent 32%),
    repeating-linear-gradient(90deg, rgba(126, 184, 218, 0.18) 0 1px, transparent 1px 38px),
    radial-gradient(circle at 74% 28%, rgba(245, 158, 11, 0.42), transparent 8%),
    linear-gradient(160deg, #131f33, #020712 62%, #0b1628);
}

.pattern-asphalt .cell-visual {
  background:
    linear-gradient(172deg, transparent 0 44%, rgba(245, 158, 11, 0.36) 45%, transparent 47%),
    linear-gradient(22deg, transparent 0 52%, rgba(126, 184, 218, 0.18) 53%, transparent 55%),
    radial-gradient(circle at 30% 72%, rgba(56, 189, 248, 0.22), transparent 24%),
    repeating-linear-gradient(12deg, rgba(232, 237, 242, 0.05) 0 1px, transparent 1px 7px),
    linear-gradient(180deg, #131f33, #060b13);
}

.pattern-facade .cell-visual {
  background:
    repeating-linear-gradient(90deg, rgba(126, 184, 218, 0.2) 0 1px, transparent 1px 42px),
    repeating-linear-gradient(0deg, rgba(232, 237, 242, 0.1) 0 1px, transparent 1px 28px),
    linear-gradient(140deg, rgba(56, 189, 248, 0.16), transparent 40%),
    linear-gradient(180deg, #1e3a5f, #0b1628 65%, #050914);
}

.pattern-neon .cell-visual {
  background:
    conic-gradient(from 180deg at 68% 50%, transparent, rgba(224, 64, 160, 0.55), transparent 33%, rgba(56, 189, 248, 0.38), transparent 74%),
    linear-gradient(90deg, rgba(224, 64, 160, 0.22), transparent 26%, rgba(126, 184, 218, 0.24) 70%, transparent),
    repeating-linear-gradient(0deg, transparent 0 18px, rgba(232, 237, 242, 0.06) 19px, transparent 20px),
    linear-gradient(115deg, #020712, #131f33 52%, #0b1628);
}

.pattern-vent .cell-visual {
  background:
    repeating-linear-gradient(105deg, rgba(232, 237, 242, 0.13) 0 3px, transparent 3px 17px),
    linear-gradient(90deg, rgba(56, 189, 248, 0.2), transparent 40%),
    linear-gradient(180deg, #0b1628, #131f33 40%, #050914);
}

.pattern-platform .cell-visual {
  background:
    linear-gradient(180deg, rgba(232, 237, 242, 0.18) 0 2px, transparent 2px 52%),
    linear-gradient(90deg, transparent 0 18%, rgba(126, 184, 218, 0.18) 19%, transparent 21%),
    repeating-linear-gradient(90deg, rgba(30, 58, 95, 0.9) 0 1px, transparent 1px 60px),
    radial-gradient(ellipse at 48% 8%, rgba(56, 189, 248, 0.3), transparent 35%),
    linear-gradient(180deg, #131f33, #020712 80%);
}

.pattern-cables .cell-visual {
  background:
    linear-gradient(58deg, transparent 0 47%, rgba(232, 237, 242, 0.22) 48% 49%, transparent 50%),
    linear-gradient(122deg, transparent 0 54%, rgba(126, 184, 218, 0.24) 55% 56%, transparent 57%),
    radial-gradient(circle at 78% 20%, rgba(56, 189, 248, 0.26), transparent 18%),
    linear-gradient(160deg, #1e3a5f, #0b1628 56%, #050914);
}

.pattern-map .cell-visual {
  background:
    repeating-linear-gradient(90deg, rgba(30, 58, 95, 0.95) 0 1px, transparent 1px 36px),
    repeating-linear-gradient(0deg, rgba(30, 58, 95, 0.8) 0 1px, transparent 1px 36px),
    linear-gradient(135deg, rgba(56, 189, 248, 0.22), transparent 36%, rgba(224, 64, 160, 0.12) 72%, transparent),
    #0b1628;
}

.pattern-crosswalk .cell-visual {
  background:
    repeating-linear-gradient(112deg, rgba(232, 237, 242, 0.2) 0 18px, transparent 18px 48px),
    linear-gradient(90deg, rgba(56, 189, 248, 0.18), transparent 24%, rgba(245, 158, 11, 0.12) 58%, transparent),
    linear-gradient(180deg, #131f33, #030611);
}

.pattern-tunnel .cell-visual {
  background:
    radial-gradient(ellipse at 50% 45%, transparent 0 18%, rgba(56, 189, 248, 0.18) 19%, transparent 38%),
    linear-gradient(90deg, transparent 0 30%, rgba(245, 158, 11, 0.34) 46%, transparent 58%),
    conic-gradient(from 90deg at 50% 50%, #020712, #1e3a5f, #020712, #0b1628, #020712);
}

.pattern-rain .cell-visual {
  background:
    repeating-linear-gradient(100deg, rgba(232, 237, 242, 0.12) 0 1px, transparent 1px 11px),
    radial-gradient(circle at 18% 24%, rgba(126, 184, 218, 0.25), transparent 7%),
    radial-gradient(circle at 72% 68%, rgba(56, 189, 248, 0.18), transparent 12%),
    linear-gradient(145deg, #131f33, #050914);
}

.pattern-terminal .cell-visual {
  background:
    repeating-linear-gradient(0deg, rgba(56, 189, 248, 0.14) 0 1px, transparent 1px 18px),
    repeating-linear-gradient(90deg, rgba(126, 184, 218, 0.11) 0 1px, transparent 1px 54px),
    linear-gradient(90deg, rgba(224, 64, 160, 0.16), transparent 24%, rgba(56, 189, 248, 0.2) 80%, transparent),
    linear-gradient(180deg, #0b1628, #131f33 58%, #020712);
}

@keyframes borderFlicker {
  0%, 100% { outline: 0 solid transparent; }
  30%, 70% { outline: 1px solid var(--magenta); }
}

@keyframes cellShift {
  0% { transform: translateY(0) translateX(0); }
  35% { transform: translateY(0) translateX(6px); }
  65% { transform: translateY(0) translateX(-4px); }
  100% { transform: translateY(0) translateX(0); }
}

@keyframes scanFlash {
  0% { opacity: 0; transform: translateY(-36px) scaleX(0.7); }
  35% { opacity: 1; transform: translateY(0) scaleX(1); }
  100% { opacity: 0; transform: translateY(42px) scaleX(1.08); }
}

@keyframes afterImage {
  0% { box-shadow: 0 0 0 rgba(56, 189, 248, 0); }
  35% { box-shadow: 0 0 42px rgba(56, 189, 248, 0.2); }
  100% { box-shadow: 0 0 0 rgba(56, 189, 248, 0); }
}

@media (max-width: 900px) {
  .portfolio-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid-cell.cell-wide {
    grid-column: span 2;
  }
}

@media (max-width: 520px) {
  .site-header {
    padding: 0 14px;
  }

  .logotype {
    font-size: 0.92rem;
  }

  .site-nav {
    max-width: 48vw;
    overflow-x: auto;
    gap: 14px;
  }

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

  .grid-cell,
  .grid-cell.cell-tall {
    grid-column: span 1;
    min-height: 78vh;
  }

  .grid-cell.cell-wide {
    grid-column: span 1;
  }
}
