/* ==========================================================================
   中秋接月饼 - 样式
   移动端优先，微信内置浏览器适配（禁长按菜单/禁选中/刘海屏安全区）
   ========================================================================== */

:root {
  --bg-deep: #150c2b;
  --bg-mid: #2a1a4d;
  --gold: #f6c445;
  --gold-deep: #d99b1f;
  --gold-light: #ffe9a8;
  --text: #f6efe3;
  --text-dim: #b9a9d6;
  --card: rgba(255, 255, 255, .07);
  --line: rgba(255, 255, 255, .14);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* 排行榜名次底色：1-5 各有区别，第 6 名起统一灰色 */
  --rank-1: linear-gradient(135deg, #ffe08a, #f0b52a);
  --rank-2: linear-gradient(135deg, #eef1f8, #c2c9d8);
  --rank-3: linear-gradient(135deg, #f5cda4, #d18f56);
  --rank-4: linear-gradient(135deg, #b7e7dc, #6cc2ae);
  --rank-5: linear-gradient(135deg, #d3c6f7, #9c8ae0);
  --rank-other: linear-gradient(135deg, #e4e4ec, #cbccd8);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: radial-gradient(120% 80% at 50% 0%, var(--bg-mid) 0%, var(--bg-deep) 62%, #0d0719 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-font-smoothing: antialiased;
}

input { -webkit-user-select: text; user-select: text; }

/* ---------------------------------------------------------------- 屏幕 */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: calc(var(--safe-top) + 16px) 20px calc(var(--safe-bottom) + 16px);
  overflow: hidden;
}

.screen.is-active { display: flex; }

.screen--center {
  align-items: center;
  justify-content: center;
}

.screen--game { padding: 0; }

/* ---------------------------------------------------------------- 加载 */
.loader {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 32%, #fff6d8, var(--gold) 58%, var(--gold-deep));
  box-shadow: 0 0 34px rgba(246, 196, 69, .45);
  animation: moonPulse 1.5s ease-in-out infinite;
}

.loader__text {
  margin-top: 18px;
  color: var(--text-dim);
  font-size: 14px;
  letter-spacing: .5px;
}

@keyframes moonPulse {
  0%, 100% { transform: scale(1); opacity: .9; }
  50%      { transform: scale(1.1); opacity: 1; }
}

/* ---------------------------------------------------------------- 卡片/表单 */
.card {
  width: 100%;
  max-width: 420px;
  padding: 26px 22px 24px;
  border-radius: 20px;
  background: var(--card);
  border: 1px solid var(--line);
  backdrop-filter: blur(6px);
}

.card__title { margin: 0 0 6px; font-size: 21px; letter-spacing: 1px; }
.card__desc { margin: 0 0 20px; font-size: 13px; color: var(--text-dim); }
.card__tip { margin: 14px 0 0; font-size: 12px; color: var(--text-dim); line-height: 1.6; }

.field { display: block; margin-bottom: 16px; }
.field__label { display: block; margin-bottom: 7px; font-size: 13px; color: var(--text-dim); }

.field__input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, .22);
  color: var(--text);
  font-size: 16px; /* 16px 以下 iOS 会自动放大页面 */
  outline: none;
  transition: border-color .2s;
}

.field__input::placeholder { color: rgba(185, 169, 214, .55); }
.field__input:focus { border-color: var(--gold); }

/* ---------------------------------------------------------------- 按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 46px;
  padding: 0 22px;
  border: 0;
  border-radius: 23px;
  font-size: 16px;
  font-family: inherit;
  font-weight: 600;
  letter-spacing: .5px;
  cursor: pointer;
  transition: transform .12s, opacity .2s, box-shadow .2s;
}

.btn:active { transform: scale(.97); }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn--block { width: 100%; }
.btn--lg { height: 54px; font-size: 18px; border-radius: 27px; }

.btn--primary {
  background: linear-gradient(135deg, var(--gold-light), var(--gold) 45%, var(--gold-deep));
  color: #3a2708;
  box-shadow: 0 10px 24px rgba(214, 155, 31, .34);
}

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

.btn--danger { background: linear-gradient(135deg, #ff9a8b, #e4573d); color: #fff; }

.btn--text {
  height: 40px;
  background: transparent;
  color: var(--text-dim);
  font-weight: 400;
  box-shadow: none;
}

.is-hidden { display: none !important; }

/* ---------------------------------------------------------------- 首页 */
.home {
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.home__moon {
  width: 118px;
  height: 118px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 36% 32%, #fffbee, #ffe9a8 40%, var(--gold) 68%, #d99b1f);
  box-shadow: 0 0 60px rgba(246, 196, 69, .4), inset -14px -12px 26px rgba(170, 116, 12, .35);
}

.home__title {
  margin: 0 0 6px;
  font-size: 27px;
  letter-spacing: 3px;
  color: var(--gold-light);
  text-shadow: 0 2px 18px rgba(246, 196, 69, .35);
}

.home__sub { margin: 0 0 8px; font-size: 13px; color: var(--text-dim); }

.home__meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 0 0 26px;
  font-size: 13px;
  color: var(--gold-light);
}

.home__dot { width: 3px; height: 3px; border-radius: 50%; background: currentColor; opacity: .6; }

.home .btn { margin-bottom: 12px; }
.home__foot { margin: 8px 0 0; font-size: 12px; color: var(--text-dim); min-height: 18px; }

/* ---------------------------------------------------------------- 游戏 */
.hud {
  position: absolute;
  top: calc(var(--safe-top) + 14px);
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  z-index: 3;
}

.hud__box {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 18px;
  background: rgba(0, 0, 0, .34);
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--text-dim);
}

.hud__box b { font-size: 22px; color: var(--gold-light); font-variant-numeric: tabular-nums; }
.hud__unit { font-size: 13px; color: var(--text-dim); }

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.countdown {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(12, 6, 26, .68);
  pointer-events: none;
  z-index: 4;
}

.countdown.is-active { display: flex; }

.countdown__num {
  font-size: 108px;
  font-weight: 700;
  line-height: 1;
  color: var(--gold);
  text-shadow: 0 0 40px rgba(246, 196, 69, .6);
  font-variant-numeric: tabular-nums;
}

.countdown__num.is-pop { animation: popIn .55s ease-out; }

@keyframes popIn {
  0%   { transform: scale(.4); opacity: 0; }
  60%  { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.countdown__tip { margin-top: 20px; font-size: 14px; color: var(--text-dim); }

/* 飘分文字 */
.float-layer { position: absolute; inset: 0; pointer-events: none; z-index: 5; overflow: hidden; }

.float-score {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 22px;
  font-weight: 700;
  text-shadow: 0 2px 8px rgba(0, 0, 0, .55);
  animation: floatUp .85s ease-out forwards;
  white-space: nowrap;
}

.float-score--plus { color: var(--gold-light); }
.float-score--minus { color: #ff8a76; }

@keyframes floatUp {
  0%   { opacity: 0; transform: translate(-50%, -30%) scale(.7); }
  25%  { opacity: 1; transform: translate(-50%, -60%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -160%) scale(1); }
}

/* ---------------------------------------------------------------- 弹层 */
.popup {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 20px;
}

.popup.is-active { display: flex; }

.popup__mask {
  position: absolute;
  inset: 0;
  background: rgba(8, 4, 18, .72);
  animation: fadeIn .18s ease-out;
}

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

.popup__panel {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: calc(100vh - 40px - var(--safe-top) - var(--safe-bottom));
  display: flex;
  flex-direction: column;
  padding: 22px 20px;
  border-radius: 22px;
  background: linear-gradient(180deg, #2b1c4f, #1d1238);
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
  animation: panelIn .22s ease-out;
  overflow: hidden;
}

@keyframes panelIn {
  from { opacity: 0; transform: translateY(14px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

.popup__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  flex: 0 0 auto;
}

.popup__title { margin: 0; font-size: 19px; letter-spacing: 1px; color: var(--gold-light); }

.popup__close {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .1);
  color: var(--text-dim);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.popup__actions { flex: 0 0 auto; margin-top: 18px; }
.popup__actions .btn { margin-bottom: 10px; }
.popup__actions .btn:last-child { margin-bottom: 0; }

/* 结算 */
.result__head { text-align: center; padding: 6px 0 16px; }
.result__label { margin: 0; font-size: 14px; color: var(--text-dim); }

.result__score {
  margin: 6px 0 4px;
  font-size: 62px;
  font-weight: 700;
  line-height: 1;
  color: var(--gold);
  text-shadow: 0 0 34px rgba(246, 196, 69, .45);
  font-variant-numeric: tabular-nums;
}

.result__record { margin: 0; min-height: 20px; font-size: 13px; color: var(--gold-light); }

.result__list { list-style: none; margin: 0; padding: 0; }

.result__list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 14px;
  color: var(--text-dim);
}

.result__list li:last-child { border-bottom: 0; }
.result__list b { color: var(--text); font-size: 17px; font-variant-numeric: tabular-nums; }

.result__error {
  margin: 10px 0 0;
  font-size: 12px;
  color: #ff9a8b;
  text-align: center;
  min-height: 0;
}

/* 排行榜 */
.rank__meta { margin: 0 0 10px; font-size: 12px; color: var(--text-dim); flex: 0 0 auto; }

.rank__list {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  margin: 0 -4px;
  padding: 0 4px;
}

.rank-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  margin-bottom: 8px;
  border-radius: 14px;
  color: #2a2036;
  background: var(--rank-other);
}

.rank-row--1 { background: var(--rank-1); }
.rank-row--2 { background: var(--rank-2); }
.rank-row--3 { background: var(--rank-3); }
.rank-row--4 { background: var(--rank-4); }
.rank-row--5 { background: var(--rank-5); }

.rank-row.is-me { outline: 2px solid var(--gold); outline-offset: -2px; }

.rank-no {
  flex: 0 0 26px;
  text-align: center;
  font-size: 15px;
  font-weight: 700;
  opacity: .8;
  font-variant-numeric: tabular-nums;
}

.rank-avatar {
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #6b5bb5, #3f3277);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .35);
}

.rank-row--1 .rank-avatar { background: linear-gradient(135deg, #b8860b, #8a5f06); }
.rank-row--2 .rank-avatar { background: linear-gradient(135deg, #8d95a8, #5d6473); }
.rank-row--3 .rank-avatar { background: linear-gradient(135deg, #b5713a, #8a4f22); }
.rank-row--4 .rank-avatar { background: linear-gradient(135deg, #3f9c87, #2b7361); }
.rank-row--5 .rank-avatar { background: linear-gradient(135deg, #6d5bc4, #4a3b91); }

.rank-name {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
}

.rank-name__text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }

.rank-win {
  flex: 0 0 auto;
  padding: 1px 6px;
  border-radius: 8px;
  background: rgba(0, 0, 0, .18);
  font-size: 10px;
  font-style: normal;
  font-weight: 600;
}

.rank-name__mobile { flex: 0 0 auto; font-size: 11px; opacity: .62; font-variant-numeric: tabular-nums; }

.rank-score { flex: 0 0 auto; font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.rank-score small { font-size: 11px; font-weight: 400; opacity: .7; margin-left: 1px; }

.rank__me {
  flex: 0 0 auto;
  margin-top: 10px;
  padding: 11px 14px;
  border-radius: 14px;
  background: rgba(246, 196, 69, .13);
  border: 1px solid rgba(246, 196, 69, .35);
  font-size: 13px;
  color: var(--gold-light);
  text-align: center;
}

.rank__me b { font-size: 17px; font-variant-numeric: tabular-nums; }

.rank__prize {
  flex: 0 0 auto;
  margin: 12px 0 0;
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-dim);
  white-space: pre-line;
  max-height: 30vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.rank-loading, .rank-empty {
  padding: 40px 10px;
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
}

/* 活动说明 */
.intro__body {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.intro__h3 {
  margin: 4px 0 8px;
  padding-left: 10px;
  border-left: 3px solid var(--gold);
  font-size: 15px;
  color: var(--gold-light);
}

.intro__text {
  margin: 0 0 18px;
  font-size: 13.5px;
  line-height: 1.85;
  color: #ddd4ee;
  white-space: pre-line;
  word-break: break-word;
}

.intro__text:last-child { margin-bottom: 0; }

/* ---------------------------------------------------------------- Toast */
.toast {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(.9);
  max-width: 78vw;
  padding: 13px 22px;
  border-radius: 14px;
  background: rgba(20, 10, 40, .94);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  z-index: 60;
  transition: opacity .2s, transform .2s;
}

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

/* ---------------------------------------------------------------- 小屏适配 */
/* iPhone SE 等矮屏机型：整体收紧，保证首页不出现裁切 */
@media (max-height: 640px) {
  .home__moon { width: 86px; height: 86px; margin-bottom: 10px; }
  .home__title { font-size: 23px; }
  .home__meta { margin-bottom: 18px; }
  .home .btn { margin-bottom: 9px; }
  .btn--lg { height: 48px; font-size: 17px; }
  .result__score { font-size: 52px; }
}
