/* 1to50 — 复刻自 com.westriversw.b1to50 v3.9(AndEngine 原作)的观感:
   素色格子、白底、方块数字。所有图形均为 CSS/DOM 绘制,未使用原版美术资源。 */
:root {
  --tile: #ffffff;
  --tile-border: #d8d8d8;
  --tile-shadow: #c4c4c4;
  --tile-hit: #ffd54a;
  --tile-miss: #ff6b5e;
  --target: #ffa726;
  --ink: #4a4a4a;
  --bg: #f2f0eb;
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: "Avenir Next", "Helvetica Neue", Arial, "PingFang SC", sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex; align-items: center; justify-content: center;
  -webkit-user-select: none; user-select: none; touch-action: manipulation;
  min-height: 100vh; min-height: 100dvh;
}

#app {
  width: min(96vw, 460px);
  display: flex; flex-direction: column; gap: 14px;
  padding: 16px 0 24px;
}

/* ---- HUD ---- */
#hud {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 4px;
}
#best { font-size: 13px; letter-spacing: 1px; color: #9a9a9a; }
#best-value { color: var(--ink); font-weight: 700; }
#timer {
  font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
}
#hud-btns { display: flex; gap: 8px; }
#btn-restart, #btn-rank {
  width: 40px; height: 40px; border: none; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 0 var(--tile-shadow);
  font-size: 20px; color: var(--ink); cursor: pointer;
}
#btn-restart:active { transform: translateY(2px); box-shadow: none; }

/* ---- 棋盘:5×5 ---- */
#board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  aspect-ratio: 1;
}
.tile {
  position: relative;
  background: var(--tile);
  border-radius: 10px;
  box-shadow: 0 4px 0 var(--tile-shadow);
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(24px, 8vw, 40px);
  font-weight: 700;
  cursor: pointer;
  transition: background .12s;
}
.tile.empty { background: var(--bg); box-shadow: none; cursor: default; }
.tile .num { pointer-events: none; }

/* ReMake 动画(复刻原版 AnswerNode.ReMake 序列):
   0.4s 放大到1.3并淡出 → 缩到0 → 0.15s 弹回 */
.tile.pop { animation: remake .65s ease forwards; }
@keyframes remake {
  0%   { transform: scale(1);    opacity: 1; }
  60%  { transform: scale(1.3);  opacity: 0; }   /* 0.4s 淡出放大 */
  62%  { transform: scale(0);    opacity: 0; }   /* 瞬间缩没 */
  100% { transform: scale(1);    opacity: 1; }   /* 0.15s 弹回 */
}
/* Miss:原版为格子闪烁;这里用红色抖动表达 */
.tile.miss { animation: miss .3s ease; }
@keyframes miss {
  0%, 100% { background: var(--tile); transform: translateX(0); }
  25%  { background: var(--tile-miss); transform: translateX(-4px); }
  75%  { background: var(--tile-miss); transform: translateX(4px); }
}
/* 帮助高亮(原版 AnswerNode.Light:目标格发光提示) */
.tile.help::after {
  content: ""; position: absolute; inset: -4px;
  border-radius: 14px;
  border: 3px solid var(--target);
  animation: helpPulse 1s ease-in-out infinite;
}
@keyframes helpPulse {
  0%, 100% { opacity: .35; }
  50% { opacity: 1; }
}

/* ---- 问题队列(原版 QuestionNode 队列:当前目标 + 后续) ---- */
#queue-wrap {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  min-height: 84px;
}
#queue-current {
  width: 72px; height: 72px; border-radius: 12px;
  background: var(--target);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 36px; font-weight: 800;
  box-shadow: 0 4px 0 #e08e12;
}
#queue-current.swap { animation: queueSwap .25s ease; }
@keyframes queueSwap {
  0% { transform: scale(.6); opacity: .3; }
  100% { transform: scale(1); opacity: 1; }
}
#queue-next { display: flex; gap: 8px; }
#queue-next .q {
  width: 42px; height: 42px; border-radius: 8px;
  background: #fff; box-shadow: 0 3px 0 var(--tile-shadow);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700; color: #9a9a9a;
}
#queue-next .q:first-child { color: var(--ink); }

/* ---- 覆盖层:倒计时 / 结算 ---- */
#overlay {
  position: fixed; inset: 0;
  background: rgba(255,255,255,.88);
  display: none;
  align-items: center; justify-content: center;
  flex-direction: column;
}
#overlay.show { display: flex; }
#countdown {
  font-size: 110px; font-weight: 800; color: var(--target);
  display: none;
}
#countdown.show { display: block; animation: cd .9s ease; }
@keyframes cd {
  0% { transform: scale(1.6); opacity: 0; }
  30% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
#gameover { display: none; flex-direction: column; align-items: center; gap: 12px; }
#gameover.show { display: flex; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
#go-text { font-size: 42px; font-weight: 800; letter-spacing: 2px; }
#go-time { font-size: 26px; font-variant-numeric: tabular-nums; }
#go-stars { font-size: 44px; letter-spacing: 6px; min-height: 54px; }
#go-stars .star { display: inline-block; animation: starPop .4s ease backwards; }
#go-stars .star:nth-child(2) { animation-delay: .25s; }
#go-stars .star:nth-child(3) { animation-delay: .5s; }
@keyframes starPop {
  0% { transform: scale(0) rotate(-40deg); }
  70% { transform: scale(1.4) rotate(8deg); }
  100% { transform: scale(1) rotate(0); }
}
#go-record { color: #e08900; font-weight: 700; min-height: 20px; }
#btn-again {
  margin-top: 10px;
  padding: 12px 42px;
  font-size: 18px; font-weight: 700;
  color: #fff; background: var(--target);
  border: none; border-radius: 24px;
  box-shadow: 0 4px 0 #e08e12;
  cursor: pointer;
}
#btn-again:active { transform: translateY(3px); box-shadow: none; }

/* ---- 世界排行榜(原版 RankWorldLayer) ---- */
#go-rank { color: #2e7d32; font-weight: 700; min-height: 20px; }
#rank-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  display: none;
  align-items: center; justify-content: center;
  z-index: 10;
}
#rank-modal.show { display: flex; }
#rank-panel {
  width: min(88vw, 360px);
  max-height: 70vh;
  background: #fff; border-radius: 16px;
  padding: 20px;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
#rank-title { font-size: 20px; font-weight: 800; text-align: center; }
#rank-list {
  overflow-y: auto; list-style-position: inside;
  display: flex; flex-direction: column; gap: 6px;
  font-variant-numeric: tabular-nums;
}
#rank-list li { display: flex; justify-content: space-between; font-size: 15px; }
#rank-list .rn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#btn-rank-close {
  padding: 10px; border: none; border-radius: 10px;
  background: var(--bg); font-size: 15px; cursor: pointer;
}

#rank-list { -webkit-overflow-scrolling: touch; min-height: 0; }
#rank-list .rt { flex-shrink: 0; margin-left: 12px; }
@media (max-height: 650px) { #app { width: min(92vw, 58vh, 460px); gap: 8px; padding: 8px 0; } #board { gap: 6px; } #queue-wrap { min-height: 60px; } #queue-current { width: 56px; height: 56px; font-size: 28px; } }
