:root {
  color-scheme: light;
  --ink: #403328;
  --muted: #8c7d70;
  --paper: #fffaf1;
  --panel: rgba(255, 255, 255, 0.82);
  --green: #47b56f;
  --green-dark: #207a49;
  --yellow: #ffd876;
  --orange: #ff9f5a;
  --pink: #ffb4bd;
  --blue: #8dd4ff;
  --shadow: 0 12px 30px rgba(87, 61, 37, 0.14);
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 216, 118, 0.38), transparent 28%),
    radial-gradient(circle at 82% 10%, rgba(141, 212, 255, 0.28), transparent 25%),
    linear-gradient(180deg, #fff7ea 0%, #f4fff6 100%);
  color: var(--ink);
  display: block;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

body.screen-pop .app {
  animation: screenPop 0.28s ease both;
}

body.screen-boom .app {
  animation: screenBoom 0.34s ease both;
}

button {
  border: 0;
  cursor: pointer;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

.app {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 0 auto;
  max-width: min(430px, 100vw);
  min-width: 0;
  min-height: 100vh;
  padding: max(18px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
  width: 100vw;
}

.hero {
  align-items: center;
  display: flex;
  justify-content: space-between;
  padding: 10px 2px 2px;
}

.sound-btn {
  align-self: flex-end;
  background: rgba(255, 255, 255, 0.76);
  border: 2px solid rgba(64, 51, 40, 0.08);
  border-radius: 999px;
  color: #6f4d34;
  font-size: 13px;
  font-weight: 900;
  margin-top: -8px;
  min-height: 34px;
  padding: 0 12px;
}

.eyebrow {
  color: var(--green-dark);
  font-size: 14px;
  font-weight: 800;
  margin: 0 0 4px;
}

h1 {
  font-size: 38px;
  letter-spacing: 0;
  line-height: 1;
  margin: 0;
}

.score-card,
.status-bar,
.tray-wrap,
.result-dialog {
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.score-card {
  border: 2px solid rgba(71, 181, 111, 0.18);
  border-radius: 18px;
  min-width: 74px;
  padding: 9px 12px;
  text-align: center;
}

.score-card span,
.status-bar span,
.tray-title small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.score-card strong,
.status-bar strong {
  display: block;
  font-size: 24px;
  line-height: 1.05;
}

.status-bar {
  align-items: center;
  border-radius: 18px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 10px;
  padding: 10px;
}

.status-bar div {
  background: rgba(255, 250, 241, 0.8);
  border-radius: 14px;
  padding: 8px 10px;
  text-align: center;
  min-width: 0;
}

#shuffleBtn,
.actions button,
.result-dialog button {
  border-radius: 999px;
  font-weight: 900;
  min-height: 44px;
  padding: 0 18px;
}

#shuffleBtn {
  min-width: 72px;
  padding-left: 14px;
  padding-right: 14px;
}

#shuffleBtn,
.ghost {
  background: #fff3dc;
  color: #86542e;
}

.primary,
.result-dialog button {
  background: var(--green);
  color: #fff;
}

.board-wrap {
  flex: 1;
  min-height: 420px;
  position: relative;
}

.board {
  height: 100%;
  min-height: 420px;
  position: relative;
  width: 100%;
}

.tile {
  align-items: center;
  animation: pop 0.26s ease both;
  background: #fffdf8;
  border: 2px solid rgba(64, 51, 40, 0.08);
  border-radius: 18px;
  box-shadow: 0 10px 20px rgba(64, 51, 40, 0.12);
  display: flex;
  height: 76px;
  justify-content: center;
  left: var(--x);
  position: absolute;
  top: var(--y);
  transform: translateZ(0);
  transition: transform 0.16s ease, box-shadow 0.16s ease, opacity 0.16s ease;
  width: 76px;
  will-change: transform;
}

.tile:active {
  transform: scale(0.94);
}

.tile.covered {
  cursor: default;
  filter: saturate(0.76);
  opacity: 0.62;
}

.tile.covered:active {
  transform: translateZ(0);
}

.tile svg {
  height: 58px;
  width: 58px;
}

.tile.in-tray {
  animation: none;
  box-shadow: none;
  height: 54px;
  position: static;
  width: 54px;
}

.tile.in-tray svg {
  height: 44px;
  width: 44px;
}

.tile.in-tray.clearing {
  animation: tileClear 0.36s cubic-bezier(0.13, 0.85, 0.24, 1) forwards;
  box-shadow: 0 0 0 5px rgba(255, 216, 118, 0.54), 0 12px 28px rgba(255, 126, 70, 0.28);
  position: relative;
  z-index: 8;
}

.tile.in-tray.clearing::after {
  animation: sparklePulse 0.36s ease forwards;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.95), rgba(255, 216, 118, 0.62) 48%, transparent 70%);
  border-radius: 999px;
  content: "";
  inset: -12px;
  pointer-events: none;
  position: absolute;
  z-index: -1;
}

.tile.removing {
  opacity: 0;
  transform: scale(0.4) rotate(8deg);
}

.tray-wrap {
  border-radius: 22px;
  padding: 12px;
}

.tray-title {
  align-items: baseline;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  margin-bottom: 10px;
}

.tray-title small {
  line-height: 1.2;
  text-align: right;
}

.tray-title span {
  font-size: 17px;
  font-weight: 900;
}

.tray {
  display: grid;
  gap: clamp(4px, 1.4vw, 7px);
  grid-template-columns: repeat(7, 1fr);
  min-height: 62px;
}

.slot {
  align-items: center;
  background: rgba(255, 246, 232, 0.75);
  border: 2px dashed rgba(64, 51, 40, 0.12);
  border-radius: 16px;
  display: flex;
  justify-content: center;
  min-height: 58px;
  min-width: 0;
}

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

.toast {
  background: rgba(64, 51, 40, 0.9);
  border-radius: 999px;
  bottom: max(22px, env(safe-area-inset-bottom));
  color: #fff;
  font-size: 14px;
  left: 50%;
  opacity: 0;
  padding: 10px 16px;
  pointer-events: none;
  position: fixed;
  transform: translate(-50%, 10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 5;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.particle {
  animation: burst 0.86s cubic-bezier(0.12, 0.72, 0.18, 1) forwards;
  color: #ff8f3d;
  font-size: 24px;
  font-weight: 1000;
  left: 0;
  pointer-events: none;
  position: fixed;
  text-shadow: 0 2px 0 #fff7e8, 0 5px 12px rgba(78, 48, 22, 0.22);
  top: 0;
  transform: translate(-50%, -50%);
  z-index: 20;
}

.particle.boom {
  color: #ff4e39;
  font-size: 28px;
}

.fx-ring {
  animation: ringPop 0.58s ease-out forwards;
  border: 5px solid rgba(255, 155, 68, 0.78);
  border-radius: 999px;
  height: 44px;
  left: 0;
  pointer-events: none;
  position: fixed;
  top: 0;
  transform: translate(-50%, -50%) scale(0.4);
  width: 44px;
  z-index: 19;
}

.fx-ring.boom {
  border-color: rgba(255, 73, 49, 0.82);
  height: 58px;
  width: 58px;
}

.fx-text {
  animation: fxText 0.72s cubic-bezier(0.15, 0.9, 0.2, 1) forwards;
  color: #ff743d;
  font-size: 34px;
  font-weight: 1000;
  left: 50%;
  letter-spacing: 0;
  pointer-events: none;
  position: fixed;
  text-shadow: 0 4px 0 #fff4dc, 0 12px 28px rgba(80, 45, 18, 0.22);
  top: 44%;
  transform: translate(-50%, -50%) scale(0.72) rotate(-4deg);
  white-space: nowrap;
  z-index: 21;
}

.fx-text.boom {
  color: #ff3d32;
  font-size: 38px;
}

.result-dialog {
  border: 0;
  border-radius: 26px;
  color: var(--ink);
  max-width: min(86vw, 360px);
  padding: 24px 22px;
  text-align: center;
}

.result-dialog::backdrop {
  background: rgba(64, 51, 40, 0.32);
}

.result-dialog h2 {
  font-size: 28px;
  margin: 8px 0;
}

.result-dialog p {
  color: var(--muted);
  margin: 0 0 18px;
}

.result-mascot svg {
  height: 92px;
  width: 92px;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: scale(0.72) translateY(8px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes screenPop {
  0% {
    transform: scale(1);
  }

  45% {
    transform: scale(1.012);
  }

  100% {
    transform: scale(1);
  }
}

@keyframes screenBoom {
  0%,
  100% {
    transform: translateX(0);
  }

  18% {
    transform: translateX(-5px) rotate(-0.4deg);
  }

  36% {
    transform: translateX(5px) rotate(0.4deg);
  }

  54% {
    transform: translateX(-3px) rotate(-0.2deg);
  }

  72% {
    transform: translateX(3px) rotate(0.2deg);
  }
}

@keyframes burst {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.6) rotate(0deg);
  }

  70% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.45) rotate(28deg);
  }
}

@keyframes tileClear {
  0% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }

  45% {
    opacity: 1;
    transform: scale(1.28) rotate(-8deg) translateY(-8px);
  }

  100% {
    opacity: 0;
    transform: scale(0.18) rotate(16deg) translateY(-24px);
  }
}

@keyframes sparklePulse {
  0% {
    opacity: 0;
    transform: scale(0.5);
  }

  45% {
    opacity: 1;
    transform: scale(1.1);
  }

  100% {
    opacity: 0;
    transform: scale(1.55);
  }
}

@keyframes ringPop {
  0% {
    opacity: 0.95;
    transform: translate(-50%, -50%) scale(0.35);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(3.7);
  }
}

@keyframes fxText {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.52) rotate(-8deg);
  }

  22% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.16) rotate(-4deg);
  }

  78% {
    opacity: 1;
    transform: translate(-50%, -62%) scale(1) rotate(-2deg);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -82%) scale(0.8) rotate(3deg);
  }
}

@media (max-width: 380px) {
  .app {
    gap: 10px;
    padding-left: 12px;
    padding-right: 12px;
  }

  h1 {
    font-size: 32px;
  }

  .board-wrap,
  .board {
    min-height: 380px;
  }

  .tile {
    height: 66px;
    width: 66px;
  }

  .tile.in-tray {
    height: 44px;
    width: 44px;
  }

  .tile.in-tray svg {
    height: 36px;
    width: 36px;
  }

  .slot {
    border-radius: 13px;
    min-height: 48px;
  }
}

@media (max-width: 460px) {
  .app {
    padding-left: 12px;
    padding-right: 12px;
  }

  .tray-wrap {
    padding: 10px;
  }

  .tray-title {
    align-items: flex-start;
  }

  .tray-title small {
    font-size: 11px;
    max-width: 160px;
  }

  .slot {
    min-height: 48px;
  }

  .tile.in-tray {
    height: 44px;
    width: 44px;
  }

  .tile.in-tray svg {
    height: 36px;
    width: 36px;
  }
}
