/* ============ 基础与配色 ============ */
:root {
  --bg-a: #F6F2EC;
  --bg-b: #EBE3D7;
  --card: rgba(255, 255, 255, .78);
  --board-bg: rgba(58, 50, 43, .07);
  --ink: #3A322B;
  --ink-soft: #9A9186;
  --radius: 18px;
  --gap: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 620px at 50% -12%, rgba(255, 255, 255, .75), transparent 62%),
    linear-gradient(180deg, var(--bg-a), var(--bg-b));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* ============ 页面框架 ============ */
.page {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(env(safe-area-inset-top, 0px) + 26px) 16px calc(env(safe-area-inset-bottom, 0px) + 26px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  animation: page-in .5s cubic-bezier(.2, .8, .3, 1) both;
}

@keyframes page-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============ 顶部：标题 + 分数 ============ */
.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
}

.title {
  margin: 0;
  font-size: 46px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -1.5px;
}

.tagline {
  margin: 8px 0 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
  color: var(--ink-soft);
}

.scores {
  display: flex;
  gap: 10px;
}

.score-card {
  min-width: 76px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--card);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 4px 16px rgba(58, 50, 43, .06);
  text-align: center;
}

.score-card .label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .05em;
  color: var(--ink-soft);
}

.score-card .value {
  display: block;
  margin-top: 2px;
  font-size: 22px;
  font-weight: 800;
  line-height: 1.1;
}

.score-card .value.pop {
  animation: num-pop 200ms cubic-bezier(.2, .8, .3, 1.2);
}

@keyframes num-pop {
  0% {
    transform: scale(1);
  }

  40% {
    transform: scale(1.28);
    color: #E28A1C;
  }

  100% {
    transform: scale(1);
  }
}

/* ============ 游戏板 ============ */
.board-wrap {
  position: relative;
  margin: 20px 0;
}

.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  padding: var(--gap);
  border-radius: var(--radius);
  background: var(--board-bg);
  box-shadow:
    0 18px 44px rgba(58, 50, 43, .10),
    inset 0 1px 0 rgba(255, 255, 255, .40),
    inset 0 -2px 6px rgba(58, 50, 43, .06);
  touch-action: none;
}

#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: var(--radius);
}

/* ============ 结束 / 胜利遮罩 ============ */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  background: rgba(246, 242, 236, .68);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity .25s ease;
}

.overlay.visible {
  display: flex;
}

.overlay.show {
  opacity: 1;
}

/* 胜利遮罩：淡淡的金色光晕 */
.overlay.win {
  background:
    radial-gradient(120% 110% at 50% -10%, rgba(240, 200, 120, .38), transparent 65%),
    rgba(246, 242, 236, .74);
}

.overlay-inner {
  text-align: center;
  padding: 24px 28px;
}

.overlay h2 {
  margin: 0 0 8px;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -.5px;
}

.overlay p {
  margin: 0 0 22px;
  font-size: 14px;
  color: var(--ink-soft);
}

.overlay-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.overlay-actions .btn {
  animation: btn-in .35s .1s cubic-bezier(.2, .9, .3, 1.3) both;
}

@keyframes btn-in {
  from {
    opacity: 0;
    transform: scale(.85);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ============ 按钮与底部 ============ */
.bottom {
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.btn {
  border: 0;
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  font-size: 15px;
  color: #FFF;
  border-radius: 999px;
  padding: 12px 28px;
  background: linear-gradient(180deg, #4C4239, #3A322B);
  box-shadow: 0 6px 16px rgba(58, 50, 43, .28);
  transition: transform .12s ease, box-shadow .12s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 22px rgba(58, 50, 43, .32);
}

.btn:active {
  transform: scale(.97);
  box-shadow: 0 4px 10px rgba(58, 50, 43, .24);
}

.btn:focus-visible {
  outline: 2px solid #E0891B;
  outline-offset: 2px;
}

.hint {
  margin: 0;
  font-size: 12px;
  line-height: 1.7;
  text-align: center;
  color: var(--ink-soft);
  letter-spacing: .02em;
}

/* ============ 新游戏确认弹窗 ============ */
.confirm {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(58, 50, 43, .32);
  opacity: 0;
  transition: opacity .2s ease;
}

.confirm.visible {
  display: flex;
}

.confirm.show {
  opacity: 1;
}

.confirm-card {
  width: min(300px, 100%);
  padding: 26px 24px 22px;
  border-radius: 20px;
  background: #FDFBF7;
  box-shadow: 0 18px 48px rgba(58, 50, 43, .28);
  text-align: center;
  transform: scale(.92);
  transition: transform .22s cubic-bezier(.2, .9, .3, 1.2);
}

.confirm.show .confirm-card {
  transform: scale(1);
}

.confirm-card h3 {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 800;
}

.confirm-card p {
  margin: 0 0 20px;
  font-size: 13px;
  color: var(--ink-soft);
}

.confirm-actions {
  display: flex;
  gap: 10px;
}

.confirm-actions .btn {
  flex: 1;
  padding: 10px 0;
}

.btn.ghost {
  color: var(--ink);
  background: #EFE9E0;
  box-shadow: none;
}

.btn.ghost:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(58, 50, 43, .12);
}

/* ============ 响应式 ============ */
@media (max-width: 380px) {
  .title {
    font-size: 38px;
  }

  .tagline {
    font-size: 11px;
  }

  .score-card {
    min-width: 66px;
    padding: 8px 10px;
  }

  .score-card .value {
    font-size: 19px;
  }

  .hint {
    font-size: 11px;
  }
}

/* 尊重减少动态效果偏好 */
@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}