:root {
  --bg: #f7f7f9;
  --bg2: #efeff3;
  --surface: #ffffff;
  --ink: #0c0c14;
  --ink2: #2a2a38;
  --muted: #8888a0;
  --border: #e4e4ec;

  /* Scroll-linked ambient (0–1); set by js/iris-tide.js */
  --iris-tide: 0;
  /* Same scroll math; always updated for top progress bar */
  --scroll-progress: 0;

  /* Iridescent palette */
  --ir-1: #c0b8f8; /* lavender */
  --ir-2: #f0b8d8; /* rose */
  --ir-3: #b8e8f8; /* sky */
  --ir-4: #b8f8e8; /* mint */
  --ir-5: #f8e8b8; /* gold */
  --ir-6: #e8c0f8; /* violet */
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html {
  scroll-behavior: smooth;
  scroll-padding-top: 96px;
}

/* Iris scroll progress — thin strip at top of viewport */
html::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  z-index: 51;
  pointer-events: none;
  background: linear-gradient(90deg, var(--ir-1), var(--ir-2), var(--ir-3), var(--ir-6));
  transform: scaleX(var(--scroll-progress, 0));
  transform-origin: left center;
}
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Sora', sans-serif;
  font-weight: 300;
  overflow-x: hidden;
}
::selection { background: var(--ir-1); color: var(--ink); }
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: linear-gradient(var(--ir-1), var(--ir-2)); }

.serif { font-family: 'DM Serif Display', serif; }

/* ===== IRIDESCENT EFFECTS ===== */

/* Animated iridescent border via wrapper trick */
@keyframes iris-rotate {
  0%   { --angle: 0deg; }
  100% { --angle: 360deg; }
}

/* Selected Work cards: 1s fade-in, then 3s fade-out while hover holds (4s total) */
@keyframes iris-border-work-opacity {
  0% {
    opacity: 0;
  }
  25% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}
@property --angle {
  syntax: '<angle>';
  initial-value: 0deg;
  inherits: false;
}

.iris-border {
  position: relative;
  background: var(--surface);
  border-radius: 4px;
}
.iris-border::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 5px;
  background: conic-gradient(from var(--angle),
    var(--ir-1), var(--ir-2), var(--ir-3),
    var(--ir-4), var(--ir-5), var(--ir-6), var(--ir-1));
  animation: iris-rotate 6s linear infinite;
  z-index: -1;
  opacity: 0;
  transition: opacity 0.4s;
}
.iris-border:hover::before { opacity: 1; }

.work-grid .project-card.iris-border:hover::before {
  animation:
    iris-rotate 6s linear infinite,
    iris-border-work-opacity var(--iris-work-border-duration, 4s) linear forwards;
  transition: none;
}

@media (prefers-reduced-motion: reduce) {
  .work-grid .project-card.iris-border:hover::before {
    animation: none;
    opacity: 0.75;
    transition: opacity 0.35s ease;
  }
}

/* Iridescent text gradient — static shimmer */
.iris-text {
  background: linear-gradient(135deg,
    #a890f8 0%, #f090c8 20%, #90d0f8 40%,
    #a890f8 60%, #f090c8 80%, #90d0f8 100%);
  background-size: 200% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: iris-slide 6s linear infinite;
}
@keyframes iris-slide {
  0% { background-position: 0% center; }
  100% { background-position: 200% center; }
}

/* Iridescent underline */
.iris-underline {
  position: relative;
  display: inline-block;
}
.iris-underline::after {
  content: '';
  position: absolute;
  bottom: -3px; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--ir-1), var(--ir-2), var(--ir-3), var(--ir-6));
  background-size: 200% auto;
  animation: iris-slide 4s linear infinite;
}

/* Surface card */
.card {
  background: var(--surface);
  border-radius: 4px;
  transition: all 0.3s ease;
}
.card:hover {
  border-color: transparent;
  box-shadow: 0 8px 40px rgba(160,136,248,0.12), 0 2px 8px rgba(0,0,0,0.06);
}

/* Pill tag */
.pill {
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 4px 14px;
  font-size: 11px;
  letter-spacing: 0.5px;
  border-radius: 40px;
  display: inline-block;
  transition: all 0.25s;
  background: white;
}
.pill:hover {
  background: linear-gradient(135deg, rgba(168,144,248,0.1), rgba(240,144,200,0.1));
  border-color: rgba(168,144,248,0.4);
  color: var(--ink2);
}
.pill.featured {
  background: linear-gradient(135deg, rgba(168,144,248,0.12), rgba(240,144,200,0.12));
  border-color: rgba(168,144,248,0.35);
  color: #7060c8;
}

/* Nav link */
.nav-link {
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.2s;
  font-weight: 400;
}
.nav-link:hover { color: var(--ink); }

.nav-link.nav-link-active {
  font-weight: 600;
  background: linear-gradient(135deg,
    #a890f8 0%, #f090c8 20%, #90d0f8 40%,
    #a890f8 60%, #f090c8 80%, #90d0f8 100%);
  background-size: 200% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: iris-slide 6s linear infinite;
  position: relative;
}
.nav-link.nav-link-active::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -7px;
  height: 2px;
  border-radius: 1px;
  background: linear-gradient(90deg, var(--ir-1), var(--ir-2), var(--ir-3));
}

/* Section number */
.num {
  font-family: 'Sora', sans-serif;
  font-size: 10px;
  letter-spacing: 3px;
  color: var(--muted);
  font-weight: 300;
}

/* Appear */
.appear {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 0.8s ease, transform 0.8s ease;
}
.appear.visible { opacity: 1; transform: translateY(0); }
.d1 { transition-delay: 0.1s; }
.d2 { transition-delay: 0.2s; }
.d3 { transition-delay: 0.3s; }
.d4 { transition-delay: 0.4s; }

/* CTA */
.cta {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 28px;
  font-weight: 500;
  transition: all 0.25s;
  border-radius: 3px;
}
.cta-iris {
  background: linear-gradient(135deg, #a890f8, #f090c8, #90c8f8);
  background-size: 200% auto;
  color: white;
  animation: iris-slide 5s linear infinite;
  box-shadow: 0 4px 20px rgba(168,144,248,0.25);
}
.cta-iris:hover {
  box-shadow: 0 8px 30px rgba(168,144,248,0.4);
  transform: translateY(-1px);
}
.cta-ghost {
  border: 1px solid var(--border);
  color: var(--muted);
  background: white;
}
.cta-ghost:hover {
  border-color: rgba(168,144,248,0.4);
  color: var(--ink);
}

/* Stat */
.stat-n {
  font-family: 'DM Serif Display', serif;
  font-size: 56px;
  line-height: 1;
  font-style: italic;
}

/* Timeline dot */
.tl-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ir-1), var(--ir-2));
  flex-shrink: 0;
  margin-top: 7px;
  box-shadow: 0 0 8px rgba(168,144,248,0.4);
}

/* Section divider */
.section-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
}

/* Hero shimmer bg — scroll tide shifts hue + parallax (see --iris-tide) */
.hero-shimmer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  filter: hue-rotate(calc(var(--iris-tide, 0) * 20deg));
}
.shimmer-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  animation: float-orb 15s ease-in-out infinite alternate;
  --iris-dx: 0px;
  --iris-dy: 0px;
}
.hero-shimmer .shimmer-orb:nth-child(1) {
  --iris-dx: calc(var(--iris-tide, 0) * 32px);
  --iris-dy: calc(var(--iris-tide, 0) * -22px);
}
.hero-shimmer .shimmer-orb:nth-child(2) {
  --iris-dx: calc(var(--iris-tide, 0) * -24px);
  --iris-dy: calc(var(--iris-tide, 0) * 28px);
}
.hero-shimmer .shimmer-orb:nth-child(3) {
  --iris-dx: calc(var(--iris-tide, 0) * 18px);
  --iris-dy: calc(var(--iris-tide, 0) * 20px);
}
@keyframes float-orb {
  0% { transform: translate(var(--iris-dx, 0px), var(--iris-dy, 0px)) translate(0, 0); }
  100% { transform: translate(var(--iris-dx, 0px), var(--iris-dy, 0px)) translate(40px, -30px); }
}

/* Fancy section heading */
.section-heading {
  font-family: 'Sora', sans-serif;
  font-weight: 700;
  letter-spacing: -0.5px;
}

/* Pearl rule */
.pearl-rule {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--ir-1), var(--ir-3), var(--ir-2), transparent);
  opacity: 0.5;
}

/* Iridescent stat box */
.stat-box {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 28px 24px;
  transition: all 0.3s;
  position: relative;
  overflow: hidden;
}
.stat-box::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg,
    rgba(168,144,248,0.05), rgba(240,144,200,0.05),
    rgba(144,208,248,0.05));
  opacity: 0;
  transition: opacity 0.3s;
}
.stat-box:hover::after { opacity: 1; }
.stat-box:hover {
  border-color: rgba(168,144,248,0.3);
  box-shadow: 0 8px 30px rgba(168,144,248,0.1);
  transform: translateY(-2px);
}

.stat-box--compact {
  padding: 16px !important;
  text-align: center;
}

/* ===== SELECTED WORK — uniform grid ===== */

#projects {
  /* 1s fade-in + 3s fade-out (keyframes: 0–25% in, 25–100% out) */
  --iris-work-border-duration: 4s;
  position: relative;
  overflow: hidden;
}

#projects::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 55% 40% at 12% 18%, rgba(192, 184, 248, 0.14), transparent 52%),
    radial-gradient(ellipse 45% 35% at 88% 72%, rgba(184, 232, 248, 0.12), transparent 48%);
  opacity: 0.85;
}

#projects > .max-w-6xl {
  position: relative;
  z-index: 1;
}

.work-lede {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.75;
  max-width: 42rem;
  margin: -0.5rem 0 2.5rem;
}

.work-grid {
  position: relative;
  z-index: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}

@media (min-width: 768px) {
  .work-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .work-grid .project-card {
    min-height: clamp(18rem, 28vh, 28rem);
  }
}

.work-grid .project-card {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  transition:
    filter 0.45s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.45s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.4s cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 0.35s ease;
}

/* Rack-style focus: lift + shadow; siblings dim (no JS timer). Hover wins over focus-within. */
.work-grid:has(.project-card:hover) .project-card:not(:hover) {
  filter: blur(0.7px);
  opacity: 0.7;
}

.work-grid:not(:has(.project-card:hover)):has(.project-card:focus-within) .project-card:not(:focus-within) {
  filter: blur(0.7px);
  opacity: 0.7;
}

@media (prefers-reduced-motion: reduce) {
  .work-grid:has(.project-card:hover) .project-card:not(:hover),
  .work-grid:not(:has(.project-card:hover)):has(.project-card:focus-within) .project-card:not(:focus-within) {
    filter: none;
    opacity: 0.82;
  }
}

.work-grid .project-card:hover {
  z-index: 3;
  transform: translateY(-4px);
  box-shadow:
    0 24px 56px rgba(84, 76, 140, 0.14),
    0 8px 20px rgba(0, 0, 0, 0.06);
}

.work-grid:not(:has(.project-card:hover)) .project-card:focus-within {
  z-index: 3;
  transform: translateY(-4px);
  box-shadow:
    0 24px 56px rgba(84, 76, 140, 0.14),
    0 8px 20px rgba(0, 0, 0, 0.06);
}

.project-kicker {
  font-size: 10px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.project-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 16px;
  line-height: 1.15;
}

.project-title--tight {
  margin-bottom: 4px;
}

.project-subtitle {
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 16px;
}

.project-desc {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.9;
  margin-bottom: 20px;
}

.work-card-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.work-card-main {
  min-width: 0;
}

/* Pills + demo/GitHub links: stay at bottom when card height varies */
.work-card-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  flex-shrink: 0;
}

.work-card-foot .project-actions {
  margin-top: 0;
}

.project-link {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  transition: color 0.2s ease;
}

.project-link:hover,
.project-link:focus-visible {
  color: #7060c8;
}

.project-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-top: 0;
}

/* Hero image mosaic */
.hero-gallery {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 14px;
}
.hero-frame {
  position: relative;
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  min-height: 170px;
  box-shadow: 0 10px 30px rgba(84, 76, 140, 0.06);
  --focus-x: 50%;
  --focus-y: 50%;
  --focus-alpha: 0;
}
/* Pointer-driven specular (see js/hero-specular.js) */
.hero-frame::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(
    circle 38% at var(--focus-x) var(--focus-y),
    rgba(255, 255, 255, 0.42) 0%,
    rgba(200, 190, 255, 0.14) 38%,
    rgba(144, 208, 248, 0.06) 58%,
    transparent 72%
  );
  opacity: var(--focus-alpha);
  transition: opacity 0.22s ease;
  mix-blend-mode: soft-light;
}
.hero-frame::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 3;
  background: linear-gradient(120deg, rgba(255,255,255,0) 40%, rgba(255,255,255,0.35) 52%, rgba(255,255,255,0) 64%);
  transform: translateX(-130%);
  transition: transform 0.7s ease;
  pointer-events: none;
}
.hero-frame:hover::after { transform: translateX(130%); }
.hero-frame img {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.hero-main { grid-row: span 2; min-height: 354px; }
.hero-caption {
  position: absolute;
  left: 12px;
  bottom: 10px;
  padding: 4px 9px;
  border-radius: 2px;
  font-size: 9px;
  letter-spacing: 1.8px;
  text-transform: uppercase;
  background: rgba(255,255,255,0.82);
  color: #64627c;
  border: 1px solid rgba(201, 198, 225, 0.92);
  backdrop-filter: blur(8px);
}
@media (max-width: 767px) {
  .hero-gallery { grid-template-columns: 1fr; }
  .hero-main { grid-row: span 1; min-height: 230px; }
}

/* ===== AI CHAT WIDGET ===== */

#chat-fab {
  position: fixed;
  bottom: 14px;
  right: 18px;
  z-index: 1002;
  width: 94px;
  height: 94px;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  display: grid;
  place-items: center;
  isolation: isolate;
  -webkit-tap-highlight-color: transparent;
  --bubble-shift-x: 0px;
  --bubble-shift-y: 0px;
  --bubble-rotate: -5deg;
  --bubble-scale-x: 1;
  --bubble-scale-y: 1;
  --bubble-opacity: 1;
  --bubble-blur: 0px;
  --bubble-brightness: 1;
  --eye-scale-x: 1;
  --eye-scale-y: 1;
  --eye-shift-y: 0px;
  --mouth-scale-x: 1;
  --mouth-scale-y: 1;
  --mouth-shift-y: 0px;
  --tongue-shift-x: 0px;
  --tongue-shift-y: 2px;
  --tongue-rotate: 0deg;
  --tongue-scale-x: 1;
  --tongue-scale-y: 1;
  --tongue-tip-scale: 1;
  --tongue-opacity: 1;
  --teeth-opacity: 1;
  --teeth-top-shift: 0px;
  --teeth-bottom-shift: 0px;
  --mouth-fill-opacity: 0;
  --mouth-depth-opacity: 1;
  --gloss-shift-y: 0px;
}

#chat-fab:focus-visible {
  outline: none;
}

#chat-fab:focus-visible .bubble-shadow {
  opacity: 0.95;
  transform: scale(1.15, 0.82);
}

#chat-fab:focus-visible .bubble-svg {
  filter:
    drop-shadow(0 12px 34px rgba(88, 66, 224, 0.38))
    drop-shadow(0 0 0 3px rgba(255,255,255,0.75));
}

.bubble-shadow {
  position: absolute;
  inset: auto 12px 8px;
  height: 18px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(56, 28, 124, 0.42) 0%, rgba(56, 28, 124, 0.22) 48%, rgba(56, 28, 124, 0) 76%);
  filter: blur(5px);
  opacity: 0.68;
  transform: scale(1, 0.72);
  transition: transform 0.28s ease, opacity 0.28s ease;
}

.bubble-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  filter: drop-shadow(0 9px 24px rgba(74, 56, 192, 0.42));
  transition: filter 0.28s ease;
}

.bubble-character {
  transform-box: fill-box;
  transform-origin: center;
  transform:
    translate(var(--bubble-shift-x), var(--bubble-shift-y))
    rotate(var(--bubble-rotate))
    scaleX(var(--bubble-scale-x))
    scaleY(var(--bubble-scale-y));
  opacity: var(--bubble-opacity);
  filter: blur(var(--bubble-blur)) brightness(var(--bubble-brightness));
  transition:
    transform 0.28s cubic-bezier(0.2, 0.88, 0.28, 1.15),
    opacity 0.22s ease,
    filter 0.22s ease;
}

.bubble-body,
.bubble-mouth-shell,
.bubble-eye,
.bubble-tongue,
.bubble-teeth,
.bubble-gloss-main,
.bubble-gloss-small,
.bubble-mouth-depth {
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.bubble-eye {
  transform: translateY(var(--eye-shift-y)) scaleX(var(--eye-scale-x)) scaleY(var(--eye-scale-y));
}

.bubble-mouth-shell,
.bubble-mouth-depth,
.bubble-mouth-fill {
  transform: translateY(var(--mouth-shift-y)) scaleX(var(--mouth-scale-x)) scaleY(var(--mouth-scale-y));
}

.bubble-tongue {
  transform-origin: 58px 60px;
  transform:
    translate(var(--tongue-shift-x), var(--tongue-shift-y))
    rotate(var(--tongue-rotate))
    scaleX(var(--tongue-scale-x))
    scaleY(var(--tongue-scale-y));
  opacity: var(--tongue-opacity);
}

.bubble-tongue-tip {
  transform-box: fill-box;
  transform-origin: center;
  transform: scale(var(--tongue-tip-scale));
  transition: transform 0.2s ease;
}

.bubble-teeth-top {
  opacity: var(--teeth-opacity);
  transform: translateY(var(--teeth-top-shift));
}

.bubble-teeth-bottom {
  opacity: var(--teeth-opacity);
  transform: translateY(var(--teeth-bottom-shift));
}

.bubble-gloss-main,
.bubble-gloss-small {
  transform: translateY(var(--gloss-shift-y));
}

.bubble-mouth-fill {
  opacity: var(--mouth-fill-opacity);
}

.bubble-mouth-depth {
  opacity: var(--mouth-depth-opacity);
}

@keyframes bubble-idle-float {
  0%, 100% {
    transform:
      translate(var(--bubble-shift-x), calc(var(--bubble-shift-y) + 0px))
      rotate(calc(var(--bubble-rotate) - 1deg))
      scaleX(var(--bubble-scale-x))
      scaleY(var(--bubble-scale-y));
  }
  50% {
    transform:
      translate(var(--bubble-shift-x), calc(var(--bubble-shift-y) - 8px))
      rotate(calc(var(--bubble-rotate) + 3deg))
      scaleX(calc(var(--bubble-scale-x) * 1.02))
      scaleY(calc(var(--bubble-scale-y) * 0.99));
  }
}

@keyframes bubble-shadow-idle {
  0%, 100% { transform: scale(1, 0.72); opacity: 0.64; }
  50% { transform: scale(0.88, 0.6); opacity: 0.42; }
}

@keyframes bubble-eye-jitter {
  0%, 100% { transform: translateY(var(--eye-shift-y)) scaleX(var(--eye-scale-x)) scaleY(var(--eye-scale-y)); }
  22% { transform: translate(-1px, calc(var(--eye-shift-y) + 0px)) scaleX(calc(var(--eye-scale-x) * 0.98)) scaleY(calc(var(--eye-scale-y) * 1.04)); }
  58% { transform: translate(1.4px, calc(var(--eye-shift-y) - 0.4px)) scaleX(calc(var(--eye-scale-x) * 1.02)) scaleY(calc(var(--eye-scale-y) * 0.96)); }
}

@keyframes bubble-mouth-breathe {
  0%, 100% {
    transform: translateY(var(--mouth-shift-y)) scaleX(var(--mouth-scale-x)) scaleY(var(--mouth-scale-y));
  }
  50% {
    transform: translateY(calc(var(--mouth-shift-y) + 0.8px)) scaleX(calc(var(--mouth-scale-x) * 1.02)) scaleY(calc(var(--mouth-scale-y) * 1.04));
  }
}

@keyframes bubble-gloss-drift {
  0%, 100% { transform: translateY(var(--gloss-shift-y)); }
  50% { transform: translate(1.5px, calc(var(--gloss-shift-y) - 1px)); }
}

@keyframes bubble-hover-body {
  0%, 100% {
    transform:
      translate(var(--bubble-shift-x), var(--bubble-shift-y))
      rotate(var(--bubble-rotate))
      scaleX(var(--bubble-scale-x))
      scaleY(var(--bubble-scale-y));
  }
  24% {
    transform:
      translate(calc(var(--bubble-shift-x) - 2px), calc(var(--bubble-shift-y) - 8px))
      rotate(calc(var(--bubble-rotate) - 10deg))
      scaleX(calc(var(--bubble-scale-x) * 1.08))
      scaleY(calc(var(--bubble-scale-y) * 0.93));
  }
  62% {
    transform:
      translate(calc(var(--bubble-shift-x) + 2px), calc(var(--bubble-shift-y) - 3px))
      rotate(calc(var(--bubble-rotate) + 9deg))
      scaleX(calc(var(--bubble-scale-x) * 0.97))
      scaleY(calc(var(--bubble-scale-y) * 1.06));
  }
}

@keyframes bubble-hover-tongue {
  0%, 100% {
    transform:
      translate(var(--tongue-shift-x), var(--tongue-shift-y))
      rotate(var(--tongue-rotate))
      scaleX(var(--tongue-scale-x))
      scaleY(var(--tongue-scale-y));
  }
  30% {
    transform:
      translate(calc(var(--tongue-shift-x) + 7px), calc(var(--tongue-shift-y) + 7px))
      rotate(calc(var(--tongue-rotate) + 24deg))
      scaleX(calc(var(--tongue-scale-x) * 0.95))
      scaleY(calc(var(--tongue-scale-y) * 1.08));
  }
  68% {
    transform:
      translate(calc(var(--tongue-shift-x) - 5px), calc(var(--tongue-shift-y) + 1px))
      rotate(calc(var(--tongue-rotate) - 22deg))
      scaleX(calc(var(--tongue-scale-x) * 1.05))
      scaleY(calc(var(--tongue-scale-y) * 0.94));
  }
}

@keyframes bubble-click-body {
  0% {
    transform:
      translate(var(--bubble-shift-x), var(--bubble-shift-y))
      rotate(var(--bubble-rotate))
      scaleX(var(--bubble-scale-x))
      scaleY(var(--bubble-scale-y));
  }
  20% {
    transform:
      translate(calc(var(--bubble-shift-x) + 2px), calc(var(--bubble-shift-y) + 6px))
      rotate(calc(var(--bubble-rotate) + 10deg))
      scaleX(calc(var(--bubble-scale-x) * 1.18))
      scaleY(calc(var(--bubble-scale-y) * 0.82));
  }
  55% {
    transform:
      translate(calc(var(--bubble-shift-x) - 4px), calc(var(--bubble-shift-y) - 12px))
      rotate(calc(var(--bubble-rotate) - 18deg))
      scaleX(calc(var(--bubble-scale-x) * 0.88))
      scaleY(calc(var(--bubble-scale-y) * 1.18));
  }
  100% {
    transform:
      translate(var(--bubble-shift-x), var(--bubble-shift-y))
      rotate(calc(var(--bubble-rotate) + 1deg))
      scaleX(var(--bubble-scale-x))
      scaleY(var(--bubble-scale-y));
  }
}

@keyframes bubble-click-mouth {
  0%, 100% {
    transform: translateY(var(--mouth-shift-y)) scaleX(var(--mouth-scale-x)) scaleY(var(--mouth-scale-y));
  }
  24% {
    transform: translateY(calc(var(--mouth-shift-y) + 4px)) scaleX(calc(var(--mouth-scale-x) * 0.92)) scaleY(calc(var(--mouth-scale-y) * 0.7));
  }
  55% {
    transform: translateY(calc(var(--mouth-shift-y) - 2px)) scaleX(calc(var(--mouth-scale-x) * 1.2)) scaleY(calc(var(--mouth-scale-y) * 1.25));
  }
}

@keyframes bubble-click-tongue {
  0% {
    transform:
      translate(var(--tongue-shift-x), var(--tongue-shift-y))
      rotate(var(--tongue-rotate))
      scaleX(var(--tongue-scale-x))
      scaleY(var(--tongue-scale-y));
  }
  28% {
    transform:
      translate(calc(var(--tongue-shift-x) + 2px), calc(var(--tongue-shift-y) - 11px))
      rotate(calc(var(--tongue-rotate) - 14deg))
      scaleX(calc(var(--tongue-scale-x) * 0.8))
      scaleY(calc(var(--tongue-scale-y) * 0.58));
  }
  52% {
    transform:
      translate(calc(var(--tongue-shift-x) + 16px), calc(var(--tongue-shift-y) + 18px))
      rotate(calc(var(--tongue-rotate) + 34deg))
      scaleX(calc(var(--tongue-scale-x) * 1.12))
      scaleY(calc(var(--tongue-scale-y) * 1.3));
  }
  78% {
    transform:
      translate(calc(var(--tongue-shift-x) - 11px), calc(var(--tongue-shift-y) + 4px))
      rotate(calc(var(--tongue-rotate) - 24deg))
      scaleX(calc(var(--tongue-scale-x) * 0.94))
      scaleY(calc(var(--tongue-scale-y) * 1.06));
  }
  100% {
    transform:
      translate(var(--tongue-shift-x), var(--tongue-shift-y))
      rotate(var(--tongue-rotate))
      scaleX(var(--tongue-scale-x))
      scaleY(var(--tongue-scale-y));
  }
}

@keyframes bubble-open-settle {
  0% {
    transform:
      translate(calc(var(--bubble-shift-x) + 16px), calc(var(--bubble-shift-y) + 8px))
      rotate(calc(var(--bubble-rotate) + 12deg))
      scaleX(calc(var(--bubble-scale-x) * 1.2))
      scaleY(calc(var(--bubble-scale-y) * 0.8));
  }
  100% {
    transform:
      translate(var(--bubble-shift-x), var(--bubble-shift-y))
      rotate(var(--bubble-rotate))
      scaleX(var(--bubble-scale-x))
      scaleY(var(--bubble-scale-y));
  }
}

@keyframes bubble-listening-body {
  0%, 100% {
    transform:
      translate(var(--bubble-shift-x), var(--bubble-shift-y))
      rotate(var(--bubble-rotate))
      scaleX(var(--bubble-scale-x))
      scaleY(var(--bubble-scale-y));
  }
  50% {
    transform:
      translate(var(--bubble-shift-x), calc(var(--bubble-shift-y) - 4px))
      rotate(calc(var(--bubble-rotate) - 4deg))
      scaleX(calc(var(--bubble-scale-x) * 1.05))
      scaleY(calc(var(--bubble-scale-y) * 0.95));
  }
}

@keyframes bubble-listening-tongue {
  0%, 100% {
    transform:
      translate(var(--tongue-shift-x), var(--tongue-shift-y))
      rotate(var(--tongue-rotate))
      scaleX(var(--tongue-scale-x))
      scaleY(var(--tongue-scale-y));
  }
  50% {
    transform:
      translate(calc(var(--tongue-shift-x) + 4px), calc(var(--tongue-shift-y) + 8px))
      rotate(calc(var(--tongue-rotate) + 14deg))
      scaleX(calc(var(--tongue-scale-x) * 0.98))
      scaleY(calc(var(--tongue-scale-y) * 1.08));
  }
}

@keyframes bubble-close-body {
  0% {
    transform:
      translate(var(--bubble-shift-x), var(--bubble-shift-y))
      rotate(var(--bubble-rotate))
      scaleX(var(--bubble-scale-x))
      scaleY(var(--bubble-scale-y));
  }
  40% {
    transform:
      translate(calc(var(--bubble-shift-x) + 1px), calc(var(--bubble-shift-y) - 18px))
      rotate(calc(var(--bubble-rotate) - 18deg))
      scaleX(calc(var(--bubble-scale-x) * 0.75))
      scaleY(calc(var(--bubble-scale-y) * 1.2));
  }
  100% {
    transform:
      translate(var(--bubble-shift-x), var(--bubble-shift-y))
      rotate(calc(var(--bubble-rotate) + 5deg))
      scaleX(var(--bubble-scale-x))
      scaleY(var(--bubble-scale-y));
  }
}

@keyframes bubble-close-tongue {
  0% {
    transform:
      translate(var(--tongue-shift-x), var(--tongue-shift-y))
      rotate(var(--tongue-rotate))
      scaleX(var(--tongue-scale-x))
      scaleY(var(--tongue-scale-y));
  }
  35% {
    transform:
      translate(calc(var(--tongue-shift-x) - 8px), calc(var(--tongue-shift-y) - 16px))
      rotate(calc(var(--tongue-rotate) - 34deg))
      scaleX(calc(var(--tongue-scale-x) * 0.76))
      scaleY(calc(var(--tongue-scale-y) * 0.5));
  }
  100% {
    transform:
      translate(var(--tongue-shift-x), var(--tongue-shift-y))
      rotate(var(--tongue-rotate))
      scaleX(var(--tongue-scale-x))
      scaleY(var(--tongue-scale-y));
  }
}

#chat-fab[data-bubble-state="idle"] .bubble-character {
  animation: bubble-idle-float 3.8s ease-in-out infinite;
}

#chat-fab[data-bubble-state="idle"] .bubble-shadow {
  animation: bubble-shadow-idle 3.8s ease-in-out infinite;
}

#chat-fab[data-bubble-state="idle"] .bubble-eye {
  animation: bubble-eye-jitter 4.8s steps(1, end) infinite;
}

#chat-fab[data-bubble-state="idle"] .bubble-mouth-shell,
#chat-fab[data-bubble-state="idle"] .bubble-mouth-depth {
  animation: bubble-mouth-breathe 3.2s ease-in-out infinite;
}

#chat-fab[data-bubble-state="idle"] .bubble-gloss-main,
#chat-fab[data-bubble-state="idle"] .bubble-gloss-small {
  animation: bubble-gloss-drift 4.6s ease-in-out infinite;
}

#chat-fab[data-bubble-state="hover"] .bubble-character {
  animation: bubble-hover-body 0.7s cubic-bezier(0.2, 0.88, 0.28, 1.15) 1;
}

#chat-fab[data-bubble-state="hover"] .bubble-tongue {
  animation: bubble-hover-tongue 0.35s cubic-bezier(0.2, 0.88, 0.28, 1.15) 1;
}

#chat-fab[data-bubble-state="click"] .bubble-character {
  animation: bubble-click-body 0.52s cubic-bezier(0.22, 1, 0.34, 1) 1;
}

#chat-fab[data-bubble-state="click"] .bubble-mouth-shell,
#chat-fab[data-bubble-state="click"] .bubble-mouth-depth {
  animation: bubble-click-mouth 0.52s cubic-bezier(0.22, 1, 0.34, 1) 1;
}

#chat-fab[data-bubble-state="click"] .bubble-tongue {
  animation: bubble-click-tongue 0.28s cubic-bezier(0.22, 1, 0.34, 1) 1;
}

#chat-fab[data-bubble-state="open"] .bubble-character {
  animation: bubble-open-settle 0.46s cubic-bezier(0.18, 0.88, 0.3, 1.08) 1;
}

#chat-fab[data-bubble-state="open"] .bubble-shadow,
#chat-fab[data-bubble-state="listening"] .bubble-shadow {
  opacity: 0.18;
  transform: scale(0.62, 0.46);
}

#chat-fab[data-bubble-state="listening"] .bubble-character {
  animation: bubble-listening-body 1.2s ease-in-out infinite;
}

#chat-fab[data-bubble-state="listening"] .bubble-tongue {
  animation: bubble-listening-tongue 0.6s ease-in-out infinite;
}

#chat-fab[data-bubble-state="close"] .bubble-character {
  animation: bubble-close-body 0.42s cubic-bezier(0.4, 0, 0.2, 1) 1;
}

#chat-fab[data-bubble-state="close"] .bubble-tongue {
  animation: bubble-close-tongue 0.21s cubic-bezier(0.4, 0, 0.2, 1) 1;
}

#chat-panel {
  position: fixed;
  bottom: 92px;
  right: 28px;
  z-index: 1001;
  width: 376px;
  max-height: 540px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.95), rgba(255,255,255,0.92)),
    radial-gradient(circle at top right, rgba(168,144,248,0.18), transparent 42%);
  border: 1px solid rgba(196, 194, 224, 0.95);
  border-radius: 22px;
  box-shadow:
    0 30px 84px rgba(88, 77, 146, 0.18),
    0 10px 30px rgba(27, 20, 52, 0.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  backdrop-filter: blur(22px);
  transform: translate3d(26px, 30px, 0) scale(0.76);
  transform-origin: calc(100% - 52px) calc(100% - 24px);
  opacity: 0;
  filter: blur(10px);
  pointer-events: none;
  transition:
    transform 0.46s cubic-bezier(0.2, 0.9, 0.25, 1),
    opacity 0.28s ease,
    filter 0.42s ease,
    box-shadow 0.32s ease;
}

#chat-panel::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 110px;
  background:
    radial-gradient(circle at top right, rgba(168,144,248,0.28), transparent 44%),
    radial-gradient(circle at top left, rgba(144,208,248,0.16), transparent 36%);
  pointer-events: none;
  opacity: 0.85;
}

#chat-panel.open,
#chat-panel[data-panel-state="opening"],
#chat-panel[data-panel-state="open"] {
  transform: translate3d(0, 0, 0) scale(1);
  opacity: 1;
  filter: blur(0);
  pointer-events: all;
}

#chat-panel[data-panel-state="closing"] {
  transform: translate3d(16px, 22px, 0) scale(0.82);
  opacity: 0;
  filter: blur(8px);
}

@media (max-width: 480px) {
  #chat-panel {
    right: 10px;
    left: 10px;
    width: auto;
    bottom: 96px;
    max-height: min(70vh, 560px);
  }
  #chat-fab { right: 8px; bottom: 8px; }
}

#chat-header {
  position: relative;
  z-index: 1;
  padding: 16px 18px 14px;
  border-bottom: 1px solid rgba(204, 202, 226, 0.9);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
#chat-header-iris {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 30%, rgba(255,255,255,0.9), rgba(255,255,255,0) 40%),
    linear-gradient(135deg, #a890f8, #f090c8, #90c8f8);
  box-shadow:
    0 8px 18px rgba(136, 111, 255, 0.24),
    inset 0 1px 0 rgba(255,255,255,0.6);
  animation: iris-slide 5s linear infinite;
  flex-shrink: 0;
}
#chat-header-text { flex: 1; }
#chat-header-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.2;
}
#chat-header-sub {
  font-size: 10px;
  color: #7b7696;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  margin-top: 3px;
}

#chat-sound-toggle,
#chat-reset,
#chat-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
  background: rgba(255,255,255,0.62);
  backdrop-filter: blur(8px);
  font-family: 'Sora', sans-serif;
  transition:
    color 0.2s ease,
    border-color 0.2s ease,
    background-color 0.2s ease,
    transform 0.18s ease,
    box-shadow 0.18s ease;
}

#chat-sound-toggle {
  padding: 5px 8px 5px 7px;
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

#chat-sound-toggle svg {
  width: 15px;
  height: 15px;
}

#chat-sound-toggle .sound-wave,
#chat-sound-toggle .sound-off-slash {
  transition: opacity 0.2s ease;
}

#chat-sound-toggle .sound-off-slash {
  opacity: 1;
}

#chat-sound-toggle .sound-wave,
#chat-panel[data-sound="off"] #chat-sound-toggle .sound-wave {
  opacity: 0.2;
}

#chat-panel[data-sound="off"] #chat-sound-toggle .sound-off-slash {
  opacity: 1;
}

#chat-panel[data-sound="on"] #chat-sound-toggle {
  color: #5b4dd8;
  border-color: rgba(109, 94, 232, 0.45);
  background: rgba(168,144,248,0.12);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.32);
}

#chat-panel[data-sound="on"] #chat-sound-toggle .sound-wave {
  opacity: 1;
}

#chat-panel[data-sound="on"] #chat-sound-toggle .sound-off-slash {
  opacity: 0;
}

#chat-reset {
  padding: 6px 9px;
  font-size: 10px;
  letter-spacing: 0.9px;
  text-transform: uppercase;
}

#chat-close {
  width: 30px;
  height: 30px;
  padding: 0;
  font-size: 16px;
}

#chat-sound-toggle:hover,
#chat-reset:hover,
#chat-close:hover {
  color: var(--ink);
  border-color: rgba(168,144,248,0.45);
  background: rgba(168,144,248,0.09);
  transform: translateY(-1px);
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  position: relative;
  z-index: 1;
  padding: 18px 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
#chat-messages::-webkit-scrollbar { width: 3px; }
#chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.chat-msg {
  max-width: 88%;
  font-size: 13px;
  line-height: 1.65;
  border-radius: 14px;
  padding: 11px 14px;
  animation: msg-in 0.24s ease;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.chat-msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(168,144,248,0.16), rgba(240,144,200,0.12));
  border: 1px solid rgba(168,144,248,0.28);
  color: var(--ink2);
  border-bottom-right-radius: 6px;
}
.chat-msg.assistant {
  align-self: flex-start;
  background: rgba(247,247,249,0.92);
  border: 1px solid rgba(223,223,236,0.92);
  color: var(--ink2);
  border-bottom-left-radius: 6px;
}
.chat-msg.assistant.typing { color: var(--muted); }

.chat-context-hint {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 8px 18px 0;
  margin: 0;
  position: relative;
  z-index: 1;
  line-height: 1.35;
}

#chat-suggestions {
  position: relative;
  z-index: 1;
  padding: 0 18px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
}
.chat-suggestion {
  font-size: 11px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.86);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: 'Sora', sans-serif;
}
.chat-suggestion:hover {
  border-color: rgba(168,144,248,0.4);
  color: var(--ink2);
  background: linear-gradient(135deg, rgba(168,144,248,0.07), rgba(240,144,200,0.07));
}

#chat-input-row {
  position: relative;
  z-index: 1;
  padding: 14px 18px 16px;
  border-top: 1px solid rgba(204, 202, 226, 0.9);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}
#chat-input {
  flex: 1;
  border: 1px solid rgba(212, 210, 232, 0.96);
  border-radius: 12px;
  padding: 10px 13px;
  font-size: 13px;
  font-family: 'Sora', sans-serif;
  color: var(--ink);
  background: rgba(247,247,249,0.95);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}
#chat-input:focus {
  border-color: rgba(168,144,248,0.5);
  box-shadow: 0 0 0 4px rgba(168,144,248,0.08);
  background: rgba(255,255,255,0.98);
}
#chat-input::placeholder { color: var(--muted); }
#chat-send {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, #a890f8, #f090c8);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 8px 18px rgba(168,144,248,0.28);
  transition: opacity 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
}
#chat-send:hover {
  opacity: 0.9;
  transform: translateY(-1px) scale(1.04);
  box-shadow: 0 12px 22px rgba(168,144,248,0.34);
}
#chat-send:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

#chat-api-overlay {
  position: absolute;
  inset: 0;
  background: var(--surface);
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px;
  gap: 14px;
  border-radius: 22px;
}
#chat-api-overlay.hidden { display: none; }
#chat-api-overlay p {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  line-height: 1.7;
}
#chat-api-overlay strong { color: var(--ink2); }
#chat-api-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 12px;
  font-family: 'Sora', sans-serif;
  font-weight: 300;
  color: var(--ink);
  background: var(--bg);
  outline: none;
  transition: border-color 0.2s;
}
#chat-api-input:focus { border-color: rgba(168,144,248,0.5); }
#chat-api-save {
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #a890f8, #f090c8, #90c8f8);
  background-size: 200% auto;
  animation: iris-slide 5s linear infinite;
  color: white;
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  font-family: 'Sora', sans-serif;
  cursor: pointer;
  transition: opacity 0.2s;
}
#chat-api-save:hover { opacity: 0.88; }
#chat-api-note {
  font-size: 10px;
  color: var(--muted);
  text-align: center;
  line-height: 1.6;
}

@media (prefers-reduced-motion: reduce) {
  #chat-fab,
  #chat-fab *,
  #chat-panel,
  #chat-panel * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.18s !important;
    scroll-behavior: auto !important;
  }

  .bubble-shadow {
    animation: none !important;
  }

  #chat-fab[data-bubble-state="idle"] .bubble-character,
  #chat-fab[data-bubble-state="idle"] .bubble-eye,
  #chat-fab[data-bubble-state="idle"] .bubble-mouth-shell,
  #chat-fab[data-bubble-state="idle"] .bubble-mouth-depth,
  #chat-fab[data-bubble-state="idle"] .bubble-gloss-main,
  #chat-fab[data-bubble-state="idle"] .bubble-gloss-small {
    animation: none !important;
  }
}
