:root {
  --navy: #5b3d58;
  --panel: #fff5e8;
  --line: #d9b5cf;
  --cyan: #70e1e1;
  --yellow: #ffd76b;
  --pink: #ff89b5;
  --violet: #bba0f0;
  --green: #a1e7ad;
  --muted: #a17d9b;
}

html, body { background: #fff0e9; }
body { color: #5b3d58; font-family: 'Fredoka', ui-rounded, system-ui, sans-serif; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 3px solid #8a64bc; outline-offset: 4px; }

.app-shell {
  background: #fff4ed url('assets/jelly-world-bg.jpg') center / cover no-repeat;
  box-shadow: 0 0 0 1px #f7d8e7;
}
.screen { position: relative; }
.landing-screen { background: linear-gradient(180deg, #fff8f088, #fff8f022 46%, #fff8f0aa); }
.landing-screen .brand-lockup {
  width: min(84vw, 382px);
  margin: 0 auto 3px;
  filter: drop-shadow(0 8px 0 #e8a6d688) drop-shadow(0 14px 18px #b775a855);
}
.landing-screen .tagline {
  color: #805878;
  font-size: clamp(16px, 4.8vw, 21px);
  font-weight: 600;
  margin: 0 0 17px;
  text-shadow: 0 2px 0 #fff;
}
.landing-screen .demo-pieces { min-height: 102px; margin-bottom: 18px; gap: 29px; }
.landing-screen .microcopy {
  color: #976c91;
  font: 600 10px 'Fredoka', sans-serif;
  letter-spacing: 2.2px;
  margin-top: 30px;
}

.btn, .text-btn { font-family: 'Fredoka', ui-rounded, sans-serif; font-weight: 600; }
.btn {
  position: relative;
  overflow: hidden;
  height: 64px;
  border: 2px solid #fff9ee;
  border-radius: 24px;
  color: #67465b;
  font-size: 22px;
  letter-spacing: .25px;
  gap: 10px;
  box-shadow: inset 0 3px 0 #ffffffaa, 0 7px 0 var(--button-edge), 0 13px 20px #bd8faa55;
  background: linear-gradient(#ffe992, #ffc65c);
  --button-edge: #e6a951;
}
.btn::before {
  content: '';
  position: absolute;
  pointer-events: none;
  top: 4px;
  left: 7%;
  right: 7%;
  height: 43%;
  border-radius: 100% 100% 55% 55%;
  background: linear-gradient(#fff9, #fff0);
}
.btn > * { position: relative; z-index: 1; }
.btn:hover { filter: brightness(1.035); transform: translateY(-2px); }
.btn:active { transform: translateY(4px); box-shadow: inset 0 2px 0 #ffffffaa, 0 3px 0 var(--button-edge), 0 6px 10px #bd8faa55; }
.btn-primary { background: linear-gradient(#ffe992, #ffc65c); color: #66455d; --button-edge: #e6a951; }
.btn-secondary, #pauseModal [data-home], #gameoverModal [data-home], #gameoverModal [data-home] {
  background: linear-gradient(#c5aeef, #a889df);
  color: #503955;
  --button-edge: #8c69bb;
}
.btn .ui-icon {
  display: block;
  width: 25px;
  height: 25px;
  flex: 0 0 25px;
  background: none;
  filter: none;
  object-fit: contain;
}
.landing-actions { gap: 17px; }
.landing-sound {
  position: absolute;
  z-index: 2;
  top: calc(16px + var(--safe-t));
  right: max(16px, var(--safe-r));
}

.game-screen { background: #fff9f2b5; }
.game-header { padding-bottom: 10px; }
.header-controls { display: flex; align-items: center; gap: 10px; }
.eyebrow, .energy-head, .goal-row span:last-child, .modal-kicker {
  color: #986689;
  font-family: 'Fredoka', sans-serif;
  font-weight: 600;
}
.game-header strong {
  display: block;
  color: #eb6a9d;
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  text-shadow: 0 3px 0 #fff, 0 5px 0 #eab5ca;
}
.icon-btn {
  width: 40px;
  height: 40px;
  border: 2px solid #fff;
  border-radius: 15px;
  background: linear-gradient(#d3bff4, #aa90de);
  box-shadow: 0 4px 0 #9174bb, 0 7px 11px #bd91ba55;
}
.icon-btn img { width: 20px; height: 20px; }
.sound-toggle[aria-pressed="false"] {
  background: linear-gradient(#f5e9f4, #ddc6df);
  box-shadow: 0 4px 0 #c4a8c7, 0 7px 11px #bd91ba44;
}
.sound-toggle[aria-pressed="false"] img { opacity: .75; }
.goal-row { color: #815e79; font-weight: 500; }
.goal-row span:last-child { color: #ad7296; }

.energy-panel {
  border: 2px solid #fff;
  border-radius: 21px;
  background: radial-gradient(ellipse at 15% 0, #fff 0, #fff7ed 43%, #ffdfeefa 100%);
  box-shadow: inset 0 -4px 7px #e6b8d377, 0 5px 0 #e9bfd5, 0 9px 15px #bd91ba44;
}
.energy-head { color: #805878; }
.energy-track {
  height: 22px;
  border: 2px solid #e6bbd0;
  background: #fff8f4;
  box-shadow: inset 0 2px 3px #dbbad0aa;
}
.energy-fill {
  background: radial-gradient(ellipse at 50% 12%, #fff9 0 7%, transparent 55%), linear-gradient(90deg, #ff84ae, #ffbf85 45%, #f6da6e 85%);
  box-shadow: inset 0 3px 0 #fff8, inset 0 -3px 4px #cd7e9a88, 0 0 9px #ff9cc4;
}
.energy-fill.charging { animation: jellyGlow 1.8s ease-in-out infinite alternate; }
@keyframes jellyGlow { to { filter: saturate(1.16) brightness(1.08); } }

.board {
  border: 4px solid #fff7f5;
  border-radius: 25px;
  background: radial-gradient(ellipse at 26% 0, #ffe9f5 0, #edc6e1 48%, #cea1cb 100%);
  box-shadow: inset 0 3px 5px #fff9, inset 0 -5px 8px #a475aa88, 0 0 0 2px #dfb0d0, 0 6px 0 #ba89b1, 0 13px 20px #af7aab66;
}
.cell {
  position: relative;
  border: 1px solid #fff9;
  border-radius: 10px;
  background: radial-gradient(ellipse at 36% 10%, #fffdfaff 0, #ffeefa 54%, #efd3e7 100%);
  box-shadow: inset 0 3px 5px #d2a1be99, inset 0 -2px 2px #fff, 0 1px 1px #a974a344;
}
.cell:not(.filled)::before {
  content: '';
  position: absolute;
  pointer-events: none;
  inset: 3px 5px auto 4px;
  height: 34%;
  border-radius: 80% 70% 60% 40%;
  background: linear-gradient(#fffdfbcc, #fff0);
}
.cell:not(.filled)::after {
  content: '';
  position: absolute;
  pointer-events: none;
  right: 18%;
  bottom: 17%;
  width: 10%;
  height: 10%;
  border-radius: 50%;
  background: #fff9;
}
.cell.filled, .piece-cell, .clear-fragment, .reward-clear-cell {
  border: 0;
  border-radius: 0;
  background-color: transparent;
  background-position: center;
  background-size: 108% 108%;
  background-repeat: no-repeat;
  box-shadow: none;
}
.cell.cyan, .piece-cell.cyan, .clear-fragment.cyan, .reward-clear-cell.cyan { background-image: url('assets/jelly-block-cyan.png?v=4'); background-color: transparent; }
.cell.pink, .piece-cell.pink, .clear-fragment.pink, .reward-clear-cell.pink { background-image: url('assets/jelly-block-pink.png?v=4'); background-color: transparent; }
.cell.yellow, .piece-cell.yellow, .clear-fragment.yellow, .reward-clear-cell.yellow { background-image: url('assets/jelly-block-yellow.png?v=4'); background-color: transparent; }
.cell.violet, .piece-cell.violet, .clear-fragment.violet, .reward-clear-cell.violet { background-image: url('assets/jelly-block-violet.png?v=4'); background-color: transparent; }
.cell.green, .piece-cell.green, .clear-fragment.green, .reward-clear-cell.green { background-image: url('assets/jelly-block-green.png?v=4'); background-color: transparent; }
.cell.drop-invalid-cell { background: #ee7197 !important; border-color: #fff; box-shadow: 0 0 0 2px #ee7197, 0 0 10px #dc5084; }
.board.drop-invalid { border-color: #eb6a97; box-shadow: 0 0 0 2px #eb6a97, 0 6px 18px #ed88aa99; }
.cell.drop-valid-cell { background: #9be9d1 !important; border-color: #fff; box-shadow: inset 0 2px 4px #fff9, 0 0 6px #70cfae; }
.board.drop-valid { border-color: #83d7c0; box-shadow: 0 0 0 2px #83d7c0, 0 7px 18px #8edccc77; }

.tray-label { color: #684b66; font-size: 17px; font-weight: 600; }
.tray-label small { color: #9e7695; }
.piece-card {
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}
.piece-card .piece { transform: scale(var(--tray-scale, .78)); }
.piece-card.arriving .piece {
  animation: jellyPieceArrive .58s cubic-bezier(.2, .9, .25, 1) var(--arrival-delay, 0ms) both;
}
@keyframes jellyPieceArrive {
  0% { opacity: 0; transform: translateY(28px) scale(calc(var(--tray-scale, .78) * .82)); filter: drop-shadow(0 0 0 #fff0); }
  58% { opacity: 1; transform: translateY(-7px) scale(calc(var(--tray-scale, .78) * 1.08)); filter: drop-shadow(0 8px 8px #e78bb277); }
  78% { transform: translateY(3px) scale(calc(var(--tray-scale, .78) * .97)); }
  100% { opacity: 1; transform: translateY(0) scale(var(--tray-scale, .78)); filter: drop-shadow(0 3px 4px #e78bb255); }
}
.drag-ghost { filter: drop-shadow(0 8px 7px #ae6d9c88); }
.drag-ghost.valid { filter: drop-shadow(0 0 9px #79dbc0); }
.drag-ghost.invalid { filter: drop-shadow(0 0 9px #e25a84); }
.drag-ghost.invalid .piece-cell { background: #ec7397 !important; border-color: #fff; box-shadow: 0 0 7px #e25a84; }
.game-tip {
  border: 2px solid #fff;
  background: #fff8efe6;
  box-shadow: 0 3px 0 #e8c9d8;
  color: #886a80;
  font-weight: 500;
}
.mini-row { color: #f6a2bc; font-size: 29px; line-height: 1; }

.row-clear-burst {
  background: url('assets/jelly-row-clear.png') center / 100% auto no-repeat;
  filter: drop-shadow(0 0 12px #f6a6c2);
}
.row-clear-burst.vertical { --burst-rotation: 90deg; }
.row-clear-burst::before {
  background: linear-gradient(90deg, transparent, #ffabcbbb 20%, #fff 50%, #ffe087 80%, transparent);
  box-shadow: 0 0 12px 4px #ffaacb, 0 0 30px 10px #ffe28977;
}
.clear-fragment { filter: drop-shadow(0 0 7px #ffacd1); }
.score-pop { color: #e96f9d; text-shadow: 0 3px 0 #fff, 0 7px 11px #a66e9388; }
.score-pop strong, .score-pop small { font-family: 'Fredoka', sans-serif; }
.score-pop small { color: #8a6abb; }
.reward-overlay img.reward-art {
  display: block;
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(118vw, 520px);
  height: auto;
  max-width: none;
  opacity: 1;
  filter: drop-shadow(0 0 15px #fff9);
  transform: translate(-50%, -50%) scale(.62);
  animation: none;
}
.reward-overlay.show img.reward-art { animation: rewardJellyReveal 1.6s cubic-bezier(.2, .82, .26, 1) both; }
.reward-overlay[data-reward="area"] img.reward-art { width: min(96vw, 440px); }
@keyframes rewardJellyReveal {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.2) rotate(-13deg); }
  21% { opacity: 1; transform: translate(-50%, -50%) scale(1.08) rotate(3deg); }
  78% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.18) rotate(8deg); }
}
.reward-overlay strong, .reward-overlay span:not(.reward-art) { font-family: 'Fredoka', sans-serif; text-shadow: 0 3px 0 #fff, 0 6px 12px #a16791aa; }
.reward-overlay strong { color: #bf4d8b; }
.reward-overlay span:not(.reward-art) { color: #77567f; }

.modal-layer { background: #70587377; backdrop-filter: blur(9px); }
.modal {
  border: 3px solid #fff;
  background: linear-gradient(155deg, #fffdf3, #ffe8f1 72%, #efe0ff);
  color: #60455d;
  box-shadow: 0 9px 0 #d6a5c4, 0 22px 42px #6e426d66;
}
.modal-close {
  top: 14px;
  right: 16px;
  color: #7c5980;
  background: #fff9f1;
  border: 2px solid #edc8db;
  border-radius: 50%;
  font-size: 26px;
}
.modal-sound {
  position: absolute;
  z-index: 2;
  top: 14px;
  left: 16px;
  width: 36px;
  height: 36px;
}
.modal-kicker { color: #c477a5; }
.modal h2 { color: #624660; font-weight: 700; }
.modal h2 em { color: #ed79a6; }
.modal p { color: #8f708a; }
.modal-rules { gap: 11px; }
.rule {
  background: #fffdf9d9;
  border: 2px solid #f2d7e4;
  border-radius: 17px;
  color: #6e536b;
}
.rule b { color: #684b63; background: #ffd989; }
.note { color: #98768f; }
.modal-actions { gap: 17px; }
.modal-actions .btn, .modal-actions .text-btn { font: 600 20px/1 'Fredoka', sans-serif; border-radius: 23px; }
#pauseModal [data-resume] { background: linear-gradient(#ffe992, #ffc65c); color: #66455d; border: 2px solid #fff9ee; --button-edge: #e6a951; box-shadow: inset 0 3px 0 #ffffffaa, 0 7px 0 var(--button-edge), 0 13px 20px #bd8faa55; }
#pauseModal [data-restart] { background: linear-gradient(#ffacc7, #f383ad); color: #66455d; border: 2px solid #fff9ee; --button-edge: #d46d97; box-shadow: inset 0 3px 0 #ffffffaa, 0 7px 0 var(--button-edge), 0 13px 20px #bd8faa55; }
#pauseModal [data-home], #gameoverModal [data-home] { border: 2px solid #fff9ee; box-shadow: inset 0 3px 0 #ffffffaa, 0 7px 0 var(--button-edge), 0 13px 20px #bd8faa55; }
.final-score { color: #ed78a6; font-family: 'Fredoka', sans-serif; text-shadow: 0 3px 0 #fff, 0 6px 0 #ecc3d4; }
.best { color: #8b6b86 !important; font-family: 'Fredoka', sans-serif !important; }
.best span { color: #d36f9f; }
.crown { color: #ffcd70; text-shadow: 0 3px 0 #eaaec9; }

@media (max-width: 390px) {
  .landing-screen .brand-lockup { width: min(87vw, 335px); margin-bottom: 0; }
  .landing-screen .demo-pieces { margin-bottom: 17px; }
  .btn { height: 60px; font-size: 20px; }
  .tray { gap: 4px; }
  .piece-card { padding: 0; }
}
@media (max-width: 500px) and (max-height: 700px) {
  .game-screen .board,
  .game-screen .energy-panel { width: var(--compact-board-size); }
  .energy-track { height: 16px; }
  .header-controls { gap: 8px; }
  .tray { gap: 4px; }
  .piece-card { padding: 2px; }
}
@media (max-width: 360px) {
  .game-screen .board { width: min(100%, calc(100vw - 48px)); }
}
@media (prefers-reduced-motion: reduce) {
  .energy-fill.charging, .reward-overlay.show img.reward-art, .piece-card.arriving .piece { animation-duration: .01ms; animation-delay: 0ms; }
}
