/* ===========================================================================
   Kula — the companion: sizing, motion and the scenes it appears in.

   The bird itself is drawn by assets/js/kula.js. This file owns how it
   moves (keyed off `.is-<state>` on the SVG) and how it sits beside words
   (scenes, bubbles, empty states, greetings, flashes, onboarding).

   Everything reads the app's own tokens — --surface, --line, --ink, --muted,
   --brand — so a scene follows light / dark / system and a workspace's
   white-label colours without a palette of its own.

   Motion rules: a breath and a blink are the idle life; every other movement
   happens once and means something (a wave to greet, a nudge toward what is
   pointed at, two hops for a celebration, a drip when confused). Nothing
   loops noisily, and the whole file goes still under prefers-reduced-motion.
   =========================================================================== */

/* ── The bird ─────────────────────────────────────────────────────────────── */
.kula {
  display: inline-block;
  width: var(--kula-size, 120px);
  height: var(--kula-size, 120px);
  vertical-align: middle;
  flex: 0 0 auto;
  line-height: 0;
  --kula-belly: #eef2ff;
}
.kula .kula-svg { width: 100%; height: 100%; overflow: visible; display: block; }
/* On a deck-themed surface (a survey's thank-you page, a projector) the bird
   wears the deck's accent pair instead of the workspace brand, so it belongs
   to the thing just answered rather than to the admin shell. */
.dk .kula { --kula-a: var(--dk-accent); --kula-b: var(--dk-accent-2, var(--dk-accent)); }
.kula.is-changing .kula-svg { animation: kFadeIn .28s ease-out; }
@keyframes kFadeIn { from { opacity: .35; transform: scale(.96); } to { opacity: 1; transform: none; } }

/* idle life: a slow breath, and a blink now and then (period per bird) */
.kula-root { transform-box: fill-box; transform-origin: 50% 90%; animation: kBreathe 4.2s ease-in-out infinite; }
@keyframes kBreathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.018, 1.03); } }

.kula-turn { transform-box: fill-box; transform-origin: 50% 75%; transform: rotate(var(--kula-tilt, 0deg)); transition: transform .35s ease; }

.kula-eye  { transform-box: fill-box; transform-origin: center; animation: kBlink var(--kula-blink, 4.4s) ease-in-out infinite; }
.kula-eye-r { animation-delay: .03s; }
@keyframes kBlink { 0%, 93%, 100% { transform: scaleY(1); } 96% { transform: scaleY(.08); } }

/* the gaze: pupils slide toward whatever the bird was asked to look at */
.kula-pupil { transform: translate(var(--kula-look-x, 0px), var(--kula-look-y, 0px)); transition: transform .25s ease-out; }

/* wings: shapes are poses; a few states add a gesture on top. Each pose
   pivots at its own shoulder, which sits at a different corner of the
   shape's box depending on where the wing is. */
.kula-wing { transform-box: fill-box; }
.kula-wing-r { transform-origin: 8% 18%; }
.kula-wing-l { transform-origin: 92% 18%; }
.kula-wing-r.kula-wing--wave,  .kula-wing-r.kula-wing--cheer,
.kula-wing-r.kula-wing--thumb, .kula-wing-r.kula-wing--scratch { transform-origin: 6% 94%; }
.kula-wing-l.kula-wing--cheer  { transform-origin: 94% 94%; }
.kula-wing-r.kula-wing--point  { transform-origin: 0% 50%; }
.kula-wing-l.kula-wing--pointl { transform-origin: 100% 50%; }
.is-greeting .kula-wing-r { animation: kWave 1.5s ease-in-out 2 both; }
@keyframes kWave { 0%, 100% { transform: rotate(0); } 30% { transform: rotate(-16deg); } 60% { transform: rotate(12deg); } }
.is-pointing .kula-wing--point  { animation: kNudgeR 1.2s ease-in-out 3; }
.is-pointing .kula-wing--pointl { animation: kNudgeL 1.2s ease-in-out 3; }
@keyframes kNudgeR { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(6px); } }
@keyframes kNudgeL { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(-6px); } }
.is-encouraging .kula-wing--thumb, .is-success .kula-wing--thumb { animation: kThumb .6s ease-out 1 both; transform-origin: 8% 80%; }
@keyframes kThumb { 0% { transform: rotate(18deg); } 60% { transform: rotate(-6deg); } 100% { transform: rotate(0); } }
.is-celebrating .kula-wing--cheer, .is-excited .kula-wing--cheer { animation: kCheer .9s ease-in-out 3; }
.is-celebrating .kula-wing-l.kula-wing--cheer, .is-excited .kula-wing-l.kula-wing--cheer { animation-direction: alternate-reverse; }
@keyframes kCheer { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(-9deg); } }
.is-confused .kula-wing--scratch { animation: kScratch .7s ease-in-out 3; transform-origin: 8% 90%; }
@keyframes kScratch { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(-7deg); } }
.is-thinking .kula-wing--chin { animation: kTap 1.4s ease-in-out infinite; transform-origin: 10% 20%; }
@keyframes kTap { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(-4deg); } }
.is-loading .kula-turn { animation: kSway 2.6s ease-in-out infinite; }
@keyframes kSway { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }

/* the whole bird: hops for a celebration, a small bounce for excitement, a sag for error */
.is-celebrating .kula-root { animation: kHop .55s cubic-bezier(.34, 1.56, .64, 1) 2, kBreathe 4.2s ease-in-out 1.2s infinite; }
.is-excited .kula-root     { animation: kHop .5s ease-out 2, kBreathe 4.2s ease-in-out 1.1s infinite; }
.is-success .kula-root     { animation: kBounce .6s cubic-bezier(.34, 1.56, .64, 1) 1, kBreathe 4.2s ease-in-out .7s infinite; }
.is-happy .kula-root       { animation: kBounce .6s ease-out 1, kBreathe 4.2s ease-in-out .7s infinite; }
.is-error .kula-root       { animation: kSag .6s ease-out 1 both, kBreathe 5s ease-in-out .7s infinite; }
@keyframes kHop    { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-14px) scale(1.02, .98); } }
@keyframes kBounce { 0% { transform: translateY(0); } 35% { transform: translateY(-8px); } 100% { transform: translateY(0); } }
@keyframes kSag    { 0% { transform: translateY(0); } 100% { transform: translateY(3px); } }

/* props */
.kula-sparkle { transform-box: fill-box; transform-origin: center; animation: kSparkle 1.6s ease-in-out infinite; }
.kula-sparkle:nth-child(2) { animation-delay: .4s; }
.kula-sparkle:nth-child(3) { animation-delay: .8s; }
@keyframes kSparkle { 0%, 100% { transform: scale(.4); opacity: .3; } 50% { transform: scale(1.1); opacity: 1; } }
.kula-dot { animation: kDot 1.3s ease-in-out infinite; }
.kula-dot:nth-child(2) { animation-delay: .18s; }
.kula-dot:nth-child(3) { animation-delay: .36s; }
@keyframes kDot { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
.kula-drop { transform-box: fill-box; transform-origin: top; animation: kDrip 2.2s ease-in infinite; }
@keyframes kDrip { 0% { transform: translateY(-6px) scale(.8); opacity: 0; } 20% { opacity: .9; } 70% { transform: translateY(6px) scale(1); opacity: .9; } 100% { transform: translateY(14px); opacity: 0; } }
.kula-bang  { transform-box: fill-box; transform-origin: center; animation: kPop .5s cubic-bezier(.34, 1.56, .64, 1) 1 both, kPulse 2s ease-in-out .6s infinite; }
.kula-check { transform-box: fill-box; transform-origin: center; animation: kPop .5s cubic-bezier(.34, 1.56, .64, 1) .2s 1 both; }
@keyframes kPop   { 0% { transform: scale(.2); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes kPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }
.kula-z { animation: kFloat 2.8s ease-in-out infinite; }
.kula-z:nth-child(2) { animation-delay: .9s; }
@keyframes kFloat { 0% { transform: translate(0, 4px); opacity: 0; } 30%, 70% { opacity: .7; } 100% { transform: translate(6px, -12px); opacity: 0; } }

/* ── Scenes: the bird beside words ────────────────────────────────────────── */
.kula-scene {
  display: flex; align-items: center; gap: 18px;
  text-align: left;
}
.kula-scene--right { flex-direction: row-reverse; }
.kula-scene--stack { flex-direction: column; text-align: center; gap: 10px; }
.kula-scene .kula-words { min-width: 0; flex: 1 1 auto; }
.kula-scene h3, .kula-scene .kula-title {
  font-size: 1.02rem; font-weight: 800; letter-spacing: -.01em; color: var(--ink); margin: 0 0 4px;
}
.kula-scene p, .kula-scene .kula-text { color: var(--muted); font-size: .9rem; line-height: 1.55; margin: 0; max-width: 46ch; }
.kula-scene--stack p { margin-left: auto; margin-right: auto; }
.kula-scene .kula-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 12px; }
.kula-scene--stack .kula-actions { justify-content: center; }

/* the speech bubble: a soft card with a tail toward the bird */
.kula-bubble {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 18px;
  box-shadow: var(--shadow-xs);
}
.kula-bubble::before {
  content: ""; position: absolute; top: 50%; left: -7px; width: 12px; height: 12px;
  background: var(--surface); border-left: 1px solid var(--line); border-bottom: 1px solid var(--line);
  transform: translateY(-50%) rotate(45deg);
}
.kula-scene--right .kula-bubble::before { left: auto; right: -7px; transform: translateY(-50%) rotate(-135deg); }
.kula-scene--stack .kula-bubble::before { top: -7px; left: 50%; transform: translateX(-50%) rotate(135deg); }
.kula-bubble--soft { background: color-mix(in srgb, var(--brand) 7%, var(--surface)); border-color: color-mix(in srgb, var(--brand) 22%, var(--line)); }
.kula-bubble--soft::before { background: color-mix(in srgb, var(--brand) 7%, var(--surface)); border-color: color-mix(in srgb, var(--brand) 22%, var(--line)); }
.kula-bubble--success { border-color: color-mix(in srgb, var(--success) 40%, var(--line)); }
.kula-bubble--warning { border-color: color-mix(in srgb, var(--warning) 45%, var(--line)); }
.kula-bubble--danger  { border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }

/* empty state: the bird, then the words, centred in a card body */
.kula-empty { padding: 40px 20px 44px; text-align: center; }
.kula-empty .kula { margin-bottom: 6px; }
.kula-empty h3 { font-size: 1.02rem; font-weight: 800; color: var(--ink); margin: 0 0 6px; }
.kula-empty p  { color: var(--muted); font-size: .875rem; max-width: 42ch; margin: 0 auto; line-height: 1.55; }
.kula-empty .kula-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: .5rem; margin-top: 16px; }
.kula-empty--compact { padding: 22px 16px 26px; }
.kula-empty--compact h3 { font-size: .95rem; }

/* dashboard greeting */
.kula-greet {
  display: flex; align-items: center; gap: 18px;
  padding: 16px 22px 16px 16px;
  margin-bottom: 20px;
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--brand) 18%, var(--line));
  background:
    radial-gradient(70% 140% at 0% 50%, color-mix(in srgb, var(--brand) 12%, transparent), transparent 70%),
    var(--surface);
}
.kula-greet-words { min-width: 0; flex: 1; }
.kula-greet-intro { color: var(--ink); margin: 0 0 6px !important; font-size: .92rem !important; line-height: 1.5; max-width: 44rem; }
.kula-greet--intro h2 { font-size: 1.35rem; }
.kula-greet h2 { font-size: 1.22rem; font-weight: 800; letter-spacing: -.02em; margin: 0 0 3px; }
.kula-greet p  { color: var(--muted); margin: 0; font-size: .9rem; }
.kula-greet .kula-actions { flex: 0 0 auto; display: flex; gap: .5rem; flex-wrap: wrap; justify-content: flex-end; }

/* a passing message inside a flash alert */
.alert .kula-flash { margin: -2px 2px -2px -4px; }

/* inline hint */
.kula-hint {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 6px 14px 6px 6px; border-radius: 999px;
  background: color-mix(in srgb, var(--brand) 8%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--brand) 20%, var(--line));
  color: var(--ink-2); font-size: .84rem; line-height: 1.35;
}

/* loading */
.kula-loading { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .9rem; }
.kula-loading--stack { flex-direction: column; text-align: center; padding: 28px 12px; }

/* onboarding checklist: the bird reacts as steps complete */
.kula-onboard {
  display: grid; grid-template-columns: auto 1fr; gap: 18px; align-items: start;
  padding: 20px 22px;
  margin-bottom: 20px;
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--brand) 22%, var(--line));
  background:
    radial-gradient(60% 120% at 100% 0%, color-mix(in srgb, var(--brand-2) 10%, transparent), transparent 70%),
    var(--surface);
}
.kula-onboard-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.kula-onboard h2 { font-size: 1.1rem; font-weight: 800; margin: 0; letter-spacing: -.01em; }
.kula-onboard-sub { color: var(--muted); font-size: .86rem; margin: 0 0 10px; }
.kula-onboard-bar { height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; margin: 0 0 12px; }
.kula-onboard-bar > i { display: block; height: 100%; width: var(--pct, 0%); border-radius: inherit;
  background: linear-gradient(90deg, var(--brand), var(--brand-2)); transition: width .6s cubic-bezier(.34, .8, .3, 1); }
.kula-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.kula-step {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 80%, transparent);
  text-decoration: none; color: var(--ink); font-size: .9rem;
  transition: border-color .15s, transform .15s;
}
a.kula-step:hover { border-color: var(--brand); transform: translateX(2px); color: var(--ink); }
.kula-step-n {
  flex: 0 0 26px; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; font-size: .78rem; font-weight: 800;
  border: 2px solid var(--line); color: var(--muted);
}
.kula-step.is-done { opacity: .82; }
.kula-step.is-done .kula-step-n { background: var(--success); border-color: var(--success); color: #fff; }
.kula-step.is-next .kula-step-n { border-color: var(--brand); color: var(--brand-ink, var(--brand)); }
.kula-step.is-next { border-color: color-mix(in srgb, var(--brand) 45%, var(--line)); }
.kula-step-t { flex: 1; min-width: 0; }
.kula-step-t small { display: block; color: var(--muted); font-size: .76rem; }
.kula-step .bi-chevron-right { color: var(--muted); font-size: .8rem; }
/* No bird (the greeting above already has one): the checklist takes the whole card. This has to come AFTER the
   base rule — declared above it, it lost the cascade and the list was squeezed into the bird's `auto` column,
   leaving half the card empty on a wide screen. */
.kula-onboard.kula-onboard--nobird { grid-template-columns: minmax(0, 1fr); }
@media (min-width: 992px) { .kula-onboard--nobird .kula-steps { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 10px; } }
.kula-onboard-foot { margin-top: 10px; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.kula-onboard-foot button { background: none; border: 0; color: var(--muted); font-size: .8rem; padding: 0; text-decoration: underline; }

/* the bird peeking over a card (auth screens) */
.kula-peek-host { position: relative; }
.kula-peek { position: absolute; top: -66px; right: 22px; z-index: 2; filter: drop-shadow(0 6px 10px rgba(15, 23, 42, .18)); }

/* host console lobby: the bird sits beside the count while the room fills */
.ef-lobby-kula { display: inline-flex; align-items: center; gap: 12px; margin-top: 1rem; text-align: left; }
.ef-lobby-kula p { max-width: 22rem; }

/* branding preview: the bird in the colours being chosen */
.kula-swatch { display: flex; align-items: center; gap: 12px; margin-top: 12px; padding: 10px 12px;
               border: 1px dashed var(--line); border-radius: 12px; font-size: .82rem; color: var(--muted); }

/* toast face */
.kula--toast { margin-right: 2px; }
.swal2-toast .swal2-icon.kula-toast-icon { border: 0; width: 34px; height: 34px; margin: 0 .5em 0 0; }

/* ── Small screens ────────────────────────────────────────────────────────── */
@media (max-width: 575.98px) {
  .kula-scene { gap: 12px; }
  .kula-scene:not(.kula-scene--stack) .kula { --kula-size: 72px !important; }
  /* wrap, or the full-width action row below squeezes the words to one
     word per line (measured at 390px with the introduction on) */
  .kula-greet { padding: 14px; gap: 12px; flex-wrap: wrap; }
  .kula-greet .kula { --kula-size: 64px !important; }
  .kula-greet-words { flex: 1 1 12rem; }
  .kula-greet h2 { font-size: 1.05rem; }
  .kula-greet .kula-actions { flex: 1 0 100%; justify-content: flex-start; }
  .kula-onboard { grid-template-columns: 1fr; }
  .kula-onboard > .kula { --kula-size: 72px !important; }
  .kula-peek { --kula-size: 68px !important; top: -46px; right: 14px; }
  .kula-empty .kula { --kula-size: 96px !important; }
}
/* When the dashboard's start panel stacks (the deck list moves below the
   words), a wing pointing off to the right points at nothing; turn it down. */
@media (max-width: 991.98px) {
  .dh-hero .kula-wing--point { transform: rotate(44deg); animation: none; }
}

/* ── Less motion ──────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .kula *, .kula .kula-svg, .kula-root, .kula-turn, .kula-eye, .kula-wing, .kula-sparkle, .kula-dot,
  .kula-drop, .kula-bang, .kula-check, .kula-z, .kula-onboard-bar > i, .kula-step {
    animation: none !important; transition: none !important;
  }
  .kula-pupil { transition: none; }
}
