/* =========================================================
   AGENCY® — минималистичное портфолио видеопродакшна
   Белый фон, чёрный текст, широкий вытянутый шрифт
   ========================================================= */

/* Логотип: Mazut SP (SIL OFL 1.1, Sasha Pavljenko) — «плавленые» буквы */
@font-face {
  font-family: 'Mazut SP';
  src: url('assets/fonts/MazutSP-Demo.otf') format('opentype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #F1F0EC;
  --bg-soft: #E6E4DE;
  --fg: #0B0B0B;
  --muted: rgba(11, 11, 11, 0.52);
  --line: rgba(11, 11, 11, 0.14);

  --font: 'Archivo', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'Space Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  /* «плавленый» акцидентный шрифт для логотипа */
  --display: 'Mazut SP', 'Archivo', sans-serif;
  /* цвет радужки глаза в негативе — им красим буквы */
  --eye: #7F94AE;

  --pad: clamp(20px, 4vw, 64px);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

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

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

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-weight: 300;
  line-height: 1.4;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
}

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

/* ---------- типографика ---------- */
.label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  line-height: 1.8;
  color: var(--muted);
}

.display {
  font-weight: 150;
  font-variation-settings: 'wdth' 125;
  letter-spacing: -0.02em;
  text-transform: uppercase;
  line-height: 0.84;
}

/* =========================================================
   СКРЫТЫЕ СТАРТОВЫЕ СОСТОЯНИЯ
   (только пока на <html> есть класс .anim — снимается скриптом,
    поэтому сайт виден даже без библиотек)
   ========================================================= */
html.anim .site-header {
  opacity: 0;
}

html.anim .hero-word {
  transform: translateY(115%);
}

html.anim .reveal {
  opacity: 0;
  transform: translateY(28px);
}

html.anim .reveal.is-in {
  opacity: 1;
  transform: none;
}

/* =========================================================
   HEADER
   ========================================================= */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px var(--pad);
  color: var(--fg);
  /* буквы — негатив к тому, что под ними: чёрные на бумаге,
     инвертируются поверх видео */
  mix-blend-mode: difference;
  will-change: opacity;
}

/* Логотип: Mazut SP — плавленые буквы, белая заливка + чёрный контур,
   слегка вразнобой, как вырезки */
.brand {
  display: inline-flex;
  align-items: baseline;
  gap: 0.03em;
  font-size: clamp(40px, 4.4vw, 66px);
  line-height: 1;
  user-select: none;
  filter: drop-shadow(0.03em 0.025em 0 rgba(11, 11, 11, 0.16));
}

.brand-l {
  display: inline-block;
  font-family: var(--display);
  font-weight: 400;
  line-height: 1;
  /* белая заливка + difference в шапке = чёрные буквы на бумаге
     и негатив поверх видео */
  color: #fff;
  -webkit-text-stroke: 0;
  will-change: transform;
}

.brand-l[data-hit] {
  cursor: pointer;
}

/* глаз — часть того же негативного слоя: на бумаге он выглядит
   негативом, поверх видео инвертируется вместе с буквами */
.brand-eye {
  width: 1.16em;
  height: auto;
  margin: 0 0.14em;
  align-self: center;
  flex: none;
  transform: rotate(-4deg) translateY(-0.01em);
  filter: drop-shadow(0 1px 1px rgba(11, 11, 11, 0.28));
  cursor: pointer;
  -webkit-user-drag: none;
  user-select: none;
}

.l1 { transform: rotate(-5deg) translateY(-0.02em); }
.l2 { transform: rotate(3deg) translateY(0.03em); font-size: 0.96em; }
.l3 { transform: rotate(-3deg) translateY(-0.03em); font-size: 1.03em; }
.l4 { transform: rotate(4deg) translateY(0.02em); font-size: 0.95em; }
.l5 { transform: rotate(-4deg) translateY(-0.01em); font-size: 1.01em; }
.l6 { transform: rotate(5deg) translateY(0.04em); font-size: 0.97em; }
.l7 { transform: rotate(-4deg) translateY(-0.02em); font-size: 1.02em; }
.l8 { transform: rotate(3deg) translateY(0.02em); font-size: 0.96em; }

/* =========================================================
   HERO
   ========================================================= */
.hero {
  position: relative;
  width: 100%;
  height: 100svh;
  min-height: 640px;
  overflow: hidden;
  background: var(--bg);
}

.hero-canvas,
.hero-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hero-canvas {
  z-index: 1;
  cursor: pointer;
  transition: opacity 0.32s ease;
  will-change: opacity;
}

/* видео включается без зума: кадр уже совпал с моделью по глазу,
   любое масштабирование сломало бы бесшовную склейку */
.hero-video {
  z-index: 2;
  object-fit: cover;
  object-position: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.32s ease;
  will-change: opacity;
}

/* состояние «видео пошло» */
.hero--video .hero-canvas {
  opacity: 0;
  pointer-events: none;
}

.hero--video .hero-video {
  opacity: 1;
}

.hero--video .hero-inner {
  opacity: 0;
  transform: translateY(24px);
  pointer-events: none;
}

/* прогресс загрузки модели / служебные подписи */
.hero-status {
  position: absolute;
  left: 50%;
  bottom: clamp(150px, 22vh, 230px);
  z-index: 5;
  transform: translateX(-50%);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.hero-status.is-on {
  opacity: 1;
}

.hero-inner {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 0 var(--pad) clamp(24px, 4vw, 56px);
  pointer-events: none;
  transition: opacity 0.8s ease, transform 0.8s var(--ease);
}

.hero-title {
  font-weight: 150;
  font-variation-settings: 'wdth' 125;
  font-size: clamp(2.8rem, 11.5vw, 12.5rem);
  line-height: 0.8;
  letter-spacing: -0.025em;
  text-align: center;
  text-transform: uppercase;
  margin-bottom: 0;
  user-select: none;
}

.hero-line {
  display: block;
  overflow: hidden;
}

.hero-word {
  display: inline-block;
  will-change: transform;
}

/* =========================================================
   СЕКЦИИ
   ========================================================= */
.section {
  padding: clamp(64px, 10vw, 150px) var(--pad);
  border-top: 1px solid var(--line);
}

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: clamp(18px, 3vw, 36px);
  border-bottom: 1px solid var(--line);
  margin-bottom: clamp(26px, 4vw, 56px);
}

.section-title {
  font-weight: 150;
  font-variation-settings: 'wdth' 125;
  font-size: clamp(2.6rem, 7vw, 7rem);
  line-height: 0.86;
  letter-spacing: -0.025em;
  text-transform: uppercase;
}

.section-count {
  font-family: var(--mono);
  font-size: clamp(12px, 1.2vw, 15px);
  color: var(--muted);
  padding-bottom: 6px;
  white-space: nowrap;
}

.section-desc {
  max-width: 520px;
  margin-bottom: clamp(32px, 5vw, 64px);
  font-size: clamp(14px, 1.3vw, 17px);
  font-weight: 300;
  line-height: 1.65;
  letter-spacing: 0.01em;
  color: var(--muted);
}

/* =========================================================
   РАБОТЫ
   ========================================================= */
.works-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(14px, 2vw, 28px);
}

.work-card {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.55s var(--ease), color 0.55s var(--ease);
}

.work-card:hover {
  background: var(--fg);
  color: var(--bg);
}

.work-index,
.work-tag {
  position: absolute;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  transition: color 0.55s var(--ease);
}

.work-index {
  top: 18px;
  left: 20px;
}

.work-tag {
  top: 18px;
  right: 20px;
}

.work-card:hover .work-index,
.work-card:hover .work-tag {
  color: var(--bg);
}

.work-title {
  font-weight: 200;
  font-variation-settings: 'wdth' 120;
  font-size: clamp(1.3rem, 2.6vw, 2.4rem);
  letter-spacing: 0.01em;
  text-transform: uppercase;
  text-align: center;
  padding: 0 24px;
  transition: color 0.55s var(--ease), transform 0.55s var(--ease);
}

.work-card:hover .work-title {
  transform: scale(1.04);
}

/* видео/постер внутри карточки */
.work-card video,
.work-card img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
  transition: transform 1.2s var(--ease);
}

.work-card.has-media {
  color: var(--bg);
  background: #111;
}

.work-card.has-media::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0.42) 0%,
    rgba(0, 0, 0, 0.06) 38%,
    rgba(0, 0, 0, 0.5) 100%
  );
}

.work-card.has-media:hover {
  background: #111;
  color: var(--bg);
}

.work-card.has-media:hover video,
.work-card.has-media:hover img {
  transform: scale(1.04);
}

.work-card.has-media .work-index,
.work-card.has-media .work-tag {
  z-index: 2;
  color: rgba(241, 240, 236, 0.72);
}

.work-card.has-media .work-title {
  position: relative;
  z-index: 2;
  color: var(--bg);
  text-shadow: 0 1px 24px rgba(0, 0, 0, 0.35);
}

/* =========================================================
   МИНИ-ИГРА: СОБЕРИ ЛОГОТИП
   ========================================================= */
.game-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--fg);
  overflow: hidden;
  cursor: default;
  touch-action: none;
  transition: background 0.7s var(--ease);
}

.game-stage.is-done {
  background: var(--bg);
}

.game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* невидимая «собранная» раскладка: по ней меряем места деталей */
.game-logo {
  --game-fs: 40px;
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--game-fs);
  pointer-events: none;
}

.game-row {
  display: flex;
  align-items: center;
  gap: 0.03em;
}

.game-piece {
  font-family: var(--display);
  font-weight: 400;
  line-height: 1;
  color: var(--bg);
  pointer-events: auto;
  cursor: grab;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
  will-change: transform;
  transition: transform 0.5s cubic-bezier(0.22, 0.9, 0.2, 1);
}

.game-logo.is-live .game-piece {
  position: absolute;
  left: 0;
  top: 0;
}

/* в режиме замера детали стоят в потоке и без сдвигов */
.game-logo:not(.is-live) .game-piece {
  transform: none !important;
}

.game-piece.is-dragging {
  transition: none;
  cursor: grabbing;
}

.game-piece.is-placed {
  cursor: default;
}

.game-piece-eye {
  width: 1.15em;
  height: auto;
  margin: 0;
  filter: invert(1) drop-shadow(0 1px 1px rgba(0, 0, 0, 0.3));
}

.game-piece:focus-visible {
  outline: 1px dashed rgba(241, 240, 236, 0.7);
  outline-offset: 5px;
}

.game-stage.is-done .game-piece {
  color: var(--fg);
}

.game-stage.is-done .game-piece:focus-visible {
  outline-color: rgba(11, 11, 11, 0.5);
}

/* призрачные места под детали */
.game-slots {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.game-slot {
  position: absolute;
  left: 0;
  top: 0;
  border: 1px dashed rgba(241, 240, 236, 0.16);
  transition: opacity 0.4s ease, border-color 0.25s ease;
}

.game-slot.is-near {
  border-color: rgba(241, 240, 236, 0.55);
}

.game-stage.is-done .game-slot {
  opacity: 0;
}

.game-hint {
  position: absolute;
  left: clamp(14px, 2vw, 24px);
  bottom: clamp(12px, 2vw, 22px);
  margin: 0;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(241, 240, 236, 0.42);
  pointer-events: none;
  transition: color 0.5s ease;
}

.game-stage.is-done .game-hint {
  color: rgba(11, 11, 11, 0.45);
}

.game-reset {
  position: absolute;
  right: clamp(14px, 2vw, 24px);
  bottom: clamp(12px, 2vw, 22px);
  padding: 8px 14px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--fg);
  background: none;
  border: 1px solid rgba(11, 11, 11, 0.35);
  cursor: pointer;
  transition: background 0.3s ease, color 0.3s ease;
}

.game-reset:hover {
  background: var(--fg);
  color: var(--bg);
}

.game-reset[hidden] {
  display: none;
}

/* =========================================================
   FOOTER
   ========================================================= */
.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 32px;
  padding: 26px var(--pad) 34px;
  border-top: 1px solid var(--line);
}

/* =========================================================
   REVEAL-АНИМАЦИИ ПРИ СКРОЛЛЕ
   ========================================================= */
.reveal {
  transition: opacity 0.9s ease, transform 1s var(--ease);
}

/* =========================================================
   АДАПТИВ
   ========================================================= */
@media (max-width: 900px) {
  .works-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .site-header {
    padding: 18px 20px;
  }

  .hero {
    min-height: 560px;
  }

  .hero-title {
    font-size: clamp(2.8rem, 15vw, 5rem);
  }

  .game-stage {
    aspect-ratio: 4 / 3;
  }

  .site-footer {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* =========================================================
   REDUCED MOTION
   ========================================================= */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  html.anim .hero-word {
    transform: none;
  }

  html.anim .site-header {
    opacity: 1;
  }

  html.anim .reveal {
    opacity: 1;
    transform: none;
  }

  .reveal {
    transition: none;
  }
}
