:root {
  --bg: #e0d8ca;
  --paper: #e8e8e6;
  --ink: #000602;
  --ink-soft: #2a2724;
  --ochre: #c57b32;
  --sage: #a4c1ad;
  --sage-deep: #557c66;
  --navy: #34495c;
  --cream: #fcf9f2;
  --muted: #7b7468;
  --shadow: rgba(70, 48, 32, .2);
  --display: "Fredoka", "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --edge: clamp(12px, 2.6vw, 34px);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#stage {
  touch-action: none;
  outline: none;
  cursor: grab;
  -webkit-tap-highlight-color: transparent;
}
#stage:focus-visible { box-shadow: inset 0 0 0 3px rgba(197, 123, 50, .55); }

.grain, .vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
}
.grain {
  mix-blend-mode: multiply;
  opacity: .6;
  background-size: 256px 256px;
}
.vignette {
  background: radial-gradient(130% 95% at 50% 42%, transparent 58%, rgba(108, 84, 58, .17) 100%);
}

.title {
  position: fixed;
  top: var(--edge);
  left: var(--edge);
  z-index: 3;
  pointer-events: none;
  transform: rotate(-1.8deg);
  filter: drop-shadow(1px 2px 0 rgba(70, 48, 32, .1)) drop-shadow(3px 9px 10px var(--shadow));
  animation: settle .8s cubic-bezier(.2, 1.3, .4, 1) .1s both;
}
.title::before {
  content: "";
  position: absolute;
  z-index: 1;
  top: -11px;
  left: 50%;
  width: 96px;
  height: 24px;
  transform: translateX(-50%) rotate(3deg);
  background: repeating-linear-gradient(45deg, rgba(164, 193, 173, .9) 0 7px, rgba(186, 209, 193, .9) 7px 14px);
  clip-path: polygon(3% 0, 97% 0, 100% 22%, 96% 42%, 100% 62%, 96% 82%, 99% 100%, 2% 100%, 0 80%, 4% 60%, 0 40%, 4% 20%);
}
.title-paper {
  padding: clamp(12px, 1.6vw, 18px) clamp(16px, 2.2vw, 28px) clamp(18px, 2.4vw, 26px);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, .75), transparent 45%),
    linear-gradient(315deg, rgba(164, 193, 173, .14), transparent 45%),
    var(--cream);
  clip-path: polygon(0 1%, 100% 0, 100% 90%, 97% 94%, 93% 91%, 88% 96%, 82% 92%, 76% 97%, 70% 93%, 63% 98%,
    57% 93%, 51% 97%, 45% 92%, 38% 97%, 32% 93%, 25% 98%, 19% 93%, 12% 97%, 6% 92%, 0 96%);
}
.title h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(28px, 4.1vw, 54px);
  line-height: 1;
  white-space: nowrap;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .9);
}
.w-guy { color: var(--navy); }
.w-and {
  color: var(--ochre);
  font-size: .6em;
  font-weight: 500;
  margin: 0 .06em;
  vertical-align: .12em;
}
.w-cat { color: #5d8669; }
.title p {
  margin: .55em 0 0;
  font: 600 11px/1.2 var(--ui);
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--muted);
}

.corner {
  position: fixed;
  top: var(--edge);
  right: var(--edge);
  z-index: 3;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  pointer-events: none;
  animation: settle .8s cubic-bezier(.2, 1.3, .4, 1) .25s both;
}
.stats {
  transform: rotate(1.4deg);
  filter: drop-shadow(1px 2px 0 rgba(70, 48, 32, .1)) drop-shadow(3px 8px 9px var(--shadow));
}
.stats-paper {
  padding: 10px 16px 12px 12px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, .7), transparent 50%),
    var(--cream);
  clip-path: polygon(0 2%, 98% 0, 100% 97%, 2% 100%);
}
.meter {
  display: flex;
  align-items: center;
  gap: 10px;
}
.meter svg {
  width: 32px;
  height: 30px;
  flex: none;
}
#heart-fill { transition: y .25s ease-out; }
.pets {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.pets-num {
  display: inline-block;
  min-width: 1ch;
  font: 600 28px/1 var(--display);
  color: var(--ink-soft);
}
.pets-label,
.tally {
  font: 600 10px/1 var(--ui);
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--muted);
}
.tally {
  list-style: none;
  display: flex;
  gap: 12px;
  margin: 9px 0 0;
  padding: 8px 0 0;
  border-top: 1px dashed rgba(0, 6, 2, .16);
}
.tally b {
  display: block;
  margin-bottom: 4px;
  font: 600 18px/1 var(--display);
  letter-spacing: 0;
  color: var(--ink-soft);
}
#n-meow { color: var(--ochre); }
#n-purr { color: var(--sage-deep); }
#n-roll { color: #b5473a; }
#n-yawn { color: var(--navy); }
.bump { animation: bump .5s cubic-bezier(.3, 1.6, .5, 1); }

.sound {
  position: relative;
  pointer-events: auto;
  appearance: none;
  border: 0;
  margin: 0;
  padding: 0;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--ink-soft);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, .85), transparent 55%),
    var(--cream);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .9) inset, 2px 3px 0 rgba(70, 48, 32, .1), 3px 8px 14px -4px var(--shadow);
  transition: transform .2s ease;
}
.sound[hidden] { display: none; }
.sound:hover { transform: translateY(-1px) rotate(-6deg); }
.sound:active { transform: translateY(1px) scale(.96); }
.sound:focus-visible { outline: 3px solid rgba(197, 123, 50, .65); outline-offset: 3px; }
.sound svg { width: 24px; height: 24px; }
.sound .waves, .sound .slash { transition: opacity .2s; }
.sound .slash { opacity: 0; }
.sound[data-state="off"] { color: var(--muted); }
.sound[data-state="off"] .waves { opacity: 0; }
.sound[data-state="off"] .slash { opacity: 1; }
.sound[data-state="waiting"]::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(197, 123, 50, .55);
  animation: ping 1.8s ease-out infinite;
}

.hint {
  position: fixed;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 3;
  margin: 0;
  padding: 2px 12px 4px;
  transform: translateX(-50%);
  pointer-events: none;
  white-space: nowrap;
  font: 500 clamp(15px, 1.5vw, 19px)/1.25 var(--display);
  color: var(--ink-soft);
  background: linear-gradient(transparent 56%, rgba(164, 193, 173, .5) 56%, rgba(164, 193, 173, .5) 90%, transparent 90%);
  transition: opacity .8s ease;
  animation: fade-up .9s ease .7s both;
}
.hint.is-quiet { opacity: .5; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.noscript {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  padding: 16px 22px;
  background: var(--cream);
  font: 500 18px/1.4 var(--display);
  box-shadow: 3px 8px 18px var(--shadow);
}

@keyframes settle {
  from { opacity: 0; translate: 0 -14px; }
  to { opacity: 1; translate: 0 0; }
}
@keyframes fade-up {
  from { opacity: 0; translate: 0 10px; }
}
@keyframes bump {
  40% { transform: scale(1.35) rotate(-5deg); }
}
@keyframes ping {
  0% { opacity: .9; transform: scale(.9); }
  80%, 100% { opacity: 0; transform: scale(1.35); }
}

@media (max-width: 700px) {
  .tally { display: none; }
  .stats-paper { padding: 8px 12px 9px 10px; }
  .pets-num { font-size: 22px; }
  .meter svg { width: 26px; height: 24px; }
  .sound { width: 42px; height: 42px; }
  .title p { font-size: 9px; letter-spacing: .16em; }
}
@media (max-width: 400px) {
  .title h1 { font-size: 24px; }
  .title p { display: none; }
  .title-paper { padding: 10px 14px 16px; }
  .corner { gap: 8px; }
}
@media (max-width: 460px) {
  .hint {
    width: max-content;
    max-width: calc(100vw - 32px);
    white-space: normal;
    text-align: center;
  }
  .pets-label { display: none; }
}
@media (max-height: 480px) and (orientation: landscape) {
  .title h1 { font-size: 26px; }
  .title p, .tally { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
