/* ============================================================
   STACK TOWER BUILDER - Premium Styles
   ============================================================ */

:root {
  --bg-1: #0f0a2e;
  --bg-2: #1a0f4e;
  --bg-3: #2d1b6e;

  --pink: #ff4d8d;
  --orange: #ff8c42;
  --yellow: #ffd23f;
  --green: #4ade80;
  --cyan: #22d3ee;
  --purple: #a855f7;
  --red: #ef4444;

  --text-1: #ffffff;
  --text-2: #e9d5ff;
  --text-3: #a78bfa;

  --card-bg: rgba(255, 255, 255, 0.08);
  --card-border: rgba(255, 255, 255, 0.18);

  --font-display: 'Bungee', 'Arial Black', sans-serif;
  --font-body: 'Fredoka', 'Segoe UI', sans-serif;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-body);
  background: var(--bg-1);
  color: var(--text-1);
  touch-action: none;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  position: fixed;
  inset: 0;
}

body {
  background:
    radial-gradient(ellipse at top, rgba(34, 211, 238, 0.25) 0%, transparent 50%),
    radial-gradient(ellipse at bottom, rgba(168, 85, 247, 0.3) 0%, transparent 55%),
    linear-gradient(180deg, var(--bg-1), var(--bg-2));
}

#app {
  width: 100%;
  height: 100%;
  max-width: 540px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 12px);
  position: relative;
}

.screen {
  position: absolute;
  inset: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 12px);
  display: none;
  flex-direction: column;
  animation: fadeIn 0.35s ease;
}

.screen.active { display: flex; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(15px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   HOME SCREEN
   ============================================================ */
.backToHub {
  position: absolute;
  top: 0;
  left: 0;
  background: var(--card-bg);
  border: 1.5px solid var(--card-border);
  border-radius: 100px;
  padding: 8px 14px;
  color: var(--text-1);
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
  z-index: 5;
}

.floatingBlocks {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.floatingBlocks span {
  position: absolute;
  width: 60px;
  height: 18px;
  background: var(--c);
  border-radius: 4px;
  left: var(--x);
  bottom: -50px;
  opacity: 0;
  animation: blockFloat 8s linear infinite;
  animation-delay: var(--delay);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

@keyframes blockFloat {
  0% { transform: translateY(0) rotate(0); opacity: 0; }
  10% { opacity: 0.4; }
  90% { opacity: 0.4; }
  100% { transform: translateY(-110vh) rotate(180deg); opacity: 0; }
}

.homeContent {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  height: 100%;
  overflow-y: auto;
  padding-top: 40px;
  padding-bottom: 20px;
}

.homeContent::-webkit-scrollbar { display: none; }

.trophyBig {
  font-size: 70px;
  filter: drop-shadow(0 10px 30px rgba(34, 211, 238, 0.5));
  animation: bounce 2.4s ease-in-out infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.bigTitle {
  font-family: var(--font-display);
  font-size: clamp(36px, 9vw, 52px);
  line-height: 1;
  margin: 8px 0 4px;
  background: linear-gradient(180deg, #fff 0%, var(--cyan) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 20px rgba(34, 211, 238, 0.6));
  letter-spacing: 1px;
}

.bigTitle span {
  background: linear-gradient(180deg, var(--purple) 0%, var(--pink) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subTitle {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 24px;
  letter-spacing: 0.3px;
  max-width: 280px;
}

.statsRow {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
  margin-bottom: 24px;
}

.statBox {
  background: var(--card-bg);
  border: 1.5px solid var(--card-border);
  border-radius: 16px;
  padding: 12px 8px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.statIcon { font-size: 26px; margin-bottom: 4px; }

.statVal {
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--cyan);
  line-height: 1;
  margin-bottom: 4px;
}

.statLbl {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-3);
}

/* Mode selector */
.modeSelector {
  width: 100%;
  margin-bottom: 20px;
}

.modeLabel {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 10px;
}

.modeGrid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.modeBtn {
  background: var(--card-bg);
  border: 1.5px solid var(--card-border);
  border-radius: 14px;
  padding: 12px 8px;
  font-family: var(--font-body);
  color: var(--text-1);
  cursor: pointer;
  transition: all 0.2s ease;
}

.modeBtn.active {
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.2), rgba(168, 85, 247, 0.2));
  border-color: var(--cyan);
  box-shadow: 0 0 16px rgba(34, 211, 238, 0.3);
}

.modeIcon { font-size: 22px; margin-bottom: 4px; }

.modeName {
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 2px;
}

.modeDesc {
  font-size: 10px;
  color: var(--text-3);
}

/* Buttons */
.bigBtn {
  position: relative;
  width: 100%;
  border: none;
  border-radius: 100px;
  padding: 16px 24px;
  font-family: var(--font-body);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  margin-bottom: 10px;
  overflow: hidden;
  transition: transform 0.1s ease;
}

.primaryBtn {
  background: linear-gradient(180deg, var(--cyan), #0891b2);
  color: white;
  box-shadow: 0 6px 0 #0e7490, 0 14px 30px rgba(34, 211, 238, 0.4);
}

.primaryBtn:active {
  box-shadow: 0 2px 0 #0e7490, 0 8px 20px rgba(34, 211, 238, 0.4);
  transform: translateY(4px);
}

.ghostBtn {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-1);
  border: 1.5px solid var(--card-border);
  font-size: 15px;
}

.btnShine {
  position: absolute;
  top: 0;
  left: -100%;
  width: 50%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
  animation: btnShine 2.5s ease-in-out infinite;
}

@keyframes btnShine {
  0%, 100% { left: -100%; }
  50% { left: 100%; }
}

.howRow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  font-size: 12px;
  color: var(--text-2);
  margin-top: 12px;
  text-align: left;
}

.howIcon { font-size: 20px; flex-shrink: 0; }

.footerLinks {
  margin-top: auto;
  padding-top: 14px;
  text-align: center;
  font-size: 11px;
  color: var(--text-3);
}

.footerLinks a {
  color: var(--text-3);
  text-decoration: none;
  font-weight: 600;
}

.footerLinks span { margin: 0 6px; opacity: 0.5; }

/* ============================================================
   GAME SCREEN
   ============================================================ */
.gameTopBar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.iconBtn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--card-bg);
  border: 1.5px solid var(--card-border);
  color: var(--text-1);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.scoreCard {
  flex: 1;
  background: var(--card-bg);
  border: 1.5px solid var(--card-border);
  border-radius: 16px;
  padding: 8px 14px;
  text-align: center;
}

.scoreLbl {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--text-3);
  text-transform: uppercase;
}

.scoreVal {
  font-family: var(--font-display);
  font-size: 26px;
  color: var(--cyan);
  line-height: 1;
  text-shadow: 0 0 12px rgba(34, 211, 238, 0.5);
}

.gameArea {
  flex: 1;
  position: relative;
  border-radius: 24px;
  overflow: hidden;
  background: linear-gradient(180deg, #0f172a 0%, #1e1b4b 50%, #2d1b6e 100%);
  border: 2px solid var(--card-border);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.comboPopup {
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.5);
  font-family: var(--font-display);
  font-size: 32px;
  color: var(--yellow);
  text-shadow: 0 0 20px rgba(255, 210, 63, 0.8), 0 4px 12px rgba(0,0,0,0.5);
  opacity: 0;
  pointer-events: none;
  z-index: 3;
  transition: all 0.5s cubic-bezier(0.22, 1.4, 0.36, 1);
}

.comboPopup.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.tapHint {
  position: absolute;
  bottom: 20%;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-display);
  font-size: 16px;
  color: rgba(255, 255, 255, 0.5);
  letter-spacing: 2px;
  animation: hintPulse 1.5s ease-in-out infinite;
  z-index: 2;
  pointer-events: none;
}

.tapHint.hidden { display: none; }

@keyframes hintPulse {
  0%, 100% { opacity: 0.3; transform: translateX(-50%) scale(1); }
  50% { opacity: 0.7; transform: translateX(-50%) scale(1.05); }
}

.gameBottomBar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 4px 0;
  flex-shrink: 0;
}

.bottomStat {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
}

.bottomStat strong {
  color: var(--cyan);
  font-family: var(--font-display);
  font-size: 14px;
}

/* ============================================================
   POPUPS
   ============================================================ */
.popup {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.popup.show { display: flex; }

.popupCard {
  width: 100%;
  max-width: 360px;
  background: linear-gradient(180deg, var(--bg-2) 0%, var(--bg-1) 100%);
  border: 2px solid var(--card-border);
  border-radius: 28px;
  padding: 28px 24px;
  text-align: center;
  animation: popupIn 0.45s cubic-bezier(0.22, 1.4, 0.36, 1);
  max-height: 90vh;
  overflow-y: auto;
}

@keyframes popupIn {
  0% { opacity: 0; transform: scale(0.7) translateY(20px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

.popupCard h2 {
  font-family: var(--font-display);
  font-size: 26px;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  background: linear-gradient(180deg, #fff, var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.popupCard p {
  font-size: 14px;
  color: var(--text-2);
  margin-bottom: 18px;
  line-height: 1.4;
}

.bigEmoji {
  font-size: 70px;
  margin-bottom: 8px;
  filter: drop-shadow(0 8px 20px rgba(34, 211, 238, 0.4));
}

.rewardRow {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.rewardBox {
  background: var(--card-bg);
  border: 1.5px solid var(--card-border);
  border-radius: 14px;
  padding: 12px 6px;
}

.rewardIcon { font-size: 26px; margin-bottom: 4px; }

.rewardVal {
  font-family: var(--font-display);
  font-size: 20px;
  color: var(--cyan);
  margin-bottom: 2px;
}

.rewardLbl {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-3);
}

.newBestBadge {
  background: linear-gradient(90deg, rgba(255, 210, 63, 0.2), rgba(255, 140, 66, 0.2));
  border: 1.5px solid rgba(255, 210, 63, 0.5);
  border-radius: 100px;
  padding: 8px 18px;
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 1.5px;
  color: var(--yellow);
  margin-bottom: 14px;
  animation: badgePulse 1.5s infinite;
}

.newBestBadge.hidden { display: none; }

@keyframes badgePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.popupCard.modal { text-align: left; }
.popupCard.modal h2 { text-align: center; }

.modalBody {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-2);
  margin-bottom: 18px;
  max-height: 50vh;
  overflow-y: auto;
}

.modalBody h4 {
  color: var(--text-1);
  margin: 12px 0 6px;
  font-size: 14px;
}

/* Ad popup */
.adCard {
  width: 100%;
  max-width: 360px;
  background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
  border: 2px solid var(--card-border);
  border-radius: 24px;
  padding: 22px;
  text-align: center;
}

.adLabel {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 14px;
}

.adContent {
  background: #000;
  border-radius: 14px;
  padding: 40px 20px;
  margin-bottom: 14px;
}

.adEmoji { font-size: 50px; margin-bottom: 10px; }

.adText { font-size: 14px; color: var(--text-2); margin-bottom: 8px; }

.adTimer {
  font-family: var(--font-display);
  font-size: 22px;
  color: var(--cyan);
}

#adSkip:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Toast */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.5);
  background: linear-gradient(135deg, var(--cyan), #0891b2);
  color: white;
  font-family: var(--font-display);
  font-size: 18px;
  padding: 12px 28px;
  border-radius: 100px;
  box-shadow: 0 10px 30px rgba(34, 211, 238, 0.4);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.22, 1.4, 0.36, 1);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

@media (max-height: 700px) {
  .trophyBig { font-size: 56px; }
  .bigTitle { font-size: 34px; }
  .subTitle { margin-bottom: 14px; }
  .statsRow { margin-bottom: 14px; }
}
