.pet-launch,
.pet-dialog {
  --pet-ink: #492350;
  --pet-edge: #75385e;
  --pet-paper: #fff9ee;
  color: var(--pet-ink);
  font-family: Baloo, "Trebuchet MS", sans-serif;
}

.pet-launch {
  position: fixed;
  z-index: 41;
  inset: auto max(14px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) auto;
  width: clamp(92px, 13vw, 142px);
  padding: 0;
  border: 0;
  border-radius: 26px;
  background: transparent;
  cursor: pointer;
  filter: drop-shadow(0 4px 3px #49235035);
  -webkit-tap-highlight-color: transparent;
}

.pet-launch canvas {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
}

.pet-launch span {
  display: block;
  position: relative;
  margin: -9px auto 0;
  width: max-content;
  max-width: 100%;
  padding: 2px 9px;
  border: 2px solid var(--pet-edge);
  border-radius: 18px;
  background: #fff0c9;
  font-size: clamp(12px, 1.5vw, 16px);
  font-weight: 800;
  line-height: 1.2;
}

.pet-dialog {
  box-sizing: border-box;
  position: fixed;
  inset: 0;
  width: min(820px, calc(100% - 24px), max(365px, calc((100dvh - 194px) * 1.385)));
  max-width: none;
  max-height: calc(100dvh - 20px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  margin: auto;
  padding: 0;
  overflow: auto;
  overscroll-behavior: contain;
  border: 3px solid var(--pet-edge);
  border-radius: 26px;
  background: var(--pet-paper);
  box-shadow: 0 7px 0 #702c60, 0 16px 64px #30153562;
}

.pet-dialog::backdrop {
  background: #3a164a82;
}

.pet-dialog[open][data-enter] {
  animation: pet-unfold .53s cubic-bezier(.2, .7, .25, 1) both;
}

@keyframes pet-unfold {
  0% { transform: translate(var(--pet-from-x), var(--pet-from-y)) scale(var(--pet-from-size)); opacity: .4; }
  70% { transform: translate(0, 0) scale(1.025); opacity: 1; }
  87% { transform: translate(0, 0) scale(.994); }
  100% { transform: none; }
}

body:has(.pet-dialog[open]) { overflow: hidden; }

.pet-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 7px 11px 8px 16px;
  border-bottom: 3px solid var(--pet-edge);
  background: linear-gradient(110deg, #ffd0e2, #f8accf);
}

.pet-heading h2 {
  margin: 0;
  font-family: inherit;
  font-size: clamp(22px, 4.5vw, 34px);
  line-height: 1;
  font-weight: 800;
}

#pet-mood {
  margin: 3px 0 0;
  color: #713456;
  font-size: clamp(13px, 2vw, 16px);
  font-weight: 650;
  line-height: 1.15;
}

.pet-actions, .pet-stickers { display: flex; flex: none; gap: 5px; }

.pet-actions button, .pet-stickers button, .pet-rooms button, .pet-photos button {
  display: grid;
  place-items: center;
  padding: 0;
  color: inherit;
  font: inherit;
  border: 2px solid var(--pet-edge);
  border-radius: 15px;
  background: #fff8ec;
  box-shadow: 0 2px 0 #75385e85;
  cursor: pointer;
}

.pet-actions button, .pet-stickers button {
  width: 44px;
  height: 44px;
  font-size: 22px;
  line-height: 1;
}

.pet-actions button svg { width: 21px; height: 21px; fill: currentColor; }
.pet-actions button { border-radius: 50%; }
.pet-actions [data-pet-action="close"] { background: #ffdcf0; }
.pet-actions button[aria-pressed="true"], .pet-stickers button[aria-pressed="true"] { background: #ffe397; }
.pet-actions button:hover, .pet-stickers button:hover, .pet-photos button:hover { background: #fff0bd; }
.pet-actions button:active, .pet-stickers button:active, .pet-rooms button:active { transform: translateY(2px); box-shadow: none; }

.pet-scene { position: relative; container-type: inline-size; background: #ffe6df; }
.pet-needs {
  position: absolute;
  z-index: 1;
  inset: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: center;
  gap: 9px;
  padding: 10px 12px 17px;
  background: linear-gradient(#fff8f1e8, #fff8f1bd 62%, transparent);
  pointer-events: none;
}

.pet-need {
  --pet-fill: #ffa78d;
  --pet-badge: 39px;
  position: relative;
  isolation: isolate;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 27px;
  margin-block: calc((var(--pet-badge) - 27px) / 2);
  padding: 0 8px 0 calc(var(--pet-badge) + 3px);
  border: 2px solid var(--pet-edge);
  border-radius: 30px;
  background: #fff9ed;
  box-shadow: 0 2px 0 #86517655;
  font-size: clamp(13px, 2.1cqi, 17px);
  line-height: 1;
}
.pet-need[data-need="dirt"] { --pet-fill: #7de2cf; }
.pet-need[data-need="tired"] { --pet-fill: #ffd369; }
.pet-need[data-need="happiness"] { --pet-fill: #ffa2ca; }
.pet-need > span {
  position: absolute;
  left: -2px;
  display: grid;
  place-items: center;
  width: var(--pet-badge);
  height: var(--pet-badge);
  border: 2px solid var(--pet-edge);
  border-radius: 50%;
  background: radial-gradient(circle at 40% 33%, white, #fff5e0);
  box-shadow: 0 2px 0 #86517644;
  font-size: calc(var(--pet-badge) * .59);
}
.pet-need meter {
  position: absolute;
  z-index: -1;
  inset: 3px 3px 3px calc(var(--pet-badge) - 3px);
  width: calc(100% - var(--pet-badge));
  height: calc(100% - 6px);
  border: 0;
  border-radius: 20px;
  background: #fff5e6;
  overflow: hidden;
  appearance: none;
}
.pet-need meter::-webkit-meter-inner-element { display: block; }
.pet-need meter::-webkit-meter-bar { position: static; height: 100%; border: 0; border-radius: 20px; background: #fff5e6; }
.pet-need meter::-webkit-meter-optimum-value { border-radius: 20px; background: linear-gradient(#fff7, transparent 55%), var(--pet-fill); }
.pet-need meter::-moz-meter-bar { border-radius: inherit; background: linear-gradient(#fff7, transparent 55%), var(--pet-fill); }
.pet-need b { font-weight: 800; }
.pet-need small { font-size: .73em; font-weight: 700; font-variant-numeric: tabular-nums; }

@container (max-width: 620px) {
  .pet-needs { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px 9px; padding: 7px 9px 11px; }
  .pet-need { --pet-badge: 29px; height: 23px; margin-block: 3px; font-size: 14px; }
}

.pet-scene canvas, .pet-decorate canvas { display: block; width: 100%; height: auto; touch-action: none; }
.pet-scene canvas { cursor: grab; }
.pet-scene canvas:active { cursor: grabbing; }
.pet-flash { position: absolute; inset: 0; pointer-events: none; background: white; opacity: 0; }
.pet-scene[data-photo] .pet-flash { animation: pet-shutter .38s ease-out; }
@keyframes pet-shutter { from { opacity: .78; } to { opacity: 0; } }

.pet-hint {
  display: grid;
  place-items: center;
  margin: 0;
  min-height: 35px;
  padding: 4px 10px;
  border-top: 2px solid #75385e52;
  text-align: center;
  font-size: clamp(15px, 2.4vw, 18px);
  font-weight: 700;
  line-height: 1.15;
}

.pet-care {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 10px;
  border-top: 2px solid #75385e52;
}
.pet-care .pet-hint { flex: 1; border: 0; padding-inline: 0; }
.pet-auto {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 44px;
  font-size: clamp(13px, 2vw, 16px);
  font-weight: 750;
  line-height: 1.1;
  cursor: pointer;
}
.pet-auto input {
  appearance: none;
  flex: none;
  width: 34px;
  height: 21px;
  margin: 0;
  border: 2px solid var(--pet-edge);
  border-radius: 14px;
  background: #efe0e7;
  cursor: inherit;
}
.pet-auto input::before {
  content: '';
  display: block;
  width: 13px;
  height: 13px;
  margin: 2px;
  border-radius: 50%;
  background: var(--pet-edge);
}
.pet-auto input:checked { background: #9fe1ca; }
.pet-auto input:checked::before { transform: translateX(13px); }

.pet-rooms {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  padding: 0 9px 10px;
}

.pet-rooms button {
  gap: 1px;
  padding: 4px 2px 3px;
  min-height: 59px;
  background: var(--pet-room, #ffe0ea);
  font-size: clamp(14px, 3vw, 18px);
  font-weight: 800;
  line-height: 1;
}

.pet-rooms button span { font-size: clamp(20px, 4vw, 27px); }
.pet-rooms [data-pet-room="bath"] { --pet-room: #c5f3eb; }
.pet-rooms [data-pet-room="bed"] { --pet-room: #e4d9ff; }
.pet-rooms [data-pet-room="play"] { --pet-room: #ffe694; }
.pet-rooms button[aria-pressed="true"] { box-shadow: inset 0 0 0 3px #fffaf3, 0 3px var(--pet-edge); }

.pet-album { padding: 12px; text-align: center; background: #fff8e8; }
.pet-album > p { margin: 22px 0; font-size: 18px; }
.pet-photos { display: flex; gap: 6px; overflow-x: auto; padding: 3px 3px 5px; }
.pet-photos:has(button) { margin-bottom: 10px; }
.pet-photos button { flex: 0 0 clamp(60px, 15vw, 110px); min-height: 44px; overflow: hidden; border-radius: 10px; }
.pet-photos button[aria-pressed="true"] { background: #f6a5cd; border-color: #a92264; box-shadow: 0 2px #a92264; }
.pet-photos img { display: block; width: 100%; pointer-events: none; }
.pet-decorate { max-width: 460px; margin-inline: auto; }
.pet-decorate canvas { border: 5px solid #fff; border-radius: 14px; box-shadow: 0 0 0 2px var(--pet-edge); }
.pet-decorate .pet-hint { border: 0; }
.pet-stickers { justify-content: center; }
.pet-stickers button { touch-action: none; cursor: grab; }

.pet-launch:focus-visible, .pet-dialog button:focus-visible, .pet-dialog canvas:focus-visible, .pet-auto input:focus-visible {
  outline: 3px solid #522268;
  outline-offset: 2px;
}
.pet-scene canvas:focus-visible { outline-offset: -4px; }

.pet-dialog [hidden], .pet-launch[hidden] { display: none; }
.pet-sr-only { position: absolute; inset: 0 auto auto 0; width: 1px; height: 1px; margin: 0; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (max-width: 520px) {
  .pet-dialog { width: calc(100% - 14px); border-radius: 21px; }
  .pet-heading { padding: 5px 6px 6px 9px; }
  .pet-heading h2 { font-size: clamp(18px, 5vw, 24px); }
  .pet-actions { gap: 3px; }
  .pet-rooms { gap: 4px; padding-inline: 5px; }
  .pet-launch { right: max(7px, env(safe-area-inset-right)); }
}
@media (max-width: 400px) {
  .pet-heading { flex-wrap: wrap; gap: 4px; }
  .pet-actions { margin-inline-start: auto; }
}
@media (max-width: 360px) {
  .pet-rooms button { font-size: 13px; }
}

@media (min-width: 540px) and (max-height: 500px) {
  .pet-dialog { width: min(820px, calc(100% - 20px), calc((100dvh - 118px) * 1.385 + 102px)); }
  .pet-heading { padding: 5px 6px; }
  .pet-heading h2 { font-size: 20px; }
  .pet-actions { gap: 3px; }
  #pet-game { display: grid; grid-template-columns: minmax(0, 1fr) 96px; grid-template-rows: auto auto; }
  .pet-care { grid-area: 2 / 1; }
  .pet-hint { font-size: 15px; }
  .pet-rooms { grid-area: 1 / 2 / span 2; grid-template-columns: 1fr; gap: 4px; padding: 5px; }
  .pet-rooms button { min-height: 44px; font-size: 15px; }
  .pet-rooms button span { font-size: 18px; }
}

:root[data-motion="reduced"] .pet-dialog[open][data-enter],
:root[data-motion="reduced"] .pet-scene[data-photo] .pet-flash { animation: none; }
