:root {
  color-scheme: light;
  --ink: #43290f;
  --cream: #fff8dc;
  --blue: #099ed8;
  --blue-dark: #087db6;
  --red: #ef492f;
  --red-dark: #bb2d1f;
  --gold: #ffcb31;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  display: grid;
  place-items: center;
  min-height: 100svh;
  overflow: hidden;
  background: #fff;
  font-family: "Trebuchet MS", "Arial Rounded MT Bold", system-ui, sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; }

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.game-wrap {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 100svh;
  padding: 0;
}

.game-shell {
  position: relative;
  width: min(100vw, 100svh, 820px);
  aspect-ratio: 1;
  overflow: hidden;
  isolation: isolate;
  border: 0;
  border-radius: 0;
  background: #22b7df url("river-board.png") center / cover no-repeat;
  box-shadow: none;
  user-select: none;
}

.game-shell::after {
  content: none;
}

.title-sign {
  position: absolute;
  z-index: 8;
  left: 50%;
  top: .7%;
  transform: translateX(-50%);
  width: 89%;
  aspect-ratio: 1090 / 176;
  overflow: hidden;
  pointer-events: none;
}

.title-sign img {
  position: absolute;
  left: -21.84%;
  top: -7.4%;
  width: 140.92%;
  max-width: none;
  height: auto;
}

.sky-tools {
  position: absolute;
  z-index: 12;
  left: 2.4%;
  right: 2.4%;
  top: 17.2%;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

.round-button {
  display: grid;
  place-items: center;
  width: clamp(30px, 5.2vmin, 46px);
  aspect-ratio: 1;
  padding: 0;
  border: 3px solid #744011;
  border-radius: 50%;
  background: #fff7d4;
  color: #6a3a12;
  box-shadow: 0 4px 0 #c8913c;
  font-size: clamp(1.1rem, 3.3vmin, 1.8rem);
  font-weight: 1000;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
}

.round-button:active { transform: translateY(3px); box-shadow: 0 1px 0 #c8913c; }

.shore-label {
  position: absolute;
  z-index: 3;
  top: 23.5%;
  min-width: 18%;
  padding: .8% 1.5%;
  border: 2px solid rgba(67, 41, 15, .45);
  border-radius: 999px;
  background: rgba(255, 248, 220, .84);
  box-shadow: 0 3px 0 rgba(67, 41, 15, .14);
  text-align: center;
  font-size: clamp(.68rem, 2.4vmin, 1.15rem);
  font-weight: 1000;
  letter-spacing: .08em;
}

.shore-label-left { left: 7%; }
.shore-label-right { right: 7%; }

.message-bubble {
  position: absolute;
  z-index: 9;
  left: 50%;
  top: 17.1%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 64%;
  padding: .95% 2.6%;
  border: 2px solid rgba(67, 41, 15, .42);
  border-radius: 999px;
  background: rgba(255, 255, 255, .94);
  box-shadow: 0 3px 0 rgba(67, 41, 15, .12);
  text-align: center;
  font-size: clamp(.86rem, 2.65vmin, 1.3rem);
  font-weight: 900;
  line-height: 1.1;
  transition: transform .18s ease;
}

.message-bubble.pop { transform: translateX(-50%) scale(1.05); }
.message-bubble.danger { background: #fff0db; border-color: #d9442f; color: #9e291d; }

.sprite {
  background-image: url("characters.png");
  background-repeat: no-repeat;
  background-size: 200% 200%;
}

.token {
  position: absolute;
  z-index: 5;
  width: 18%;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 30%;
  background-color: transparent;
  cursor: pointer;
  filter: drop-shadow(0 4px 0 rgba(73, 50, 13, .16));
  transition:
    left .68s cubic-bezier(.22, .78, .2, 1),
    top .45s ease,
    width .35s ease,
    transform .16s ease,
    filter .16s ease;
}

.token:hover,
.token:focus-visible {
  outline: none;
  transform: scale(1.07);
  filter: drop-shadow(0 5px 0 rgba(73, 50, 13, .2)) drop-shadow(0 0 8px #fffbd2);
}

.token:active { transform: scale(.94); }
.token.selected { filter: drop-shadow(0 0 8px #fff) drop-shadow(0 0 14px var(--gold)); }
.token:disabled { cursor: default; }
.token.hopping { animation: hop-aboard .66s cubic-bezier(.2, .72, .25, 1) both; }
.token.fox-chase { animation: fox-chase 1.05s ease-in-out both; z-index: 7 !important; }
.token.chicken-panic { animation: chicken-panic .18s linear 6; }
.token.chicken-peck { animation: chicken-peck 1.05s ease-in-out both; z-index: 7 !important; }
.token.grain-wobble { animation: grain-wobble .18s linear 6; }

.fox { background-position: 0 0; }
.chicken { background-position: 100% 0; }
.grain { background-position: 0 100%; }

.boat {
  position: absolute;
  z-index: 4;
  left: 27%;
  top: 50%;
  width: 33%;
  aspect-ratio: 1;
  background-position: 100% 100%;
  filter: drop-shadow(0 7px 0 rgba(11, 73, 95, .18));
  transition: left .72s cubic-bezier(.22, .78, .2, 1), transform .25s ease;
  animation: bob 2.2s ease-in-out infinite;
}

.boat.right { left: 40%; }
.boat.sailing { animation: sail-bob .36s ease-in-out infinite alternate; }

@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-.4deg); }
  50% { transform: translateY(-1.5%) rotate(.5deg); }
}

@keyframes sail-bob {
  from { transform: translateY(-1%) rotate(-1deg); }
  to { transform: translateY(1%) rotate(1deg); }
}

@keyframes hop-aboard {
  0% { transform: translateY(0) scale(1); }
  38% { transform: translateY(-46%) scale(1.08, .94) rotate(-3deg); }
  72% { transform: translateY(-12%) scale(.96, 1.06) rotate(2deg); }
  88% { transform: translateY(3%) scale(1.04, .96); }
  100% { transform: translateY(0) scale(1); }
}

@keyframes fox-chase {
  0% { transform: translate(0, 0) scale(1); }
  24% { transform: translate(-8%, -4%) scale(.94, 1.06) rotate(-4deg); }
  58% { transform: translate(18%, 78%) scale(1.1, .92) rotate(7deg); }
  78% { transform: translate(8%, 70%) scale(.98, 1.05) rotate(-3deg); }
  100% { transform: translate(18%, 78%) scale(1.05); }
}

@keyframes chicken-panic {
  0%, 100% { transform: translateX(0) rotate(0); }
  33% { transform: translateX(-10%) rotate(-6deg); }
  66% { transform: translateX(11%) rotate(7deg); }
}

@keyframes chicken-peck {
  0% { transform: translate(0, 0) rotate(0); }
  28% { transform: translate(0, 65%) rotate(8deg) scale(1.04); }
  43% { transform: translate(0, 73%) rotate(17deg) scale(1.07, .93); }
  58% { transform: translate(0, 64%) rotate(5deg); }
  73% { transform: translate(0, 74%) rotate(18deg) scale(1.07, .93); }
  100% { transform: translate(0, 67%) rotate(9deg); }
}

@keyframes grain-wobble {
  0%, 100% { transform: rotate(0) scale(1); }
  33% { transform: rotate(-5deg) scale(.98, 1.02); }
  66% { transform: rotate(5deg) scale(1.02, .98); }
}

.controls {
  position: absolute;
  z-index: 10;
  inset: auto 0 0;
  width: 100%;
  height: 13.6%;
  overflow: hidden;
}

.controls-art {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  max-width: none;
  height: auto;
  pointer-events: none;
}

.move-button,
.restart-button {
  position: absolute;
  top: 5%;
  height: 80%;
  padding: 0;
  border: 0;
  border-radius: 20%;
  background: transparent;
  color: transparent;
  box-shadow: none;
  cursor: pointer;
}

.move-button {
  left: 32.6%;
  width: 32.9%;
}

.restart-button {
  left: 67%;
  top: 17%;
  width: 17.7%;
  height: 66%;
}

.move-button:active,
.restart-button:active { background: rgba(255, 255, 255, .18); transform: scale(.97); }

.move-button:focus-visible,
.restart-button:focus-visible,
.result-card button:focus-visible,
.got-it:focus-visible { outline: 4px solid #fff; outline-offset: 3px; }

.move-button:disabled,
.restart-button:disabled { cursor: default; }

.result-card button,
.got-it {
  border: clamp(3px, .5vmin, 5px) solid #fff8dd;
  font-weight: 1000;
  cursor: pointer;
}

.result-layer {
  position: absolute;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 8%;
  background: rgba(3, 70, 96, .42);
  backdrop-filter: blur(3px);
}

.result-layer[hidden] { display: none; }

.result-card {
  position: relative;
  z-index: 2;
  width: min(82%, 480px);
  padding: 7% 7% 6%;
  border: clamp(4px, .8vmin, 8px) solid #6d3d14;
  border-radius: clamp(22px, 4vmin, 38px);
  background: #fff8d7;
  box-shadow: inset 0 -10px 0 #f0cc78, 0 18px 40px rgba(25, 37, 40, .28);
  text-align: center;
  animation: card-in .35s cubic-bezier(.18, .89, .32, 1.28);
}

@keyframes card-in {
  from { opacity: 0; transform: scale(.72) translateY(8%); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.result-icon {
  margin: -3% auto 1%;
  color: #f4a819;
  font-size: clamp(2.6rem, 11vmin, 6rem);
  line-height: .9;
  text-shadow: 0 4px 0 #9a5318;
}

.result-card h2 {
  margin: 2% 0 1%;
  color: #ec5a22;
  font-size: clamp(1.55rem, 6vmin, 3.5rem);
  line-height: 1;
}

.result-card p {
  margin: 3% auto 7%;
  max-width: 32ch;
  font-size: clamp(.86rem, 2.7vmin, 1.35rem);
  line-height: 1.25;
  font-weight: 800;
}

.result-card button,
.got-it {
  padding: .7em 1.35em;
  border-radius: 999px;
  background: var(--blue);
  color: #fff;
  box-shadow: 0 5px 0 var(--blue-dark), 0 0 0 3px #6d3d14;
  font-size: clamp(.82rem, 2.7vmin, 1.35rem);
}

.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }

.confetti-piece {
  position: absolute;
  top: -10%;
  width: 2.1%;
  aspect-ratio: .55;
  border-radius: 3px;
  animation: fall var(--fall-time) linear var(--delay) infinite;
}

@keyframes fall {
  to { transform: translate3d(var(--drift), 118vh, 0) rotate(760deg); }
}

.help-dialog {
  width: min(88vw, 480px);
  padding: 0;
  border: 6px solid #6d3d14;
  border-radius: 28px;
  background: #fff8d7;
  color: var(--ink);
  box-shadow: 0 24px 60px rgba(24, 62, 72, .35);
}

.help-dialog::backdrop { background: rgba(4, 76, 103, .55); backdrop-filter: blur(3px); }
.help-dialog form { position: relative; padding: 30px clamp(24px, 6vw, 42px) 36px; }
.help-dialog h2 { margin: 0 0 18px; color: #ee5d22; font-size: 2rem; }
.help-dialog ol { margin: 0 0 26px; padding-left: 1.35em; font-size: 1rem; font-weight: 750; line-height: 1.45; }
.help-dialog li + li { margin-top: .65em; }
.dialog-close { position: absolute; top: 10px; right: 14px; border: 0; background: transparent; color: #744011; font-size: 2rem; font-weight: 1000; cursor: pointer; }
.got-it { display: block; margin: 0 auto; }

@media (max-aspect-ratio: 1/1) {
  .game-wrap { align-items: start; }
  .game-shell { width: min(100vw, 820px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
