/* ─────────────────────────────────────────────────────────────
   汤圆大亨 — 移动端优先样式表
   配色：深红背景 · 金色强调 · 节庆红 · 暖白文字
   ───────────────────────────────────────────────────────────── */

:root {
  --bg-deep:      #1a0205;
  --bg-mid:       #3a0510;
  --gold:         #f39c12;
  --gold-light:   #ffd166;
  --gold-dim:     rgba(255, 200, 50, 0.18);
  --gold-border:  rgba(255, 200, 50, 0.28);
  --red:          #c0392b;
  --red-bright:   #e74c3c;
  --text:         #fde8c8;
  --text-dim:     rgba(253, 232, 200, 0.55);
  --card-bg:      rgba(255, 200, 50, 0.07);
  --shop-height:  52vh;
  --header-h:     54px;
  --radius:       12px;
}

/* ── 重置 ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
               -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  color: var(--text);
  background: var(--bg-deep);
  -webkit-font-smoothing: antialiased;
}

/* ── 背景天空（随进度变化） ─────────────────────────────────── */
body {
  background: linear-gradient(170deg, var(--bg-deep) 0%, var(--bg-mid) 100%);
  transition: background 3s ease;
}
body.milestone-1 { background: linear-gradient(170deg, #2a0408 0%, #500d1a 100%); }
body.milestone-2 { background: linear-gradient(170deg, #3d0610 0%, #6b1020 100%); }
body.milestone-3 { background: linear-gradient(170deg, #5a0a0a 0%, #8b1a0a 100%); }

/* ── 背景灯笼 ───────────────────────────────────────────────── */
.lanterns-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.lantern {
  position: absolute;
  font-size: clamp(1.4rem, 4vw, 2.2rem);
  opacity: 0.28;
  animation:
    bobLantern  var(--dur,         4s)   ease-in-out infinite,
    flickerGlow var(--flicker-dur, 2.3s) ease-in-out infinite;
  animation-delay: var(--del, 0s), var(--flicker-del, 0s);
  user-select: none;
}

.lantern::after {
  content: '';
  position: absolute;
  bottom: -8px; left: 50%;
  transform: translateX(-50%);
  width: 200%; height: 60%;
  background: radial-gradient(ellipse at center top,
    rgba(255,120,20,.20) 0%, rgba(220,60,10,.08) 50%, transparent 100%);
  border-radius: 50%;
  pointer-events: none;
  filter: blur(4px);
  animation: flickerGlow var(--flicker-dur, 2.3s) ease-in-out infinite;
  animation-delay: var(--flicker-del, 0s);
}

@keyframes bobLantern {
  0%, 100% { transform: translateY(0)     rotate(-4deg); }
  50%       { transform: translateY(-14px) rotate(4deg);  }
}

@keyframes flickerGlow {
  0%   { filter: drop-shadow(0 0  6px rgba(255,120,20,.55)) drop-shadow(0 0 14px rgba(220,60,10,.30)); }
  18%  { filter: drop-shadow(0 0 10px rgba(255,160,30,.80)) drop-shadow(0 0 22px rgba(240,80,10,.45)); }
  35%  { filter: drop-shadow(0 0  5px rgba(255,100,10,.45)) drop-shadow(0 0 12px rgba(200,50, 5,.25)); }
  52%  { filter: drop-shadow(0 0 12px rgba(255,180,40,.90)) drop-shadow(0 0 28px rgba(255,100,20,.50)); }
  70%  { filter: drop-shadow(0 0  7px rgba(255,130,20,.60)) drop-shadow(0 0 16px rgba(220,70,10,.35)); }
  100% { filter: drop-shadow(0 0  6px rgba(255,120,20,.55)) drop-shadow(0 0 14px rgba(220,60,10,.30)); }
}

/* ── App 外壳 ───────────────────────────────────────────────── */
.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh; /* 旧浏览器回退 */
  overflow: hidden;
}

/* ── 顶部标题栏 ─────────────────────────────────────────────── */
.game-header {
  flex-shrink: 0;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: rgba(26, 2, 5, 0.88);
  border-bottom: 1px solid var(--gold-border);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.game-title {
  font-size: clamp(0.95rem, 4.5vw, 1.2rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--gold-light);
  text-shadow: 0 0 12px rgba(255, 200, 50, 0.45);
  white-space: nowrap;
}

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

.tys-display {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--gold);
  background: var(--gold-dim);
  border: 1px solid var(--gold-border);
  border-radius: 20px;
  padding: 3px 10px;
  white-space: nowrap;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 4px;
  opacity: 0.7;
  transition: opacity 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { opacity: 1; }

/* ── 汤圆收集区 ─────────────────────────────────────────────── */
.clicker-area {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}

/* 顶部统计（叠在捕捉区上方） */
.catch-stats {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 12px 4px;
  z-index: 15;
  pointer-events: none; /* 不遮挡汤圆点击 */
}

.tangyuan-counter {
  font-size: clamp(1.5rem, 6vw, 2rem);
  font-weight: 800;
  color: var(--gold-light);
  text-shadow: 0 0 16px rgba(255, 200, 50, 0.55);
  line-height: 1.1;
  text-align: center;
}
.counter-label {
  font-size: 0.75em;
  font-weight: 400;
  color: var(--text-dim);
}

.click-power-display {
  font-size: 0.72rem;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  margin-top: 2px;
}

/* 淡水印提示 */
.catch-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.8rem;
  color: rgba(253, 232, 200, 0.12);
  pointer-events: none;
  text-align: center;
  z-index: 1;
  white-space: nowrap;
  user-select: none;
}

/* ── 落下的汤圆 ─────────────────────────────────────────────── */
@keyframes fallDown {
  0%   { top: -72px; transform: rotate(0deg);   }
  30%  {             transform: rotate(14deg);  }
  65%  {             transform: rotate(-11deg); }
  100% { top: 108%;  transform: rotate(8deg);   }
}

@keyframes catchBurst {
  0%   { transform: scale(1);    opacity: 1; }
  40%  { transform: scale(1.9);  opacity: 0.8; }
  100% { transform: scale(0.3);  opacity: 0; }
}

.falling-tangyuan {
  position: absolute;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  /* 汤圆外观：白色球体渐变 */
  background: radial-gradient(circle at 38% 32%,
    #fffcf5 0%,
    #f5e8d0 50%,
    #ddc89a 100%
  );
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.35),
    0 0 0 2px rgba(255, 210, 120, 0.25),
    inset 0 -4px 8px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  z-index: 10;
  touch-action: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  animation: fallDown var(--fall-dur, 2.8s) linear forwards;
  will-change: top, transform;
}

.falling-tangyuan:active {
  filter: brightness(1.3);
}

.tangyuan-caught {
  pointer-events: none;
  animation: catchBurst 0.38s ease-out forwards !important;
}

/* ── 浮动 "+N" 文字 ──────────────────────────────────────────── */
@keyframes floatUp {
  0%   { opacity: 1;   transform: translateY(0)     scale(1);    }
  20%  { opacity: 1;   transform: translateY(-10px) scale(1.12); }
  100% { opacity: 0;   transform: translateY(-64px) scale(0.85); }
}

.float-text {
  position: absolute;
  color: var(--gold-light);
  font-weight: 800;
  font-size: 1.15rem;
  pointer-events: none;
  animation: floatUp 0.85s ease-out forwards;
  z-index: 20;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9);
  white-space: nowrap;
}

/* ── 连击显示 ────────────────────────────────────────────────── */
.combo-display {
  flex-shrink: 0;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--red-bright);
  text-shadow: 0 0 8px rgba(231, 76, 60, 0.6);
  opacity: 0;
  transition: opacity 0.3s;
  min-height: 1.4em;
  text-align: center;
  padding-bottom: 6px;
  z-index: 15;
}

@keyframes comboPulse1 {
  0%, 100% { transform: scale(1);    }
  50%       { transform: scale(1.06); }
}
@keyframes comboPulse2 {
  0%, 100% { transform: scale(1);   text-shadow: 0 0 10px #f39c12; }
  50%       { transform: scale(1.1); text-shadow: 0 0 22px #e74c3c, 0 0 8px #f39c12; }
}
@keyframes comboPulse3 {
  0%,100% { transform: scale(1)    rotate(0deg);    text-shadow: 0 0 14px #e74c3c; }
  25%      { transform: scale(1.15) rotate(-1.5deg); }
  75%      { transform: scale(1.15) rotate(1.5deg);  text-shadow: 0 0 30px #ff4500, 0 0 10px #ffd166; }
}

.combo-display.combo-phase-1 {
  opacity: 1;
  color: #f5a623;
  animation: comboPulse1 0.8s ease-in-out infinite;
}
.combo-display.combo-phase-2 {
  opacity: 1;
  color: #e74c3c;
  font-size: 1rem;
  animation: comboPulse2 0.5s ease-in-out infinite;
}
.combo-display.combo-phase-3 {
  opacity: 1;
  color: #ff4500;
  font-size: 1.1rem;
  animation: comboPulse3 0.35s ease-in-out infinite;
}

/* ── 商店 ────────────────────────────────────────────────────── */
.shop {
  flex-shrink: 0;
  height: var(--shop-height);
  height: 52dvh;
  display: flex;
  flex-direction: column;
  background: rgba(14, 2, 4, 0.95);
  border-top: 1px solid var(--gold-border);
}

/* 选项卡栏 */
.tab-bar {
  flex-shrink: 0;
  display: flex;
  border-bottom: 1px solid var(--gold-border);
}

.tab-btn {
  flex: 1;
  padding: 9px 4px;
  background: rgba(40, 5, 8, 0.40);
  border: none;
  color: var(--text-dim);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.tab-btn.active {
  color: var(--gold-light);
  background: var(--gold-dim);
  border-bottom: 2px solid var(--gold);
}

/* 商店滚动区 */
.shop-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ── 商店卡片（统一三列网格布局） ─────────────────────────────── */
.shop-list {
  padding: 6px 0 calc(env(safe-area-inset-bottom, 0px) + 80px);
}
.shop-list.hidden { display: none; }

.shop-card {
  display: grid;
  grid-template-columns: 46px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 9px 12px;
  margin: 5px 8px;
  background: var(--card-bg);
  border: 1px solid var(--gold-border);
  border-radius: var(--radius);
  transition: background 0.2s, opacity 0.2s;
}

.shop-card.unaffordable { opacity: 0.42; }

.shop-card.purchased {
  background: rgba(255, 200, 50, 0.12);
  border-color: rgba(255, 200, 50, 0.45);
}

/* 左列：图标 */
.b-emoji {
  font-size: 1.75rem;
  line-height: 1;
  text-align: center;
}

/* 中列：名称 + 统计 + 描述 */
.b-body {
  min-width: 0;
}

.b-name {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 生产者统计：每秒 X 个 · 已产 Y 个 */
.b-stats {
  font-size: 0.63rem;
  color: var(--text-dim);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

.b-stats strong {
  color: var(--gold);
  font-weight: 700;
}

.b-stats-sep {
  margin: 0 4px;
  opacity: 0.5;
}

/* 馅料描述 */
.b-desc {
  font-size: 0.63rem;
  color: var(--text-dim);
  margin-top: 3px;
  line-height: 1.35;
}

/* 馅料效果标签 */
.filling-bonus {
  font-size: 0.6rem;
  background: var(--red);
  color: #fff;
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 5px;
  vertical-align: middle;
  font-weight: 600;
}

/* 右列：数量徽章 + 购买按钮 */
.b-tail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

/* ×N 数量徽章 */
.b-count {
  font-size: 0.95rem;
  font-weight: 900;
  color: var(--gold-light);
  background: var(--gold-dim);
  border: 1px solid var(--gold-border);
  border-radius: 6px;
  padding: 1px 7px;
  text-align: center;
  min-width: 34px;
  white-space: nowrap;
}

/* 购买按钮 */
.buy-btn {
  background: linear-gradient(135deg, var(--red) 0%, #8b1a1a 100%);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  letter-spacing: 0.02em;
  line-height: 1.3;
  text-align: center;
}

.buy-btn:not(:disabled):active { transform: scale(0.92); }

.buy-btn:disabled {
  background: rgba(100, 80, 80, 0.45);
  color: var(--text-dim);
  cursor: default;
}

/* 已拥有徽章（馅料） */
.purchased-badge {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--gold);
  background: var(--gold-dim);
  border: 1px solid var(--gold-border);
  border-radius: 8px;
  padding: 4px 8px;
  white-space: nowrap;
}

/* ── 滚动条（Webkit） ────────────────────────────────────────── */
.shop-content::-webkit-scrollbar { width: 4px; }
.shop-content::-webkit-scrollbar-track { background: transparent; }
.shop-content::-webkit-scrollbar-thumb {
  background: var(--gold-border);
  border-radius: 2px;
}

/* ── 成就弹窗 ────────────────────────────────────────────────── */
@keyframes overlayIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes boxPop {
  0%   { transform: scale(0.5) translateY(30px); opacity: 0; }
  70%  { transform: scale(1.05);                 opacity: 1; }
  100% { transform: scale(1);                    opacity: 1; }
}

@keyframes particleFly {
  0%   { transform: rotate(var(--angle)) translateX(0);           opacity: 1; }
  80%  {                                                           opacity: 1; }
  100% { transform: rotate(var(--angle)) translateX(var(--dist)); opacity: 0; }
}

.achievement-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 2, 3, 0.82);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: overlayIn 0.4s ease forwards;
  padding: 24px;
}

.achievement-overlay.ending {
  background: rgba(10, 2, 3, 0.96);
}

.ach-box {
  background: linear-gradient(160deg, #1a0205 0%, #3d0810 100%);
  border: 2px solid var(--gold);
  border-radius: 20px;
  padding: 32px 24px 24px;
  max-width: 340px;
  width: 100%;
  text-align: center;
  box-shadow:
    0 0 40px rgba(255, 200, 50, 0.35),
    0 0 80px rgba(200, 50, 50, 0.2);
  animation: boxPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.ach-icon {
  font-size: 3.5rem;
  line-height: 1;
  margin-bottom: 14px;
}

.ach-title {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--gold-light);
  text-shadow: 0 0 16px rgba(255, 200, 50, 0.6);
  margin-bottom: 4px;
  letter-spacing: 0.03em;
}

.ach-subtitle {
  font-size: 0.78rem;
  color: var(--gold);
  opacity: 0.85;
  margin-bottom: 14px;
}

.ach-desc {
  font-size: 0.82rem;
  color: var(--text);
  line-height: 1.7;
  margin-bottom: 22px;
  opacity: 0.92;
}

.ach-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.ach-btn {
  background: linear-gradient(135deg, var(--red) 0%, #8b1a1a 100%);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 20px;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.ach-btn:active { transform: scale(0.92); }

.ach-btn.ach-continue {
  background: var(--gold-dim);
  border: 1px solid var(--gold-border);
  color: var(--gold-light);
}

.ach-btn.ach-restart {
  background: linear-gradient(135deg, #e74c3c 0%, #8b0000 100%);
}

/* 粒子爆炸效果 */
.ach-particle {
  position: fixed;
  left: 50%;
  top: 40%;
  pointer-events: none;
  z-index: 101;
  animation: particleFly linear forwards;
}

/* ── 响应式（宽屏） ──────────────────────────────────────────── */
@media (min-width: 540px) {
  :root { --shop-height: 48vh; }
  .game-title  { font-size: 1.2rem; }
  .shop-card   { padding: 10px 16px; margin: 6px 12px; }
  .b-name      { font-size: 0.92rem; }
  .b-stats     { font-size: 0.67rem; }
  .b-desc      { font-size: 0.67rem; }
}

@media (min-width: 768px) {
  :root { --shop-height: 44vh; }
  .game-title  { font-size: 1.3rem; }
}

/* ── 彩灯串 ─────────────────────────────────────────────────── */
.light-string {
  flex-shrink: 0;
  position: relative;
  height: 22px;
  width: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: space-evenly;
  padding: 0 8px;
  z-index: 14;
  pointer-events: none;
}

.string-wire {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg,
    transparent 0%, rgba(200,50,20,.55) 8%, rgba(180,40,15,.70) 50%,
    rgba(200,50,20,.55) 92%, transparent 100%);
}

.bulb {
  position: relative;
  display: block;
  width: 10px; height: 14px;
  border-radius: 50% 50% 45% 45%;
  animation: bulbFlicker 3.2s ease-in-out infinite;
  animation-delay: var(--blink-del, 0s);
}

.bulb::before {
  content: '';
  position: absolute;
  top: -4px; left: 50%;
  transform: translateX(-50%);
  width: 4px; height: 4px;
  background: rgba(180,140,80,.8);
  border-radius: 1px;
}

.bulb-red {
  background: radial-gradient(circle at 38% 32%, #ff6655, #cc1a0a);
  box-shadow: 0 0 4px 1px rgba(220,40,10,.60), 0 0 10px 2px rgba(200,30,5,.30);
}

.bulb-gold {
  background: radial-gradient(circle at 38% 32%, #ffe066, #cc8800);
  box-shadow: 0 0 4px 1px rgba(255,190,20,.65), 0 0 10px 2px rgba(220,150,10,.30);
}

@keyframes bulbFlicker {
  0%   { opacity: .80; filter: brightness(.90); }
  15%  { opacity: 1.0; filter: brightness(1.30); }
  30%  { opacity: .65; filter: brightness(.70); }
  45%  { opacity: .95; filter: brightness(1.10); }
  60%  { opacity: 1.0; filter: brightness(1.40); }
  75%  { opacity: .75; filter: brightness(.80); }
  100% { opacity: .80; filter: brightness(.90); }
}

/* ── 环境闪光粒子 ───────────────────────────────────────────── */
@keyframes sparkleFade {
  0%   { opacity: 0;    transform: scale(.3)  translateY(0);     }
  20%  { opacity: 1;    transform: scale(1)   translateY(-4px);  }
  60%  { opacity: .85;  transform: scale(.85) translateY(-10px); }
  100% { opacity: 0;    transform: scale(.4)  translateY(-20px); }
}

.ambient-sparkle {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  z-index: 2;
  will-change: opacity, transform;
  animation: sparkleFade var(--sp-dur, 1.4s) ease-out forwards;
}
