:root {
  --grass-1: #7dd87d;
  --grass-2: #2e7a2e;
  --dirt:    #8a5a33;
  --dirt-d:  #432d19;
  --gold:    #f4c542;
  --gold-d:  #d4a422;
  --red:     #e53935;
  --red-d:   #b71c1c;
  --cream:   #fff5d6;
  --ink:     #231712;
  --ink-2:   #3b2616;
  --pink:    #ff8fb1;
  --blue:    #4a90e2;

  --shadow-hard: 0 4px 0 var(--ink);
  --radius: 14px;
  --font: "Fredoka", "Comic Sans MS", "Chalkboard SE", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: #0a0604;
  color: var(--cream);
  font-family: var(--font);
  overflow: hidden;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
canvas#game {
  touch-action: none;
}

body {
  display: flex;
  flex-direction: column;
}

/* AD SLOTS */
.ad-slot {
  width: 100%;
  min-height: 50px;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #666;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 2px;
  flex-shrink: 0;
}
.ad-slot--top { border-bottom: 1px solid rgba(255,255,255,0.05); }
.ad-slot--bottom { border-top: 1px solid rgba(255,255,255,0.05); }
.ad-slot[hidden] { display: none; }

#game-shell {
  position: relative;
  flex: 1;
  width: 100%;
  overflow: hidden;
  background: radial-gradient(ellipse at top, #ffe5b0 0%, #ffb86b 55%, #c86b2a 100%);
}

canvas#game {
  display: block;
  width: 100%;
  height: 100%;
  cursor: none;
  image-rendering: auto;
}

/* HUD */
.hud {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 12px; right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  z-index: 5;
  gap: 8px;
}
.hud__left, .hud__right {
  display: flex;
  gap: 8px;
  align-items: center;
  pointer-events: auto;
}
.hud__pill {
  background: rgba(0,0,0,0.55);
  padding: 8px 14px;
  border-radius: 999px;
  border: 2px solid var(--gold);
  font-size: 18px;
  font-weight: 700;
  color: var(--cream);
  text-shadow: 1px 1px 0 #000;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 70px;
  justify-content: center;
  backdrop-filter: blur(6px);
}
.hud__pill--combo {
  border-color: var(--red);
  background: rgba(229, 57, 53, 0.85);
  animation: combo-pulse 0.4s ease-out;
}
.hud__pill--time { border-color: #7dd87d; }
.hud__pill--lives { border-color: #ff4d6d; padding: 8px 12px; letter-spacing: 1px; }
.hud__icon { font-size: 16px; }

@keyframes combo-pulse {
  0% { transform: scale(1.4); }
  100% { transform: scale(1); }
}

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 2px solid var(--gold);
  background: rgba(0,0,0,0.55);
  color: var(--cream);
  font-size: 18px;
  cursor: pointer;
  display: grid;
  place-items: center;
  backdrop-filter: blur(6px);
  transition: transform 0.1s, background 0.15s;
}
.icon-btn:hover { background: rgba(0,0,0,0.75); transform: scale(1.05); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn--ghost {
  border-color: rgba(255, 245, 214, 0.4);
  background: rgba(255, 255, 255, 0.1);
}

/* POWER BAR */
.power-bar {
  position: absolute;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: min(320px, 70vw);
  height: 18px;
  background: rgba(0,0,0,0.5);
  border: 2px solid var(--gold);
  border-radius: 999px;
  overflow: hidden;
  z-index: 5;
  pointer-events: none;
}
.power-bar__fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ffdd55, #ff8800);
  transition: width 0.15s ease-out;
  box-shadow: 0 0 10px var(--gold) inset;
}
.power-bar__label {
  position: absolute;
  inset: 0;
  display: grid; place-items: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--cream);
  text-shadow: 1px 1px 0 #000;
}
.power-bar.ready .power-bar__fill { animation: power-ready 0.6s infinite alternate; }
@keyframes power-ready {
  from { filter: brightness(1); }
  to { filter: brightness(1.4) drop-shadow(0 0 8px var(--gold)); }
}

/* COMBO BANNER */
.combo-banner {
  position: absolute;
  top: 42%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.2);
  font-size: clamp(40px, 9vw, 80px);
  font-weight: 900;
  color: var(--gold);
  text-shadow:
    4px 4px 0 #000,
    -2px -2px 0 #000,
    2px -2px 0 #000,
    -2px 2px 0 #000,
    0 0 20px rgba(244, 197, 66, 0.6);
  pointer-events: none;
  letter-spacing: 2px;
  opacity: 0;
  z-index: 6;
  white-space: nowrap;
}
.combo-banner.show {
  animation: combo-pop 0.7s cubic-bezier(.34,1.56,.64,1) forwards;
}
@keyframes combo-pop {
  0% { transform: translate(-50%, -50%) scale(0.2) rotate(-20deg); opacity: 0; }
  20% { transform: translate(-50%, -50%) scale(1.2) rotate(-6deg); opacity: 1; }
  70% { transform: translate(-50%, -50%) scale(1) rotate(-6deg); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1.4) rotate(-6deg); opacity: 0; }
}

/* OVERLAYS */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,0.72);
  backdrop-filter: blur(8px);
  z-index: 20;
  padding: 20px;
  animation: overlay-in 0.25s ease-out;
}
/* Secondary overlays (leaderboard, how-to, privacy, name prompt, pause)
   must stack above the main title overlay */
#lbOverlay, #howOverlay, #privacyOverlay, #nameOverlay, #pauseOverlay {
  z-index: 30;
}
.overlay[hidden] { display: none; }

@keyframes overlay-in {
  from { opacity: 0; backdrop-filter: blur(0); }
  to { opacity: 1; backdrop-filter: blur(8px); }
}

.panel {
  background: var(--cream);
  color: var(--ink);
  padding: 28px 32px;
  border-radius: 20px;
  border: 5px solid var(--red);
  text-align: center;
  max-width: 460px;
  width: 100%;
  box-shadow: 0 12px 40px rgba(0,0,0,0.6), inset 0 -6px 0 rgba(0,0,0,0.1);
  animation: panel-in 0.35s cubic-bezier(.34,1.56,.64,1);
  max-height: 90vh;
  overflow-y: auto;
}

@keyframes panel-in {
  from { transform: scale(0.7) rotate(-2deg); opacity: 0; }
  to { transform: scale(1) rotate(0); opacity: 1; }
}

.panel h2 {
  font-size: 32px;
  color: var(--red);
  margin-bottom: 16px;
  letter-spacing: 1px;
  text-shadow: 2px 2px 0 var(--gold);
}

/* TITLE LOGO */
.logo {
  margin-bottom: 16px;
}
.logo__main {
  font-size: clamp(48px, 11vw, 72px);
  font-weight: 900;
  color: var(--red);
  letter-spacing: 2px;
  text-shadow:
    3px 3px 0 var(--gold),
    6px 6px 0 var(--ink);
  line-height: 1;
  transform: rotate(-2deg);
}
.logo__dash {
  color: var(--gold);
  display: inline-block;
  transform: scale(1.4) translateY(-4px);
  text-shadow: 3px 3px 0 var(--ink);
}
.logo__sub {
  font-size: 14px;
  color: #7a4a1a;
  margin-top: 8px;
  font-weight: 500;
  letter-spacing: 1px;
}

.title-trum {
  width: 120px; height: 120px;
  margin: 12px auto;
  background: radial-gradient(circle at 35% 30%, #ffc080 0%, #f4a261 60%, #c86b2a 100%);
  border-radius: 50%;
  position: relative;
  animation: trum-wiggle 2s ease-in-out infinite;
  box-shadow: 0 6px 0 var(--ink);
}
.title-trum::before {
  content: '';
  position: absolute;
  top: -20%; left: 10%;
  width: 80%; height: 50%;
  background: var(--gold);
  border-radius: 50% 50% 40% 60%;
  transform: rotate(-8deg);
  box-shadow: 2px 2px 0 var(--gold-d);
}
.title-trum::after {
  content: '👀';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 32px;
}
@keyframes trum-wiggle {
  0%, 100% { transform: rotate(-4deg); }
  50% { transform: rotate(4deg); }
}

/* MODES */
.modes {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 20px 0;
}
.mode-btn {
  width: 100%;
  padding: 14px 20px;
  background: white;
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: var(--shadow-hard);
  cursor: pointer;
  font-family: inherit;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  transition: transform 0.1s, box-shadow 0.1s;
}
.mode-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 0 var(--ink); }
.mode-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--ink); }
.mode-btn--primary {
  background: var(--gold);
  color: var(--ink);
}
.mode-btn__title {
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 1px;
}
.mode-btn__desc {
  font-size: 12px;
  color: #666;
}
.mode-btn--primary .mode-btn__desc { color: rgba(0,0,0,0.6); }

.title-footer {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: 12px 0;
}
.title-footer .icon-btn {
  width: 44px; height: 44px;
  background: white;
  color: var(--ink);
  border-color: var(--ink);
  box-shadow: var(--shadow-hard);
}

.disclaimer {
  font-size: 10px;
  color: #999;
  margin-top: 12px;
  line-height: 1.5;
  font-style: italic;
}

/* BUTTONS */
.btn {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 14px 24px;
  font-size: 20px;
  font-weight: 900;
  font-family: inherit;
  background: var(--red);
  color: white;
  border: 3px solid var(--ink);
  border-radius: 12px;
  cursor: pointer;
  box-shadow: var(--shadow-hard);
  transition: transform .1s, box-shadow .1s;
  letter-spacing: 1px;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 6px 0 var(--ink); }
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--ink); }
.btn--primary { background: var(--red); }
.btn--ghost { background: white; color: var(--ink); }
.btn--revive {
  background: linear-gradient(135deg, #ffdd55, #ff9500);
  color: var(--ink);
  border-color: var(--ink);
  animation: pulse-glow 1.4s infinite;
}
.btn--small { font-size: 14px; padding: 10px 16px; }

@keyframes pulse-glow {
  0%, 100% { box-shadow: var(--shadow-hard), 0 0 0 rgba(255, 221, 85, 0); }
  50% { box-shadow: var(--shadow-hard), 0 0 20px rgba(255, 221, 85, 0.8); }
}

/* STATS (gameover) */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 18px 0;
}
.stat {
  background: white;
  border: 2px solid var(--ink);
  border-radius: 10px;
  padding: 12px 6px;
  box-shadow: 0 3px 0 var(--ink);
}
.stat__label {
  display: block;
  font-size: 10px;
  color: #666;
  letter-spacing: 1px;
  margin-bottom: 4px;
}
.stat__val {
  display: block;
  font-size: 24px;
  font-weight: 900;
  color: var(--red);
}

.gameover__sub {
  color: #7a4a1a;
  font-size: 14px;
  font-style: italic;
  margin-bottom: 4px;
}

.revive {
  margin: 12px 0;
  padding: 12px;
  background: rgba(244, 197, 66, 0.15);
  border: 2px dashed var(--gold-d);
  border-radius: 10px;
}
.revive__note {
  font-size: 10px;
  color: #888;
  margin-top: 6px;
}

/* HOW-TO list */
.how-list {
  list-style: none;
  text-align: left;
  margin: 18px 0;
}
.how-list li {
  padding: 10px;
  margin-bottom: 6px;
  background: rgba(244, 197, 66, 0.15);
  border-left: 4px solid var(--gold);
  border-radius: 6px;
  font-size: 15px;
  line-height: 1.4;
}
.how-list b { color: var(--red); }

.panel--text p {
  text-align: left;
  margin: 10px 0;
  font-size: 14px;
  line-height: 1.5;
}
.panel--text a { color: var(--red); }

/* LEADERBOARD */
.panel--lb { max-width: 500px; }
.tabs {
  display: flex;
  gap: 4px;
  margin: 12px 0 8px;
  background: rgba(0,0,0,0.05);
  padding: 4px;
  border-radius: 10px;
}
.tabs--sub .tab {
  font-size: 11px;
  padding: 6px 8px;
}
.tab {
  flex: 1;
  padding: 8px 10px;
  background: transparent;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-weight: 700;
  font-size: 13px;
  color: #888;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.5px;
}
.tab:hover { color: var(--ink); }
.tab--active {
  background: var(--red);
  color: white;
  box-shadow: 0 2px 0 var(--ink);
}
.lb-list {
  list-style: none;
  max-height: 45vh;
  overflow-y: auto;
  margin: 10px 0 14px;
  padding: 0;
  text-align: left;
  background: white;
  border: 2px solid var(--ink);
  border-radius: 10px;
}
.lb-list::-webkit-scrollbar { width: 8px; }
.lb-list::-webkit-scrollbar-thumb { background: var(--red); border-radius: 4px; }
.lb-row {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(0,0,0,0.08);
  font-size: 15px;
}
.lb-row:last-child { border-bottom: none; }
.lb-row--me {
  background: linear-gradient(90deg, rgba(244, 197, 66, 0.3), transparent);
  font-weight: 700;
}
.lb-rank {
  font-weight: 900;
  font-size: 18px;
  color: #888;
  text-align: center;
}
.lb-row--top1 .lb-rank { color: #f4c542; font-size: 22px; }
.lb-row--top2 .lb-rank { color: #bbb; font-size: 20px; }
.lb-row--top3 .lb-rank { color: #c87533; font-size: 19px; }
.lb-name {
  font-weight: 700;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lb-score {
  font-weight: 900;
  color: var(--red);
  font-size: 16px;
}
.lb-empty {
  padding: 30px;
  text-align: center;
  color: #888;
  font-style: italic;
}
.lb-meta {
  font-size: 10px;
  color: #888;
  margin-left: 6px;
  font-weight: 500;
}

/* NAME INPUT */
.name-input {
  width: 100%;
  padding: 14px 18px;
  font-size: 22px;
  font-family: inherit;
  font-weight: 700;
  text-align: center;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: white;
  color: var(--ink);
  margin: 12px 0 6px;
  box-shadow: inset 0 3px 0 rgba(0,0,0,0.1);
  letter-spacing: 1px;
  text-transform: uppercase;
}
.name-input:focus {
  outline: none;
  border-color: var(--red);
  box-shadow: 0 0 0 4px rgba(229, 57, 53, 0.2), inset 0 3px 0 rgba(0,0,0,0.1);
}
.name-prompt__sub { color: #7a4a1a; font-size: 14px; }
.name-prompt__hint { font-size: 11px; color: #888; margin-bottom: 8px; }

/* RANK BADGE */
.rank-badge {
  background: linear-gradient(135deg, #ffdd55, #ff9500);
  color: var(--ink);
  font-weight: 900;
  padding: 10px 16px;
  border-radius: 12px;
  border: 3px solid var(--ink);
  box-shadow: var(--shadow-hard);
  margin: 12px 0;
  font-size: 18px;
  letter-spacing: 1px;
}

/* RESPONSIVE */
@media (max-width: 480px) {
  .panel { padding: 20px; }
  .mode-btn { padding: 12px 14px; }
  .mode-btn__title { font-size: 18px; }
  .hud__pill { padding: 6px 10px; font-size: 16px; min-width: 60px; }
  .icon-btn { width: 36px; height: 36px; font-size: 16px; }
}

@media (min-width: 768px) {
  .ad-slot { min-height: 90px; }
}
