* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: #1d2330;
  color: #fff8e8;
  font-family: Inter, "Noto Sans TC", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overscroll-behavior: none;
}

body {
  min-height: 100svh;
}

button,
a,
select {
  font: inherit;
}

.snack-game {
  min-height: 100svh;
  padding: max(12px, env(safe-area-inset-top)) 12px max(14px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  background:
    radial-gradient(circle at 18% 14%, rgba(255, 213, 94, 0.28), transparent 24%),
    radial-gradient(circle at 86% 20%, rgba(104, 211, 145, 0.22), transparent 26%),
    linear-gradient(160deg, #222839 0%, #353048 52%, #553849 100%);
}

.topbar,
.hud,
.menu-panel,
.play-panel,
.result-card {
  width: min(720px, 100%);
  margin: 0 auto;
}

.topbar {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.home-link,
button {
  border: 0;
  border-radius: 8px;
  min-height: 44px;
  cursor: pointer;
}

.home-link {
  display: grid;
  place-items: center;
  text-decoration: none;
  color: #352314;
  background: #ffe28a;
  font-size: 1.5rem;
  font-weight: 900;
}

.topbar p,
.topbar h1 {
  margin: 0;
}

.topbar p {
  color: #f8d47d;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.topbar h1 {
  font-size: clamp(1.35rem, 7vw, 2.25rem);
  line-height: 1;
}

.language-picker {
  display: grid;
  gap: 4px;
  color: #f8e8c2;
  font-size: 0.72rem;
  font-weight: 800;
}

.language-picker select {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  padding: 0 8px;
  color: #22170f;
  background: #fff7dc;
  font-weight: 800;
}

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

.hud div,
.score-line {
  min-height: 54px;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(16, 20, 30, 0.62);
  display: grid;
  gap: 2px;
  place-items: center;
}

.hud span,
.score-line span {
  color: #f1cf8b;
  font-size: 0.72rem;
  font-weight: 800;
}

.hud strong,
.score-line strong {
  font-size: 1.35rem;
}

.menu-panel,
.result-card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
  animation: snack-panel-pop 0.4s cubic-bezier(0.17, 0.9, 0.28, 1.2);
}

.menu-panel img {
  width: min(260px, 68%);
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  align-self: center;
  border: 3px solid rgba(255, 255, 255, 0.28);
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.25);
}

.menu-panel strong,
.result-card strong {
  font-size: clamp(1.35rem, 7vw, 2rem);
  line-height: 1.05;
  text-align: center;
}

.menu-panel span,
.result-card span,
.hint {
  color: #f5e0b1;
  font-weight: 700;
  text-align: center;
  line-height: 1.35;
}

.stage-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.stage-card {
  min-width: 0;
  min-height: 88px;
  padding: 8px;
  display: grid;
  gap: 2px;
  place-items: center;
  color: #2b1d12;
  background: linear-gradient(180deg, #ffe899, #ffbd57);
  box-shadow: 0 4px 0 #b56a28;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

.stage-card:active {
  transform: translateY(3px) scale(0.98);
  box-shadow: 0 1px 0 #b56a28;
}

.stage-card strong {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff8e8;
  background: #d95b51;
  font-size: 1rem;
}

.stage-card span {
  color: #322113;
  font-size: 0.78rem;
  font-weight: 900;
}

.stage-card em {
  color: rgba(45, 29, 18, 0.72);
  font-size: 0.68rem;
  font-style: normal;
  font-weight: 800;
}

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

button {
  padding: 0 18px;
  color: #2b1d12;
  background: #ffd95f;
  font-weight: 900;
  box-shadow: 0 4px 0 #b56a28;
}

button:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #b56a28;
}

.play-panel {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.score-line {
  width: min(240px, 100%);
  justify-self: center;
}

.board {
  position: relative;
  width: min(94vw, 620px, 72svh);
  aspect-ratio: 1;
  margin: 0 auto;
  padding: 8px;
  border-radius: 8px;
  background: rgba(18, 21, 31, 0.76);
  border: 2px solid rgba(255, 255, 255, 0.18);
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  touch-action: none;
  overflow: hidden;
  contain: layout paint size;
}

.tile {
  position: relative;
  z-index: 1;
  min-width: 0;
  aspect-ratio: 1;
  border: 0;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: clamp(0.95rem, 5.5vw, 2.15rem);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
  box-shadow: inset 0 -5px rgba(0, 0, 0, 0.18), 0 4px 8px rgba(0, 0, 0, 0.16);
  transform: translateZ(0);
  will-change: transform, opacity, filter;
  transition: transform 150ms ease, filter 150ms ease, opacity 180ms ease;
}

.tile.dropping {
  animation: snack-drop-move 0.34s cubic-bezier(0.2, 0.86, 0.25, 1.08) both;
}

.tile.selected {
  outline: 4px solid rgba(255, 255, 255, 0.9);
  transform: scale(1.06);
}

.tile.matching {
  filter: brightness(1.45);
  opacity: 0.18;
  transform: scale(0.58) rotate(5deg);
}

.match-spark {
  position: absolute;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  margin: -15px 0 0 -15px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.96), rgba(255, 227, 111, 0.84) 46%, rgba(255, 116, 90, 0) 72%);
  color: #ffffff;
  font-size: 18px;
  font-weight: 1000;
  text-shadow: 0 1px 4px rgba(118, 62, 12, 0.55);
  pointer-events: none;
  animation: snack-spark-pop 0.48s ease-out both;
}

.score-pop {
  animation: snack-score-pop 0.28s ease;
}

.tile-0 {
  background: linear-gradient(180deg, #ff8aa0, #e84a68);
}

.tile-1 {
  background: linear-gradient(180deg, #ffe782, #f2a83c);
}

.tile-2 {
  background: linear-gradient(180deg, #8ff0c0, #31b779);
}

.tile-3 {
  background: linear-gradient(180deg, #a7d4ff, #4a8fe7);
}

.tile-4 {
  background: linear-gradient(180deg, #d7b6ff, #8856d9);
}

.tile-5 {
  background: linear-gradient(180deg, #ffd7a8, #d87a3b);
}

.result-card {
  padding: 18px;
  border-radius: 8px;
  background: rgba(18, 21, 31, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 22px 54px rgba(0, 0, 0, 0.34);
}

.result-stars {
  min-height: 42px;
  color: #ffe36f;
  font-size: 2rem;
  letter-spacing: 4px;
  text-align: center;
  text-shadow: 0 0 16px rgba(255, 227, 111, 0.7);
}

.result-card a {
  min-height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #fff4c8;
  text-decoration: none;
  font-weight: 900;
  background: rgba(255, 255, 255, 0.14);
}

.loading-panel {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: #202535;
}

.loading-card {
  width: min(360px, 100%);
  display: grid;
  gap: 12px;
  text-align: center;
  animation: snack-panel-pop 0.35s ease;
}

.loading-card strong {
  font-size: 1.4rem;
}

.loading-card div {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
}

.loading-card i {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #ffdf62, #6fe3a8);
}

.hidden {
  display: none !important;
}

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

@keyframes snack-tile-appear {
  from {
    opacity: 0;
    transform: scale(0.82);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes snack-drop-move {
  from {
    opacity: 0.98;
    transform: translateY(var(--drop)) scale(0.98);
  }
  78% {
    transform: translateY(4%) scale(1.02);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes snack-spark-pop {
  0% {
    opacity: 0;
    transform: scale(0.45);
  }
  38% {
    opacity: 1;
    transform: scale(1.2);
  }
  100% {
    opacity: 0;
    transform: translateY(-26px) scale(0.72);
  }
}

@keyframes snack-score-pop {
  0% {
    transform: scale(1);
    color: #fff8e8;
  }
  55% {
    transform: scale(1.26);
    color: #ffe36f;
    text-shadow: 0 0 14px rgba(255, 227, 111, 0.85);
  }
  100% {
    transform: scale(1);
    color: #fff8e8;
  }
}

@media (prefers-reduced-motion: reduce) {
  .menu-panel,
  .result-card,
  .loading-card,
  .tile,
  .match-spark,
  .score-pop {
    animation: none;
  }
}

@media (max-height: 760px) {
  .menu-panel img {
    display: none;
  }

  .stage-card {
    min-height: 74px;
  }
}

@media (max-width: 390px) {
  .stage-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .board {
    gap: 4px;
    padding: 6px;
  }
}
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;
}
