/* ==========================================================================
   Barterly — Motion & signature elements
   Preloader, page curtain, custom cursor, scroll progress, split-text
   masks, rolling buttons, stickers, polaroids, tape and doodles.
   ========================================================================== */

/* ---------- Scroll progress ---------- */
.scroll-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 150;
  height: 3px;
  pointer-events: none;
}

.scroll-progress span {
  display: block;
  height: 100%;
  background: var(--primary);
  transform: scaleX(0);
  transform-origin: left;
}

/* ---------- Preloader ---------- */
.preloader {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: var(--ink);
  color: var(--paper);
}

.js .preloader.is-active {
  display: flex;
  /* Safety net: never block the page for more than a few seconds */
  animation: preloader-failsafe 0s 4.5s forwards;
}

@keyframes preloader-failsafe {
  to {
    visibility: hidden;
  }
}

.preloader {
  transition: transform 900ms cubic-bezier(0.76, 0, 0.24, 1);
}

.preloader.is-done {
  transform: translateY(-100%);
}

.preloader-inner {
  display: grid;
  justify-items: center;
  gap: 18px;
}

.preloader-mark {
  position: relative;
  display: grid;
  place-items: center;
  width: 92px;
  height: 92px;
  isolation: isolate;
}

.preloader-mark::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: 46% 54% 58% 42% / 52% 44% 56% 48%;
  background: linear-gradient(135deg, rgba(76, 201, 255, 0.2), rgba(200, 107, 255, 0.24));
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 0 60px -10px rgba(120, 90, 255, 0.8);
  animation: blob-morph 6s ease-in-out infinite;
}

.preloader-mark img {
  width: 80%;
  height: 80%;
}

@keyframes blob-morph {
  0%,
  100% {
    border-radius: 46% 54% 58% 42% / 52% 44% 56% 48%;
    transform: rotate(-8deg);
  }

  50% {
    border-radius: 58% 42% 44% 56% / 42% 58% 42% 58%;
    transform: rotate(10deg);
  }
}

.preloader-word {
  font-family: var(--font-display);
  font-size: clamp(2.6rem, 8vw, 5rem);
  font-weight: 700;
  letter-spacing: -0.05em;
  line-height: 1;
}

.preloader-word .serif {
  color: var(--primary);
}

.preloader-count {
  font-family: var(--font-display);
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  opacity: 0.6;
}

.preloader-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4px;
}

.preloader-bar span {
  display: block;
  height: 100%;
  background: var(--primary);
  transform: scaleX(0);
  transform-origin: left;
}

/* ---------- Page transition curtain ---------- */
.curtain {
  position: fixed;
  inset: 0;
  z-index: 320;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: var(--paper);
  transform: translateY(100%);
  transition: transform 620ms cubic-bezier(0.76, 0, 0.24, 1);
  pointer-events: none;
}

.curtain.is-covering {
  transform: translateY(0);
  pointer-events: auto;
}

.curtain.is-leaving {
  transform: translateY(-100%);
  transition-duration: 800ms;
}

.curtain.no-transition {
  transition: none;
}

.curtain-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 4vw, 2.6rem);
  font-weight: 700;
  letter-spacing: -0.03em;
}

.curtain .preloader-mark {
  width: 64px;
  height: 64px;
}

/* ---------- Custom cursor ---------- */
.cursor {
  display: none;
}

.has-cursor .cursor {
  display: block;
}

.has-cursor body.landing,
.has-cursor body.landing a,
.has-cursor body.landing button,
.has-cursor body.landing label,
.has-cursor body.landing summary {
  cursor: none;
}

.cursor-dot,
.cursor-ring {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 600;
  pointer-events: none;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 300ms ease;
}

.cursor.is-visible .cursor-dot,
.cursor.is-visible .cursor-ring {
  opacity: 1;
}

.cursor-dot {
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  background: var(--primary);
}

.cursor-ring {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  margin: -19px 0 0 -19px;
  border: 1.5px solid color-mix(in srgb, var(--text) 45%, transparent);
  transition: opacity 300ms ease, width 400ms var(--ease-out-expo), height 400ms var(--ease-out-expo),
    margin 400ms var(--ease-out-expo), background-color 300ms ease, border-color 300ms ease;
}

.cursor-label {
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 250ms ease, transform 400ms var(--ease-out-expo);
}

.cursor.is-hover .cursor-ring {
  width: 60px;
  height: 60px;
  margin: -30px 0 0 -30px;
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 12%, transparent);
}

.cursor.is-label .cursor-ring {
  width: 92px;
  height: 92px;
  margin: -46px 0 0 -46px;
  border-color: transparent;
  background: var(--primary);
}

.cursor.is-label .cursor-label {
  opacity: 1;
  transform: none;
}

.cursor.is-label .cursor-dot,
.cursor.is-text .cursor-ring {
  opacity: 0;
}

.cursor.is-text .cursor-dot {
  width: 2px;
  height: 22px;
  margin: -11px 0 0 -1px;
  border-radius: 1px;
}

.cursor.is-down .cursor-ring {
  width: 30px;
  height: 30px;
  margin: -15px 0 0 -15px;
}

/* ---------- Split text masks ---------- */
.line {
  display: block;
  overflow: hidden;
  padding-bottom: 0.08em;
  margin-bottom: -0.08em;
}

.line-i {
  display: inline-block;
}

.w {
  display: inline-block;
  overflow: hidden;
  vertical-align: top;
  padding-bottom: 0.1em;
  margin-bottom: -0.1em;
}

.w-i {
  display: inline-block;
}

/* ---------- Buttons: ink pill with rolling label ---------- */
.btn {
  --h: 50px;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: var(--h);
  padding: 0 8px 0 24px;
  border: 1.5px solid transparent;
  border-radius: var(--r-full);
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1;
  white-space: nowrap;
  isolation: isolate;
  overflow: hidden;
  transition: color 400ms var(--ease), border-color 300ms ease, background-color 300ms ease;
}

.btn:not(:has(.btn-arrow)) {
  padding-right: 24px;
}

.btn-sm {
  --h: 42px;
  padding-inline: 18px;
  font-size: 0.88rem;
}

.btn-lg {
  --h: 58px;
  font-size: 1rem;
}

.btn-ink {
  background: var(--ink);
  color: var(--paper);
}

.btn-line {
  border-color: var(--border-strong);
  color: var(--text);
}

/* Fill that sweeps up from the bottom on hover */
.btn::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: var(--primary);
  transform: translateY(101%);
  transition: transform 500ms var(--ease-out-expo);
}

.btn:hover::before {
  transform: translateY(0);
}

.btn:hover {
  color: #ffffff;
  border-color: var(--primary);
}

.btn-roll {
  position: relative;
  display: inline-block;
  overflow: hidden;
  line-height: 1.3;
  vertical-align: middle;
}

/* motion.js wraps the label in .btn-roll-i and copies it into ::after */
.btn-roll-i {
  position: relative;
  display: inline-block;
  transition: transform 500ms var(--ease-out-expo);
}

.btn-roll-i::after {
  content: attr(data-text);
  position: absolute;
  left: 0;
  top: 100%;
  white-space: nowrap;
}

.btn:hover .btn-roll-i {
  transform: translateY(-100%);
}

.btn-arrow {
  display: grid;
  place-items: center;
  width: calc(var(--h) - 14px);
  height: calc(var(--h) - 14px);
  border-radius: 50%;
  background: var(--primary);
  color: #ffffff;
  transition: transform 500ms var(--ease-out-expo), background-color 300ms ease, color 300ms ease;
}

.btn:hover .btn-arrow {
  background: #ffffff;
  color: var(--primary);
  transform: rotate(45deg);
}

.btn-arrow .icon {
  width: 18px;
  height: 18px;
}

/* ---------- Stickers ---------- */
.sticker {
  position: absolute;
  display: grid;
  place-items: center;
  align-content: center;
  width: 104px;
  height: 104px;
  border: 2px solid #171512;
  border-radius: 50%;
  color: #171512;
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: -0.04em;
  text-align: center;
  box-shadow: 4px 5px 0 #171512;
  user-select: none;
}

.sticker small,
.sticker strong {
  display: block;
}

.sticker small {
  margin-top: 4px;
  font-family: var(--font-sans);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sticker strong {
  font-size: 1.5rem;
}

.sticker-yellow {
  background: var(--sticker-yellow);
}

.sticker-pink {
  background: var(--sticker-pink);
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  font-size: 1.05rem;
  border-radius: 22px;
  transform: rotate(8deg);
}

.sticker-green {
  background: var(--sticker-green);
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  font-size: 1rem;
}

/* ---------- Polaroids with tape ---------- */
.polaroid {
  position: absolute;
  padding: 10px 10px 0;
  background: #fffdf8;
  border-radius: 4px;
  box-shadow: var(--shadow-photo);
  will-change: transform;
}

.polaroid img {
  width: 100%;
  aspect-ratio: 4 / 3.4;
  object-fit: cover;
  border-radius: 2px;
}

.polaroid figcaption {
  padding: 8px 4px 12px;
  color: #3a352d;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1.05rem;
  line-height: 1.2;
}

.tape {
  position: absolute;
  top: -14px;
  left: 50%;
  z-index: 2;
  width: 96px;
  height: 28px;
  margin-left: -48px;
  background: color-mix(in srgb, var(--sticker-yellow) 70%, transparent);
  transform: rotate(-4deg);
  -webkit-mask-image: linear-gradient(90deg, transparent 0 3px, #000 3px calc(100% - 3px), transparent calc(100% - 3px));
  mask-image: linear-gradient(90deg, transparent 0 3px, #000 3px calc(100% - 3px), transparent calc(100% - 3px));
  opacity: 0.9;
}

.tape-blue {
  background: color-mix(in srgb, var(--sticker-blue) 75%, transparent);
  transform: rotate(5deg);
}

/* ---------- Doodles (drawn with stroke-dashoffset) ---------- */
.scribble,
.doodle {
  overflow: visible;
}

.scribble path,
.doodle path {
  fill: none;
  stroke: var(--primary);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 0;
}

.doodle path {
  stroke: var(--text);
  stroke-width: 2.2;
}

.doodle-note {
  position: absolute;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1.15rem;
  line-height: 1.1;
  color: var(--text-2);
  transform: rotate(-6deg);
}

/* ---------- Rotating badge ---------- */
.rotate-badge {
  position: absolute;
  width: 132px;
  height: 132px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
}

.rotate-badge svg {
  width: 100%;
  height: 100%;
  animation: spin-slow 16s linear infinite;
}

.rotate-badge text {
  fill: currentColor;
  font-family: var(--font-sans);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 2.3px;
}

.rotate-badge-mark {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}

.rotate-badge-mark img {
  width: 60px;
  height: 60px;
}

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

.live-dot {
  position: relative;
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
}

.live-dot::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid #22c55e;
  animation: ping 2s ease-out infinite;
}

@keyframes ping {
  from {
    transform: scale(0.6);
    opacity: 1;
  }

  to {
    transform: scale(1.8);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rotate-badge svg {
    animation: none;
  }
}
