/* ===== 泡泡龙 卡通风格样式 (Telegram Mini App) ===== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

:root {
  --c-pink: #ff7eb6;
  --c-orange: #ffb15c;
  --c-yellow: #ffe066;
  --c-green: #7ed957;
  --c-blue: #6cc6ff;
  --c-purple: #b691ff;
  --ink: #4a3c5a;
  --ink-soft: #7a6b8c;
  --panel: #ffffff;
  --shadow: 0 8px 0 rgba(74, 60, 90, 0.18), 0 14px 30px rgba(74, 60, 90, 0.18);

  /* Telegram theme variables (fallback to defaults if not in Telegram) */
  --tg-bg: var(--tg-theme-bg-color, #ffffff);
  --tg-text: var(--tg-theme-text-color, #4a3c5a);
  --tg-hint: var(--tg-theme-hint-color, #7a6b8c);
  --tg-link: var(--tg-theme-link-color, #6cc6ff);
  --tg-btn: var(--tg-theme-button-color, #ff7eb6);
  --tg-btn-text: var(--tg-theme-button-text-color, #ffffff);
  --tg-secondary-bg: var(--tg-theme-secondary-bg-color, #f5f5f5);
}

html, body {
  height: 100%;
  font-family: "Baloo 2", "Comic Sans MS", "Microsoft YaHei", sans-serif;
  color: var(--tg-text);
  overflow: hidden;
  background: var(--tg-bg);
}

body {
  background: linear-gradient(180deg, #aee3ff 0%, #c9f0ff 45%, #e9fff5 100%);
}

/* Telegram user bar */
.tg-user-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--tg-secondary-bg, rgba(255,255,255,0.85));
  backdrop-filter: blur(6px);
  font-size: 13px;
  font-weight: 700;
  color: var(--tg-hint);
  border-bottom: 1px solid rgba(0,0,0,0.06);
}
.tg-user-bar .avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--tg-btn);
  color: var(--tg-btn-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  flex-shrink: 0;
}

/* 背景天空 + 云朵 */
#app {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.cloud {
  position: absolute;
  width: 160px;
  height: 60px;
  background: #fff;
  border-radius: 60px;
  opacity: 0.85;
  filter: blur(0.5px);
  box-shadow: 0 10px 30px rgba(120, 180, 255, 0.3);
}
.cloud::before,
.cloud::after {
  content: "";
  position: absolute;
  background: #fff;
  border-radius: 50%;
}
.cloud::before {
  width: 80px;
  height: 80px;
  top: -34px;
  left: 26px;
}
.cloud::after {
  width: 60px;
  height: 60px;
  top: -22px;
  right: 28px;
}
.cloud1 { top: 8%; left: -180px; animation: drift 38s linear infinite; }
.cloud2 { top: 24%; left: -260px; transform: scale(0.7); animation: drift 52s linear infinite; animation-delay: -10s; }
.cloud3 { top: 60%; left: -220px; transform: scale(1.2); animation: drift 64s linear infinite; animation-delay: -24s; }

@keyframes drift {
  from { left: -260px; }
  to { left: 110%; }
}

/* 游戏容器 */
.game-wrap {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 12px;
  padding-top: 44px; /* space for user bar */
}

/* HUD */
.hud {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--panel);
  padding: 12px 18px;
  border-radius: 22px;
  box-shadow: var(--shadow);
  flex-wrap: wrap;
  justify-content: center;
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 56px;
}

.hud-label {
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: 700;
  letter-spacing: 1px;
}

.hud-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--ink);
}

.next-wrap {
  flex-direction: row;
  gap: 8px;
  align-items: center;
}

#nextCanvas {
  background: #f3f0ff;
  border-radius: 50%;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.08);
}

/* 按钮 */
.btn {
  font-family: inherit;
  font-weight: 800;
  font-size: 16px;
  color: #fff;
  background: linear-gradient(180deg, var(--c-pink), #ff5aa3);
  border: none;
  border-radius: 16px;
  padding: 10px 18px;
  cursor: pointer;
  box-shadow: 0 5px 0 #d63d82, 0 8px 14px rgba(214, 61, 130, 0.35);
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #d63d82, 0 4px 8px rgba(214, 61, 130, 0.35);
}
.btn-alt {
  background: linear-gradient(180deg, var(--c-blue), #3ea8f0);
  box-shadow: 0 5px 0 #2a7fc4, 0 8px 14px rgba(42, 127, 196, 0.35);
}
.btn-alt:active {
  box-shadow: 0 2px 0 #2a7fc4, 0 4px 8px rgba(42, 127, 196, 0.35);
}
.btn-big {
  font-size: 22px;
  padding: 14px 34px;
  margin-top: 8px;
}

/* 舞台 */
.stage {
  position: relative;
  border-radius: 24px;
  overflow: hidden;
  box-shadow: var(--shadow);
  background: linear-gradient(180deg, #fff7fb 0%, #eef9ff 100%);
  border: 4px solid #fff;
  /* 响应式缩放：按高度限制，保持 480:640 比例 */
  width: min(480px, calc((100vh - 160px) * 0.75));
  aspect-ratio: 3 / 4;
}

#game {
  display: block;
  background: transparent;
  touch-action: none;
  width: 100%;
  height: 100%;
}

/* 提示条 */
.tip {
  font-size: 13px;
  color: var(--ink-soft);
  font-weight: 700;
  background: rgba(255,255,255,0.7);
  padding: 6px 14px;
  border-radius: 14px;
}

/* 遮罩 */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(74, 60, 90, 0.45);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  transition: opacity 0.25s;
}
.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay-card {
  background: #fff;
  border-radius: 26px;
  padding: 28px 36px;
  text-align: center;
  box-shadow: var(--shadow);
  max-width: 80%;
  animation: pop 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes pop {
  0% { transform: scale(0.7); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.overlay-card h1 {
  font-size: 34px;
  color: var(--c-pink);
  text-shadow: 0 3px 0 #ffd6e7;
  margin-bottom: 8px;
}
.overlay-card p {
  color: var(--ink-soft);
  font-weight: 700;
  margin-bottom: 6px;
}

/* 关卡选择弹窗 */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(74, 60, 90, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
.modal.hidden { display: none; }

.modal-card {
  background: #fff;
  border-radius: 24px;
  padding: 24px;
  width: min(92vw, 460px);
  text-align: center;
  box-shadow: var(--shadow);
}
.modal-card h2 {
  color: var(--c-blue);
  margin-bottom: 14px;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.level-btn {
  font-family: inherit;
  font-weight: 800;
  font-size: 20px;
  aspect-ratio: 1;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  background: linear-gradient(180deg, #fff, #ffe9f3);
  color: var(--ink);
  box-shadow: 0 4px 0 #f0d4e6;
  transition: transform 0.08s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.level-btn:hover { transform: translateY(-2px); }
.level-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #f0d4e6; }
.level-btn.locked {
  background: linear-gradient(180deg, #eee, #ddd);
  color: #aaa;
  cursor: not-allowed;
  box-shadow: 0 4px 0 #ccc;
}
.level-btn .star {
  font-size: 11px;
  color: var(--c-yellow);
}
.level-btn.cleared {
  background: linear-gradient(180deg, #e8fff0, #c9f5d8);
  box-shadow: 0 4px 0 #a8e6c0;
}
.level-btn.premium-locked {
  background: linear-gradient(180deg, #fff8e1, #ffefb3);
  box-shadow: 0 4px 0 #e6d58e;
  cursor: pointer;
  animation: pulse-star 1.5s ease-in-out infinite;
}
.level-btn.premium-locked:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #e6d58e;
}
.level-btn.premium-locked .premium-star {
  font-size: 16px;
  color: #ffc107;
  filter: drop-shadow(0 0 4px rgba(255, 193, 7, 0.6));
}
@keyframes pulse-star {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}
.level-btn.premium-locked:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #e6d58e;
}

/* Loading spinner */
.tg-loading {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--tg-bg, #fff);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-family: "Baloo 2", sans-serif;
  font-weight: 700;
  color: var(--tg-hint, #7a6b8c);
}
.tg-loading .spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--tg-secondary-bg, #eee);
  border-top-color: var(--tg-btn, #ff7eb6);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.tg-loading.hidden {
  display: none;
}

@media (max-width: 540px) {
  .hud { gap: 8px; padding: 10px; }
  .hud-value { font-size: 18px; }
  .btn { font-size: 14px; padding: 8px 12px; }
  .overlay-card h1 { font-size: 26px; }
}