/* ============================================================
   SCROLLY.CSS — Unified Design System for 4x4x.ru
   Apple-style scrollytelling primitives
   ============================================================ */

/* --- Design Tokens --- */
:root {
  /* Surfaces */
  --s-bg: #0a0a0a;
  --s-bg-raised: #111113;
  --s-bg-card: #161618;
  --s-bg-card-hover: #1e1e22;
  --s-bg-overlay: rgba(10, 10, 10, 0.6);

  /* Text */
  --t-primary: #f5f5f7;
  --t-secondary: #a1a1a6;
  --t-tertiary: #6e6e73;

  /* Brand — Gold */
  --c-gold: #c9a84c;
  --c-gold-light: #d4af37;
  --c-gold-pale: #e8cc7a;
  --c-gold-dim: rgba(201, 168, 76, 0.12);
  --c-gold-border: rgba(201, 168, 76, 0.28);
  --c-gold-glow: rgba(212, 175, 55, 0.25);

  /* Borders */
  --b-subtle: rgba(255, 255, 255, 0.08);
  --b-medium: rgba(255, 255, 255, 0.14);
  --b-hover: rgba(201, 168, 76, 0.4);

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.6);
  --shadow-gold: 0 8px 32px rgba(212, 175, 55, 0.25);

  /* Glass */
  --glass-bg: rgba(10, 10, 10, 0.78);
  --glass-border: rgba(255, 255, 255, 0.06);
  --glass-blur: 22px;

  /* Radii */
  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;

  /* Motion */
  --ease-smooth: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur-fast: 0.22s;
  --dur-base: 0.4s;
  --dur-slow: 0.72s;
  --dur-reveal: 0.85s;

  /* Typography */
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', monospace;

  /* Layout */
  --nav-h: 64px;
  --section-pad: clamp(60px, 10vw, 120px);
  --content-max: 1200px;
  --content-narrow: 800px;
}

/* --- Light Theme --- */
[data-theme="light"] {
  --s-bg: #f5f5f7;
  --s-bg-raised: #ebebed;
  --s-bg-card: #ffffff;
  --s-bg-card-hover: #f9f9fb;
  --s-bg-overlay: rgba(245, 245, 247, 0.6);
  --t-primary: #1d1d1f;
  --t-secondary: #555555;
  --t-tertiary: #888888;
  --b-subtle: rgba(0, 0, 0, 0.06);
  --b-medium: rgba(0, 0, 0, 0.12);
  --glass-bg: rgba(245, 245, 247, 0.82);
  --glass-border: rgba(0, 0, 0, 0.06);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.14);
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font);
  background: var(--s-bg);
  color: var(--t-primary);
  line-height: 1.6;
  overflow-x: hidden;
  transition: background-color var(--dur-base) var(--ease-smooth),
              color var(--dur-base) var(--ease-smooth);
}

img, video { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }

/* --- Language Visibility --- */
[data-lang="en"] .lang-ru { display: none !important; }
[data-lang="ru"] .lang-en { display: none !important; }
[data-lang="en"] .lang-en { display: inline; }
[data-lang="ru"] .lang-ru { display: inline; }

/* --- Typography --- */
.eyebrow {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--c-gold);
  margin-bottom: 1rem;
}

.headline-xl {
  font-size: clamp(2.8rem, 7vw, 5.5rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.05;
  color: var(--t-primary);
}

.headline-lg {
  font-size: clamp(2rem, 5vw, 3.5rem);
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.1;
}

.headline-md {
  font-size: clamp(1.4rem, 3vw, 2rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.body-lg {
  font-size: clamp(1rem, 2vw, 1.25rem);
  color: var(--t-secondary);
  line-height: 1.65;
}

.body-md {
  font-size: 1rem;
  color: var(--t-secondary);
  line-height: 1.6;
}

.gold-text {
  background: linear-gradient(135deg, var(--c-gold-light), var(--c-gold-pale), var(--c-gold));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* --- Navigation (Glass) --- */
.nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(1rem, 3vw, 2.5rem);
  background: var(--glass-bg);
  border-bottom: 1px solid var(--glass-border);
  backdrop-filter: saturate(180%) blur(var(--glass-blur));
  -webkit-backdrop-filter: saturate(180%) blur(var(--glass-blur));
  transition: background var(--dur-base) var(--ease-smooth),
              border-color var(--dur-base) var(--ease-smooth);
}

.nav-logo {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.nav-links {
  display: flex;
  gap: 2rem;
  list-style: none;
}

.nav-links a {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--t-secondary);
  transition: color var(--dur-fast) ease;
  position: relative;
}

.nav-links a:hover,
.nav-links a.active {
  color: var(--t-primary);
}

.nav-links a.active::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--c-gold);
  border-radius: 1px;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Theme toggle */
.theme-toggle, .lang-toggle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--b-subtle);
  background: transparent;
  color: var(--t-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color var(--dur-fast) ease, color var(--dur-fast) ease;
}

.theme-toggle:hover, .lang-toggle:hover {
  border-color: var(--c-gold-border);
  color: var(--c-gold);
}

/* Mobile hamburger */
.nav-burger {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}

.nav-burger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--t-primary);
  border-radius: 1px;
  transition: transform var(--dur-base) var(--ease-smooth),
              opacity var(--dur-base) var(--ease-smooth);
}

/* Mobile nav */
@media (max-width: 768px) {
  .nav-links { display: none; }
  .nav-burger { display: flex; }

  .nav-links.open {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: var(--nav-h);
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--s-bg);
    padding: 2rem;
    gap: 1.5rem;
    z-index: 999;
  }

  .nav-links.open a {
    font-size: 1.2rem;
  }
}

/* --- Section Layout --- */
.section {
  padding: var(--section-pad) clamp(1.25rem, 4vw, 3rem);
}

.section-inner {
  max-width: var(--content-max);
  margin: 0 auto;
}

.section-narrow {
  max-width: var(--content-narrow);
  margin: 0 auto;
}

.section-header {
  text-align: center;
  margin-bottom: clamp(2.5rem, 5vw, 4rem);
}

/* --- Reveal Animations --- */

/* Slide Up (default) */
[data-scrolly="reveal"],
.scrolly-reveal {
  opacity: 0;
  transform: translateY(40px);
  transition: opacity var(--dur-reveal) var(--ease-smooth),
              transform var(--dur-reveal) var(--ease-smooth);
}

[data-scrolly="reveal"].is-visible,
.scrolly-reveal.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Scale */
[data-scrolly-type="scale"] {
  opacity: 0;
  transform: scale(0.92);
}

[data-scrolly-type="scale"].is-visible {
  opacity: 1;
  transform: scale(1);
}

/* Blur */
[data-scrolly-type="blur"] {
  opacity: 0;
  filter: blur(10px);
  transform: translateY(20px);
}

[data-scrolly-type="blur"].is-visible {
  opacity: 1;
  filter: blur(0);
  transform: translateY(0);
  transition: opacity var(--dur-reveal) var(--ease-smooth),
              filter var(--dur-reveal) var(--ease-smooth),
              transform var(--dur-reveal) var(--ease-smooth);
}

/* Wipe (clip-path) */
[data-scrolly-type="wipe"] {
  clip-path: inset(0 100% 0 0);
  transition: clip-path var(--dur-reveal) var(--ease-out);
}

[data-scrolly-type="wipe"].is-visible {
  clip-path: inset(0 0 0 0);
}

/* Split (per-character) — JS adds .split-char spans */
[data-scrolly-type="split"] .split-char {
  display: inline-block;
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 0.5s var(--ease-smooth),
              transform 0.5s var(--ease-smooth);
}

[data-scrolly-type="split"].is-visible .split-char {
  opacity: 1;
  transform: translateY(0);
}

/* Stagger delays (applied by JS via style or classes) */
.stagger-1 { transition-delay: 0.08s; }
.stagger-2 { transition-delay: 0.16s; }
.stagger-3 { transition-delay: 0.24s; }
.stagger-4 { transition-delay: 0.32s; }
.stagger-5 { transition-delay: 0.40s; }
.stagger-6 { transition-delay: 0.48s; }

/* --- Sticky Scene --- */
.scrolly-sticky {
  position: relative;
}

.scrolly-sticky__pin {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Steps inside sticky scene — hidden by default, JS controls visibility */
.scrolly-sticky__step {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.5s var(--ease-smooth),
              transform 0.5s var(--ease-smooth);
  pointer-events: none;
}

.scrolly-sticky__step.is-active {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* Progress dots (side indicator) */
.scrolly-dots {
  position: absolute;
  right: 2rem;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 10;
}

.scrolly-dots__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--b-subtle);
  transition: background var(--dur-base) ease, transform var(--dur-base) var(--ease-spring);
}

.scrolly-dots__dot.is-active {
  background: var(--c-gold);
  transform: scale(1.4);
}

/* --- Parallax / Depth Layers --- */
.scrolly-depth {
  position: relative;
  overflow: hidden;
}

.scrolly-depth__layer {
  position: absolute;
  inset: -20% 0;
  will-change: transform;
}

/* --- Image Scrub (crossfade stack) --- */
.scrolly-scrub {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.scrolly-scrub__frame {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.15s linear;
}

.scrolly-scrub__frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scrolly-scrub__frame.is-active {
  opacity: 1;
}

/* --- Wipe Transition --- */
.scrolly-wipe {
  position: relative;
  overflow: hidden;
}

.scrolly-wipe__layer {
  position: absolute;
  inset: 0;
  clip-path: inset(0 100% 0 0);
  transition: clip-path 0.3s var(--ease-smooth);
}

.scrolly-wipe__layer.is-revealed {
  clip-path: inset(0 0 0 0);
}

/* --- Photo Cinematic Treatment --- */
.photo-cinema {
  position: relative;
  overflow: hidden;
  background: var(--s-bg);
}

.photo-cinema img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: contrast(1.12) saturate(0.7) brightness(0.85) sepia(0.08);
  transition: filter var(--dur-slow) var(--ease-smooth),
              transform var(--dur-slow) var(--ease-smooth);
}

.photo-cinema:hover img {
  filter: contrast(1.08) saturate(0.85) brightness(0.9) sepia(0.04);
  transform: scale(1.03);
}

/* Grain overlay */
.photo-cinema::after {
  content: '';
  position: absolute;
  inset: 0;
  background: url('/shared/img/grain.svg') repeat;
  background-size: 300px 300px;
  opacity: 0.06;
  mix-blend-mode: overlay;
  pointer-events: none;
}

/* Vignette */
.photo-cinema::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(10, 10, 10, 0.7) 100%);
  pointer-events: none;
  z-index: 1;
}

/* Bottom fade */
.photo-cinema--fade-bottom::after {
  background:
    url('/shared/img/grain.svg') repeat,
    linear-gradient(to bottom, transparent 60%, var(--s-bg) 100%);
  background-size: 300px 300px, 100% 100%;
  opacity: 1;
}

/* --- SVG Timeline (for how-it-works) --- */
.scrolly-timeline {
  position: relative;
}

.scrolly-timeline__line {
  stroke: var(--c-gold);
  stroke-width: 2;
  fill: none;
  stroke-dasharray: var(--line-length, 1000);
  stroke-dashoffset: var(--line-length, 1000);
  transition: stroke-dashoffset 0.1s linear;
}

/* --- CountUp --- */
.scrolly-count {
  font-variant-numeric: tabular-nums;
}

/* --- Cards --- */
.card {
  background: var(--s-bg-card);
  border: 1px solid var(--b-subtle);
  border-radius: var(--r-lg);
  padding: clamp(1.5rem, 3vw, 2.5rem);
  transition: background var(--dur-base) var(--ease-smooth),
              border-color var(--dur-base) var(--ease-smooth),
              box-shadow var(--dur-base) var(--ease-smooth),
              transform var(--dur-base) var(--ease-smooth);
}

.card:hover {
  background: var(--s-bg-card-hover);
  border-color: var(--b-hover);
  box-shadow: var(--shadow-gold);
  transform: translateY(-4px);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: clamp(1rem, 2.5vw, 2rem);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.85rem 2rem;
  border-radius: var(--r-md);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--dur-base) var(--ease-smooth);
}

.btn-gold {
  background: linear-gradient(135deg, var(--c-gold), var(--c-gold-light));
  color: #0a0a0a;
}

.btn-gold:hover {
  box-shadow: var(--shadow-gold);
  transform: translateY(-2px);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--c-gold-border);
  color: var(--c-gold);
}

.btn-outline:hover {
  background: var(--c-gold-dim);
  border-color: var(--c-gold);
}

/* --- Hero Section --- */
.hero {
  position: relative;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: calc(var(--nav-h) + 2rem) clamp(1.25rem, 4vw, 3rem) 4rem;
  overflow: hidden;
}

.hero-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.hero-content {
  position: relative;
  z-index: 2;
  max-width: 900px;
}

.hero-glow {
  position: absolute;
  width: 600px;
  height: 600px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--c-gold-glow) 0%, transparent 70%);
  filter: blur(80px);
  animation: heroGlow 6s ease-in-out infinite alternate;
  pointer-events: none;
  z-index: 0;
}

@keyframes heroGlow {
  0% { opacity: 0.4; transform: scale(1); }
  100% { opacity: 0.7; transform: scale(1.2); }
}

.hero-scroll-indicator {
  position: absolute;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  color: var(--t-tertiary);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  animation: scrollBounce 2s ease-in-out infinite;
}

@keyframes scrollBounce {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(8px); }
}

/* --- Footer --- */
.footer {
  padding: 3rem clamp(1.25rem, 4vw, 3rem);
  border-top: 1px solid var(--b-subtle);
  text-align: center;
  color: var(--t-tertiary);
  font-size: 0.85rem;
}

/* --- Horizontal Scroll Section --- */
.scrolly-hscroll {
  overflow: hidden;
}

.scrolly-hscroll__track {
  display: flex;
  gap: 2rem;
  will-change: transform;
}

.scrolly-hscroll__panel {
  flex: 0 0 80vw;
  max-width: 900px;
}

@media (max-width: 768px) {
  .scrolly-hscroll__panel {
    flex: 0 0 90vw;
  }
}

/* --- Utility --- */
.text-center { text-align: center; }
.text-gold { color: var(--c-gold); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }
.mt-6 { margin-top: 3rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 2rem; }

/* Content visibility optimization */
.section:not(.hero) {
  content-visibility: auto;
  contain-intrinsic-size: auto 600px;
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  [data-scrolly="reveal"],
  .scrolly-reveal,
  [data-scrolly-type="scale"],
  [data-scrolly-type="blur"],
  [data-scrolly-type="wipe"],
  .scrolly-depth__layer {
    opacity: 1 !important;
    transform: none !important;
    filter: none !important;
    clip-path: none !important;
  }

  .hero-glow {
    animation: none;
    opacity: 0.5;
  }
}

/* --- CSS View Timeline Progressive Enhancement --- */
@supports (animation-timeline: view()) {
  [data-scrolly="reveal"]:not(.js-controlled) {
    animation: cssRevealSlideUp linear both;
    animation-timeline: view();
    animation-range: entry 0% entry 35%;
    opacity: 1;
    transform: none;
    transition: none;
  }

  @keyframes cssRevealSlideUp {
    from { opacity: 0; transform: translateY(40px); }
    to   { opacity: 1; transform: translateY(0); }
  }

  [data-scrolly-type="scale"]:not(.js-controlled) {
    animation: cssRevealScale linear both;
    animation-timeline: view();
    animation-range: entry 0% entry 35%;
    opacity: 1;
    transform: none;
    transition: none;
  }

  @keyframes cssRevealScale {
    from { opacity: 0; transform: scale(0.92); }
    to   { opacity: 1; transform: scale(1); }
  }
}

/* --- Responsive --- */
@media (max-width: 768px) {
  :root {
    --section-pad: clamp(40px, 8vw, 60px);
    --nav-h: 56px;
  }

  .headline-xl {
    font-size: clamp(2rem, 8vw, 3rem);
  }

  /* Disable sticky scenes on mobile */
  .scrolly-sticky__pin {
    position: relative;
    height: auto;
    min-height: auto;
  }

  .scrolly-sticky__step {
    position: relative;
    opacity: 1;
    transform: none;
    pointer-events: auto;
    padding: 2rem 0;
  }

  .scrolly-dots { display: none; }

  /* Disable parallax on mobile */
  .scrolly-depth__layer {
    position: relative;
    inset: auto;
    transform: none !important;
  }

  /* Simplify reveals on mobile */
  [data-scrolly-type="split"] .split-char {
    display: inline;
    opacity: 1;
    transform: none;
    transition: none;
  }
}

@media (min-width: 769px) and (max-width: 1024px) {
  :root {
    --section-pad: clamp(50px, 8vw, 80px);
  }
}
