:root {
  color-scheme: light;
  --ink: #6f3515;
  --ink-deep: #4b240f;
  --shadow: rgba(91, 44, 13, 0.28);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  font-family: "Nunito", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
}

body {
  min-height: 100svh;
  overflow-x: hidden;
  color: var(--ink);
  background: #e9c58e;
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 4px solid #fff8dc;
  outline-offset: 3px;
}

.game-app {
  position: relative;
  width: min(100%, 840px);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) clamp(12px, 3vw, 26px) max(18px, env(safe-area-inset-bottom));
  overflow: hidden;
  isolation: isolate;
  background-color: #f5d5a0;
  background-image: url("./assets/ui/sprites/background-scene.png");
  background-repeat: no-repeat;
  background-position: center top;
  background-size: 100% 100%;
  box-shadow: 0 0 60px rgba(71, 34, 10, 0.3);
}

.game-app::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: rgba(255, 231, 190, 0.08);
}

.game-toolbar {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: clamp(12px, 3vw, 26px);
  z-index: 20;
  display: flex;
  gap: 8px;
}

.wood-chip {
  min-width: 58px;
  min-height: 38px;
  border: 0;
  border-radius: 16px;
  padding: 8px 12px;
  color: #fff3d5;
  background-color: #7c3d17;
  box-shadow: inset 0 -3px 0 #4d250f, 0 5px 12px rgba(86, 43, 15, 0.22);
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
  transition: transform 150ms var(--ease), filter 150ms var(--ease);
}

.game-logo {
  position: relative;
  width: min(78%, 580px);
  aspect-ratio: 2.34;
  margin: 4px auto -8px;
  display: grid;
  place-items: center;
  filter: drop-shadow(0 10px 8px rgba(74, 35, 10, 0.25));
  animation: logo-in 620ms var(--ease) both;
}

.game-logo > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.game-logo__copy {
  position: relative;
  z-index: 1;
  display: grid;
  justify-items: center;
  line-height: 0.92;
  transform: translateY(-2%);
  text-align: center;
  text-shadow: 0 3px 0 rgba(91, 39, 10, 0.55), 0 6px 8px rgba(71, 30, 7, 0.25);
}

.game-logo__fruit {
  color: #ffd34f;
  font-family: "Arial Rounded MT Bold", "Arial Black", sans-serif;
  font-size: clamp(30px, 8vw, 68px);
  font-weight: 1000;
  letter-spacing: 0.03em;
}

.game-logo__fruit span:nth-child(1) {
  color: #ffd94d;
}

.game-logo__fruit span:nth-child(2) {
  color: #ff9a18;
}

.game-logo__fruit span:nth-child(3) {
  color: #78b930;
}

.game-logo__fruit span:nth-child(4) {
  color: #ef4c37;
}

.game-logo__fruit span:nth-child(5) {
  color: #ffad20;
}

.game-logo__flood {
  margin-top: 5px;
  color: #fff4d8;
  font-family: "Arial Rounded MT Bold", "Arial Black", sans-serif;
  font-size: clamp(16px, 4.2vw, 34px);
  font-weight: 1000;
  letter-spacing: 0.04em;
}

.play-layout {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(82px, 17vw, 124px);
  align-items: center;
  gap: clamp(6px, 1.6vw, 14px);
  margin-top: -2px;
}

.board-column {
  position: relative;
  min-width: 0;
  padding-top: clamp(18px, 3.6vw, 30px);
}

.origin-label {
  position: absolute;
  top: 0;
  left: 8%;
  z-index: 5;
  color: #fff9e7;
  font-size: clamp(12px, 2.5vw, 20px);
  font-weight: 1000;
  text-shadow: 0 2px 5px rgba(75, 36, 12, 0.78);
}

.origin-label img {
  width: clamp(20px, 4vw, 34px);
  margin-left: 2px;
  vertical-align: -55%;
  transform: rotate(105deg);
  filter: drop-shadow(0 2px 3px rgba(75, 36, 12, 0.4));
}

.board-shell {
  position: relative;
  width: min(100%, 650px);
  margin-inline: auto;
  aspect-ratio: 595 / 570;
  display: grid;
  place-items: center;
  background: url("./assets/ui/sprites/board-basket.png") center / contain no-repeat;
  filter: drop-shadow(0 16px 12px rgba(74, 35, 10, 0.3));
  animation: board-in 650ms 80ms var(--ease) both;
}

.board-grid {
  width: 83%;
  height: 83%;
  margin-top: -1.5%;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-template-rows: repeat(6, minmax(0, 1fr));
  gap: clamp(1px, 0.4vw, 3px);
  transform: perspective(900px) rotateX(1deg);
}

.fruit-tile {
  position: relative;
  min-width: 0;
  border-radius: 15%;
  transform: translateZ(0);
  transition: transform 240ms var(--ease), filter 240ms var(--ease);
}

.fruit-tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  filter: saturate(1.05) drop-shadow(0 2px 1px rgba(71, 29, 6, 0.24));
  user-select: none;
  -webkit-user-drag: none;
}

.fruit-tile--origin::after {
  content: "";
  position: absolute;
  inset: 1px;
  border: clamp(2px, 0.6vw, 5px) solid #fffdf1;
  border-radius: 17%;
  box-shadow: 0 0 0 2px rgba(113, 53, 15, 0.14);
  pointer-events: none;
}

.fruit-tile.is-growing {
  z-index: 2;
  animation: tile-pop 420ms var(--ease);
}

.side-panel {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: clamp(5px, 1vw, 10px);
}

.status-panel {
  width: 130%;
  aspect-ratio: 215 / 450;
  display: grid;
  grid-template-rows: 1fr 1fr;
  background: url("./assets/ui/sprites/status-panel.png") center / contain no-repeat;
  filter: drop-shadow(0 8px 7px rgba(76, 36, 11, 0.24));
}

.status-panel__section {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  text-align: center;
}

.status-panel__section span,
.status-panel__section small {
  color: var(--ink);
  font-size: clamp(10px, 2vw, 15px);
  font-weight: 1000;
}

.status-panel__section--target {
  padding-top: 7%;
}

.status-panel__section--target img {
  width: 55%;
  aspect-ratio: 1;
  margin-top: 5%;
  object-fit: cover;
  border-radius: 18%;
  filter: drop-shadow(0 5px 3px rgba(91, 44, 13, 0.26));
}

.status-panel__section--moves {
  padding-bottom: 8%;
}

.status-panel__section--moves strong {
  margin: -1px 0;
  color: #8d4517;
  font-family: Georgia, serif;
  font-size: clamp(31px, 7vw, 54px);
  line-height: 1;
}

.action-button {
  position: relative;
  width: min(94%, 100px);
  aspect-ratio: 1;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  transition: transform 150ms var(--ease), filter 150ms var(--ease), opacity 150ms var(--ease);
}

.action-button img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.action-button span {
  position: absolute;
  left: 50%;
  bottom: -1%;
  transform: translateX(-50%);
  min-width: 52%;
  color: var(--ink);
  font-size: clamp(10px, 2vw, 14px);
  font-weight: 1000;
  text-shadow: 0 1px 0 #fff0c8;
}

.action-button:disabled {
  opacity: 0.45;
  cursor: default;
  filter: grayscale(0.3);
}

.picker-shell {
  position: relative;
  z-index: 3;
  width: min(92%, 620px);
  aspect-ratio: 660 / 180;
  margin: clamp(-4px, -0.6vw, 0px) auto 0;
  display: grid;
  place-items: center;
  background: url("./assets/ui/sprites/picker-tray.png") center / contain no-repeat;
  filter: drop-shadow(0 10px 8px rgba(74, 35, 10, 0.27));
}

.fruit-picker {
  width: 83%;
  height: 57%;
  margin-top: -1%;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  align-items: center;
  gap: clamp(6px, 2vw, 18px);
}

.fruit-button {
  position: relative;
  border: 0;
  padding: 0;
  aspect-ratio: 1;
  background: transparent;
  cursor: pointer;
  transition: transform 180ms var(--ease), filter 180ms var(--ease), opacity 180ms var(--ease);
}

.fruit-button img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  filter: drop-shadow(0 4px 2px rgba(73, 31, 7, 0.2));
}

.fruit-button[aria-pressed="true"] {
  transform: translateY(-8%) scale(1.08);
}

.fruit-button[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  inset: -3px;
  border: 3px solid #fffdf2;
  border-radius: 17%;
  box-shadow: 0 0 0 2px rgba(104, 45, 11, 0.4);
}

.fruit-button.is-hinted {
  animation: hint-pulse 720ms var(--ease) 2;
}

.fruit-button:disabled {
  opacity: 0.55;
  cursor: default;
}

.fruit-button[aria-pressed="true"]:disabled {
  opacity: 1;
}

.picker-label {
  position: absolute;
  left: 50%;
  bottom: -18%;
  width: 72%;
  min-height: 30%;
  padding: 4% 8% 2%;
  transform: translateX(-50%);
  display: grid;
  place-items: center;
  color: #fff3d6;
  background: url("./assets/ui/sprites/wood-label.png") center / 100% 100% no-repeat;
  font-size: clamp(13px, 3vw, 23px);
  font-weight: 1000;
  letter-spacing: 0.04em;
  text-shadow: 0 2px 2px #4a210d;
  white-space: nowrap;
}

.game-message {
  position: relative;
  z-index: 3;
  min-height: 1.4em;
  margin: clamp(14px, 2.2vw, 20px) auto 0;
  color: var(--ink);
  font-size: clamp(12px, 2.2vw, 15px);
  font-weight: 900;
  text-align: center;
  text-shadow: 0 1px 0 rgba(255, 244, 215, 0.95);
}

.decor {
  position: absolute;
  z-index: 0;
  pointer-events: none;
  user-select: none;
  filter: drop-shadow(0 12px 8px rgba(74, 34, 9, 0.24));
}

.decor--watermelon {
  width: clamp(80px, 17vw, 128px);
  left: -8%;
  top: 12%;
  transform: rotate(-15deg);
}

.decor--kiwi {
  width: clamp(74px, 15vw, 112px);
  left: -7%;
  bottom: 5%;
}

.decor--dragon {
  width: clamp(88px, 18vw, 140px);
  right: -8%;
  bottom: 3%;
  transform: rotate(13deg);
}

.decor--leaves {
  width: clamp(90px, 19vw, 145px);
  right: -5%;
  top: 17%;
  transform: rotate(22deg);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(77, 37, 12, 0.56);
}

.overlay[hidden] {
  display: none;
}

.result-card,
.instructions-card {
  position: relative;
  width: min(92vw, 530px);
  min-height: 390px;
  padding: 80px 56px 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: url("./assets/ui/sprites/parchment-panel.png") center / 100% 100% no-repeat;
  filter: drop-shadow(0 25px 25px rgba(47, 20, 4, 0.35));
  animation: modal-in 360ms var(--ease) both;
}

.result-card__confetti {
  position: absolute;
  top: 22px;
  width: 72%;
  height: 90px;
  object-fit: cover;
}

.result-card__trophy {
  position: relative;
  width: 116px;
  margin-bottom: 4px;
}

.result-card p,
.result-card h2,
.result-card span {
  margin: 0;
}

.result-card p {
  color: #a44f14;
  font-size: 22px;
  font-weight: 1000;
}

.result-card h2,
.instructions-card h2 {
  color: var(--ink-deep);
  font-size: clamp(28px, 7vw, 42px);
  line-height: 1.1;
}

.result-card span {
  margin-top: 8px;
  font-weight: 800;
}

.result-card button,
.primary-button {
  min-width: 150px;
  margin-top: 22px;
  border: 0;
  border-radius: 18px;
  padding: 12px 22px;
  color: #fff3d5;
  background-color: #7a3b16;
  box-shadow: inset 0 -4px 0 #4c240e, 0 7px 10px rgba(80, 36, 9, 0.22);
  font-weight: 1000;
  cursor: pointer;
}

.instructions-card {
  align-items: stretch;
  padding-top: 54px;
  text-align: left;
}

.instructions-card h2 {
  margin: 0 0 20px;
  text-align: center;
}

.instructions-card ol {
  margin: 0;
  padding: 0;
  display: grid;
  gap: 15px;
  list-style: none;
  counter-reset: step;
}

.instructions-card li {
  position: relative;
  min-height: 52px;
  padding-left: 58px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  counter-increment: step;
}

.instructions-card li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  width: 42px;
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff2d3;
  background: #8a4318;
  font-weight: 1000;
}

.instructions-card li strong {
  font-size: 17px;
}

.instructions-card li span {
  margin-top: 2px;
  color: #865228;
  font-size: 13px;
  font-weight: 700;
}

.instructions-card .primary-button {
  align-self: center;
}

.close-button {
  position: absolute;
  top: 32px;
  right: 38px;
  min-width: 48px;
  border: 0;
  border-radius: 50%;
  color: #fff4d7;
  background: #7b3a15;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (hover: hover) {
  .wood-chip:hover,
  .action-button:not(:disabled):hover,
  .fruit-button:not(:disabled):hover,
  .result-card button:hover,
  .primary-button:hover {
    transform: translateY(-3px) scale(1.03);
    filter: brightness(1.05);
  }
}

@media (max-width: 480px) {
  .game-app {
    padding-inline: 8px;
  }

  .game-toolbar {
    right: 8px;
  }

  .wood-chip {
    min-width: 48px;
    min-height: 32px;
    border-radius: 13px;
    padding: 6px 8px;
    font-size: 11px;
  }

  .game-logo {
    width: 78%;
    margin-top: 20px;
  }

  .play-layout {
    grid-template-columns: minmax(0, 1fr) 74px;
    gap: 2px;
  }

  .side-panel {
    gap: 2px;
  }

  .fruit-picker {
    gap: 5px;
  }

  .result-card,
  .instructions-card {
    min-height: 360px;
    padding-inline: 38px;
  }
}

@media (min-width: 481px) {
  .board-column {
    transform: translateX(20px);
  }

  .side-panel {
    align-self: start;
    margin-top: -5px;
    transform: translateX(-20px);
  }

  .game-message {
    position: absolute;
    right: 0;
    bottom: 8px;
    left: 0;
    margin: 0;
  }
}

@media (max-height: 720px) and (min-width: 481px) {
  .game-logo {
    width: min(62%, 430px);
    margin-top: -8px;
    margin-bottom: -26px;
  }

  .play-layout {
    max-width: 580px;
    margin-inline: auto;
  }

  .picker-shell {
    width: min(72%, 500px);
    margin-top: -18px;
  }

  .game-message {
    margin-top: 20px;
  }
}

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

@keyframes logo-in {
  from {
    opacity: 0;
    transform: translateY(-16px) scale(0.94);
  }
}

@keyframes board-in {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.96);
  }
}

@keyframes tile-pop {
  0% {
    transform: scale(0.88);
  }
  55% {
    transform: scale(1.12) translateY(-4%);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes hint-pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: translateY(-8%) scale(1.16);
    filter: brightness(1.18) drop-shadow(0 0 8px #fff5a6);
  }
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: scale(0.88) translateY(18px);
  }
}
