* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: radial-gradient(circle at 50% 0%, #6b4226 0%, #3a2417 55%, #221208 100%);
  color: #fff8ec;
  padding: 16px;
}

#game-wrap {
  width: 100%;
  max-width: 560px;
  background: linear-gradient(160deg, #8a5a34, #6b3f22);
  border-radius: 24px;
  padding: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5), inset 0 0 0 4px rgba(255,255,255,0.08);
}

#top-bar h1 {
  text-align: center;
  margin: 4px 0 12px;
  font-size: 1.6rem;
  text-shadow: 0 2px 4px rgba(0,0,0,0.4);
}

#hud {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}

#objectives-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

#objectives-row:empty {
  margin-bottom: 0;
}

.objective-box {
  background: rgba(0,0,0,0.22);
  border-radius: 12px;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 700;
}

.objective-box .obj-icon {
  width: 1.3em;
  height: 1.3em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.objective-box .obj-icon svg {
  width: 100%;
  height: 100%;
}

.objective-box.complete {
  background: rgba(76, 175, 80, 0.35);
}

.hud-box {
  background: rgba(0,0,0,0.25);
  border-radius: 12px;
  padding: 6px 4px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.hud-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.75;
}

.hud-box span:last-child {
  font-size: 1.1rem;
  font-weight: 700;
}

#progress-bar-wrap {
  height: 14px;
  background: rgba(0,0,0,0.3);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 14px;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.4);
}

#progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ffd54f, #ff9800);
  transition: width 0.4s ease;
}

#board {
  --size: 8;
  display: grid;
  grid-template-columns: repeat(var(--size), 1fr);
  grid-template-rows: repeat(var(--size), 1fr);
  gap: 4px;
  background: rgba(0,0,0,0.3);
  border-radius: 16px;
  padding: 8px;
  aspect-ratio: 1 / 1;
  position: relative;
  touch-action: none;
  user-select: none;
}

.tile {
  position: relative;
  border-radius: 10px;
  background: rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.1rem, 4.2vw, 1.8rem);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  will-change: transform;
}

.tile:hover {
  transform: scale(1.06);
}

.tile svg {
  width: 78%;
  height: 78%;
  display: block;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.35));
}

#title-capy svg,
.toast-capy svg {
  width: 1.3em;
  height: 1.3em;
  vertical-align: -0.3em;
}

.tile.selected {
  box-shadow: 0 0 0 3px #fff59d, 0 0 14px 3px #ffeb3b;
  transform: scale(1.1);
  z-index: 3;
}

.tile.falling {
  animation: dropIn 0.35s ease;
}

@keyframes dropIn {
  from { transform: translateY(-110%); opacity: 0.4; }
  to { transform: translateY(0); opacity: 1; }
}

.tile.matched {
  animation: pop 0.28s ease forwards;
  z-index: 2;
}

@keyframes pop {
  0% { transform: scale(1); opacity: 1; }
  60% { transform: scale(1.35) rotate(15deg); opacity: 0.8; }
  100% { transform: scale(0.1) rotate(45deg); opacity: 0; }
}

.tile.swap-a, .tile.swap-b {
  z-index: 4;
}

.tile.special-stripe-h::after,
.tile.special-stripe-v::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 10px;
  box-shadow: 0 0 0 3px #90caf9, 0 0 10px 2px #64b5f6;
  pointer-events: none;
}

.tile.special-wrapped::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 10px;
  box-shadow: 0 0 0 3px #ce93d8, 0 0 12px 3px #ba68c8;
  pointer-events: none;
}

.tile.special-bomb::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 10px;
  box-shadow: 0 0 0 3px #212121, 0 0 16px 4px #ffeb3b;
  pointer-events: none;
}

/* Jelly: a colored layer stuck to the board cell, under whatever candy sits there */
.tile.jelly-1 {
  background: rgba(100, 181, 246, 0.35);
  box-shadow: inset 0 0 0 2px rgba(100, 181, 246, 0.55);
}

.tile.jelly-2 {
  background: rgba(30, 136, 229, 0.55);
  box-shadow: inset 0 0 0 3px rgba(30, 136, 229, 0.75);
}

/* Chocolate blocker: fixed in place, no candy, spreads if not cleared adjacent */
.tile.is-chocolate {
  background: linear-gradient(160deg, #5d4037, #3e2723);
  cursor: not-allowed;
  box-shadow: inset 0 0 0 2px rgba(0,0,0,0.4);
}

.tile.is-chocolate:hover {
  transform: none;
}

/* Licorice lock: candy is caged until a match clears next to it */
.tile.is-locked {
  cursor: not-allowed;
}

.tile.is-locked::before {
  content: "🔒";
  position: absolute;
  inset: -2px;
  border-radius: 10px;
  background-image: repeating-linear-gradient(
    45deg,
    rgba(20, 10, 5, 0.55) 0 6px,
    rgba(60, 30, 15, 0.55) 6px 12px
  );
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  z-index: 3;
  pointer-events: none;
}

.tile.is-locked:hover {
  transform: none;
}

/* Ingredient: falls with gravity, delivered when it reaches the bottom row */
.tile.is-ingredient {
  background: rgba(255, 193, 7, 0.18);
}

#controls {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

#controls button {
  flex: 1;
  padding: 10px 8px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(160deg, #ffb74d, #f57c00);
  color: #402200;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  box-shadow: 0 4px 0 #b25800;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

#controls button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #b25800;
}

#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  transition: opacity 0.25s ease;
}

#overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

#overlay-card {
  background: linear-gradient(160deg, #fff3e0, #ffe0b2);
  color: #4e2600;
  border-radius: 20px;
  padding: 28px 32px;
  text-align: center;
  min-width: 260px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}

#overlay-card h2 {
  margin: 0 0 8px;
  font-size: 1.6rem;
}

#overlay-card button {
  margin-top: 14px;
  padding: 10px 24px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(160deg, #66bb6a, #388e3c);
  color: white;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 4px 0 #1b5e20;
}

#overlay-card button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #1b5e20;
}

#combo-toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.75);
  color: #ffeb3b;
  padding: 8px 18px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 60;
}

#combo-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(6px);
}

@media (max-width: 420px) {
  #top-bar h1 { font-size: 1.25rem; }
  .hud-box span:last-child { font-size: 0.95rem; }
}
