/* ==========================================================================
   MANDOCMD — fx: preloader, grain, cursor, marquee, glitch, speed lines
   ========================================================================== */

/* ---------- preloader ---------- */
.preloader {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  background: var(--ink);
}

.preloader__panel {
  position: absolute;
  left: 0;
  width: 100%;
  height: 50.2%;
  background: var(--ink);
  transition: transform 0.9s var(--ease);
}
.preloader__panel--top { top: 0; }
.preloader__panel--bot { bottom: 0; }

.preloader.is-done { pointer-events: none; }
.preloader.is-done .preloader__panel--top { transform: translateY(-101%); }
.preloader.is-done .preloader__panel--bot { transform: translateY(101%); }
.preloader.is-done .preloader__core { opacity: 0; transform: scale(0.94); }

.preloader__core {
  position: relative;
  z-index: 2;
  display: grid;
  justify-items: center;
  gap: 18px;
  transition: opacity 0.4s ease, transform 0.6s var(--ease);
}

.tacho { width: clamp(160px, 26vw, 220px); height: auto; overflow: visible; }
.tacho__track { fill: none; stroke: rgba(243, 233, 216, 0.12); stroke-width: 6; stroke-linecap: round; }
.tacho__fill {
  fill: none;
  stroke: var(--orange);
  stroke-width: 6;
  stroke-linecap: round;
  filter: drop-shadow(0 0 10px rgba(242, 107, 29, 0.6));
  stroke-dasharray: 340;
  stroke-dashoffset: 340;
  transition: stroke-dashoffset 0.25s linear;
}
.tacho__needle { transform-origin: 100px 100px; transition: transform 0.25s var(--ease-in-out); }
.tacho__needle line { stroke: var(--cream); stroke-width: 3; stroke-linecap: round; }
.tacho__hub { fill: var(--orange); }

.preloader__num {
  font-family: var(--display);
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  letter-spacing: 0.06em;
  color: var(--cream);
  font-variant-numeric: tabular-nums;
}
.preloader__label {
  font-family: ui-monospace, monospace;
  font-size: 0.66rem;
  letter-spacing: 0.44em;
  text-transform: uppercase;
  color: var(--orange);
}

/* ---------- fixed overlays ---------- */
.grain,
.scanlines,
.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 40;
}

.grain {
  opacity: 0.28;
  mix-blend-mode: overlay;
  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='3'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
  animation: grain-shift 0.6s steps(3) infinite;
}

@keyframes grain-shift {
  0% { transform: translate(0, 0); }
  33% { transform: translate(-3%, 2%); }
  66% { transform: translate(2%, -3%); }
  100% { transform: translate(0, 0); }
}

.scanlines {
  opacity: 0.075;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.5) 3px,
    rgba(0, 0, 0, 0) 4px
  );
}

.vignette {
  background: radial-gradient(120% 80% at 50% 40%, transparent 45%, rgba(0, 0, 0, 0.62) 100%);
}

/* ---------- cursor ---------- */
.cursor,
.cursor-dot {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 150;
  pointer-events: none;
  border-radius: 50%;
  transform: translate3d(-50%, -50%, 0);
  will-change: transform;
}

.cursor {
  width: 34px;
  height: 34px;
  border: 1px solid rgba(243, 233, 216, 0.55);
  transition: width 0.35s var(--ease), height 0.35s var(--ease), background 0.35s, border-color 0.35s, opacity 0.3s;
}

.cursor-dot {
  width: 5px;
  height: 5px;
  background: var(--orange);
  transition: opacity 0.3s;
}

.cursor.is-hot {
  width: 74px;
  height: 74px;
  background: rgba(242, 107, 29, 0.16);
  border-color: var(--orange);
  mix-blend-mode: normal;
}

.cursor.is-hot::after {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  width: 5px;
  height: 5px;
  margin: -2.5px 0 0 -2.5px;
  border-radius: 50%;
  background: var(--orange);
}

body.no-cursor .cursor,
body.no-cursor .cursor-dot { opacity: 0; }

@media (hover: none), (pointer: coarse) {
  .cursor, .cursor-dot { display: none; }
}

/* ---------- spotlight ---------- */
.spotlight {
  position: fixed;
  top: 0;
  left: 0;
  width: 720px;
  height: 720px;
  margin: -360px 0 0 -360px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 1;
  background: radial-gradient(circle, rgba(242, 107, 29, 0.13) 0%, rgba(242, 107, 29, 0.05) 38%, transparent 68%);
  will-change: transform;
  mix-blend-mode: screen;
}

/* ---------- scroll progress ---------- */
.progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 100%;
  z-index: 120;
  transform-origin: 0 50%;
  transform: scaleX(0);
  background: linear-gradient(90deg, var(--orange), #ffd08a);
  box-shadow: 0 0 18px rgba(242, 107, 29, 0.8);
}

/* ---------- marquee ---------- */
.marquee {
  position: relative;
  overflow: hidden;
  border-block: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(242, 107, 29, 0.07), rgba(242, 107, 29, 0));
  padding-block: clamp(12px, 1.6vw, 20px);
  --skew: 0deg;
}

.marquee__track {
  display: flex;
  width: max-content;
  animation: marquee-run 34s linear infinite;
  will-change: transform;
  transform: skewX(var(--skew));
}

.marquee--fast .marquee__track { animation-duration: 18s; }
.marquee--rev .marquee__track { animation-direction: reverse; }

.marquee__group {
  display: flex;
  align-items: center;
  gap: 0;
  flex: none;
}

.marquee__item {
  display: inline-flex;
  align-items: center;
  gap: clamp(14px, 2.4vw, 34px);
  padding-inline: clamp(14px, 2.4vw, 34px);
  font-family: var(--display);
  font-size: clamp(1.1rem, 2.4vw, 1.9rem);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(243, 233, 216, 0.5);
  white-space: nowrap;
}

.marquee__item em {
  font-style: normal;
  color: var(--orange);
}

.marquee__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--orange);
  flex: none;
  box-shadow: 0 0 12px var(--orange);
}

@keyframes marquee-run {
  from { transform: translate3d(0, 0, 0) skewX(var(--skew)); }
  to { transform: translate3d(-50%, 0, 0) skewX(var(--skew)); }
}

/* ---------- reveal ---------- */
[data-reveal] {
  opacity: 0;
  transform: translate3d(0, 34px, 0);
  transition: opacity 0.9s var(--ease), transform 1s var(--ease);
  transition-delay: calc(var(--i, 0) * 90ms);
  will-change: opacity, transform;
}

[data-reveal="left"] { transform: translate3d(-40px, 0, 0); }
[data-reveal="scale"] { transform: scale(0.94); }
[data-reveal].in { opacity: 1; transform: none; }

/* ---------- split text ---------- */
.split-line { display: block; overflow: hidden; }
.split-line > span { display: inline-block; transform: translateY(105%); transition: transform 1.05s var(--ease); }
.in .split-line > span,
.split-line.in > span { transform: translateY(0); }
.split-line:nth-child(2) > span { transition-delay: 0.08s; }
.split-line:nth-child(3) > span { transition-delay: 0.16s; }

/* ---------- glitch ---------- */
.glitch { position: relative; display: inline-block; }
.glitch::before,
.glitch::after {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  pointer-events: none;
  clip-path: inset(0 0 0 0);
  opacity: 0;
}
.glitch:hover::before {
  opacity: 0.85;
  color: var(--orange);
  animation: glitch-a 0.45s steps(2) infinite;
}
.glitch:hover::after {
  opacity: 0.6;
  color: var(--cream);
  animation: glitch-b 0.4s steps(2) infinite;
}

@keyframes glitch-a {
  0% { clip-path: inset(0 0 72% 0); transform: translate(-3px, -2px); }
  50% { clip-path: inset(58% 0 12% 0); transform: translate(3px, 2px); }
  100% { clip-path: inset(24% 0 40% 0); transform: translate(-2px, 1px); }
}
@keyframes glitch-b {
  0% { clip-path: inset(70% 0 4% 0); transform: translate(3px, 2px); }
  50% { clip-path: inset(12% 0 62% 0); transform: translate(-4px, -2px); }
  100% { clip-path: inset(44% 0 28% 0); transform: translate(2px, -1px); }
}

/* ---------- speed lines (easter egg) ---------- */
.speedlines {
  position: fixed;
  inset: 0;
  z-index: 140;
  pointer-events: none;
  opacity: 0;
  background:
    repeating-conic-gradient(from 0deg at 50% 50%, rgba(243, 233, 216, 0.5) 0deg 0.35deg, transparent 0.35deg 3.2deg);
  mask-image: radial-gradient(circle at 50% 50%, transparent 12%, #000 42%, #000 100%);
  -webkit-mask-image: radial-gradient(circle at 50% 50%, transparent 12%, #000 42%, #000 100%);
  transition: opacity 0.18s ease;
  animation: spin 6s linear infinite;
}

.speedlines.is-on { opacity: 0.22; animation-duration: 0.55s; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 160;
  transform: translate(-50%, 140%);
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 14px 22px;
  border-radius: 999px;
  border: 1px solid var(--orange);
  background: rgba(14, 14, 14, 0.92);
  backdrop-filter: blur(10px);
  font-family: ui-monospace, monospace;
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--cream);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.6);
  transition: transform 0.6s var(--ease), opacity 0.4s;
  opacity: 0;
  pointer-events: none;
}

.toast.is-on { transform: translate(-50%, 0); opacity: 1; }
.toast__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--orange); animation: blink 1s steps(2) infinite; }

@keyframes blink { 50% { opacity: 0.2; } }

/* ---------- misc ---------- */
.to-top {
  position: fixed;
  right: clamp(16px, 3vw, 32px);
  bottom: clamp(16px, 3vw, 32px);
  z-index: 70;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: rgba(19, 19, 19, 0.8);
  backdrop-filter: blur(8px);
  color: var(--cream);
  opacity: 0;
  transform: translateY(20px) scale(0.9);
  pointer-events: none;
  transition: opacity 0.4s, transform 0.5s var(--ease), border-color 0.3s, background 0.3s;
}

.to-top.is-on { opacity: 1; transform: none; pointer-events: auto; }
.to-top:hover { border-color: var(--orange); background: var(--orange); color: #120a04; }

@media (max-width: 720px) {
  .to-top { width: 40px; height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .grain, .scanlines, .marquee__track, .speedlines { animation: none !important; }
  [data-reveal] { opacity: 1 !important; transform: none !important; }
  .split-line > span { transform: none !important; }
  * { transition-duration: 0.01ms !important; }
}
