@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;600;700;800&display=swap');
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { -webkit-tap-highlight-color: transparent; }

:root {
  --green-dark: #1a3a1a; --green-mid: #2d5a1b; --green-light: #4a8c2a;
  --leaf: #6abf3a; --yellow: #f5c842; --orange: #f5823a; --red: #e84040;
  --cream: #fffbe6; --ui-bg: rgba(10,30,10,0.82); --ui-border: #4a8c2a;
  --font-title: 'Baloo 2', cursive; --font-body: 'Baloo 2', sans-serif;
}

body {
  background: var(--green-dark);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100vh; font-family: var(--font-body); font-weight: 700; overflow: hidden; user-select: none;
}

/* ── Splash ── */
#splash-screen {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background-color: #000000; display: flex; justify-content: center; align-items: center;
  z-index: 99999; transition: opacity 0.3s ease;
}
#splash-logo { max-width: 40%; max-height: 50vh; object-fit: contain; }

#gameWrapper { position: relative; width: 480px; max-width: 100vw; transform-origin: center center; }
#gameScreen { position: relative; }
canvas {
  display: block; border-radius: 18px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.7), 0 0 0 3px var(--ui-border);
  cursor: default; width: 100%;
}

/* ── HUD ── */
#hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 12px 16px; pointer-events: none; z-index: 10; gap: 6px;
}
.hud-pill {
  background: var(--ui-bg); border: 2px solid var(--ui-border); border-radius: 30px;
  padding: 4px 14px; color: var(--cream); font-family: var(--font-title); font-size: 18px;
  letter-spacing: 0.5px; display: flex; align-items: center; gap: 6px;
}
.hud-pill span.label {
  font-family: var(--font-body); font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1px; color: var(--leaf); margin-right: 2px;
}
#hudPowerups {
  position: absolute; top: 54px; left: 16px; z-index: 10;
  display: flex; gap: 6px; pointer-events: none;
}
.powerup-chip {
  background: var(--ui-bg); border: 2px solid var(--ui-border); border-radius: 20px;
  width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
  font-size: 16px; position: relative; overflow: hidden;
}
.powerup-chip .fill {
  position: absolute; bottom: 0; left: 0; right: 0; background: rgba(90,200,250,0.35);
  height: 100%; transform-origin: bottom; transition: transform 0.1s linear;
}
.powerup-chip span { position: relative; z-index: 1; }
.powerup-chip .chip-icon { position: relative; z-index: 1; width: 20px; height: 20px; object-fit: contain; }

/* ── Buttons (music/back) ── */
#musicBtn, #backBtn, #pauseBtn, #leaderBtn, #achieveBtn {
  position: absolute; z-index: 15;
  background: var(--ui-bg); border: 2px solid var(--ui-border); border-radius: 50%;
  width: 38px; height: 38px; cursor: pointer; font-size: 18px;
  display: flex; align-items: center; justify-content: center; transition: background .15s;
}
#musicBtn:hover, #backBtn:hover, #pauseBtn:hover, #leaderBtn:hover, #achieveBtn:hover { background: var(--green-mid); }
#musicBtn { bottom: 14px; right: 14px; }
#backBtn  { bottom: 14px; left: 14px; display: none; }
#backBtn.visible { display: flex; }
#pauseBtn { bottom: 14px; left: 50%; transform: translateX(-50%); display: none; }
#pauseBtn.visible { display: flex; }
.home-icon { width: 20px; height: 20px; object-fit: contain; display: block; }
.pause-icon { display: flex; gap: 4px; }
.pause-icon span { width: 4px; height: 14px; background: #fff; border-radius: 1px; }

/* ── Overlays ── */
.overlay {
  display: none; position: absolute; inset: 0; background: rgba(5,18,5,0.88);
  border-radius: 18px; flex-direction: column; align-items: center;
  gap: 14px; z-index: 20; backdrop-filter: blur(4px); padding: 20px;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.overlay::before, .overlay::after { content: ''; flex: 1 0 auto; min-height: 0; }
.overlay.active { display: flex; }
.overlay h1 { font-family: var(--font-title); font-weight: 800; font-size: 42px; color: var(--yellow); text-shadow: 0 4px 18px rgba(245,200,66,0.4); line-height: 1; text-align: center; }
.overlay h2 { font-family: var(--font-title); font-weight: 700; font-size: 26px; color: var(--leaf); }

/* ── Main menu title row + swaying sloth icon ── */
.title-row { display: flex; align-items: center; justify-content: center; gap: 8px; }
.menu-sloth {
  width: 58px; height: 58px; object-fit: contain;
  animation: slothSway 3.2s ease-in-out infinite;
  transform-origin: 50% 85%;
}
@keyframes slothSway {
  0%, 100% { transform: rotate(-8deg); }
  50%      { transform: rotate(8deg); }
}
.overlay p  { color: var(--cream); font-size: 13px; text-align: center; max-width: 320px; line-height: 1.6; opacity: 0.85; }

/* ── Instructions ── */
.instr-list { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 340px; }
.instr-row {
  display: flex; align-items: center; gap: 12px; text-align: left;
  background: rgba(255,255,255,0.05); border: 2px solid rgba(255,255,255,0.1);
  border-radius: 12px; padding: 8px 12px;
}
.instr-icon { font-size: 20px; white-space: nowrap; }
.instr-icon-imgs { display: flex; gap: 3px; align-items: center; }
.instr-icon-imgs img { width: 22px; height: 22px; object-fit: contain; }
.instr-icon-arrow { color: #ffffff; font-weight: 900; }
.instr-text { color: var(--cream); font-size: 13px; line-height: 1.35; opacity: 0.92; }
.instr-text b { color: var(--yellow); }

/* ── Music note icon (white PNG asset — no emoji color quirks) ── */
.music-icon { position: relative; display: inline-block; width: 17px; height: 17px; vertical-align: middle; }
.music-icon img { width: 100%; height: 100%; object-fit: contain; display: block; }
.music-icon.muted::after {
  content: ''; position: absolute; left: -3px; top: 50%; width: calc(100% + 6px);
  height: 2px; background: var(--red); transform: rotate(-45deg);
}
#musicBtn .music-icon { width: 18px; height: 18px; }
.credits-line { font-size: 11px; color: rgba(255,255,255,0.45); text-align: center; }
.overlay .score-big { font-family: var(--font-title); font-size: 52px; color: #fff; line-height: 1; }
.overlay .hi-label  { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 2px; color: var(--yellow); }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.btn-col { display: flex; flex-direction: column; gap: 10px; width: 220px; }
.btn-col .btn { width: 100%; text-align: center; }
.btn {
  font-family: var(--font-title); font-size: 18px; padding: 11px 30px;
  border: none; border-radius: 50px; cursor: pointer;
  transition: transform .12s, box-shadow .12s; letter-spacing: 0.5px;
}
.btn:active { transform: scale(0.95); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; transform: none !important; }
.btn { font-weight: 700; }
.btn-primary { background: linear-gradient(135deg, #6abf3a, #4a8c2a); color: #fff; box-shadow: 0 4px 18px rgba(106,191,58,0.45); }
.btn-primary:hover { box-shadow: 0 6px 24px rgba(106,191,58,0.65); transform: translateY(-2px); }
.btn-shop { background: linear-gradient(135deg, #f5c842, #f5823a); color: #2d1a00; box-shadow: 0 4px 18px rgba(245,200,66,0.4); }
.btn-shop:hover { box-shadow: 0 6px 24px rgba(245,200,66,0.6); transform: translateY(-2px); }
.btn-ghost { background: rgba(255,255,255,0.08); color: var(--cream); border: 2px solid rgba(255,255,255,0.18); }
.btn-ghost:hover { background: rgba(255,255,255,0.15); }

/* ── Progress overlay tabs (Achievements / Daily / Leaderboard) ── */
.progress-tabs { margin-bottom: 4px; }
.btn-tab {
  background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.6);
  border: 2px solid rgba(255,255,255,0.12); font-size: 13px; padding: 8px 14px;
}
.btn-tab.active { background: rgba(106,191,58,0.18); border-color: var(--leaf); color: var(--cream); }
.progress-panel { width: 100%; display: flex; flex-direction: column; align-items: center; }

/* ── Mini leaderboard on start screen ── */
.mini-leaderboard { display:flex; flex-direction:column; gap:8px; width: 260px; }
.mini-leaderboard .row { display:flex; justify-content:space-between; font-size:18px; font-weight:700; color: var(--cream); opacity:0.9; padding: 4px 2px; }
.mini-leaderboard .row b { color: var(--yellow); font-size: 20px; }

/* ── Shop ── */
#shopOverlay h2 { font-size: 30px; color: var(--yellow); }
.shop-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; justify-items: center; max-width: 440px; }
.skin-card {
  background: rgba(255,255,255,0.06); border: 2px solid rgba(255,255,255,0.12);
  border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column;
  align-items: center; gap: 6px; cursor: pointer;
  transition: border-color .15s, background .15s; width: 100%; box-sizing: border-box;
}
.skin-card:hover { border-color: var(--leaf); background: rgba(106,191,58,0.1); }
.skin-card.owned  { border-color: var(--yellow); }
.skin-card.active-skin { border-color: #fff; background: rgba(255,255,255,0.1); }
.skin-swatch { width: 52px; height: 52px; background-size: contain; background-position: center; background-repeat: no-repeat; }
.skin-name  { font-size: 11px; font-weight: 700; color: var(--cream); text-transform: uppercase; letter-spacing: 1px; }
.skin-price { font-size: 10px; color: var(--yellow); font-weight: 700; }
.shop-coins { font-family: var(--font-title); font-size: 22px; color: var(--yellow); }
#shopMsg { font-size: 13px; color: var(--leaf); min-height: 18px; font-weight: 700; }

/* ── Achievements overlay ── */
.achieve-list { display:flex; flex-direction:column; gap:8px; max-height: 320px; overflow-y:auto; width: 100%; max-width: 380px; }
.achieve-item {
  display:flex; align-items:center; gap:10px; padding: 8px 12px; border-radius: 12px;
  background: rgba(255,255,255,0.05); border: 2px solid rgba(255,255,255,0.1);
}
.achieve-item.unlocked { border-color: var(--yellow); background: rgba(245,200,66,0.08); }
.achieve-icon { font-size: 22px; width: 30px; text-align:center; }
.achieve-icon-img { width: 24px; height: 24px; object-fit: contain; vertical-align: middle; }
.achieve-text { display:flex; flex-direction:column; flex: 1; min-width: 0; }
.achieve-text .name { font-family: var(--font-title); font-size: 14px; color: var(--cream); }
.achieve-text .desc { font-size: 11px; color: rgba(255,255,255,0.55); }
.achieve-item.locked .achieve-icon { filter: grayscale(1); opacity: 0.4; }
.achieve-item.locked .name { opacity: 0.5; }
.achieve-item.claimed { border-color: rgba(106,191,58,0.4); }
.btn-claim {
  font-family: var(--font-title); font-weight: 700; font-size: 12px;
  background: linear-gradient(135deg, #f5c842, #f5823a); color: #2d1a00;
  border: none; border-radius: 20px; padding: 6px 12px; cursor: pointer;
  white-space: nowrap; box-shadow: 0 3px 10px rgba(245,200,66,0.4);
  transition: transform .12s;
}
.btn-claim:hover { transform: translateY(-1px); }
.btn-claim:active { transform: scale(0.94); }

/* ── Daily challenge progress bar ── */
.challenge-bar {
  width: 100%; height: 5px; border-radius: 3px; margin-top: 4px;
  background: rgba(255,255,255,0.1); overflow: hidden;
}
.challenge-fill {
  height: 100%; background: linear-gradient(90deg, #6abf3a, #f5c842);
  border-radius: 3px; transition: width .2s ease;
}

/* ── Toasts ── */
#toastWrap {
  position: absolute; top: 150px; left: 50%; transform: translateX(-50%);
  z-index: 30; display: flex; flex-direction: column; gap: 6px; align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--ui-bg); border: 2px solid var(--yellow); border-radius: 20px;
  padding: 6px 18px; color: var(--cream); font-family: var(--font-title); font-size: 14px;
  opacity: 0; transform: translateY(-10px); transition: opacity .25s ease, transform .25s ease;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-icon { width: 18px; height: 18px; object-fit: contain; vertical-align: middle; margin-right: 4px; }

/* ── Touch controls ── */
#touchControls { display: none; justify-content: space-between; width: 100%; padding: 10px 4px 0; }
.touch-btn {
  background: var(--ui-bg); border: 2px solid var(--ui-border); color: var(--cream);
  font-size: 28px; height: 56px; border-radius: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex: 1; margin: 0 4px; transition: background .1s;
}
.touch-btn:active { background: var(--green-mid); }
#touchControls.inactive {
  opacity: 0.35; filter: grayscale(1) blur(0.5px); pointer-events: none;
  transition: opacity .2s ease, filter .2s ease;
}
.touch-btn-jump {
  flex: 0.8; border-color: var(--yellow); color: var(--yellow); font-weight: 700;
}
.touch-btn-jump:active { background: rgba(245,200,66,0.25); }
@media (max-width: 520px) { #touchControls { display: flex; } }
@media (hover: none)      { #touchControls { display: flex; } }

/* ── Rotate overlay ── */
#rotate-overlay {
  display:none; position:fixed; inset:0; z-index:99999; background:#1a3a1a;
  flex-direction:column; align-items:center; justify-content:center; gap:24px;
}
#rotate-icon { font-size:72px; display:inline-block; animation: rotateHint 1.6s ease-in-out infinite; }
@keyframes rotateHint {
  0%   { transform: rotate(0deg);   opacity: 1;   }
  45%  { transform: rotate(-90deg); opacity: 0.6; }
  55%  { transform: rotate(-90deg); opacity: 0.6; }
  100% { transform: rotate(0deg);   opacity: 1;   }
}
