:root {
  color-scheme: light;
  --ink: #2d2018;
  --muted: #76553f;
  --paper: #fffdf6;
  --sky: #f8c67b;
  --road: #744b36;
  --button: #e85d36;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #2d2018;
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.shell {
  position: relative;
  width: min(100vw, 177.78dvh);
  height: min(100dvh, 56.25vw);
  min-width: 320px;
  min-height: 180px;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #f7c57c;
}

.topbar {
  position: absolute;
  z-index: 20;
  top: max(10px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  display: grid;
  grid-template-columns: minmax(0, 1fr) repeat(4, minmax(58px, 86px));
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

h1 {
  margin: 0;
  width: min(39vw, 330px);
  height: clamp(34px, 8.5dvh, 62px);
  overflow: visible;
  filter: drop-shadow(0 7px 7px rgba(23, 18, 37, 0.28));
}

h1 img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: left center;
}

.stat {
  appearance: none;
  min-width: 0;
  padding: 6px 8px;
  border: 2px solid rgba(89, 53, 31, 0.3);
  border-radius: 8px;
  background: rgba(255, 253, 246, 0.9);
  text-align: center;
  font-weight: 900;
  box-shadow: 0 4px 0 rgba(82, 45, 24, 0.18);
}

button.stat {
  font: inherit;
  cursor: pointer;
  pointer-events: auto;
}

.rank-trigger:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(82, 45, 24, 0.18);
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: clamp(10px, 1.8dvh, 12px);
  font-weight: 750;
}

.stat strong {
  display: block;
  font-size: clamp(15px, 3dvh, 22px);
  line-height: 1.05;
}

.combo-stat {
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.combo-stat.is-combo-pulse {
  background: #fff0a8;
  border-color: rgba(229, 119, 31, 0.76);
  color: #7a3219;
  animation: combo-pop 0.48s cubic-bezier(.2, 1.35, .28, 1);
}

.combo-stat.is-combo-pulse span {
  color: #c04e26;
}

.combo-stat.is-combo-pulse strong {
  color: #1f1712;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.8);
}

.combo-stat.is-max {
  border-color: rgba(255, 209, 79, 0.92);
  background: linear-gradient(180deg, rgba(255, 248, 199, 0.96), rgba(255, 218, 102, 0.94));
}

.combo-stat.is-max span::after {
  content: " MAX";
  color: #c15624;
  font-size: 0.72em;
}

.combo-stat.is-gold-rush {
  border-color: rgba(255, 178, 49, 0.98);
  background: linear-gradient(180deg, #fff4aa 0%, #ffb83d 100%);
  animation: combo-pop 0.7s cubic-bezier(.2, 1.35, .28, 1) infinite alternate;
}

.combo-stat.is-gold-rush span::after {
  content: " RUSH";
  color: #8d4618;
  font-size: 0.72em;
}

#lives {
  color: #e85d36;
  display: flex;
  justify-content: center;
  gap: 2px;
  font-size: clamp(12px, 2.15dvh, 16px);
  letter-spacing: 0;
  white-space: nowrap;
  overflow: hidden;
}

.life-dot {
  display: inline-grid;
  width: clamp(13px, 2.35dvh, 18px);
  height: clamp(13px, 2.35dvh, 18px);
  place-items: center;
  line-height: 1;
}

.game {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 0;
  background: #f7c57c;
  box-shadow: none;
  touch-action: manipulation;
  user-select: none;
}

.game::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 18;
  opacity: 0;
  pointer-events: none;
}

.game.feedback-good::after {
  background: radial-gradient(circle at 34% 48%, rgba(255, 213, 99, 0.36), transparent 36%);
  animation: feedback-flash 0.34s ease-out;
}

.game.feedback-score::after {
  background: radial-gradient(circle at 24% 58%, rgba(255, 249, 226, 0.24), transparent 34%);
  animation: feedback-flash 0.24s ease-out;
}

.game.is-gold-rush::after {
  background:
    radial-gradient(circle at 18% 24%, rgba(255, 214, 91, 0.32), transparent 18%),
    radial-gradient(circle at 82% 22%, rgba(255, 214, 91, 0.28), transparent 19%),
    linear-gradient(90deg, rgba(255, 188, 63, 0.14), transparent 24%, transparent 76%, rgba(255, 188, 63, 0.14));
  animation: fever-glow 0.9s ease-in-out infinite alternate;
}

.game.feedback-danger::after {
  background: rgba(216, 55, 36, 0.24);
  animation: danger-flash 0.34s ease-out;
}

.map-art {
  position: absolute;
  inset: 0;
  background-image: url("./assets/night-stall-bg-v34.png");
  background-size: auto 100%;
  background-position: var(--map-x, 0px) center;
  background-repeat: repeat-x;
  pointer-events: none;
}

.snowfall {
  position: absolute;
  inset: -30% 0 0;
  z-index: 2;
  background-image:
    radial-gradient(circle, rgba(255, 255, 255, 0.88) 0 2px, transparent 3px),
    radial-gradient(circle, rgba(255, 255, 255, 0.72) 0 1px, transparent 2px),
    radial-gradient(circle, rgba(255, 255, 255, 0.62) 0 1.5px, transparent 2.5px);
  background-size: 130px 110px, 190px 160px, 260px 210px;
  background-position: 0 0, 60px 30px, 120px 80px;
  animation: snowfall 9s linear infinite;
  pointer-events: none;
}

.snow-lane {
  position: absolute;
  left: -10%;
  right: -10%;
  bottom: 0;
  height: 28%;
  background:
    radial-gradient(ellipse at 40px 68%, rgba(210, 198, 205, 0.5) 0 14px, transparent 15px),
    radial-gradient(ellipse at 180px 78%, rgba(210, 198, 205, 0.42) 0 10px, transparent 11px),
    linear-gradient(180deg, rgba(255, 255, 255, 0), rgba(252, 246, 242, 0.32));
  background-size: 260px 100%, 260px 100%, 100% 100%;
  background-position: var(--lane-x, 0px) 0, var(--lane-x, 0px) 0, 0 0;
  pointer-events: none;
}

.ground {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 12%;
  background: linear-gradient(180deg, rgba(78, 45, 33, 0.0), rgba(78, 45, 33, 0.16));
  border-top: 0;
  pointer-events: none;
}

.cat {
  position: absolute;
  z-index: 12;
  left: 5.8%;
  bottom: 11%;
  width: 25%;
  aspect-ratio: 1.48 / 1;
  transform-origin: 50% 100%;
  image-rendering: auto;
  filter: drop-shadow(0 10px 8px rgba(71, 41, 25, 0.2));
  opacity: 1;
  overflow: visible;
}

.cat::before {
  content: "";
  position: absolute;
  left: -2%;
  right: -2%;
  top: -7%;
  bottom: -4%;
  background-repeat: no-repeat;
  background-position: center;
}

.cat-runner::before {
  width: auto;
  background-image: url("./assets/cat-run-frame-0-v40.png");
  background-size: contain;
  background-position: center;
}

.cat-runner[data-run-frame="1"]::before {
  background-image: url("./assets/cat-run-frame-1-v40.png");
}

.cat-runner[data-run-frame="2"]::before {
  background-image: url("./assets/cat-run-frame-2-v40.png");
}

.cat-runner[data-run-frame="3"]::before {
  background-image: url("./assets/cat-run-frame-3-v40.png");
}

.cat-jumper::before {
  width: auto;
  background-image: url("./assets/cat-jump-flat-v40.png");
  background-size: contain;
  background-position: center;
}

.cat.is-running {
  animation: bob 0.32s ease-in-out infinite alternate;
}

.cat.is-hit {
  opacity: 0.68;
  transition: opacity 80ms ease-out;
}

.item {
  position: absolute;
  bottom: var(--item-bottom, 22%);
  width: 9.5%;
  aspect-ratio: 4 / 3;
  height: auto;
  background: center / contain no-repeat;
  filter: drop-shadow(0 8px 0 rgba(71, 41, 25, 0.16));
}

.item.redbean {
  background-image: url("./assets/fish-redbean-flat-v34.png");
}

.item.custard {
  background-image: url("./assets/fish-custard-flat-v34.png");
}

.item.gold {
  background-image: url("./assets/fish-custard-flat-v34.png");
  filter:
    drop-shadow(0 0 10px rgba(255, 224, 89, 0.82))
    drop-shadow(0 8px 0 rgba(71, 41, 25, 0.16))
    saturate(1.35) brightness(1.18);
}

.item.goldbit {
  width: 7.8%;
  background-image: url("./assets/fish-custard-flat-v34.png");
  filter:
    drop-shadow(0 0 8px rgba(255, 224, 89, 0.76))
    drop-shadow(0 6px 0 rgba(71, 41, 25, 0.14))
    saturate(1.45) brightness(1.22);
}

.item.bad {
  bottom: var(--item-bottom, 20%);
  width: 9%;
  aspect-ratio: 1 / 1;
  height: auto;
  background-image: url("./assets/burnt-fish-flat-v34.png");
}

.item.puddle {
  bottom: var(--item-bottom, 15%);
  width: 10%;
  aspect-ratio: 2 / 1;
  background-image: url("./assets/puddle-v40.png");
  filter: drop-shadow(0 6px 0 rgba(47, 65, 86, 0.18));
}

.item.bag {
  bottom: var(--item-bottom, 23%);
  width: 8%;
  aspect-ratio: 4 / 5;
  background-image: url("./assets/bag-item-v34.png");
  filter: drop-shadow(0 8px 0 rgba(71, 41, 25, 0.14));
}

.item.bag::before {
  content: none;
}

.float-text {
  position: absolute;
  left: 16%;
  bottom: 42%;
  color: var(--button);
  font-weight: 950;
  font-size: clamp(14px, 2.8dvh, 20px);
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.75);
  pointer-events: none;
  animation: float-up 0.75s ease-out forwards;
}

.float-text.combo,
.float-text.bonus {
  left: 23%;
  bottom: 48%;
  padding: 0.2em 0.48em 0.25em;
  border: 2px solid rgba(126, 73, 32, 0.18);
  border-radius: 8px;
  color: #8a3b1e;
  background: rgba(255, 247, 210, 0.92);
  font-size: clamp(17px, 4dvh, 28px);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.95);
  box-shadow: 0 6px 14px rgba(88, 47, 24, 0.16);
  animation: float-combo 0.82s ease-out forwards;
}

.float-text.danger {
  left: 18%;
  bottom: 45%;
  padding: 0.18em 0.46em 0.24em;
  border: 2px solid rgba(255, 255, 255, 0.34);
  border-radius: 8px;
  color: #ffffff;
  background: rgba(207, 55, 42, 0.86);
  font-size: clamp(16px, 3.7dvh, 26px);
  text-shadow: 0 2px 0 rgba(112, 30, 25, 0.42);
  box-shadow: 0 7px 16px rgba(91, 22, 12, 0.22);
  animation: float-danger 0.72s ease-out forwards;
}

.burst {
  position: absolute;
  z-index: 28;
  left: 50%;
  top: 34%;
  padding: 0.22em 0.56em 0.28em;
  border-radius: 8px;
  opacity: 0;
  color: #fff7d4;
  background: rgba(232, 93, 54, 0.9);
  border: 2px solid rgba(255, 255, 255, 0.42);
  font-size: clamp(18px, 4.6dvh, 34px);
  font-weight: 950;
  line-height: 1;
  text-align: center;
  text-shadow: 0 2px 0 rgba(93, 40, 20, 0.28);
  transform: translate(-50%, -50%) scale(0.82);
  pointer-events: none;
  white-space: nowrap;
}

.burst.combo {
  color: #55311a;
  background: linear-gradient(180deg, #fff7cf 0%, #ffd36b 100%);
  box-shadow: 0 4px 0 rgba(143, 75, 26, 0.42), 0 12px 24px rgba(92, 46, 20, 0.18);
}

.burst.danger {
  color: #fff9f1;
  background: linear-gradient(180deg, #f06f54 0%, #c83c34 100%);
  box-shadow: 0 4px 0 rgba(111, 28, 26, 0.48), 0 12px 24px rgba(92, 24, 20, 0.2);
}

.burst.gold {
  color: #5a2f16;
  background: linear-gradient(180deg, #fff6a8 0%, #ffb12f 100%);
  border-color: rgba(255, 251, 216, 0.75);
  box-shadow: 0 5px 0 rgba(145, 75, 25, 0.46), 0 0 30px rgba(255, 215, 86, 0.42);
}

.burst.is-visible {
  animation: burst-pop 0.62s cubic-bezier(.18, 1.35, .28, 1) forwards;
}

.title-screen {
  position: absolute;
  inset: 0;
  z-index: 55;
  padding: clamp(18px, 4dvh, 34px) clamp(18px, 4vw, 48px) clamp(24px, 5dvh, 42px);
  background: url("./assets/title-key-art.png") center / cover no-repeat;
}

.title-screen.is-hidden {
  display: none;
}

.title-actions {
  position: absolute;
  left: 50%;
  bottom: clamp(6px, 2.2dvh, 18px);
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  transform: translateX(-50%);
}

.title-play {
  width: clamp(152px, 23dvh, 216px);
  aspect-ratio: 2.84 / 1;
  border: 0;
  color: transparent;
  font: inherit;
  font-weight: 950;
  cursor: pointer;
  background: url("./assets/play-button-v35.png") center / contain no-repeat;
  filter: drop-shadow(0 12px 12px rgba(54, 31, 20, 0.28));
  transition: transform 120ms ease, filter 120ms ease;
}

.title-play:active {
  transform: translateY(4px) scale(0.97);
  filter: drop-shadow(0 7px 8px rgba(54, 31, 20, 0.24));
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(58px, 12dvh) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background: rgba(45, 32, 24, 0.38);
  z-index: 60;
}

[hidden] {
  display: none !important;
}

.panel {
  width: min(620px, 78%);
  max-height: 100%;
  overflow: auto;
  padding: clamp(10px, 2.2dvh, 16px);
  border: 4px solid rgba(72, 42, 24, 0.28);
  border-radius: 8px;
  background: var(--paper);
  text-align: center;
  box-shadow: 0 18px 36px rgba(76, 44, 20, 0.18);
}

.panel.is-ranking-only .name-label,
.panel.is-ranking-only .name-row {
  display: none;
}

.panel h2 {
  margin: 0 0 4px;
  font-size: clamp(22px, 5.4dvh, 34px);
  letter-spacing: 0;
}

.panel p {
  margin: 4px 0 0;
  color: var(--muted);
  line-height: 1.55;
  font-weight: 700;
}

.name-label {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
  text-align: left;
}

.name-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 5px;
}

.name-row input {
  width: 100%;
  min-height: clamp(32px, 7.5dvh, 40px);
  border: 2px solid rgba(89, 53, 31, 0.28);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: #fffaf0;
  font: inherit;
  font-weight: 850;
}

.save-score {
  min-height: clamp(32px, 7.5dvh, 40px);
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  color: #fffdf6;
  background: var(--button);
  font: inherit;
  font-weight: 950;
  cursor: pointer;
}

.ranking-list {
  margin: 8px 0 0;
  padding-left: 24px;
  color: var(--ink);
  text-align: left;
  font-weight: 850;
}

.ranking-list li {
  padding: 1px 0;
}

.shell.has-overlay .topbar {
  z-index: 15;
}

.shell.has-overlay .action,
.shell.has-overlay .hint {
  display: none;
}

.action {
  position: absolute;
  z-index: 30;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: clamp(52px, 7.6dvh, 68px);
  height: clamp(52px, 7.6dvh, 68px);
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #ff6b42 0%, #d8452a 100%);
  color: #fff8e8;
  text-shadow: 0 2px 0 rgba(77, 38, 24, 0.35);
  box-shadow: 0 5px 0 #922d1f, 0 10px 20px rgba(54, 31, 20, 0.24);
  font-size: clamp(10px, 1.9dvh, 13px);
  font-weight: 950;
  cursor: pointer;
  line-height: 1.05;
}

.action:active {
  transform: translateY(5px) scale(0.96);
  box-shadow: 0 3px 0 #922d1f, 0 8px 18px rgba(54, 31, 20, 0.24);
}

.action[data-mode="playing"] {
  background: linear-gradient(180deg, #ffd46c 0%, #e98c2e 100%);
  box-shadow: 0 5px 0 #9b5d1f, 0 10px 20px rgba(54, 31, 20, 0.24);
}

.action[data-mode="paused"] {
  background: linear-gradient(180deg, #7e8da8 0%, #46536b 100%);
  box-shadow: 0 5px 0 #2c3444, 0 10px 20px rgba(54, 31, 20, 0.24);
}

.hint {
  position: absolute;
  z-index: 21;
  left: max(12px, env(safe-area-inset-left));
  bottom: max(12px, env(safe-area-inset-bottom));
  max-width: 48%;
  color: rgba(255, 248, 232, 0.9);
  font-size: clamp(11px, 1.9dvh, 14px);
  font-weight: 800;
  text-shadow: 0 2px 0 rgba(61, 32, 17, 0.3);
}

@keyframes bob {
  from {
    transform: translateY(0) rotate(-1deg);
  }
  to {
    transform: translateY(-5px) rotate(1deg);
  }
}

@keyframes combo-pop {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.24) rotate(-2deg);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes feedback-flash {
  0% {
    opacity: 0;
  }
  35% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@keyframes fever-glow {
  from {
    opacity: 0.35;
  }
  to {
    opacity: 0.82;
  }
}

@keyframes danger-flash {
  0% {
    opacity: 0;
    transform: translateX(0);
  }
  22% {
    opacity: 1;
    transform: translateX(-4px);
  }
  46% {
    transform: translateX(4px);
  }
  100% {
    opacity: 0;
    transform: translateX(0);
  }
}

@keyframes burst-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.84) rotate(-2deg);
  }
  22% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.06) rotate(1deg);
  }
  78% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -72%) scale(0.92);
  }
}

@keyframes snowfall {
  from {
    transform: translate3d(0, 0, 0);
  }
  to {
    transform: translate3d(-70px, 210px, 0);
  }
}

@keyframes float-up {
  to {
    opacity: 0;
    transform: translateY(-42px);
  }
}

@keyframes float-combo {
  0% {
    opacity: 0;
    transform: translateY(10px) scale(0.82);
  }
  24% {
    opacity: 1;
    transform: translateY(-8px) scale(1.12);
  }
  100% {
    opacity: 0;
    transform: translateY(-58px) scale(1);
  }
}

@keyframes float-danger {
  0% {
    opacity: 0;
    transform: translateX(0) scale(0.9);
  }
  25% {
    opacity: 1;
    transform: translateX(-8px) scale(1.08);
  }
  55% {
    transform: translateX(8px) scale(1.02);
  }
  100% {
    opacity: 0;
    transform: translateY(-40px) scale(1);
  }
}

@keyframes hit-blink {
  50% {
    opacity: 0.36;
  }
}

@media (max-aspect-ratio: 16 / 9) {
  .shell {
    width: 100vw;
    height: 56.25vw;
  }
}

@media (max-height: 430px) {
  .topbar {
    grid-template-columns: minmax(0, 1fr) repeat(4, minmax(48px, 66px));
    gap: 6px;
  }

  .stat {
    padding: 4px 6px;
  }

  .hint {
    display: none;
  }

  .title-screen {
    padding-top: 10px;
    padding-bottom: 12px;
  }

  .title-actions {
    bottom: 6px;
  }

  .title-play {
    width: clamp(136px, 21dvh, 176px);
  }
}
