html, body { position: fixed; inset: 0; overflow: hidden; }

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.topbar {
  position: fixed;
  z-index: 5;
  top: calc(var(--safe-top) + 10px);
  left: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.sq-btn, .banner, .tool {
  color: #fff;
  background: linear-gradient(180deg, var(--blue-1), var(--blue-2));
  box-shadow: 0 4px 0 var(--blue-edge), 0 8px 16px rgba(59, 71, 196, .22);
}
.tier-hard .sq-btn, .tier-hard .banner, .tier-hard .tool {
  background: linear-gradient(180deg, var(--red-1), var(--red-2));
  box-shadow: 0 4px 0 var(--red-edge), 0 8px 16px rgba(168, 37, 64, .22);
}
.tier-super .sq-btn, .tier-super .banner, .tier-super .tool {
  color: #ffe08a;
  background: linear-gradient(180deg, #43357e, #241a4d);
  box-shadow: 0 4px 0 #120c2b, 0 8px 18px rgba(36, 26, 77, .35), inset 0 0 0 1.5px rgba(255, 209, 46, .35);
}
.tier-super { background: linear-gradient(180deg, #a9b6e8 0%, #cdd6f2 50%, #e2e6f5 100%); }
.tier-mega .sq-btn, .tier-mega .banner, .tier-mega .tool {
  background: linear-gradient(180deg, #ff8a1f, #e0237a);
  box-shadow: 0 4px 0 #9c1452, 0 8px 18px rgba(224, 35, 122, .3);
}
.tier-mega { background: linear-gradient(180deg, #f7c7b0 0%, #f4dbe6 50%, #f2e7ef 100%); }
.tier-giga .sq-btn, .tier-giga .banner, .tier-giga .tool {
  color: #7ff6ff;
  background: linear-gradient(180deg, #1c1c2b, #07070d);
  box-shadow: 0 4px 0 #000, 0 0 16px rgba(0, 229, 255, .35), inset 0 0 0 1.5px rgba(0, 229, 255, .55);
}
.tier-giga { background: linear-gradient(180deg, #8e9ab5 0%, #c3cad9 50%, #dfe3ec 100%); }
.tier-huge .sq-btn, .tier-huge .banner, .tier-huge .tool {
  background: linear-gradient(180deg, #19b38a, #0c7f6c);
  box-shadow: 0 4px 0 #075a4c, 0 8px 16px rgba(12, 127, 108, .25);
}
.tier-huge { background: linear-gradient(180deg, #b6e3d6 0%, #d3ede6 50%, #e5f3ef 100%); }
.tier-mega .gear-hole { fill: #e0237a; }
.tier-giga .gear-hole { fill: #07070d; }
.tier-huge .gear-hole { fill: #0c7f6c; }
.tier-mega .tier-tag { background: #fff; color: #e0237a; }
.tier-giga .tier-tag { background: linear-gradient(90deg, #00e5ff, #a855f7, #ff3896); color: #fff; }
.tier-mega .counter { color: #e0237a; }
.tier-giga .counter { color: #07070d; box-shadow: 0 6px 14px rgba(0, 0, 0, .25), inset 0 -2px 0 #00e5ff; }
.tier-huge .counter { color: #0c7f6c; }

.progress { display: flex; align-items: center; gap: 8px; flex: 1; margin-right: 12px; }
.progress[hidden] { display: none; }
.progress .bar { flex: 1; height: 10px; border-radius: 99px; background: rgba(255, 255, 255, .3); overflow: hidden; }
.progress .bar i { display: block; height: 100%; width: 0; border-radius: inherit; background: #fff; transition: width .3s; }
.progress span { font-weight: 900; font-size: 15px; min-width: 38px; }
.stars[hidden] { display: none; }

.sq-btn {
  flex: none;
  width: 50px;
  height: 52px;
  border: 0;
  border-radius: 15px;
  display: grid;
  place-items: center;
  cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
}
.sq-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--blue-edge); }
.sq-btn svg { width: 27px; height: 27px; }
.gear-hole { fill: var(--blue-2); }
.tier-hard .gear-hole { fill: var(--red-2); }
.tier-super .gear-hole { fill: #2c2160; }

.banner {
  flex: 1;
  min-width: 0;
  height: 52px;
  border-radius: 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px 0 10px;
}
.stars { display: flex; gap: 1px; }
.stars svg { width: 31px; height: 31px; fill: rgba(255, 255, 255, .28); }
.stars svg.on { fill: #ffd12e; filter: drop-shadow(0 2px 0 rgba(170, 110, 0, .55)); }
.star-lost { animation: starLost .55s ease-out; }
@keyframes starLost {
  0% { transform: scale(1); }
  35% { transform: scale(1.45) rotate(-14deg); }
  100% { transform: scale(1); }
}
.lvl {
  margin-left: auto; /* stays on the right even while the stars are hidden */
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-weight: 900;
  font-size: 21px;
  line-height: 1;
  letter-spacing: .01em;
  white-space: nowrap;
}
.tier-tag {
  margin-top: 3px;
  padding: 2px 7px 1px;
  border-radius: 6px;
  background: #fff;
  color: var(--red-2);
  font-size: 11px;
  letter-spacing: .08em;
}
.tier-tag:empty { display: none; }
.tier-super .tier-tag { background: #ffd12e; color: #241a4d; }

.counter {
  position: fixed;
  z-index: 4;
  top: calc(var(--safe-top) + 66px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 16px 5px;
  border-radius: 0 0 14px 14px;
  background: #fff;
  color: var(--blue-2);
  font-weight: 900;
  font-size: 22px;
  line-height: 1;
  box-shadow: 0 6px 14px rgba(59, 71, 196, .15);
}
.tier-hard .counter { color: var(--red-2); }
.tier-super .counter { color: #2c2160; box-shadow: 0 6px 14px rgba(36, 26, 77, .2), inset 0 -2px 0 #ffd12e; }
.counter svg { width: 17px; height: 20px; }

.tools {
  position: fixed;
  z-index: 5;
  left: 0;
  right: 0;
  bottom: calc(var(--safe-bottom) + 14px);
  display: flex;
  justify-content: center;
  gap: 16px;
  pointer-events: none;
}
.tool {
  pointer-events: auto;
  width: 80px;
  height: 70px;
  border: 0;
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-weight: 800;
  font-size: 12.5px;
  cursor: pointer;
  touch-action: manipulation;
}
.tool svg { width: 28px; height: 28px; }
.tool:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--blue-edge); }
.tool:disabled { opacity: .45; transform: none; }

.loading {
  position: fixed;
  inset: 0;
  z-index: 3;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  padding: 0 32px;
  color: var(--blue-2);
  font-weight: 800;
  text-align: center;
  pointer-events: none;
  transition: opacity .2s;
}
.loading.hide { opacity: 0; }
.spinner {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 5px solid rgba(77, 91, 230, .2);
  border-top-color: var(--blue-2);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }

.big-stars { display: flex; justify-content: center; gap: 6px; margin: 2px 0 10px; }
.big-stars svg { width: 56px; height: 56px; fill: #e3e8f3; }
.big-stars svg.on { fill: #ffd12e; filter: drop-shadow(0 3px 0 rgba(170, 110, 0, .45)); }
.big-stars svg:nth-child(2) { transform: translateY(-8px); }

.tut-art { display: block; width: 150px; height: 96px; margin: 2px auto 10px; }
.tip { font-size: 14px; color: #8a92ad; font-weight: 700; }

.rules { text-align: left; display: grid; gap: 12px; margin: 6px 0 4px; }
.rules .rule { display: grid; grid-template-columns: 64px 1fr; gap: 12px; align-items: center; }
.rules svg { width: 64px; height: 42px; }
.rules b { display: block; font-size: 15px; }
.rules span { color: var(--muted); font-size: 14px; line-height: 1.35; }

.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 4px; border-radius: 14px; background: #eef2fb; }
.seg-btn {
  appearance: none;
  border: 0;
  padding: 10px 4px;
  border-radius: 11px;
  background: transparent;
  color: #6b75a0;
  font-weight: 800;
  font-size: 14.5px;
  cursor: pointer;
}
.seg-btn.on { background: #fff; color: var(--blue-2); box-shadow: 0 2px 6px rgba(59, 71, 196, .18); }
.seg-btn[data-mode="hard"].on { color: var(--red-2); }
.seg-btn[data-mode="super"].on { color: #fff; background: linear-gradient(180deg, #43357e, #241a4d); }
.seg-btn[data-mode="huge"].on { color: #fff; background: linear-gradient(180deg, #19b38a, #0c7f6c); }
.seg-note { margin: 8px 2px 4px !important; font-size: 13.5px !important; }

.stepper { display: flex; align-items: center; gap: 6px; }
.stepper .btn { padding: 6px 12px; font-size: 20px; border-radius: 12px; line-height: 1; }
.stepper input {
  width: 64px;
  padding: 7px 4px;
  border: 2px solid #e1e6f2;
  border-radius: 10px;
  text-align: center;
  font-weight: 800;
  font-size: 17px;
  -webkit-user-select: text;
  user-select: text;
}
