/* ============================================================
   TT Love Loading — AI-wait / splash / pending animation
   Prototype-owned copy (React/Babel workspace). Brand tokens come
   from workspace.css (--cyan, --teal, --gold, --gold-light, --ease,
   --ink*, --gold-grad, --brand-grad, --bg-grad, --stroke). Missing
   tokens (--mint, --surface-strong) fall back inline. All motion is
   transform/opacity. Real progress sets --tt-w via inline style
   (no CSP on the prototype page).
   ============================================================ */

.tt-loading {
  --tt-d: clamp(180px, 34vmin, 280px);

  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(18px, 4vmin, 34px);
  padding: 24px;
  overflow: hidden;
  isolation: isolate;
  color: var(--ink, #163a42);
  /* Transparent layer (no green fill): only the centred loader + the soft water
     waves show. It still covers the viewport so it stays on top and blocks
     interaction while work is in flight. */
  background: transparent;
  transition: opacity 0.5s var(--ease, ease), visibility 0.5s var(--ease, ease);
}

/* Fullscreen splash sits above every panel, scrim (z 80) and drawer (z 81). */
.tt-loading--fullscreen {
  position: fixed;
  inset: 0;
  z-index: 1200;
}

/* Inline overlay: top-anchored and capped to the viewport so the logo/caption
   stay centred in view even when the host panel is far taller than the screen. */
.tt-loading--inline {
  inset: 0 0 auto 0;
  height: 100%;
  max-height: 100vh;
  z-index: 60; /* sit above sibling cards in the same panel */
}

/* Positioning context for a non-fullscreen (inline) loader: add to the parent
   that the overlay should fill. Reusable across any AI-wait panel. */
.loading-host {
  position: relative;
  min-height: 360px;
}

.tt-loading--hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.tt-loading--sm { --tt-d: clamp(120px, 24vmin, 180px); }
.tt-loading--md { --tt-d: clamp(180px, 34vmin, 280px); }
.tt-loading--lg { --tt-d: clamp(220px, 42vmin, 360px); }

/* ----------------------- background water ----------------------- */
/* Soft drifting water lines. Kept even when the backdrop is transparent. */
.tt-loading__waves {
  position: absolute;
  inset: -10% -30%;
  z-index: 0;
  opacity: 0.55;
  background-repeat: repeat;
  background-size: 220px 120px, 320px 160px;
  background-image:
    repeating-radial-gradient(120% 60% at 50% 120%, transparent 0 22px, rgba(95, 196, 204, 0.14) 22px 24px, transparent 24px 46px),
    repeating-radial-gradient(140% 60% at 50% -20%, transparent 0 30px, rgba(143, 214, 218, 0.12) 30px 33px, transparent 33px 60px);
  animation: tt-wave-drift 26s linear infinite;
  will-change: transform;
}

@keyframes tt-wave-drift {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(-220px, 0, 0); }
}

/* ----------------------- centre stage ----------------------- */
.tt-loading__stage {
  position: relative;
  z-index: 1;
  width: var(--tt-d);
  height: var(--tt-d);
  display: grid;
  place-items: center;
  animation: tt-float 6s ease-in-out infinite;
  will-change: transform;
}

@keyframes tt-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2.2%); }
}

.tt-loading__glow {
  position: absolute;
  inset: -16%;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 46%, rgba(95, 196, 204, 0.45), transparent 62%);
  filter: blur(6px);
  animation: tt-breathe 5.5s ease-in-out infinite;
}

@keyframes tt-breathe {
  0%, 100% { opacity: 0.6; transform: scale(0.98); }
  50% { opacity: 1; transform: scale(1.04); }
}

/* outer rainbow ring — clockwise */
.tt-loading__halo {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  padding: clamp(6px, 1.6vmin, 12px);
  background: conic-gradient(
    from 0deg,
    #8fd6da, #bfe3d9, #f2de96, #e8ce73, #c9a24b,
    #d9c6ec, #9fd4ff, #8fd6da
  );
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - clamp(6px, 1.6vmin, 12px)), #000 0);
  mask: radial-gradient(farthest-side, transparent calc(100% - clamp(6px, 1.6vmin, 12px)), #000 0);
  filter: saturate(1.05) drop-shadow(0 0 10px rgba(143, 214, 218, 0.5));
  animation: tt-spin 9s linear infinite;
  will-change: transform;
}

/* inner thinner ring — counter-clockwise */
.tt-loading__halo2 {
  position: absolute;
  inset: 11%;
  border-radius: 50%;
  padding: clamp(2px, 0.7vmin, 5px);
  background: conic-gradient(
    from 120deg,
    rgba(201, 162, 75, 0.7), rgba(255, 255, 255, 0.85),
    rgba(95, 196, 204, 0.7), rgba(201, 162, 75, 0.7)
  );
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - clamp(2px, 0.7vmin, 5px)), #000 0);
  mask: radial-gradient(farthest-side, transparent calc(100% - clamp(2px, 0.7vmin, 5px)), #000 0);
  opacity: 0.85;
  animation: tt-spin-rev 7s linear infinite;
  will-change: transform;
}

/* gold sweep arc rotating around the logo */
.tt-loading__sweep {
  position: absolute;
  inset: 5%;
  border-radius: 50%;
  background: conic-gradient(
    from 0deg,
    transparent 0deg,
    transparent 250deg,
    rgba(242, 222, 150, 0.85) 320deg,
    rgba(255, 255, 255, 0.95) 350deg,
    transparent 360deg
  );
  -webkit-mask: radial-gradient(farthest-side, transparent 64%, #000 66%);
  mask: radial-gradient(farthest-side, transparent 64%, #000 66%);
  mix-blend-mode: screen;
  animation: tt-spin 3.6s linear infinite;
  will-change: transform;
}

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

/* glass disc + logo */
.tt-loading__logo {
  position: relative;
  width: 64%;
  height: 64%;
  border-radius: 50%;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--surface-strong, rgba(255, 255, 255, 0.9));
  border: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow:
    inset 0 1px 6px rgba(255, 255, 255, 0.7),
    0 14px 34px -16px rgba(18, 88, 106, 0.45);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.tt-loading__logo img {
  width: 88%;
  height: 88%;
  object-fit: contain;
  border-radius: 50%;
  user-select: none;
}

/* ----------------------- sparkles ----------------------- */
.tt-loading__sparks {
  position: absolute;
  inset: -6%;
  pointer-events: none;
}

.tt-loading__spark {
  position: absolute;
  width: clamp(3px, 0.9vmin, 6px);
  height: clamp(3px, 0.9vmin, 6px);
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, rgba(242, 222, 150, 0.9) 40%, transparent 70%);
  opacity: 0;
  animation: tt-twinkle 3.4s ease-in-out infinite;
  will-change: transform, opacity;
}

.tt-loading__spark.s1 { top: 6%;  left: 50%; animation-delay: 0s;    }
.tt-loading__spark.s2 { top: 18%; left: 84%; animation-delay: 0.5s;  }
.tt-loading__spark.s3 { top: 52%; left: 95%; animation-delay: 1.1s;  }
.tt-loading__spark.s4 { top: 84%; left: 80%; animation-delay: 1.7s;  }
.tt-loading__spark.s5 { top: 94%; left: 46%; animation-delay: 0.9s;  }
.tt-loading__spark.s6 { top: 80%; left: 14%; animation-delay: 2.1s;  }
.tt-loading__spark.s7 { top: 46%; left: 4%;  animation-delay: 1.4s;  }
.tt-loading__spark.s8 { top: 16%; left: 16%; animation-delay: 0.3s;  }

@keyframes tt-twinkle {
  0%, 100% { opacity: 0; transform: scale(0.4); }
  45%, 60% { opacity: 1; transform: scale(1); }
}

/* ----------------------- caption ----------------------- */
.tt-loading__caption {
  position: relative;
  z-index: 1;
  width: min(420px, 84vmin);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, 1.6vmin, 14px);
}

.tt-loading__text {
  margin: 0;
  font-family: var(--font-display, system-ui, sans-serif);
  font-weight: 700;
  letter-spacing: 0.42em;
  text-indent: 0.42em;
  font-size: clamp(13px, 2.2vmin, 17px);
  color: var(--ink-2, #3c5c63);
}

/* Indeterminate "processing" bar — a glowing segment sweeps across; NO
   percentage / progress is shown (we only signal that work is in flight). */
.tt-loading__bar {
  position: relative;
  width: min(280px, 70vmin);
  height: clamp(6px, 1.2vmin, 9px);
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid var(--stroke, rgba(31, 126, 145, 0.16));
  box-shadow: inset 0 1px 3px rgba(18, 88, 106, 0.12);
}

.tt-loading__bar-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 38%;
  border-radius: inherit;
  background: linear-gradient(90deg, transparent, var(--cyan, #5fc4cc), var(--gold-light, #e8ce73), transparent);
  animation: tt-indeterminate 1.5s var(--ease, ease) infinite;
  will-change: transform;
}

@keyframes tt-indeterminate {
  0% { transform: translateX(-115%); }
  100% { transform: translateX(290%); }
}

.tt-loading__sub {
  margin: 0;
  font-size: clamp(10px, 1.7vmin, 12px);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3, #6e8a8f);
}

/* ----------------------- variants ----------------------- */
.tt-loading--minimal .tt-loading__halo2,
.tt-loading--minimal .tt-loading__sweep,
.tt-loading--minimal .tt-loading__sparks,
.tt-loading--minimal .tt-loading__waves {
  display: none;
}

/* ----------------------- reduced motion ----------------------- */
@media (prefers-reduced-motion: reduce) {
  .tt-loading *,
  .tt-loading {
    animation: none !important;
    transition: opacity 0.3s ease, visibility 0.3s ease !important;
  }
  /* static calm hint instead of the sweeping segment */
  .tt-loading__bar-fill { left: 31%; width: 38%; }
}
