/* ============================================
   SHVETS VENTURES - FX layer
   Motion, tilt, gyroscope, small delights.
   Everything here is progressive: without JS
   the site looks exactly as before.
   ============================================ */

:root {
  /* Smoothed tilt, -1..1. Set by js/fx.js from the gyroscope or the mouse. */
  --tx: 0;
  --ty: 0;
}

/* Scroll progress */
.fx-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  z-index: 200;
  background: var(--color-text);
  transform: scaleX(0);
  transform-origin: 0 0;
  pointer-events: none;
}

/* Hero dot field */
.hero,
.page-hero {
  position: relative;
  overflow: hidden;
}

.fx-field {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(to bottom, #000 60%, transparent);
  mask-image: linear-gradient(to bottom, #000 60%, transparent);
}

.hero > .container,
.page-hero > .container {
  position: relative;
  z-index: 1;
}

/* Hero parallax: layers drift against the tilt */
.fx-on .hero h1,
.fx-on .page-hero h1 {
  translate: calc(var(--tx) * -12px) calc(var(--ty) * -8px);
}

.fx-on .hero .hero-status {
  translate: calc(var(--tx) * -20px) calc(var(--ty) * -12px);
}

.fx-on .hero h1 + p,
.fx-on .page-hero h1 + p {
  translate: calc(var(--tx) * -6px) calc(var(--ty) * -4px);
}

/* Headline: word-by-word rise */
.fx-word {
  display: inline-block;
  overflow: hidden;
  vertical-align: top;
  padding-bottom: 0.08em;
  margin-bottom: -0.08em;
}

.fx-word > span {
  display: inline-block;
  transform: translateY(105%);
  animation: fxRise 0.9s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  animation-delay: calc(var(--i) * 70ms + 100ms);
  transition: color 0.3s;
}

.fx-word > span.is-ready {
  animation: none;
  transform: none;
}

.fx-word > span.is-bounce {
  animation: fxBounce 0.5s cubic-bezier(0.3, 1.6, 0.5, 1);
}

@keyframes fxRise {
  to { transform: translateY(0); }
}

@keyframes fxBounce {
  0% { transform: translateY(0); }
  40% { transform: translateY(-18%) rotate(-3deg); }
  100% { transform: translateY(0); }
}

@media (hover: hover) {
  .fx-word > span:hover {
    color: var(--color-live);
  }
}

/* Scroll reveal (translate, not transform, so it composes with tilt) */
.fx-reveal {
  opacity: 0;
  translate: 0 28px;
  transition: opacity 0.7s ease, translate 0.7s cubic-bezier(0.2, 0.8, 0.2, 1);
  transition-delay: calc(var(--i, 0) * 90ms);
}

.fx-reveal.is-in {
  opacity: 1;
  translate: 0 0;
}

/* Tilt cards + glare */
.fx-tilt {
  position: relative;
  overflow: hidden;
  transform: perspective(900px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg));
  transition: transform 0.25s ease-out, border-color 0.3s;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.fx-glare {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at var(--gx, 50%) var(--gy, 50%), rgba(255, 255, 255, 0.13), transparent 55%);
  opacity: var(--glare, 0);
  transition: opacity 0.4s;
}

.terminal-mode .fx-glare {
  background: radial-gradient(circle at var(--gx, 50%) var(--gy, 50%), rgba(91, 228, 155, 0.18), transparent 55%);
}

/* Phone: the gyroscope drives every card at once, like a hologram */
.fx-gyro .fx-tilt {
  --rx: calc(var(--ty) * -6deg);
  --ry: calc(var(--tx) * 6deg);
  transition: border-color 0.3s;
}

.fx-gyro .fx-tilt,
.fx-gyro .fx-glare-host {
  --gx: calc(50% + var(--tx) * 70%);
  --gy: calc(50% + var(--ty) * 70%);
  --glare: 1;
}

/* Tap ripple */
.fx-ripple-host {
  position: relative;
  overflow: hidden;
}

.fx-ripple {
  position: absolute;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.25;
  pointer-events: none;
  transform: scale(0);
  animation: fxRipple 0.65s ease-out forwards;
}

@keyframes fxRipple {
  to { transform: scale(var(--s, 30)); opacity: 0; }
}

/* Magnetic primary button */
.btn-primary {
  transition: all var(--transition), translate 0.2s ease-out;
  translate: var(--mx, 0) var(--my, 0);
}

/* Mobile menu: burger to X, staggered links */
.menu-toggle {
  position: relative;
  z-index: 110;
}

.menu-toggle span {
  transform-origin: center;
}

.menu-toggle.active span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.menu-toggle.active span:nth-child(2) {
  opacity: 0;
  transform: scaleX(0);
}

.menu-toggle.active span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

@media (max-width: 768px) {
  nav {
    z-index: 105;
  }

  nav a {
    opacity: 0;
    translate: 40px 0;
    transition: opacity 0.4s ease, translate 0.5s cubic-bezier(0.2, 0.8, 0.2, 1), color var(--transition);
  }

  nav.active a {
    opacity: 1;
    translate: 0 0;
  }

  nav.active a:nth-child(1) { transition-delay: 0.08s; }
  nav.active a:nth-child(2) { transition-delay: 0.14s; }
  nav.active a:nth-child(3) { transition-delay: 0.20s; }
  nav.active a:nth-child(4) { transition-delay: 0.26s; }
}

/* Motion permission chip (iOS) */
.motion-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: var(--spacing-md);
  padding: 8px 16px;
  border: 1px dashed var(--color-border);
  border-radius: 999px;
  background: transparent;
  color: var(--color-text);
  font: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: border-color 0.3s, opacity 0.5s, translate 0.5s;
}

.motion-chip:active {
  scale: 0.96;
}

.motion-chip .phone {
  display: inline-block;
  animation: fxWiggle 2.4s ease-in-out infinite;
}

.motion-chip.is-done {
  opacity: 0;
  translate: 0 -8px;
  pointer-events: none;
}

@keyframes fxWiggle {
  0%, 60%, 100% { transform: rotate(0); }
  70% { transform: rotate(-18deg); }
  80% { transform: rotate(14deg); }
  90% { transform: rotate(-8deg); }
}

/* Spirit level easter egg */
.fx-level {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 300;
  width: 140px;
  height: 140px;
  margin: -70px 0 0 -70px;
  border: 1px solid var(--color-border);
  border-radius: 50%;
  background: rgba(10, 10, 10, 0.85);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  opacity: 0;
  scale: 0.8;
  pointer-events: none;
  transition: opacity 0.4s, scale 0.4s, border-color 0.3s;
}

.fx-level.is-visible {
  opacity: 1;
  scale: 1;
}

.fx-level::before,
.fx-level::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  border: 1px solid var(--color-border);
  border-radius: 50%;
}

.fx-level::before {
  width: 36px;
  height: 36px;
  margin: -18px 0 0 -18px;
}

.fx-level::after {
  width: 90px;
  height: 90px;
  margin: -45px 0 0 -45px;
  border-style: dashed;
}

.fx-level-bubble {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  border-radius: 50%;
  background: var(--color-text-muted);
  transition: background 0.3s;
}

.fx-level-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -28px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.fx-level.is-level {
  border-color: var(--color-live);
}

.fx-level.is-level .fx-level-bubble {
  background: var(--color-live);
}

/* Upside-down egg */
.logo {
  display: inline-block;
  transition: rotate 0.6s cubic-bezier(0.3, 1.4, 0.5, 1);
}

.fx-upside .logo {
  rotate: 180deg;
}

/* Shake egg: brief jolt */
.fx-jolt body {
  animation: fxJolt 0.4s ease;
}

@keyframes fxJolt {
  20% { translate: -6px 0; }
  40% { translate: 5px 0; }
  60% { translate: -3px 0; }
  80% { translate: 2px 0; }
}

/* Status pill is a ping button now */
.hero-status {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.3s, scale 0.2s;
}

.hero-status:hover {
  border-color: var(--color-text-muted);
}

.hero-status:active {
  scale: 0.96;
}

.hero-meta [data-count] {
  font-variant-numeric: tabular-nums;
}

/* Taps on phones: no grey flash, the ripple does that job */
.fx-ripple-host,
.fx-tilt {
  -webkit-tap-highlight-color: transparent;
}

@media (prefers-reduced-motion: reduce) {
  .fx-word > span {
    transform: none;
    animation: none;
  }

  .fx-reveal {
    opacity: 1;
    translate: none;
    transition: none;
  }

  .fx-on .hero h1,
  .fx-on .page-hero h1,
  .fx-on .hero .hero-status,
  .fx-on .hero h1 + p,
  .fx-on .page-hero h1 + p {
    translate: none;
  }

  .fx-tilt {
    transform: none;
  }

  .motion-chip .phone,
  .fx-jolt body {
    animation: none;
  }
}

/* Toast: size to its text, not to half the screen */
.toast {
  width: max-content;
  max-width: calc(100vw - 32px);
  text-align: center;
  border-radius: 20px;
}

.page-hero h1 {
  margin-bottom: var(--spacing-sm);
}

/* 404 ball game */
.ball-game {
  margin-top: var(--spacing-lg);
  max-width: 640px;
}

.ball-hint {
  margin-bottom: var(--spacing-sm);
  font-size: 0.875rem;
}

.ball-field {
  position: relative;
  height: 220px;
  border: 1px solid var(--color-border);
  background:
    radial-gradient(circle, var(--color-border) 1px, transparent 1.5px) 0 0 / 22px 22px;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.4s;
}

.ball-field:focus-visible {
  outline: 2px solid var(--color-text);
  outline-offset: 3px;
}

.ball-field.is-won {
  border-color: var(--color-live);
}

.ball-field .ball,
.ball-field .hole {
  position: absolute;
  left: 0;
  top: 0;
  border-radius: 50%;
  will-change: transform;
}

.ball-field .hole {
  width: 52px;
  height: 52px;
  background: #000;
  box-shadow: inset 0 4px 10px rgba(0, 0, 0, 0.9), 0 0 0 1px var(--color-border);
}

.ball-field .hole span {
  position: absolute;
  left: 50%;
  top: calc(100% + 6px);
  translate: -50% 0;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--color-text-muted);
}

.ball-field.is-won .hole {
  box-shadow: inset 0 4px 10px rgba(0, 0, 0, 0.9), 0 0 0 2px var(--color-live), 0 0 24px rgba(91, 228, 155, 0.4);
}

.ball-field .ball {
  width: 28px;
  height: 28px;
  background: radial-gradient(circle at 35% 30%, #fff, #bbb 60%, #777);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.6);
  cursor: grab;
}

.ball-field .ball.is-grabbed {
  cursor: grabbing;
}

.ball-field .ball.is-sunk {
  animation: ballSink 0.6s ease-in forwards;
}

@keyframes ballSink {
  to { opacity: 0; scale: 0.2; }
}
