/* ================================
   月圆合合乐 · 中秋合成大作战
   全局样式
   ================================ */

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

:root {
  --color-bg: #0a2240;
  --color-bg-dark: #071a33;
  --color-bg-mid: #11315a;
  --color-moon: #f5e6c8;
  --color-gold: #d4a853;
  --color-red: #c44545;
  --color-text: #fff;
  --color-text-dim: rgba(255,255,255,0.65);
  --color-btn-primary: linear-gradient(135deg, #f5d085, #d4a853);
  --color-btn-ghost: rgba(255,255,255,0.15);
  --font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-family);
  color: var(--color-text);
  background: var(--color-bg);
  position: relative;
}

body {
  max-width: 480px;
  margin: 0 auto;
  background: linear-gradient(180deg, #071a33 0%, #0a2240 40%, #11315a 100%);
}

/* ================================
   页面切换
   ================================ */
.page {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: none !important;
  overflow: hidden;
  max-width: 480px;
  margin: 0 auto;
  z-index: 1;
}

.page.active {
  display: block !important;
  z-index: 10;
}

#page-login.active,
#page-game.active,
#page-result.active {
  display: flex !important;
}

#page-home.active,
#page-ranking.active {
  display: block !important;
}

.hidden {
  display: none !important;
}

/* ================================
   首页
   ================================ */
#page-home {
  overflow: hidden;
  z-index: 5;
  background: #071a33;
}

#page-home.active {
  z-index: 5;
}

#page-home .home-bg-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  background: #071a33;
}

.home-btn {
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);
  background: transparent;
  border: none;
  cursor: pointer;
  z-index: 999;
  border-radius: 999px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.home-btn:active {
  transform: translate(-50%, -50%) scale(0.96);
}

.home-btn-start {
  top: 59%;
  width: 300px;
  height: 72px;
}

.home-btn-ranking {
  top: 67.5%;
  width: 300px;
  height: 72px;
  border-radius: 36px;
}

/* 活动结束提示横幅 */
.ended-banner {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 9999;
  width: 85%;
  max-width: 420px;
}
.ended-banner-inner {
  background: linear-gradient(135deg, #0a1a3f 0%, #142860 100%);
  border: 2px solid #d4a74a;
  border-radius: 20px;
  padding: 28px 20px;
  text-align: center;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}
.ended-title {
  font-size: 24px;
  font-weight: bold;
  color: #f5c96e;
  margin-bottom: 12px;
  text-shadow: 0 2px 8px rgba(212, 167, 74, 0.4);
}
.ended-sub {
  font-size: 14px;
  color: #c4cde0;
  line-height: 1.6;
  margin-bottom: 20px;
}
.ended-btn {
  background: linear-gradient(135deg, #e9b65a, #d4941f);
  color: #1a2a5a;
  font-weight: bold;
  font-size: 16px;
  border: none;
  border-radius: 999px;
  padding: 12px 32px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(212, 167, 74, 0.4);
}
.ended-btn:active {
  transform: scale(0.97);
}
.home-btn-disabled {
  pointer-events: none;
  opacity: 0.4;
  filter: grayscale(0.6);
}

/* ================================
   按钮
   ================================ */
.btn {
  border: none;
  border-radius: 24px;
  padding: 14px 36px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: var(--color-btn-primary);
  color: #3a2810;
  box-shadow: 0 6px 20px rgba(212,168,83,0.35);
}

.btn-primary:active {
  box-shadow: 0 3px 10px rgba(212,168,83,0.35);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  filter: grayscale(0.3);
  transform: none !important;
}

.btn-ghost {
  background: var(--color-btn-ghost);
  color: var(--color-text);
  border: 1px solid rgba(255,255,255,0.2);
}

/* ================================
   登录页
   ================================ */
#page-login {
  background: linear-gradient(180deg, #071a33 0%, #0a2240 50%, #11315a 100%);
  padding: 40px 30px;
  display: flex;
  align-items: center;
  z-index: 20;
}

#page-login.active {
  display: flex;
  z-index: 20;
}

.login-container {
  width: 100%;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(212,168,83,0.25);
  border-radius: 24px;
  padding: 36px 28px;
  backdrop-filter: blur(10px);
}

.login-header {
  text-align: center;
  margin-bottom: 28px;
}

.login-moon {
  font-size: 44px;
  margin-bottom: 10px;
  animation: glow 2s ease-in-out infinite alternate;
}

@keyframes glow {
  0% { filter: drop-shadow(0 0 5px rgba(245,230,200,0.5)); }
  100% { filter: drop-shadow(0 0 20px rgba(245,230,200,0.9)); }
}

.login-header h2 {
  font-size: 22px;
  color: var(--color-moon);
  margin-bottom: 14px;
}

.login-rules {
  background: rgba(255,248,224,0.1);
  border: 1px solid rgba(212,168,83,0.4);
  border-radius: 12px;
  padding: 14px 16px;
  margin: 12px 0;
  text-align: left;
}

.login-rules-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-gold);
  margin-bottom: 8px;
}

.login-rules-steps {
  font-size: 12px;
  color: var(--color-text-dim);
  line-height: 1.9;
}

.login-rules-chain {
  font-size: 16px;
  text-align: center;
  margin-top: 10px;
  letter-spacing: 2px;
}

.login-tip {
  font-size: 13px;
  color: var(--color-text-dim);
  line-height: 1.6;
}

.login-tip-main {
  font-size: 15px;
  color: var(--color-gold);
  font-weight: 600;
  margin-bottom: 4px;
}

.login-tip-sub {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed rgba(212,168,83,0.3);
  font-size: 12px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.form-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-item label {
  font-size: 14px;
  color: var(--color-moon);
}

.form-item input {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(212,168,83,0.3);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 16px;
  color: var(--color-text);
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.form-item input::placeholder {
  color: rgba(255,255,255,0.3);
}

.form-item input:focus {
  border-color: var(--color-gold);
  background: rgba(255,255,255,0.1);
}

.btn-enter {
  margin-top: 10px;
  padding: 16px;
  font-size: 18px;
}

.form-footer {
  text-align: center;
  font-size: 12px;
  color: var(--color-text-dim);
}

/* ================================
   游戏页
   ================================ */
#page-game {
  background: linear-gradient(180deg, #071a33 0%, #0a2240 50%, #11315a 100%);
  display: flex;
  flex-direction: column;
  z-index: 15;
  /* 防止出现滚动条，底部不会变成无底洞 */
  height: 100vh;
  height: 100dvh; /* 手机动态视口 */
  height: 100svh;
  overflow: hidden;
}

#page-game.active {
  display: flex;
  z-index: 15;
}

.game-wrapper {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  max-width: 900px;
  margin: 0 auto;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  background: rgba(0,0,0,0.35);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  flex-shrink: 0;
  min-height: 56px;
}

.score-box, .level-box, .next-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 56px;
}

.score-label, .level-label, .next-label {
  font-size: 11px;
  color: var(--color-text-dim);
  margin-bottom: 2px;
  line-height: 1;
}

.score-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--color-gold);
  line-height: 1.1;
}

.level-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-moon);
  line-height: 1.2;
}

.next-badge {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  background: rgba(212,168,83,0.15);
  border: 1px solid rgba(212,168,83,0.4);
  box-shadow: 0 0 10px rgba(212,168,83,0.25);
  line-height: 1;
}

.btn-pause {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  color: var(--color-text);
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.btn-pause:active {
  transform: scale(0.94);
}

.game-body {
  flex: 1 1 auto;
  display: flex;
  min-height: 0; /* Flexbox layout: prevent overflow */
  width: 100%;
  position: relative;
}

.chain-sidebar {
  width: 82px;
  flex-shrink: 0;
  padding: 10px 6px;
  background: rgba(0,0,0,0.25);
  border-right: 1px solid rgba(212,168,83,0.15);
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
}

.chain-title {
  font-size: 11px;
  color: var(--color-text-dim);
  text-align: center;
  padding: 4px 0 8px;
  letter-spacing: 1px;
  border-bottom: 1px dashed rgba(212,168,83,0.2);
  margin-bottom: 4px;
}

.chain-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 4px;
  border-radius: 8px;
  font-size: 12px;
  color: rgba(255,255,255,0.35);
  transition: all 0.25s;
}

.chain-item .chain-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.15) inset;
  flex-shrink: 0;
  opacity: 0.4;
}

.chain-item.unlocked {
  color: rgba(255,255,255,0.95);
  background: rgba(212,168,83,0.1);
  box-shadow: 0 0 0 1px rgba(212,168,83,0.25) inset;
}

.chain-item.unlocked .chain-dot {
  opacity: 1;
  box-shadow: 0 0 10px currentColor, 0 0 0 1px rgba(255,255,255,0.3) inset;
}

.chain-item.fullmoon-unlocked {
  color: #fff2b5 !important;
  background: linear-gradient(90deg, rgba(255,200,60,0.15), rgba(255,240,150,0.22), rgba(255,200,60,0.15));
  border: 1px solid rgba(255,210,80,0.55);
  animation: fullmoonGlow 1.8s ease-in-out infinite;
  position: relative;
}

.chain-item.fullmoon-unlocked::after {
  content: '✓';
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  color: #ffe066;
  font-weight: bold;
  font-size: 14px;
  text-shadow: 0 0 8px rgba(255,220,100,0.9);
}

.chain-item.fullmoon-unlocked .chain-dot {
  animation: fullmoonPulse 1.8s ease-in-out infinite;
  box-shadow: 0 0 14px #fff2a8, 0 0 0 2px #ffe066 inset;
}

@keyframes fullmoonGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,220,100,0.4), 0 0 0 1px rgba(255,210,80,0.55) inset; }
  50%      { box-shadow: 0 0 18px 2px rgba(255,220,100,0.65), 0 0 0 1px rgba(255,210,80,0.75) inset; }
}

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

.canvas-wrap {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  position: relative;
}

#game-canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* 手机端：隐藏侧边合成链（canvas 内用警戒红线+顶部状态替代） */
@media (max-width: 640px) {
  .chain-sidebar { display: none; }

  .game-header {
    padding: 8px 10px;
    min-height: 50px;
    gap: 4px;
  }
  .score-box, .level-box, .next-box { min-width: 48px; }
  .score-value { font-size: 20px; }
  .level-value { font-size: 13px; }
  .next-badge { width: 26px; height: 26px; font-size: 16px; }
  .btn-pause { width: 34px; height: 34px; font-size: 15px; }
}

/* 横屏提示 */
.orientation-lock {
  display: none;
  position: fixed;
  inset: 0;
  background: #071a33;
  color: #fff;
  z-index: 9999;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
  text-align: center;
}
.orientation-lock .lock-icon { font-size: 48px; }
.orientation-lock .lock-text { font-size: 16px; color: #d4a853; }

@media (orientation: landscape) and (max-height: 500px) {
  .orientation-lock { display: flex; }
  #app-wrap > .page { display: none !important; }
}

/* ================================
   遮罩
   ================================ */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.overlay-content {
  background: linear-gradient(180deg, #142d4e 0%, #0e2038 100%);
  border: 1px solid rgba(212,168,83,0.45);
  border-radius: 24px;
  padding: 30px 40px;
  text-align: center;
  min-width: 260px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5), 0 0 0 1px rgba(212,168,83,0.1) inset;
}

.overlay-content h3 {
  font-size: 22px;
  color: var(--color-moon);
}

.gameover-content {
  min-width: 280px;
}

.gameover-emoji {
  font-size: 56px;
  animation: bounce 0.6s ease;
}

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

.gameover-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 10px 0;
}

.gameover-score span {
  font-size: 13px;
  color: var(--color-text-dim);
  margin-bottom: 4px;
}

.gameover-score strong {
  font-size: 42px;
  color: var(--color-gold);
  font-weight: 800;
}

.gameover-rank {
  font-size: 14px;
  color: var(--color-moon);
  margin-bottom: 8px;
}

.gameover-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ================================
   结算页
   ================================ */
#page-result {
  background: linear-gradient(180deg, #071a33 0%, #0a2240 50%, #11315a 100%);
  padding: 40px 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 18;
}

#page-result.active {
  display: flex;
  z-index: 18;
}

.result-container {
  width: 100%;
  text-align: center;
}

.result-header {
  margin-bottom: 30px;
}

.result-moon {
  font-size: 64px;
  animation: glow 2s ease-in-out infinite alternate;
}

.result-header h2 {
  font-size: 28px;
  color: var(--color-moon);
}

.result-score {
  display: flex;
  justify-content: center;
  margin-bottom: 30px;
}

.score-ring {
  position: relative;
  width: 180px;
  height: 180px;
}

.score-ring svg {
  transform: rotate(-90deg);
}

.score-bg {
  fill: none;
  stroke: rgba(212,168,83,0.2);
  stroke-width: 8;
}

.score-fg {
  fill: none;
  stroke: var(--color-gold);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 326.7;
  stroke-dashoffset: 326.7;
  transition: stroke-dashoffset 1s ease;
}

.score-ring-inner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.score-ring-inner span {
  font-size: 36px;
  font-weight: 800;
  color: var(--color-gold);
}

.score-ring-inner small {
  font-size: 12px;
  color: var(--color-text-dim);
}

.result-info {
  margin-bottom: 30px;
  font-size: 14px;
  color: var(--color-text-dim);
  line-height: 1.8;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ================================
   排行榜
   ================================ */
#page-ranking {
  background: linear-gradient(180deg, #071a33 0%, #0a2240 50%, #11315a 100%);
  padding: 20px 16px;
  overflow-y: auto;
  z-index: 25;
}

#page-ranking.active {
  z-index: 25;
}

.ranking-container {
  max-width: 440px;
  margin: 0 auto;
}

.ranking-back {
  position: absolute;
  top: 20px;
  left: 20px;
  background: rgba(212,168,83,0.2);
  border: 1px solid rgba(212,168,83,0.4);
  color: var(--color-gold);
  font-size: 14px;
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  z-index: 5;
  font-family: inherit;
}

.ranking-back:active {
  transform: scale(0.95);
}

.ranking-header {
  text-align: center;
  margin-bottom: 20px;
  padding: 16px;
}

.ranking-header h2 {
  font-size: 22px;
  color: var(--color-moon);
}

.ranking-status {
  font-size: 13px;
  color: var(--color-gold);
  margin-top: 6px;
}

.my-rank {
  background: linear-gradient(135deg, rgba(212,168,83,0.25), rgba(212,168,83,0.1));
  border: 1px solid rgba(212,168,83,0.4);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.my-rank .rank-num {
  font-size: 32px;
  font-weight: 800;
  color: var(--color-gold);
  min-width: 50px;
}

.my-rank .rank-info {
  flex: 1;
  margin: 0 12px;
}

.my-rank .rank-name {
  font-size: 16px;
  color: var(--color-moon);
  margin-bottom: 4px;
}

.my-rank .rank-score {
  font-size: 14px;
  color: var(--color-text-dim);
}

.ranking-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ranking-item {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.ranking-item.top-1 {
  background: linear-gradient(135deg, rgba(255,215,0,0.2), rgba(255,215,0,0.05));
  border-color: rgba(255,215,0,0.5);
}

.ranking-item.top-2 {
  background: linear-gradient(135deg, rgba(192,192,192,0.2), rgba(192,192,192,0.05));
  border-color: rgba(192,192,192,0.5);
}

.ranking-item.top-3 {
  background: linear-gradient(135deg, rgba(205,127,50,0.2), rgba(205,127,50,0.05));
  border-color: rgba(205,127,50,0.5);
}

.rank-badge {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 800;
  background: rgba(255,255,255,0.1);
  color: var(--color-text);
  flex-shrink: 0;
}

.top-1 .rank-badge { background: #ffd700; color: #3a2810; }
.top-2 .rank-badge { background: #c0c0c0; color: #3a2810; }
.top-3 .rank-badge { background: #cd7f32; color: #3a2810; }

.rank-detail {
  flex: 1;
  min-width: 0;
}

.rank-detail .rd-name {
  font-size: 15px;
  color: var(--color-text);
  margin-bottom: 2px;
}

.rank-detail .rd-phone {
  font-size: 12px;
  color: var(--color-text-dim);
}

.rank-detail .rd-meta {
  font-size: 11px;
  color: rgba(255,255,255,0.3);
  margin-top: 2px;
}

.rank-score-val {
  font-size: 20px;
  font-weight: 800;
  color: var(--color-gold);
  flex-shrink: 0;
}

/* ================================
   Toast
   ================================ */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(10px);
  border-radius: 12px;
  padding: 12px 24px;
  font-size: 14px;
  color: var(--color-text);
  z-index: 999;
  max-width: 80%;
  text-align: center;
  animation: toast-in 0.3s ease;
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, -40%); }
  to { opacity: 1; transform: translate(-50%, -50%); }
}

/* ================================
   合成特效
   ================================ */
.merge-effect {
  position: absolute;
  pointer-events: none;
  font-size: 48px;
  font-weight: 800;
  color: var(--color-gold);
  text-shadow: 0 0 20px rgba(212,168,83,0.8);
  animation: merge-pop 0.8s ease forwards;
}

@keyframes merge-pop {
  0% { transform: scale(0.5) translateY(0); opacity: 0; }
  30% { transform: scale(1.3) translateY(-10px); opacity: 1; }
  100% { transform: scale(1) translateY(-30px); opacity: 0; }
}

/* ================================
   响应式
   ================================ */
@media (max-height: 640px) {
  .game-title { font-size: 40px; }
  .home-rules { padding: 14px; }
  .home-rules p { font-size: 12px; line-height: 1.6; }
}
