/* ============================================================
   Casa Quipu — Loader
   Scoped entirely under #cq-loader-root to avoid colliding with
   the site's CSS. Three states: 'first', 'slow', 'offline'.
   Mounted/unmounted by casa-loader.js.
   ============================================================ */

#cq-loader-root {
  --cq-parchment:      #ECE1C8;
  --cq-parchment-deep: #E2D4B5;
  --cq-ink:            #2A1F14;
  --cq-ink-mid:        rgba(42,31,20,0.62);
  --cq-ink-dim:        rgba(42,31,20,0.35);
  --cq-ink-faint:      rgba(42,31,20,0.14);
  --cq-copper:         #9C6E3E;
  --cq-copper-deep:    #7E5832;

  --cq-font-display: "Cormorant Garamond", Georgia, serif;
  --cq-font-ui:      "Syne", -apple-system, system-ui, sans-serif;
  --cq-font-body:    "DM Sans", -apple-system, system-ui, sans-serif;

  --cq-ease:    cubic-bezier(0.22, 1, 0.36, 1);
  --cq-ease-io: cubic-bezier(0.22, 0.61, 0.36, 1);

  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--cq-parchment);
  background-image:
    radial-gradient(ellipse at 50% 38%, transparent 0%, transparent 55%, rgba(120,90,55,0.10) 100%),
    radial-gradient(circle at 30% 80%, rgba(160,120,75,0.05), transparent 40%),
    radial-gradient(circle at 80% 20%, rgba(140,100,65,0.04), transparent 35%);
  color: var(--cq-ink);
  font-family: var(--cq-font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
  transition: opacity 320ms var(--cq-ease);
}
#cq-loader-root.is-out { opacity: 0; pointer-events: none; }
#cq-loader-root *, #cq-loader-root *::before, #cq-loader-root *::after { box-sizing: border-box; }

/* ---------- offline-state nav ---------- */
#cq-loader-root .cq-nav {
  position: fixed; top: 0; left: 0; right: 0;
  height: 64px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 32px;
  border-bottom: 1px solid var(--cq-ink-faint);
  z-index: 5;
  opacity: 0;
  transition: opacity 320ms var(--cq-ease);
  pointer-events: none;
}
#cq-loader-root .cq-nav.is-visible { opacity: 1; }
#cq-loader-root .cq-nav .cq-nav-mark {
  font-family: var(--cq-font-display);
  font-style: italic;
  font-weight: 300;
  font-size: 22px;
  letter-spacing: 0.02em;
  color: var(--cq-ink);
}
#cq-loader-root .cq-nav ul {
  display: flex; gap: 28px; list-style: none; margin: 0; padding: 0;
  font-family: var(--cq-font-ui);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--cq-ink-mid);
}

/* ---------- scenes ---------- */
#cq-loader-root .cq-scene {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 2;
  opacity: 0;
  pointer-events: none;
  transition: opacity 400ms var(--cq-ease);
}
#cq-loader-root .cq-scene.is-active { opacity: 1; pointer-events: auto; }

/* ---------- quipu SVG ---------- */
#cq-loader-root .cq-quipu-wrap {
  width: min(720px, 80vw);
  position: relative;
}
#cq-loader-root .cq-quipu {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}
@media (max-width: 720px) {
  #cq-loader-root .cq-quipu-wrap { width: 70vw; }
}

#cq-loader-root .cq-cord,
#cq-loader-root .cq-pendant {
  fill: none;
  stroke: var(--cq-ink);
  stroke-width: 1.25;
  stroke-linecap: round;
  opacity: 0.95;
}
#cq-loader-root .cq-pendant { stroke-width: 1.15; opacity: 0.92; }

#cq-loader-root .cq-cord {
  stroke-dasharray: var(--len);
  stroke-dashoffset: var(--len);
}
#cq-loader-root .cq-pendant {
  stroke-dasharray: var(--len);
  stroke-dashoffset: var(--len);
}

#cq-loader-root .cq-knot-strand {
  fill: none;
  stroke: var(--cq-ink);
  stroke-width: 1.25;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.95;
  stroke-dasharray: 44;
  stroke-dashoffset: 44;
}

/* ---------- animation keyframes ---------- */
@keyframes cq-drawCord { to { stroke-dashoffset: 0; } }
@keyframes cq-drawPend { to { stroke-dashoffset: 0; } }
@keyframes cq-knotTie  { to { stroke-dashoffset: 0; } }

#cq-loader-root .cq-quipu.is-playing .cq-knot-strand--a {
  animation: cq-knotTie 240ms var(--cq-ease) var(--kdelay) forwards;
}
#cq-loader-root .cq-quipu.is-playing .cq-knot-strand--b {
  animation: cq-knotTie 240ms var(--cq-ease) calc(var(--kdelay) + 140ms) forwards;
}
#cq-loader-root .cq-quipu.is-playing .cq-cord {
  animation: cq-drawCord 600ms var(--cq-ease) 200ms forwards;
}
#cq-loader-root .cq-quipu.is-playing .cq-pendant {
  animation: cq-drawPend 150ms var(--cq-ease) var(--delay) forwards;
}

#cq-loader-root .cq-quipu.is-reset .cq-cord,
#cq-loader-root .cq-quipu.is-reset .cq-pendant {
  animation: none;
  stroke-dashoffset: var(--len);
}
#cq-loader-root .cq-quipu.is-reset .cq-knot-strand {
  animation: none;
  stroke-dashoffset: 44;
}

#cq-loader-root .cq-quipu-fade {
  transition: opacity 400ms var(--cq-ease);
}
#cq-loader-root .cq-quipu-fade.is-out { opacity: 0; }

/* ---------- typography around the loader ---------- */
#cq-loader-root .cq-stage-label {
  margin-top: 56px;
  font-family: var(--cq-font-ui);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--cq-ink-dim);
  opacity: 0;
  transition: opacity 500ms var(--cq-ease) 400ms;
  text-align: center;
}
#cq-loader-root .cq-stage-label.is-in { opacity: 1; }

#cq-loader-root .cq-slow-line {
  margin: 28px 0 0;
  font-family: var(--cq-font-display);
  font-style: italic;
  font-weight: 300;
  font-size: 1.25rem;
  color: var(--cq-ink-mid);
  opacity: 0;
  transition: opacity 800ms var(--cq-ease);
  text-align: center;
  letter-spacing: 0.01em;
}
#cq-loader-root .cq-slow-line.is-in { opacity: 1; }

#cq-loader-root .cq-slow-sub {
  margin: 14px 0 0;
  font-family: var(--cq-font-ui);
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--cq-ink-dim);
  opacity: 0;
  transition: opacity 800ms var(--cq-ease) 200ms;
  text-align: center;
}
#cq-loader-root .cq-slow-sub.is-in { opacity: 1; }

/* ---------- offline scene ---------- */
#cq-loader-root .cq-offline-eyebrow {
  font-family: var(--cq-font-ui);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--cq-copper);
  margin-bottom: 32px;
}
#cq-loader-root .cq-offline-eyebrow::before {
  content: "— ";
  letter-spacing: 0;
}
#cq-loader-root .cq-offline-headline {
  font-family: var(--cq-font-display);
  font-style: italic;
  font-weight: 300;
  font-size: clamp(38px, 6.2vw, 78px);
  line-height: 1.02;
  color: var(--cq-ink);
  text-align: center;
  margin: 0;
  max-width: 16ch;
  letter-spacing: -0.005em;
}
#cq-loader-root .cq-offline-body {
  margin-top: 48px;
  max-width: 360px;
  text-align: center;
  font-size: 15px;
  line-height: 1.55;
  color: var(--cq-ink-mid);
  font-weight: 300;
}
#cq-loader-root .cq-offline-cord {
  margin-top: 64px;
  width: 280px;
  height: 40px;
}
#cq-loader-root .cq-offline-cord line {
  stroke: var(--cq-ink);
  stroke-width: 1.25;
  stroke-linecap: round;
  opacity: 0.95;
}
#cq-loader-root .cq-offline-cord .cq-knot-strand--static {
  fill: none;
  stroke: var(--cq-ink);
  stroke-width: 1.25;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.95;
}
#cq-loader-root .cq-offline-retry {
  margin-top: 56px;
  background: none;
  border: 0;
  padding: 8px 0;
  font-family: var(--cq-font-ui);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--cq-ink-dim);
  cursor: pointer;
  border-bottom: 1px solid var(--cq-ink-faint);
  transition: color 240ms var(--cq-ease), border-color 240ms var(--cq-ease);
}
#cq-loader-root .cq-offline-retry:hover {
  color: var(--cq-copper);
  border-bottom-color: var(--cq-copper);
}

/* ---------- reduced motion fallback ---------- */
@media (prefers-reduced-motion: reduce) {
  #cq-loader-root .cq-quipu.is-playing .cq-cord,
  #cq-loader-root .cq-quipu.is-playing .cq-pendant {
    animation: none;
    stroke-dashoffset: 0;
  }
  #cq-loader-root .cq-quipu.is-playing .cq-knot-strand--a,
  #cq-loader-root .cq-quipu.is-playing .cq-knot-strand--b {
    animation: cq-knotFade 320ms var(--cq-ease) var(--kdelay) forwards;
  }
  @keyframes cq-knotFade {
    from { stroke-dashoffset: 0; opacity: 0; }
    to   { stroke-dashoffset: 0; opacity: 0.95; }
  }
  #cq-loader-root .cq-scene,
  #cq-loader-root .cq-quipu-fade { transition: opacity 200ms linear; }
}

/* ---------- screen-reader only ---------- */
#cq-loader-root .cq-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
