:root {
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --bg: #020202;
  --ink: #f1f1f1;
  --dim: rgba(241, 241, 241, 0.62);
  --line: rgba(241, 241, 241, 0.18);
  --card: rgba(9, 9, 9, 0.94);
  --paper: #eeeeee;
  --accent: #ff2d55;
  --accent-contrast: #21f1ff;
  --hover-dim: rgba(245, 245, 245, 0.7);
  --glitch-red: rgba(255, 45, 85, 0.72);
  --glitch-cyan: rgba(33, 241, 255, 0.58);
  --glitch-shadow: 1px 0 var(--glitch-red), -1px 0 var(--glitch-cyan);
  --card-static:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.055) 0 1px, transparent 1px 4px),
    linear-gradient(90deg, rgba(255, 45, 85, 0.08), transparent 22%, rgba(33, 241, 255, 0.07));
  --pin-shadow:
    0 2px 0 rgba(244, 244, 244, 0.08),
    0 22px 52px rgba(0, 0, 0, 0.58);
  --pin-shadow-lift:
    0 0 0 1px rgba(255, 45, 85, 0.38),
    0 28px 70px rgba(0, 0, 0, 0.72);
  --shadow:
    0 16px 34px rgba(0, 0, 0, 0.64),
    0 3px 8px rgba(0, 0, 0, 0.5);
  --shadow-lift:
    0 30px 56px rgba(0, 0, 0, 0.78),
    0 6px 14px rgba(0, 0, 0, 0.62);
  --grain-opacity: 0.55;
  --photo-filter: none;
  --pile-photo-filter: none;
  --pile-photo-filter-active: contrast(1.08) brightness(1.04) saturate(1.04);
  --footer-ink: var(--ink);
  --pile-headroom: clamp(76px, 7vw, 136px);
  --pile-height: clamp(640px, 68vw, 940px);
  --pile-lift: clamp(-520px, -32vw, -360px);
  --pile-reveal-scroll: clamp(620px, 52vh, 820px);
  --pile-sticky-top: 0px;
  --pile-view-scale: 0.96;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  overflow-x: clip;
}

/* VHS / CRT shell */

body {
  isolation: isolate;
  position: relative;
  margin: 0;
  background: var(--bg);
  background-image:
    linear-gradient(180deg, rgba(241, 241, 241, 0.035), transparent 26rem),
    linear-gradient(180deg, #050505, #080808 46%, #020202);
  color: var(--ink);
  font-family: var(--font-mono);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}

body::before,
body::after {
  content: "";
  position: fixed;
  pointer-events: none;
}

body::before {
  z-index: 0;
  inset: 0;
  background:
    repeating-linear-gradient(0deg, rgba(241, 241, 241, 0.035) 0 1px, transparent 1px 4px),
    linear-gradient(180deg, rgba(241, 241, 241, 0.035), transparent 34%, rgba(0, 0, 0, 0.18));
  mix-blend-mode: screen;
  opacity: 0.26;
}

body::after {
  z-index: 0;
  inset: -18vh -18vw;
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.05' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.72 0 0 0 0 0.72 0 0 0 0 0.72 0 0 0 0.14 0'/%3E%3C/filter%3E%3Crect width='220' height='220' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 220px 220px;
  mix-blend-mode: screen;
  opacity: 0.22;
  animation: vhs-noise-shift 0.72s steps(2, end) infinite;
}

.wrap {
  position: relative;
  z-index: 2;
  width: min(1120px, calc(100% - 48px));
  margin: 0 auto;
  pointer-events: none;
}

a {
  color: var(--ink);
}

.wrap a {
  pointer-events: auto;
}

::selection {
  background: var(--accent);
  color: var(--bg);
}

.mono {
  font-family: var(--font-mono);
}

a:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 4px;
}

/* Confession — тишина */

.confession {
  padding: 11vh 0 14vh;
}

.confession p {
  margin: 0 0 1.15em;
  font-size: clamp(1.08rem, 1.85vw, 1.74rem);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.01em;
  max-width: 40ch;
  text-shadow: var(--glitch-shadow);
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

.confession .dim {
  color: var(--dim);
  font-size: 0.88rem;
  font-weight: 500;
  line-height: 1.5;
  max-width: 58ch;
  text-shadow: none;
  text-transform: none;
  overflow-wrap: anywhere;
}

.confession a {
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
  text-decoration-color: var(--dim);
}

.confession a:hover {
  color: var(--accent);
  text-decoration-color: var(--accent);
}

/* Labels */

.label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--dim);
  margin: 0 0 18px;
}

/* Grown — структура */

.grown {
  padding: 0 0 clamp(40px, 6vh, 70px);
}

.projects {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: stretch;
  gap: clamp(18px, 2.2vw, 30px);
}

.proj,
.pile a {
  overflow: hidden;
  isolation: isolate;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 2px;
  box-shadow: var(--pin-shadow);
}

.proj::after,
.pile a::after {
  content: "";
  position: absolute;
  z-index: 4;
  inset: 0;
  background: var(--card-static);
  mix-blend-mode: screen;
  opacity: 0.2;
  pointer-events: none;
  transition: opacity 0.16s ease;
}

.proj {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 100%;
  color: var(--ink);
  text-decoration: none;
  transform: none;
  transition: background 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.proj img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  height: auto;
  object-fit: cover;
  border-bottom: 1px solid var(--line);
  filter: var(--photo-filter);
  transform-origin: center;
  transition: filter 0.16s ease, transform 0.18s ease;
}

.proj-meta {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: baseline;
  gap: 12px;
  padding: 18px 16px 0;
}

.num {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.18em;
  color: var(--dim);
}

.name {
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.25;
  text-shadow: var(--glitch-shadow);
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

.what {
  display: block;
  flex: 1;
  padding: 12px 16px 20px;
  color: var(--dim);
  font-size: 0.86rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.open {
  display: block;
  padding: 0 16px 16px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  text-shadow: var(--glitch-shadow);
  overflow-wrap: anywhere;
}

.proj:hover {
  background: #101015;
  border-color: var(--ink);
  box-shadow: var(--pin-shadow-lift);
  color: var(--ink);
  transform: translateY(-6px);
}

.proj:hover .name {
  color: var(--ink);
}

.proj:hover .num,
.proj:hover .what {
  color: var(--hover-dim);
}

.proj:hover .open {
  color: var(--accent-contrast);
}

.proj:hover::after {
  opacity: 0.22;
}

.proj:hover img {
  filter: var(--pile-photo-filter-active);
  transform: scale(1.025) translate3d(1px, -1px, 0);
}

@media (max-width: 899px) {
  .projects {
    grid-template-columns: 1fr;
  }
}

/* Pile — хаос */

.pile-zone {
  position: relative;
  z-index: 1;
  height: calc(var(--pile-height) + var(--pile-headroom) + var(--pile-reveal-scroll));
  margin-top: var(--pile-lift);
}

.pile {
  position: sticky;
  top: var(--pile-sticky-top);
  width: 100%;
  height: calc(var(--pile-height) + var(--pile-headroom));
  overflow: visible;
  perspective: 920px;
  transform-style: preserve-3d;
  transform: scale(var(--pile-view-scale));
  transform-origin: center top;
  touch-action: manipulation;
}

.pile::before {
  content: "";
  position: absolute;
  inset: -40px;
  z-index: 56;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.54);
  opacity: 0;
  transition: opacity 0.12s ease;
}

.pile.has-focused::before {
  opacity: 1;
}

.pile a {
  position: absolute;
  left: var(--l);
  top: calc(var(--t) + var(--pile-headroom));
  width: clamp(min(var(--w), 30vw), 12vw, 32vw);
  transform: rotate(var(--r)) scale(var(--depth-scale, 1));
  z-index: var(--z);
  display: block;
  margin: 0;
  padding: 0;
  cursor: zoom-in;
  will-change: transform;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.14s ease;
}

.pile a.is-hovered {
  z-index: 50;
  border-color: var(--ink);
  transform: translateY(-10px) rotate(0deg) scale(1.06);
  box-shadow: var(--pin-shadow-lift);
}

.pile img {
  width: 100%;
  display: block;
  height: auto;
  filter: var(--pile-photo-filter);
  transition: filter 0.16s ease;
}

.pile a.is-hovered img {
  filter: var(--pile-photo-filter-active);
}

.pile a.is-focused img {
  filter: var(--pile-photo-filter-active);
  transform: none;
}

/* зерно поверх кучи */

.pile::after {
  content: "";
  position: absolute;
  inset: -40px;
  z-index: 55;
  pointer-events: none;
  opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.06 0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* Footer — поверх основания кучи */

footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: baseline;
  gap: 10px 28px;
  padding: 18px 24px 26px;
  background: transparent;
  border: 0;
  box-shadow: none;
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--footer-ink);
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.92), var(--glitch-shadow);
}

footer a {
  color: var(--footer-ink);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  text-decoration-color: rgba(241, 241, 241, 0.38);
  overflow-wrap: anywhere;
}

footer a:hover {
  color: var(--accent-contrast);
  text-decoration-color: var(--accent-contrast);
}

@media (max-width: 640px) {
  :root {
    --pile-headroom: clamp(34px, 9vw, 48px);
    --pile-height: clamp(480px, 124vw, 570px);
    --pile-lift: -250px;
    --pile-reveal-scroll: 640px;
    --pile-sticky-top: max(0px, calc(100vh - (var(--pile-height) + var(--pile-headroom) - 120px)));
    --pile-view-scale: 1;
  }

  .wrap {
    width: min(100% - 32px, 1120px);
  }

  .confession {
    padding: 9vh 0 12vh;
  }

  .confession p {
    max-width: 100%;
    font-size: 1rem;
  }

  .confession .dim {
    font-size: 0.9rem;
  }

  .grown {
    margin-right: -16px;
    padding-bottom: 24px;
    overflow: hidden;
  }

  .projects {
    display: flex;
    gap: 14px;
    overflow-x: auto;
    padding: 0 16px 10px 0;
    scroll-padding-left: 0;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
  }

  .proj {
    flex: 0 0 min(82vw, 330px);
    scroll-snap-align: start;
    transform: none;
  }

  .proj img {
    aspect-ratio: 16 / 9;
  }

  .proj:hover {
    transform: translateY(-4px);
  }

  .proj-meta {
    padding: 16px 14px 0;
  }

  .what {
    padding: 10px 14px 18px;
  }

  .open {
    padding: 0 14px 14px;
  }

  .pile a {
    width: clamp(100px, 29vw, 124px);
    transition-duration: 0.14s;
  }

  .pile a:nth-child(1) {
    left: 31%;
    top: calc(9% + var(--pile-headroom));
    width: clamp(116px, 34vw, 142px);
    z-index: 16;
    border-color: rgba(241, 241, 241, 0.34);
    box-shadow:
      0 0 0 1px rgba(241, 241, 241, 0.14),
      var(--pin-shadow);
  }

  .pile a:nth-child(2) {
    left: 8%;
    top: calc(15% + var(--pile-headroom));
  }

  .pile a:nth-child(3) {
    left: 58%;
    top: calc(15% + var(--pile-headroom));
  }

  .pile a:nth-child(4) {
    left: 76%;
    top: calc(20% + var(--pile-headroom));
  }

  .pile a:nth-child(5) {
    left: -4%;
    top: calc(26% + var(--pile-headroom));
  }

  .pile a:nth-child(6) {
    left: 25%;
    top: calc(25% + var(--pile-headroom));
  }

  .pile a:nth-child(7) {
    left: 54%;
    top: calc(26% + var(--pile-headroom));
  }

  footer {
    justify-content: flex-start;
    gap: 8px 16px;
    padding: 18px 16px 24px;
    font-size: 11px;
  }
}

.pile a.is-focused {
  left: var(--pile-focus-left, 50%);
  top: var(--pile-focus-top, 50%);
  z-index: 200;
  border-color: rgba(241, 241, 241, 0.92);
  box-shadow:
    0 0 0 1px rgba(255, 45, 85, 0.42),
    0 0 34px rgba(241, 241, 241, 0.16),
    var(--pin-shadow-lift);
  transform: rotate(0deg);
  cursor: zoom-out;
}

@keyframes vhs-noise-shift {
  0% {
    transform: translate3d(0, 0, 0);
  }

  50% {
    transform: translate3d(-28px, 17px, 0);
  }

  100% {
    transform: translate3d(15px, -23px, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  body::before,
  body::after {
    animation: none;
  }

  .pile a {
    transform: rotate(var(--r));
  }
}
