* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: linear-gradient(135deg, #FFF8E1, #FFECB3);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.game-container {
  text-align: center;
  padding: 20px;
  max-width: 600px;
  width: 100%;
}

h1 {
  font-size: 2rem;
  margin-bottom: 12px;
  color: #4E342E;
}

/* ---- Controls ---- */

.controls {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.diff-btn {
  padding: 8px 18px;
  border: 2px solid #FF8C42;
  background: #fff;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  color: #E65100;
  transition: all 0.2s;
}

.diff-btn:hover {
  background: #FFF3E0;
}

.diff-btn.active {
  background: #FF8C42;
  color: #fff;
}

/* ---- Game info bar ---- */

.game-info {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
  font-size: 1rem;
  color: #5D4037;
}

#status {
  font-weight: 600;
}

#timer {
  font-variant-numeric: tabular-nums;
  background: #FFF3E0;
  padding: 4px 10px;
  border-radius: 10px;
  font-weight: 600;
}

#reset-btn {
  padding: 6px 14px;
  border: 2px solid #BCAAA4;
  background: #fff;
  border-radius: 16px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: #5D4037;
  transition: all 0.2s;
}

#reset-btn:hover {
  background: #EFEBE9;
}

/* ---- Grid ---- */

#grid-container {
  display: inline-grid;
  gap: 1px;
  background: #C9BDB5;
  border: 1px solid #C9BDB5;
  border-radius: 8px;
  padding: 0;
  user-select: none;
  touch-action: none;
  -webkit-user-select: none;
  position: relative;
  overflow: hidden;
}

#path-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.cell {
  width: var(--cell-size, 60px);
  height: var(--cell-size, 60px);
  background: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell-size, 60px) * 0.38);
  font-weight: 700;
  border-radius: 0;
  cursor: pointer;
  transition: background-color 0.12s ease;
  position: relative;
  color: transparent;
}

.cell.clue {
  background: #FFF8E1;
  color: #BF360C;
}

.cell.visited {
  background: #E8A45A;
  transition: background-color 0.08s ease;
}


.cell.valid-next {
  background: #FFF3E0;
}

.cell.invalid-flash {
  animation: flash-red 0.3s;
}

@keyframes flash-red {
  0%, 100% { background: inherit; }
  50% { background: #FFCDD2; }
}

/* ---- Win overlay ---- */

#win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fade-in 0.3s;
}

#win-overlay.hidden {
  display: none;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.win-message {
  background: #fff;
  padding: 36px 48px;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  text-align: center;
}

.win-message h2 {
  font-size: 1.8rem;
  color: #4E342E;
  margin-bottom: 8px;
}

.win-message p {
  font-size: 1.1rem;
  color: #795548;
  margin-bottom: 20px;
}

#next-btn {
  padding: 10px 28px;
  border: none;
  background: #FF8C42;
  color: #fff;
  border-radius: 24px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 700;
  transition: background 0.2s;
}

#next-btn:hover {
  background: #F57C00;
}

/* ---- Instructions ---- */

.instructions {
  margin-top: 16px;
  font-size: 0.85rem;
  color: #8D6E63;
  line-height: 1.5;
}

/* ---- Confetti ---- */

.confetti {
  position: fixed;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  z-index: 200;
  pointer-events: none;
  animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
  0% {
    opacity: 1;
    transform: translateY(0) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translateY(100vh) rotate(720deg);
  }
}

/* ---- Responsive ---- */

@media (max-width: 480px) {
  .game-container {
    padding: 12px;
  }

  h1 {
    font-size: 1.5rem;
  }

  .game-info {
    gap: 8px;
    font-size: 0.85rem;
  }

  .controls {
    gap: 4px;
  }

  .diff-btn {
    padding: 6px 12px;
    font-size: 0.8rem;
  }
}
