/* ==========================================================================
   CATEGORY 3: Kinetic Typography (Demos 16–22)
   Styles for Split-Text, Marquee, Matrix Scramble, Typewriter, Scroll Highlight,
   Rolling Slot-Machine, and Glitch RGB Split.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Shared Stage Container for Category 3
   -------------------------------------------------------------------------- */
.cat3-stage {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 1.25rem;
  background: radial-gradient(circle at 50% 50%, rgba(30, 41, 59, 0.35) 0%, rgba(11, 13, 18, 0.7) 100%);
  user-select: none;
  font-family: inherit;
}

/* Category 3 mini toolbar */
.cat3-controls {
  position: absolute;
  bottom: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  z-index: 10;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 9999px;
  padding: 0.25rem 0.6rem;
}

.cat3-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #f1f5f9;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: 9999px;
  cursor: pointer;
  transition: all calc(0.2s / var(--speed-mult, 1)) ease;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.cat3-btn:hover {
  background: rgba(99, 102, 241, 0.25);
  border-color: rgba(99, 102, 241, 0.5);
  color: #ffffff;
  transform: translateY(-1px);
}

.cat3-btn:active {
  transform: translateY(0);
}

.cat3-btn.active {
  background: #6366f1;
  border-color: #818cf8;
  color: #ffffff;
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.4);
}

/* --------------------------------------------------------------------------
   Demo 16: Split-Text Mask Reveal
   -------------------------------------------------------------------------- */
.demo-split-text {
  text-align: center;
  width: 100%;
}

.split-line-mask {
  display: block;
  overflow: hidden;
  padding: 0.15rem 0;
  line-height: 1.15;
}

.split-word-mask {
  display: inline-block;
  overflow: hidden;
  vertical-align: top;
  margin: 0 0.2em;
}

.split-word,
.split-char {
  display: inline-block;
  font-weight: 800;
  letter-spacing: -0.02em;
  transform: translateY(125%) rotate(4deg);
  opacity: 0;
  filter: blur(6px);
  will-change: transform, opacity, filter;
  transition: transform calc(var(--duration, 0.65s) / var(--speed-mult, 1)) var(--easing, cubic-bezier(0.16, 1, 0.3, 1)),
              opacity calc(var(--duration, 0.55s) / var(--speed-mult, 1)) ease,
              filter calc(var(--duration, 0.55s) / var(--speed-mult, 1)) ease;
}

.split-line-1 .split-word,
.split-line-1 .split-char {
  font-size: clamp(1.4rem, 3.2vw, 2.2rem);
  background: linear-gradient(135deg, #ffffff 30%, #94a3b8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.split-line-2 .split-word,
.split-line-2 .split-char {
  font-size: clamp(1.6rem, 3.8vw, 2.6rem);
  background: linear-gradient(135deg, #818cf8 0%, #c084fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 25px rgba(99, 102, 241, 0.3);
}

.demo-split-text.is-revealed .split-word,
.demo-split-text.is-revealed .split-char {
  transform: translateY(0) rotate(0deg);
  opacity: 1;
  filter: blur(0);
}

/* --------------------------------------------------------------------------
   Demo 17: Infinite Marquee
   -------------------------------------------------------------------------- */
.demo-marquee-wrapper {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  overflow: hidden;
  position: relative;
  mask-image: linear-gradient(to right, transparent, black 12%, black 88%, transparent);
  -webkit-mask-image: linear-gradient(to right, transparent, black 12%, black 88%, transparent);
}

.marquee-track-row {
  display: flex;
  width: max-content;
  will-change: transform;
}

.marquee-track-row.dir-left {
  animation: marqueeLeft calc(var(--duration, 24s) / var(--speed-mult, 1)) linear infinite;
}

.marquee-track-row.dir-right {
  animation: marqueeRight calc(var(--duration, 28s) / var(--speed-mult, 1)) linear infinite;
}

.demo-marquee-wrapper:hover .marquee-track-row,
.demo-marquee-wrapper.is-paused .marquee-track-row {
  animation-play-state: paused;
}

.marquee-track-row.speed-fast {
  animation-duration: calc(12s / var(--speed-mult, 1));
}

.marquee-track-row.speed-slow {
  animation-duration: calc(40s / var(--speed-mult, 1));
}

@keyframes marqueeLeft {
  0% {
    transform: translate3d(0, 0, 0);
  }
  100% {
    transform: translate3d(-50%, 0, 0);
  }
}

@keyframes marqueeRight {
  0% {
    transform: translate3d(-50%, 0, 0);
  }
  100% {
    transform: translate3d(0, 0, 0);
  }
}

.marquee-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 1rem;
  margin: 0 0.4rem;
  background: rgba(30, 41, 59, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 9999px;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #e2e8f0;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  transition: all calc(0.25s / var(--speed-mult, 1)) ease;
}

.marquee-pill:hover {
  background: rgba(99, 102, 241, 0.25);
  border-color: rgba(129, 140, 248, 0.6);
  color: #ffffff;
  transform: scale(1.05);
}

.marquee-pill .pill-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #6366f1;
  box-shadow: 0 0 6px #6366f1;
}

.marquee-pill.accent-pink .pill-dot {
  background: #f43f5e;
  box-shadow: 0 0 6px #f43f5e;
}

.marquee-pill.accent-cyan .pill-dot {
  background: #06b6d4;
  box-shadow: 0 0 6px #06b6d4;
}

.marquee-pill.accent-emerald .pill-dot {
  background: #10b981;
  box-shadow: 0 0 6px #10b981;
}

/* --------------------------------------------------------------------------
   Demo 18: Text Scramble / Matrix Decode
   -------------------------------------------------------------------------- */
.demo-scramble-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 440px;
  padding: 1.2rem;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(56, 189, 248, 0.2);
  border-radius: 12px;
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.scramble-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.68rem;
  color: #38bdf8;
  letter-spacing: 0.1em;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid rgba(56, 189, 248, 0.15);
  padding-bottom: 0.4rem;
}

.scramble-status-beacon {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.scramble-status-beacon::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
  animation: beaconPulse calc(1.5s / var(--speed-mult, 1)) infinite ease-in-out;
}

@keyframes beaconPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

.scramble-output {
  font-family: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
  font-size: clamp(1.15rem, 2.5vw, 1.45rem);
  font-weight: 700;
  letter-spacing: 0.08em;
  min-height: 2.2em;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #f8fafc;
  word-break: break-all;
}

.scramble-char-lock {
  color: #38bdf8;
  text-shadow: 0 0 10px rgba(56, 189, 248, 0.5);
}

.scramble-char-mutating {
  color: #f43f5e;
  text-shadow: 0 0 10px rgba(244, 63, 94, 0.8);
  font-weight: 800;
}

/* --------------------------------------------------------------------------
   Demo 19: Typewriter + Blinking Caret
   -------------------------------------------------------------------------- */
.demo-typewriter-window {
  width: 100%;
  max-width: 460px;
  background: #090d16;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
}

.typewriter-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.8rem;
  background: rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.window-dots {
  display: flex;
  gap: 0.35rem;
}

.window-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.window-dot.dot-red { background: #ef4444; }
.window-dot.dot-yellow { background: #f59e0b; }
.window-dot.dot-green { background: #10b981; }

.window-title {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.68rem;
  color: #64748b;
  letter-spacing: 0.04em;
}

.typewriter-body {
  padding: 1rem 1.1rem;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.95rem;
  line-height: 1.5;
  color: #f1f5f9;
  min-height: 4.8rem;
  display: flex;
  align-items: center;
}

.typewriter-prompt-symbol {
  color: #818cf8;
  margin-right: 0.6rem;
  user-select: none;
}

.typewriter-text {
  color: #e2e8f0;
}

.typewriter-cursor {
  display: inline-block;
  width: 8px;
  height: 1.15em;
  background: #a855f7;
  vertical-align: text-bottom;
  margin-left: 2px;
  box-shadow: 0 0 8px rgba(168, 85, 247, 0.8);
  animation: caretBlink calc(0.8s / var(--speed-mult, 1)) steps(1) infinite;
}

@keyframes caretBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* --------------------------------------------------------------------------
   Demo 20: Scroll Text Highlight
   -------------------------------------------------------------------------- */
.demo-scroll-highlight-wrap {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.scrub-slider-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.72rem;
  color: #94a3b8;
  font-weight: 600;
}

.scrub-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 9999px;
  outline: none;
  cursor: pointer;
}

.scrub-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #6366f1;
  border: 2px solid #ffffff;
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.7);
  cursor: pointer;
  transition: transform 0.15s ease;
}

.scrub-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.scroll-text-viewport {
  height: 120px;
  overflow-y: auto;
  padding: 0.85rem 1rem;
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  font-size: 0.95rem;
  line-height: 1.7;
  scroll-behavior: auto; /* auto allows crisp drag without fighting async smooth-scroll */
}

.scroll-text-viewport::-webkit-scrollbar {
  width: 6px;
}
.scroll-text-viewport::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
}
.scroll-text-viewport::-webkit-scrollbar-thumb {
  background: rgba(99, 102, 241, 0.4);
  border-radius: 9999px;
}

.hl-word {
  display: inline-block;
  color: #475569;
  opacity: 0.25;
  filter: blur(0.4px);
  transform: translateY(0) scale(0.98);
  margin-right: 0.25em;
  will-change: color, opacity, filter, transform;
  transition: color calc(var(--duration, 0.3s) / var(--speed-mult, 1)) var(--easing, ease),
              opacity calc(var(--duration, 0.3s) / var(--speed-mult, 1)) var(--easing, ease),
              filter calc(var(--duration, 0.3s) / var(--speed-mult, 1)) var(--easing, ease),
              transform calc(var(--duration, 0.3s) / var(--speed-mult, 1)) var(--easing, ease);
}

.hl-word.lit {
  color: #f8fafc;
  opacity: 1;
  filter: blur(0);
  transform: translateY(0) scale(1);
  text-shadow: 0 0 12px rgba(129, 140, 248, 0.6);
}

/* --------------------------------------------------------------------------
   Demo 21: Rolling / Slot-Machine Text
   -------------------------------------------------------------------------- */
.demo-rolling-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

.rolling-words-row {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0.5rem 1.2rem;
  background: rgba(30, 41, 59, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  transition: border-color calc(0.3s / var(--speed-mult, 1)) ease;
}

.rolling-words-row:hover {
  border-color: rgba(99, 102, 241, 0.5);
}

.rolling-char-box {
  display: inline-block;
  overflow: hidden;
  height: 2.2rem;
  vertical-align: middle;
}

.rolling-track {
  display: flex;
  flex-direction: column;
  transform: translate3d(0, 0, 0);
  will-change: transform;
  transition: transform calc(var(--duration, 0.65s) / var(--speed-mult, 1)) var(--easing, cubic-bezier(0.34, 1.4, 0.64, 1));
}

.demo-rolling-container.is-rolled .rolling-track {
  transform: translate3d(0, -50%, 0);
}

.rolling-char-val {
  height: 2.2rem;
  line-height: 2.2rem;
  font-size: clamp(1.4rem, 3.2vw, 2rem);
  font-weight: 800;
  text-align: center;
}

.rolling-char-val.primary {
  color: #e2e8f0;
}

.rolling-char-val.secondary {
  background: linear-gradient(135deg, #38bdf8 0%, #818cf8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 16px rgba(56, 189, 248, 0.4);
}

/* Rolling Odometer Counter */
.odometer-card {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.4rem 0.9rem;
  background: #090d16;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
}

.odometer-digit-col {
  height: 1.8rem;
  overflow: hidden;
  position: relative;
}

.odometer-track {
  display: flex;
  flex-direction: column;
  transition: transform calc(var(--duration, 0.8s) / var(--speed-mult, 1)) var(--easing, cubic-bezier(0.16, 1, 0.3, 1));
  will-change: transform;
}

.odometer-num {
  height: 1.8rem;
  line-height: 1.8rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.15rem;
  font-weight: 700;
  color: #10b981;
  text-align: center;
}

.odometer-sym {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.15rem;
  font-weight: 700;
  color: #94a3b8;
}

/* --------------------------------------------------------------------------
   Demo 22: Glitch / RGB Split
   -------------------------------------------------------------------------- */
.demo-glitch-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.glitch-title {
  position: relative;
  font-size: clamp(1.8rem, 4vw, 2.7rem);
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #ffffff;
  user-select: none;
  cursor: pointer;
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.2);
}

.glitch-title::before,
.glitch-title::after {
  content: attr(data-text);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
}

.glitch-title::before {
  left: 2px;
  text-shadow: -2px 0 #00f0ff;
  color: #00f0ff;
  opacity: 0.8;
  mix-blend-mode: screen;
}

.glitch-title::after {
  left: -2px;
  text-shadow: 2px 0 #ff0055;
  color: #ff0055;
  opacity: 0.8;
  mix-blend-mode: screen;
}

/* Burst active state */
.demo-glitch-stage.is-glitching .glitch-title::before {
  animation: glitchSlice1 calc(0.35s / var(--speed-mult, 1)) infinite linear;
}

.demo-glitch-stage.is-glitching .glitch-title::after {
  animation: glitchSlice2 calc(0.35s / var(--speed-mult, 1)) infinite linear;
}

.demo-glitch-stage.is-glitching .glitch-title {
  animation: glitchJitter calc(0.2s / var(--speed-mult, 1)) infinite;
}

@keyframes glitchSlice1 {
  0% {
    clip-path: polygon(0 15%, 100% 15%, 100% 28%, 0 28%);
    transform: translate(-4px, 1px);
  }
  20% {
    clip-path: polygon(0 60%, 100% 60%, 100% 75%, 0 75%);
    transform: translate(5px, -2px);
  }
  40% {
    clip-path: polygon(0 2%, 100% 2%, 100% 18%, 0 18%);
    transform: translate(-3px, 2px);
  }
  60% {
    clip-path: polygon(0 80%, 100% 80%, 100% 98%, 0 98%);
    transform: translate(4px, 1px);
  }
  80% {
    clip-path: polygon(0 40%, 100% 40%, 100% 52%, 0 52%);
    transform: translate(-5px, -1px);
  }
  100% {
    clip-path: polygon(0 15%, 100% 15%, 100% 28%, 0 28%);
    transform: translate(-4px, 1px);
  }
}

@keyframes glitchSlice2 {
  0% {
    clip-path: polygon(0 70%, 100% 70%, 100% 85%, 0 85%);
    transform: translate(4px, -2px);
  }
  25% {
    clip-path: polygon(0 30%, 100% 30%, 100% 45%, 0 45%);
    transform: translate(-4px, 1px);
  }
  50% {
    clip-path: polygon(0 5%, 100% 5%, 100% 22%, 0 22%);
    transform: translate(3px, 3px);
  }
  75% {
    clip-path: polygon(0 88%, 100% 88%, 100% 99%, 0 99%);
    transform: translate(-3px, -2px);
  }
  100% {
    clip-path: polygon(0 70%, 100% 70%, 100% 85%, 0 85%);
    transform: translate(4px, -2px);
  }
}

@keyframes glitchJitter {
  0% { transform: translate(0, 0); }
  25% { transform: translate(-1px, 1px) skewX(0.5deg); }
  50% { transform: translate(1px, -1px) skewX(-0.5deg); }
  75% { transform: translate(-1px, -1px); }
  100% { transform: translate(0, 0); }
}

/* Reduced Motion Override for Category 3 */
.reduced-motion .split-word,
.reduced-motion .split-char,
.reduced-motion .marquee-track-row,
.reduced-motion .rolling-track,
.reduced-motion .odometer-track,
.reduced-motion .hl-word {
  animation: none !important;
  transition: none !important;
  transform: none !important;
  opacity: 1 !important;
  filter: none !important;
}

.reduced-motion .glitch-title::before,
.reduced-motion .glitch-title::after {
  display: none !important;
}
