@font-face {
  font-family: "Fredoka";
  src: url("fonts/Fredoka.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
}

:root {
  --floor: #f3e3cd;
  --floor-2: #ecd8bd;
  --rug: #5fa8a0;
  --rug-edge: #3f837d;
  --rug-dot: #f6e7c8;
  --card: #fffaf1;
  --text: #4a2a18;
  --text-soft: #8a6a55;
  --accent: #ff8a5c;
  --accent-deep: #e0632f;
  --pink: #ff9fb0;
  --pink-deep: #f4788f;
  --ink: #2d1810;

  /* coat: ginger */
  --fur: #f6a94b;
  --stripe: #d9812c;
  --belly: #fff1dc;
  --muzzle: #fff1dc;
  --pawfur: #fff4e2;
  --earfur: #f6a94b;
  --tailfur: #f6a94b;
  --line: #55301a;
}
body[data-coat="grey"] {
  --fur: #aab2c0; --stripe: #7e8797; --belly: #f6f3ee; --muzzle: #f6f3ee;
  --pawfur: #f8f6f2; --earfur: #aab2c0; --tailfur: #aab2c0; --line: #393d49;
}
body[data-coat="tuxedo"] {
  --fur: #4a4654; --stripe: #37333f; --belly: #fdf8ef; --muzzle: #fdf8ef;
  --pawfur: #fdf8ef; --earfur: #4a4654; --tailfur: #4a4654; --line: #1f1c25;
}
body[data-coat="siamese"] {
  --fur: #f3e4cb; --stripe: #e2cba9; --belly: #fffaf0; --muzzle: #8a6652;
  --pawfur: #8a6652; --earfur: #8a6652; --tailfur: #8a6652; --line: #4b372c;
}
body[data-coat="cocoa"] {
  --fur: #b98463; --stripe: #94603f; --belly: #f9e6d2; --muzzle: #f9e6d2;
  --pawfur: #f9e6d2; --earfur: #b98463; --tailfur: #b98463; --line: #45281a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Fredoka", ui-rounded, "SF Pro Rounded", "Nunito", system-ui, sans-serif;
  color: var(--text);
  background:
    repeating-linear-gradient(90deg, transparent 0 118px, rgba(120, 80, 40, .07) 118px 120px),
    linear-gradient(180deg, var(--floor), var(--floor-2));
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
svg { display: block; }
button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.600; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- header ---------- */
#top {
  flex: none;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: calc(8px + env(safe-area-inset-top)) 14px 4px;
  z-index: 5;
}
.round {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--card);
  box-shadow: 0 2px 0 rgba(85, 48, 26, .25), inset 0 0 0 2px rgba(85, 48, 26, .12);
  display: grid; place-items: center;
  transition: transform .12s;
}
.round:active { transform: translateY(2px) scale(.96); }
#level-nav { display: flex; align-items: center; gap: 6px; }
#level-label {
  display: flex; align-items: baseline; gap: 6px;
  background: var(--card);
  padding: 5px 16px;
  border-radius: 999px;
  box-shadow: 0 2px 0 rgba(85, 48, 26, .25), inset 0 0 0 2px rgba(85, 48, 26, .12);
  font-weight: 600;
  min-width: 108px;
  justify-content: center;
}
#level-label .small { font-size: 13px; color: var(--text-soft); font-weight: 500; text-transform: uppercase; letter-spacing: .06em; }
#level-num { font-size: 22px; font-variant-numeric: tabular-nums; }
.nav { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: var(--text-soft); }
.nav:disabled { opacity: .25; cursor: default; }
#timer {
  justify-self: end;
  font-weight: 600; font-size: 18px;
  font-variant-numeric: tabular-nums;
  color: var(--text-soft);
  padding-right: 4px;
}

/* ---------- stage ---------- */
#main {
  flex: 1;
  min-height: 0;
  position: relative;
  container-type: size;
  display: grid;
  place-items: center;
}
#stage {
  position: relative;
  width: min(100cqw, calc(100cqh * 560 / 910), 620px);
  aspect-ratio: 560 / 910;
  container-type: inline-size;
  --u: calc(100cqw / 560);
}
#stage.wiggle { animation: wiggle .5s ease-in-out; }
@keyframes wiggle {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-1.800deg); } 40% { transform: rotate(1.800deg); }
  60% { transform: rotate(-1.200deg); } 80% { transform: rotate(1deg); }
}
.catsvg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.catsvg * { transform-box: view-box; }
#cat-top { pointer-events: none; }
#cat-top #head { pointer-events: auto; }
.ol { stroke: var(--line); stroke-width: 6; stroke-linejoin: round; }
.fur { fill: var(--fur); }
.pawfur { fill: var(--pawfur); }
.earfur { fill: var(--earfur); }
.ear-in { fill: var(--pink); }
.bean { fill: var(--pink); }
.stripe-fill { fill: var(--stripe); }
.stripe-line { fill: none; stroke: var(--stripe); stroke-width: 11; stroke-linecap: round; }
.stroke-ink { fill: none; stroke: var(--line); stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; }
.stroke-ink.thin, .thin .stroke-ink, [data-m] .stroke-ink.thin { stroke-width: 5; }
.tail-ol { fill: none; stroke: var(--line); stroke-width: 48; stroke-linecap: round; }
.tail-fill { fill: none; stroke: var(--tailfur); stroke-width: 36; stroke-linecap: round; }
.tail-stripe { fill: none; stroke: var(--stripe); stroke-width: 9; stroke-linecap: round; }
#whiskers path { fill: none; stroke: var(--line); stroke-width: 3; stroke-linecap: round; opacity: .65; }
.blush { fill: var(--pink-deep); opacity: .28; transition: opacity .3s; }
#stage[data-blush="1"] .blush { opacity: .7; }

/* face states */
#stage [data-e], #stage [data-m] { display: none; }
#stage[data-eyes="open"] [data-e="open"], #stage[data-eyes="happy"] [data-e="happy"],
#stage[data-eyes="closed"] [data-e="closed"], #stage[data-eyes="wide"] [data-e="wide"],
#stage[data-eyes="annoyed"] [data-e="annoyed"], #stage[data-eyes="heart"] [data-e="heart"],
#stage[data-mouth="w"] [data-m="w"], #stage[data-mouth="open"] [data-m="open"],
#stage[data-mouth="o"] [data-m="o"], #stage[data-mouth="frown"] [data-m="frown"] { display: block; }
#stage .eye { transform-box: fill-box; transform-origin: center; transition: transform .07s; }
#stage.blink .eye { transform: scaleY(.08); }
#stage [data-e="heart"] { transform-origin: 280px 150px; animation: throb .5s ease-in-out infinite alternate; }
@keyframes throb { to { transform: scale(1.080); } }
#zzz { display: none; }
#stage[data-zzz="1"] #zzz { display: block; }
#zzz text { animation: zzz 2.400s ease-in-out infinite; opacity: 0; }
#zzz text:nth-child(2) { animation-delay: .5s; }
#zzz text:nth-child(3) { animation-delay: 1s; }
@keyframes zzz { 0% { opacity: 0; transform: translate(-6px, 8px); } 40% { opacity: .9; } 100% { opacity: 0; transform: translate(8px, -12px); } }

/* moving parts */
#torso { transform-origin: 280px 520px; }
#head { transform-origin: 280px 260px; }
#tail { transform-origin: 280px 800px; animation: sway 3.400s ease-in-out infinite alternate; }
#stage[data-tail="fast"] #tail { animation-duration: .7s; }
#stage[data-tail="thump"] #tail { animation: thump .32s ease-in-out infinite alternate; }
@keyframes sway { from { transform: rotate(9deg); } to { transform: rotate(-24deg); } }
@keyframes thump { from { transform: rotate(14deg); } to { transform: rotate(-30deg); } }
.ear { transition: transform .18s cubic-bezier(.3, 1.600, .5, 1); }
#ear-l { transform-origin: 195px 100px; }
#ear-r { transform-origin: 365px 100px; }
#stage[data-ears="flat"] #ear-l { transform: rotate(-30deg) translate(-4px, 14px); }
#stage[data-ears="flat"] #ear-r { transform: rotate(30deg) translate(4px, 14px); }
#stage[data-ears="perk"] #ear-l { transform: rotate(6deg) translateY(-4px); }
#stage[data-ears="perk"] #ear-r { transform: rotate(-6deg) translateY(-4px); }
#ear-l.twitch { animation: twitch-l .34s ease-out; }
#ear-r.twitch { animation: twitch-r .34s ease-out; }
@keyframes twitch-l { 30% { transform: rotate(-14deg); } 60% { transform: rotate(5deg); } }
@keyframes twitch-r { 30% { transform: rotate(14deg); } 60% { transform: rotate(-5deg); } }
#hand-l { transform-origin: 90px 290px; }
#hand-r { transform-origin: 470px 290px; }
#foot-l { transform-origin: 150px 800px; }
#foot-r { transform-origin: 410px 800px; }
.paw.kick { animation: kick .42s ease-in-out; }
.paw.kick:nth-of-type(odd) { animation-delay: .05s; }
#hand-r.kick, #foot-l.kick { animation-name: kick-b; }
@keyframes kick { 25% { transform: rotate(-13deg) translateY(-5px); } 60% { transform: rotate(8deg); } }
@keyframes kick-b { 25% { transform: rotate(13deg) translateY(-5px); } 60% { transform: rotate(-8deg); } }
#stage[data-party="1"] .paw { animation: kick .5s ease-in-out infinite; }
#stage[data-party="1"] #hand-r, #stage[data-party="1"] #foot-l { animation-name: kick-b; animation-delay: .12s; }

/* board */
#board {
  position: absolute;
  left: calc(16 * var(--u)); top: calc(262 * var(--u));
  width: calc(528 * var(--u)); height: calc(528 * var(--u));
  touch-action: none;
  cursor: pointer;
  transform-origin: 50% 48%;
}
#fx { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.heart {
  position: absolute; width: 22px; height: 22px; margin: -11px;
  animation: floatup 1.300s ease-out forwards;
  will-change: transform, opacity;
}
.heart svg { width: 100%; height: 100%; }
@keyframes floatup {
  0% { transform: translate(0, 0) scale(.2) rotate(var(--r0)); opacity: 0; }
  18% { opacity: 1; transform: translate(calc(var(--dx) * .2), -14px) scale(1.150) rotate(var(--r0)); }
  100% { transform: translate(var(--dx), var(--dy)) scale(.8) rotate(var(--r1)); opacity: 0; }
}

/* ---------- speech bubble ---------- */
#bubble {
  position: absolute; z-index: 6;
  top: 4px; left: 50%; translate: -50% 0;
  width: min(calc(100% - 20px), 440px);
  background: var(--card);
  border: 3px solid var(--line);
  border-radius: 22px;
  padding: 12px 14px 12px;
  box-shadow: 0 5px 0 rgba(60, 30, 12, .2);
  animation: pop-in .28s cubic-bezier(.3, 1.500, .5, 1);
}
#bubble::after {
  content: ""; position: absolute; left: 50%; bottom: -13px; margin-left: -11px;
  width: 20px; height: 20px; background: var(--card);
  border-right: 3px solid var(--line); border-bottom: 3px solid var(--line);
  transform: rotate(45deg); border-radius: 0 0 5px 0;
}
#bubble p { margin: 0 0 10px; font-size: 16px; line-height: 1.350; font-weight: 500; text-wrap: pretty; }
#bubble .row { display: flex; gap: 8px; justify-content: flex-end; }
@keyframes pop-in { from { transform: scale(.7) translateY(-10px); opacity: 0; } }
#toast {
  position: absolute; left: 50%; bottom: 10px; translate: -50% 0; z-index: 6;
  background: var(--text); color: #fff6e8; padding: 8px 16px; border-radius: 999px;
  font-weight: 500; font-size: 15px; white-space: nowrap;
  animation: pop-in .25s cubic-bezier(.3, 1.500, .5, 1);
}

/* ---------- buttons ---------- */
.pill {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); color: #fff;
  font-weight: 600; font-size: 17px;
  padding: 10px 20px; border-radius: 999px;
  box-shadow: 0 4px 0 var(--accent-deep);
  transition: transform .1s, box-shadow .1s;
}
.pill:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-deep); }
.pill.ghost { background: var(--card); color: var(--text); box-shadow: 0 3px 0 rgba(85, 48, 26, .25), inset 0 0 0 2px rgba(85, 48, 26, .15); }
.pill.small { padding: 6px 14px; font-size: 15px; }
.pill.wide { width: 100%; padding: 13px 20px; font-size: 19px; }
#bubble .pill { font-size: 15px; padding: 7px 14px; }

#controls {
  flex: none;
  display: flex; align-items: center; justify-content: center; gap: 22px;
  padding: 6px 14px calc(12px + env(safe-area-inset-bottom));
  z-index: 5;
}
.round.big { width: 58px; height: 58px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; }
.round.big span { font-size: 11px; font-weight: 600; color: var(--text-soft); line-height: 1; }
.round.big svg { width: 20px; height: 20px; }
.pill.hint { font-size: 20px; padding: 13px 34px; }
.pill.hint svg { width: 24px; height: 24px; }

/* ---------- win card ---------- */
#win {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; place-items: center;
  padding: 0 14px calc(14px + env(safe-area-inset-bottom));
  pointer-events: none;
}
#win .card {
  pointer-events: auto;
  width: min(100%, 400px);
  text-align: center;
  padding: 14px 20px 18px;
  animation: rise .5s cubic-bezier(.2, 1.400, .4, 1);
}
@keyframes rise { from { transform: translateY(120%); } }
.card {
  position: relative;
  background: var(--card);
  border: 3px solid var(--line);
  border-radius: 28px;
  box-shadow: 0 7px 0 rgba(60, 30, 12, .22);
}
#win h2 { margin: 2px 0 2px; font-size: 30px; font-weight: 700; letter-spacing: .01em; }
#win p { margin: 0 0 12px; color: var(--text-soft); font-weight: 500; }
#stars { display: flex; justify-content: center; gap: 6px; height: 40px; }
#stars svg { width: 40px; height: 40px; animation: star-in .5s cubic-bezier(.3, 1.800, .5, 1) backwards; }
#stars svg:nth-child(2) { animation-delay: .15s; transform: translateY(-6px); }
#stars svg:nth-child(3) { animation-delay: .3s; }
@keyframes star-in { from { scale: 0; rotate: -90deg; } }

/* ---------- sheets ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(60, 32, 14, .42);
  display: grid; place-items: center;
  padding: 18px;
  animation: fade .2s;
}
@keyframes fade { from { opacity: 0; } }
.sheet .card {
  width: min(100%, 400px);
  max-height: 100%;
  overflow: auto;
  padding: 22px 22px 22px;
  animation: pop-in .3s cubic-bezier(.3, 1.400, .5, 1);
}
.sheet h1 { margin: 0 0 14px; font-size: 30px; font-weight: 700; }
.sheet .close { position: absolute; top: 14px; right: 14px; width: 38px; height: 38px; }
.opt { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; font-size: 17px; font-weight: 500; border-top: 2px dashed rgba(85, 48, 26, .14); }
.opt.col { flex-direction: column; align-items: stretch; }
.toggle { flex: none; width: 54px; height: 32px; border-radius: 999px; background: #d9c8b2; position: relative; transition: background .2s; }
.toggle::after { content: ""; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 2px 0 rgba(60, 30, 12, .2); transition: transform .2s cubic-bezier(.3, 1.500, .5, 1); }
.toggle[aria-checked="true"] { background: #6cc48a; }
.toggle[aria-checked="true"]::after { transform: translateX(22px); }
#coats { display: flex; gap: 10px; }
.coat { width: 46px; height: 46px; border-radius: 50%; border: 3px solid var(--c-line); background: linear-gradient(135deg, var(--c-fur) 0 58%, var(--c-belly) 58%); box-shadow: 0 2px 0 rgba(60, 30, 12, .2); transition: transform .15s; }
.coat[aria-pressed="true"] { outline: 3px solid var(--accent); outline-offset: 3px; transform: scale(1.060); }
.jump { display: flex; gap: 8px; align-items: center; }
#jump { width: 84px; font: inherit; font-weight: 600; text-align: center; padding: 6px 8px; border-radius: 12px; border: 2px solid rgba(85, 48, 26, .25); background: #fff; color: var(--text); }
.note { margin: 2px 0 14px; font-size: 14px; color: var(--text-soft); }
.lead { margin: 0 0 10px; font-size: 18px; font-weight: 500; }
.rules { margin: 0 0 18px; padding-left: 0; list-style: none; display: grid; gap: 10px; font-size: 16px; line-height: 1.350; }
.rules li { padding-left: 30px; position: relative; }
.rules li::before { content: ""; position: absolute; left: 0; top: 2px; width: 20px; height: 20px; background: var(--pink-deep); border-radius: 50% 50% 46% 46%; box-shadow: inset 0 0 0 5px var(--card), inset 0 0 0 20px var(--pink-deep); }

[hidden] { display: none !important; }

@media (min-width: 700px) {
  #top { padding-left: 28px; padding-right: 28px; }
  #controls { gap: 30px; padding-bottom: 20px; }
}
@media (max-height: 620px) {
  .round.big { width: 48px; height: 48px; }
  .pill.hint { padding: 9px 26px; font-size: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  #tail, #stage.wiggle, .paw.kick, #stage[data-party="1"] .paw { animation: none; }
}
