/*
 * Abhyas full-page preloader.
 *
 * Design intent: reuse the logo's own construction (pixel grid, amber crossbar)
 * so the loader reads as the brand "assembling" rather than a generic spinner.
 * All motion uses steps() timing on purpose: stepped easing keeps the retro-pixel
 * language consistent and avoids smooth tweens that would clash with the mark.
 */
:root {
  --ap-ink: #121110;
  --ap-amber: #ff6a2b;
  --ap-cream: #efe9dc;
  --ap-dim: rgba(239, 233, 220, 0.16);
}

[data-theme="paper"] {
  --ap-ink: #efe9dc;
  --ap-amber: #ff6a2b;
  --ap-cream: #121110;
  --ap-dim: rgba(18, 17, 16, 0.16);
}

/* Prevent background scroll while the overlay is up; removed by preloader.js. */
html.ap-lock {
  overflow: hidden;
}

#abhyas-preloader {
  position: fixed;
  inset: 0;
  z-index: 2147483000; /* above app chrome, modals and toasts */
  display: grid;
  place-items: center;
  background: var(--ap-ink);
  color: var(--ap-cream);
  font-family: var(--font-display, "Pixelify Sans", ui-monospace, monospace);
}

.ap-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

/* ---- Mark: pixels pop in top-to-bottom, then the crossbar sweeps across ---- */
/* 105px => 15px cells; whole-pixel cells avoid hairline seams between rects. */
.ap-mark {
  width: 105px;
  height: 105px;
  display: block;
  overflow: visible;
}

.ap-px,
.ap-bar {
  transform-box: fill-box;
}

.ap-px {
  fill: var(--ap-cream);
  transform-origin: center;
  opacity: 0;
  animation: ap-pop 0.24s steps(3, end) forwards;
  animation-delay: calc(var(--i) * 70ms);
}

.ap-bar {
  fill: var(--ap-amber);
  transform-origin: left center;
  transform: scaleX(0);
  animation:
    ap-sweep 0.42s steps(7, end) 0.85s forwards,
    ap-flicker 1.6s steps(1, end) 1.6s infinite;
}

/* ---- Wordmark: typed in character by character with a blinking block cursor ---- */
.ap-word {
  display: flex;
  align-items: center;
  font-size: 34px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 1px;
}

.ap-word-text {
  display: inline-block;
  overflow: hidden;
  white-space: nowrap;
  max-width: 0;
  animation: ap-type 0.66s steps(6, end) 1.05s forwards;
}

.ap-cursor {
  width: 0.5em;
  height: 0.8em;
  margin-left: 4px;
  background: var(--ap-amber);
  animation: ap-blink 0.9s steps(1, end) infinite;
}

/* ---- Meter: indeterminate on purpose; real progress is unknowable for arbitrary assets ---- */
.ap-meter {
  display: flex;
  gap: 6px;
  opacity: 0;
  animation: ap-fade-in 0.3s steps(3, end) 1.5s forwards;
}

.ap-meter span {
  width: 14px;
  height: 10px;
  background: var(--ap-dim);
  animation: ap-seg 1.6s steps(1, end) infinite;
  animation-delay: calc(var(--s) * 0.2s + 1.5s);
}

/* ---- Exit state ---- */
#abhyas-preloader.ap-leaving {
  pointer-events: none;
  background: transparent !important;
}

/* Inline / component-level loader styles */
.abh-loader-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-12) var(--space-6);
  min-height: 320px;
  width: 100%;
  box-sizing: border-box;
}

.abh-loader-container.abh-loader--fullscreen {
  min-height: 100vh;
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 1000;
}

@keyframes ap-pop {
  0% {
    opacity: 0;
    transform: scale(0);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}
@keyframes ap-sweep {
  to {
    transform: scaleX(1);
  }
}
@keyframes ap-flicker {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.55;
  }
}
@keyframes ap-type {
  to {
    max-width: 10ch;
  }
}
@keyframes ap-blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}
@keyframes ap-fade-in {
  to {
    opacity: 1;
  }
}
@keyframes ap-seg {
  0% {
    background: var(--ap-amber);
  }
  12.5%,
  100% {
    background: var(--ap-dim);
  }
}
@keyframes ap-exit {
  to {
    opacity: 0;
  }
}

#abhyas-preloader.ap-leaving .ap-stage {
  opacity: 0;
  transform: translateY(-24px) scale(0.96);
  transition:
    opacity 0.5s ease-out,
    transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Smooth Shutter Curtain Exit Transition */
.ap-shutter-curtain {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: row;
  z-index: 20;
  pointer-events: none;
  overflow: hidden;
  background: transparent;
}

.ap-shutter-col {
  flex: 1;
  height: 100%;
  background-color: var(--ap-ink);
  transform: translateY(0);
  will-change: transform;
  border-bottom: 3px solid var(--ap-amber);
  box-shadow: 0 4px 18px rgba(255, 106, 43, 0.45);
  box-sizing: border-box;
  margin-right: -1px;
}

#abhyas-preloader.ap-leaving .ap-shutter-col {
  animation: ap-shutter-lift 1.15s cubic-bezier(0.2, 1, 0.3, 1) forwards;
  animation-delay: var(--d, 0ms);
}

@keyframes ap-shutter-lift {
  0% {
    transform: translateY(0);
  }
  100% {
    transform: translateY(-101%);
  }
}

/* Reduced motion: show the finished logo statically and skip the intro entirely. */
@media (prefers-reduced-motion: reduce) {
  .ap-px,
  .ap-bar,
  .ap-word-text,
  .ap-meter,
  .ap-meter span,
  .ap-cursor {
    animation: none !important;
  }
  .ap-px {
    opacity: 1;
  }
  .ap-bar {
    transform: none;
  }
  .ap-word-text {
    max-width: none;
  }
  .ap-meter {
    opacity: 1;
  }
  .ap-meter span:nth-child(-n + 4) {
    background: var(--ap-amber);
  }
  #abhyas-preloader.ap-leaving {
    animation-duration: 0.01s;
  }
}
