/* =====================================================================
   Web Textures Kit — textures.css
   Pure-CSS textures. Pair with textures.js for the canvas/SVG effects
   (pixel mosaic, ASCII, grass, dither, impressionist, caustics,
   stipple, topographic, monochrome landscape, lens distortion, tilt).
   Every class is prefixed tx-. Tweak with the --tx-* variables.
   ===================================================================== */

:root {
  --tx-grain-img: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='g'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix type='saturate' values='0'/></filter><rect width='100%25' height='100%25' filter='url(%23g)'/></svg>");
  --tx-iri: #ff9ae6, #a79bff, #7fe7ff, #9dffb5, #fff59a, #ffb38a, #ff9ae6;
}

/* Elements that use pseudo-element layers */
.tx-grain, .tx-grainy, .tx-noise, .tx-halftone, .tx-fluted, .tx-blur-photo,
.tx-cloudy, .tx-thermal-live, .tx-iridescent, .tx-vignette {
  position: relative;
  isolation: isolate;
  overflow: clip; /* clip, not hidden: keeps position:sticky children working */
}

/* ---------- Generic film grain overlay (add to anything) ---------- */
.tx-grain::after, .tx-grainy::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: var(--tx-grain-img);
  opacity: var(--tx-grain, .3);
  mix-blend-mode: overlay;
}

/* ---------- 1. Thermal gradients ---------- */
.tx-thermal, .tx-thermal-live {
  --tx-thermal-spots:
    radial-gradient(40% 50% at 28% 38%, #fffbe0 0%, #ffe14d 14%, #ff8a00 30%, #ff1f3d 48%, #a1008f 66%, transparent 82%),
    radial-gradient(35% 45% at 74% 64%, #fff3a0 0%, #ffb300 16%, #ff3c28 36%, #b0007a 58%, transparent 80%),
    radial-gradient(60% 60% at 60% 8%, #6a00ff 0%, transparent 70%);
  --tx-thermal-base: linear-gradient(160deg, #050530, #140b5c 45%, #0a1f6b);
  color: #fff;
}
.tx-thermal { background: var(--tx-thermal-spots), var(--tx-thermal-base); }
.tx-thermal-live { background: var(--tx-thermal-base); }
.tx-thermal-live::before {
  content: "";
  position: absolute;
  inset: -25%;
  z-index: -1;
  background: var(--tx-thermal-spots);
  filter: blur(26px) saturate(1.15);
  animation: tx-heat 14s ease-in-out infinite alternate;
}
@keyframes tx-heat {
  0%   { transform: translate(0, 0) scale(1) rotate(0deg); }
  50%  { transform: translate(-5%, 4%) scale(1.1) rotate(8deg); }
  100% { transform: translate(4%, -3%) scale(.95) rotate(-6deg); }
}

/* ---------- 2. Paper texture ---------- */
.tx-paper {
  background-color: var(--tx-paper, #f4efe4);
  background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='400' height='400'><filter id='p'><feTurbulence type='fractalNoise' baseFrequency='.035' numOctaves='5' stitchTiles='stitch' result='t'/><feDiffuseLighting in='t' lighting-color='%23fff' surfaceScale='1.6'><feDistantLight azimuth='45' elevation='62'/></feDiffuseLighting></filter><rect width='100%25' height='100%25' filter='url(%23p)'/></svg>"),
                    url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='f'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix type='saturate' values='0'/></filter><rect width='100%25' height='100%25' filter='url(%23f)' opacity='.35'/></svg>");
  background-blend-mode: multiply, multiply;
  color: #2b2620;
}

/* ---------- 3. Grainy gradients ---------- */
.tx-grainy {
  --tx-grain: .5;
  background:
    radial-gradient(at 18% 22%, var(--tx-c1, #ff7a59) 0, transparent 55%),
    radial-gradient(at 82% 18%, var(--tx-c2, #7b61ff) 0, transparent 50%),
    radial-gradient(at 72% 85%, var(--tx-c3, #00c2a8) 0, transparent 55%),
    radial-gradient(at 12% 92%, var(--tx-c4, #ffd166) 0, transparent 50%),
    var(--tx-c0, #f7ecdf);
}

/* ---------- 5. Cloudy sky ---------- */
.tx-cloudy { background: linear-gradient(#3d82d6, #8ec5f2 62%, #d4ebfb); }
.tx-cloudy::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='900' height='600'><filter id='c' x='0' y='0' width='100%25' height='100%25' color-interpolation-filters='sRGB'><feTurbulence type='fractalNoise' baseFrequency='.005 .011' numOctaves='6' seed='4' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  2.6 0 0 0 -1.15'/><feGaussianBlur stdDeviation='1.2'/></filter><rect width='100%25' height='100%25' filter='url(%23c)'/></svg>") 0 0 / 900px 600px repeat;
  animation: tx-drift 120s linear infinite;
}
@keyframes tx-drift { to { background-position: 900px 0; } }

/* ---------- 6. Blueprint grids ---------- */
.tx-blueprint {
  --tx-line: rgba(255, 255, 255, .32);
  --tx-line-soft: rgba(255, 255, 255, .1);
  background-color: var(--tx-blue, #0d3b78);
  background-image:
    linear-gradient(var(--tx-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--tx-line) 1px, transparent 1px),
    linear-gradient(var(--tx-line-soft) 1px, transparent 1px),
    linear-gradient(90deg, var(--tx-line-soft) 1px, transparent 1px);
  background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;
  background-position: -1px -1px;
  color: #e8f1ff;
  font-family: ui-monospace, Consolas, "Courier New", monospace;
}

/* ---------- 7. Blurred photos ----------
   set --tx-photo: url(photo.jpg) on the element */
.tx-blur-photo { background: #222; color: #fff; }
.tx-blur-photo::before {
  content: "";
  position: absolute;
  inset: -60px;
  z-index: -1;
  background: var(--tx-photo) center / cover;
  filter: blur(var(--tx-blur, 36px)) saturate(1.35) brightness(.92);
}

/* ---------- 8. Halftone ----------
   --tx-tone: the gradient to render; --tx-ink: dot colour; --tx-dot: cell size */
.tx-halftone { background: #fff; }
.tx-halftone::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(closest-side, #888, #fff) 0 0 / var(--tx-dot, 12px) var(--tx-dot, 12px),
    var(--tx-tone, linear-gradient(135deg, #000, #fff));
  background-blend-mode: multiply;
  filter: contrast(24);
}
.tx-halftone::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--tx-ink, #111);
  mix-blend-mode: screen;
}

/* ---------- 9. Monochrome landscapes (photo variants; generator in JS) ---------- */
.tx-mono-photo { filter: grayscale(1) contrast(1.12) brightness(1.04); }
.tx-duotone { position: relative; isolation: isolate; }
.tx-duotone img { filter: grayscale(1) contrast(1.2); mix-blend-mode: multiply; display: block; width: 100%; }
.tx-duotone { background: var(--tx-duo, #1f4e79); }

/* ---------- 10. ASCII art (fill with TX.ascii) ---------- */
.tx-ascii {
  margin: 0;
  overflow: hidden;
  white-space: pre;
  line-height: 1;
  letter-spacing: 0;
  font-family: Consolas, "Courier New", ui-monospace, monospace;
  color: var(--tx-ascii, #9effa8);
  background: #050805;
}

/* ---------- 11. Felt texture ---------- */
.tx-felt {
  background-color: var(--tx-felt, #2f6b4f);
  background-image:
    url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='300' height='300'><filter id='f'><feTurbulence type='fractalNoise' baseFrequency='.55 .8' numOctaves='5' stitchTiles='stitch'/><feColorMatrix type='saturate' values='0'/></filter><rect width='100%25' height='100%25' filter='url(%23f)'/></svg>"),
    url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='300' height='300'><filter id='l'><feTurbulence type='turbulence' baseFrequency='.08' numOctaves='3' stitchTiles='stitch'/><feDiffuseLighting surfaceScale='2' lighting-color='%23fff'><feDistantLight azimuth='90' elevation='58'/></feDiffuseLighting></filter><rect width='100%25' height='100%25' filter='url(%23l)'/></svg>");
  background-blend-mode: soft-light, multiply;
  box-shadow: inset 0 0 60px rgba(0, 0, 0, .35);
}
.tx-felt-stitch { outline: 2px dashed rgba(255, 255, 255, .45); outline-offset: -12px; }

/* ---------- 12. Dot matrix ---------- */
.tx-dotmatrix {
  background:
    radial-gradient(circle, var(--tx-led-dim, rgba(255, 176, 0, .13)) 0 1.5px, transparent 2.2px) 0 0 / var(--tx-cell, 8px) var(--tx-cell, 8px),
    #0d0d0d;
}
.tx-dotmatrix-text {
  color: var(--tx-led, #ffb000);
  font-weight: 900;
  text-shadow: 0 0 10px currentColor;
  -webkit-mask: radial-gradient(circle, #000 0 42%, transparent 50%) 0 0 / var(--tx-cell, 8px) var(--tx-cell, 8px);
          mask: radial-gradient(circle, #000 0 42%, transparent 50%) 0 0 / var(--tx-cell, 8px) var(--tx-cell, 8px);
}
.tx-dots { background: radial-gradient(circle, var(--tx-dot-c, rgba(0,0,0,.18)) 1.2px, transparent 1.8px) 0 0 / 16px 16px; }

/* ---------- 13. Fluted glass (overlay — blurs and ribs what's inside/behind) ---------- */
.tx-fluted::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  -webkit-backdrop-filter: blur(var(--tx-flute-blur, 7px));
          backdrop-filter: blur(var(--tx-flute-blur, 7px));
  background: repeating-linear-gradient(90deg,
    rgba(255, 255, 255, .24) 0,
    rgba(255, 255, 255, .05) calc(var(--tx-flute, 26px) * .25),
    rgba(0, 0, 0, .16) calc(var(--tx-flute, 26px) * .88),
    rgba(255, 255, 255, .24) var(--tx-flute, 26px));
}
.tx-fluted > .tx-above { position: relative; z-index: 4; }

/* ---------- 17. Noise texture ---------- */
.tx-noise { background-color: var(--tx-noise-bg, #5b5f73); }
.tx-noise::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--tx-grain-img);
  opacity: var(--tx-noise, .55);
  mix-blend-mode: overlay;
}

/* ---------- 21. Lens distortion helpers (real warp = TX.lens) ---------- */
.tx-chroma { text-shadow: -2px 0 rgba(255, 0, 80, .75), 2px 0 rgba(0, 220, 255, .75); }
.tx-vignette::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 50%, rgba(0, 0, 0, .6));
}

/* ---------- 22. Iridescent 3D ---------- */
@property --tx-a { syntax: "<angle>"; inherits: false; initial-value: 0deg; }
@keyframes tx-spin { to { --tx-a: 360deg; } }
@keyframes tx-morph {
  0%   { border-radius: 42% 58% 63% 37% / 45% 38% 62% 55%; }
  50%  { border-radius: 60% 40% 35% 65% / 55% 62% 38% 45%; }
  100% { border-radius: 38% 62% 55% 45% / 40% 50% 50% 60%; }
}
.tx-iridescent {
  background:
    radial-gradient(circle at var(--mx, 30%) var(--my, 25%), rgba(255, 255, 255, .8), transparent 38%),
    conic-gradient(from var(--tx-a) at 50% 50%, var(--tx-iri));
  animation: tx-spin 9s linear infinite;
  transform: perspective(900px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg));
  transition: transform .25s ease-out;
  transform-style: preserve-3d;
  color: #1d1636;
}
.tx-iridescent::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: repeating-linear-gradient(115deg, transparent 0 14px, rgba(255, 255, 255, .35) 20px, transparent 28px);
  mix-blend-mode: overlay;
}
.tx-iri-orb, .tx-iri-blob {
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 28%, #fff 0, rgba(255, 255, 255, 0) 30%),
    radial-gradient(circle at 70% 78%, rgba(40, 0, 90, .45), transparent 55%),
    conic-gradient(from var(--tx-a), var(--tx-iri));
  box-shadow: inset -18px -26px 50px rgba(60, 0, 120, .35), 0 30px 60px -20px rgba(120, 80, 255, .55);
  animation: tx-spin 10s linear infinite;
}
.tx-iri-blob { animation: tx-spin 10s linear infinite, tx-morph 9s ease-in-out infinite alternate; }
.tx-iri-text {
  background: conic-gradient(from var(--tx-a), var(--tx-iri));
  -webkit-background-clip: text;
          background-clip: text;
  color: transparent;
  animation: tx-spin 6s linear infinite;
}

/* ---------- Respect reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  [class*="tx-"], [class*="tx-"]::before, [class*="tx-"]::after { animation: none !important; }
}
