:root {
  --pink: #ff4f9a;
  --pink-dark: #cf1f6d;
  --pink-soft: #ffd9ea;
  --purple: #7a3fa8;
  --purple-deep: #45215e;
  --mint: #2fbd6f;
  --sun: #ffc53d;
  --ink: #3a2340;
  --paper: #ffffff;
  --font-display: 'Baloo 2', 'Trebuchet MS', system-ui, sans-serif;
  --font-ui: 'Fredoka', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #2a1140;
  font-family: var(--font-ui);
  color: #fff;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100dvh;
  background:
    radial-gradient(120% 80% at 50% -10%, #ff8fc6 0%, #b464d6 42%, #5b2b8f 78%, #35155a 100%);
  padding: max(8px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
  gap: 8px;
}

/* ---------- topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.logo {
  display: inline-flex;
  gap: 6px;
  align-items: baseline;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(15px, 3.4vw, 22px);
  letter-spacing: .5px;
  text-decoration: none;
  white-space: nowrap;
}
.logo-sweet { color: #fff; }
.logo-candy { color: var(--sun); }

.stats {
  display: flex;
  gap: 6px;
  margin-left: auto;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.stat {
  min-width: 62px;
  padding: 5px 10px 6px;
  border-radius: 13px;
  background: rgba(255, 255, 255, .14);
  border: 1px solid rgba(255, 255, 255, .2);
  text-align: center;
  line-height: 1.1;
  backdrop-filter: blur(6px);
}
.stat--best { background: rgba(255, 197, 61, .2); border-color: rgba(255, 197, 61, .45); }

.stat-label {
  display: block;
  font-size: 9px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  opacity: .78;
}
.stat-value {
  font-family: var(--font-display);
  font-size: clamp(15px, 3.6vw, 20px);
  font-weight: 800;
}

.topbar-actions { display: flex; gap: 6px; }

.icon-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .24);
  background: rgba(255, 255, 255, .12);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 16px;
  cursor: pointer;
  transition: background .15s, transform .15s;
}
.icon-btn:hover { background: rgba(255, 255, 255, .22); }
.icon-btn:active { transform: scale(.94); }
.icon-btn[aria-pressed="false"] .wave { display: none; }

/* ---------- stage ---------- */

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(40, 10, 60, .45), inset 0 0 0 2px rgba(255, 255, 255, .16);
  touch-action: none;
}

#canvas { display: block; width: 100%; height: 100%; }

.multi-badge {
  position: absolute;
  top: 12px; left: 50%;
  transform: translateX(-50%);
  padding: 5px 16px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffe08a, #ffb02e);
  color: #5c2c00;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 18px;
  box-shadow: 0 6px 18px rgba(255, 160, 40, .5);
  animation: pop .25s ease;
}
@keyframes pop { from { transform: translateX(-50%) scale(.6); } to { transform: translateX(-50%) scale(1); } }

/* ---------- overlay ---------- */

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(38, 12, 58, .62);
  backdrop-filter: blur(5px);
  transition: opacity .2s;
}
.overlay.hidden { opacity: 0; pointer-events: none; }

.overlay-card {
  width: min(420px, 100%);
  padding: 22px;
  border-radius: 22px;
  background: rgba(255, 255, 255, .96);
  color: var(--ink);
  text-align: center;
  box-shadow: 0 20px 50px rgba(30, 8, 50, .4);
}
.overlay-card h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: clamp(21px, 5vw, 27px);
  color: var(--purple-deep);
}
.overlay-card p { margin: 0; font-size: 14.5px; line-height: 1.5; color: #6f5878; }

.overlay-stats {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.overlay-stats div {
  min-width: 84px;
  padding: 8px 12px;
  border-radius: 14px;
  background: #fff2f8;
  border: 1px solid var(--pink-soft);
}
.overlay-stats span {
  display: block;
  font-size: 9.5px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: #a07f96;
}
.overlay-stats b { font-family: var(--font-display); font-size: 19px; color: var(--pink-dark); }

.cta {
  margin-top: 16px;
  padding: 12px 26px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #ff77b5, var(--pink));
  color: #fff;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 17px;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(255, 79, 154, .45);
  transition: transform .15s, box-shadow .15s;
}
.cta:hover { transform: translateY(-1px); box-shadow: 0 14px 28px rgba(255, 79, 154, .55); }
.cta:active { transform: translateY(1px); }

/* ---------- hud ---------- */

.hud { display: flex; flex-direction: column; gap: 6px; align-items: center; }

.hud-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

.pill-btn {
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .26);
  background: rgba(255, 255, 255, .14);
  color: #fff;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, transform .12s;
}
.pill-btn:hover:not(:disabled) { background: rgba(255, 255, 255, .24); }
.pill-btn:active:not(:disabled) { transform: scale(.96); }
.pill-btn:disabled { opacity: .45; cursor: default; }

.pill-btn--primary {
  background: linear-gradient(180deg, #ffe08a, #ffb02e);
  border-color: rgba(255, 255, 255, .5);
  color: #5c2c00;
  font-weight: 700;
}

.pill-btn--speed { display: inline-flex; align-items: center; gap: 6px; }
.pill-btn--speed .bolt { font-size: 14px; filter: grayscale(1) opacity(.7); }
.pill-btn--speed .speed-x {
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .18);
  font-size: 12px;
  font-weight: 700;
}

.pill-btn--full {
  background: linear-gradient(180deg, #ffe08a, #ff9c1a);
  border-color: rgba(255, 255, 255, .6);
  color: #5c2c00;
  font-weight: 700;
  box-shadow: 0 0 0 2px rgba(255, 176, 46, .35), 0 8px 22px rgba(255, 140, 20, .45);
  animation: fullPulse 1.4s ease-in-out infinite;
}
.pill-btn--full .bolt { filter: none; }
.pill-btn--full .speed-x { background: rgba(92, 44, 0, .18); }

@keyframes fullPulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(255, 176, 46, .35), 0 8px 22px rgba(255, 140, 20, .45); }
  50%      { box-shadow: 0 0 0 5px rgba(255, 176, 46, .18), 0 8px 26px rgba(255, 140, 20, .6); }
}

.multi-badge--full {
  background: linear-gradient(180deg, #fff0b0, #ff9c1a);
  box-shadow: 0 6px 22px rgba(255, 140, 20, .65);
}

.mode {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 8px 6px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .14);
  border: 1px solid rgba(255, 255, 255, .26);
  font-size: 12px;
  letter-spacing: .4px;
  text-transform: uppercase;
}
.mode select {
  border: 0;
  border-radius: 999px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, .92);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 13px;
  cursor: pointer;
}

.hud-note { font-size: 11px; letter-spacing: .3px; opacity: .7; text-align: center; }

/* ---------- modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(30, 8, 50, .66);
  backdrop-filter: blur(6px);
}
.modal.hidden { display: none; }

.modal-card {
  position: relative;
  width: min(520px, 100%);
  max-height: 82dvh;
  overflow-y: auto;
  padding: 24px 22px;
  border-radius: 22px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 24px 60px rgba(30, 8, 50, .45);
}

.modal-close {
  position: absolute;
  top: 12px; right: 12px;
  width: 32px; height: 32px;
  border: 0;
  border-radius: 50%;
  background: #ffe6f1;
  color: var(--pink-dark);
  font-size: 15px;
  cursor: pointer;
}

.modal-body h3 {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: 21px;
  color: var(--purple-deep);
}
.modal-body h4 {
  margin: 18px 0 8px;
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--pink-dark);
}
.modal-body p, .modal-body li { font-size: 14px; line-height: 1.55; color: #5b4465; }
.modal-body ul { margin: 0; padding-left: 18px; }

.pay-list { display: grid; gap: 6px; margin-top: 6px; }
.pay-list div {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 12px;
  background: #fff4f9;
}
.pay-list img { width: 34px; height: 34px; }
.pay-list b { margin-left: auto; font-family: var(--font-display); color: var(--pink-dark); }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  padding: 9px 18px;
  border-radius: 999px;
  background: rgba(30, 8, 50, .9);
  color: #fff;
  font-size: 13.5px;
  z-index: 30;
  transition: opacity .25s;
}
.toast.hidden { opacity: 0; pointer-events: none; }

.hidden { display: none; }
.overlay.hidden { display: grid; }

@media (max-width: 620px) {
  .topbar { gap: 6px; }
  .logo { font-size: 15px; }
  .stats {
    order: 3;
    width: 100%;
    margin-left: 0;
    justify-content: space-between;
    gap: 4px;
  }
  .stat { flex: 1; min-width: 0; padding: 4px 4px 5px; border-radius: 11px; }
  .stat-label { font-size: 8px; letter-spacing: .8px; }
  .stat-value { font-size: 16px; }
  .topbar-actions { margin-left: auto; }
  .hud-controls { gap: 6px; }
  .pill-btn { padding: 8px 12px; font-size: 13px; }
  .mode { padding: 4px 6px 4px 10px; font-size: 11px; }
  .mode select { padding: 5px 8px; font-size: 12px; }
  .hud-note { display: none; }
}
