:root {
  --bg: linear-gradient(160deg, #fdf2f8 0%, #fce7f3 50%, #fbcfe8 100%);
  --card: rgba(255, 255, 255, 0.7);
  --card-border: rgba(244, 143, 177, 0.3);
  --text: #3d1a2c;
  --muted: #7a4f63;
  --accent: #e91e63;
  --accent-soft: #ffd1e0;
  --gold: #f6c453;
  --shadow: 0 8px 32px rgba(233, 30, 99, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, "Segoe UI", "Inter", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.hdr {
  padding: 18px 32px 10px;
  text-align: center;
}

.hdr h1 {
  margin: 0 0 4px;
  font-weight: 700;
  font-size: 1.6rem;
  letter-spacing: -0.01em;
}

.hdr-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.total-wrap {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 6px 22px;
  border-radius: 999px;
  background: var(--card);
  backdrop-filter: blur(8px);
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow);
}
.sound-toggle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--card-border);
  background: var(--card);
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.1s, background 0.15s;
}
.sound-toggle:hover  { background: var(--accent-soft); }
.sound-toggle:active { transform: scale(0.94); }
.sound-toggle.muted  { filter: grayscale(0.8); opacity: 0.65; }
.total-label {
  font-size: 0.95rem;
  color: var(--muted);
  font-weight: 500;
}
.total {
  font-size: 1.8rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  letter-spacing: -0.02em;
  transition: transform 0.3s ease;
}
.total.bump { transform: scale(1.08); }
.total-cur {
  font-size: 1.3rem;
  color: var(--accent);
  font-weight: 700;
}

.main {
  flex: 1;
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 20px;
  padding: 12px 32px;
  min-height: 0;
}

.leaders {
  background: var(--card);
  backdrop-filter: blur(8px);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
  overflow-y: auto;
}
.leaders h2 {
  margin: 0 0 10px;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}
.leaderboard {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.leaderboard li {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.5);
  font-size: 0.95rem;
  transition: background 0.4s ease;
}
.leaderboard li.empty {
  display: block;
  text-align: center;
  color: var(--muted);
  font-style: italic;
  background: transparent;
}
.leaderboard .rank {
  font-weight: 700;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: center;
}
.leaderboard .name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.leaderboard .sum {
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.leaderboard li.flash {
  animation: flash 1.2s ease;
}
@keyframes flash {
  0%   { background: var(--gold); transform: translateX(-4px); }
  100% { background: rgba(255, 255, 255, 0.5); transform: translateX(0); }
}
.leaderboard li:nth-child(1) .rank::before { content: "🥇 "; }
.leaderboard li:nth-child(2) .rank::before { content: "🥈 "; }
.leaderboard li:nth-child(3) .rank::before { content: "🥉 "; }
.leaderboard li:nth-child(1) .rank,
.leaderboard li:nth-child(2) .rank,
.leaderboard li:nth-child(3) .rank { font-size: 0; }
.leaderboard li:nth-child(1) .rank::before,
.leaderboard li:nth-child(2) .rank::before,
.leaderboard li:nth-child(3) .rank::before { font-size: 1rem; }

.stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card);
  backdrop-filter: blur(8px);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  min-height: 360px;
}

.pig-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 24px;
}

.pig {
  --scale: 1;
  width: clamp(280px, 42vw, 460px);
  height: auto;
  max-height: 80%;
  object-fit: contain;
  transform: scale(var(--scale));
  transform-origin: 50% 100%;
  transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
  filter: drop-shadow(0 14px 22px rgba(190, 60, 110, 0.25));
  user-select: none;
  -webkit-user-drag: none;
}
.pig.shake { animation: pigShake 0.45s ease; }
@keyframes pigShake {
  0%, 100% { transform: scale(var(--scale)) rotate(0deg); }
  25%      { transform: scale(var(--scale)) rotate(-2deg); }
  75%      { transform: scale(var(--scale)) rotate(2deg); }
}

.jar {
  position: absolute;
  right: 28px;
  bottom: 28px;
  width: 240px;
  height: 280px;
  border-radius: 24px 24px 36px 36px / 18px 18px 32px 32px;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.55) 0%,
    rgba(220, 240, 255, 0.35) 100%
  );
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow:
    inset 0 0 25px rgba(255, 255, 255, 0.7),
    inset 6px 0 12px rgba(150, 180, 220, 0.15),
    0 12px 30px rgba(60, 80, 120, 0.18);
  overflow: hidden;
  backdrop-filter: blur(2px);
}
.jar-rim {
  position: absolute;
  top: 0;
  left: -2px;
  right: -2px;
  height: 14px;
  background: linear-gradient(180deg, #b8d4e8 0%, #7aa8c9 100%);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
#jar-canvas {
  position: absolute;
  inset: 14px 0 0 0;
  width: 100%;
  height: calc(100% - 14px);
  display: block;
}
.jar-shine {
  position: absolute;
  top: 22px;
  left: 12px;
  width: 18px;
  height: 70%;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.7) 0%,
    rgba(255, 255, 255, 0.05) 100%
  );
  border-radius: 999px;
  pointer-events: none;
}

.footer {
  padding: 14px 32px 22px;
}

.add-form {
  background: var(--card);
  backdrop-filter: blur(8px);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  padding: 16px 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.add-form .row {
  display: grid;
  grid-template-columns: 1.4fr 1fr auto;
  gap: 12px;
  align-items: end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.field span {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}
.field input {
  padding: 11px 14px;
  font-size: 1rem;
  border: 2px solid transparent;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.85);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(233, 30, 99, 0.12);
}
.amount-field input {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.btn-primary {
  padding: 12px 22px;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #ec4899 0%, #e91e63 100%);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(233, 30, 99, 0.35);
  transition: transform 0.1s, box-shadow 0.15s;
  white-space: nowrap;
}
.btn-primary:hover  { box-shadow: 0 6px 18px rgba(233, 30, 99, 0.45); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.6; cursor: wait; }

.quick {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.quick-btn {
  padding: 7px 14px;
  font-size: 0.92rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.7);
  color: var(--accent);
  border: 1.5px solid var(--accent-soft);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.12s, transform 0.08s;
  font-variant-numeric: tabular-nums;
}
.quick-btn:hover  { background: var(--accent-soft); }
.quick-btn:active { transform: scale(0.95); }

.form-error {
  color: #b3132a;
  font-size: 0.88rem;
  font-weight: 500;
  background: #ffe1e6;
  border: 1px solid #f3b8c1;
  padding: 8px 12px;
  border-radius: 10px;
}

@media (max-width: 820px) {
  .main {
    grid-template-columns: 1fr;
    padding: 12px 16px;
  }
  .leaders { max-height: 200px; }
  .stage { min-height: 320px; }
  .jar { width: 180px; height: 220px; right: 16px; bottom: 16px; }
  .add-form .row { grid-template-columns: 1fr; }
  .footer { padding: 14px 16px 22px; }
  .hdr { padding: 14px 16px 8px; }
  .hdr h1 { font-size: 1.25rem; }
}
