:root {
  --grotto-ink: #4b3027;
  --grotto-cream: #fff9e9;
  --grotto-gold: #f6ca66;
  --grotto-coral: #cf694b;
  --grotto-green: #4d876c;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #332428;
}

.grotto-shell,
.grotto-world,
.grotto-scene {
  width: 100%;
  height: 100svh;
  overflow: hidden;
}

.grotto-world {
  position: relative;
  isolation: isolate;
  background: radial-gradient(circle at 50% 52%, #d58b56, #5b332d 72%, #2c2226);
}

.grotto-scene {
  position: absolute;
  inset: 0;
  isolation: isolate;
}

.grotto-art {
  position: absolute;
  z-index: 0;
  inset: 0;
  background: var(--pw-cinder-grotto-bg, url('/cinder/backgrounds/warmstone-pet-grotto-background.webp')) center / cover no-repeat;
  transform: scale(1.003);
}

.grotto-wallet {
  position: absolute;
  z-index: 65;
  top: calc(env(safe-area-inset-top) + 12px);
  right: 14px;
  display: flex;
  min-height: 54px;
  overflow: hidden;
  border: 3px solid rgba(255, 255, 255, .9);
  border-radius: 999px;
  background: rgba(255, 249, 232, .96);
  box-shadow: 0 5px 0 rgba(55, 42, 35, .26), 0 10px 24px rgba(40, 25, 21, .2);
}

.grotto-wallet span {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 7px;
  min-width: 104px;
  padding: 6px 13px;
}

.grotto-wallet span + span {
  border-left: 2px solid #dec99f;
}

.grotto-wallet small {
  color: #806b57;
  font-size: 10px;
  font-weight: 1000;
  letter-spacing: .08em;
}

.grotto-wallet strong {
  color: #53382d;
  font-size: 19px;
  font-weight: 1000;
}

.grotto-prompt {
  top: calc(env(safe-area-inset-top) + 12px);
  width: min(480px, 43%);
  min-height: 62px;
  padding: 11px 19px;
  border-width: 3px;
  border-radius: 22px;
  font-size: clamp(17px, 1.6vw, 24px);
}

.grotto-floor {
  position: absolute;
  z-index: 12;
  left: 11%;
  right: 11%;
  top: 34%;
  bottom: 15%;
  touch-action: none;
}

.grotto-pet-stage {
  position: absolute;
  inset: 0;
}

.grotto-empty-callout {
  position: absolute;
  z-index: 10;
  left: 50%;
  top: 45%;
  display: grid;
  grid-template-columns: auto auto;
  place-items: center;
  gap: 10px;
  min-width: 190px;
  min-height: 58px;
  padding: 8px 19px;
  border: 4px solid #ffe8a0;
  border-radius: 999px;
  background: rgba(66, 42, 34, .92);
  box-shadow: 0 7px 0 rgba(46, 30, 25, .34), 0 12px 28px rgba(39, 24, 21, .25);
  color: #fffdf1;
  cursor: pointer;
  transform: translate(-50%, -50%);
}

.grotto-empty-callout span {
  font-size: 27px;
}

.grotto-empty-callout:focus-visible,
.grotto-actions button:focus-visible,
.grotto-dialog button:focus-visible,
.grotto-dialog input:focus-visible,
.grotto-pet:focus-visible {
  outline: 5px solid #fff0a6;
  outline-offset: 3px;
}

.grotto-pet {
  position: absolute;
  display: block;
  width: clamp(112px, 14vw, 180px);
  height: auto;
  aspect-ratio: 3 / 4;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 42%;
  background: transparent;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transform-origin: 50% 94%;
}

.grotto-pet::before {
  content: "";
  position: absolute;
  z-index: -1;
  left: 17%;
  right: 17%;
  bottom: 5%;
  height: 9%;
  border-radius: 50%;
  background: rgba(64, 37, 27, .34);
  filter: blur(4px);
}

.grotto-pet-visual {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform-origin: 50% 94%;
  animation: grottoPetIdle 3.6s ease-in-out infinite;
  pointer-events: none;
}

.grotto-pet .grotto-pet-sprite {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background-size: calc(var(--cinder-frames, 4) * 100%) 100%;
  background-position: var(--cinder-position, 0%) center;
  background-repeat: no-repeat;
  filter: drop-shadow(0 9px 6px rgba(49, 27, 22, .36));
  pointer-events: none;
}

.grotto-pet-name {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: -3px;
  max-width: 92%;
  overflow: hidden;
  padding: 5px 10px;
  border: 2px solid rgba(255, 243, 195, .95);
  border-radius: 999px;
  background: rgba(64, 42, 35, .91);
  color: #fffbea;
  font-size: clamp(11px, 1.15vw, 15px);
  font-weight: 1000;
  text-overflow: ellipsis;
  white-space: nowrap;
  transform: translateX(-50%);
  pointer-events: none;
}

.grotto-pet[aria-pressed="true"] .grotto-pet-name {
  background: #f9d67e;
  color: #53372d;
  box-shadow: 0 0 0 3px rgba(79, 54, 43, .72), 0 0 20px #ffd66b;
}

.grotto-pet-reaction {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 4%;
  color: #ff7386;
  font-size: clamp(31px, 4vw, 54px);
  font-weight: 1000;
  opacity: 0;
  filter: drop-shadow(0 3px #fff4d8);
  transform: translateX(-50%);
  pointer-events: none;
}

.grotto-pet.is-character-dragging {
  cursor: grabbing;
  filter: drop-shadow(0 0 18px rgba(255, 224, 115, .95));
}

.grotto-pet.is-character-dragging .grotto-pet-visual {
  animation: none;
}

.grotto-pet.is-playing {
  z-index: 45 !important;
}

.grotto-pet.is-playing .grotto-pet-visual {
  animation: grottoBigPlay .92s cubic-bezier(.17, .84, .24, 1.16);
}

.grotto-pet.is-patted .grotto-pet-visual {
  animation: grottoPat .86s ease-out;
}

.grotto-pet.is-patted .grotto-pet-reaction {
  animation: grottoHeart .86s ease-out;
}

.grotto-pet.is-sleeping .grotto-pet-visual {
  animation: grottoNap 2.35s ease-in-out;
}

.grotto-pet.is-eating .grotto-pet-visual {
  animation: grottoEat 1.85s ease-in-out;
}

.grotto-actions {
  position: absolute;
  z-index: 68;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 12px);
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 7px;
  min-height: 66px;
  padding: 7px;
  border: 3px solid rgba(255, 235, 173, .94);
  border-radius: 25px;
  background: rgba(57, 39, 35, .92);
  box-shadow: 0 7px 0 rgba(35, 24, 22, .35), 0 15px 35px rgba(37, 24, 21, .28);
  transform: translateX(-50%);
}

.grotto-actions button {
  display: grid;
  grid-template-columns: auto;
  place-items: center;
  align-content: center;
  gap: 1px;
  min-width: 66px;
  min-height: 52px;
  padding: 4px 9px;
  border: 0;
  border-radius: 17px;
  background: #fff6db;
  box-shadow: 0 4px 0 #bb8b50;
  color: #56392d;
  cursor: pointer;
  touch-action: manipulation;
}

.grotto-actions button span {
  font-size: 22px;
  line-height: 1;
}

.grotto-actions button strong {
  font-size: 11px;
  line-height: 1.1;
}

.grotto-actions button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #bb8b50;
}

#grotto-meal[data-due="true"] {
  background: #ffda75;
  box-shadow: 0 4px 0 #b97736, 0 0 20px rgba(255, 202, 78, .9);
  animation: grottoMealReady 1.8s ease-in-out infinite;
}

.grotto-dialog {
  width: min(820px, 94vw);
  max-height: calc(100dvh - 24px);
  overflow: auto;
  padding: clamp(20px, 3vw, 31px);
  border: 5px solid #bb8150;
  border-radius: 31px;
  background: linear-gradient(150deg, rgba(255, 251, 234, .99), rgba(243, 222, 183, .99));
  box-shadow: 0 27px 85px rgba(36, 23, 22, .58), inset 0 2px rgba(255, 255, 255, .85);
  color: var(--grotto-ink);
  text-align: center;
}

.grotto-dialog::backdrop {
  background: rgba(37, 24, 24, .68);
  backdrop-filter: blur(5px);
}

.grotto-dialog[open] {
  animation: grottoDialogArrive .3s cubic-bezier(.2, .84, .27, 1.12);
}

.grotto-dialog h2 {
  margin: 2px 48px 6px;
  font-size: clamp(27px, 4vw, 41px);
  line-height: 1.06;
}

.grotto-dialog > p:not(.grotto-eyebrow):not(.grotto-choice-status):not(.grotto-friend-status) {
  max-width: 620px;
  margin: 0 auto 11px;
  color: #725b49;
  font-weight: 700;
  line-height: 1.38;
}

.grotto-eyebrow {
  margin: 0 48px 5px;
  color: #a35c3f;
  font-size: 11px;
  font-weight: 1000;
  letter-spacing: .13em;
}

.grotto-dialog-close {
  position: absolute;
  z-index: 10;
  top: 13px;
  right: 13px;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #ead8ba;
  color: #5b4032;
  font-size: 31px;
  font-weight: 1000;
  line-height: 1;
  cursor: pointer;
}

.grotto-dialog-balances {
  display: flex;
  justify-content: center;
  gap: 9px;
  margin: 9px 0 15px;
}

.grotto-dialog-balances span {
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border: 2px solid #d5bc8f;
  border-radius: 999px;
  background: #fffaf0;
  color: #7a6551;
  font-size: 10px;
  font-weight: 1000;
  letter-spacing: .07em;
}

.grotto-dialog-balances strong {
  color: #52382c;
  font-size: 15px;
  letter-spacing: 0;
}

.grotto-book {
  width: min(930px, 95vw);
}

.grotto-book-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(245px, .72fr);
  gap: 15px;
  align-items: stretch;
}

.grotto-catalog {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.grotto-pet-card {
  position: relative;
  display: grid;
  grid-template-rows: 101px auto;
  gap: 4px;
  min-height: 168px;
  padding: 8px 6px 9px;
  border: 4px solid #d8bd8f;
  border-radius: 20px;
  background: #fffaf0;
  box-shadow: 0 5px 0 #b99162;
  color: #53392e;
  cursor: pointer;
  touch-action: manipulation;
}

.grotto-pet-card[aria-pressed="true"] {
  border-color: #b05f45;
  background: #fff1cf;
  box-shadow: 0 5px 0 #8d4937, 0 0 0 3px #ffe59a;
}

.grotto-pet-card[data-owned="true"]::after {
  content: "YOURS";
  position: absolute;
  top: 7px;
  right: 7px;
  padding: 4px 6px;
  border-radius: 999px;
  background: #4e8b69;
  color: white;
  font-size: 8px;
  font-weight: 1000;
  letter-spacing: .08em;
}

.grotto-card-sprite {
  justify-self: center;
  width: 76px;
  height: 101px;
  background-size: calc(var(--cinder-frames, 4) * 100%) 100%;
  background-position: var(--cinder-position, 0%) center;
  background-repeat: no-repeat;
  filter: drop-shadow(0 6px 4px rgba(61, 38, 30, .22));
  pointer-events: none;
}

.grotto-pet-card span:last-child {
  display: grid;
  gap: 2px;
}

.grotto-pet-card strong {
  overflow: hidden;
  font-size: 13px;
  line-height: 1.08;
  text-overflow: ellipsis;
}

.grotto-pet-card small {
  color: #836c56;
  font-size: 10px;
  font-weight: 900;
}

.grotto-book-choice {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  min-height: 340px;
  padding: 15px;
  border: 3px solid #d4b77f;
  border-radius: 24px;
  background: rgba(255, 250, 235, .86);
}

.grotto-choice-preview {
  align-self: center;
  width: 109px;
  height: 145px;
  background-size: calc(var(--cinder-frames, 4) * 100%) 100%;
  background-position: var(--cinder-position, 0%) center;
  background-repeat: no-repeat;
  filter: drop-shadow(0 8px 5px rgba(56, 34, 27, .25));
}

.grotto-choice-preview:not([data-species]) {
  visibility: hidden;
}

.grotto-book-choice h3 {
  margin: 4px 0 6px;
  font-size: 22px;
  line-height: 1.1;
}

.grotto-book-choice > p {
  margin: 0 0 10px;
  color: #735d4a;
  font-size: 13px;
  line-height: 1.35;
}

.grotto-primary,
.grotto-dialog-actions button,
.grotto-pay-choices button {
  min-height: 50px;
  border: 0;
  border-radius: 16px;
  font-weight: 1000;
  cursor: pointer;
  touch-action: manipulation;
}

.grotto-primary {
  padding: 10px 15px;
  background: linear-gradient(#df7954, #bf583f);
  box-shadow: 0 5px 0 #8b4133;
  color: white;
}

.grotto-primary:disabled,
.grotto-pay-choices button:disabled {
  opacity: .48;
  box-shadow: none;
  cursor: not-allowed;
}

.grotto-name-area {
  display: grid;
  gap: 7px;
}

.grotto-name-area label {
  color: #735642;
  font-size: 12px;
  font-weight: 1000;
  text-align: left;
}

.grotto-name-area input {
  width: 100%;
  min-height: 50px;
  padding: 9px 12px;
  border: 3px solid #c9a878;
  border-radius: 14px;
  background: white;
  color: #4d342a;
  font: 1000 18px inherit;
}

.grotto-choice-status,
.grotto-friend-status {
  min-height: 20px;
  margin: 9px 0 0 !important;
  color: #9b493c !important;
  font-size: 12px;
  font-weight: 1000;
  line-height: 1.3;
}

.grotto-friends {
  width: min(800px, 94vw);
}

.grotto-friend-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 11px;
  margin: 18px 0 8px;
}

.grotto-friend-card {
  position: relative;
  display: grid;
  grid-template-rows: 112px auto;
  place-items: center;
  min-height: 174px;
  padding: 8px;
  border: 4px solid #d6bd91;
  border-radius: 21px;
  background: #fffaf0;
  color: #54392e;
  cursor: pointer;
  touch-action: manipulation;
}

.grotto-friend-card[aria-pressed="true"] {
  border-color: #4e8c69;
  background: #e9f7e8;
  box-shadow: 0 5px 0 #8ab698;
}

.grotto-friend-card[aria-pressed="true"]::after {
  content: "✓";
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #4e8c69;
  color: white;
  font-size: 20px;
  font-weight: 1000;
}

.grotto-friend-sprite {
  width: 84px;
  height: 112px;
  background-size: calc(var(--cinder-frames, 4) * 100%) 100%;
  background-position: var(--cinder-position, 0%) center;
  background-repeat: no-repeat;
  filter: drop-shadow(0 6px 4px rgba(61, 38, 30, .2));
  pointer-events: none;
}

.grotto-friend-card span:last-child {
  display: grid;
  gap: 2px;
}

.grotto-friend-card strong {
  font-size: 15px;
}

.grotto-friend-card small {
  color: #76614f;
  font-size: 11px;
  font-weight: 900;
}

.grotto-dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1.25fr;
  gap: 10px;
  max-width: 510px;
  margin: 14px auto 0;
}

.grotto-dialog-actions button {
  padding: 9px 14px;
  background: #eadcc3;
  color: #6b5543;
}

.grotto-dialog-actions .grotto-primary {
  background: linear-gradient(#619b78, #427a5e);
  box-shadow: 0 5px 0 #2f5a45;
  color: white;
}

.grotto-feeding {
  width: min(650px, 94vw);
}

.grotto-meal-bowl {
  display: grid;
  place-items: center;
  width: 76px;
  height: 64px;
  margin: 0 auto 5px;
  border: 4px solid #724933;
  border-radius: 48% 48% 43% 43%;
  background: linear-gradient(#f1c877 0 24%, #ba6c4d 25% 100%);
  box-shadow: inset 0 6px rgba(255, 255, 255, .25), 0 5px 0 #593727;
  font-size: 34px;
}

.grotto-pay-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 17px;
}

.grotto-pay-choices button {
  display: grid;
  grid-template-columns: 47px 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  min-height: 101px;
  padding: 11px 13px;
  border: 4px solid #c9aa76;
  background: #fffaf0;
  box-shadow: 0 5px 0 #a47d4e;
  color: #52372c;
  text-align: left;
}

.grotto-pay-choices button > span {
  grid-row: 1 / 3;
  font-size: 34px;
}

.grotto-pay-choices button strong {
  font-size: 15px;
}

.grotto-pay-choices button small {
  color: #765e4a;
  font-size: 12px;
  font-weight: 900;
}

.grotto-support {
  display: grid;
  gap: 5px;
  margin-top: 14px;
  padding: 14px;
  border: 3px solid #77a98c;
  border-radius: 19px;
  background: #e9f7e9;
  color: #3f684f;
}

.grotto-support span {
  font-size: 13px;
  font-weight: 800;
}

.grotto-support .grotto-primary {
  margin-top: 5px;
  background: linear-gradient(#659b77, #447a5b);
  box-shadow: 0 5px 0 #315d46;
}

@keyframes grottoPetIdle {
  0%, 100% { transform: translateY(0) rotate(0); }
  50% { transform: translateY(-5px) rotate(1deg); }
}

@keyframes grottoBigPlay {
  0%, 100% { transform: translateY(0) scale(1) rotate(0); }
  28% { transform: translateY(-34px) scale(1.32, 1.18) rotate(-7deg); }
  58% { transform: translateY(-10px) scale(1.2, 1.28) rotate(7deg); }
  80% { transform: translateY(-20px) scale(1.14) rotate(-3deg); }
}

@keyframes grottoPat {
  0%, 100% { transform: scale(1); }
  35% { transform: translateY(7px) scale(1.08, .87) rotate(-2deg); }
  68% { transform: translateY(-8px) scale(.97, 1.09) rotate(2deg); }
}

@keyframes grottoHeart {
  0% { opacity: 0; transform: translate(-50%, 12px) scale(.45); }
  28% { opacity: 1; transform: translate(-50%, 0) scale(1.18); }
  100% { opacity: 0; transform: translate(-50%, -36px) scale(.9); }
}

@keyframes grottoNap {
  0% { transform: scale(1); }
  15%, 85% { transform: translateY(10px) scale(1.05, .91) rotate(-3deg); }
  100% { transform: scale(1); }
}

@keyframes grottoEat {
  0%, 100% { transform: translateY(0) rotate(0); }
  22%, 48%, 74% { transform: translateY(8px) rotate(2deg) scale(.98, .93); }
  35%, 61% { transform: translateY(-4px) rotate(-2deg) scale(1.02); }
}

@keyframes grottoMealReady {
  50% { filter: brightness(1.08); transform: translateY(-2px); }
}

@keyframes grottoDialogArrive {
  from { opacity: 0; transform: translateY(18px) scale(.97); }
}

@media (orientation: portrait) {
  .grotto-prompt {
    top: calc(env(safe-area-inset-top) + 76px);
    width: min(650px, 82%);
    min-height: 64px;
    font-size: clamp(18px, 2.6vw, 25px);
  }

  .grotto-floor {
    left: 7%;
    right: 7%;
    top: 31%;
    bottom: 13%;
  }

  .grotto-pet {
    width: clamp(108px, 20vw, 160px);
    height: auto;
  }
}

@media (max-width: 820px) {
  .grotto-wallet span {
    min-width: 91px;
    padding: 5px 10px;
  }

  .grotto-wallet small {
    font-size: 9px;
  }

  .grotto-wallet strong {
    font-size: 17px;
  }

  .grotto-book-layout {
    grid-template-columns: 1fr;
  }

  .grotto-book-choice {
    min-height: 0;
  }

  .grotto-choice-preview {
    height: 120px;
  }
}

@media (max-width: 650px) {
  .cinder-back b,
  .grotto-actions button strong {
    display: none;
  }

  .grotto-wallet span {
    grid-template-columns: 1fr;
    gap: 0;
    min-width: 68px;
    text-align: center;
  }

  .grotto-actions {
    gap: 5px;
    padding: 6px;
  }

  .grotto-actions button {
    min-width: 50px;
    min-height: 50px;
    padding: 5px;
  }

  .grotto-catalog,
  .grotto-friend-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grotto-pay-choices {
    grid-template-columns: 1fr;
  }
}

@media (max-height: 650px) and (orientation: landscape) {
  .grotto-prompt {
    top: 8px;
    min-height: 52px;
    font-size: 16px;
  }

  .grotto-wallet,
  .cinder-back {
    top: 8px;
    min-height: 48px;
  }

  .grotto-actions {
    bottom: 7px;
    min-height: 57px;
    padding: 5px;
  }

  .grotto-actions button {
    min-height: 48px;
  }

  .grotto-floor {
    bottom: 13%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .grotto-pet,
  .grotto-pet-visual,
  .grotto-pet-reaction,
  .grotto-dialog[open],
  #grotto-meal[data-due="true"] {
    animation: none !important;
    transition: none !important;
  }

  .grotto-pet.is-patted .grotto-pet-reaction {
    opacity: 1;
  }
}

html[data-motion="reduced"] .grotto-pet,
html[data-motion="reduced"] .grotto-pet-visual,
html[data-motion="reduced"] .grotto-pet-reaction,
html[data-motion="reduced"] .grotto-dialog[open],
html[data-motion="reduced"] #grotto-meal[data-due="true"] {
  animation: none !important;
  transition: none !important;
}

html[data-motion="reduced"] .grotto-pet.is-patted .grotto-pet-reaction {
  opacity: 1;
}
