:root {
  --cream: #fff8ec;
  --cream-2: #ffe9c2;
  --ink: #3b2a17;
  --ink-soft: #7a6647;
  --gold: #e7a417;
  --gold-deep: #b9740f;
  --line: rgba(120, 84, 30, 0.16);
  --card: rgba(255, 255, 255, 0.82);
  --shadow: 0 -10px 40px rgba(120, 70, 10, 0.16);
  --font: "Baloo Chettan 2", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }

body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(60% 50% at 50% 80%, rgba(255, 255, 255, 0.55) 0%, rgba(255, 236, 196, 0) 62%),
    radial-gradient(125% 100% at 50% 0%, var(--cream) 0%, var(--cream-2) 52%, #f3cd86 100%);
  background-attachment: fixed;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.app {
  position: relative;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-bottom: 16px; /* mascot sits low; the drawer overlaps its base, Popcat-style */
}

/* ---------- top corners ---------- */
.topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  z-index: 5;
}
.chip {
  width: 46px; height: 46px;
  border-radius: 999px;
  display: grid; place-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 1.4rem;
  box-shadow: 0 4px 14px rgba(120, 70, 10, 0.12);
}
.icon-btn {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  width: 46px; height: 46px;
  font-size: 1.2rem;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.2s ease;
}
.icon-btn:hover { background: #fff; }
.icon-btn:active { transform: scale(0.92); }
.icon-btn.muted { opacity: 0.5; }

/* ---------- title + count ---------- */
.hero {
  text-align: center;
  margin-top: 22px;
  padding: 0 16px;
  z-index: 2; /* keep title/count/hint above the now-very-tall mascot if they overlap */
}
.title {
  margin: 0;
  font-weight: 800;
  font-size: clamp(2.4rem, 6.5vw, 4rem);
  letter-spacing: -0.02em;
  line-height: 1;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.5);
}
.title .tld { color: var(--gold-deep); }
.count {
  margin-top: 8px;
  font-size: clamp(2rem, 5.5vw, 3.2rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.count.bump { animation: bump 0.18s ease; }
@keyframes bump { 0% { transform: scale(1); } 45% { transform: scale(1.05); } 100% { transform: scale(1); } }
.count-label { margin-top: 4px; font-size: 0.95rem; color: var(--ink-soft); font-weight: 600; }

/* ---------- energy + hint ---------- */
.energy {
  width: min(320px, 70vw);
  height: 12px;
  margin: 12px auto 0;
  background: rgba(120, 84, 30, 0.14);
  border-radius: 999px;
  overflow: hidden;
}
.energy-fill {
  height: 100%; width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gold), var(--gold-deep));
  transition: width 0.12s linear, background 0.2s ease;
}
.energy-fill.low { background: linear-gradient(90deg, #e98b3a, #c14b1f); }
.hint { margin: 10px 0 0; color: var(--ink-soft); font-weight: 600; font-size: 0.92rem; }
.hint .ml { color: var(--gold-deep); }
.hint b { color: var(--ink); }

/* ---------- mascot: big, bottom-anchored ---------- */
.stage {
  position: relative;
  width: 100%;
  margin-top: auto; /* push the mascot down to the bottom, Popcat-style */
  display: flex;
  justify-content: center;
  padding: 6px 0;
}
.papp-btn {
  appearance: none;
  border: none; background: none; padding: 0; margin: 0;
  cursor: pointer;
  display: block;
  width: fit-content;
}
/* Sized by HEIGHT like Popcat's cat (height:850px / ~88vh, bottom-anchored).
   The aspect of the mascot art is ~1.62:1, so we cap width to 95vw too. */
.papp-wrap {
  display: block;
  position: relative;
  width: fit-content;
  filter: drop-shadow(0 24px 30px rgba(150, 90, 12, 0.3));
  transition: filter 0.18s ease; /* transform is driven per-pop by the Web Animations API */
  transform: translateZ(0) scale(1);
  will-change: transform, filter;
}
.papp-wrap.tired { filter: drop-shadow(0 16px 22px rgba(120, 90, 40, 0.2)) grayscale(0.55) brightness(0.96); }
.pappadam { height: min(72vh, 520px); width: auto; margin: 0 auto; display: block; }
.papp-photo { display: none; height: min(72vh, calc(95vw / 1.62)); width: auto; }
.papp-wrap.has-photo .pappadam { display: none; }
.papp-wrap.has-photo #pappImg { display: block; }
.papp-wrap.has-photo.show-pop #pappImg { display: none; }
.papp-wrap.has-photo.show-pop #pappImgPop { display: block; }

/* shatter pieces — wedges of the mascot flung on each pop (built in JS) */
.shard-layer { position: absolute; inset: 0; pointer-events: none; }
.shard {
  position: absolute;
  inset: 0;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  opacity: 0;
  will-change: transform, opacity;
  pointer-events: none;
}
.crumb {
  position: absolute;
  top: 50%; left: 50%;
  width: 10px; height: 10px;
  border-radius: 40% 55% 50% 45%;
  background: var(--gold-deep);
  pointer-events: none;
  will-change: transform, opacity;
}

/* ---------- leaderboard: bottom drawer ---------- */
.board {
  position: fixed;
  left: 50%; bottom: 0;
  transform: translateX(-50%);
  width: min(680px, 96vw);
  background: var(--card);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow);
  z-index: 6;
  overflow: hidden;
}
.board-head {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 800;
  font-size: 1.02rem;
  color: var(--ink);
}
.board-sub { font-size: 0.8rem; color: var(--ink-soft); font-weight: 600; margin-left: 6px; }
.chev { transition: transform 0.25s ease; color: var(--ink-soft); }
.board.open .chev { transform: rotate(180deg); }
.board-body { max-height: 0; overflow: hidden; transition: max-height 0.3s ease; }
.board.open .board-body { max-height: min(46vh, 420px); overflow-y: auto; }
.board-list { list-style: none; margin: 0; padding: 2px 10px 12px; }
.board-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 8px;
  border-radius: 10px;
  font-weight: 600;
}
.board-list li + li { border-top: 1px solid var(--line); }
.board-list li.me { background: rgba(231, 164, 23, 0.16); }
.rank { width: 1.4em; color: var(--ink-soft); font-weight: 700; text-align: right; }
.flag { font-size: 1.3rem; line-height: 1; }
.cname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cnum { font-variant-numeric: tabular-nums; font-weight: 700; }
.board-empty { color: var(--ink-soft); justify-content: center; font-weight: 600; padding: 14px 8px; }

@media (max-width: 540px) {
  .hero { margin-top: 58px; }
  .papp-btn { width: 94vw; }
}

@media (prefers-reduced-motion: reduce) {
  .papp-wrap, .count.bump, .crumb, .chev, .board-body { transition: none !important; animation: none !important; }
}
