*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0b0e1a;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-border: rgba(255, 255, 255, 0.10);
  --text: #f4f6fb;
  --text-muted: #9aa3b8;
  --accent: #7c5cff;
  --accent-2: #4aa8ff;
  --danger: #ff5f6d;
  --gold: #ffd166;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--text);
  min-height: 100vh;
  background: var(--bg);
  background-image:
    radial-gradient(circle at 18% -5%, #1c2445 0%, transparent 46%),
    radial-gradient(circle at 85% 105%, #2b1c45 0%, transparent 48%),
    linear-gradient(160deg, #12162b 0%, #0b0e1a 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  padding: calc(env(safe-area-inset-top, 0px) + 20px) 16px
    calc(env(safe-area-inset-bottom, 0px) + 28px);
}

.app {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
}

/* 页面切换 */
.screen {
  display: none;
  flex-direction: column;
  min-height: calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 48px);
}

.screen.active {
  display: flex;
}

/* 标题 */
.title {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: 2px;
  text-align: center;
  background: linear-gradient(120deg, #a78bff 0%, #5ec5ff 50%, #ff9ce2 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

.subtitle {
  margin-top: 12px;
  text-align: center;
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1.6;
}

/* 开始页 */
.start-inner {
  margin-top: 8vh;
}

.demo-board {
  display: grid;
  gap: 5px;
  width: 168px;
  margin: 28px auto 0;
}

.demo-board .cell {
  cursor: default;
  border-radius: 5px;
}

.start-form {
  margin-top: 34px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.start-form .tip {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.5;
}

.start-form input {
  width: 100%;
  height: 54px;
  border-radius: 14px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font-size: 16px;
  padding: 0 18px;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}

.start-form input::placeholder {
  color: var(--text-muted);
}

.start-form input:focus {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.10);
}

.btn-primary {
  height: 54px;
  border: none;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #fff;
  background: linear-gradient(120deg, var(--accent) 0%, var(--accent-2) 100%);
  box-shadow: 0 10px 24px rgba(124, 92, 255, 0.35);
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.btn-primary:active {
  transform: scale(0.97);
  opacity: 0.9;
}

.error {
  min-height: 18px;
  font-size: 13px;
  color: var(--danger);
  text-align: center;
}

/* 排行榜 */
.rank-wrap {
  margin-top: 40px;
  flex: 1;
}

.rank-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.rank-title span {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-2);
  background: rgba(74, 168, 255, 0.12);
  padding: 3px 8px;
  border-radius: 999px;
}

.rank-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rank-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  font-size: 14px;
}

.rank-item .rank-no {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
}

.rank-item .rank-no.rank-1 { background: rgba(255, 209, 102, 0.22); color: var(--gold); }
.rank-item .rank-no.rank-2 { background: rgba(200, 214, 235, 0.16); color: #d7e2f2; }
.rank-item .rank-no.rank-3 { background: rgba(230, 150, 106, 0.18); color: #f0b28a; }

.rank-item .rank-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.rank-item .rank-level {
  color: var(--accent-2);
  font-weight: 700;
}

.rank-item .rank-time {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.rank-list .empty {
  text-align: center;
  color: var(--text-muted);
  padding: 20px 0;
  font-size: 14px;
}

/* 游戏页 */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 4px 18px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 70px;
}

.stat .label {
  font-size: 12px;
  color: var(--text-muted);
}

.stat .value {
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.stat.hearts {
  font-size: 24px;
  letter-spacing: 3px;
  color: var(--danger);
  text-shadow: 0 2px 10px rgba(255, 95, 109, 0.4);
}

.board-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.board {
  display: grid;
  gap: 5px;
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
}

.cell {
  aspect-ratio: 1 / 1;
  border-radius: 6px;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.cell:active {
  transform: scale(0.92);
}

.cell.correct {
  animation: pop 0.28s ease;
}

.cell.wrong {
  animation: wrong-flash 0.4s ease;
}

.board.shake {
  animation: shake 0.4s ease;
}

.hint {
  margin-top: 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* 结果页 */
.result-inner {
  margin-top: 8vh;
}

.result-stats {
  margin-top: 30px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.rstat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 18px 8px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
}

.rstat .label {
  font-size: 12px;
  color: var(--text-muted);
}

.rstat .value {
  font-size: 24px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

#btn-restart {
  margin-top: 24px;
  width: 100%;
}

/* 动画 */
@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(0.86); opacity: 0.7; }
  100% { transform: scale(1); }
}

@keyframes wrong-flash {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}
