/* Bug Bash 2 */
* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%;
  background: #14100a;
  overflow: hidden;
  font-family: "Nunito", "Trebuchet MS", "Segoe UI", sans-serif;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
}

h1, h2, h3, .btn, .logo, #banner-big, #hud, .level-card .lv-num, #end-title {
  font-family: "Fredoka", "Trebuchet MS", sans-serif;
}

#game-wrap {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
}

#game {
  display: block;
  background: #1c150c;
  cursor: none;
  touch-action: none; /* not inherited — without this, mobile drags become scroll gestures */
}

.hidden { display: none !important; }

/* ---------- Loading: a little green caterpillar inching along ---------- */
#boot {
  position: absolute;
  display: flex; flex-direction: column;
  align-items: center;
  gap: 18px;
}
.boot-cat {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  animation: catCrawl 2.6s ease-in-out infinite alternate;
}
.boot-cat .seg {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #c9f59a, #79c43f 55%, #4c8a33);
  box-shadow: inset 0 -3px 0 rgba(30, 60, 12, .45), 0 4px 6px rgba(0,0,0,.45);
  animation: catWave 0.9s ease-in-out infinite;
}
.boot-cat .seg:nth-child(1) { animation-delay: 0s; }
.boot-cat .seg:nth-child(2) { animation-delay: .09s; }
.boot-cat .seg:nth-child(3) { animation-delay: .18s; }
.boot-cat .seg:nth-child(4) { animation-delay: .27s; }
.boot-cat .seg:nth-child(5) { animation-delay: .36s; }
.boot-cat .seg:nth-child(6) { animation-delay: .45s; }
.boot-cat .head {
  width: 28px; height: 28px;
  position: relative;
  background: radial-gradient(circle at 32% 28%, #d6f8ac, #8ad14e 55%, #569339);
}
.boot-cat .head::before, .boot-cat .head::after { /* eyes */
  content: '';
  position: absolute;
  top: 7px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #fff;
  box-shadow: inset -2px 0 0 1px #1a1208;
}
.boot-cat .head::before { right: 3px; }
.boot-cat .head::after { right: 13px; }
@keyframes catWave {
  0%, 100% { transform: translateY(0) scaleY(1); }
  40% { transform: translateY(-9px) scaleY(1.08); }
  70% { transform: translateY(0) scaleY(.92); }
}
@keyframes catCrawl {
  from { transform: translateX(-46px); }
  to   { transform: translateX(46px); }
}
.boot-text {
  color: rgba(255, 233, 179, .85);
  font-size: 19px;
  letter-spacing: 3px;
  font-family: "Fredoka", sans-serif;
  font-weight: 600;
}
.boot-dots span {
  animation: dotBlink 1.3s infinite;
  opacity: 0;
}
.boot-dots span:nth-child(2) { animation-delay: .35s; }
.boot-dots span:nth-child(3) { animation-delay: .7s; }
@keyframes dotBlink {
  0% { opacity: 0; }
  30%, 70% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---------- Rotate-your-device overlay (portrait phones) ---------- */
#rotate-overlay { display: none; }
@media (orientation: portrait) and (pointer: coarse) {
  #rotate-overlay {
    display: flex;
    position: fixed; inset: 0;
    z-index: 50;
    flex-direction: column;
    align-items: center; justify-content: center;
    gap: 26px;
    background: #14100a;
    color: #ffe9b3;
    font-family: "Fredoka", "Trebuchet MS", sans-serif;
    font-size: 18px;
    letter-spacing: 1px;
    text-align: center;
  }
}
.rotate-phone {
  width: 44px; height: 78px;
  border: 4px solid #ffc93c;
  border-radius: 10px;
  position: relative;
  animation: phoneTurn 2.2s ease-in-out infinite;
}
.rotate-phone::after { /* home indicator */
  content: '';
  position: absolute;
  left: 50%; bottom: 5px;
  width: 18px; height: 3px;
  margin-left: -9px;
  border-radius: 3px;
  background: #ffc93c;
}
@keyframes phoneTurn {
  0%, 20% { transform: rotate(0); }
  55%, 85% { transform: rotate(-90deg); }
  100% { transform: rotate(0); }
}

/* ---------- Screens ---------- */
.screen {
  position: absolute;
  display: flex; flex-direction: column;
  align-items: center;
  /* NOT justify-content: center — that pushes overflowing content above the
     scroll start, making the top unreachable (level grid on phones). The auto
     margins below center short content and yield gracefully on overflow. */
  justify-content: flex-start;
  gap: 16px;
  background: linear-gradient(rgba(12, 8, 3, .55), rgba(12, 8, 3, .72));
  padding: 20px;
  text-align: center;
  overflow-y: auto;
}
.screen > :first-child { margin-top: auto; }
.screen > :last-child { margin-bottom: auto; }

.screen h2 {
  color: #ffe9b3;
  font-size: clamp(26px, 5vw, 46px);
  font-weight: 700;
  letter-spacing: 2px;
  text-shadow: 0 4px 0 rgba(58, 36, 8, .9), 0 8px 22px rgba(0,0,0,.6);
}

.logo {
  font-size: clamp(44px, 10vw, 96px);
  letter-spacing: 4px;
  color: #aee571;
  text-shadow: 0 5px 0 #2c4a12, 0 9px 18px rgba(0,0,0,.6);
  transform: rotate(-2deg);
}
.logo-img {
  display: block;
  width: clamp(280px, 56vw, 640px);
  filter: drop-shadow(0 12px 22px rgba(0,0,0,.6));
}
.logo-accent { color: #f3c11d; text-shadow: 0 5px 0 #7a5a05, 0 9px 18px rgba(0,0,0,.6); }
.logo-two    { color: #ff6f61; text-shadow: 0 5px 0 #7a241c, 0 9px 18px rgba(0,0,0,.6); }

.tagline {
  color: #ffe9b3;
  font-size: clamp(15px, 2.6vw, 23px);
  font-weight: 800;
  margin-bottom: 10px;
  text-shadow: 0 2px 4px rgba(0,0,0,.7);
}

.footnote {
  color: rgba(255, 233, 179, .55);
  font-size: 12px;
  margin-top: 16px;
}

/* ---------- Buttons: glossy candy ---------- */
.btn {
  position: relative;
  font-family: "Fredoka", sans-serif;
  font-weight: 600;
  font-size: clamp(16px, 2.4vw, 21px);
  letter-spacing: 2px;
  color: #4a2c06;
  background: linear-gradient(180deg, #ffe793 0%, #ffc93c 48%, #f0a818 52%, #e89c0c 100%);
  border: none;
  border-radius: 999px;
  padding: 14px 40px;
  min-width: 240px;
  min-height: 52px;
  cursor: pointer;
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,.65),
    inset 0 -3px 0 rgba(122, 80, 5, .45),
    0 6px 0 #9a6e08,
    0 12px 22px rgba(0,0,0,.45);
  text-shadow: 0 1px 0 rgba(255,255,255,.5);
  transition: transform .08s, box-shadow .08s, filter .08s;
}
.btn::before {
  content: '';
  position: absolute;
  left: 12%; right: 12%; top: 7%;
  height: 38%;
  background: linear-gradient(rgba(255,255,255,.55), rgba(255,255,255,0));
  border-radius: 999px;
  pointer-events: none;
}
.btn:hover { filter: brightness(1.06); transform: translateY(-1px); }
.btn:active {
  transform: translateY(5px);
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,.65),
    inset 0 -3px 0 rgba(122, 80, 5, .45),
    0 1px 0 #9a6e08,
    0 4px 10px rgba(0,0,0,.45);
}
.btn-big {
  font-size: clamp(22px, 3.6vw, 32px);
  padding: 18px 56px;
  color: #1d3c0a;
  background: linear-gradient(180deg, #d2f59a 0%, #94d94e 48%, #6fbe2e 52%, #5dab22 100%);
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,.65),
    inset 0 -3px 0 rgba(34, 66, 10, .5),
    0 6px 0 #3a6d14,
    0 12px 22px rgba(0,0,0,.45);
}
.btn-big:active {
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,.65),
    inset 0 -3px 0 rgba(34, 66, 10, .5),
    0 1px 0 #3a6d14,
    0 4px 10px rgba(0,0,0,.45);
}
.btn-small { min-width: 160px; padding: 10px 26px; min-height: 46px; }

/* Short screens (phones in landscape): everything fits without scrolling */
@media (max-height: 540px) {
  .screen { gap: 6px; padding: 10px; }
  .screen h2 { font-size: clamp(19px, 5.5vh, 28px); letter-spacing: 1px; }
  .btn {
    font-size: 13px;
    padding: 6px 24px;
    min-width: 180px;
    min-height: 34px;
    letter-spacing: 1.5px;
    box-shadow:
      inset 0 2px 0 rgba(255,255,255,.65),
      inset 0 -2px 0 rgba(122, 80, 5, .45),
      0 4px 0 #9a6e08,
      0 8px 14px rgba(0,0,0,.45);
  }
  .btn-big {
    font-size: 17px;
    padding: 7px 32px;
    box-shadow:
      inset 0 2px 0 rgba(255,255,255,.65),
      inset 0 -2px 0 rgba(34, 66, 10, .5),
      0 4px 0 #3a6d14,
      0 8px 14px rgba(0,0,0,.45);
  }
  .btn-small { min-width: 130px; min-height: 32px; padding: 5px 16px; }
  .logo { font-size: clamp(30px, 9vh, 48px); }
  .logo-img { width: auto; max-height: 26vh; max-width: 60vw; }
  .tagline { font-size: 12px; margin-bottom: 0; }
  .footnote { font-size: 9px; margin-top: 0; }
  .help-box { max-height: 56vh; padding: 10px 18px; font-size: 12.5px; line-height: 1.45; }
  .help-box p { margin-bottom: 6px; }
  #level-grid { gap: 8px; }
  #intro-desc { font-size: 13px; }
  #end-stats, #intro-info { padding: 8px 18px; font-size: 12.5px; line-height: 1.5; }
  #end-stars { font-size: 38px; }
}

/* ---------- Level grid: postcard thumbnails ---------- */
#level-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 175px));
  gap: 14px;
  max-width: 94%;
}
@media (max-width: 760px) {
  #level-grid { grid-template-columns: repeat(3, minmax(100px, 1fr)); gap: 10px; }
}

.level-card {
  position: relative;
  aspect-ratio: 16 / 10.5;
  border-radius: 14px;
  cursor: pointer;
  overflow: hidden;
  background-color: #2c2118;
  background-size: cover;
  background-position: center;
  border: 3px solid rgba(255, 214, 120, .75);
  box-shadow: 0 5px 0 rgba(58, 36, 8, .8), 0 10px 18px rgba(0,0,0,.5);
  transition: transform .1s, box-shadow .1s;
  display: flex; flex-direction: column; justify-content: flex-end;
}
.level-card:hover { transform: translateY(-3px) scale(1.03); }
.level-card:active { transform: translateY(1px); }
.level-card::after { /* readability gradient over the scene */
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(rgba(0,0,0,.05) 35%, rgba(8, 5, 2, .82));
  pointer-events: none;
}
.level-card > * { position: relative; z-index: 1; }
.level-card .lv-num {
  position: absolute;
  top: 6px; left: 8px;
  font-size: clamp(15px, 2vw, 20px);
  font-weight: 700;
  color: #fff;
  background: rgba(20, 12, 4, .72);
  border: 2px solid rgba(255, 214, 120, .8);
  border-radius: 10px;
  min-width: 32px;
  padding: 1px 8px;
  text-shadow: 0 2px 2px rgba(0,0,0,.7);
}
.level-card .lv-name {
  font-size: clamp(11px, 1.4vw, 14px);
  font-weight: 800;
  color: #ffe9b3;
  line-height: 1.15;
  padding: 0 6px 2px;
  text-shadow: 0 2px 3px rgba(0,0,0,.9);
}
.level-card .lv-stars {
  font-size: clamp(14px, 1.9vw, 19px);
  letter-spacing: 2px;
  color: #ffc93c;
  padding-bottom: 6px;
  text-shadow: 0 2px 2px rgba(0,0,0,.9);
}
.level-card .lv-stars .dim { color: rgba(255,255,255,.3); }
.level-card.boss-card {
  border-color: #ff7a5e;
  box-shadow: 0 5px 0 rgba(90, 24, 16, .9), 0 10px 18px rgba(0,0,0,.5), 0 0 18px rgba(255, 90, 60, .35);
}
.level-card.boss-card .lv-num { border-color: #ff7a5e; background: rgba(70, 14, 8, .8); }
.level-card.locked {
  filter: grayscale(1) brightness(.55);
  cursor: default;
}
.level-card.locked:hover { transform: none; }
.level-card .lv-lock {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -55%);
  font-size: clamp(20px, 3vw, 30px);
  opacity: .9;
}

/* ---------- Shared parchment/glass panels ---------- */
.help-box, #end-stats, #intro-info {
  background: rgba(18, 12, 5, .82);
  border: 2px solid rgba(255, 214, 120, .55);
  border-radius: 18px;
  backdrop-filter: blur(4px);
  padding: 16px 28px;
  color: #f5e7c8;
  font-size: clamp(14px, 2vw, 17px);
  font-weight: 600;
  line-height: 1.65;
  box-shadow: 0 10px 26px rgba(0,0,0,.5);
}
.help-box {
  max-width: 640px;
  text-align: left;
  max-height: 58vh;
  overflow-y: auto;
}
.help-box p { margin-bottom: 9px; }
.help-box b { color: #ffc93c; }

#end-stats, #intro-info { min-width: 280px; max-width: 580px; }
#end-stats .row, #intro-info .row {
  display: flex; justify-content: space-between; gap: 34px;
  border-bottom: 1px solid rgba(255, 214, 120, .14);
  padding: 2px 0;
}
#end-stats .row:last-child, #intro-info .row:last-child { border-bottom: none; }
#end-stats .row b, #intro-info .row b { color: #ffc93c; }

/* ---------- Level intro ---------- */
#intro-title {
  color: #ffc93c;
  font-size: clamp(28px, 5.6vw, 52px);
  font-weight: 700;
  text-shadow: 0 4px 0 rgba(58, 36, 8, .95), 0 9px 24px rgba(0,0,0,.7);
}
#intro-desc {
  color: #ffe9b3;
  font-size: clamp(15px, 2.6vw, 22px);
  font-weight: 800;
  max-width: 620px;
  text-shadow: 0 2px 4px rgba(0,0,0,.75);
}

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 10px 14px;
  pointer-events: none;
  color: #fff;
}
.hud-pill {
  background: rgba(16, 10, 4, .66);
  border: 2px solid rgba(255, 214, 120, .55);
  border-radius: 16px;
  padding: 6px 16px;
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
  backdrop-filter: blur(3px);
}
#hud-left { text-align: left; max-width: 34%; }
#hud-level {
  font-size: clamp(13px, 2vw, 18px);
  font-weight: 600;
  color: #ffe9b3;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#hud-target { font-size: clamp(11px, 1.6vw, 14px); font-weight: 600; color: rgba(255,255,255,.75); }
#hud-center { text-align: center; min-width: 150px; }
#hud-score {
  font-size: clamp(26px, 4.6vw, 42px);
  font-weight: 700;
  line-height: 1.05;
  color: #b9ef74;
  text-shadow: 0 3px 6px rgba(0,0,0,.6);
}
#hud-bar {
  height: 7px;
  border-radius: 99px;
  background: rgba(255,255,255,.16);
  overflow: hidden;
  margin-top: 4px;
}
#hud-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, #ffc93c, #b9ef74);
  transition: width .25s;
}
#hud-right { display: flex; align-items: center; gap: 10px; }
#hud-time {
  font-size: clamp(18px, 3vw, 28px);
  font-weight: 700;
}
#hud-time.low { color: #ff6f61; animation: timePulse .8s infinite; }
@keyframes timePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}
.hud-btn {
  pointer-events: auto;
  font-family: "Fredoka", sans-serif;
  font-size: 16px; font-weight: 700;
  width: 48px; height: 48px;
  border-radius: 14px;
  border: none;
  background: linear-gradient(180deg, #ffe793, #f0a818);
  color: #4a2c06;
  cursor: pointer;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.6), 0 4px 0 #9a6e08, 0 8px 14px rgba(0,0,0,.4);
}
.hud-btn:active { transform: translateY(3px); box-shadow: inset 0 2px 0 rgba(255,255,255,.6), 0 1px 0 #9a6e08; }

/* ---------- Banner ---------- */
#banner {
  position: absolute;
  top: 30%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  animation: bannerPop 4s ease forwards;
}
#banner-big {
  font-size: clamp(34px, 7vw, 66px);
  font-weight: 700;
  letter-spacing: 4px;
  color: #ffe34d;
  text-shadow: 0 5px 0 rgba(122, 90, 5, .95), 0 10px 22px rgba(0,0,0,.65);
}
#banner-small {
  font-size: clamp(14px, 2.6vw, 22px);
  font-weight: 800;
  color: #fff;
  text-shadow: 0 2px 4px rgba(0,0,0,.85);
  margin-top: 6px;
}
@keyframes bannerPop {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(.5); }
  12%  { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  18%  { transform: translate(-50%, -50%) scale(1); }
  80%  { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(1); }
}

/* ---------- End screen ---------- */
#end-title { font-size: clamp(30px, 6.4vw, 56px); font-weight: 700; }
#end-title.win  { color: #b9ef74; text-shadow: 0 4px 0 #2c4a12, 0 9px 24px rgba(0,0,0,.7); }
#end-title.lose { color: #ff6f61; text-shadow: 0 4px 0 #7a241c, 0 9px 24px rgba(0,0,0,.7); }
#end-stars {
  font-size: clamp(44px, 9vw, 76px);
  color: #ffc93c;
  letter-spacing: 10px;
  text-shadow: 0 4px 0 rgba(122, 90, 5, .8), 0 0 26px rgba(255, 201, 60, .55);
}
#end-stars .dim { color: rgba(255,255,255,.22); text-shadow: none; }
#end-reason {
  color: #ffe9b3;
  font-size: clamp(14px, 2.2vw, 19px);
  font-weight: 800;
  max-width: 580px;
  text-shadow: 0 2px 4px rgba(0,0,0,.75);
}
.end-buttons { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.end-buttons .btn { min-width: 170px; }
