:root {
  --wood-dark: #3d1c08;
  --wood-mid: #6b3410;
  --wood-light: #8b4a1b;
  --gold: #d4a017;
  --gold-light: #f4c141;
  --gold-dark: #8a6410;
  --cream: #fff5e1;
  --red-deep: #8b0000;
  --red-bright: #c8102e;

  --cell-size: 42px;
  --gap: 2px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--cream);
  background:
    linear-gradient(170deg, rgba(0,0,0,0) 0%, rgba(0,0,0,0.35) 100%),
    repeating-linear-gradient(
      90deg,
      var(--wood-mid) 0,
      var(--wood-mid) 60px,
      var(--wood-light) 60px,
      var(--wood-light) 62px,
      var(--wood-mid) 62px,
      var(--wood-mid) 120px
    ),
    linear-gradient(180deg, var(--wood-light), var(--wood-dark));
}

#app { min-height: 100vh; }

.screen { max-width: 600px; margin: 0 auto; padding: 16px; }

/* ---------- Level map ------------------------------------------------ */
.screen-map { padding-bottom: 40px; }

.map-header {
  text-align: center;
  padding: 20px 0 28px;
}
.map-header h1 {
  margin: 0 0 6px;
  font-size: 40px;
  font-weight: 900;
  color: var(--gold-light);
  text-shadow: 0 3px 0 var(--gold-dark), 0 5px 0 var(--wood-dark), 0 6px 10px rgba(0,0,0,0.5);
  letter-spacing: 1px;
}
.map-header .subtitle {
  margin: 0;
  color: var(--cream);
  opacity: 0.85;
  font-size: 15px;
}

.level-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.level-node {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: linear-gradient(180deg, var(--cream), #f0dfb0);
  border: 3px solid var(--gold);
  border-radius: 18px;
  box-shadow: 0 4px 0 var(--gold-dark), 0 6px 14px rgba(0,0,0,0.35);
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease;
  color: #3d1c08;
}
.level-node:hover:not(.locked) { transform: translateY(-2px); box-shadow: 0 6px 0 var(--gold-dark), 0 8px 18px rgba(0,0,0,0.4); }
.level-node:active:not(.locked) { transform: translateY(2px); box-shadow: 0 2px 0 var(--gold-dark), 0 4px 10px rgba(0,0,0,0.3); }
.level-node.locked {
  filter: grayscale(0.7) brightness(0.6);
  cursor: not-allowed;
  border-color: #888;
  box-shadow: 0 4px 0 #444, 0 6px 14px rgba(0,0,0,0.35);
}
.level-node.current {
  animation: pulseGold 1.4s ease-in-out infinite;
}
@keyframes pulseGold {
  0%, 100% { box-shadow: 0 4px 0 var(--gold-dark), 0 0 0 0 rgba(244, 193, 65, 0.6); }
  50%      { box-shadow: 0 4px 0 var(--gold-dark), 0 0 0 10px rgba(244, 193, 65, 0); }
}

.level-num {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(180deg, var(--red-bright), var(--red-deep));
  color: #fff;
  font-weight: 900;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.3), 0 2px 4px rgba(0,0,0,0.3);
  border: 2px solid var(--gold);
  flex-shrink: 0;
}

.level-info { flex: 1; }
.level-name { font-weight: 800; font-size: 16px; }
.level-type { font-size: 12px; opacity: 0.75; margin-top: 2px; }

.level-stars { display: flex; gap: 2px; }
.star { font-size: 20px; color: #b08030; text-shadow: 0 1px 0 rgba(0,0,0,0.2); }
.star.on { color: var(--gold-light); text-shadow: 0 0 6px var(--gold-light); }

/* ---------- Game screen ---------------------------------------------- */
.screen-level { padding-bottom: 30px; }

.game-header {
  background: linear-gradient(180deg, var(--red-bright), var(--red-deep));
  border: 3px solid var(--gold);
  border-radius: 16px;
  padding: 12px 16px;
  box-shadow: 0 4px 0 var(--gold-dark), 0 6px 14px rgba(0,0,0,0.4);
  position: relative;
}
.back-btn {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0,0,0,0.2);
  color: var(--cream);
  border: 1px solid var(--gold);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}
.level-title {
  text-align: center;
  font-size: 18px;
  font-weight: 800;
  color: var(--gold-light);
  text-shadow: 0 2px 0 rgba(0,0,0,0.4);
  margin: 2px 0 8px;
}
.header-stats {
  display: flex;
  justify-content: space-around;
  gap: 12px;
  margin-bottom: 6px;
}
.stat-block {
  background: rgba(0,0,0,0.2);
  border-radius: 10px;
  padding: 4px 12px;
  text-align: center;
  min-width: 70px;
}
.stat-label { display: block; font-size: 10px; text-transform: uppercase; opacity: 0.8; letter-spacing: 1px; }
.stat-value { display: block; font-size: 20px; font-weight: 800; color: var(--gold-light); }
.objective {
  text-align: center;
  font-size: 13px;
  color: var(--cream);
  padding-top: 4px;
  font-weight: 600;
}

/* ---------- Board ----------------------------------------------------- */
.board-wrap {
  display: flex;
  justify-content: center;
  padding: 20px 0 16px;
}
.board {
  position: relative;
  padding: 10px;
  background:
    radial-gradient(ellipse at center, rgba(0,0,0,0.45), rgba(0,0,0,0.2)),
    linear-gradient(180deg, var(--wood-dark), #1a0a03);
  border: 3px solid var(--gold);
  border-radius: 14px;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.5), 0 6px 0 var(--gold-dark), 0 8px 16px rgba(0,0,0,0.5);
  display: inline-block;
}

.board-cells {
  position: relative;
  overflow: hidden;
  border-radius: 6px;
}

.tile {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--cell-size);
  height: var(--cell-size);
  cursor: pointer;
  transition: transform 320ms cubic-bezier(.34, 1.56, .64, 1);
  touch-action: none;
  will-change: transform;
}
.tile.empty { cursor: default; pointer-events: none; }

.tile .candy {
  position: absolute;
  inset: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 180ms cubic-bezier(.34, 1.56, .64, 1);
}
.candy svg { width: 100%; height: 100%; display: block; }

/* Selected — ring around the tile, plus a subtle pop of the candy */
.tile.selected {
  z-index: 5;
}
.tile.selected .candy {
  transform: scale(1.12);
  filter: drop-shadow(0 0 6px var(--gold-light));
}
.tile.selected::after {
  content: '';
  position: absolute;
  inset: -2px;
  border: 3px solid var(--gold-light);
  border-radius: 10px;
  pointer-events: none;
  box-shadow: 0 0 12px rgba(244, 193, 65, 0.7);
  animation: selectedPulse 1.2s ease-in-out infinite;
}
@keyframes selectedPulse {
  0%, 100% { box-shadow: 0 0 8px rgba(244, 193, 65, 0.6); }
  50%      { box-shadow: 0 0 18px rgba(244, 193, 65, 1); }
}

/* Exploding candy when cleared ---------------------------------------- */
@keyframes explodePop {
  0%   { transform: scale(1) rotate(0deg); opacity: 1; }
  30%  { transform: scale(1.35) rotate(8deg); opacity: 1; filter: brightness(2) saturate(2); }
  60%  { transform: scale(1.5) rotate(-5deg); opacity: 0.7; filter: brightness(2.5); }
  100% { transform: scale(0.2) rotate(0deg); opacity: 0; filter: brightness(3); }
}
.tile.exploding {
  pointer-events: none;
  z-index: 10;
}
.tile.exploding .candy {
  animation: explodePop 320ms ease-out forwards;
}
.tile.exploding::before {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.8) 0%, rgba(255,220,100,0.6) 30%, rgba(255,100,50,0) 70%);
  animation: explodeBurst 320ms ease-out forwards;
  pointer-events: none;
}
@keyframes explodeBurst {
  0%   { transform: scale(0.2); opacity: 0; }
  40%  { transform: scale(1); opacity: 0.9; }
  100% { transform: scale(1.8); opacity: 0; }
}

/* Just-created special — brief flash */
@keyframes specialFlash {
  0%   { filter: brightness(1); transform: scale(1); }
  30%  { filter: brightness(3) drop-shadow(0 0 8px #fff); transform: scale(1.3); }
  100% { filter: brightness(1); transform: scale(1); }
}
.tile.just-created .candy {
  animation: specialFlash 480ms ease-out;
}

/* Invalid shake (applied to .candy so it doesn't override positioning) */
@keyframes invalidShake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-5px); }
  40%      { transform: translateX(5px); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(3px); }
}
.tile.invalid .candy { animation: invalidShake 340ms ease; }

/* Jelly --------------------------------------------------------------- */
.jelly-bg {
  position: absolute;
  inset: 0;
  border-radius: 7px;
  pointer-events: none;
  z-index: 0;
}

/* Single jelly: light lavender glow with a dashed border */
.tile.jelly-1 .jelly-bg {
  background:
    linear-gradient(135deg, rgba(210, 140, 255, 0.55), rgba(150, 80, 220, 0.4));
  border: 2px dashed rgba(240, 200, 255, 0.9);
  box-shadow:
    inset 0 0 6px rgba(220, 160, 255, 0.55),
    0 0 4px rgba(200, 140, 255, 0.35);
}

/* Double jelly: deeper violet, solid double border, stronger glow */
.tile.jelly-2 .jelly-bg {
  background:
    linear-gradient(135deg, rgba(190, 70, 255, 0.72), rgba(90, 20, 180, 0.65));
  border: 3px double rgba(255, 210, 255, 0.95);
  box-shadow:
    inset 0 0 10px rgba(230, 160, 255, 0.85),
    inset 0 0 0 1px rgba(255, 210, 255, 0.6),
    0 0 6px rgba(180, 80, 255, 0.5);
}

/* Subtle pulse so players spot jelly cells easily */
.tile.jelly-1 .jelly-bg,
.tile.jelly-2 .jelly-bg {
  animation: jellyShimmer 2.2s ease-in-out infinite;
}
@keyframes jellyShimmer {
  0%, 100% { filter: brightness(1); }
  50%      { filter: brightness(1.25); }
}

/* Special overlays ---------------------------------------------------- */
.ovl-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Color-bomb replaces the candy entirely */
.tile[data-special="color-bomb"] > .candy { display: none; }

.ovl-bomb {
  animation: bombSpin 6s linear infinite;
}
@keyframes bombSpin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* Striped candies get a subtle shimmer on the bars */
.ovl-striped {
  animation: stripeShimmer 1.8s ease-in-out infinite;
}
@keyframes stripeShimmer {
  0%, 100% { filter: brightness(1) drop-shadow(0 0 0 rgba(255,255,255,0)); }
  50%      { filter: brightness(1.25) drop-shadow(0 0 4px rgba(255,255,255,0.9)); }
}

/* Wrapped — pulsing halo */
.ovl-wrap {
  animation: wrapPulse 1.5s ease-in-out infinite;
  transform-origin: center;
}
@keyframes wrapPulse {
  0%, 100% { transform: scale(0.96); filter: brightness(1); }
  50%      { transform: scale(1.06); filter: brightness(1.4); }
}
.ovl-wrap .wrap-dash-layer {
  animation: wrapSpin 4s linear infinite;
  transform-origin: 20px 20px;
}
@keyframes wrapSpin {
  from { stroke-dashoffset: 0; }
  to   { stroke-dashoffset: 32; }
}

/* Obstacles ------------------------------------------------------------ */
.tile.hole {
  pointer-events: none;
  cursor: default;
}
.tile.hole .ovl-svg {
  filter: drop-shadow(inset 0 0 8px #000);
}

.tile.blocker {
  pointer-events: none;
  cursor: not-allowed;
}
.blocker-svg { transition: filter 200ms ease; }

@keyframes blockerHit {
  0%   { transform: scale(1) rotate(0); }
  25%  { transform: scale(1.1) rotate(-4deg); filter: brightness(1.8); }
  50%  { transform: scale(0.92) rotate(3deg); }
  75%  { transform: scale(1.05) rotate(-2deg); }
  100% { transform: scale(1) rotate(0); }
}
.tile.blocker-hit .blocker-svg {
  animation: blockerHit 420ms ease;
}

/* Ingredient */

.ovl-ingredient {
  position: absolute;
  inset: 0;
}
.ovl-ingredient svg { width: 100%; height: 100%; }

/* ---------- Overlays (win/lose) -------------------------------------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 300ms ease;
}
.overlay.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.overlay .card {
  background: linear-gradient(180deg, var(--cream), #f0dfb0);
  color: var(--wood-dark);
  border: 4px solid var(--gold);
  border-radius: 20px;
  padding: 26px 32px;
  text-align: center;
  box-shadow: 0 0 40px rgba(244, 193, 65, 0.5), 0 10px 40px rgba(0,0,0,0.6);
  max-width: 360px;
  animation: popIn 400ms cubic-bezier(.34, 1.56, .64, 1);
}
@keyframes popIn {
  0%   { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
.overlay .card h2 {
  margin: 0 0 12px;
  font-size: 32px;
  color: var(--red-deep);
  text-shadow: 0 2px 0 var(--gold-light);
}
.overlay .card p { margin: 8px 0; font-size: 16px; font-weight: 600; }
.big-stars { font-size: 40px; margin: 14px 0; }
.big-star.on { color: var(--gold-light); text-shadow: 0 0 14px var(--gold-light); }
.big-star.off { color: #b08030; opacity: 0.4; }
.card-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 14px;
}
.card-buttons button {
  appearance: none;
  background: linear-gradient(180deg, var(--red-bright), var(--red-deep));
  color: var(--cream);
  border: 2px solid var(--gold);
  border-radius: 12px;
  padding: 10px 18px;
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--gold-dark);
}
.card-buttons button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--gold-dark); }

/* ---------- Responsive ----------------------------------------------- */
@media (max-width: 480px) {
  :root { --cell-size: 36px; }
  .map-header h1 { font-size: 32px; }
}
