* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy: #14286b;
  --blue: #2563d8;
  --blue-light: #4b8df5;
  --gold: #ffc51e;
  --orange: #f08a12;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #3f8f1f;
  font-family: 'Lilita One', 'Trebuchet MS', sans-serif;
  color: #fff;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#world-vignette {
  position: fixed; inset: 0; pointer-events: none; transition: background .6s;
  background: radial-gradient(ellipse at 50% 50%, transparent 55%, var(--vig, rgba(10,40,5,0.35)) 100%);
}

#game, #game canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; border: none; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud button { pointer-events: auto; }

#topbar {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  display: flex; align-items: flex-start;
}
.panel {
  width: 128px; height: 58px; margin-top: -2px;
  background: linear-gradient(#ffffff, #dfe9fb);
  border: 4px solid var(--navy); border-top: none;
  display: flex; flex-direction: column; align-items: center;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .25);
}
.panel.left { border-radius: 0 0 0 16px; border-right: none; }
.panel.right { border-radius: 0 0 16px 0; border-left: none; }
.tag {
  margin-top: 5px; padding: 2px 14px; border-radius: 10px;
  background: linear-gradient(#4b8df5, #2563d8); font-size: 13px; letter-spacing: .5px;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .2);
}
.val { color: var(--navy); font-size: 26px; line-height: 30px; }
.val.small { font-size: 15px; line-height: 28px; }

#next-wrap {
  width: 74px; height: 80px; margin-top: -2px;
  background: linear-gradient(#ffffff, #dbe6fb);
  border: 4px solid var(--navy); border-top: none; border-radius: 0 0 22px 22px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .25), inset 0 0 0 4px #3d7be8;
}
#next-ball {
  width: 40px; height: 40px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff 0 8%, var(--ball, #2a84ee) 30%, color-mix(in srgb, var(--ball, #2a84ee) 55%, #000) 100%);
  box-shadow: 0 3px 4px rgba(0, 0, 0, .35);
  transition: transform .15s;
}
#next-wrap:active #next-ball { transform: scale(.85); }
#next-ball.power {
  display: grid; place-items: center; font-size: 22px; line-height: 1;
  box-shadow: 0 0 0 3px #fff, 0 0 16px 4px var(--ball);
  animation: powerGlow .8s ease-in-out infinite alternate;
}
@keyframes powerGlow { to { box-shadow: 0 0 0 3px #fff, 0 0 26px 8px var(--ball); } }
#next-ball { position: relative; }
#next-ball.power::before {
  content: ''; position: absolute; inset: -7px; border-radius: 50%;
  background: conic-gradient(var(--ball), transparent 25%, var(--ball) 50%, transparent 75%, var(--ball));
  -webkit-mask: radial-gradient(circle, transparent 60%, #000 62%);
  mask: radial-gradient(circle, transparent 60%, #000 62%);
  animation: ringSpin 1.1s linear infinite;
}
@keyframes ringSpin { to { transform: rotate(360deg); } }

/* Big power-ball popup */
#power-banner {
  position: fixed; left: 50%; top: 42%; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; pointer-events: none; opacity: 0;
  --pc: #ffe23a;
}
#power-banner::before {
  content: ''; position: absolute; inset: -60px -120px; z-index: -1;
  background: radial-gradient(ellipse at center, color-mix(in srgb, var(--pc) 45%, transparent), transparent 65%);
}
.pb-icon { font-size: 72px; line-height: 1; filter: drop-shadow(0 4px 0 rgba(0, 0, 0, .35)); }
.pb-title {
  font-size: clamp(40px, 8vw, 96px); line-height: 1; color: var(--pc); letter-spacing: 2px; white-space: nowrap;
  -webkit-text-stroke: 8px #10261d; paint-order: stroke fill;
  text-shadow: 0 7px 0 #10261d, 0 0 30px var(--pc);
}
.pb-sub {
  margin-top: 8px; padding: 6px 16px; border-radius: 14px;
  background: #fffbea; color: #10261d; border: 3px solid #10261d; box-shadow: 0 4px 0 #10261d;
  font-family: Nunito, 'Segoe UI', sans-serif; font-weight: 900; font-size: 17px;
}
#power-banner.show { animation: powerSlam 1.7s ease-out forwards; }
#power-banner.show .pb-icon { animation: iconBounce .6s cubic-bezier(.3, 1.8, .5, 1); }
@keyframes powerSlam {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(2.6) rotate(-6deg); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(.92) rotate(2deg); }
  20% { transform: translate(-50%, -50%) scale(1.06) rotate(-1deg); }
  28% { transform: translate(-50%, -50%) scale(1) rotate(0); }
  80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -62%) scale(.9); }
}
@keyframes iconBounce { from { transform: scale(0) rotate(-40deg); } }

/* Frozen chain: icy screen edges */
#frost {
  position: fixed; inset: 0; pointer-events: none; opacity: 0; transition: opacity .4s;
  box-shadow: inset 0 0 90px 30px rgba(150, 230, 255, .75);
  background: radial-gradient(ellipse at center, transparent 55%, rgba(200, 245, 255, .35));
}
#frost.on { opacity: 1; animation: frostPulse 1.2s ease-in-out infinite alternate; }
#frost.reverse {
  box-shadow: inset 0 0 90px 30px rgba(80, 230, 130, .7);
  background: radial-gradient(ellipse at center, transparent 55%, rgba(120, 255, 170, .25));
  animation: none;
}
#danger.surge { animation: surgeFlash .9s ease-out; }
@keyframes surgeFlash { 0% { opacity: .95; } 100% { opacity: 0; } }
@keyframes frostPulse { to { box-shadow: inset 0 0 120px 40px rgba(150, 230, 255, .9); } }

#info-left {
  position: absolute; top: 12px; left: 16px;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .45);
}
#level-label { font-size: 16px; opacity: .95; }
#score-label { font-size: 28px; }

#progress {
  position: absolute; left: 16px; top: 76px; width: 140px; height: 10px;
  border-radius: 6px; background: rgba(0, 0, 0, .3); overflow: hidden;
}
#progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, #ffd23c, #ff7a1a); transition: width .2s; }

/* Coins */
.coin {
  display: inline-block; width: 22px; height: 22px; border-radius: 50%; vertical-align: middle; flex: none;
  background: radial-gradient(circle at 40% 35%, #fff3a8 0 10%, #ffcc22 30%, #f39a0c 70%, #c26a05 100%);
  box-shadow: inset 0 0 0 3px #e48a08, 0 2px 0 rgba(0, 0, 0, .3);
}
.coin.tiny { width: 16px; height: 16px; box-shadow: inset 0 0 0 2px #e48a08; }
#coins-box {
  position: absolute; top: 14px; right: 16px; display: flex; align-items: center; gap: 6px;
  padding: 4px 14px 4px 6px; border-radius: 20px; font-size: 20px;
  background: rgba(20, 40, 107, .8); border: 3px solid var(--navy);
}
#coins-box.bump { animation: coinBump .5s ease-out; }
@keyframes coinBump { 40% { transform: scale(1.25); } }

/* Buy a Golden ball */
#shop-btn {
  position: absolute; left: 16px; bottom: 16px; width: 76px; padding: 8px 0 6px; border-radius: 16px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: linear-gradient(#ffffff, #dfe9fb); border: 3px solid var(--navy);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .1), 0 4px 0 rgba(0, 0, 0, .3);
  transition: transform .08s;
}
#shop-btn:active { transform: translateY(3px); }
.shop-ball {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; font-size: 18px; line-height: 1;
  background: radial-gradient(circle at 35% 30%, #fffbe0 0 10%, #ffd23a 35%, #c98500 100%);
  box-shadow: 0 0 0 3px #fff, 0 0 14px 4px rgba(255, 194, 26, .8);
  animation: shopSpin 1.6s ease-in-out infinite;
}
@keyframes shopSpin { 50% { box-shadow: 0 0 0 3px #fff, 0 0 22px 8px rgba(255, 194, 26, .95); } }
.shop-price { display: flex; align-items: center; gap: 3px; font-size: 15px; color: var(--navy); }
#shop-btn.cant { filter: grayscale(.85); opacity: .75; }
#shop-btn.cant .shop-ball { animation: none; box-shadow: 0 0 0 3px #fff; }
#shop-btn.loaded { border-color: #ffc21a; }
#shop-btn.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.shop-tip {
  position: absolute; left: 100px; bottom: 30px; max-width: 260px; padding: 8px 12px; border-radius: 12px;
  background: #fffbea; color: #10261d; border: 3px solid #10261d; box-shadow: 0 4px 0 #10261d;
  font: 900 14px Nunito, 'Segoe UI', sans-serif; opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s; pointer-events: none;
}
.shop-tip.show { opacity: 1; transform: none; }

.win-coins { display: flex; align-items: center; gap: 8px; font-size: 26px; color: #ffe14a; text-shadow: 0 2px 0 #7a3b06; }
.win-coins .coin { width: 30px; height: 30px; }
.win-coins small { font-size: 14px; color: #fff; text-shadow: none; opacity: .85; }

#next-ball.golden { background: radial-gradient(circle at 35% 30%, #fffbe0 0 10%, #ffd23a 35%, #c98500 100%); }

#pause-btn {
  position: absolute; right: 16px; bottom: 16px; width: 50px; height: 50px;
  border-radius: 12px; background: linear-gradient(#5aa0ff, #1f5fd6);
  border: 3px solid #0e2a73; box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .25), 0 3px 0 rgba(0, 0, 0, .3);
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
#pause-btn span { width: 7px; height: 20px; background: #fff; border-radius: 2px; }

/* danger vignette */
#danger {
  position: fixed; inset: 0; pointer-events: none; opacity: 0;
  box-shadow: inset 0 0 120px 30px rgba(255, 30, 0, .55);
  transition: opacity .4s;
}
#danger.on { animation: dangerPulse .9s infinite alternate; }
@keyframes dangerPulse { from { opacity: .2; } to { opacity: .8; } }

/* popups */
#popups { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.pop {
  position: absolute; transform: translate(-50%, -50%);
  font-size: 22px; color: #fff; white-space: nowrap;
  text-shadow: 0 2px 0 #1b3a8a, 0 0 6px rgba(0, 0, 0, .5);
  animation: popUp 1s ease-out forwards;
}
.pop.big { font-size: 30px; color: #ffe14a; text-shadow: 0 3px 0 #a0400a, 0 0 8px rgba(0, 0, 0, .5); }
@keyframes popUp {
  0% { opacity: 0; margin-top: 10px; scale: .6; }
  15% { opacity: 1; scale: 1.15; }
  30% { scale: 1; }
  100% { opacity: 0; margin-top: -50px; }
}

#combo-banner {
  position: fixed; left: 50%; top: 32%; transform: translate(-50%, -50%);
  font-size: 54px; color: #ffe14a; pointer-events: none; opacity: 0;
  text-shadow: 0 4px 0 #b4420a, 0 0 18px rgba(0, 0, 0, .5);
  -webkit-text-stroke: 2px #7a2a05;
}
#combo-banner.show { animation: banner 1.1s ease-out; }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.3); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
  35% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -70%) scale(1); }
}

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; padding: 16px;
}
.overlay.dim { background: rgba(5, 20, 10, .55); backdrop-filter: blur(3px); }
.overlay.jungle {
  background:
    radial-gradient(ellipse at 70% 0%, rgba(190, 255, 170, .25), transparent 55%),
    radial-gradient(ellipse at center, rgba(10, 40, 20, .55), rgba(3, 15, 8, .92));
  backdrop-filter: blur(4px);
}

.btn {
  min-width: 200px; padding: 12px 28px; border-radius: 16px;
  font-size: 24px; color: #fff; letter-spacing: .5px;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .35);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .08s;
}
.btn:active { transform: scale(.95); }
.btn.big { font-size: 34px; min-width: 240px; padding: 14px 40px; }
.btn.yellow {
  background: linear-gradient(#ffe25a, #f5a40c); color: #7a3606; text-shadow: 0 1px 0 rgba(255, 255, 255, .5);
  border: 3px solid #a85a05; box-shadow: inset 0 -5px 0 rgba(0, 0, 0, .15), 0 4px 0 #7a3b06;
}
.btn.blue {
  background: linear-gradient(#5aa0ff, #1f5fd6);
  border: 3px solid #0e2a73; box-shadow: inset 0 -5px 0 rgba(0, 0, 0, .2), 0 4px 0 #0e2a73;
}

.card {
  position: relative; width: min(340px, 100%);
  padding: 46px 22px 22px;
  background: linear-gradient(#3b78ea, #1d4fc0);
  border: 5px solid var(--orange); border-radius: 18px;
  box-shadow: 0 0 0 4px #7a3b06, 0 18px 40px rgba(0, 0, 0, .55);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  animation: cardIn .35s cubic-bezier(.2, 1.4, .4, 1);
}
@keyframes cardIn { from { transform: scale(.6); opacity: 0; } }
.ribbon {
  position: absolute; top: -24px; left: 50%; transform: translateX(-50%);
  padding: 8px 34px; font-size: 24px; white-space: nowrap;
  background: linear-gradient(#5da2ff, #1f5fd6);
  border: 3px solid #0e2a73; border-radius: 12px;
  box-shadow: 0 4px 0 #0e2a73;
}
.ribbon.red { background: linear-gradient(#ff6a5a, #c8251a); border-color: #6a0e08; box-shadow: 0 4px 0 #6a0e08; }
.goal-box {
  width: 100%; padding: 10px; border-radius: 10px;
  background: #14286b; border: 2px solid #0a1a4a; text-align: center; font-size: 22px;
}
.goal-box .check { color: #4ee14a; font-size: 34px; line-height: 1; text-shadow: 0 2px 0 #1a6a10; }
.goal-box.fail .check { color: #ff5040; text-shadow: 0 2px 0 #6a0e08; }
.label { font-size: 16px; }
.win-stars { display: flex; justify-content: center; gap: 6px; font-size: 54px; line-height: 1; }
.win-stars span { color: #2a4a9a; -webkit-text-stroke: 3px #0e2a73; paint-order: stroke fill; animation: starPop .45s backwards; }
.win-stars span.on { color: #ffc400; -webkit-text-stroke-color: #7a3b06; }
.win-stars span:nth-child(2) { animation-delay: .15s; transform: translateY(-10px); }
.win-stars span:nth-child(3) { animation-delay: .3s; }
@keyframes starPop { 0% { opacity: 0; scale: .3; } 70% { scale: 1.2; } 100% { opacity: 1; scale: 1; } }
.stats { font-size: 15px; opacity: .9; text-align: center; line-height: 1.4; }
.link-btn { background: none; color: #fff; font-size: 22px; text-shadow: 0 2px 0 rgba(0, 0, 0, .6); padding: 8px 20px; }

@media (max-width: 520px) {
  .panel { width: 96px; height: 52px; }
  .val { font-size: 22px; }
  .val.small { font-size: 12px; }
  #next-wrap { width: 62px; height: 70px; }
  #next-ball { width: 34px; height: 34px; }
  #info-left { top: 64px; }
  #progress { top: 124px; }
  #coins-box { top: 64px; }
}

/* ---------- Phones: notch / home-bar safe areas and touch sizing ---------- */
:root {
  --sa-t: env(safe-area-inset-top, 0px);
  --sa-r: env(safe-area-inset-right, 0px);
  --sa-b: env(safe-area-inset-bottom, 0px);
  --sa-l: env(safe-area-inset-left, 0px);
}
html, body { overscroll-behavior: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
#topbar { top: var(--sa-t); }
#info-left { top: calc(12px + var(--sa-t)); left: calc(16px + var(--sa-l)); }
#progress { top: calc(76px + var(--sa-t)); left: calc(16px + var(--sa-l)); }
#coins-box { top: calc(14px + var(--sa-t)); right: calc(16px + var(--sa-r)); }
#pause-btn { right: calc(16px + var(--sa-r)); bottom: calc(16px + var(--sa-b)); }
#shop-btn { left: calc(16px + var(--sa-l)); bottom: calc(16px + var(--sa-b)); }
.shop-tip { left: calc(102px + var(--sa-l)); bottom: calc(30px + var(--sa-b)); max-width: min(260px, calc(100vw - 120px)); }

/* The next ball doubles as the swap button. */
#next-wrap { position: relative; }
.swap-badge {
  position: absolute; left: 50%; bottom: -11px; transform: translateX(-50%);
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(#5aa0ff, #1f5fd6); border: 2px solid var(--navy); color: #fff; font-size: 13px; line-height: 1;
}

@media (max-width: 520px) {
  #info-left { top: calc(66px + var(--sa-t)); }
  #level-label { font-size: 12px; }
  #score-label { font-size: 22px; }
  #progress { top: calc(122px + var(--sa-t)); width: 110px; }
  #coins-box { top: calc(68px + var(--sa-t)); font-size: 17px; }
  #shop-btn { width: 66px; }
  .shop-ball { width: 34px; height: 34px; }
  .pb-icon { font-size: 50px; }
  .pb-title { font-size: clamp(30px, 9vw, 96px); -webkit-text-stroke-width: 6px; }
  .pb-sub { font-size: 14px; }
  #combo-banner { font-size: 40px; }
}

/* Phones held sideways: a slimmer top bar. */
@media (max-height: 500px) {
  .panel { height: 48px; }
  .tag { margin-top: 3px; font-size: 11px; }
  .val { font-size: 20px; line-height: 24px; }
  .val.small { line-height: 22px; }
  #next-wrap { height: 60px; width: 64px; }
  #next-ball { width: 32px; height: 32px; }
  #progress { top: calc(66px + var(--sa-t)); }
  .pb-icon { font-size: 44px; }
}
