/* ============================================================
   loader.css — Work-open loading overlay
   ------------------------------------------------------------
   Triggered by a click on the active work card. It owns:

     · the dimmed + blurred veil
     · the progress ring with a live percentage
     · the caption (label + work title) and the thin fill bar

   JS drives the progress by writing three things:
   stroke-dashoffset on .lr-bar, scaleX() on .loader-bar i and
   the text of .lr-pct. Nothing here animates on its own except
   the decorative halo and the outer spinner arc.
   ============================================================ */

.loader {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.42s ease, visibility 0.42s ease;
}

.loader.open { opacity: 1; visibility: visible; }

/* cleared state — slightly quicker than the entrance */
.loader.done {
  opacity: 0;
  transition-duration: 0.38s;
}

/* ---------- veil ---------- */

.loader-veil {
  position: absolute;
  inset: 0;
  background: rgba(6, 6, 6, 0.66);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

/* ---------- panel ---------- */

.loader-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  opacity: 0;
  transform: translateY(16px) scale(0.985);
  transition:
    transform 0.42s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.42s ease;
}

.loader.open .loader-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  transition-delay: 0.07s;
}

/* settles upward instead of dropping back down */
.loader.done .loader-panel {
  opacity: 0;
  transform: translateY(-10px) scale(1.02);
  transition-delay: 0s;
}

/* ---------- progress ring ---------- */

.loader-ring {
  position: relative;
  width: 132px;
  height: 132px;
}

/* ambient-tinted halo, breathing */
.loader-ring::before {
  content: "";
  position: absolute;
  inset: -30px;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(
    closest-side,
    rgba(var(--amb-c, 32, 32, 36), 0.55),
    transparent 70%
  );
  filter: blur(14px);
  animation: loader-breathe 3.6s ease-in-out infinite;
}

@keyframes loader-breathe {
  0%, 100% { opacity: 0.35; }
  50%      { opacity: 0.8; }
}

/* outer arc — keeps the state alive even while the bar sits at 0% */
.loader-ring::after {
  content: "";
  position: absolute;
  inset: -12px;
  border-radius: 50%;
  pointer-events: none;
  border: 1px solid transparent;
  border-top-color: rgba(255, 255, 255, 0.42);
  border-right-color: rgba(255, 255, 255, 0.1);
  animation: loader-arc 1.15s linear infinite;
}

@keyframes loader-arc {
  to { transform: rotate(360deg); }
}

.loader-ring svg {
  position: relative;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);   /* start the fill at 12 o'clock */
  overflow: visible;
}

.lr-track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.09);
  stroke-width: 1.5;
}

.lr-bar {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.5;
  stroke-linecap: round;
  /* fallbacks — JS overwrites both from getTotalLength() */
  stroke-dasharray: 327;
  stroke-dashoffset: 327;
  transition: stroke-dashoffset 0.2s linear;
}

.lr-pct {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 26px;
  letter-spacing: 0.02em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;   /* digits must not jitter the layout */
}

.lr-pct::after {
  content: "%";
  margin-left: 2px;
  font-size: 0.44em;
  letter-spacing: 0;
  color: var(--ink-faint);
  vertical-align: 0.5em;
}

/* ---------- caption ---------- */

.loader-caption {
  margin-top: 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}

.lc-label {
  font-size: 10px;
  letter-spacing: 0.36em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* the label swaps Loading → Ready, so it needs its own fade */
.lc-label.swap {
  animation: swap-in 0.4s cubic-bezier(0.22, 0.8, 0.3, 1) both;
}

.lc-title {
  font-family: var(--font-art);
  font-weight: 300;
  font-size: clamp(22px, 2.4vw, 32px);
  letter-spacing: 0.015em;
  color: var(--ink);
}

/* ---------- thin fill bar ---------- */

.loader-bar {
  position: relative;
  margin-top: 26px;
  width: 190px;
  height: 1px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.loader-bar i {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.3), var(--ink));
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.2s linear;
}

/* ---------- mobile + reduced motion ---------- */

@media (max-width: 860px) {
  .loader-ring { width: 108px; height: 108px; }
  .lr-pct { font-size: 22px; }
  .loader-bar { width: 160px; }
}

@media (prefers-reduced-motion: reduce) {
  .loader-ring::before,
  .loader-ring::after { animation: none; }
  .loader-ring::after { opacity: 0.35; }
}
