:root {
  --ink: #2b1d0e;
  --cream: #fff6df;
  --gold: #ffc928;
  --red: #e8432f;
  --blue: #3b62c4;
  --panel: rgba(30, 22, 12, 0.72);
  font-family: 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif;
}
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1b2747;
  color: var(--cream);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}
canvas#c {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.hidden {
  display: none !important;
}

/* ---- buttons ---- */
button {
  font: inherit;
  cursor: pointer;
  border: none;
}
button.big {
  display: block;
  margin: 10px auto;
  min-width: 220px;
  padding: 14px 26px;
  font-size: 20px;
  font-weight: 800;
  color: var(--ink);
  background: linear-gradient(#ffe27a, #f5b21b);
  border-radius: 14px;
  box-shadow: 0 5px 0 #a8670b, 0 8px 18px rgba(0, 0, 0, 0.35);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}
button.big:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #a8670b;
}
button.big.alt {
  background: linear-gradient(#f3e6c8, #d8c39a);
  box-shadow: 0 5px 0 #8c7650, 0 8px 18px rgba(0, 0, 0, 0.3);
}
button.round {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--panel);
  color: var(--cream);
  font-size: 18px;
  font-weight: 800;
  border: 2px solid rgba(255, 255, 255, 0.25);
}

/* ---- HUD ---- */
#hud {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 0;
  pointer-events: none;
}
#hud .row {
  display: flex;
  gap: 8px;
  align-items: center;
}
#hud button {
  pointer-events: auto;
}
.spacer {
  flex: 1;
}
.pill {
  background: var(--panel);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 800;
  font-size: 17px;
  white-space: nowrap;
}
.pill.gold {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--gold);
  font-size: 20px;
}
.pill.gold.bump {
  animation: bump 0.2s;
}
@keyframes bump {
  50% {
    transform: scale(1.15);
  }
}
.coin {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff2a8, #ffc928 55%, #b77d00);
  box-shadow: 0 0 0 2px #8a5a00 inset;
}
.hpbar {
  position: relative;
  margin: 8px auto 0;
  width: min(420px, 80vw);
  height: 18px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.55);
  border: 2px solid rgba(255, 255, 255, 0.3);
  overflow: hidden;
}
.hpbar .fill {
  position: absolute;
  inset: 0;
  width: 100%;
  background: linear-gradient(#7fe0ff, #2f8fd8);
  transition: width 0.15s;
}
.hpbar.low .fill {
  background: linear-gradient(#ff8a7a, #d7321f);
}
.hpbar span {
  position: absolute;
  inset: 0;
  text-align: center;
  font-size: 12px;
  line-height: 14px;
  font-weight: 800;
  text-shadow: 0 1px 2px #000;
}

#btn-night {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 18px);
  transform: translateX(-50%);
  margin: 0;
  background: linear-gradient(#ff8f6b, #d8402a);
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.3);
  box-shadow: 0 5px 0 #8d2213, 0 8px 18px rgba(0, 0, 0, 0.35);
  animation: pulse 1.6s infinite;
}
#btn-night:active {
  transform: translateX(-50%) translateY(3px);
}
@keyframes pulse {
  50% {
    filter: brightness(1.15);
  }
}
#hint {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 92px);
  transform: translateX(-50%);
  width: min(460px, 90vw);
  text-align: center;
  background: var(--panel);
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 15px;
  pointer-events: none;
}
#banner {
  position: fixed;
  left: 0;
  right: 0;
  top: 28%;
  text-align: center;
  font-size: clamp(30px, 8vw, 54px);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.35), 0 0 20px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  opacity: 0;
}
#banner small {
  display: block;
  font-size: 0.45em;
  font-weight: 700;
}
#banner.show {
  animation: banner 2.2s ease-out;
}
@keyframes banner {
  0% {
    opacity: 0;
    transform: scale(1.4);
  }
  12% {
    opacity: 1;
    transform: scale(1);
  }
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

/* ---- world-space labels ---- */
#labels {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.pad-label,
.spawn-label {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px 3px 4px;
  background: var(--panel);
  border-radius: 999px;
  font-weight: 800;
  font-size: 14px;
  white-space: nowrap;
  will-change: transform;
}
.pad-label .ic {
  font-size: 15px;
}
.pad-label .cost {
  color: var(--gold);
}
.pad-label .cost::before {
  content: '';
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-right: 3px;
  border-radius: 50%;
  background: var(--gold);
  vertical-align: -1px;
}
.pad-label .cost.poor {
  color: #ff8a7a;
}
.pad-label.focus {
  font-size: 16px;
  background: rgba(60, 40, 10, 0.9);
  border: 2px solid var(--gold);
  z-index: 2;
}
.pad-label {
  overflow: hidden;
}
.pad-label .prog {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 4px;
  width: 0;
  background: var(--gold);
}
.spawn-label {
  background: rgba(150, 20, 10, 0.85);
  padding: 4px 10px;
  font-size: 16px;
}

/* ---- joystick ---- */
#joy {
  position: fixed;
  left: -60px;
  top: -60px;
  width: 120px;
  height: 120px;
  margin: 0;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.45);
  background: rgba(0, 0, 0, 0.15);
  display: none;
  pointer-events: none;
}
#joy .knob {
  position: absolute;
  left: 34px;
  top: 34px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
}

/* ---- overlays ---- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(ellipse at center, rgba(30, 20, 8, 0.6), rgba(10, 8, 4, 0.85));
  text-align: center;
  overflow-y: auto;
}
#menu {
  background: linear-gradient(rgba(20, 30, 60, 0.25), rgba(10, 12, 25, 0.7));
}
#loading {
  background: linear-gradient(rgba(20, 30, 60, 0.55), rgba(10, 12, 25, 0.85));
}
h1 {
  margin: 0;
  font-size: clamp(40px, 11vw, 72px);
  font-weight: 900;
  color: var(--gold);
  text-shadow: 0 4px 0 #8a4f00, 0 8px 22px rgba(0, 0, 0, 0.5);
  letter-spacing: 1px;
}
h1 span {
  color: #fff;
}
h2 {
  margin: 0 0 14px;
  font-size: 32px;
  color: var(--gold);
  text-shadow: 0 3px 0 #8a4f00;
}
.sub {
  margin: 6px 0 22px;
  opacity: 0.85;
}
.credits {
  margin-top: 18px;
  font-size: 12px;
  opacity: 0.6;
}
#levels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  width: min(820px, 100%);
}
.level {
  position: relative;
  padding: 14px 10px 12px;
  border-radius: 16px;
  background: linear-gradient(#fff3d4, #e8cf9a);
  color: var(--ink);
  box-shadow: 0 5px 0 #8c7650, 0 8px 18px rgba(0, 0, 0, 0.3);
  text-align: center;
}
.level .num {
  font-size: 34px;
  font-weight: 900;
}
.level .name {
  font-weight: 800;
}
.level .kind {
  font-size: 12px;
  opacity: 0.7;
}
.level .lstars {
  margin-top: 4px;
  font-size: 18px;
  letter-spacing: 2px;
}
.level.locked {
  filter: grayscale(1) brightness(0.6);
  cursor: default;
}
.stars {
  font-size: 54px;
  letter-spacing: 6px;
}
.star-off {
  opacity: 0.25;
  filter: grayscale(1);
}
.load {
  margin-top: 30px;
  width: min(320px, 70vw);
  height: 14px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.5);
  overflow: hidden;
}
#load-fill {
  height: 100%;
  width: 0;
  background: var(--gold);
  transition: width 0.1s;
}

/* ---- upgrade cards ---- */
#cards {
  background: rgba(10, 8, 4, 0.7);
}
.cardrow {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}
.card {
  width: min(200px, 28vw);
  min-width: 102px;
  padding: 16px 10px;
  border-radius: 16px;
  background: linear-gradient(#fff3d4, #e8cf9a);
  color: var(--ink);
  box-shadow: 0 6px 0 #8c7650, 0 10px 22px rgba(0, 0, 0, 0.4);
  animation: deal 0.35s backwards;
}
.card:nth-child(2) {
  animation-delay: 0.08s;
}
.card:nth-child(3) {
  animation-delay: 0.16s;
}
@keyframes deal {
  from {
    transform: translateY(40px) scale(0.8);
    opacity: 0;
  }
}
.card .icon {
  font-size: 44px;
}
.card .cname {
  font-weight: 900;
  font-size: 17px;
  margin: 6px 0 4px;
}
.card .cdesc {
  font-size: 14px;
}
.card .clvl {
  margin-top: 6px;
  font-size: 12px;
  opacity: 0.7;
}
@media (max-width: 520px) {
  .cardrow {
    gap: 8px;
    flex-wrap: nowrap;
  }
  .card {
    width: 31vw;
    min-width: 0;
    padding: 12px 6px;
  }
  .card .icon {
    font-size: 34px;
  }
  .card .cname {
    font-size: 14px;
  }
  .card .cdesc {
    font-size: 12px;
  }
  button.big {
    min-width: 200px;
    font-size: 18px;
  }
}
@media (max-width: 420px) {
  #hud .row {
    gap: 5px;
  }
  .pill {
    font-size: 14px;
    padding: 5px 10px;
  }
  .pill.gold {
    font-size: 16px;
  }
  button.round {
    width: 36px;
    height: 36px;
    font-size: 15px;
  }
  .pad-label,
  .spawn-label {
    font-size: 12px;
  }
}
