@import url("https://fonts.googleapis.com/css2?family=Baloo+2:wght@400;600;700;800&display=swap");

:root {
  --ink: #2d2440;
  --muted: #8b7fa5;
  --accent: #ff5e9c;
  --accent2: #7c5cff;
  --glass: rgba(255, 255, 255, 0.78);
  --radius: 22px;
  --shadow: 0 10px 30px rgba(90, 60, 160, 0.18);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}
html,
body {
  height: 100%;
}
html {
  font-size: 16px;
}
body {
  font-family:
    "Baloo 2", "Comic Sans MS", "Chalkboard SE", system-ui, sans-serif;
  color: var(--ink);
  background: #1c1533;
  overflow: hidden;
}
#app {
  height: 100%;
}
.hidden {
  display: none !important;
}
.muted {
  color: var(--muted);
  font-size: 0.82em;
}
.hint {
  font-size: 0.7em;
  color: var(--muted);
  font-weight: 600;
}

/* ============ CREATE SCREEN ============ */
#create-screen {
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background:
    radial-gradient(1000px 500px at 80% -10%, #ffe3f1 0%, transparent 55%),
    radial-gradient(800px 500px at -10% 30%, #d9ecff 0%, transparent 55%),
    linear-gradient(165deg, #fdeef6 0%, #e6efff 60%, #dff3ff 100%);
}
.create-card {
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(14px);
  border-radius: 28px;
  padding: 28px 24px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow);
  text-align: center;
  border: 2px solid rgba(255, 255, 255, 0.9);
}
.logo {
  font-size: 2.3rem;
  font-weight: 800;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline {
  margin: 4px 0 20px;
  color: var(--muted);
  font-weight: 600;
}
#pet-name {
  width: 100%;
  padding: 15px;
  font-size: 1.15rem;
  border-radius: 16px;
  border: 2px solid #e6dcf7;
  outline: none;
  text-align: center;
  background: #fbf8ff;
  font-family: inherit;
  font-weight: 600;
  color: var(--ink);
}
#pet-name:focus {
  border-color: var(--accent2);
}
.species-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 18px 0;
}
.species-btn {
  background: #fbf8ff;
  border: 3px solid transparent;
  border-radius: 18px;
  padding: 14px 6px;
  font-size: 2rem;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.species-btn span {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  margin-top: 4px;
}
.species-btn:active {
  transform: scale(0.95);
}
.species-btn.active {
  border-color: var(--accent);
  background: #fff0f7;
  transform: scale(1.05);
  box-shadow: 0 6px 18px rgba(255, 94, 156, 0.3);
}
.seed-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 0 20px;
  font-size: 0.92rem;
  font-weight: 700;
}
.seed-row select {
  flex: 1;
  padding: 11px;
  border-radius: 14px;
  border: 2px solid #e6dcf7;
  background: #fbf8ff;
  font-size: 0.92rem;
  font-family: inherit;
  font-weight: 600;
  color: var(--ink);
}
.primary-btn {
  width: 100%;
  padding: 16px;
  font-size: 1.25rem;
  font-weight: 800;
  color: #fff;
  border: none;
  border-radius: 18px;
  cursor: pointer;
  font-family: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  box-shadow:
    0 8px 20px rgba(124, 92, 255, 0.4),
    inset 0 -3px 0 rgba(0, 0, 0, 0.12);
  transition: transform 0.1s;
}
.primary-btn:active {
  transform: scale(0.97);
}

/* ============ THE SCENE (full-screen world) ============ */
#game-screen {
  height: 100dvh;
  display: flex;
  justify-content: center;
}
.scene {
  --avatar-bottom: 21%;
  --avatar-size: clamp(11rem, min(58vw, 32vh), 17rem);
  position: relative;
  width: 100%;
  max-width: 540px;
  height: 100dvh;
  overflow: hidden;
  transition: background 1.2s ease;
  background: linear-gradient(180deg, #bfe4ff 0%, #e8f6ff 55%, #c9e8ff 100%);
}
@media (min-width: 600px) {
  .scene {
    border-left: 2px solid rgba(255, 255, 255, 0.3);
    border-right: 2px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.35);
  }
}

/* sky tints by mood */
.scene.mood-happy,
.scene.mood-excited,
.scene.mood-playful,
.scene.mood-loved,
.scene.mood-content,
.scene.mood-curious,
.scene.mood-dramatic {
  background: linear-gradient(180deg, #ffdfec 0%, #ffeef6 55%, #fff6d9 100%);
}
.scene.mood-grumpy,
.scene.mood-sad,
.scene.mood-scared,
.scene.mood-suspicious {
  background: linear-gradient(180deg, #b8b8d4 0%, #d5d5ea 60%, #c8ccdd 100%);
}
.scene.mood-hungry,
.scene.mood-thirsty {
  background: linear-gradient(180deg, #ffe3c4 0%, #fff0de 55%, #ffe9ef 100%);
}
.scene.mood-sleepy,
.scene.mood-bored {
  background: linear-gradient(180deg, #a99ad8 0%, #c4bbec 55%, #b8c4f5 100%);
}
/* time of day */
.scene.time-evening {
  filter: sepia(0.16) hue-rotate(-10deg) brightness(0.97);
}
.scene.time-night {
  filter: brightness(0.78) saturate(0.9) hue-rotate(6deg);
}
.scene.time-night .stars {
  opacity: 1;
}
.stars {
  position: absolute;
  inset: 0 0 55% 0;
  opacity: 0;
  transition: opacity 1.2s;
  pointer-events: none;
  background-image:
    radial-gradient(2px 2px at 12% 18%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 32% 8%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 55% 22%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 74% 10%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 88% 26%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 44% 34%, #fff 50%, transparent 51%);
  animation: twinkle 3s ease-in-out infinite alternate;
}
@keyframes twinkle {
  from {
    opacity: 0.55;
  }
  to {
    opacity: 1;
  }
}

.sunbeam {
  position: absolute;
  top: -70px;
  left: 50%;
  transform: translateX(-50%);
  width: 360px;
  height: 360px;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(255, 255, 255, 0.8) 0%,
    rgba(255, 255, 255, 0) 65%
  );
  pointer-events: none;
}
.cloud {
  position: absolute;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 999px;
  filter: blur(2px);
  opacity: 0.9;
}
.cloud::before,
.cloud::after {
  content: "";
  position: absolute;
  background: inherit;
  border-radius: 999px;
}
.cloud.c1 {
  width: 90px;
  height: 26px;
  top: 9%;
  left: 8%;
  animation: drift 26s linear infinite;
}
.cloud.c1::before {
  width: 40px;
  height: 40px;
  top: -18px;
  left: 14px;
}
.cloud.c1::after {
  width: 28px;
  height: 28px;
  top: -12px;
  left: 48px;
}
.cloud.c2 {
  width: 70px;
  height: 20px;
  top: 18%;
  right: 6%;
  animation: drift 34s linear infinite reverse;
}
.cloud.c2::before {
  width: 30px;
  height: 30px;
  top: -14px;
  left: 10px;
}
.cloud.c2::after {
  width: 22px;
  height: 22px;
  top: -10px;
  left: 38px;
}
.cloud.c3 {
  width: 60px;
  height: 18px;
  top: 28%;
  left: 32%;
  animation: drift 40s linear infinite;
  opacity: 0.7;
}
.cloud.c3::before {
  width: 26px;
  height: 26px;
  top: -12px;
  left: 8px;
}
.cloud.c3::after {
  width: 18px;
  height: 18px;
  top: -8px;
  left: 32px;
}
@keyframes drift {
  0% {
    transform: translateX(-40px);
  }
  100% {
    transform: translateX(60px);
  }
}

.hill {
  position: absolute;
  bottom: 56px;
  border-radius: 50%;
  pointer-events: none;
}
.hill.h1 {
  left: -20%;
  width: 70%;
  height: 120px;
  background: rgba(120, 200, 140, 0.35);
}
.hill.h2 {
  right: -25%;
  width: 75%;
  height: 140px;
  background: rgba(100, 185, 130, 0.3);
}
.floor {
  position: absolute;
  bottom: -34px;
  left: 50%;
  transform: translateX(-50%);
  width: 135%;
  height: 130px;
  border-radius: 50%;
  background: linear-gradient(180deg, #9fe08f 0%, #6fc46a 100%);
  box-shadow: inset 0 8px 0 rgba(255, 255, 255, 0.25);
}
.floor::before {
  content: "";
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: 140px;
  height: 36px;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(0, 0, 0, 0.2) 0%,
    rgba(0, 0, 0, 0) 70%
  );
}
.prop {
  position: absolute;
  z-index: 1;
  font-size: 1.6rem;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.15));
}
.prop.bowl {
  bottom: 52px;
  left: 18%;
}
.prop.toy {
  bottom: 46px;
  right: 16%;
}

/* ============ HUD: top ============ */
.hud-top {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  z-index: 20;
  gap: 8px;
  animation: slideDown 0.5s ease;
}
@keyframes slideDown {
  from {
    transform: translateY(-16px);
    opacity: 0;
  }
}
#pet-title {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  padding: 6px 12px 6px 8px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  border: 2px solid rgba(255, 255, 255, 0.85);
}
.pet-avatar {
  font-size: 1.9rem;
  line-height: 1;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.15));
}
.pet-avatar.small {
  font-size: 1.6rem;
}
h1 {
  font-size: 1.15rem;
  font-weight: 800;
  line-height: 1.05;
}
.new-pet-btn {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-left: 2px;
  padding: 3px 0 3px 9px;
  border: 0;
  border-left: 2px solid rgba(124, 92, 255, 0.18);
  background: transparent;
  color: var(--accent2);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 800;
  white-space: nowrap;
}
.new-pet-btn > span:first-child {
  font-size: 1rem;
  line-height: 1;
}
.new-pet-btn:focus-visible {
  border-radius: 6px;
  outline: 2px solid var(--accent2);
  outline-offset: 2px;
}
.hud-top-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 7px;
}
.mood-chip {
  background: var(--glass);
  backdrop-filter: blur(10px);
  white-space: nowrap;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 800;
  box-shadow: var(--shadow);
  border: 2px solid rgba(255, 255, 255, 0.85);
}
.speed-toggle {
  background: var(--glass);
  backdrop-filter: blur(10px);
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
  box-shadow: var(--shadow);
  cursor: pointer;
  border: 2px solid rgba(255, 255, 255, 0.85);
  display: flex;
  align-items: center;
  gap: 3px;
}
.speed-toggle input {
  accent-color: var(--accent2);
}

/* ============ HUD: stats ============ */
.hud-stats {
  position: absolute;
  top: calc(64px + env(safe-area-inset-top));
  left: 12px;
  z-index: 20;
  background: var(--glass);
  backdrop-filter: blur(10px);
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 9px 10px;
  display: grid;
  gap: 5px;
  width: 190px;
  animation: slideDown 0.6s ease;
}
.stat {
  display: flex;
  align-items: center;
  gap: 6px;
}
.stat-icon {
  width: 18px;
  text-align: center;
  font-size: 0.85rem;
}
.stat-label {
  display: none;
}
.bar {
  flex: 1;
  height: 9px;
  background: rgba(120, 100, 160, 0.15);
  border-radius: 99px;
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}
.fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.5s ease;
  position: relative;
}
.fill::after {
  content: "";
  position: absolute;
  inset: 0 0 55% 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.45), transparent);
  border-radius: 99px;
}
.fill.health {
  background: linear-gradient(90deg, #ff5e7a, #ff8fa3);
}
.fill.happy {
  background: linear-gradient(90deg, #ffc93c, #ffe07a);
}
.fill.hunger {
  background: linear-gradient(90deg, #ff9433, #ffb45e);
}
.fill.thirst {
  background: linear-gradient(90deg, #3ba2ff, #75c6ff);
}
.fill.energy {
  background: linear-gradient(90deg, #a55eff, #c48fff);
}
.fill.bond {
  background: linear-gradient(90deg, #ff5ec8, #ff8fda);
}
.stat-num {
  width: 22px;
  text-align: right;
  font-weight: 800;
  font-size: 0.72rem;
}

/* ============ pet ============ */
.avatar-wrap {
  position: absolute;
  left: 50%;
  bottom: var(--avatar-bottom);
  transform: translateX(-50%);
  z-index: 10;
}
.avatar {
  font-size: var(--avatar-size);
  line-height: 1;
  display: inline-block;
  animation: idlebob 3.2s ease-in-out infinite;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.2));
  transform-origin: 50% 100%;
}
@keyframes idlebob {
  0%,
  100% {
    transform: translateY(0) scale(1, 1);
  }
  50% {
    transform: translateY(-7px) scale(1.02, 0.98);
  }
}
.avatar.bounce {
  animation: bounce 0.5s ease;
}
@keyframes bounce {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }
  40% {
    transform: translateY(-22px) scale(0.96, 1.04);
  }
}
.avatar.sad {
  animation: sadrock 0.7s ease;
  filter: saturate(0.5) drop-shadow(0 8px 10px rgba(0, 0, 0, 0.2));
}
@keyframes sadrock {
  0%,
  100% {
    transform: rotate(0);
  }
  30% {
    transform: rotate(-10deg);
  }
  70% {
    transform: rotate(7deg);
  }
}
.avatar.sleepy {
  animation: sleepy 2.4s ease-in-out infinite;
}
@keyframes sleepy {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(0.93);
  }
}
.avatar.spin {
  animation: spinny 0.7s ease;
}
@keyframes spinny {
  0% {
    transform: rotate(0);
  }
  100% {
    transform: rotate(360deg);
  }
}
.avatar.wiggle {
  animation: wig 0.55s ease;
}
@keyframes wig {
  0%,
  100% {
    transform: rotate(0);
  }
  25% {
    transform: rotate(-11deg);
  }
  75% {
    transform: rotate(11deg);
  }
}
.zzz {
  position: absolute;
  top: -16px;
  right: -20px;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--accent2);
  display: none;
  pointer-events: none;
}
.avatar.sleepy ~ .zzz {
  display: block;
}
.zzz span {
  position: absolute;
  animation: zz 2.4s ease-in infinite;
  opacity: 0;
}
.zzz span:nth-child(2) {
  animation-delay: 0.8s;
}
.zzz span:nth-child(3) {
  animation-delay: 1.6s;
}
@keyframes zz {
  0% {
    opacity: 0;
    transform: translate(0, 0) scale(0.6);
  }
  30% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(16px, -46px) scale(1.2) rotate(18deg);
  }
}
.burst {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 15;
}
.burst span {
  position: absolute;
  left: 50%;
  top: 30%;
  font-size: 1.5rem;
  animation: pop-fly 1s ease-out forwards;
}
@keyframes pop-fly {
  0% {
    opacity: 0;
    transform: translate(0, 0) scale(0.5);
  }
  20% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(var(--dx), -95px) scale(1.25) rotate(var(--rot));
  }
}
.scene.shake {
  animation: shake 0.35s ease;
}
@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-6px);
  }
  50% {
    transform: translateX(5px);
  }
  75% {
    transform: translateX(-3px);
  }
}

/* ============ speech / status ============ */
.speech-bubble {
  position: absolute;
  z-index: 14;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--avatar-bottom) + var(--avatar-size) + 0.5rem);
  width: min(88%, 400px);
  background: #fff;
  border: 2px solid #ffd6e8;
  border-radius: 18px;
  padding: 11px 15px;
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 8px 18px rgba(255, 94, 156, 0.25);
  animation: pop 0.25s ease;
}
.speech-bubble::after {
  content: "";
  position: absolute;
  bottom: -9px;
  left: 50%;
  transform: translateX(-50%);
  border: 10px solid transparent;
  border-top-color: #fff;
}
.speech-bubble::before {
  content: "";
  position: absolute;
  bottom: -13px;
  left: 50%;
  transform: translateX(-50%);
  border: 10px solid transparent;
  border-top-color: #ffd6e8;
}
@keyframes pop {
  from {
    transform: translateX(-50%) scale(0.88);
    opacity: 0;
  }
}
.behavior-line {
  position: absolute;
  z-index: 12;
  bottom: calc(var(--avatar-bottom) - 8px);
  left: 50%;
  transform: translateX(-50%);
  width: min(90%, 420px);
  text-align: center;
  font-style: italic;
  color: #fff;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
  font-size: 0.92rem;
  min-height: 1.2em;
}
.status-line {
  position: absolute;
  z-index: 12;
  bottom: calc(var(--avatar-bottom) - 28px);
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  text-align: center;
  font-size: 0.85rem;
  color: #fff;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
  font-weight: 800;
  min-height: 1.2em;
}
.status-line .dots::after {
  content: "…";
  animation: dots 1.2s infinite;
}
@keyframes dots {
  0% {
    content: "";
  }
  33% {
    content: ".";
  }
  66% {
    content: "..";
  }
  100% {
    content: "…";
  }
}

/* ============ suggestion ============ */
.suggestion {
  position: absolute;
  z-index: 25;
  left: 12px;
  right: 12px;
  bottom: 96px;
  background: var(--glass);
  backdrop-filter: blur(12px);
  border: 2px solid #cdbcff;
  border-radius: 16px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow);
  animation: rise 0.3s ease;
  font-size: 0.92rem;
  font-weight: 700;
}
@keyframes rise {
  from {
    transform: translateY(14px);
    opacity: 0;
  }
}
.suggestion span {
  flex: 1;
}
.mini-btn {
  background: linear-gradient(90deg, var(--accent2), #9d8cff);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.12);
}
.mini-btn.ghost {
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
  box-shadow: none;
}

/* ============ HUD: drawers ============ */
.hud-drawers {
  display: flex;
  gap: 6px;
  animation: slideDown 0.7s ease;
}
.hud-btn {
  width: 56px;
  padding: 8px 0 7px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 16px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  cursor: pointer;
  font-family: inherit;
  color: var(--ink);
  font-size: 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}
.hud-btn span {
  font-size: 0.62rem;
  font-weight: 800;
}
.hud-btn:active {
  transform: scale(0.93);
}

/* ============ action bar ============ */
.action-bar {
  position: absolute;
  z-index: 25;
  bottom: calc(12px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--glass);
  backdrop-filter: blur(14px);
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 999px;
  padding: 8px 10px;
  box-shadow: var(--shadow);
  animation: rise 0.5s ease;
}
.act-btn {
  position: relative;
  width: 52px;
  height: 52px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(180deg, #ffffff, #f1eaff);
  cursor: pointer;
  box-shadow:
    0 4px 0 #d5c8f2,
    0 6px 12px rgba(90, 60, 160, 0.25);
  transition: all 0.08s;
  font-family: inherit;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
}
.act-btn span {
  font-size: 0.55rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}
.act-btn:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow:
    0 0 0 #d5c8f2,
    0 2px 6px rgba(90, 60, 160, 0.25);
}
.act-btn:disabled {
  opacity: 0.45;
}
.act-btn.talk-btn {
  width: 58px;
  height: 58px;
  margin-left: 2px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  font-size: 1.5rem;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  box-shadow:
    0 4px 0 #5a43b8,
    0 8px 16px rgba(124, 92, 255, 0.45);
}

/* ============ modals (bottom sheets) ============ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(28, 21, 51, 0.55);
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  backdrop-filter: blur(4px);
}
.modal-card {
  background: #fff;
  border-radius: 26px 26px 0 0;
  width: 100%;
  max-width: 540px;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  animation: sheet 0.28s ease;
  padding-bottom: env(safe-area-inset-bottom);
}
@keyframes sheet {
  from {
    transform: translateY(60px);
    opacity: 0;
  }
}
.modal-card.small {
  max-width: 420px;
  align-self: center;
  border-radius: 26px;
  max-height: 74vh;
  margin-bottom: 20px;
}
.modal-card header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 18px 12px;
  border-bottom: 2px solid #f4ecfa;
  font-weight: 800;
}
.close-btn {
  background: #f4ecfa;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  color: var(--muted);
  border-radius: 999px;
  width: 32px;
  height: 32px;
  font-family: inherit;
}
.sheet-body {
  overflow-y: auto;
  padding: 6px 18px 18px;
}
.card-section {
  margin-top: 16px;
}
.card-section h2 {
  font-size: 0.98rem;
  font-weight: 800;
  margin-bottom: 9px;
}
.brain-shell {
  max-height: 72vh;
}
.brain-shell header {
  color: #e9e3ff;
  background: #241d3a;
  border-bottom-color: #3a2f5e;
}
.brain-log {
  flex: 1;
  overflow-y: auto;
  background: #241d3a;
  color: #d7d0f0;
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: 0.78rem;
  line-height: 1.7;
  padding: 12px 16px;
}
.brain-log .line {
  padding: 2px 6px;
  border-radius: 6px;
  animation: pop 0.2s ease;
}
.brain-log .in {
  background: rgba(255, 94, 156, 0.14);
  color: #ff9ec4;
}
.brain-log .think {
  color: #7e75a8;
}
.brain-log .done {
  background: rgba(124, 255, 190, 0.08);
  color: #8fe8c0;
}
.brain-log .notice {
  background: rgba(255, 212, 94, 0.12);
  color: #ffd45e;
}

/* ============ chat ============ */
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 220px;
}
.msg {
  max-width: 80%;
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 0.95rem;
  font-weight: 600;
  animation: pop 0.2s ease;
}
.msg.me {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--accent2), #9d8cff);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.pet {
  align-self: flex-start;
  background: #f4f0fc;
  border-bottom-left-radius: 4px;
}
.msg .by {
  font-size: 0.68rem;
  opacity: 0.7;
  display: block;
  margin-bottom: 2px;
  font-weight: 800;
}
.msg.pet .thinking {
  color: var(--muted);
  font-style: italic;
}
#chat-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 2px solid #f4ecfa;
}
#chat-input {
  flex: 1;
  padding: 12px 14px;
  border-radius: 14px;
  border: 2px solid #e6dcf7;
  outline: none;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 600;
  color: var(--ink);
}
.send-btn {
  background: linear-gradient(135deg, var(--accent2), #9d8cff);
  color: #fff;
  border: none;
  border-radius: 14px;
  padding: 0 18px;
  font-size: 1.15rem;
  cursor: pointer;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.12);
}

/* ============ feed ============ */
.food-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 16px;
}
.food-btn {
  background: #fbf8ff;
  border: 3px solid transparent;
  border-radius: 16px;
  padding: 12px 6px;
  font-size: 1.7rem;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.12s;
}
.food-btn span {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
}
.food-btn:hover,
.food-btn:active {
  border-color: var(--accent);
  transform: scale(1.06);
  box-shadow: 0 4px 14px rgba(255, 94, 156, 0.25);
}

/* ============ journal chips ============ */
.traits {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.trait {
  background: linear-gradient(90deg, #fff0f7, #ffe4f0);
  border: 2px solid #ffc4dd;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.9rem;
  font-weight: 700;
  animation: pop 0.3s ease;
  box-shadow: 0 2px 8px rgba(255, 94, 156, 0.15);
}
.trait b {
  color: var(--accent);
}
.trait-progress {
  background: #f2f7ff;
  border: 2px dashed #b8cffb;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent2);
}
.personality {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.p-chip {
  background: #f6f2fb;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.8rem;
  font-weight: 600;
}
.p-chip b {
  color: var(--accent2);
}
.p-chip .delta {
  color: #3aa75d;
  font-weight: 800;
}
.p-chip .delta.down {
  color: #ff5e7a;
}
.preferences {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 1.2em;
}
.pref {
  background: #effaf1;
  border: 2px solid #a8e0b5;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.85rem;
  font-weight: 700;
}
.pref.dislike {
  background: #fff3ec;
  border-color: #ffc9a8;
}
.pref .n {
  color: var(--muted);
  font-size: 0.75em;
}
.pref .prov {
  color: var(--muted);
  font-size: 0.7em;
  font-style: italic;
}
.craving {
  background: #fff8e1;
  border-color: #ffd45e;
  color: #8a6d00;
}
.memories {
  margin-top: 12px;
  font-size: 0.8rem;
  line-height: 1.6;
}
.memories .mem {
  color: var(--muted);
}

/* ============ mobile ============ */
@media (max-width: 480px) {
  .scene {
    --avatar-bottom: 23%;
  }
  .hud-stats {
    width: 172px;
    padding: 8px 9px;
  }
  .act-btn {
    width: 46px;
    height: 46px;
    font-size: 1.2rem;
  }
  .act-btn.talk-btn {
    width: 52px;
    height: 52px;
    font-size: 1.35rem;
  }
  .action-bar {
    gap: 6px;
    padding: 7px 9px;
  }
}
@media (max-width: 360px) {
  .new-pet-label {
    display: none;
  }
}
