:root {
  color-scheme: light;
  font-family: "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
  background: #dff7ca;
  color: #24351b;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
  touch-action: manipulation;
  overscroll-behavior: none;
}

body {
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 14% 12%, rgba(255, 219, 99, 0.45), transparent 24%),
    radial-gradient(circle at 84% 10%, rgba(100, 181, 246, 0.32), transparent 24%),
    linear-gradient(180deg, #e8ffd4 0%, #8fd18a 55%, #5fac72 100%);
}

button,
select,
a {
  font: inherit;
}

.rescue-game {
  position: relative;
  display: grid;
  grid-template-rows: 62px 58px minmax(0, 1fr);
  gap: 10px;
  width: min(100vw, 540px);
  height: min(100dvh, 940px);
  padding: max(12px, env(safe-area-inset-top)) 14px calc(16px + env(safe-area-inset-bottom));
  overflow: hidden;
}

.topbar {
  display: grid;
  grid-template-columns: 50px 1fr 130px;
  gap: 10px;
  align-items: center;
  min-width: 0;
}

.home-link,
.language-picker,
.hud div,
.animal-panel,
.board,
.stage-card,
.result-card,
.loading-card {
  border: 3px solid #3e702d;
  border-radius: 8px;
  background: #fffbea;
  box-shadow: 0 5px 0 #6ca75b;
}

.home-link {
  display: grid;
  place-items: center;
  height: 50px;
  color: #24351b;
  font-size: 28px;
  font-weight: 1000;
  text-decoration: none;
}

.topbar > div {
  min-width: 0;
}

.topbar p,
.language-picker span,
.hud span {
  margin: 0;
  color: #496b2e;
  font-size: 12px;
  font-weight: 1000;
}

.topbar h1 {
  overflow: hidden;
  margin: 3px 0 0;
  font-size: clamp(23px, 6vw, 34px);
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.language-picker {
  display: grid;
  gap: 5px;
  padding: 8px;
}

.language-picker select {
  width: 100%;
  min-height: 32px;
  border: 2px solid #3e702d;
  border-radius: 8px;
  background: #fff;
  color: #24351b;
  font-size: 13px;
  font-weight: 1000;
}

.hud {
  grid-row: 2;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.hud div {
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 7px 4px;
}

.hud strong {
  color: #e87332;
  font-size: clamp(18px, 5vw, 25px);
  line-height: 1;
}

.stage-select,
.play-area {
  min-height: 0;
}

.stage-select {
  grid-row: 2 / 4;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  overflow: hidden;
}

.stage-select > strong {
  font-size: clamp(28px, 8vw, 42px);
  line-height: 1;
  text-align: center;
}

.stage-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  overflow-y: auto;
  padding: 2px 2px 10px;
}

.stage-card {
  position: relative;
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 8px;
  min-height: 112px;
  padding: 10px;
  color: inherit;
  text-align: left;
}

.stage-card.locked {
  filter: grayscale(1);
  opacity: 0.62;
}

.stage-card .mini-animal {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 8px;
  background: #dff7ca;
  font-size: 34px;
}

.stage-card strong {
  display: block;
  margin-bottom: 4px;
  font-size: 16px;
  line-height: 1.1;
}

.stage-card span {
  color: #5b7448;
  font-size: 12px;
  font-weight: 900;
  line-height: 1.25;
}

.stage-stars {
  grid-column: 1 / -1;
  color: #f5a623;
  font-size: 18px;
  letter-spacing: 1px;
}

.play-area {
  grid-row: 3;
  display: grid;
  grid-template-rows: 88px minmax(0, 1fr) 54px;
  gap: 10px;
}

.animal-panel {
  display: grid;
  grid-template-columns: 68px 1fr;
  gap: 10px;
  align-items: center;
  padding: 10px;
}

.animal-avatar {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 8px;
  background: linear-gradient(180deg, #fff8c9, #daf4b7);
  font-size: 42px;
}

.animal-panel strong {
  display: block;
  font-size: 23px;
  line-height: 1;
}

.animal-panel span {
  display: block;
  margin-top: 5px;
  color: #5b7448;
  font-size: 14px;
  font-weight: 900;
  line-height: 1.2;
}

.board {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-template-rows: repeat(5, minmax(0, 1fr));
  align-self: center;
  width: 100%;
  max-height: 100%;
  aspect-ratio: 1;
  gap: 7px;
  min-height: 0;
  padding: 9px;
  background:
    linear-gradient(180deg, rgba(255, 251, 234, 0.94), rgba(227, 247, 198, 0.94)),
    #fffbea;
}

.tile {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(180deg, #d7c18a, #b99357);
  color: #24351b;
  font-size: clamp(27px, 10vw, 48px);
  box-shadow: inset 0 -5px 0 rgba(79, 52, 25, 0.18);
}

.tile.path {
  background: linear-gradient(180deg, #f7de9f, #cfaa66);
}

.tile.grass {
  background: linear-gradient(180deg, #8bd76e, #4fa95f);
}

.tile.water {
  background: linear-gradient(180deg, #8ed9ff, #3b9dd5);
}

.tile.rock {
  background: linear-gradient(180deg, #a5a6a1, #696f70);
}

.tile.blocked {
  cursor: not-allowed;
  filter: saturate(0.88);
}

.tile.current {
  outline: 5px solid #fff4a3;
  z-index: 2;
}

.tile.next {
  outline: 4px solid rgba(255, 255, 255, 0.78);
}

.tile.visited::after {
  content: "";
  position: absolute;
  inset: 30% 28%;
  border-radius: 999px;
  background: rgba(102, 64, 29, 0.32);
}

.action-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.action-row button,
.result-card button,
.result-card a {
  display: grid;
  place-items: center;
  min-height: 48px;
  border: 3px solid #3e702d;
  border-radius: 8px;
  background: #ffd866;
  color: #24351b;
  font-size: 18px;
  font-weight: 1000;
  text-decoration: none;
  box-shadow: 0 5px 0 #b78633;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

.action-row button:active,
.result-card button:active,
.result-card a:active {
  transform: translateY(3px) scale(0.98);
  box-shadow: 0 2px 0 #b78633;
  filter: brightness(1.05);
}

.result-panel,
.loading-panel {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(223, 247, 202, 0.9);
  animation: rescue-fade-in 0.24s ease;
}

.result-card,
.loading-card {
  display: grid;
  justify-items: center;
  gap: 11px;
  width: min(100%, 360px);
  padding: 22px;
  text-align: center;
}

.result-card {
  border: 3px solid rgba(62, 112, 45, 0.3);
  border-radius: 8px;
  background: rgba(255, 253, 232, 0.78);
  box-shadow: 0 20px 44px rgba(62, 112, 45, 0.22);
  animation: rescue-panel-pop 0.42s cubic-bezier(0.17, 0.9, 0.28, 1.2);
}

.loading-card {
  animation: rescue-panel-pop 0.36s ease;
}

.result-card strong,
.loading-card strong {
  font-size: clamp(30px, 9vw, 44px);
  line-height: 1;
}

.result-card span {
  color: #5b7448;
  font-size: 16px;
  font-weight: 900;
  line-height: 1.3;
}

.star-line {
  color: #f5a623;
  font-size: 34px;
  letter-spacing: 2px;
  animation: rescue-star-burst 0.72s ease;
}

.loading-card div {
  width: 100%;
  height: 18px;
  padding: 3px;
  border: 3px solid #3e702d;
  border-radius: 999px;
  background: #fff;
}

.loading-card i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #8bd76e, #ffd866, #ff9f5a);
  transition: width 0.2s ease;
}

.hidden {
  display: none !important;
}

@keyframes rescue-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes rescue-panel-pop {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.92);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes rescue-star-burst {
  0% {
    opacity: 0;
    transform: scale(0.5) rotate(-8deg);
    filter: brightness(1.5);
  }
  55% {
    transform: scale(1.22) rotate(4deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .result-panel,
  .loading-panel,
  .result-card,
  .loading-card,
  .star-line {
    animation: none;
  }
}

@media (max-width: 420px) {
  .rescue-game {
    grid-template-rows: 56px 52px minmax(0, 1fr);
    gap: 8px;
    padding-right: 9px;
    padding-left: 9px;
  }

  .topbar {
    grid-template-columns: 44px 1fr 112px;
  }

  .home-link {
    height: 44px;
  }

  .language-picker span {
    display: none;
  }

  .stage-grid {
    gap: 8px;
  }

  .stage-card {
    grid-template-columns: 48px 1fr;
    min-height: 104px;
    padding: 8px;
  }
}
html,
body,
button,
a,
canvas,
[role="button"] {
  -webkit-user-select: none;
  user-select: none;
}

input,
textarea,
select,
[contenteditable="true"] {
  -webkit-user-select: text;
  user-select: text;
}
