:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --rose: #ff719d;
  --rose-light: #ffd3e1;
  background: #09070b;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: #09070b;
}

body {
  min-width: 320px;
  color: #fff7fb;
  overscroll-behavior: none;
}

button { font: inherit; }

.app-shell {
  position: relative;
  width: min(100%, 520px);
  height: 100svh;
  min-height: 100svh;
  margin: 0 auto;
  overflow: hidden;
  background: #120d15;
  isolation: isolate;
}

.stage {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #201720;
}

.portrait-rig {
  position: absolute;
  inset: -3.5%;
  overflow: hidden;
  contain: strict;
}

.portrait-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 43%;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.portrait-video {
  z-index: 1;
  opacity: 0;
  background: #201720 url("./assets/companion-portrait.png") center 43% / cover no-repeat;
  transition: opacity 180ms ease;
}

.portrait-fallback {
  z-index: 0;
  display: block;
}

.portrait-video.is-playing { opacity: 1; }

.stage-shade {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(6, 4, 7, 0.35) 0%, transparent 22%),
    linear-gradient(180deg, transparent 64%, rgba(7, 4, 8, 0.16) 79%, rgba(8, 5, 9, 0.72) 100%);
  pointer-events: none;
}

.talk-button {
  position: absolute;
  z-index: 8;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  display: grid;
  width: 88px;
  height: 88px;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(255, 200, 219, 0.76);
  border-radius: 50%;
  color: #3c0d1e;
  background: linear-gradient(145deg, var(--rose-light), var(--rose));
  box-shadow:
    0 0 0 10px rgba(255, 113, 157, 0.1),
    0 16px 44px rgba(0, 0, 0, 0.46),
    inset 0 1px rgba(255, 255, 255, 0.48);
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transform: translateX(-50%);
  transition: transform 160ms ease, filter 160ms ease, box-shadow 160ms ease;
}

.talk-button:active,
.talk-button.is-recording {
  filter: brightness(1.08) saturate(1.08);
  transform: translateX(-50%) scale(0.94);
  box-shadow:
    0 0 0 13px rgba(255, 113, 157, 0.16),
    0 12px 36px rgba(0, 0, 0, 0.5),
    inset 0 1px rgba(255, 255, 255, 0.58);
}

.talk-icon {
  position: relative;
  z-index: 2;
  width: 37px;
  height: 37px;
  overflow: visible;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.talk-icon path:first-child { stroke: none; }
.talk-icon path:last-child { fill: none; }

.talk-rings {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.talk-rings i {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 88px;
  height: 88px;
  border: 1px solid rgba(255, 212, 226, 0.55);
  border-radius: 50%;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.72);
}

.talk-button.is-recording .talk-rings i { animation: record-ring 1.5s ease-out infinite; }
.talk-button.is-recording .talk-rings i:nth-child(2) { animation-delay: 500ms; }
.talk-button.is-recording .talk-rings i:nth-child(3) { animation-delay: 1000ms; }

.heart-burst {
  position: absolute;
  z-index: 5;
  top: 38%;
  left: 50%;
  display: grid;
  width: 96px;
  height: 96px;
  place-items: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 20px) scale(0.4);
}

.heart-burst span {
  position: relative;
  z-index: 2;
  color: #ff77a2;
  font-size: 4.8rem;
  filter: drop-shadow(0 8px 22px rgba(255, 63, 124, 0.48));
}

.heart-burst i {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ffd1df;
}

.heart-burst i:nth-of-type(1) { transform: translate(-48px, -18px); }
.heart-burst i:nth-of-type(2) { transform: translate(46px, -30px); }
.heart-burst i:nth-of-type(3) { transform: translate(38px, 36px); }

.toast {
  position: fixed;
  z-index: 20;
  right: 22px;
  bottom: calc(128px + env(safe-area-inset-bottom));
  left: 22px;
  max-width: 430px;
  margin: auto;
  padding: 11px 15px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.88);
  background: rgba(17, 10, 20, 0.86);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(16px);
  font-size: 0.82rem;
  text-align: center;
}

.app-shell[data-state="heart"] .heart-burst { animation: heart-in 2.25s cubic-bezier(0.2, 0.8, 0.2, 1) both; }

@keyframes heart-in {
  0% { opacity: 0; transform: translate(-50%, 18px) scale(0.35) rotate(-9deg); }
  18%, 72% { opacity: 1; transform: translate(-50%, 0) scale(1) rotate(0); }
  45% { transform: translate(-50%, -5px) scale(1.12) rotate(4deg); }
  100% { opacity: 0; transform: translate(-50%, -30px) scale(0.86) rotate(7deg); }
}

@keyframes record-ring {
  0% { opacity: 0.5; transform: translate(-50%, -50%) scale(0.7); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.75); }
}

@media (min-width: 700px) {
  body { display: grid; place-items: center; }
  .app-shell { max-height: 960px; }
}

@media (prefers-reduced-motion: reduce) {
  .heart-burst,
  .talk-rings i {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
