:root {
  --bg: #0b1233;
  --panel: #14205a;
  --fg: #f3f5ff;
  --muted: #9aa5d6;
  --accent: #ff7da0;
  --accent-dark: #c2385e;
  --danger: #ff4a4a;
  --gold: #ffd23f;
  --sky: #5fd0ff;
  --toon: 'Luckiest Guy', 'Arial Rounded MT Bold', 'Trebuchet MS', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: radial-gradient(ellipse at 50% 0%, #22489e 0%, var(--bg) 65%) fixed var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.55;
}

.hidden { display: none !important; }

/* ---------- App shell: fills exactly one screen ---------- */
.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px;
}
.topbar h1 {
  margin: 0;
  font: 22px var(--toon);
  letter-spacing: 1px;
  color: var(--accent);
  text-shadow: 2px 2px 0 var(--accent-dark);
}
.toplink { color: var(--muted); font-size: 13px; }
.toplinks { display: flex; gap: 16px; }

.layout {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  justify-content: center;
  gap: 150px; /* keeps the wide-screen side ad 150px from the game */
  padding: 0 8px;
}
.stage {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 1280px;
  display: flex;
}

#gameWrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #060a20;
  border-radius: 12px;
  box-shadow: 0 0 0 1px rgba(140, 170, 255, .2), 0 10px 40px rgba(0, 0, 0, .6);
}
#gameWrap:fullscreen { border-radius: 0; }

#game {
  display: block;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- In-game buttons ---------- */
.corner-btns {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  z-index: 5;
}
.icon-btn {
  width: 40px;
  height: 40px;
  border: 1px solid rgba(255, 255, 255, .3);
  border-radius: 10px;
  background: rgba(10, 16, 50, .6);
  color: var(--fg);
  font-size: 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { background: rgba(40, 60, 140, .8); }
.icon-btn.off { opacity: .45; }

.boost-btn {
  position: absolute;
  right: 14px;
  bottom: 14px;
  z-index: 3;
  width: 84px;
  height: 84px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 30px;
  line-height: 1;
  color: #fff;
  background: radial-gradient(circle at 40% 35%, #ff9a3c, #d8361c);
  border: 3px solid #fff3;
  border-radius: 50%;
  box-shadow: 0 4px 0 #7a1608, 0 6px 18px rgba(0, 0, 0, .5);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}
.boost-btn span { font: 12px var(--toon); letter-spacing: 1px; }
.boost-btn.on { transform: translateY(3px); box-shadow: 0 1px 0 #7a1608, 0 0 24px rgba(255, 160, 60, .9); }
.boost-btn.empty { filter: grayscale(1); opacity: .5; }
@media (pointer: fine) { .boost-btn { width: 70px; height: 70px; font-size: 24px; } }

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  padding: 56px 16px 16px;
  text-align: center;
  background: rgba(6, 10, 34, .7);
  overflow-y: auto;
}
.overlay > :first-child { margin-top: auto; }
.overlay > :last-child { margin-bottom: auto; }
#menu { background: linear-gradient(rgba(6, 10, 34, .15), rgba(6, 10, 34, .55)); }

.title {
  font: clamp(48px, 11vw, 92px)/0.95 var(--toon);
  color: var(--accent);
  letter-spacing: 2px;
  text-shadow: 0 5px 0 var(--accent-dark), 0 8px 18px rgba(0, 0, 0, .5);
  -webkit-text-stroke: 2px #fff;
}
.title.small { font-size: clamp(34px, 8vw, 54px); color: var(--sky); text-shadow: 0 4px 0 #1a6fa8, 0 6px 14px rgba(0, 0, 0, .5); -webkit-text-stroke: 0; }
.title.red { color: var(--danger); text-shadow: 0 4px 0 #8a1414, 0 6px 14px rgba(0, 0, 0, .5); }
.title.gold { color: var(--gold); text-shadow: 0 4px 0 #9a6a00, 0 6px 14px rgba(0, 0, 0, .5); }

.tag { margin: 0; color: #dfe5ff; font-size: 15px; text-shadow: 0 1px 3px #000; }
.stat { margin: 0; font: 22px var(--toon); color: var(--gold); letter-spacing: 1px; text-shadow: 0 2px 0 #000; }
.stat.small { font-size: 16px; color: #dfe5ff; }
.final { margin: 0; font: 36px var(--toon); color: var(--fg); text-shadow: 0 3px 0 #000; }
.newbest { margin: 0; font: 18px var(--toon); color: var(--gold); animation: pulse-text .8s ease-in-out infinite; }
.hint { margin: 0; max-width: 420px; color: var(--muted); font-size: 13px; }
.row { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }

.btn {
  min-width: 190px;
  padding: 12px 22px;
  font: 20px var(--toon);
  letter-spacing: 1px;
  color: #fff;
  background: linear-gradient(#ff8fb0, #e2547e);
  border: none;
  border-radius: 14px;
  box-shadow: 0 5px 0 var(--accent-dark), 0 8px 16px rgba(0, 0, 0, .4);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform .08s;
}
.btn:hover, .btn:focus-visible { filter: brightness(1.1); outline: none; }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--accent-dark); }
.btn-gold { color: #4a2c00; background: linear-gradient(#ffe57a, #f4b31c); box-shadow: 0 5px 0 #a8700a, 0 8px 16px rgba(0, 0, 0, .4); }
.btn-gold:active { box-shadow: 0 2px 0 #a8700a; }
.btn-dim { min-width: 150px; font-size: 15px; padding: 9px 18px; color: #dfe5ff; background: linear-gradient(#4a5a9a, #2e3a72); box-shadow: 0 4px 0 #1a2350; }
.btn-dim:active { box-shadow: 0 1px 0 #1a2350; }
#doubleBtn { animation: pulse 1.4s ease-in-out infinite; }

@keyframes pulse { 50% { box-shadow: 0 5px 0 #a8700a, 0 0 22px rgba(255, 210, 63, .8); } }
@keyframes pulse-text { 50% { transform: scale(1.12); } }

/* ---------- Results ---------- */
.earn { border-collapse: collapse; min-width: 240px; font-size: 15px; }
.earn td { padding: 3px 10px; text-align: left; color: #dfe5ff; }
.earn td:last-child { text-align: right; color: var(--gold); font-weight: 700; }
.earn tr.total td { border-top: 1px solid rgba(255, 255, 255, .25); padding-top: 6px; font: 20px var(--toon); color: var(--gold); }

/* ---------- Shop ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
  width: min(820px, 100%);
}
.card {
  display: grid;
  grid-template-columns: 44px 1fr;
  grid-template-rows: auto auto auto auto;
  column-gap: 10px;
  row-gap: 3px;
  align-items: center;
  padding: 10px 12px;
  color: var(--fg);
  font-family: inherit;
  text-align: left;
  background: linear-gradient(180deg, rgba(30, 44, 110, .95), rgba(14, 20, 60, .95));
  border: 2px solid rgba(255, 255, 255, .15);
  border-radius: 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.card .icon { grid-row: 1 / span 4; font-size: 32px; line-height: 1; text-align: center; }
.card .name { font: 17px var(--toon); letter-spacing: .5px; color: var(--gold); }
.card .desc { font-size: 12px; color: #c8cfef; line-height: 1.3; }
.card .cost { font: 15px var(--toon); color: #7dff9a; }
.card.poor .cost { color: #ff8a8a; }
.card.maxed { border-color: rgba(125, 255, 154, .5); cursor: default; }
.card.maxed .cost { color: #7dff9a; }
.card:not(.maxed):not(.poor):hover, .card:not(.maxed):not(.poor):focus-visible { border-color: var(--gold); outline: none; box-shadow: 0 0 16px rgba(255, 210, 63, .35); }
.card.poor { cursor: not-allowed; }
.card.bought { animation: bought .4s ease-out; }
@keyframes bought { 40% { transform: scale(1.05); border-color: var(--gold); } }
.pips { display: flex; gap: 3px; flex-wrap: wrap; }
.pips i { width: 12px; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, .18); }
.pips i.on { background: var(--accent); box-shadow: 0 0 5px var(--accent); }

/* ---------- Level list ---------- */
.level-list {
  list-style: none;
  margin: 0;
  padding: 0;
  width: min(380px, 100%);
  display: flex;
  flex-direction: column-reverse;
  gap: 4px;
}
.level-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .06);
  text-align: left;
  font-size: 14px;
}
.level-list li .n { font: 16px var(--toon); width: 26px; color: var(--muted); }
.level-list li .nm { flex: 1; font-weight: 700; }
.level-list li .d { color: var(--muted); font-size: 12px; }
.level-list li.done { background: rgba(255, 125, 160, .18); }
.level-list li.done .n { color: var(--accent); }
.level-list li.locked .nm { color: var(--muted); }

/* ---------- Ad slots ---------- */
.ad-slot { text-align: center; }
.ad-label {
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  opacity: .7;
}
/* At least 150px between the play area and any ad (AdSense game-page guidance).
   computer: banner stays on screen under the game, with a 150px empty gap.
   phone/tablet: the game fills the screen, the banner sits below it and is reached by scrolling. */
.ad-banner { flex: 0 0 auto; margin-top: 150px; padding-bottom: max(4px, env(safe-area-inset-bottom)); }
.scroll-hint { display: none; }
@media (pointer: coarse) {
  .app { height: auto; }
  .topbar { height: 36px; padding-top: 0; padding-bottom: 0; white-space: nowrap; }
  .layout { flex: none; height: calc(100vh - 70px); height: calc(100dvh - 70px); }
  .scroll-hint { display: block; height: 34px; line-height: 34px; text-align: center; font-size: 12px; color: var(--muted); }
  .ad-banner { margin-top: 116px; }
}
@media (pointer: coarse) and (max-width: 480px) {
  .topbar { padding: 0 10px; }
  .topbar h1 { font-size: 16px; }
  .toplinks { gap: 10px; }
  .toplink { font-size: 12px; }
}
@media (pointer: coarse) and (max-height: 500px) {
  .layout { height: calc(100vh - 34px); height: calc(100dvh - 34px); }
}
.ad-banner ins { display: inline-block; width: 320px; height: 50px; }
@media (min-width: 768px) and (min-height: 600px) {
  .ad-banner ins { width: 728px; height: 90px; }
}

.side-ad { display: none; flex: 0 0 160px; flex-direction: column; justify-content: center; }
.side-ad ins { display: inline-block; width: 160px; height: 600px; }
@media (min-width: 1400px) and (min-height: 760px) { .side-ad { display: flex; } }

/* Shown during development, before your AdSense IDs are set */
.ad-placeholder ins {
  background: repeating-linear-gradient(45deg, #14205a, #14205a 10px, #1a2868 10px, #1a2868 20px);
  border: 1px dashed #3a4a9a;
}

/* Landscape phones: give the game every pixel we can */
@media (max-height: 500px) {
  .topbar { display: none; }
  .overlay { gap: 7px; padding-top: 50px; }
  .title { font-size: 44px; }
  .title.small { font-size: 30px; }
  .btn { padding: 8px 18px; font-size: 17px; }
  .boost-btn { width: 68px; height: 68px; font-size: 22px; }
}

/* Short computer screens: the 150px ad gap leaves a shorter game, so compact the menus */
@media (pointer: fine) and (max-height: 820px) {
  .overlay { gap: 7px; padding-top: 50px; }
  .title { font-size: 44px; -webkit-text-stroke: 1.5px #fff; }
  .title.small { font-size: 30px; }
  .btn { padding: 8px 18px; font-size: 17px; }
  .btn-dim { padding: 6px 16px; font-size: 14px; }
  .tag, .hint { font-size: 12px; }
}

/* ---------- Content below the game (also helps AdSense approval) ---------- */
.content {
  max-width: 820px;
  margin: 0 auto;
  padding: 40px 20px 60px;
}
.content h2 { font: 26px var(--toon); letter-spacing: 1px; color: var(--accent); margin: 36px 0 10px; }
.content li { margin-bottom: 6px; }
.content a { color: var(--gold); }
kbd {
  display: inline-block;
  padding: 1px 6px;
  font: 12px ui-monospace, monospace;
  border: 1px solid #3a4a9a;
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--panel);
}
footer { margin-top: 48px; color: var(--muted); font-size: 13px; text-align: center; }
.btn-gold.glow { animation: pulse 1.4s ease-in-out infinite; }
.overlay .hint { color: #e6eaff; text-shadow: 0 1px 3px #000, 0 0 6px rgba(0, 0, 0, .6); }
.stat.money { color: #7dff9a; }
.btn-reset { min-width: 0; margin-top: 6px; padding: 7px 14px; font-size: 12px; color: #ffb3b3; background: transparent; border: 1px solid rgba(255, 120, 120, .5); box-shadow: none; }
.btn-reset:hover, .btn-reset:focus-visible { background: rgba(255, 80, 80, .15); }
.btn-reset:active { box-shadow: none; }
.card .icon .img-icon { display: block; width: 44px; height: 44px; margin: 0 auto; }
