/* ===== 全局变量 ===== */
:root {
  --bg-gradient: linear-gradient(180deg, #FFF5E6 0%, #FFE9B8 100%);
  --card-bg: #FFFFFF;
  --primary: #FFC947;
  --accent: #FF6B6B;
  --blue: #4A90D9;
  --text-primary: #3D3D3D;
  --text-secondary: #8B7355;
  --shadow-warm: rgba(255, 201, 71, 0.15);
  --shadow-red: rgba(255, 107, 107, 0.3);
  --radius-large: 24px;
  --radius-medium: 20px;
  --radius-pill: 50px;
}

/* ===== 基础重置 ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text-primary);
  overflow-x: hidden;
  min-height: 100vh;
  position: relative;
}

button {
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

button:active:not(:disabled) {
  transform: scale(0.95);
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

.hidden {
  display: none !important;
}

/* ===== iOS 体感按钮 ===== */
.tilt-permission-btn {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  padding: 14px 28px;
  border-radius: 999px;
  background: linear-gradient(180deg, #5BA0E8 0%, #4A90D9 100%);
  color: #fff;
  font-size: 16px;
  font-weight: bold;
  letter-spacing: 1px;
  box-shadow: 0 6px 20px rgba(74, 144, 217, 0.45);
  animation: claimPulse 1.6s ease-in-out infinite;
}

/* ===== 页面切换 ===== */
.page {
  display: none;
  min-height: 100vh;
  padding: 16px 20px 12px;
  animation: fadeIn 0.3s ease;
}

.page.active {
  display: flex;
  flex-direction: column;
}

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

/* ===== 顶部 ===== */
.header {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 12px 0;
}

.title {
  font-size: 30px;
  font-weight: bold;
  letter-spacing: 2px;
}

.header-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

/* 音乐按钮 */
.music-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--card-bg);
  color: var(--text-primary);
  font-size: 20px;
  box-shadow: 0 2px 8px var(--shadow-warm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.music-btn.off {
  color: #BBB;
  text-decoration: line-through;
}

/* 仓库按钮（背包图标） */
.warehouse-btn {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  overflow: visible;
  position: relative;
  filter: drop-shadow(0 3px 8px var(--shadow-warm));
}

.warehouse-btn img {
  width: 100%;
  height: 100%;
  border-radius: 14px;
}

.badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #FF3B30;
  color: white;
  border-radius: 999px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
  box-shadow: 0 2px 6px rgba(255, 59, 48, 0.5);
  border: 2px solid #FFF;
}

/* ===== 扭蛋机区域 ===== */
.machine-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 0 20px;
}

.machine-wrapper {
  position: relative;
  width: min(78%, 360px);
}

.machine-img {
  width: 100%;
  filter: drop-shadow(0 10px 24px rgba(139, 115, 85, 0.25));
}

/* ===== 摇晃 + 闪光 ===== */
.machine-img.shaking {
  animation: shake 0.55s ease-in-out 3;
}

@keyframes shake {
  0%, 100% { transform: rotate(0deg) translateX(0); }
  20% { transform: rotate(-6deg) translateX(-8px); }
  40% { transform: rotate(5deg) translateX(7px); }
  60% { transform: rotate(-4deg) translateX(-5px); }
  80% { transform: rotate(3deg) translateX(3px); }
}

.sparkle-layer {
  position: absolute;
  inset: -8%;
  pointer-events: none;
  opacity: 0;
  overflow: visible;
}

.sparkle-layer.active {
  opacity: 1;
}

.sparkle {
  position: absolute;
  width: 14px;
  height: 14px;
  background: #FFF;
  border-radius: 50%;
  box-shadow:
    0 0 6px 2px rgba(255, 255, 255, 0.9),
    0 0 14px 6px rgba(255, 224, 130, 0.6);
  animation: sparkleAnim var(--dur, 0.9s) ease-in-out infinite;
  animation-delay: var(--delay, 0s);
}

@keyframes sparkleAnim {
  0%, 100% { transform: scale(0) rotate(0deg); opacity: 0; }
  50% { transform: scale(1) rotate(180deg); opacity: 1; }
}

/* ===== 出奖遮罩 ===== */
.prize-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 25, 18, 0.72);
  backdrop-filter: blur(2px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 36px;
  z-index: 200;
  animation: overlayIn 0.3s ease;
}

@keyframes overlayIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.prize-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  perspective: 1000px;
}

.prize-3d {
  width: min(60vw, 260px);
  height: min(60vw, 260px);
  object-fit: contain;
  filter: drop-shadow(0 16px 40px rgba(0, 0, 0, 0.5)) drop-shadow(0 0 24px rgba(255, 224, 130, 0.45));
  transition: transform 0.08s ease-out;
  transform-style: preserve-3d;
  animation: prizeIn 0.5s cubic-bezier(0.2, 1.4, 0.4, 1);
}

@keyframes prizeIn {
  0% { transform: scale(0.1) translateY(80px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.prize-name {
  font-size: 26px;
  font-weight: bold;
  color: #FFF;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
  letter-spacing: 2px;
}

/* 收下按钮 - 蓝色 */
.claim-btn {
  width: 180px;
  height: 56px;
  border-radius: var(--radius-pill);
  background: linear-gradient(180deg, #5BA0E8 0%, #4A90D9 100%);
  color: white;
  font-size: 20px;
  font-weight: bold;
  letter-spacing: 6px;
  text-indent: 6px;
  box-shadow: 0 6px 20px rgba(74, 144, 217, 0.45);
  animation: claimPulse 1.6s ease-in-out infinite;
}

@keyframes claimPulse {
  0%, 100% { box-shadow: 0 6px 20px rgba(74, 144, 217, 0.45); }
  50% { box-shadow: 0 6px 30px rgba(74, 144, 217, 0.65); }
}

/* ===== 扭蛋按钮 ===== */
.gacha-btn {
  width: 180px;
  height: 52px;
  margin-top: 12px;
  border-radius: var(--radius-pill);
  background: linear-gradient(180deg, #FF8A80 0%, #FF6B6B 100%);
  color: white;
  font-size: 19px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.15);
  font-weight: bold;
  letter-spacing: 4px;
  box-shadow: 0 6px 18px var(--shadow-red);
  flex: 0 0 auto;
}

.gacha-btn:disabled {
  background: #CCC;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  cursor: not-allowed;
}

/* ===== 奖品预览区 ===== */
.prize-preview {
  margin-top: 8px;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0 4px;
}

.section-title {
  font-size: 17px;
  font-weight: bold;
}

.progress-text {
  font-size: 13px;
  color: var(--text-secondary);
}

.scroll-hint {
  text-align: center;
  font-size: 11px;
  color: var(--text-secondary);
  opacity: 0.55;
  margin: 6px 0 8px;
}

/* 关键：横向滚动容器 */
.prize-list {
  background: var(--card-bg);
  border-radius: var(--radius-medium);
  padding: 14px;
  box-shadow: 0 4px 16px var(--shadow-warm);
  display: flex;
  gap: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;   /* iOS 惯性滚动 */
  scrollbar-width: thin;
  scrollbar-color: #FFC947 transparent;
}

.prize-list::-webkit-scrollbar {
  height: 6px;
}

.prize-list::-webkit-scrollbar-track {
  background: transparent;
}

.prize-list::-webkit-scrollbar-thumb {
  background: #FFDF9E;
  border-radius: 3px;
}

.prize-item {
  flex: 0 0 auto;          /* 不压缩，可滚动 */
  width: 72px;
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.prize-item img {
  width: 64px;
  height: 64px;
  object-fit: contain;
  transition: filter 0.3s ease, opacity 0.3s ease;
}

.prize-item.claimed img {
  filter: grayscale(100%);
  opacity: 0.45;
}

.prize-item.claimed::before {
  content: "✓";
  position: absolute;
  top: 0px;
  right: 0px;
  width: 18px;
  height: 18px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: bold;
}

.prize-item { position: relative; }

.prize-item-name {
  font-size: 10px;
  color: var(--text-secondary);
  text-align: center;
  white-space: nowrap;
}

/* ===== 免责声明 ===== */
.disclaimer {
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
  opacity: 0.7;
  padding: 14px 0 10px;
  margin-top: auto;
}

/* ===== 仓库页面 ===== */
.warehouse-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 0 16px;
}

.back-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--card-bg);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px var(--shadow-warm);
}

.warehouse-title {
  font-size: 24px;
  font-weight: bold;
}

/* 统一卡片：固定正方 + 名称行 */
.warehouse-content {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  grid-auto-rows: min-content;   /* 行高按内容，不拉伸 */
  align-content: start;          /* 整体顶部对齐，不撑满 */
  gap: 14px;
  padding-bottom: 24px;
}

.warehouse-item {
  background: var(--card-bg);
  border-radius: var(--radius-medium);
  padding: 10px;
  box-shadow: 0 4px 16px var(--shadow-warm);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: transform 0.08s ease-out;
  transform-style: preserve-3d;
}

.warehouse-item .img-box {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.warehouse-item img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.warehouse-item-name {
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.warehouse-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 80px 20px;
  color: var(--text-secondary);
  font-size: 16px;
}
