:root {
  --bg: #eef9ff;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-solid: #ffffff;
  --ink: #193344;
  --muted: #637a88;
  --line: rgba(70, 135, 160, 0.18);
  --cell: rgba(255, 255, 255, 0.62);
  --cell-strong: rgba(255, 255, 255, 0.92);
  --shadow: 0 16px 40px rgba(60, 145, 180, 0.18);
  --radius: 22px;
  --drop-color: #8fd3ff;
  --drop-size: 70%;
  --drag-x: 0px;
  --drag-y: 0px;
  --drag-scale-x: 1;
  --drag-scale-y: 1;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 8%, rgba(134, 220, 255, 0.5), transparent 28%),
    radial-gradient(circle at 82% 0%, rgba(255, 225, 146, 0.48), transparent 26%),
    linear-gradient(180deg, #eaf9ff 0%, #f6fbff 54%, #eef7ff 100%);
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: min(100%, 520px);
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(14px + var(--safe-top)) 14px calc(18px + var(--safe-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

h1 {
  margin: 0;
  font-size: clamp(26px, 7vw, 38px);
  letter-spacing: 0.04em;
}

.daily-label {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.round-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--panel-solid);
  box-shadow: var(--shadow);
  font-weight: 800;
}

.stats-card, .jars-panel, .rules-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.stats-card {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 10px;
}

.stat {
  min-width: 0;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.54);
  padding: 9px 8px;
  text-align: center;
}

.stat span {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

.stat strong {
  display: block;
  margin-top: 3px;
  font-size: 20px;
  line-height: 1;
}

.jars-panel {
  margin-top: 10px;
  padding: 12px;
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.section-title span { font-weight: 800; }
.section-title small { color: var(--muted); font-size: 12px; text-align: right; }

.jar-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 9px;
}

.jar {
  position: relative;
  min-height: 86px;
  padding: 8px 6px 6px;
  border-radius: 18px 18px 22px 22px;
  background: linear-gradient(180deg, rgba(255,255,255,0.78), rgba(231,246,255,0.78));
  border: 1px solid rgba(85, 147, 170, 0.22);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.65), 0 8px 18px rgba(60,145,180,0.10);
  overflow: hidden;
  transition: transform 180ms ease, box-shadow 180ms ease, outline-color 180ms ease;
}

.jar::before {
  content: "";
  position: absolute;
  left: 22%;
  right: 22%;
  top: 4px;
  height: 10px;
  border-radius: 5px 5px 2px 2px;
  background: rgba(110, 145, 160, 0.18);
}

.jar.drag-over {
  transform: translateY(-3px) scale(1.04);
  outline: 3px solid rgba(57, 160, 220, 0.45);
  box-shadow: 0 12px 30px rgba(60,145,180,0.22), inset 0 0 0 1px rgba(255,255,255,0.75);
}

.jar.disabled { opacity: 0.42; }

.jar-fill {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  height: calc(var(--fill, 0) * 1%);
  min-height: 0;
  border-radius: 16px 16px 12px 12px;
  background: var(--jar-color, rgba(170, 220, 255, 0.42));
  opacity: 0.72;
  transition: height 220ms cubic-bezier(.2,.8,.2,1.2);
}

.jar-fill::before {
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  top: -4px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,0.45);
  filter: blur(.2px);
}

.jar.rainbow .jar-fill, .jar.rainbow::after {
  background: linear-gradient(90deg, #f35e5e, #f6c64f, #50c878, #4d8df7, #8b5cf6, #f35e5e);
}

.jar-label {
  position: relative;
  z-index: 2;
  display: flex;
  min-height: 64px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.jar-count { color: var(--muted); font-weight: 700; }

.board-wrap {
  margin: 12px auto 8px;
  padding: 8px;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.42);
  border: 1px solid rgba(80, 150, 180, 0.16);
  box-shadow: var(--shadow);
}

.board {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 7px;
  touch-action: none;
  user-select: none;
}

.cell {
  aspect-ratio: 1;
  position: relative;
  border-radius: 18px;
  background: linear-gradient(180deg, var(--cell-strong), var(--cell));
  border: 1px solid rgba(65, 130, 155, 0.12);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.9), inset 0 -7px 18px rgba(75, 165, 200, 0.07);
  display: grid;
  place-items: center;
  overflow: visible;
}

.cell::before {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(160,220,245,0.14), transparent 64%);
  opacity: .65;
}

.cell.drag-origin {
  background: linear-gradient(180deg, #ffffff, rgba(242,251,255,0.82));
  box-shadow: inset 0 0 0 2px rgba(38, 169, 224, 0.16), inset 0 1px 0 rgba(255,255,255,0.9);
  z-index: 4;
}

.cell.drag-target {
  z-index: 2;
}

.cell.drag-ok {
  box-shadow: inset 0 0 0 3px rgba(53, 176, 118, 0.28), inset 0 1px 0 rgba(255,255,255,0.9);
}

.cell.drag-bad {
  box-shadow: inset 0 0 0 3px rgba(235, 92, 92, 0.24), inset 0 1px 0 rgba(255,255,255,0.9);
}

.cell.drag-ok::after,
.cell.drag-bad::after {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  opacity: .5;
  animation: ripple 900ms ease infinite;
}

.cell.drag-ok::after { border: 2px solid rgba(53, 176, 118, .34); }
.cell.drag-bad::after { border: 2px solid rgba(235, 92, 92, .28); }

.drop {
  position: relative;
  z-index: 2;
  width: var(--drop-size, 70%);
  height: var(--drop-size, 70%);
  border-radius: 64% 58% 68% 55% / 66% 62% 72% 64%;
  background:
    radial-gradient(circle at 34% 24%, rgba(255,255,255,0.72) 0 10%, transparent 22%),
    radial-gradient(circle at 68% 72%, rgba(255,255,255,0.22), transparent 48%),
    linear-gradient(145deg, rgba(255,255,255,0.24), rgba(255,255,255,0) 45%),
    var(--drop-color);
  box-shadow:
    inset -9px -12px 16px rgba(0,0,0,0.13),
    inset 5px 7px 12px rgba(255,255,255,0.38),
    0 10px 19px rgba(42, 107, 130, 0.20);
  transform: translate(var(--drag-x), var(--drag-y)) scale(var(--drag-scale-x), var(--drag-scale-y));
  transition: transform 170ms cubic-bezier(.2,.9,.2,1.18), filter 170ms ease;
  animation: breathe 2.8s ease-in-out infinite;
  will-change: transform;
  cursor: grab;
}

.drop::before {
  content: "";
  position: absolute;
  width: 38%;
  height: 30%;
  left: 18%;
  top: 8%;
  border-radius: 50%;
  background: rgba(255,255,255,0.45);
  transform: rotate(-20deg);
  filter: blur(.1px);
}

.drop::after {
  content: "";
  position: absolute;
  width: 20%;
  height: 16%;
  right: 18%;
  bottom: 14%;
  border-radius: 50%;
  background: rgba(255,255,255,0.22);
}

.drop.full {
  filter: saturate(1.18) drop-shadow(0 0 10px rgba(255,255,255,0.65));
  animation: breathe 2.3s ease-in-out infinite, fullGlow 1.8s ease-in-out infinite;
}

.drop.pop {
  animation: pop 260ms cubic-bezier(.18,.9,.24,1.24), breathe 2.8s ease-in-out 280ms infinite;
}

.drop.dragging-drop {
  z-index: 12;
  cursor: grabbing;
  pointer-events: none;
  animation: none;
  transition: none;
  filter: saturate(1.1) drop-shadow(0 12px 16px rgba(51, 119, 145, 0.20));
}

.drop-shine {
  position: absolute;
  width: 13%;
  height: 13%;
  left: 34%;
  top: 18%;
  border-radius: 50%;
  background: rgba(255,255,255,0.82);
}

.drop-face {
  position: absolute;
  left: 27%;
  right: 27%;
  top: 43%;
  height: 26%;
  display: block;
  transform-origin: center;
}

.eye {
  position: absolute;
  top: 0;
  width: 22%;
  height: 32%;
  border-radius: 50%;
  background: rgba(28, 53, 64, 0.62);
  box-shadow: 0 1px 0 rgba(255,255,255,0.34);
  animation: blink 4.6s ease-in-out infinite;
}

.eye.left { left: 8%; }
.eye.right { right: 8%; }

.mouth {
  position: absolute;
  left: 39%;
  top: 46%;
  width: 22%;
  height: 14%;
  border-radius: 0 0 10px 10px;
  border-bottom: 2px solid rgba(28, 53, 64, 0.42);
}

@keyframes breathe {
  0%, 100% { transform: translate(var(--drag-x), var(--drag-y)) scale(var(--drag-scale-x), var(--drag-scale-y)); }
  50% { transform: translate(var(--drag-x), calc(var(--drag-y) - 2px)) scale(calc(var(--drag-scale-x) * 1.02), calc(var(--drag-scale-y) * .985)); }
}

@keyframes blink {
  0%, 92%, 100% { transform: scaleY(1); }
  95% { transform: scaleY(.12); }
}

@keyframes pop {
  0% { transform: translate(0, 0) scale(.64, .76); opacity: .2; }
  68% { transform: translate(0, -2px) scale(1.16, .92); opacity: 1; }
  100% { transform: translate(0, 0) scale(1); }
}

@keyframes fullGlow {
  0%, 100% { box-shadow: inset -9px -12px 16px rgba(0,0,0,0.13), inset 5px 7px 12px rgba(255,255,255,0.38), 0 10px 19px rgba(42, 107, 130, 0.20), 0 0 0 rgba(255,255,255,0); }
  50% { box-shadow: inset -9px -12px 16px rgba(0,0,0,0.13), inset 5px 7px 12px rgba(255,255,255,0.38), 0 10px 19px rgba(42, 107, 130, 0.20), 0 0 18px rgba(255,255,255,.72); }
}

@keyframes ripple {
  0% { transform: scale(.72); opacity: .6; }
  100% { transform: scale(1.16); opacity: .08; }
}

.message {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  margin: 8px 0;
  border-radius: 18px;
  background: rgba(255,255,255,0.72);
  border: 1px solid var(--line);
  color: #33566a;
  text-align: center;
  font-size: 14px;
}

.controls {
  display: grid;
  grid-template-columns: 0.75fr 1.35fr 1fr;
  gap: 8px;
}

.soft-btn, .primary-btn {
  border-radius: 16px;
  padding: 11px 10px;
  background: #ffffff;
  border: 1px solid rgba(75, 135, 165, 0.16);
  box-shadow: 0 8px 22px rgba(60, 145, 180, 0.12);
  font-weight: 800;
}

.soft-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.primary-btn { width: 100%; color: #ffffff; background: linear-gradient(180deg, #26a9e0, #148cc8); }
.reward-btn { background: linear-gradient(90deg, rgba(255,255,255,0.96), rgba(239,250,255,0.96)); }
.danger { color: #ad423c; }

.rules-card {
  margin-top: 10px;
  padding: 12px;
}

.mix-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.mix-item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 34px;
  border-radius: 14px;
  background: rgba(255,255,255,0.62);
  font-size: 12px;
  font-weight: 800;
}

.swatch {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  display: inline-block;
  background: var(--swatch-color);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08);
}

footer {
  margin-top: 12px;
  color: var(--muted);
  text-align: center;
  font-size: 11px;
}

.help-dialog {
  width: min(calc(100% - 30px), 440px);
  border: 0;
  border-radius: 24px;
  padding: 0;
  color: var(--ink);
  background: #ffffff;
  box-shadow: 0 24px 80px rgba(30, 80, 115, 0.28);
}

.help-dialog::backdrop { background: rgba(25, 51, 68, 0.28); backdrop-filter: blur(3px); }
.help-dialog form { padding: 20px; }
.help-dialog h2 { margin: 0 0 12px; }
.help-dialog p { margin: 8px 0; color: #3c5c6d; line-height: 1.55; }
.help-dialog .soft-btn { width: 100%; margin-top: 8px; }

@media (max-width: 380px) {
  .app-shell { padding-left: 10px; padding-right: 10px; }
  .board { gap: 5px; }
  .cell { border-radius: 15px; }
  .jar-row { gap: 6px; }
  .jar { min-height: 80px; }
  .controls { grid-template-columns: 1fr; }
  .mix-grid { grid-template-columns: repeat(2, 1fr); }
}
