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

* {
  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 18% 14%, rgba(255, 209, 96, 0.42), transparent 22%),
    radial-gradient(circle at 82% 12%, rgba(104, 179, 255, 0.28), transparent 24%),
    linear-gradient(180deg, #dff7ca 0%, #8fd18a 100%);
}

button,
select,
a {
  font: inherit;
}

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

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

.home-link,
.language-picker,
.choice-grid button,
.feedback strong {
  border: 3px solid #386b2d;
  border-radius: 8px;
  background: #fffbea;
  box-shadow: 0 5px 0 #6aa45c;
}

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

.topbar p {
  margin: 0 0 3px;
  color: #496b2e;
  font-size: 13px;
  font-weight: 1000;
}

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

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

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

.language-picker span {
  color: #496b2e;
  font-size: 11px;
  font-weight: 1000;
}

.language-picker select {
  width: 100%;
  min-height: 34px;
  border: 2px solid #386b2d;
  border-radius: 8px;
  background: #ffffff;
  color: #233516;
  font-size: 13px;
  font-weight: 1000;
}

.level-line {
  grid-row: 2;
  display: grid;
  grid-template-columns: minmax(0, 190px) 1fr;
  gap: 10px;
  align-items: center;
  height: 42px;
  min-width: 0;
  color: #2d5123;
  font-weight: 1000;
}

.level-line span {
  display: block;
  overflow: hidden;
  min-width: 0;
  font-size: clamp(12px, 3.2vw, 15px);
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.level-line div {
  height: 18px;
  padding: 3px;
  border: 3px solid #386b2d;
  border-radius: 999px;
  background: #fffbea;
}

.level-line i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: #ffbf45;
  transition: width 0.25s ease;
}

.stage-select {
  grid-row: 2 / -1;
  display: grid;
  align-content: start;
  gap: 12px;
  min-height: 0;
  overflow: auto;
  padding: 2px 2px 8px;
}

.stage-select > strong {
  color: #2d5123;
  font-size: 25px;
  font-weight: 1000;
}

.stage-grid {
  display: grid;
  gap: 12px;
}

.stage-card {
  display: grid;
  gap: 7px;
  width: 100%;
  min-height: 116px;
  padding: 14px;
  border: 4px solid #386b2d;
  border-radius: 8px;
  background: #fffbea;
  color: #233516;
  text-align: left;
  box-shadow: 0 7px 0 #6aa45c;
}

.stage-card span {
  justify-self: start;
  padding: 4px 9px;
  border-radius: 999px;
  background: #ffcf63;
  color: #233516;
  font-size: 12px;
  font-weight: 1000;
}

.stage-card strong {
  font-size: 22px;
  line-height: 1.12;
}

.stage-card small {
  color: #496b2e;
  font-size: 14px;
  font-weight: 900;
  line-height: 1.35;
}

.stage-card.locked {
  border-color: #7d8979;
  background: #dde2d8;
  color: #687165;
  box-shadow: 0 7px 0 #a3aaa0;
}

.stage-card.locked span {
  background: #bdc4b8;
  color: #586052;
}

.quiz-stage {
  grid-row: 3;
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: hidden;
}

.animal-card {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto 40px;
  justify-items: center;
  gap: 8px;
  width: min(100%, 350px);
  height: 100%;
  max-height: 330px;
  padding: 14px;
  border: 4px solid #386b2d;
  border-radius: 8px;
  background: #fffbea;
  text-align: center;
  box-shadow: 0 10px 0 #6aa45c, 0 18px 26px rgba(42, 88, 34, 0.22);
}

.animal-card img {
  width: min(54vw, 190px);
  height: min(100%, 190px);
  min-height: 0;
  object-fit: contain;
}

.animal-card strong {
  overflow: hidden;
  max-width: 100%;
  font-size: clamp(19px, 5vw, 24px);
  line-height: 1.12;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.animal-card span {
  display: -webkit-box;
  overflow: hidden;
  color: #496b2e;
  font-size: clamp(12px, 3.5vw, 15px);
  font-weight: 900;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

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

.choice-grid button {
  overflow: hidden;
  min-height: 0;
  color: #233516;
  font-size: clamp(17px, 4.8vw, 22px);
  font-weight: 1000;
  line-height: 1.1;
  text-overflow: ellipsis;
}

.choice-grid button.correct {
  background: #98df75;
  transform: translateY(2px);
}

.choice-grid button.wrong {
  background: #ff9c8d;
  animation: shake 0.24s ease;
}

.feedback {
  grid-row: 5;
  display: grid;
  place-items: center;
  min-height: 0;
}

.feedback strong {
  display: inline-grid;
  place-items: center;
  width: min(100%, 260px);
  height: 44px;
  overflow: hidden;
  padding: 8px 16px;
  color: #233516;
  font-size: clamp(15px, 4vw, 18px);
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-panel,
.loading-panel {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(216, 242, 200, 0.94);
}

.result-card,
.loading-card {
  display: grid;
  gap: 12px;
  width: min(100%, 330px);
  padding: 24px;
  border: 4px solid #386b2d;
  border-radius: 8px;
  background: #fffbea;
  color: #233516;
  text-align: center;
  box-shadow: 0 10px 0 #6aa45c;
}

.result-card strong,
.loading-card strong {
  font-size: 36px;
}

.result-card span,
.loading-card span {
  font-size: 20px;
  font-weight: 1000;
}

.result-card button,
.result-card a {
  display: grid;
  place-items: center;
  min-height: 50px;
  border: 3px solid #386b2d;
  border-radius: 8px;
  background: #ffcf63;
  color: #233516;
  font-size: 18px;
  font-weight: 1000;
  text-decoration: none;
}

.result-card button.hidden {
  display: none !important;
}

.loading-card div {
  height: 18px;
  padding: 3px;
  border: 3px solid #386b2d;
  border-radius: 999px;
  background: #ffffff;
}

.loading-card i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: #ffbf45;
  transition: width 0.2s ease;
}

.result-panel,
.loading-panel {
  animation: quiz-fade-in 0.22s ease;
}

.result-card,
.loading-card {
  animation: quiz-panel-pop 0.38s cubic-bezier(0.17, 0.9, 0.28, 1.2);
}

.result-card strong {
  animation: quiz-title-pop 0.5s ease;
}

.choice-grid button,
.result-card button,
.result-card a {
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

.choice-grid button:active,
.result-card button:active,
.result-card a:active {
  transform: translateY(3px) scale(0.98);
  filter: brightness(1.05);
}

.sound-toggle {
  position: fixed;
  z-index: 40;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  border: 3px solid #386b2d;
  border-radius: 50%;
  background: #fffbea;
  color: #233516;
  font-size: 22px;
  box-shadow: 0 5px 0 #6aa45c;
}

.hidden {
  display: none !important;
}

@keyframes shake {
  25% {
    transform: translateX(-6px);
  }
  75% {
    transform: translateX(6px);
  }
}

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

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

@keyframes quiz-title-pop {
  0% {
    transform: scale(0.82);
    filter: brightness(1.4);
  }
  65% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}

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

@media (max-width: 430px) {
  .animal-game {
    grid-template-rows: 58px 38px minmax(0, 1fr) 124px 46px;
    gap: 9px;
    padding: max(9px, env(safe-area-inset-top)) 10px calc(12px + env(safe-area-inset-bottom));
  }

  .topbar {
    grid-template-columns: 46px 1fr 116px;
    height: 58px;
  }

  .home-link {
    height: 46px;
  }

  .level-line {
    grid-template-columns: minmax(0, 164px) 1fr;
    height: 38px;
  }

  .choice-grid button {
    font-size: 19px;
  }

  .animal-card {
    max-height: 292px;
    padding: 12px;
  }

  .animal-card img {
    width: min(48vw, 165px);
    height: min(100%, 165px);
  }
}

@media (max-height: 680px) {
  .animal-game {
    grid-template-rows: 52px 34px minmax(0, 1fr) 112px 42px;
    gap: 8px;
  }

  .topbar {
    height: 52px;
  }

  .topbar h1 {
    font-size: 24px;
  }

  .language-picker {
    padding: 6px;
  }

  .language-picker span {
    display: none;
  }

  .language-picker select {
    min-height: 31px;
  }

  .home-link {
    height: 42px;
  }

  .level-line {
    height: 34px;
  }

  .animal-card {
    max-height: 246px;
    padding: 10px;
  }

  .animal-card img {
    width: min(42vw, 138px);
    height: min(100%, 138px);
  }

  .animal-card strong {
    font-size: 18px;
  }

  .animal-card span {
    font-size: 12px;
  }

  .choice-grid {
    gap: 8px;
  }

  .feedback strong {
    height: 38px;
  }
}
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;
}
