:root {
  --vh: 1vh;
  --gold: #ffc21f;
  --gold2: #ff8a1f;
  --amber-dark: #8a3a06;
  --ember: #ff6a1a;
  --panel-b: rgba(255, 170, 80, 0.38);
}
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Outfit', sans-serif;
  touch-action: none;
  background: #0c0403;
}

#gameWrap {
  position: relative;
  width: 100vw;
  height: calc(var(--vh, 1vh) * 100);
  overflow: hidden;
  background: #1a0806;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#gameWrap::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  background: radial-gradient(ellipse at 50% 50%, rgba(0, 0, 0, 0) 58%, rgba(20, 3, 0, 0.45) 100%);
}

#uiLayer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}

.glass {
  background: linear-gradient(180deg, rgba(92, 40, 22, 0.9) 0%, rgba(38, 14, 9, 0.93) 100%);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--panel-b);
  box-shadow: 0 8px 24px rgba(10, 2, 0, 0.55), 0 0 14px rgba(255, 110, 30, 0.14), inset 0 1px 0 rgba(255, 220, 170, 0.24), inset 0 -2px 6px rgba(0, 0, 0, 0.35);
}

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) calc(env(safe-area-inset-right, 0px) + 12px) 0 calc(env(safe-area-inset-left, 0px) + 12px);
  opacity: 0;
  transform: translateY(-14px);
  transition: opacity .35s ease, transform .35s ease;
}

.playing #hud {
  opacity: 1;
  transform: none;
}

.hudGroup {
  display: flex;
  gap: 8px;
  align-items: center;
}

.hudPill {
  border-radius: 999px;
  padding: 5px 14px 5px 10px;
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
  color: #fff3dd;
  min-height: 36px;
}

.hudPill .ic {
  width: 20px;
  height: 20px;
  flex: none;
}

.hudPill .lbl {
  font-size: 10px;
  letter-spacing: 1.4px;
  color: #ffd2a0;
  font-weight: 700;
}

.hudPill .val {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  color: #ffc21f;
  font-size: 18px;
  min-width: 18px;
  text-shadow: 0 0 10px rgba(255, 140, 30, 0.45), 0 2px 6px rgba(0, 0, 0, 0.4);
}

#timePill.low .val {
  color: #ff5a4a;
  animation: pulseBadge .6s ease infinite;
}

#heartsRow {
  display: flex;
  gap: 4px;
}

.heart {
  width: 20px;
  height: 18px;
}

.heart svg {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.4));
}

#iconBtns {
  display: flex;
  gap: 8px;
  pointer-events: all;
}

.logo {
  border-radius: 60px;
  width: 300px;
  box-shadow:
    0 3px 0 #c9c9c9,
    0 6px 0 #999,
    0 9px 0 #666,
    0 14px 22px rgba(0, 0, 0, 0.45);

  transition: transform 0.2s ease, box-shadow 0.2s ease;margin-bottom: 20px;
}

.iconBtn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 1px solid rgba(255, 170, 80, 0.4);
  background: linear-gradient(180deg, rgba(112, 52, 28, 0.95), rgba(44, 16, 10, 0.95));
  box-shadow: 0 5px 14px rgba(10, 2, 0, 0.55), inset 0 1px 0 rgba(255, 220, 170, 0.28);
  transition: transform .15s ease;
}

.iconBtn:active {
  transform: scale(0.86);
}

.iconBtn svg {
  width: 18px;
  height: 18px;
  fill: #fff3dd;
}

/* ---------- touch controls ---------- */
#touch {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 calc(env(safe-area-inset-right, 0px) + 18px) calc(env(safe-area-inset-bottom, 0px) + 14px) calc(env(safe-area-inset-left, 0px) + 18px);
  opacity: 0;
  transition: opacity .3s ease;
}

.touchOn.playing #touch {
  display: flex;
  opacity: 1;
}

.tgroup {
  display: flex;
  gap: 14px;
  align-items: flex-end;
}

.tbtn {
  pointer-events: all;
  width: 74px;
  height: 74px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff3dd;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  cursor: pointer;
  touch-action: none;
  opacity: 0.88;
  transition: transform .08s ease;
}

.tbtn svg {
  width: 32px;
  height: 32px;
  fill: #fff3dd;
}

.tbtn.dash {
  width: 62px;
  height: 62px;
  font-size: 13px;
  letter-spacing: 1px;
}

.tbtn.jump {
  width: 92px;
  height: 92px;
  font-size: 17px;
  letter-spacing: 1px;
  color: #3a1800;
  border: none;
  background: linear-gradient(180deg, #fff0b8, var(--gold) 52%, var(--gold2));
  box-shadow: 0 5px 0 var(--amber-dark), 0 12px 26px rgba(0, 0, 0, 0.5), inset 0 2px 0 rgba(255, 255, 255, 0.7);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55);
}

.tbtn.down {
  transform: scale(0.9);
  opacity: 1;
}

/* ---------- screens ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: all;
  text-align: center;
  padding: 16px 24px;
  z-index: 6;
  opacity: 0;
  visibility: hidden;
  transform: scale(0.97);
  transition: opacity .4s cubic-bezier(.2, .8, .2, 1), transform .4s cubic-bezier(.2, .8, .2, 1), visibility .4s;
  background: radial-gradient(ellipse at 50% 28%, rgba(150, 56, 14, 0.5), rgba(22, 6, 3, 0.9) 72%);
}

.screen.active {
  opacity: 1;
  visibility: visible;
  transform: scale(1);
}

.menuRow {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(20px, 6vw, 70px);
  width: 100%;
}

.menuCol {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.logoWrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: logoFloat 3.4s ease-in-out infinite;
}

.mascot {
  width: clamp(70px, 18vh, 130px);
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.5)) drop-shadow(0 0 14px rgba(255, 130, 30, 0.35));
  margin-bottom: 4px;
}

@keyframes logoFloat {

  0%,
  100% {
    transform: translateY(0) rotate(-1deg);
  }

  50% {
    transform: translateY(-6px) rotate(1deg);
  }
}

h1.title {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 0.92;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
}

h1.title .t1 {
  font-size: clamp(48px, 15vh, 84px);
  letter-spacing: 3px;
  background: linear-gradient(180deg, #fff6c8 0%, #ffc21f 40%, #ff6a1a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-stroke: 2px rgba(110, 28, 4, 0.7);
  filter: drop-shadow(0 0 14px rgba(255, 110, 20, 0.55));
}

h1.title .t2 {
  font-size: clamp(24px, 7vh, 38px);
  letter-spacing: 8px;
  background: linear-gradient(90deg, #ffd27a, #ff6a3a, #ffd27a);
  background-size: 220% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shine 4s linear infinite;
}

@keyframes shine {
  0% {
    background-position: 0% 50%;
  }

  100% {
    background-position: -220% 50%;
  }
}

.subtitle {
  color: #fff;
  font-size: 14px;
  margin-top: 8px;
  letter-spacing: 3px;
  opacity: 0.85;
  text-transform: uppercase;
  font-weight: 700;
}

/* ---------- buttons ---------- */
.btn {
  font-family: 'Outfit', sans-serif;
  font-weight: 800;
  font-size: 17px;
  color: #3a1800;
  border: none;
  border-radius: 30px;
  padding: 14px 38px;
  cursor: pointer;
  background: linear-gradient(180deg, #fff6c4, var(--gold) 52%, var(--gold2));
  box-shadow: 0 5px 0 var(--amber-dark), 0 12px 26px rgba(0, 0, 0, 0.5), 0 0 24px rgba(255, 130, 30, 0.38), inset 0 2px 0 rgba(255, 255, 255, 0.7), inset 0 -3px 6px rgba(190, 80, 10, 0.4);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55);
  margin: 7px 6px;
  transition: transform .12s ease, box-shadow .12s ease;
  min-width: 190px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  position: relative;
  overflow: hidden;
}

.btn::after {
  content: '';
  position: absolute;
  top: 0;
  left: -60%;
  width: 40%;
  height: 100%;
  background: linear-gradient(120deg, transparent, rgba(255, 255, 255, 0.55), transparent);
  transform: skewX(-20deg);
  animation: btnShine 3.2s ease-in-out infinite;
}

@keyframes btnShine {

  0%,
  60% {
    left: -60%;
  }

  100% {
    left: 140%;
  }
}

.btn:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--amber-dark), 0 4px 10px rgba(0, 0, 0, 0.3);
}

.btn.secondary {
  background: linear-gradient(180deg, #7a3a22, #3e1810);
  color: #fff3dd;
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.4);
  box-shadow: 0 5px 0 rgba(20, 4, 0, 0.7), 0 10px 20px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 210, 160, 0.3);
  border: 1px solid rgba(255, 170, 80, 0.35);
  min-width: 150px;
  font-size: 15px;
  padding: 12px 22px;
}

.btn.secondary::after {
  display: none;
}

.btn.secondary:active {
  box-shadow: 0 1px 0 rgba(20, 4, 0, 0.7);
}

.btnRow {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}

.statsRow {
  display: flex;
  gap: 10px;
  margin: 8px 0 10px 0;
  flex-wrap: wrap;
  justify-content: center;
}

.statCard {
  border-radius: 16px;
  padding: 10px 18px;
  min-width: 96px;
}

.statCard .label {
  font-size: 10px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: #ffcaa0;
  margin-bottom: 3px;
  font-weight: 700;
}

.statCard .num {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: 22px;
  color: #ffc21f;
  text-shadow: 0 0 10px rgba(255, 140, 30, 0.45), 0 2px 6px rgba(0, 0, 0, 0.4);
}

h2.screenTitle {
  font-family: 'Baloo 2', sans-serif;
  color: #fff3dd;
  font-size: 30px;
  margin-bottom: 6px;
  letter-spacing: 1px;
  text-shadow: 0 0 18px rgba(255, 120, 30, 0.5), 0 3px 12px rgba(0, 0, 0, 0.5);
}

.footLinks {
  margin-top: 8px;
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #e9a979;
}

.footLinks a {
  color: #e9a979;
  text-decoration: none;
  padding: 4px 6px;
  font-weight: 600;
}

.newBest {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  background: linear-gradient(90deg, #ff9f6b, #ffd76b);
  color: #3a1a00;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 1px;
  padding: 5px 14px;
  border-radius: 999px;
  text-transform: uppercase;
  animation: pulseBadge 1s ease infinite;
}

@keyframes pulseBadge {

  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.08);
  }
}

/* ---------- loader ---------- */
#loadBarOuter {
  width: min(260px, 50vw);
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.35);
  margin-top: 18px;
  border: 1px solid rgba(255, 170, 80, 0.35);
}

#loadBarInner {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ff6a1a, #ffc21f, #fff2c2);
  box-shadow: 0 0 14px rgba(255, 140, 30, 0.7);
  border-radius: 999px;
  transition: width .25s ease;
}

#loadLabel {
  margin-top: 10px;
  font-size: 13px;
  color: #ffcaa0;
  letter-spacing: 0.5px;
}

/* ---------- level select ---------- */
#levelGrid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(560px, 100%);
  margin-bottom: 8px;
}

.worldRow {
  display: flex;
  align-items: center;
  gap: 10px;
}

.worldName {
  width: 96px;
  flex: none;
  text-align: left;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: 13px;
  line-height: 1.1;
  color: #ffd2a0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.worldName small {
  display: block;
  font-size: 10px;
  color: #c98a5e;
  letter-spacing: 1px;
}

.worldCells {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  flex: 1;
}

.lvl {
  height: clamp(46px, 11vh, 62px);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: 18px;
  color: #3a1800;
  background: linear-gradient(180deg, #fff0b8, #ffc21f 55%, #ff8a1f);
  box-shadow: 0 4px 0 var(--amber-dark), 0 8px 14px rgba(0, 0, 0, 0.45), inset 0 2px 0 rgba(255, 255, 255, 0.6);
  line-height: 1;
  gap: 2px;
  transition: transform .12s ease;
}

.lvl:active {
  transform: translateY(3px);
}

.lvl .st {
  font-size: 10px;
  letter-spacing: 1px;
}

.lvl .st b {
  color: #d96a00;
}

.lvl .st s {
  text-decoration: none;
  color: rgba(120, 60, 0, 0.3);
}

.lvl.locked {
  background: linear-gradient(180deg, #5a3224, #2e140e);
  color: rgba(255, 220, 190, 0.45);
  box-shadow: 0 4px 0 rgba(15, 3, 0, 0.6), inset 0 1px 0 rgba(255, 200, 150, 0.15);
  cursor: default;
}

.lvl.locked svg {
  width: 18px;
  height: 18px;
  fill: rgba(255, 220, 190, 0.5);
}

.lvl.current {
  animation: pulseBadge 1.1s ease infinite;
}

/* ---------- how to ---------- */
.htpGrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  max-width: 640px;
  margin: 6px 0 10px 0;
}

.htpTip {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  border-radius: 15px;
  padding: 10px 14px;
}

.htpTip .htpIcon {
  width: 34px;
  height: 34px;
  flex: none;
}

.htpTip .htpIcon svg {
  width: 100%;
  height: 100%;
}

.htpTip .txt {
  font-size: 13px;
  color: #ffeedd;
  line-height: 1.35;
}

.htpTip .txt b {
  color: var(--gold);
}

/* ---------- win ---------- */
#starsRow {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 6px;
  margin: 0 0 4px 0;
}

#starsRow .star {
  width: 52px;
  height: 52px;
  fill: rgba(255, 255, 255, 0.16);
  stroke: rgba(255, 255, 255, 0.25);
  stroke-width: 0.8;
  transform: scale(0.8);
}

#starsRow .star.mid {
  width: 68px;
  height: 68px;
  margin-bottom: 6px;
}

#starsRow .star.on {
  fill: #ffc21f;
  stroke: #b06800;
  stroke-width: 1;
  filter: drop-shadow(0 0 14px rgba(255, 150, 30, 0.9));
  animation: starPop .6s cubic-bezier(.2, 1.6, .3, 1) both;
  animation-delay: var(--d, 0s);
}

@keyframes starPop {
  0% {
    transform: scale(0) rotate(-40deg);
  }

  100% {
    transform: scale(1) rotate(0);
  }
}

#flashOverlay {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 5;
}

/* ---------- rotate hint (portrait phones) ---------- */
#rotateHint {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  color: #fff3dd;
  font-weight: 700;
  line-height: 1.4;
  background: radial-gradient(ellipse at 50% 30%, rgba(150, 56, 14, 0.7), rgba(14, 4, 2, 0.97) 75%);
}

#rotateHint svg {
  width: 84px;
  animation: rot 2.2s ease-in-out infinite;
}

@keyframes rot {

  0%,
  20% {
    transform: rotate(0);
  }

  60%,
  100% {
    transform: rotate(-90deg);
  }
}

@media (orientation: portrait) and (pointer: coarse) {
  #rotateHint {
    display: flex;
  }
}

@media (max-height: 460px) {
  .screen {
    padding: 8px 18px;
  }

  h2.screenTitle {
    font-size: 24px;
    margin-bottom: 2px;
  }

  .btn {
    padding: 10px 28px;
    font-size: 15px;
    margin: 4px 5px;
  }

  .btn.secondary {
    padding: 9px 18px;
    font-size: 14px;
  }

  .statCard {
    padding: 7px 14px;
    min-width: 80px;
  }

  .statCard .num {
    font-size: 19px;
  }

  #starsRow .star {
    width: 40px;
    height: 40px;
  }

  #starsRow .star.mid {
    width: 54px;
    height: 54px;
  }

  .htpTip .txt {
    font-size: 12px;
  }

  .tbtn {
    width: 64px;
    height: 64px;
  }

  .tbtn.jump {
    width: 80px;
    height: 80px;
  }

  .tbtn.dash {
    width: 54px;
    height: 54px;
  }
}