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

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 219, 102, 0.28), transparent 26%),
    radial-gradient(circle at 88% 12%, rgba(99, 190, 111, 0.24), transparent 30%),
    linear-gradient(160deg, #f9f6e4 0%, #e9f3d8 54%, #d6ead3 100%);
}

button,
a,
select {
  font: inherit;
}

.garden-game {
  width: min(100%, 900px);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 14px calc(18px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 12px;
}

.topbar {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) minmax(144px, 180px);
  gap: 12px;
  align-items: center;
}

.home-link,
.result-actions a,
.result-actions button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #315b35;
  color: #fff;
  text-decoration: none;
  font-weight: 1000;
  box-shadow: 0 10px 24px rgba(49, 91, 53, 0.22);
}

.home-link {
  font-size: 28px;
}

.title-block {
  min-width: 0;
}

.title-block p {
  margin: 0 0 3px;
  color: #6f7f44;
  font-size: 13px;
  font-weight: 1000;
}

.title-block h1 {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(27px, 7vw, 44px);
  line-height: 1.02;
}

.language-picker {
  display: grid;
  gap: 5px;
  padding: 8px;
  border: 1px solid rgba(49, 91, 53, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.68);
}

.language-picker span {
  color: rgba(36, 53, 40, 0.72);
  font-size: 12px;
  font-weight: 1000;
}

.language-picker select {
  width: 100%;
  height: 36px;
  border: 1px solid rgba(49, 91, 53, 0.22);
  border-radius: 8px;
  background: #fffdf1;
  color: #243528;
  font-size: 14px;
  font-weight: 900;
}

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

.statusbar div {
  min-height: 68px;
  padding: 10px 12px;
  border: 1px solid rgba(49, 91, 53, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 8px 20px rgba(49, 91, 53, 0.08);
}

.statusbar span {
  display: block;
  color: rgba(36, 53, 40, 0.66);
  font-size: 13px;
  font-weight: 1000;
}

.statusbar strong {
  display: block;
  margin-top: 4px;
  color: #315b35;
  font-size: clamp(22px, 5vw, 32px);
  line-height: 1;
}

.level-select {
  display: grid;
  gap: 12px;
  align-content: start;
  padding: 14px;
  border: 1px solid rgba(49, 91, 53, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.52);
}

.level-select h2 {
  margin: 0;
  font-size: clamp(24px, 6vw, 34px);
}

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

.level-grid button {
  min-height: 64px;
  border: 2px solid rgba(49, 91, 53, 0.16);
  border-radius: 8px;
  background: #fffdf1;
  color: #243528;
  font-size: 25px;
  font-weight: 1000;
  box-shadow: 0 8px 18px rgba(49, 91, 53, 0.1);
}

.level-grid button.locked {
  background: #dfe4d4;
  color: rgba(36, 53, 40, 0.46);
}

.level-grid button.completed {
  background: #bce58e;
}

.level-grid button.challenge {
  border-color: #f2b84b;
  background: #ffe29c;
}

.hidden {
  display: none !important;
}

.board-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 10px;
}

.tile-board {
  --cols: 4;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: clamp(8px, 2vw, 12px);
  align-content: center;
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 14px;
  border: 1px solid rgba(49, 91, 53, 0.16);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.72), rgba(255, 250, 217, 0.56)),
    rgba(255, 255, 255, 0.42);
}

.tile {
  position: relative;
  aspect-ratio: 1;
  min-height: 68px;
  border: 3px solid rgba(49, 91, 53, 0.18);
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #fffdf1;
  color: #243528;
  font-size: clamp(34px, 9vw, 62px);
  box-shadow: 0 10px 18px rgba(49, 91, 53, 0.12);
  transform: translateY(0) scale(1);
  transition: transform 0.14s ease, background 0.14s ease, opacity 0.18s ease;
}

.tile:active,
.tile.selected {
  transform: translateY(-3px) scale(1.03);
  border-color: #f2b84b;
  background: #fff0b8;
}

.tile.matched {
  pointer-events: none;
  opacity: 0;
  transform: scale(0.86);
}

.tile.wrong {
  animation: shake 0.22s ease;
}

.message {
  min-height: 42px;
  display: grid;
  place-items: center;
  color: #315b35;
  font-size: clamp(17px, 4vw, 24px);
  font-weight: 1000;
  text-align: center;
}

.result-panel,
.loading-panel {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  background: rgba(36, 53, 40, 0.42);
  backdrop-filter: blur(8px);
}

.result-card,
.loading-card {
  width: min(92vw, 460px);
  display: grid;
  gap: 12px;
  padding: 20px;
  border: 1px solid rgba(49, 91, 53, 0.16);
  border-radius: 8px;
  background: #fffdf1;
  color: #243528;
  box-shadow: 0 28px 70px rgba(36, 53, 40, 0.26);
  animation: pop 0.22s ease both;
}

.result-card h2 {
  margin: 0;
  font-size: clamp(30px, 8vw, 44px);
  line-height: 1;
}

.stars {
  color: #f2b84b;
  font-size: clamp(38px, 12vw, 58px);
  letter-spacing: 0;
}

.result-card p {
  margin: 0;
  color: rgba(36, 53, 40, 0.74);
  font-size: 18px;
  font-weight: 900;
  line-height: 1.45;
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.loading-card div {
  height: 10px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(49, 91, 53, 0.12);
}

.loading-card i {
  display: block;
  width: 100%;
  height: 100%;
  background: #77bb56;
}

@keyframes pop {
  from { transform: translateY(16px) scale(0.96); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  35% { transform: translateX(-5px); }
  70% { transform: translateX(5px); }
}

@media (max-width: 520px) {
  .garden-game {
    gap: 9px;
    padding-inline: 9px;
  }

  .topbar {
    grid-template-columns: 44px minmax(0, 1fr) 126px;
    gap: 8px;
  }

  .home-link {
    min-height: 44px;
  }

  .statusbar div {
    min-height: 58px;
    padding: 8px;
  }

  .level-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 7px;
  }

  .level-grid button {
    min-height: 54px;
    font-size: 21px;
  }

  .tile-board {
    padding: 9px;
    gap: 7px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tile,
  .result-card,
  .loading-card {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
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;
}
