:root {
  color-scheme: light;
  font-family:
    Inter, ui-rounded, "SF Pro Rounded", "SF Pro Display", system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #252233;
  --muted: #726a7f;
  --panel: rgba(255, 255, 255, 0.74);
  --panel-strong: rgba(255, 255, 255, 0.91);
  --line: rgba(74, 55, 92, 0.15);
  --berry: #e43f70;
  --mint: #2fae83;
  --sky: #39a6df;
  --gold: #f4b23b;
  --shadow: 0 12px 28px rgba(75, 51, 82, 0.16);
}

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

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

body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background:
    linear-gradient(145deg, rgba(246, 225, 255, 0.88), rgba(224, 248, 255, 0.78) 42%, rgba(255, 244, 206, 0.9)),
    radial-gradient(circle at 18% 18%, rgba(255, 255, 255, 0.9), transparent 30%),
    #fff7e7;
}

button {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  min-height: 44px;
  padding: 0 18px;
  box-shadow: 0 8px 18px rgba(67, 50, 77, 0.1);
  transition:
    transform 120ms cubic-bezier(0.2, 0.8, 0.2, 1),
    box-shadow 120ms ease,
    background-color 120ms ease;
}

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

button:disabled {
  opacity: 0.55;
}

button.armed {
  background: rgba(255, 239, 155, 0.95);
  box-shadow:
    0 8px 18px rgba(67, 50, 77, 0.1),
    0 0 0 3px rgba(244, 178, 59, 0.34);
}

.game-shell {
  width: 100%;
  max-width: 470px;
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    calc(env(safe-area-inset-top) + 8px)
    10px
    calc(env(safe-area-inset-bottom) + 10px);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 7px;
}

.topbar {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  align-items: center;
  gap: 7px;
}

.status-strip,
.goal-panel {
  min-width: 0;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.status-strip {
  min-width: 0;
  height: 44px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: center;
  padding: 6px 10px;
  text-align: center;
  box-shadow: 0 8px 18px rgba(67, 50, 77, 0.1);
}

.status-item {
  min-width: 0;
}

.status-item + .status-item {
  border-left: 1px solid var(--line);
}

.control-cluster {
  display: flex;
  align-items: center;
  justify-content: end;
  gap: 6px;
}

.icon-button {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 1.08rem;
  font-weight: 850;
  line-height: 1;
  white-space: nowrap;
  box-shadow: 0 5px 13px rgba(67, 50, 77, 0.08);
}

.status-item span {
  display: block;
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.status-item strong {
  display: block;
  margin-top: 1px;
  font-size: 1.12rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  transition: color 160ms ease;
}

.status-item.moves-warning strong {
  color: #b86b16;
}

.status-item.moves-danger strong {
  color: #d62f57;
}

.play-stage {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 0;
  display: grid;
  align-items: center;
  justify-items: center;
}

.board {
  --gap: 1px;
  width: min(100%, 460px, calc((100dvh - 152px) * 0.875));
  max-width: 100%;
  max-height: calc(100dvh - 152px);
  aspect-ratio: 7 / 8;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  gap: var(--gap);
  padding: 0;
  touch-action: none;
  user-select: none;
}

.cell {
  appearance: none;
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  overflow: visible;
  padding: 0;
  transition: none;
  will-change: transform;
}

.piece-travel,
.piece-select,
.piece-motion,
.piece-pulse {
  position: relative;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  transform-origin: 50% 54%;
}

.piece-travel {
  z-index: 1;
  transition: transform 170ms cubic-bezier(0.16, 0.86, 0.22, 1);
  will-change: transform, opacity;
}

.piece-select {
  will-change: auto;
}

.piece-motion {
  animation: gummy-idle 5200ms ease-in-out infinite;
  animation-delay: calc(var(--wiggle, 0) * -520ms);
  will-change: transform;
}

.cell img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  filter: drop-shadow(0 8px 7px rgba(45, 37, 49, 0.2));
  transition:
    opacity 150ms ease,
    filter 120ms ease;
  will-change: opacity, filter;
}

.sugar-layer {
  position: absolute;
  z-index: 2;
  inset: 5%;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.9);
  background:
    radial-gradient(circle at 32% 24%, rgba(255, 255, 255, 0.72) 0 10%, transparent 11%),
    radial-gradient(circle at 62% 70%, rgba(173, 229, 255, 0.18), transparent 42%),
    rgba(255, 255, 255, 0.08);
  box-shadow:
    inset 0 0 12px rgba(255, 255, 255, 0.78),
    inset 0 -7px 12px rgba(126, 211, 255, 0.16),
    0 0 10px rgba(183, 229, 255, 0.42);
  pointer-events: none;
}

.sugar-layer.double {
  inset: 2%;
  border-width: 3px;
  box-shadow:
    inset 0 0 14px rgba(255, 255, 255, 0.86),
    inset 0 -8px 14px rgba(126, 211, 255, 0.2),
    0 0 0 3px rgba(183, 229, 255, 0.2),
    0 0 14px rgba(126, 211, 255, 0.52);
}

.cell.selected .piece-travel {
  transform: scale(1.12);
}

.cell:active .piece-travel,
.cell.pressing .piece-travel {
  transform: scale(0.86);
}

.cell:active img,
.cell.pressing img {
  filter: drop-shadow(0 4px 4px rgba(45, 37, 49, 0.2));
}

.cell.selected {
  outline: 0;
}

.cell.selected img {
  filter:
    drop-shadow(0 9px 8px rgba(45, 37, 49, 0.2))
    drop-shadow(0 0 10px rgba(47, 174, 131, 0.6));
}

.cell.power-lineH img,
.cell.power-lineV img {
  filter:
    grayscale(1)
    saturate(0.18)
    brightness(1.18)
    contrast(1.08)
    drop-shadow(0 8px 7px rgba(45, 37, 49, 0.18))
    drop-shadow(0 0 9px rgba(232, 241, 255, 0.86))
    drop-shadow(0 0 18px rgba(176, 202, 235, 0.58));
}

.cell.powering .piece-pulse {
  animation: power-reveal 360ms cubic-bezier(0.14, 1, 0.28, 1);
}

.cell.powering.power-lineH img,
.cell.powering.power-lineV img {
  animation: silver-tint-reveal 360ms ease-out;
}

.cell.power-burst .piece-pulse {
  animation: golden-pulse 1400ms ease-in-out infinite;
}

.cell.power-burst img {
  filter:
    sepia(1)
    saturate(1.7)
    hue-rotate(345deg)
    brightness(1.18)
    contrast(1.04)
    drop-shadow(0 9px 8px rgba(45, 37, 49, 0.18))
    drop-shadow(0 0 10px rgba(255, 246, 174, 0.92))
    drop-shadow(0 0 22px rgba(244, 178, 59, 0.72));
}

.cell.powering.power-burst .piece-pulse {
  animation:
    power-reveal 360ms cubic-bezier(0.14, 1, 0.28, 1),
    golden-pulse 1400ms ease-in-out infinite 360ms;
}

.cell.powering.power-burst img {
  animation: gold-tint-reveal 420ms ease-out;
}

.cell.swapping img {
  filter:
    drop-shadow(0 12px 10px rgba(45, 37, 49, 0.22))
    drop-shadow(0 0 10px rgba(255, 255, 255, 0.72));
}

.cell.clearing .piece-travel {
  animation: gummy-clear 420ms cubic-bezier(0.14, 0.78, 0.18, 1) forwards;
}

.cell.invalid {
  animation: nudge 150ms ease-in-out 2;
}

.goal-panel {
  padding: 8px 9px 9px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  align-items: center;
  gap: 6px 8px;
}

.goal-summary {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.goal-title {
  min-width: 0;
}

.goal-title span {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  line-height: 1;
  text-transform: uppercase;
}

.goal-title p {
  margin: 0;
  color: var(--ink);
  font-size: 0.98rem;
  font-weight: 850;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.goal-counter {
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 4px;
  margin: 0;
  color: var(--ink);
  font-size: 0.96rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.goal-icon {
  width: 28px;
  height: 28px;
  margin: 0;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.62);
  box-shadow: inset 0 0 11px rgba(255, 255, 255, 0.8);
}

.goal-icon img {
  width: 130%;
  height: 130%;
  object-fit: contain;
  filter: drop-shadow(0 4px 4px rgba(45, 37, 49, 0.18));
}

.goal-icon.sugar::before {
  content: "";
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background:
    radial-gradient(circle at 38% 30%, rgba(255, 255, 255, 0.96), rgba(255, 241, 187, 0.78) 40%, rgba(248, 187, 88, 0.48));
  box-shadow:
    inset 0 0 10px rgba(255, 255, 255, 0.9),
    0 4px 7px rgba(130, 88, 29, 0.2);
}

.progress-track {
  grid-column: 1 / -1;
  height: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(48, 39, 57, 0.12);
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--berry), var(--gold) 48%, var(--mint));
  transition: width 220ms ease;
}

.celebration {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transform: scale(0.94);
  transition:
    opacity 170ms ease,
    transform 170ms cubic-bezier(0.14, 1.15, 0.36, 1);
}

.celebration.show {
  opacity: 1;
  transform: scale(1);
}

.celebration.game-over {
  pointer-events: auto;
}

.celebration-card {
  min-width: min(84vw, 320px);
  padding: 20px 22px 18px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.92), rgba(255, 245, 183, 0.88)),
    rgba(255, 255, 255, 0.9);
  box-shadow: 0 18px 38px rgba(58, 39, 66, 0.24);
  text-align: center;
}

.celebration-card span {
  display: block;
  color: var(--berry);
  font-size: 2.15rem;
  font-weight: 950;
  line-height: 1;
}

.celebration-card strong {
  display: block;
  margin-top: 8px;
  font-size: 1rem;
}

.star-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
}

.star-dot {
  width: 28px;
  height: 28px;
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 56%, 79% 91%, 50% 70%, 21% 91%, 32% 56%, 2% 35%, 39% 35%);
  background: rgba(128, 119, 139, 0.22);
}

.star-dot.active {
  background: linear-gradient(150deg, #fff7a8, var(--gold));
  filter: drop-shadow(0 4px 4px rgba(130, 88, 29, 0.22));
}

.retry-button {
  width: 100%;
  margin-top: 16px;
  background: rgba(255, 255, 255, 0.96);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 92px);
  width: max-content;
  max-width: min(86vw, 360px);
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(37, 34, 51, 0.9);
  color: white;
  font-weight: 900;
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
  box-shadow: 0 12px 28px rgba(40, 32, 49, 0.24);
  text-align: center;
}

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

@keyframes gummy-idle {
  0%,
  100% {
    transform: rotate(0deg);
  }

  25% {
    transform: rotate(-2.4deg);
  }

  50% {
    transform: rotate(1.3deg);
  }

  75% {
    transform: rotate(2.1deg);
  }
}

@keyframes golden-pulse {
  0%,
  100% {
    transform: scale(1);
    filter:
      sepia(1)
      saturate(1.7)
      hue-rotate(345deg)
      brightness(1.18)
      contrast(1.04)
      drop-shadow(0 9px 8px rgba(45, 37, 49, 0.18))
      drop-shadow(0 0 10px rgba(255, 246, 174, 0.92))
      drop-shadow(0 0 22px rgba(244, 178, 59, 0.72));
  }

  50% {
    transform: scale(1.045);
    filter:
      sepia(1)
      saturate(1.85)
      hue-rotate(345deg)
      brightness(1.26)
      contrast(1.06)
      drop-shadow(0 10px 9px rgba(45, 37, 49, 0.18))
      drop-shadow(0 0 14px rgba(255, 249, 188, 0.98))
      drop-shadow(0 0 28px rgba(244, 178, 59, 0.86));
  }
}

@keyframes power-reveal {
  0% {
    transform: scale(0.82);
  }

  62% {
    transform: scale(1.2);
  }

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

@keyframes silver-tint-reveal {
  0% {
    filter:
      saturate(1)
      brightness(1)
      drop-shadow(0 8px 7px rgba(45, 37, 49, 0.2));
  }

  100% {
    filter:
      grayscale(1)
      saturate(0.18)
      brightness(1.18)
      contrast(1.08)
      drop-shadow(0 8px 7px rgba(45, 37, 49, 0.18))
      drop-shadow(0 0 9px rgba(232, 241, 255, 0.86))
      drop-shadow(0 0 18px rgba(176, 202, 235, 0.58));
  }
}

@keyframes gold-tint-reveal {
  0% {
    filter:
      saturate(1)
      brightness(1)
      drop-shadow(0 8px 7px rgba(45, 37, 49, 0.2));
  }

  100% {
    filter:
      sepia(1)
      saturate(1.7)
      hue-rotate(345deg)
      brightness(1.18)
      contrast(1.04)
      drop-shadow(0 9px 8px rgba(45, 37, 49, 0.18))
      drop-shadow(0 0 10px rgba(255, 246, 174, 0.92))
      drop-shadow(0 0 22px rgba(244, 178, 59, 0.72));
  }
}

@keyframes gummy-clear {
  0% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
    filter:
      drop-shadow(0 8px 7px rgba(45, 37, 49, 0.18))
      drop-shadow(0 0 0 rgba(255, 255, 255, 0));
  }

  46% {
    opacity: 1;
    transform: scale(1.28) rotate(-4deg);
    filter:
      drop-shadow(0 10px 9px rgba(45, 37, 49, 0.16))
      drop-shadow(0 0 14px rgba(255, 255, 255, 0.95))
      drop-shadow(0 0 26px rgba(255, 215, 117, 0.58));
  }

  100% {
    opacity: 0;
    transform: scale(1.72) rotate(8deg);
    filter:
      drop-shadow(0 8px 7px rgba(45, 37, 49, 0))
      drop-shadow(0 0 24px rgba(255, 255, 255, 0.52))
      drop-shadow(0 0 40px rgba(255, 215, 117, 0.28));
  }
}

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

  33% {
    transform: translateX(-4px);
  }

  66% {
    transform: translateX(4px);
  }
}

@media (max-height: 700px) {
  .game-shell {
    gap: 6px;
  }

  .status-strip,
  .icon-button {
    height: 40px;
    min-height: 40px;
  }

  .icon-button {
    width: 40px;
    min-width: 40px;
  }

  .board {
    width: min(100%, calc((100dvh - 138px) * 0.875));
    max-height: calc(100dvh - 138px);
  }
}
