:root {
  --bg-top: #fff7da;
  --bg-bottom: #ffd6b8;
  --panel: rgba(255, 250, 242, 0.92);
  --panel-border: rgba(148, 87, 45, 0.18);
  --text: #4f2b1f;
  --muted: #805846;
  --shadow: rgba(128, 72, 39, 0.18);
  --accent: #d8613c;
  --accent-dark: #b84a28;
  --grid-bg: rgba(255, 244, 230, 0.95);
  --selected: #2f7fff;
  --empty: rgba(255, 255, 255, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.75), transparent 32%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

.app {
  width: min(1100px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 32px;
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(320px, 1fr);
  gap: 24px;
  align-items: start;
}

.panel,
.board-wrap {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  box-shadow: 0 18px 40px var(--shadow);
}

.panel {
  padding: 24px;
}

.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.78rem;
  color: var(--muted);
}

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

.intro {
  margin: 14px 0 0;
  line-height: 1.5;
  color: var(--muted);
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 24px 0;
}

.stat-card,
.goal-card {
  padding: 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.7);
}

.goal-card {
  margin-bottom: 20px;
}

.stat-label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
}

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

.goal-label {
  margin-top: 12px;
}

.goal-text,
.goal-progress {
  margin: 8px 0 0;
}

.goal-text {
  line-height: 1.45;
}

.goal-progress {
  font-weight: 700;
  color: var(--accent-dark);
}

.actions {
  display: grid;
  gap: 12px;
}

button {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 14px 18px;
  font: inherit;
  font-weight: 700;
  color: #fff7f1;
  background: linear-gradient(180deg, var(--accent), var(--accent-dark));
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
  box-shadow: 0 8px 18px rgba(184, 74, 40, 0.25);
}

button:hover {
  transform: translateY(-1px);
}

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

.message {
  min-height: 44px;
  margin: 0;
  line-height: 1.45;
  color: var(--muted);
}

.board-wrap {
  padding: 20px;
  display: flex;
  justify-content: center;
  position: relative;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 6px;
  width: min(76vw, 560px);
  aspect-ratio: 1;
  padding: 12px;
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0.18)),
    var(--grid-bg);
  overflow: hidden;
}

.tile {
  appearance: none;
  border: 0;
  border-radius: 0;
  position: relative;
  padding: 0;
  background: transparent;
  box-shadow: none;
  color: inherit;
  cursor: pointer;
  isolation: isolate;
  transition: transform 150ms ease, filter 150ms ease, outline-color 150ms ease, opacity 150ms ease;
}

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

.tile:active {
  transform: translateY(0) scale(1);
}

.tile.selected {
  animation: selectedPulse 800ms ease-in-out infinite;
}

.tile.clearing {
  z-index: 2;
  animation: clearBurst 220ms cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

.tile.invalid {
  animation: invalidShake 200ms ease;
}

.tile.swap {
  animation: swapSlide 190ms cubic-bezier(0.25, 0.9, 0.3, 1) both;
}

.tile.drop {
  animation: tileDrop 320ms cubic-bezier(0.16, 0.84, 0.24, 1) both;
  animation-delay: var(--drop-delay, 0ms);
}

.tile::before {
  display: none;
}

.tile::after {
  display: none;
}

.tile.empty {
  pointer-events: none;
  opacity: 0;
}

.tile.hint .tile-art {
  animation: hintPulse 1200ms ease-in-out infinite;
}

.tile-art {
  position: absolute;
  inset: 4%;
  z-index: 1;
  display: block;
  width: 92%;
  height: 92%;
  margin: auto;
  object-fit: contain;
  filter: drop-shadow(0 6px 10px rgba(100, 57, 36, 0.1));
  user-select: none;
  -webkit-user-drag: none;
}

.tile.special-line-row .tile-art,
.tile.special-line-col .tile-art,
.tile.special-bomb .tile-art,
.tile.special-rainbow .tile-art {
  filter:
    drop-shadow(0 0 10px rgba(255, 255, 255, 0.75))
    drop-shadow(0 6px 12px rgba(216, 97, 60, 0.22));
}

.tile.special-line-row::before,
.tile.special-line-col::before,
.tile.special-bomb::before,
.tile.special-rainbow::before {
  content: "";
  position: absolute;
  inset: 12%;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(255,255,255,0.65), transparent 70%);
  pointer-events: none;
}

.tile.special-line-row::after,
.tile.special-line-col::after,
.tile.special-bomb::after,
.tile.special-rainbow::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.tile.special-line-row::after {
  left: 14%;
  right: 14%;
  top: 50%;
  height: 4px;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 8px rgba(255,255,255,0.8);
}

.tile.special-line-col::after {
  top: 14%;
  bottom: 14%;
  left: 50%;
  width: 4px;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 8px rgba(255,255,255,0.8);
}

.tile.special-bomb::after {
  inset: 22%;
  border: 3px dashed rgba(255, 255, 255, 0.9);
  border-radius: 50%;
}

.tile.special-rainbow::after {
  inset: 16%;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.9);
  box-shadow:
    0 0 0 4px rgba(255, 190, 59, 0.55),
    0 0 0 8px rgba(111, 174, 255, 0.35);
}

.floating-feedback {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.feedback-badge {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 250, 242, 0.94);
  color: var(--accent-dark);
  font-weight: 800;
  box-shadow: 0 10px 24px rgba(100, 57, 36, 0.16);
  animation: feedbackRise 900ms ease forwards;
  white-space: nowrap;
}

@keyframes selectedPulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.06);
  }
}

@keyframes hintPulse {
  0%,
  100% {
    transform: scale(1);
    filter: drop-shadow(0 6px 10px rgba(100, 57, 36, 0.1));
  }
  50% {
    transform: scale(1.08);
    filter:
      drop-shadow(0 0 8px rgba(255, 231, 140, 0.95))
      drop-shadow(0 6px 10px rgba(100, 57, 36, 0.1));
  }
}

@keyframes invalidShake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-6px);
  }
  40% {
    transform: translateX(6px);
  }
  60% {
    transform: translateX(-4px);
  }
  80% {
    transform: translateX(4px);
  }
}

@keyframes swapSlide {
  0% {
    transform: translate(
      calc(var(--swap-x, 0) * -100%),
      calc(var(--swap-y, 0) * -100%)
    ) scale(0.96);
    filter: brightness(0.95);
  }
  70% {
    transform: translate(
      calc(var(--swap-x, 0) * 6%),
      calc(var(--swap-y, 0) * 6%)
    ) scale(1.05);
  }
  100% {
    transform: translate(0, 0) scale(1);
    filter: brightness(1);
  }
}

@keyframes tileDrop {
  0% {
    transform: translateY(calc(var(--drop-distance, 1) * -72px)) scale(0.94);
    opacity: 0;
    filter: saturate(1.15);
  }
  68% {
    transform: translateY(4px) scale(1.02);
    opacity: 1;
  }
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
    filter: saturate(1);
  }
}

@keyframes clearBurst {
  0% {
    transform: scale(1);
    opacity: 1;
    filter: brightness(1);
  }
  45% {
    transform: scale(1.12);
    opacity: 1;
    filter: brightness(1.45);
  }
  100% {
    transform: scale(0.2);
    opacity: 0;
    filter: brightness(1.8);
  }
}

@keyframes feedbackRise {
  0% {
    opacity: 0;
    transform: translate(-50%, -30%) scale(0.88);
  }
  18% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -170%) scale(1.04);
  }
}

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

  .board {
    width: min(92vw, 560px);
  }
}
