:root {
  --bg-top: #f3efe4;
  --bg-bottom: #d8e3d1;
  --panel: rgba(255, 250, 240, 0.78);
  --panel-border: rgba(74, 88, 63, 0.12);
  --ink: #243127;
  --muted: #66715f;
  --accent: #c56a3d;
  --accent-strong: #a34721;
  --tile-top: #fff8ea;
  --tile-bottom: #f7e3ba;
  --tile-border: rgba(70, 51, 21, 0.15);
  --tile-shadow: 0 14px 28px rgba(80, 62, 38, 0.16);
  --selected: #ef8d32;
  --matched: #8ea67f;
  --hint: #3e7f68;
  --grid-gap: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Trebuchet MS", "PingFang SC", "Hiragino Sans GB", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.7), transparent 28%),
    radial-gradient(circle at right 18% top 22%, rgba(197, 106, 61, 0.15), transparent 18%),
    linear-gradient(160deg, var(--bg-top), var(--bg-bottom));
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: auto;
  border-radius: 999px;
  pointer-events: none;
  filter: blur(8px);
  opacity: 0.45;
}

body::before {
  width: 220px;
  height: 220px;
  left: -60px;
  bottom: 8vh;
  background: rgba(225, 180, 108, 0.26);
}

body::after {
  width: 280px;
  height: 280px;
  right: -90px;
  top: 10vh;
  background: rgba(108, 157, 126, 0.22);
}

.app {
  width: min(1100px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 32px 0 40px;
}

.hero,
.panel,
.board-shell {
  backdrop-filter: blur(14px);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: 0 18px 36px rgba(53, 67, 43, 0.1);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(280px, 0.9fr);
  gap: 20px;
  padding: 26px;
  border-radius: 28px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent-strong);
  font-size: 0.85rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.6rem, 5vw, 4.2rem);
  line-height: 0.95;
}

.subtitle {
  max-width: 44ch;
  margin: 14px 0 0;
  font-size: 1.03rem;
  line-height: 1.65;
  color: var(--muted);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  align-content: center;
}

.stat-card {
  padding: 18px 16px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(120, 117, 91, 0.12);
}

.stat-card span {
  display: block;
  font-size: 0.86rem;
  color: var(--muted);
}

.stat-card strong {
  display: block;
  margin-top: 10px;
  font-size: 1.65rem;
}

.panel {
  margin-top: 18px;
  padding: 18px 20px;
  border-radius: 24px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.controls button {
  appearance: none;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: #fff9f2;
  padding: 12px 20px;
  font-size: 0.98rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 20px rgba(163, 71, 33, 0.25);
  transition: transform 180ms ease, box-shadow 180ms ease, filter 180ms ease;
}

#soundToggleBtn {
  background: linear-gradient(180deg, #4d6a52, #324d37);
  box-shadow: 0 10px 20px rgba(50, 77, 55, 0.22);
}

#soundToggleBtn[aria-pressed="true"] {
  background: linear-gradient(180deg, #8d978a, #6f7b6d);
  box-shadow: 0 10px 20px rgba(78, 87, 75, 0.18);
}

.controls button:hover {
  transform: translateY(-1px);
  filter: brightness(1.02);
  box-shadow: 0 14px 24px rgba(163, 71, 33, 0.28);
}

.controls button:active {
  transform: translateY(1px);
}

.message {
  margin: 14px 2px 0;
  min-height: 1.6em;
  color: var(--muted);
}

.board-shell {
  position: relative;
  margin-top: 18px;
  padding: 20px;
  border-radius: 30px;
  overflow: hidden;
}

#pathCanvas,
.board {
  width: 100%;
}

#pathCanvas {
  position: absolute;
  inset: 20px;
  height: calc(100% - 40px);
  pointer-events: none;
  z-index: 1;
}

.board {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: var(--grid-gap);
}

.tile {
  position: relative;
  min-height: 70px;
  border: 1px solid var(--tile-border);
  border-radius: 20px;
  background: linear-gradient(180deg, var(--tile-top), var(--tile-bottom));
  box-shadow: var(--tile-shadow);
  cursor: pointer;
  transition:
    transform 100ms ease,
    box-shadow 100ms ease,
    border-color 100ms ease,
    opacity 100ms ease;
}

.tile::before {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.55);
}

.tile:hover {
  transform: translateY(-2px) scale(1.01);
}

.tile.selected {
  border-color: rgba(239, 141, 50, 0.9);
  box-shadow: 0 0 0 3px rgba(239, 141, 50, 0.18), var(--tile-shadow);
}

.tile.hint {
  border-color: rgba(62, 127, 104, 0.8);
  box-shadow: 0 0 0 3px rgba(62, 127, 104, 0.16), var(--tile-shadow);
}

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

.tile-face {
  display: grid;
  place-items: center;
  font-size: clamp(1.8rem, 3vw, 2.4rem);
}

.board.win {
  animation: board-pop 600ms ease;
}

@keyframes board-pop {
  0% {
    transform: scale(0.99);
  }
  45% {
    transform: scale(1.008);
  }
  100% {
    transform: scale(1);
  }
}

@media (max-width: 860px) {
  .hero {
    grid-template-columns: 1fr;
  }

  .stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .tile {
    min-height: 60px;
  }
}

@media (max-width: 620px) {
  .app {
    width: min(100vw - 20px, 100%);
    padding-top: 18px;
  }

  .hero,
  .panel,
  .board-shell {
    border-radius: 22px;
  }

  .hero {
    padding: 20px;
  }

  .stats {
    grid-template-columns: 1fr;
  }

  .board-shell {
    padding: 14px;
  }

  #pathCanvas {
    inset: 14px;
    height: calc(100% - 28px);
  }

  .board {
    gap: 8px;
  }

  .tile {
    min-height: 54px;
    border-radius: 16px;
  }
}
