/* 05 «Проєкти» — Figma node 42:367: an intro with the project index, then four 1800 × 1000 panels.
   Interaction follows the notes «05 — інтерактив для верстки». Base styles are a plain list
   (reduced motion, no JS); .projects--live (projects.js) adds the sticky stack and the motion. */

/* --p: one design pixel of text and boxes; --edge: of the horizontal margins. Registered so cqw resolves here. */
@property --p    { syntax: "<length>"; inherits: true; initial-value: 1px; }
@property --edge { syntax: "<length>"; inherits: true; initial-value: 1px; }

.projects {
  --p: min(100cqw / 1800, 100svh / 1000);
  --edge: calc(100cqw / 1800);
  background: var(--color-bg-page);
}

/* ───────────── Intro ───────────── */
/* at least a screen tall, so only the 40px lip of the first panel shows under it, as in Figma */
.projects__intro { display: flex; justify-content: center; align-items: center; min-height: 100svh; }
.projects__canvas { --ui: var(--p); position: relative; width: calc(1800 * var(--p)); height: calc(1000 * var(--p)); }
.projects__canvas > .section-index { position: absolute; top: calc(72 * var(--p)); left: calc(64 * var(--p)); }

.projects__count { position: absolute; top: calc(129 * var(--p)); left: calc(48 * var(--p)); font-family: var(--font-display); font-weight: 500; white-space: nowrap; }
.projects__count strong { display: block; font-weight: 500; font-size: calc(360 * var(--p)); line-height: .82; letter-spacing: -.06em; }
.projects__count span { display: flex; gap: calc(12 * var(--p)); padding-left: calc(13 * var(--p)); font-size: calc(44 * var(--p)); line-height: calc(46 * var(--p)); letter-spacing: -.025em; }
.projects__count b, .projects__count i { font-style: normal; font-weight: 500; }
.projects__count i { color: var(--color-text-secondary); }

.projects__text { position: absolute; top: calc(301 * var(--p)); left: calc(1216 * var(--p)); display: flex; flex-direction: column; align-items: flex-start; gap: calc(28 * var(--p)); width: calc(520 * var(--p)); }
.projects__title { font-family: var(--font-display); font-weight: 500; font-size: calc(44 * var(--p)); line-height: calc(46 * var(--p)); letter-spacing: -.025em; }
.projects__lead { position: relative; top: calc(-1 * var(--p)); font-size: calc(18 * var(--p)); line-height: calc(24 * var(--p)); color: var(--color-text-secondary); }
.projects__text .btn { min-width: calc(166 * var(--p)); }

.projects__index { position: absolute; top: calc(635 * var(--p)); left: calc(64 * var(--p)); width: calc(1672 * var(--p)); margin: 0; padding: 0; list-style: none; }
.projects__index li { border-top: 1px solid rgb(28 27 25 / .12); }
.projects__index li:last-child { border-bottom: 1px solid rgb(28 27 25 / .12); }
.row {
  display: grid;
  grid-template-columns: calc(120 * var(--p)) calc(560 * var(--p)) calc(360 * var(--p)) calc(360 * var(--p)) minmax(0, 1fr);
  align-items: center;
  height: calc(74 * var(--p));
  padding: 0 calc(4 * var(--p));
  white-space: nowrap;
  transition: background-color .2s ease, color .2s ease;
}
.row__num { font-weight: 600; font-size: calc(14 * var(--p)); letter-spacing: .04em; color: var(--color-text-secondary); }
.row__title { font-family: var(--font-display); font-size: calc(30 * var(--p)); line-height: calc(32 * var(--p)); letter-spacing: -.02em; }
.row__place { font-size: calc(18 * var(--p)); line-height: calc(24 * var(--p)); color: var(--color-text-secondary); }
.row__kind { font-size: calc(15 * var(--p)); line-height: calc(23 * var(--p)); color: var(--color-text-secondary); }
.row__power { justify-self: end; font-weight: 600; font-size: calc(28 * var(--p)); line-height: calc(34 * var(--p)); letter-spacing: -.01em; }
.row:focus-visible { outline-color: var(--color-bg-strong); }
.row:focus-visible, .row.is-active { border-radius: calc(18 * var(--p)); background: var(--color-bg-accent); }
.row:focus-visible > *, .row.is-active > * { color: var(--color-text-primary); }
@media (hover: hover) {
  .row:hover { border-radius: calc(18 * var(--p)); background: var(--color-bg-accent); }
  .row:hover > * { color: var(--color-text-primary); }
}

/* the thumbnail that floats next to the cursor */
.projects__preview {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  width: calc(260 * var(--p));
  height: calc(180 * var(--p));
  margin: calc(-90 * var(--p)) 0 0 calc(-130 * var(--p));
  border-radius: calc(18 * var(--p));
  object-fit: cover;
  box-shadow: 0 calc(14 * var(--p)) calc(36 * var(--p)) rgb(38 26 13 / .14);
  opacity: 0;
  rotate: 4deg;
  scale: .92;
  transition: opacity .2s ease, scale .25s cubic-bezier(.23, 1, .32, 1);
  pointer-events: none;
}
.projects__preview.is-on { opacity: 1; scale: 1; }

/* ───────────── Panels ───────────── */
.stack {
  position: relative;
  z-index: 1;
  margin-top: calc(-40 * var(--p));
  /* dark behind the panels, but not in the strip that overlaps the intro */
  background: linear-gradient(rgb(38 41 50 / 0) calc(40 * var(--p)), var(--color-bg-inverse) calc(40 * var(--p)));
}
.project {
  --shade:
    linear-gradient(rgb(28 27 25 / .5), rgb(28 27 25 / 0)) top / 100% 20% no-repeat,
    linear-gradient(rgb(28 27 25 / 0), rgb(28 27 25 / .85)) bottom / 100% 56% no-repeat,
    linear-gradient(90deg, rgb(28 27 25 / .78), rgb(28 27 25 / .35) 45%, rgb(28 27 25 / 0) 70%);
  height: 100lvh; /* the whole screen, also once a phone browser tucks its bars away */
  min-height: 600px;
  color: #fff;
}
.project__card {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  height: 100%;
  border-radius: calc(28 * var(--p)) calc(28 * var(--p)) 0 0;
  background: var(--color-bg-inverse);
  box-shadow: 0 calc(-24 * var(--p)) calc(64 * var(--p)) rgb(15 15 18 / .5);
}
.project__media, .project__shade, .project__veil { position: absolute; inset: 0; pointer-events: none; }
.project__media img { width: 100%; height: 100%; object-fit: cover; }
.project__shade { background: var(--shade); }
.project__veil { z-index: 2; background: #0f0f12; opacity: 0; } /* darkens the covered panel */
.project :focus-visible { outline-color: var(--color-bg-accent); }

.project__bar { position: absolute; top: calc(57 * var(--p)); /* 57: Figma's baseline rounding */ left: calc(64 * var(--edge)); display: flex; align-items: center; gap: calc(12 * var(--p)); white-space: nowrap; }
.project__counter { font-weight: 600; font-size: calc(14 * var(--p)); line-height: calc(17 * var(--p)); letter-spacing: .04em; text-transform: uppercase; }
/* Figma's glass blur is left out: backdrop-filter flickers on panels that move and scale */
.project__tag, .btn--glass { border: 1px solid var(--color-border-on-photo-muted); background: rgb(255 255 255 / .14); }
.project__tag { position: relative; top: calc(-1 * var(--p)); padding: calc(8 * var(--p)) calc(16 * var(--p)); border-radius: var(--radius-full); font-size: calc(13 * var(--p)); line-height: calc(16 * var(--p)); }
.btn--glass { --ui: var(--p); color: #fff; }
@media (hover: hover) { .btn--glass:hover { background: rgb(255 255 255 / .25); } }
.project__more { position: absolute; top: calc(50 * var(--p)); right: calc(65 * var(--edge)); }

.project__hero {
  position: absolute;
  bottom: calc(55 * var(--p));
  left: calc(52 * var(--edge));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: calc(8 * var(--p));
  font-family: var(--font-display);
  white-space: nowrap;
}
.project__title { position: relative; top: calc(-1 * var(--p)); }
.project__title, .project__unit { font-weight: 500; font-size: calc(88 * var(--p)); line-height: calc(85 * var(--p)); letter-spacing: -.035em; }
.project__figure { display: flex; align-items: baseline; gap: calc(20 * var(--p)); }
.project__big { position: relative; margin-right: .06em; font-size: calc(360 * var(--p)); line-height: .82; letter-spacing: -.06em; } /* margin: Figma keeps no tracking after the last digit */
.project__ghost { visibility: hidden; } /* holds the final width, so the unit does not move while counting */
.project__num { position: absolute; top: 0; left: 0; }
.project__unit { color: var(--color-bg-accent); }

.project__stats { position: absolute; right: calc(64 * var(--edge)); bottom: calc(56 * var(--p)); width: calc(420 * var(--p)); margin: 0; padding: 0; list-style: none; white-space: nowrap; }
.project__stats li { display: flex; flex-direction: column; gap: calc(4 * var(--p)); padding: calc(16 * var(--p)) calc(4 * var(--p)); border-top: 1px solid rgb(251 247 239 / .15); }
.project__stats strong { font-family: var(--font-display); font-weight: 500; font-size: calc(30 * var(--p)); line-height: calc(32 * var(--p)); letter-spacing: -.02em; }
.project__stats li > span { font-size: calc(15 * var(--p)); line-height: calc(23 * var(--p)); color: var(--color-text-on-photo-muted); }

/* ───────────── Live: sticky stack (notes 1–5) ───────────── */
.projects--live .project { position: sticky; top: 0; min-height: 0; }
.projects--live :is(.project__hero, .project__stats) { margin-bottom: calc(100lvh - 100dvh); } /* above the browser's bars while they show */
.projects--live .project__card { transform-origin: 50% 50%; }
/* Memory matters here: each full-screen layer costs tens of megabytes on a Retina screen, and when the
   browser runs out it leaves photos black. So: no copies of photos, no filters, no forced layers on
   anything large, and only the panels around the current one are drawn (projects.js sets .is-away). */
/* only the pictures are switched off; text and buttons stay, so keyboard focus can still reach every project */
.projects--live .project.is-away :is(.project__media, .project__shade, .project__veil) { visibility: hidden; }
.projects--live .project__big { will-change: transform; } /* small layer: the counting digits repaint alone */

/* Ken Burns: one slow drift, never rewound while the panel can be seen */
.projects--live .project.is-zooming .project__media img { animation: project-drift 12s cubic-bezier(.2, .5, .3, 1) forwards; }
@keyframes project-drift { to { transform: scale(1.06); } }

/* Scroll-linked motion runs on the compositor, in the same frame as the scroll itself.
   Panel n rises while the stack scrolls through screen n; it recedes during the next one. */
@supports (animation-timeline: view()) {
  .projects--live .stack { view-timeline: --stack block; }
  .projects--live .project__media {
    animation: project-parallax linear both;
    animation-timeline: --stack;
    animation-range: cover calc(var(--n) * 100lvh) cover calc(var(--n) * 100lvh + 100dvh);
  }
  .projects--live .project:not(:last-child) .project__card {
    animation: project-shrink linear both;
    animation-timeline: --stack;
    animation-range: cover calc((var(--n) + 1) * 100lvh) cover calc((var(--n) + 1) * 100lvh + 100dvh);
  }
  .projects--live .project:not(:last-child) .project__veil {
    animation: project-dim linear both;
    animation-timeline: --stack;
    animation-range: cover calc((var(--n) + 1) * 100lvh) cover calc((var(--n) + 1) * 100lvh + 100dvh);
  }
}
@keyframes project-parallax { from { transform: translate3d(0, -22%, 0); } to { transform: translate3d(0, 0, 0); } }
@keyframes project-shrink { from { transform: scale(1); } to { transform: scale(.94); } }
@keyframes project-dim { from { opacity: 0; } to { opacity: .4; } }

.projects--live .project__unit { opacity: 0; translate: -24px 0; }
.projects--live .project__stats li { opacity: 0; translate: 0 32px; }
.projects--live .project.is-in .project__unit {
  opacity: 1;
  translate: 0 0;
  transition: opacity .5s ease .6s, translate .6s cubic-bezier(.23, 1, .32, 1) .6s;
}
.projects--live .project.is-in .project__stats li {
  opacity: 1;
  translate: 0 0;
  transition:
    opacity .5s ease calc(.15s + var(--i) * 80ms),
    translate .6s cubic-bezier(.23, 1, .32, 1) calc(.15s + var(--i) * 80ms);
}

/* ───────────── Narrower windows ─────────────
   Figma has only the 1800 frame: the intro stacks, each panel keeps one screen with its parts in a column. */
@media (max-width: 1279px) {
  .projects { --p: 1px; }
  .projects__intro { min-height: 0; }
  .projects__canvas { width: 100%; height: auto; max-width: 760px; padding: 72px 20px 56px; box-sizing: border-box; }
  .projects__canvas > * { position: static; }
  .projects__canvas > .section-index { position: static; width: fit-content; }
  .projects__count { margin-top: 20px; }
  .projects__count strong { font-size: min(32cqw, 260px); line-height: .9; }
  .projects__count span { flex-wrap: wrap; gap: 8px; padding: 4px 0 0; font-size: clamp(24px, 7cqw, 36px); line-height: 1.1; }
  .projects__text { width: auto; margin-top: 40px; gap: 20px; }
  .projects__title { font-size: clamp(28px, 8cqw, 44px); line-height: 1.05; }
  .projects__lead { max-width: 520px; font-size: 16px; line-height: 1.45; }
  .projects__index { width: auto; margin-top: 40px; }
  .row { grid-template-columns: 32px minmax(0, 1fr) auto; column-gap: 8px; row-gap: 2px; height: auto; padding: 14px 8px; white-space: normal; }
  .row__num { font-size: 12px; }
  .row__title { font-size: clamp(18px, 5cqw, 24px); line-height: 1.15; }
  .row__power { grid-column: 3; grid-row: 1; font-size: clamp(16px, 4.6cqw, 22px); line-height: 1.2; white-space: nowrap; }
  .row__place { grid-column: 2 / -1; font-size: 13px; line-height: 1.4; }
  .row__kind { grid-column: 2 / -1; font-size: 12px; line-height: 1.4; }
  .row:focus-visible, .row.is-active { border-radius: 14px; }
  .projects__preview { display: none; }

  .stack { margin-top: -24px; background: linear-gradient(rgb(38 41 50 / 0) 24px, var(--color-bg-inverse) 24px); }
  .project__card { display: flex; flex-direction: column; align-items: flex-start; padding: 20px; border-radius: 24px 24px 0 0; box-sizing: border-box; }
  .project { --shade: linear-gradient(rgb(28 27 25 / .55), rgb(28 27 25 / .1) 28%, rgb(28 27 25 / .55) 55%, rgb(28 27 25 / .9)); }
  .project__bar { position: relative; top: auto; left: auto; flex-wrap: wrap; gap: 8px; white-space: normal; }
  .project__counter { flex-basis: 100%; font-size: 12px; line-height: 15px; }
  .project__tag { padding: 6px 12px; font-size: 12px; line-height: 15px; }
  .project__hero { position: relative; bottom: auto; left: auto; gap: 8px; margin-top: auto; white-space: normal; }
  .project__title { font-size: clamp(28px, 8cqw, 64px); line-height: 1; }
  .project__figure { flex-wrap: wrap; gap: 4px 12px; }
  .project__big { font-size: min(34cqw, 240px, 26svh); line-height: .9; }
  .project__unit { font-size: clamp(26px, 8cqw, 64px); line-height: 1; }
  .project__stats { position: relative; right: auto; bottom: auto; display: grid; grid-template-columns: 1fr 1fr; column-gap: 16px; width: 100%; max-width: 560px; margin-top: 16px; white-space: normal; }
  .project__stats li { gap: 2px; padding: 10px 0; }
  .project__stats strong { font-size: clamp(17px, 4.8cqw, 26px); line-height: 1.15; }
  .project__stats li > span { font-size: 12px; line-height: 1.35; }
  .project__more { position: relative; top: auto; right: auto; margin-top: 8px; font-size: 13px; line-height: 16px; padding: 11px 18px; }
}
@media (min-width: 600px) and (max-width: 1279px) {
  .projects__canvas { padding-inline: 40px; }
  .project__card { padding: 40px; }
}
