:root {
  color-scheme: light;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: #522d41;
  background: #f6e4de;
}
* { box-sizing: border-box; }
body {
  min-height: 100svh;
  margin: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at 36% 24%, #fff5e7, transparent 66%),
              linear-gradient(150deg, #f7e7dd, #ecd5de);
}
.stage {
  position: relative;
  isolation: isolate;
  width: min(100vw, calc(100svh * .5625));
  aspect-ratio: 9 / 16;
  overflow: hidden;
  background: #f8dce2 url("assets/cat-tree.webp") center / cover no-repeat;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.stage:focus { outline: none; }
canvas {
  display: block;
  width: 100%;
  height: 100%;
}
.hud {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 13px;
  right: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  gap: 10px;
}
.hud-button, .fish-score, .restart {
  margin: 0;
  padding: 8px 12px;
  border-radius: 17px;
  border: 1.5px solid #966170;
  background: #fffaecf2;
  box-shadow: 0 2px 0 #7040511a;
  color: inherit;
  line-height: 1.25;
}
.hud-button, .fish-score {
  font-size: 14px;
  font-weight: 800;
}
.hud-button { min-height: 44px; pointer-events: auto; }
.fish-score {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-inline: 9px;
  font-variant-numeric: tabular-nums;
}
.fish-icon {
  position: relative;
  display: inline-block;
  width: 19px;
  height: 13px;
  color: #a65d35;
}
.fish-icon::before, .fish-icon::after {
  position: absolute;
  content: "";
}
.fish-icon::before {
  inset: 1px 5px 1px 0;
  z-index: 1;
  border: 1px solid currentColor;
  border-radius: 60% 48% 48% 60%;
  background: radial-gradient(circle at 23% 44%, currentColor 0 1px, #ffda88 1.4px);
}
.fish-icon::after {
  inset: 2px 0 2px 9px;
  background: currentColor;
  clip-path: polygon(0 50%, 100% 0, 100% 100%);
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}
button { font: inherit; cursor: pointer; }
button[hidden] { display: none; }
.restart {
  pointer-events: auto;
  min-height: 44px;
  font-size: 14px;
  font-weight: 750;
}
.restart span { font-size: 21px; vertical-align: -1px; line-height: .8; }
.message {
  position: absolute;
  z-index: 1;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(17px, env(safe-area-inset-bottom));
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 7px 11px;
  border: 1px solid #93616b45;
  border-radius: 11px;
  background: #fff8edee;
  text-align: center;
  pointer-events: none;
  font-size: 14px;
  line-height: 1.4;
}
.stage[data-control="button"] .message {
  bottom: calc(75px + env(safe-area-inset-bottom));
}
.stage:is([data-state="free"], [data-state="swatting"]) .message {
  top: max(65px, calc(env(safe-area-inset-top) + 52px));
  bottom: auto;
}
.scene-target {
  position: absolute;
  left: clamp(22px, var(--target-x), calc(100% - 22px));
  top: var(--target-y);
  transform: translate(-50%, -50%);
  width: max(44px, var(--target-width));
  height: max(44px, var(--target-height));
  border: 0;
  border-radius: 14px;
  padding: 0;
  background: none;
  color: #853e4c;
  -webkit-tap-highlight-color: transparent;
}
.scene-target::before {
  content: "";
  position: absolute;
  inset: 18% 5%;
  border: 2px solid #a15d48;
  border-radius: inherit;
  background: #fff4b440;
  box-shadow: 0 0 0 2px #fff1afd9 inset, 0 0 9px #fff9c8;
  pointer-events: none;
}
.scene-target span {
  position: absolute;
  left: 50%;
  top: 16%;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  width: 23px;
  height: 23px;
  border-radius: 50%;
  border: 1.5px solid #9e584c;
  background: #fff2b8;
  font-size: 15px;
  line-height: 1;
  box-shadow: 0 2px 0 #7a405230;
  pointer-events: none;
}
.scene-target:is(:hover, :focus-visible) span { background: #ffd67d; }
.scene-target:active::before { background: #ffe69b85; }
.controls {
  position: absolute;
  inset-inline: 13px;
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 2;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}
.controls[hidden] { display: none; }
.movement-pad, .action-pad { display: flex; align-items: flex-end; gap: 8px; }
.movement-pad[hidden] { display: none; }
.action-pad { margin-inline-start: auto; }
.control {
  min-height: 48px;
  padding: 0 10px;
  border-radius: 16px;
  border: 2px solid #764651;
  background: #fff5df;
  box-shadow: 0 4px 0 #764651;
  color: #522d41;
  font-size: 16px;
  font-weight: 850;
  line-height: 1.15;
  white-space: nowrap;
  pointer-events: auto;
  touch-action: none;
  transition: background .12s;
}
.control:active, .move[data-held="true"] {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #764651;
}
.move { width: 51px; height: 51px; }
.move span { font-size: 25px; font-weight: 900; }
.move[data-held="true"] { background: #fbd5c0; }
.move:disabled { opacity: .50; cursor: default; }
.move:disabled:active { transform: none; box-shadow: 0 4px 0 #764651; }
.action { min-width: 84px; height: 51px; background: #ffe6a9; }
.interact {
  width: auto;
  min-height: 51px;
  background: #fff5df;
}
.interact:not([hidden]) { display: flex; align-items: center; gap: 5px; }
.interact span:last-child { font-size: 14px; }
.interact[data-kind="climb"] { background: #c7eadd; }
.interact[data-kind="push"] { background: #ffd6a1; }
.interact[data-kind="swat"] { background: #e8d4f5; }
.paw-icon {
  position: relative;
  display: block;
  width: 26px;
  height: 24px;
  margin-inline: auto;
}
.paw-icon::before, .paw-icon::after {
  content: "";
  position: absolute;
  background: currentColor;
}
.paw-icon::before {
  width: 16px;
  height: 13px;
  left: 5px;
  bottom: 0;
  border-radius: 55% 55% 44% 44%;
}
.paw-icon::after {
  width: 5px;
  height: 7px;
  left: 0;
  top: 6px;
  border-radius: 50%;
  box-shadow: 6px -5px currentColor, 14px -5px currentColor, 21px 0 currentColor;
}
.stage[data-cue="true"] .action { background: #ffda80; }
.stage[data-state="arrived"] .message { font-weight: 850; background: #fff4d4; }
button:focus-visible { outline: 3px solid #783c78; outline-offset: 3px; }

.game-sheet {
  width: min(calc(100% - 34px), 330px);
  max-height: calc(100svh - 24px);
  padding: clamp(16px, 4vh, 26px) 20px 20px;
  border: 2px solid #a76565;
  border-radius: 20px;
  background: #fff6e5;
  color: #522d41;
  box-shadow: 0 14px 34px #5932423a;
  text-align: center;
  overscroll-behavior: contain;
}
.game-sheet::backdrop { background: #44263f82; }
.game-sheet[open] { animation: show-sheet .22s cubic-bezier(.16, 1, .3, 1) both; }
@keyframes show-sheet {
  from { transform: translateY(12px) scale(.98); opacity: .6; }
}
.game-sheet h2 {
  margin: 0;
  font-size: clamp(24px, 6vw, 31px);
  letter-spacing: -.025em;
  line-height: 1.18;
}
.result-cat {
  position: relative;
  display: grid;
  place-items: center;
  margin-bottom: 9px;
}
.result-cat::before {
  position: absolute;
  bottom: 0;
  width: 104px;
  height: 16px;
  border-radius: 50%;
  background: #ebc9d5;
  content: "";
}
.result-cat img {
  z-index: 1;
  display: block;
  width: auto;
  height: clamp(61px, 12vh, 101px);
}
.result-level {
  margin: 8px 0 17px;
  color: #74485b;
  font-size: 14px;
  font-weight: 650;
}
.result-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: 0 0 18px;
  padding: 10px 0 12px;
  border-block: 1px solid #dcb7b1;
}
.result-stats div + div { border-inline-start: 1px solid #dcb7b1; }
.result-stats:has(> div[hidden]) { grid-template-columns: 1fr; }
.result-stats dt { font-size: 14px; }
.result-stats dd {
  margin: 3px 0 0;
  font-size: 21px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.sheet-actions {
  display: grid;
  grid-template-columns: 1fr 1.25fr;
  gap: 10px;
}
.sheet-button, .level-row {
  min-height: 46px;
  border: 1.5px solid #986272;
  border-radius: 12px;
  background: #faecde;
  color: inherit;
}
.sheet-button { padding: 8px 9px; font-size: 15px; font-weight: 800; }
.sheet-button.primary { background: #ffdc93; border-color: #96604c; }
.sheet-button:active, .level-row:active:not(:disabled) { background: #f5cda8; }
.level-list {
  display: grid;
  gap: 9px;
  margin: 17px 0;
}
.level-help { font-size: 14px; line-height: 1.5; margin: 8px 0 0; color: #74485b; }
.level-row {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  text-align: start;
  font-size: 14px;
}
.level-row strong { font-size: 16px; }
.level-row[data-active="true"] { background: #dcece3; border-color: #6a897a; }
.level-row:disabled { background: #f0e7db; color: #724f5d; border-color: #cdada7; cursor: default; }
.level-sheet form .sheet-button { width: 100%; }

@media (min-width: 560px) and (min-height: 520px) {
  .stage {
    width: min(calc((100svh - 32px) * .5625), 500px);
    border-radius: 19px;
    box-shadow: 0 16px 60px #643c4c33, 0 0 0 1px #9d67724d;
  }
}
@media (max-height: 560px) {
  .message { font-size: 12px; padding: 4px 6px; }
  .stage[data-control="button"] .message { bottom: 63px; }
  .stage[data-control="button"]:not([data-state="free"]):has(#interact:not([hidden])) .message { bottom: 108px; }
  .stage:is([data-state="free"], [data-state="swatting"]) .message { top: 49px; bottom: auto; }
  .controls { inset-inline: 8px; bottom: 9px; gap: 7px; }
  .movement-pad, .action-pad { gap: 5px; }
  .action-pad { flex-direction: column; }
  .move, .action, .interact { height: 44px; min-height: 44px; font-size: 14px; }
  .move { width: 44px; }
  .move span { font-size: 22px; }
  .interact { padding-inline: 8px; }
  .action { min-width: 69px; }
  .hud { top: 7px; left: 7px; right: 7px; }
  .hud { gap: 5px; }
  .hud-button, .fish-score, .restart { padding: 4px 6px; font-size: 12px; }
  .hud-button, .restart { min-height: 44px; }
  .fish-score { gap: 3px; }
  .restart span { font-size: 15px; }
}
@media (max-width: 350px) {
  .action-pad { flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) {
  .control { transition: none; }
  .game-sheet[open] { animation: none; }
}
