/* ==========================================================================
   Milo — intro, teddy seats, sound popover, connection banner
   ========================================================================== */

html.is-intro, html.is-intro body { overflow: hidden; }

.milo-canvas { display: block; touch-action: manipulation; }
#milo-canvas { position: fixed; left: -9999px; top: 0; width: 10px; height: 10px; pointer-events: none; }
.hero-milo #milo-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* ---------- intro ---------- */

.intro {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: radial-gradient(70% 60% at 50% 38%, #fff6e8 0%, #fbe7cf 46%, #f2cfa6 100%);
  color: #2a1b12;
}
html[data-theme='dark'] .intro {
  background: radial-gradient(70% 60% at 50% 38%, #3a2618 0%, #23170f 52%, #120c08 100%);
  color: #fbf1e6;
}

.intro__sky { position: absolute; inset: 0; pointer-events: none; }
.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(2px);
  opacity: 0.55;
  background: radial-gradient(circle at 35% 30%, #fff7e6, rgba(255, 196, 128, 0.35) 60%, transparent 70%);
  animation: orb-float 9s ease-in-out infinite alternate;
}
.o1 { width: 220px; height: 220px; left: 6%; top: 12%; }
.o2 { width: 120px; height: 120px; right: 12%; top: 18%; animation-delay: -2s; background: radial-gradient(circle at 35% 30%, #ffe1e1, rgba(255, 143, 143, 0.32) 60%, transparent 70%); }
.o3 { width: 300px; height: 300px; right: -4%; bottom: -6%; animation-delay: -4s; }
.o4 { width: 90px; height: 90px; left: 18%; bottom: 16%; animation-delay: -6s; }
.o5 { width: 160px; height: 160px; left: 46%; top: -4%; animation-delay: -1s; opacity: 0.35; }
html[data-theme='dark'] .orb { opacity: 0.22; mix-blend-mode: screen; filter: blur(6px); }
@keyframes orb-float {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(24px, -30px, 0) scale(1.08); }
}

.intro__stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: -2vh;
  width: 100%;
}
.intro__milo { width: min(54vh, 84vw, 500px); aspect-ratio: 1; margin-bottom: -5.5vh; }

.intro__word {
  position: relative;
  height: 1.08em;
  width: 100%;
  font-family: var(--font-brand);
  font-weight: 600;
  font-size: clamp(64px, 13vw, 156px);
  line-height: 1;
  letter-spacing: -0.02em;
}
.iw {
  position: absolute;
  left: 50%;
  top: 0;
  display: flex;
  transform: translateX(-50%);
  white-space: pre;
}
.iw__ch { display: inline-block; will-change: transform, opacity; }
.iw--old { color: #5a4636; font-family: var(--font-display); font-weight: 400; font-style: italic; letter-spacing: -0.03em; }
html[data-theme='dark'] .iw--old { color: #d9c4b0; }
.iw--new .iw__ch {
  background: var(--honey-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 6px 14px rgba(184, 84, 31, 0.25));
  padding: 0 0.01em;
}
.intro__word.is-milo .iw--new { animation: word-float 2.4s ease-in-out infinite; }
@keyframes word-float {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-4px); }
}

.intro__tag {
  margin-top: 18px;
  font-size: 14px;
  color: #7a6150;
  letter-spacing: 0.01em;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.5s var(--ease), transform 0.5s var(--ease);
}
.intro__tag b { color: #b8541f; font-weight: 600; }
.intro__tag.is-in { opacity: 1; transform: none; }
html[data-theme='dark'] .intro__tag { color: #c6ab95; }

.intro__bubble {
  position: fixed;
  left: 60%;
  top: 22%;
  z-index: 1002;
  padding: 11px 16px 11px 15px;
  border-radius: 20px 20px 20px 6px;
  background: #fff;
  color: #2a1b12;
  font-family: var(--font-brand);
  font-weight: 600;
  font-size: 19px;
  white-space: nowrap;
  box-shadow: 0 14px 34px -12px rgba(120, 60, 20, 0.45);
  transform-origin: 0% 100%;
  transform: scale(0) rotate(-8deg);
  opacity: 0;
  pointer-events: none;
}
.intro__bubble.is-in { animation: bubble-pop 0.5s var(--spring) forwards; }
.intro__bubble.is-out { animation: bubble-out 0.25s ease-in forwards; }
@keyframes bubble-pop { to { transform: scale(1) rotate(0); opacity: 1; } }
@keyframes bubble-out { from { transform: scale(1); opacity: 1; } to { transform: scale(0.6) translateY(-10px); opacity: 0; } }
.wave-emoji { display: inline-block; transform-origin: 70% 80%; animation: wave-hand 0.9s ease-in-out infinite; }
@keyframes wave-hand {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(18deg); }
  40% { transform: rotate(-10deg); }
  60% { transform: rotate(16deg); }
  80% { transform: rotate(-6deg); }
}

.intro__fx { position: fixed; inset: 0; pointer-events: none; z-index: 1003; }
.spark {
  position: absolute;
  width: 9px;
  height: 9px;
  margin: -4.5px 0 0 -4.5px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 12px var(--c);
  animation: spark-fly 1.1s cubic-bezier(0.15, 0.7, 0.3, 1) forwards;
}
.spark--star {
  border-radius: 0;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  box-shadow: none;
  clip-path: polygon(50% 0, 61% 39%, 100% 50%, 61% 61%, 50% 100%, 39% 61%, 0 50%, 39% 39%);
}
@keyframes spark-fly {
  0% { transform: translate(0, 0) scale(0); opacity: 1; }
  30% { transform: translate(calc(var(--dx) * 0.6), calc(var(--dy) * 0.6)) scale(var(--s)) rotate(90deg); opacity: 1; }
  100% { transform: translate(var(--dx), calc(var(--dy) + 30px)) scale(0) rotate(200deg); opacity: 0; }
}

.intro__skip {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 1004;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  color: #6b5444;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(160, 110, 70, 0.22);
  backdrop-filter: blur(10px);
  transition: background 0.2s, transform 0.2s;
}
.intro__skip:hover { background: #fff; transform: translateY(-1px); }
.intro__skip .icon { width: 14px; height: 14px; }
html[data-theme='dark'] .intro__skip { color: #e3d3c3; background: rgba(255, 255, 255, 0.08); }

/* ---------- Milo's seat on the landing preview ---------- */

.landing__preview { margin-top: 150px; }
.hero-milo {
  position: absolute;
  z-index: 5;
  right: 3%;
  top: calc(24px - 244px);
  width: 272px;
  height: 272px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.hero-milo__bubble {
  position: absolute;
  right: 72%;
  top: 22%;
  white-space: nowrap;
  padding: 8px 13px;
  border-radius: 16px 16px 4px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  font-family: var(--font-brand);
  font-size: 15px;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  transform-origin: 100% 100%;
  transform: scale(0.4);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.35s var(--spring), opacity 0.2s;
}
.hero-milo__bubble.is-in { transform: scale(1); opacity: 1; }
.hero-milo.is-fallback::before,
.empty-card__milo.is-fallback::before {
  content: '🧸';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: end center;
  font-size: 120px;
  line-height: 1;
  padding-bottom: 14%;
}
.empty-card__milo.is-fallback::before { font-size: 64px; padding-bottom: 6px; }

/* ---------- mini Milo on the empty stage ---------- */

.empty-card__milo {
  position: relative;
  width: 150px;
  height: 150px;
  margin: -18px 0 0;
  cursor: pointer;
}
.empty-card__milo canvas { width: 100%; height: 100%; display: block; }
.stage-milo__bubble {
  position: absolute;
  left: 78%;
  top: 6%;
  z-index: 2;
  white-space: nowrap;
  padding: 6px 11px;
  border-radius: 14px 14px 14px 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  font-family: var(--font-brand);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  transform-origin: 0 100%;
  transform: scale(0.4);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.35s var(--spring), opacity 0.2s;
}
.stage-milo__bubble.is-in { transform: scale(1); opacity: 1; }
.stage__empty .empty-card h2 { font-family: var(--font-brand); font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }

/* ---------- landing touches ---------- */

.landing h1 em {
  background: var(--honey-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  padding-right: 0.06em;
}
.landing__glow {
  background:
    radial-gradient(42% 38% at 82% 14%, rgba(240, 162, 79, 0.24), transparent 70%),
    radial-gradient(35% 30% at 6% 32%, rgba(255, 143, 143, 0.12), transparent 70%);
}
.btn--primary { box-shadow: 0 6px 18px -8px color-mix(in srgb, var(--accent) 80%, transparent); }
.btn--primary:active { transform: translateY(1px) scale(0.99); }

/* ---------- dock: sound ---------- */

.dock-btn .mic-ring {
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  border: 2px solid var(--live);
  opacity: calc(var(--mic-level, 0) * 1.6);
  transform: scale(calc(0.85 + var(--mic-level, 0) * 0.3));
  transition: opacity 0.08s linear, transform 0.08s linear;
  pointer-events: none;
}
#btn-sound.is-active { background: var(--accent); color: #fff; }
#btn-sound.is-active .mic-ring { border-color: #fff; }

/* ---------- sound popover ---------- */

.sound-pop {
  position: fixed;
  z-index: 70;
  left: 50%;
  bottom: 92px;
  transform: translate(-50%, 0);
  width: min(400px, calc(100vw - 20px));
  max-height: calc(100dvh - 120px);
  overflow-y: auto;
  padding: 16px;
  border-radius: 22px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(24px);
}
.sound-pop__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.sound-pop__head h3 { font-family: var(--font-brand); font-size: 20px; font-weight: 600; }
.sound-pop__head p { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.sp-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border-radius: 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.sp-block + .sp-block { margin-top: 8px; }
.sp-block__title { display: flex; align-items: center; gap: 8px; }
.sp-block__title b { font-size: 13px; font-weight: 600; }
.sp-block__title small { font-size: 11px; color: var(--muted); }
.sp-ico { width: 26px; height: 26px; border-radius: 9px; display: grid; place-items: center; flex: none; }
.sp-ico .icon { width: 14px; height: 14px; }
.sp-ico--mic { background: color-mix(in srgb, var(--live) 16%, transparent); color: var(--live); }
.sp-ico--voice { background: color-mix(in srgb, #5b6bb5 16%, transparent); color: #5b6bb5; }
.sp-ico--music { background: var(--accent-soft); color: var(--accent); }
html[data-theme='dark'] .sp-ico--voice { color: #9aa6ee; }
.sp-test,
.sp-mic {
  margin-left: auto;
  height: 26px;
  padding: 0 11px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--line);
  transition: background 0.15s, color 0.15s, transform 0.15s;
}
.sp-test:hover { background: var(--accent); color: #fff; border-color: transparent; }
.sp-test:active { transform: scale(0.95); }
.sp-mic { width: 30px; padding: 0; display: grid; place-items: center; }
.sp-mic .icon { width: 14px; height: 14px; }
.sp-mic.is-off { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.sp-row { display: flex; gap: 6px; align-items: center; }
.sp-row .select-field { flex: 1; min-width: 0; }
.sp-range { display: flex; align-items: center; gap: 9px; color: var(--muted); }
.sp-range .icon { width: 15px; height: 15px; }
.sp-range output { width: 38px; text-align: right; font-size: 11px; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.sp-range input[type='range'] {
  --fill: 100%;
  flex: 1;
  height: 6px;
  appearance: none;
  -webkit-appearance: none;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent) var(--fill), var(--surface-3) var(--fill));
  cursor: pointer;
}
.sp-range input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  box-shadow: 0 2px 6px rgba(60, 32, 14, 0.25);
  transition: transform 0.15s;
}
.sp-range input[type='range']::-webkit-slider-thumb:hover { transform: scale(1.15); }
.sp-range input[type='range']::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: #fff; border: 2px solid var(--accent); }
.sp-note { font-size: 10.5px; line-height: 1.5; color: var(--muted); }
.sp-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }
.sp-foot .text-link { display: inline-flex; align-items: center; gap: 5px; }
.sp-foot .icon { width: 13px; height: 13px; }
.sp-foot__tip { font-size: 10.5px; color: var(--muted-2); }
.sound-pop .mic-level { height: 7px; }
.inline-buttons { display: inline-flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- connection banner ---------- */

.net-banner {
  position: fixed;
  z-index: 80;
  top: 74px;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: 12.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: banner-in 0.35s var(--spring);
}
.net-banner__spin {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--bg) 35%, transparent);
  border-top-color: var(--bg);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes banner-in { from { transform: translate(-50%, -14px); opacity: 0; } }

@media (max-width: 1000px) {
  .hero-milo { right: 4%; width: 236px; height: 236px; top: calc(24px - 212px); }
  .landing__preview { margin-top: 170px; }
}

@media (max-width: 620px) {
  .hero-milo { width: 200px; height: 200px; top: calc(24px - 180px); right: 0; }
  .landing__preview { margin-top: 140px; }
  .hero-milo__bubble { font-size: 13px; }
  .intro__bubble { font-size: 16px; }
  .intro__milo { margin-bottom: -3vh; }
  .sound-pop { bottom: 78px; padding: 13px; }
  .net-banner { top: 62px; }
  .empty-card__milo { width: 120px; height: 120px; margin-top: -10px; }
}

@media (prefers-reduced-motion: reduce) {
  .orb, .wave-emoji, .intro__word.is-milo .iw--new { animation: none !important; }
}
