/* 舒尔特方格 · 移动优先 */

:root {
  --bg: #0b1220;
  --bg-deep: #070c16;
  --surface: #151e32;
  --surface-2: #1c2740;
  --surface-3: #243252;
  --ink: #f2f6ff;
  --muted: #8b9bb8;
  --muted-2: #5c6b88;
  --accent: #5b8cff;
  --accent-2: #7aa2ff;
  --success: #3ddc97;
  --warn: #ffb020;
  --danger: #ff6b7a;
  --p1: #5b8cff;
  --p2: #ff7ab6;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --font: "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  --mono: "SF Mono", "Cascadia Code", "Roboto Mono", Consolas, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg-deep);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}

#app {
  min-height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  position: relative;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(91, 140, 255, 0.18), transparent 55%),
    radial-gradient(800px 400px at 100% 100%, rgba(61, 220, 151, 0.08), transparent 50%),
    var(--bg);
  overflow: hidden;
}

/* 平板/桌面：放宽容器(与横竖屏无关) */
@media (min-width: 720px) {
  #app {
    max-width: 960px;
  }
}

/* Screens */
.screen {
  display: none;
  min-height: 100dvh;
  padding: calc(16px + var(--safe-top)) 18px calc(24px + var(--safe-bottom));
  flex-direction: column;
  animation: screen-in 0.28s ease;
}

.screen.active {
  display: flex;
}

@keyframes screen-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .screen,
  .cell,
  .countdown-num {
    animation: none !important;
    transition: none !important;
  }
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
}

.topbar h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.topbar-spacer {
  width: 40px;
  flex: 0 0 auto;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  transition: background 0.15s, color 0.15s, transform 0.1s;
}

.icon-btn:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
}

.icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

.screen-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.lead {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.section-label {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

/* Home */
.home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(145deg, var(--accent), #8b5cf6);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  padding: 7px;
  box-shadow: 0 8px 24px rgba(91, 140, 255, 0.35);
}

.brand-mark span {
  background: rgba(255, 255, 255, 0.9);
  border-radius: 3px;
}

.brand-mark span:nth-child(2) {
  opacity: 0.55;
}
.brand-mark span:nth-child(3) {
  opacity: 0.7;
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.tagline {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.home-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.hero-card {
  background: linear-gradient(160deg, var(--surface-2), var(--surface));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow:
    0 18px 48px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  display: grid;
  grid-template-columns: 88px 1fr;
  grid-template-areas:
    "preview copy"
    "cta cta";
  gap: 14px 16px;
  align-items: center;
}

.hero-preview {
  grid-area: preview;
  width: 88px;
  height: 88px;
  border-radius: 16px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 6px;
  background: var(--bg);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    0 8px 20px rgba(0, 0, 0, 0.25);
}

.hero-preview i {
  border-radius: 4px;
  display: block;
  opacity: 0.95;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.hero-copy {
  grid-area: copy;
  min-width: 0;
}

.hero-kicker {
  margin: 0;
  color: var(--accent-2);
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: 0.08em;
}

.hero-copy h2 {
  margin: 4px 0 6px;
  font-size: 1.2rem;
  font-weight: 700;
}

.hero-desc {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.88rem;
}

.hero-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.8rem;
  font-family: var(--mono);
}

.hero-meta .dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--muted-2);
}

.hero-card .btn {
  grid-area: cta;
}

/* Mode grid */
.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.mode-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: linear-gradient(165deg, var(--surface-2), var(--surface));
  border: 1px solid rgba(255, 255, 255, 0.07);
  text-align: left;
  transition: transform 0.12s, border-color 0.15s, box-shadow 0.15s;
  min-height: 112px;
  box-shadow:
    0 8px 22px rgba(0, 0, 0, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.mode-card:hover {
  border-color: rgba(91, 140, 255, 0.4);
  box-shadow:
    0 12px 28px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.mode-card:active {
  transform: scale(0.97) translateY(1px);
}

.mode-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.mode-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.mode-icon-classic {
  background: rgba(91, 140, 255, 0.18);
  color: #9bb8ff;
}
.mode-icon-reverse {
  background: rgba(255, 176, 32, 0.16);
  color: #ffc85c;
}
.mode-icon-stats {
  background: rgba(61, 220, 151, 0.14);
  color: #6eecc0;
}

.mode-icon-letters {
  background: rgba(244, 114, 182, 0.16);
  color: #f9a8d4;
}
.mode-icon-mole {
  background: rgba(251, 191, 36, 0.16);
  color: #fcd34d;
}
.mode-icon-find {
  background: rgba(251, 146, 60, 0.16);
  color: #fdba74;
}
.mode-icon-flash {
  background: rgba(139, 92, 246, 0.16);
  color: #c4b5fd;
}
.mode-icon-math {
  background: rgba(34, 211, 238, 0.14);
  color: #67e8f9;
}
.mode-icon-poem {
  background: rgba(232, 121, 249, 0.14);
  color: #f0abfc;
}
.mode-icon-challenge {
  background: rgba(251, 191, 36, 0.18);
  color: #fbbf24;
}

.math-prompt {
  text-align: center;
  margin-bottom: 10px;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(91, 140, 255, 0.12);
  border: 1px solid rgba(91, 140, 255, 0.25);
}

.math-eyebrow {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 2px;
}

.math-prompt strong {
  font-family: var(--mono);
  font-size: 1.45rem;
  color: var(--accent-2);
}

.flash-timer {
  text-align: center;
  margin-bottom: 8px;
  font-size: 0.9rem;
  color: var(--warn);
}

/* ========== 经典打地鼠 · 写实洞口 ========== */
.whack-board {
  gap: 14px;
  padding: 18px;
  border-radius: 28px;
  background:
    radial-gradient(ellipse 100% 60% at 50% -8%, rgba(200, 255, 160, 0.22), transparent 50%),
    radial-gradient(ellipse 45% 35% at 12% 18%, rgba(255, 255, 255, 0.1), transparent 50%),
    radial-gradient(ellipse 30% 20% at 88% 72%, rgba(20, 70, 20, 0.2), transparent 50%),
    repeating-linear-gradient(98deg, transparent 0 3px, rgba(40, 90, 30, 0.04) 3px 4px),
    linear-gradient(180deg, #6fb84a 0%, #4f9a32 45%, #3a7a26 100%);
  box-shadow:
    0 20px 50px rgba(0, 0, 0, 0.4),
    inset 0 2px 0 rgba(255, 255, 255, 0.18),
    inset 0 -12px 28px rgba(0, 0, 0, 0.16);
  border: 2px solid #2a6a1c;
}

/* 洞口：草毯 + 泥丘 + 深洞 + 前土沿 */
.hole {
  position: relative;
  aspect-ratio: 1;
  min-height: 0;
  border: 0;
  border-radius: 42% 42% 46% 46% / 38% 38% 48% 48%;
  background: transparent;
  overflow: hidden;
  outline: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.08s;
}

.hole:focus,
.hole:focus-visible {
  outline: none;
}

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

/* 洞周草毯 */
.hole::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    /* 不规则草斑 */
    radial-gradient(ellipse 28% 18% at 22% 18%, rgba(200, 250, 140, 0.55), transparent 60%),
    radial-gradient(ellipse 22% 16% at 78% 16%, rgba(80, 150, 45, 0.5), transparent 55%),
    radial-gradient(ellipse 30% 20% at 18% 70%, rgba(60, 120, 35, 0.4), transparent 55%),
    radial-gradient(ellipse 26% 18% at 82% 68%, rgba(50, 110, 30, 0.45), transparent 55%),
    radial-gradient(ellipse 40% 24% at 50% 100%, rgba(30, 70, 20, 0.35), transparent 60%),
    /* 细草纹理 */
    repeating-linear-gradient(
      82deg,
      transparent 0 7px,
      rgba(40, 100, 28, 0.08) 7px 8px
    ),
    repeating-linear-gradient(
      98deg,
      transparent 0 11px,
      rgba(120, 200, 80, 0.06) 11px 12px
    ),
    linear-gradient(168deg, #6fbe44 0%, #4a942e 42%, #327020 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.2),
    inset 0 -8px 14px rgba(0, 60, 0, 0.28),
    inset 0 0 0 1px rgba(0, 70, 0, 0.18);
  z-index: 0;
}

/* 洞周草叶点缀 */
.hole::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    /* 左侧草簇 */
    linear-gradient(100deg, transparent 0 12%, #7ed957 12% 13%, transparent 13% 16%, #5cb83e 16% 17%, transparent 17%),
    /* 右上草簇 */
    linear-gradient(160deg, transparent 0 20%, #8fe06a 20% 21%, transparent 21% 24%, #6bc044 24% 25%, transparent 25%),
    /* 下缘草尖 */
    linear-gradient(80deg, transparent 0 30%, #5cb83e 30% 31%, transparent 31% 34%, #7ed957 34% 35%, transparent 35% 38%, #4a9a32 38% 39%, transparent 39%);
  opacity: 0.7;
  z-index: 0;
  pointer-events: none;
}

/* 泥土环（湿土色带斑） */
.mud-ring {
  position: absolute;
  left: 6%;
  right: 6%;
  top: 14%;
  bottom: 6%;
  border-radius: 44% 44% 48% 48% / 40% 40% 52% 52%;
  background:
    radial-gradient(ellipse 26% 16% at 20% 32%, rgba(170, 120, 55, 0.5), transparent 55%),
    radial-gradient(ellipse 22% 14% at 80% 40%, rgba(55, 32, 12, 0.45), transparent 55%),
    radial-gradient(ellipse 28% 18% at 50% 72%, rgba(100, 60, 28, 0.45), transparent 55%),
    radial-gradient(ellipse 18% 12% at 38% 16%, rgba(210, 160, 80, 0.4), transparent 50%),
    radial-gradient(ellipse 14% 10% at 68% 18%, rgba(180, 130, 60, 0.3), transparent 50%),
    linear-gradient(
      178deg,
      #b8884a 0%,
      #9a6a34 22%,
      #7a5028 48%,
      #5e3c1c 72%,
      #4a2e14 100%
    );
  box-shadow:
    inset 0 -6px 12px rgba(0, 0, 0, 0.45),
    inset 0 10px 16px rgba(0, 0, 0, 0.15),
    0 3px 5px rgba(0, 0, 0, 0.28);
  z-index: 1;
}

/* 深洞 */
.tunnel {
  position: absolute;
  left: 16%;
  right: 16%;
  top: 30%;
  bottom: 20%;
  border-radius: 44%;
  background:
    radial-gradient(ellipse 70% 55% at 50% 25%, #3a2214 0%, #1a0e06 50%, #050302 100%);
  box-shadow:
    inset 0 16px 24px rgba(0, 0, 0, 1),
    inset 0 -8px 12px rgba(70, 40, 18, 0.4),
    inset 0 2px 0 rgba(90, 55, 28, 0.35);
  z-index: 2;
}

/* 前景土丘沿 */
.lip {
  position: absolute;
  left: -4%;
  right: -4%;
  bottom: -6%;
  height: 56%;
  border-radius: 50% 50% 40% 40% / 38% 38% 64% 64%;
  background:
    /* 土块高光 */
    radial-gradient(ellipse 20% 14% at 16% 30%, rgba(220, 170, 100, 0.55), transparent 55%),
    radial-gradient(ellipse 16% 11% at 84% 36%, rgba(190, 140, 70, 0.4), transparent 50%),
    radial-gradient(ellipse 14% 10% at 48% 14%, rgba(240, 200, 140, 0.45), transparent 50%),
    radial-gradient(ellipse 12% 9% at 28% 48%, rgba(200, 150, 80, 0.3), transparent 50%),
    /* 土块阴影与裂纹感 */
    radial-gradient(ellipse 18% 12% at 38% 72%, rgba(55, 30, 12, 0.45), transparent 55%),
    radial-gradient(ellipse 14% 10% at 72% 60%, rgba(45, 25, 10, 0.4), transparent 50%),
    linear-gradient(ellipse 8% 30% at 55% 50%, rgba(40, 22, 8, 0.35), transparent 70%),
    linear-gradient(
      178deg,
      #c8944e 0%,
      #a87438 22%,
      #8b5a2c 48%,
      #6b4420 74%,
      #543418 100%
    );
  box-shadow:
    0 12px 20px rgba(0, 0, 0, 0.42),
    inset 0 -5px 0 rgba(0, 0, 0, 0.35),
    inset 0 18px 28px rgba(0, 0, 0, 0.14);
  z-index: 5;
  pointer-events: none;
}

/* 土沿：土粒 + 小石子 + 顶缘草叶 */
.lip::before {
  content: "";
  position: absolute;
  left: 6%;
  right: 6%;
  top: -6%;
  height: 28%;
  border-radius: 50% 50% 0 0;
  background:
    repeating-linear-gradient(
      76deg,
      transparent 0 9px,
      rgba(90, 165, 48, 0.55) 9px 11px,
      transparent 11px 17px
    ),
    repeating-linear-gradient(
      104deg,
      transparent 0 13px,
      rgba(65, 135, 38, 0.5) 13px 15px,
      transparent 15px 22px
    ),
    repeating-linear-gradient(
      90deg,
      transparent 0 18px,
      rgba(100, 180, 55, 0.4) 18px 19px,
      transparent 19px 28px
    );
  opacity: 0.75;
  mask-image: linear-gradient(180deg, #000 20%, transparent 95%);
  -webkit-mask-image: linear-gradient(180deg, #000 20%, transparent 95%);
  pointer-events: none;
}

.lip::after {
  content: "";
  position: absolute;
  inset: 22% 10% auto;
  height: 48%;
  background:
    radial-gradient(circle at 10% 35%, #c8b898 0 3.5px, transparent 4px),
    radial-gradient(circle at 24% 60%, #a09078 0 2.5px, transparent 3px),
    radial-gradient(circle at 38% 28%, #d0c0a0 0 2px, transparent 2.5px),
    radial-gradient(circle at 52% 55%, #8a7860 0 3px, transparent 3.5px),
    radial-gradient(circle at 68% 32%, #b8a888 0 2.5px, transparent 3px),
    radial-gradient(circle at 80% 58%, #988870 0 3.5px, transparent 4px),
    radial-gradient(circle at 92% 40%, #c0b090 0 2px, transparent 2.5px),
    /* 更大泥块 */
    radial-gradient(ellipse 12% 8% at 30% 42%, rgba(160, 110, 50, 0.35), transparent 60%),
    radial-gradient(ellipse 10% 7% at 70% 48%, rgba(140, 95, 45, 0.3), transparent 55%);
  opacity: 0.65;
  border-radius: 45%;
  pointer-events: none;
}

/* ========== 精修地鼠 ========== */
.mole {
  position: absolute;
  left: 50%;
  bottom: 16%;
  width: 64%;
  height: 72%;
  transform: translate(-50%, 120%);
  transition: transform 0.2s cubic-bezier(0.25, 0.9, 0.3, 1.08);
  z-index: 3;
  pointer-events: none;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.25));
}

.hole.up .mole {
  transform: translate(-50%, 0%);
}

/* 身体（在头部下方，被 lip 挡住一部分） */
.mole-body {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 70%;
  height: 48%;
  border-radius: 40% 40% 20% 20%;
  background: linear-gradient(180deg, #b87a42 0%, #8b5528 100%);
  z-index: 1;
}

.mole-head {
  position: absolute;
  left: 50%;
  top: 6%;
  transform: translateX(-50%);
  width: 82%;
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 28%, #e8b878 0%, #d49a58 35%, #b07030 78%, #8b5020 100%);
  box-shadow:
    inset -5px -8px 14px rgba(0, 0, 0, 0.18),
    inset 4px 5px 10px rgba(255, 230, 180, 0.3),
    0 6px 10px rgba(0, 0, 0, 0.22);
  z-index: 2;
}

/* 口鼻浅色区 */
.muzzle {
  position: absolute;
  left: 50%;
  top: 48%;
  transform: translateX(-50%);
  width: 58%;
  height: 36%;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 30%, #ffe8c4 0%, #f0d0a0 70%, #e0b880 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3);
  z-index: 3;
}

.mole-ear {
  position: absolute;
  top: 14%;
  width: 24%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #d49a58, #8b5020);
  z-index: 1;
  box-shadow:
    inset -2px -3px 5px rgba(0, 0, 0, 0.2),
    0 2px 4px rgba(0, 0, 0, 0.15);
}

.mole-ear.left {
  left: 2%;
}

.mole-ear.right {
  right: 2%;
}

.mole-ear i {
  display: block;
  width: 48%;
  height: 48%;
  margin: 26% auto 0;
  border-radius: 50%;
  background: #f0a880;
  opacity: 0.85;
}

.mole-eye {
  position: absolute;
  top: 34%;
  width: 16%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #4a3218, #140e06 72%);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.12),
    0 0 0 2px rgba(80, 50, 25, 0.15),
    inset 2px 3px 0 rgba(255, 255, 255, 0.5);
  z-index: 5;
  overflow: hidden;
}

.mole-eye.left {
  left: 26%;
}

.mole-eye.right {
  right: 26%;
}

.mole-eye::after {
  content: "";
  position: absolute;
  top: 16%;
  left: 20%;
  width: 42%;
  height: 42%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
}

.mole-nose {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translateX(-50%);
  width: 18%;
  aspect-ratio: 1.25;
  border-radius: 50% 50% 55% 55%;
  background: radial-gradient(circle at 40% 30%, #ffb8a0, #f07858 55%, #d06040 100%);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  z-index: 6;
}

.mole-mouth {
  position: absolute;
  left: 50%;
  top: 58%;
  transform: translateX(-50%);
  width: 16%;
  height: 10%;
  border-bottom: 2.5px solid #6b3820;
  border-radius: 0 0 50% 50%;
  opacity: 0.45;
  z-index: 6;
}

/* 腮红 */
.mole-blush {
  position: absolute;
  top: 48%;
  width: 12%;
  aspect-ratio: 1.3;
  border-radius: 50%;
  background: rgba(255, 120, 120, 0.28);
  filter: blur(1px);
  z-index: 4;
}

.mole-blush.left {
  left: 14%;
}

.mole-blush.right {
  right: 14%;
}

.mole-paw {
  position: absolute;
  bottom: 10%;
  width: 20%;
  aspect-ratio: 0.65;
  border-radius: 45% 45% 40% 40%;
  background: linear-gradient(180deg, #e0a868 0%, #c48848 100%);
  z-index: 4;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.18);
}

.mole-paw.left {
  left: 6%;
  transform: rotate(-16deg);
}

.mole-paw.right {
  right: 6%;
  transform: rotate(16deg);
}

.hole.hit .mole {
  animation: whack-hit 0.2s ease;
}

.hole.wrong {
  animation: shake 0.28s ease;
}

@keyframes whack-hit {
  0% {
    transform: translate(-50%, 0%) scale(1);
  }
  40% {
    transform: translate(-50%, 10%) scale(0.9);
  }
  100% {
    transform: translate(-50%, 0%) scale(1);
  }
}

.whack-board + .game-tip {
  color: var(--warn);
}

.level-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* 古诗选择列表 */
.poem-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.poem-card {
  text-align: left;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color 0.15s, transform 0.1s;
}

.poem-card:hover {
  border-color: rgba(91, 140, 255, 0.4);
}

.poem-card:active {
  transform: scale(0.99);
}

.poem-card-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.poem-card-head strong {
  font-size: 1.02rem;
}

.poem-dynasty {
  flex-shrink: 0;
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(91, 140, 255, 0.14);
  color: #9bb8ff;
  font-size: 0.72rem;
}

.poem-meta {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.72rem;
  font-family: var(--mono);
  flex-shrink: 0;
}

.poem-text {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.65;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* 玩法页诗文面板：进度高亮 */
.poem-panel {
  flex-shrink: 0;
  margin: 6px 4px 0;
  padding: 10px 14px 12px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.05);
  text-align: center;
}

.poem-panel-name {
  font-weight: 650;
  font-size: 0.9rem;
  color: var(--accent-2);
  margin-bottom: 4px;
}

.poem-panel-text {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.85;
  color: var(--ink);
}

.poem-panel-text .pp-punct {
  color: var(--muted);
}

.poem-panel-text span {
  transition: color 0.2s ease, opacity 0.2s ease;
}

.poem-panel-text .read {
  color: var(--muted);
  opacity: 0.72;
}

.poem-panel-text .next {
  color: var(--success);
  font-weight: 700;
  text-shadow: 0 0 12px rgba(61, 220, 151, 0.45);
}

.level-card {
  text-align: left;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 0.15s, transform 0.1s;
}

.level-card strong {
  font-size: 1.05rem;
}

.level-card.locked {
  opacity: 0.45;
}

.level-card:not(.locked):hover {
  border-color: rgba(91, 140, 255, 0.4);
}

.level-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--muted);
}

.level-stars {
  color: var(--warn);
  letter-spacing: 0.06em;
}

.level-meta {
  color: var(--muted);
  font-size: 0.82rem;
}

.mode-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mode-text strong {
  font-size: 0.95rem;
  font-weight: 650;
}

.mode-text span {
  color: var(--muted);
  font-size: 0.78rem;
}

/* Panels */
.panel {
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.panel-head h3 {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 650;
}

.panel-hint {
  color: var(--muted);
  font-size: 0.78rem;
}

.theme-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 110px;
  overflow-y: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.theme-row::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}

.theme-row::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 999px;
}

.theme-panel {
  flex-shrink: 0;
}

.theme-row::-webkit-scrollbar {
  display: none;
}

.theme-chip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 0.85rem;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.theme-chip.active {
  border-color: rgba(91, 140, 255, 0.5);
  color: var(--ink);
  background: rgba(91, 140, 255, 0.12);
}

.theme-swatch {
  display: flex;
  gap: 3px;
}

.theme-swatch i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 20px;
  border-radius: 14px;
  font-weight: 650;
  font-size: 0.98rem;
  letter-spacing: 0.02em;
  transition: transform 0.1s, filter 0.15s, background 0.15s, opacity 0.15s;
}

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

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #7c5cff);
  color: white;
  box-shadow: 0 10px 28px rgba(91, 140, 255, 0.35);
}

.btn-primary:hover {
  filter: brightness(1.06);
}

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

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.09);
}

.btn-block {
  width: 100%;
}

.btn-lg {
  min-height: 54px;
  font-size: 1.05rem;
}

/* Size grid — 一行 4 个，末行 3 个居中 */
.size-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.size-card {
  width: calc((100% - 30px) / 4);
  max-width: 110px;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: border-color 0.15s, transform 0.12s, background 0.15s;
  flex: 0 0 auto;
}

.size-card strong {
  font-size: clamp(1.15rem, 5vw, 1.45rem);
  font-weight: 700;
  font-family: var(--mono);
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.size-card span {
  color: var(--muted);
  font-size: clamp(0.78rem, 3vw, 0.92rem);
  font-weight: 500;
  line-height: 1.2;
}

.size-card:hover {
  border-color: rgba(91, 140, 255, 0.4);
  background: var(--surface-2);
}

.size-card:active {
  transform: scale(0.97);
}

.size-card.selected {
  border-color: var(--accent);
  background: rgba(91, 140, 255, 0.12);
  box-shadow: 0 0 0 1px rgba(91, 140, 255, 0.3);
}

.size-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Option card / switches */
.option-card {
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.05);
  padding: 4px 16px;
}

.interf-panel {
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}

.interf-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 8px;
}

.interf-label strong {
  font-size: 0.92rem;
  font-weight: 650;
}

.interf-label span {
  color: var(--muted);
  font-size: 0.8rem;
}

.seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.28);
}

.seg-btn {
  min-height: 44px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
  border: 1px solid transparent;
  background: transparent;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s, border-color 0.15s;
}

.seg-btn.active {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #7c5cff);
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.12),
    0 6px 14px rgba(91, 140, 255, 0.35);
}

.seg-btn:not(.active):hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
}

.seg-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.cell.mono-cell {
  color: rgba(255, 255, 255, 0.9);
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.08),
    0 2px 3px rgba(0, 0, 0, 0.35);
}

.cell.mono-cell.on-light {
  color: rgba(20, 16, 28, 0.92);
}

/* 动态随机：整盘闪一下 */
.board.flash-recolor {
  animation: recolor-flash 0.28s ease;
}

@keyframes recolor-flash {
  0% {
    filter: brightness(1.12) saturate(1.15);
  }
  100% {
    filter: none;
  }
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.switch-row:last-child {
  border-bottom: 0;
}

.switch-row strong {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
}

.switch-row span:not(.switch) {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 2px;
}

.switch-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch {
  position: relative;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: var(--surface-3);
  flex: 0 0 auto;
  transition: background 0.2s;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.switch-row input:checked + .switch {
  background: var(--accent);
}

.switch-row input:checked + .switch::after {
  transform: translateX(20px);
}

.switch-row input:focus-visible + .switch {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* 双人/单人分段（难度页「训练方式」） */
.seg-2 {
  grid-template-columns: repeat(2, 1fr);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  min-width: 56px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid transparent;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.9rem;
  font-weight: 600;
}

.chip.active {
  color: var(--ink);
  border-color: var(--accent);
  background: rgba(91, 140, 255, 0.14);
}

.chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Stats */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.05);
  padding: 14px 10px;
  text-align: center;
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  margin-bottom: 6px;
}

.stat-card strong {
  font-size: 1.15rem;
  font-family: var(--mono);
  font-weight: 700;
}

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

.best-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 0.9rem;
}

.best-row:last-child {
  border-bottom: 0;
}

.best-row span {
  color: var(--muted);
}

.best-row strong {
  font-family: var(--mono);
  font-weight: 650;
}

#trend-canvas {
  width: 100%;
  height: 140px;
  display: block;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.2);
}

.empty-state {
  color: var(--muted);
  text-align: center;
  font-size: 0.85rem;
  padding: 18px 0;
}

.about-text {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.65;
}

.about-text.muted {
  color: var(--muted-2);
  font-size: 0.8rem;
  margin: 0;
}

/* Game screens */
.game-screen {
  padding-left: 14px;
  padding-right: 14px;
  overflow: hidden;
}

#screen-race .game-top {
  margin-bottom: 8px;
}

#screen-race .game-tip {
  margin-top: 4px;
}

.game-top {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.game-top .icon-btn {
  align-self: flex-start;
}

.game-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.game-mode {
  color: var(--muted);
  font-size: 0.88rem;
}

.game-timer {
  font-family: var(--mono);
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  transition: color 0.15s, transform 0.15s;
}

.game-timer.has-penalty {
  color: var(--warn);
}

.game-timer.penalty-flash {
  color: var(--danger);
  animation: penalty-bump 0.4s ease;
}

@keyframes penalty-bump {
  0% {
    transform: scale(1);
  }
  30% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}

.game-progress-wrap {
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.game-progress {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--success));
  transition: width 0.2s ease;
}

.game-hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.hud-item {
  background: rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  padding: 8px 10px;
  text-align: center;
}

.hud-item span {
  display: block;
  color: var(--muted);
  font-size: 0.7rem;
  margin-bottom: 2px;
}

.hud-item strong {
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 700;
}

.board-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 4px 0 12px;
  position: relative;
}

.board-wrap::before {
  content: "";
  position: absolute;
  width: min(92%, 380px);
  aspect-ratio: 1;
  border-radius: 28px;
  background: radial-gradient(circle at 50% 30%, rgba(91, 140, 255, 0.1), transparent 70%);
  filter: blur(18px);
  pointer-events: none;
  z-index: 0;
}

.board {
  width: min(100%, 420px);
  aspect-ratio: 1;
  display: grid;
  gap: 9px;
  touch-action: manipulation;
  user-select: none;
  position: relative;
  z-index: 1;
  padding: 10px;
  border-radius: 22px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.015));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 20px 50px rgba(0, 0, 0, 0.28);
}

.board-sm {
  width: 100%;
  gap: 5px;
  padding: 6px;
  border-radius: 14px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    0 10px 28px rgba(0, 0, 0, 0.22);
}

/* Cells — 立体压感 + 随机凹凸 */
.cell {
  --lift: 6px;
  --lift-shadow: 0 10px 18px rgba(0, 0, 0, 0.28);
  --bevel-top: inset 0 2px 0 rgba(255, 255, 255, 0.32);
  --bevel-bot: inset 0 -2px 0 rgba(0, 0, 0, 0.18);
  --press-y: 3px;
  --sheen: 165deg;
  position: relative;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-family: var(--mono);
  color: rgba(255, 255, 255, 0.98);
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.12),
    0 2px 3px rgba(0, 0, 0, 0.35);
  box-shadow:
    0 var(--lift) 0 rgba(0, 0, 0, 0.22),
    var(--lift-shadow),
    var(--bevel-top),
    var(--bevel-bot);
  transition:
    transform 0.11s cubic-bezier(0.2, 0.8, 0.3, 1),
    box-shadow 0.11s cubic-bezier(0.2, 0.8, 0.3, 1),
    opacity 0.28s ease,
    filter 0.15s ease;
  overflow: hidden;
  cursor: pointer;
  font-size: clamp(1.35rem, 6.2vw, 2rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  isolation: isolate;
  transform: none;
}

/* 凸起：高按键 */
.cell.r-up-2 {
  --lift: 9px;
  --lift-shadow: 0 14px 22px rgba(0, 0, 0, 0.34);
  --bevel-top: inset 0 2.5px 0 rgba(255, 255, 255, 0.42);
  --bevel-bot: inset 0 -2.5px 0 rgba(0, 0, 0, 0.22);
  filter: brightness(1.05);
}

.cell.r-up-1 {
  --lift: 7px;
  --lift-shadow: 0 11px 18px rgba(0, 0, 0, 0.3);
  --bevel-top: inset 0 2px 0 rgba(255, 255, 255, 0.36);
  --bevel-bot: inset 0 -2px 0 rgba(0, 0, 0, 0.2);
  filter: brightness(1.02);
}

/* 平：基准 */
.cell.r-flat {
  --lift: 5px;
  --lift-shadow: 0 8px 14px rgba(0, 0, 0, 0.24);
}

/* 凹陷：嵌进棋盘 */
.cell.r-down-1 {
  --lift: 2px;
  --lift-shadow: 0 4px 8px rgba(0, 0, 0, 0.18);
  --bevel-top: inset 0 2px 2px rgba(0, 0, 0, 0.22);
  --bevel-bot: inset 0 -1px 0 rgba(255, 255, 255, 0.14);
  --press-y: 1px;
  filter: brightness(0.92) saturate(0.96);
}

.cell.r-down-2 {
  --lift: 0px;
  --lift-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
  --bevel-top: inset 0 3px 3px rgba(0, 0, 0, 0.3);
  --bevel-bot: inset 0 -1px 0 rgba(255, 255, 255, 0.16);
  --press-y: 0px;
  filter: brightness(0.86) saturate(0.92);
  transform: scale(0.96);
  border-radius: 14px;
}

/* 玻璃高光层 */
.cell::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(
    var(--sheen),
    rgba(255, 255, 255, 0.28) 0%,
    rgba(255, 255, 255, 0.08) 38%,
    transparent 62%
  );
  pointer-events: none;
  z-index: 1;
}

.cell.r-down-1::before,
.cell.r-down-2::before {
  opacity: 0.55;
  background: linear-gradient(
    var(--sheen),
    rgba(255, 255, 255, 0.1) 0%,
    rgba(0, 0, 0, 0.08) 45%,
    transparent 70%
  );
}

.cell-num {
  position: relative;
  z-index: 2;
  display: block;
  pointer-events: none;
}

.cell.on-light {
  color: rgba(20, 16, 28, 0.92);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* 多彩纯白格：更接近纯白，减弱灰边 */
.cell.mc-white {
  box-shadow:
    0 6px 0 rgba(0, 0, 0, 0.16),
    0 10px 18px rgba(0, 0, 0, 0.22),
    inset 0 0 0 1px rgba(0, 0, 0, 0.04);
}

.cell.mc-white::before {
  background: linear-gradient(
    var(--sheen, 165deg),
    rgba(255, 255, 255, 0.55) 0%,
    rgba(255, 255, 255, 0.12) 40%,
    transparent 62%
  );
}

.cell.mc-white:active,
.cell.mc-white.pressing {
  box-shadow:
    0 2px 0 rgba(0, 0, 0, 0.14),
    0 4px 10px rgba(0, 0, 0, 0.16),
    inset 0 0 0 1px rgba(0, 0, 0, 0.04);
}

.cell.mc-white.hint {
  box-shadow:
    0 6px 0 rgba(0, 0, 0, 0.16),
    0 10px 18px rgba(0, 0, 0, 0.22),
    0 0 0 2px rgba(255, 255, 255, 0.95),
    0 0 28px rgba(255, 255, 255, 0.45);
}

/* 点击涟漪 */
.cell::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 20%;
  height: 20%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.7), transparent 70%);
  transform: translate(-50%, -50%) scale(1);
  opacity: 0;
  pointer-events: none;
  z-index: 0;
}

.cell:active,
.cell.pressing {
  transform: translateY(var(--press-y)) scale(0.97);
  box-shadow:
    0 2px 0 rgba(0, 0, 0, 0.24),
    0 4px 10px rgba(0, 0, 0, 0.22),
    var(--bevel-top),
    var(--bevel-bot);
}

.cell.done {
  pointer-events: none;
}

/* 消隐（可选项，默认关闭）：点对的格子淡出缩小；
   关闭时盘面保持 .keep，点对的格子视觉不变，难度更高 */
.board:not(.keep) .cell.done {
  opacity: 0.14;
  filter: grayscale(0.5);
  transform: scale(0.86) translateY(3px);
  box-shadow:
    0 1px 0 rgba(0, 0, 0, 0.1),
    inset 0 2px 3px rgba(0, 0, 0, 0.25),
    inset 0 -1px 0 rgba(255, 255, 255, 0.08);
}

.board:not(.keep) .cell.done::before {
  opacity: 0.25;
}

.cell.wrong {
  animation: shake 0.35s ease;
  filter: brightness(1.2) saturate(1.25);
}

.cell.hint {
  box-shadow:
    0 var(--lift) 0 rgba(0, 0, 0, 0.22),
    var(--lift-shadow),
    0 0 0 2px rgba(255, 255, 255, 0.92),
    0 0 28px rgba(255, 255, 255, 0.4),
    var(--bevel-top),
    var(--bevel-bot);
  animation: pulse-hint 1.1s ease-in-out infinite;
  filter: brightness(1.06) !important;
}

.cell.ripple::after {
  animation: ripple-out 0.32s ease-out forwards;
}

@keyframes ripple-out {
  0% {
    opacity: 0.85;
    transform: translate(-50%, -50%) scale(0.4);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(14);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-4px);
  }
  75% {
    transform: translateX(4px);
  }
}

@keyframes pulse-hint {
  0%,
  100% {
    box-shadow:
      0 var(--lift) 0 rgba(0, 0, 0, 0.22),
      var(--lift-shadow),
      0 0 0 2px rgba(255, 255, 255, 0.8),
      0 0 16px rgba(255, 255, 255, 0.28),
      var(--bevel-top),
      var(--bevel-bot);
  }
  50% {
    box-shadow:
      0 var(--lift) 0 rgba(0, 0, 0, 0.22),
      var(--lift-shadow),
      0 0 0 2px rgba(255, 255, 255, 1),
      0 0 36px rgba(255, 255, 255, 0.5),
      var(--bevel-top),
      var(--bevel-bot);
  }
}

.board-sm .cell {
  border-radius: 11px;
  font-size: clamp(1.05rem, 4.8vw, 1.45rem);
  --press-y: 2px;
}

.board-sm .cell.r-up-2 {
  --lift: 5px;
}

.board-sm .cell.r-up-1 {
  --lift: 4px;
}

.board-sm .cell.r-flat {
  --lift: 3px;
}

.board-sm .cell.r-down-1 {
  --lift: 1px;
}

.board-sm .cell.r-down-2 {
  --lift: 0px;
  border-radius: 10px;
}

.board-sm .cell:active,
.board-sm .cell.pressing {
  transform: translateY(var(--press-y)) scale(0.96);
}

.game-tip {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  min-height: 1.4em;
}

/* Race — 面对面分屏（上侧旋转 180°） */
#screen-race {
  padding-top: calc(8px + var(--safe-top));
  padding-bottom: calc(8px + var(--safe-bottom));
}

.race-top {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

.race-title {
  font-weight: 650;
}

.race-arena {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr auto 1fr;
  gap: 0;
  min-height: 0;
  overflow: hidden;
}

.race-divider {
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.18),
    transparent
  );
  margin: 2px 12px;
  flex-shrink: 0;
  order: 1;
}

/* 竖屏：玩家 1 在下、玩家 2 在上并整体旋转（面对面） */
.race-side-top {
  order: 0;
  transform: rotate(180deg);
  transform-origin: center center;
}

.race-divider {
  order: 1;
}

.race-side-bottom {
  order: 2;
}

/* 横屏：左右并排，对面玩家的盘面旋转 180° 面对面 */
@media (orientation: landscape) and (min-height: 300px) {
  .race-arena {
    grid-template-columns: 1fr 1px 1fr;
    grid-template-rows: 1fr;
    gap: 0;
  }

  .race-side {
    justify-content: center;
  }

  .race-side-top {
    order: 0;
    grid-column: 1;
    grid-row: 1;
    transform: rotate(180deg);
  }

  .race-divider {
    order: 1;
    grid-column: 2;
    grid-row: 1;
    width: 1px;
    height: auto;
    margin: 8px 0;
    background: linear-gradient(
      180deg,
      transparent,
      rgba(255, 255, 255, 0.18),
      transparent
    );
    justify-self: center;
    z-index: 2;
  }

  .race-side-bottom {
    order: 2;
    grid-column: 3;
    grid-row: 1;
  }

  .race-side .board {
    width: min(100%, 44vh, 420px);
  }
}

.race-side {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 0;
}

.race-side.finished {
  opacity: 0.7;
}

.race-side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.78rem;
  font-weight: 650;
  padding: 0 2px;
  flex-shrink: 0;
}

.race-side-head.p1 {
  color: var(--p1);
}

.race-side-head.p2 {
  color: var(--p2);
}

.race-tag {
  opacity: 0.9;
}

.race-exit {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.05);
  flex-shrink: 0;
}

.race-exit:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.1);
}

.race-timer {
  font-family: var(--mono);
  font-size: 1.2rem;
  color: var(--accent-2);
  font-variant-numeric: tabular-nums;
}

.race-side .board {
  flex: 0 0 auto;
  width: min(100%, 42vw, 300px);
  aspect-ratio: 1;
  margin: 0 auto;
  align-self: center;
  gap: 7px;
  padding: 7px;
}

/* portrait stacked: fit both boards in viewport */
@media (orientation: portrait) {
  .race-arena {
    overflow: hidden;
  }

  .race-side {
    min-height: 0;
    justify-content: center;
  }

  .race-side .board {
    width: min(100%, 36vh, 320px);
    max-height: 100%;
  }
}

/* race 内的打地鼠盘：压缩留白适配半屏 */
.race-side .whack-board {
  gap: 8px;
  padding: 10px;
  border-radius: 18px;
}

.race-side .whack-board .mole-mouth,
.race-side .whack-board .mole-blush {
  display: none;
}

.race-target {
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  flex-shrink: 0;
}

.race-target strong {
  color: var(--ink);
  font-family: var(--mono);
  font-size: 1rem;
  margin-left: 4px;
}

#screen-race .game-tip {
  margin-top: 4px;
  flex-shrink: 0;
}

/* Result */
.result-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  padding: 20px 8px;
}

.result-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 88px;
  padding: 8px 18px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  background: rgba(61, 220, 151, 0.16);
  color: var(--success);
  border: 1px solid rgba(61, 220, 151, 0.35);
}

.result-badge.good {
  background: rgba(91, 140, 255, 0.16);
  color: var(--accent-2);
  border-color: rgba(91, 140, 255, 0.35);
}

.result-badge.ok {
  background: rgba(255, 176, 32, 0.14);
  color: var(--warn);
  border-color: rgba(255, 176, 32, 0.35);
}

.result-badge.battle {
  background: rgba(255, 122, 182, 0.14);
  color: var(--p2);
  border-color: rgba(255, 122, 182, 0.35);
}

.result-title {
  margin: 4px 0 0;
  font-size: 1.5rem;
  font-weight: 700;
}

.result-sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.result-time {
  font-family: var(--mono);
  font-size: 3.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
  margin: 10px 0 4px;
  font-variant-numeric: tabular-nums;
}

.result-time span {
  font-size: 1.2rem;
  color: var(--muted);
  margin-left: 4px;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(72px, 1fr));
  gap: 10px;
  width: min(100%, 320px);
  margin: 12px 0 4px;
}

.result-stats div {
  background: var(--surface);
  border-radius: 12px;
  padding: 10px 6px;
}

.result-stats span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  margin-bottom: 4px;
}

.result-stats strong {
  font-family: var(--mono);
  font-size: 1rem;
}

.result-new {
  margin-top: 4px;
  padding: 6px 14px;
  border-radius: 999px;
  background: linear-gradient(135deg, #ffb020, #ff7ab6);
  color: #1a1020;
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(100%, 280px);
  margin-top: 18px;
}

.br-rows {
  width: min(100%, 340px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 16px 0 8px;
}

.br-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.br-row.win {
  border-color: rgba(61, 220, 151, 0.45);
  background: rgba(61, 220, 151, 0.08);
}

.br-row .name {
  font-weight: 650;
}

.br-row.p1 .name {
  color: var(--p1);
}
.br-row.p2 .name {
  color: var(--p2);
}

.br-row .time {
  font-family: var(--mono);
  font-size: 1.15rem;
  font-weight: 700;
}

/* Countdown */
.countdown {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(7, 12, 22, 0.72);
  backdrop-filter: blur(6px);
}

.countdown[hidden] {
  display: none;
}

.countdown-num {
  font-size: 5rem;
  font-weight: 800;
  font-family: var(--mono);
  color: var(--ink);
  animation: count-pop 0.7s ease;
  text-shadow: 0 0 40px rgba(91, 140, 255, 0.5);
}

@keyframes count-pop {
  0% {
    transform: scale(0.6);
    opacity: 0;
  }
  40% {
    transform: scale(1.08);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Toast */
.toast {
  position: absolute;
  left: 50%;
  bottom: calc(28px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(90%, 320px);
  padding: 12px 18px;
  border-radius: 999px;
  background: rgba(28, 39, 64, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--ink);
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  text-align: center;
}

.toast[hidden] {
  display: none;
}

/* Wide desktop comfort */
@media (min-width: 520px) {
  .board {
    width: min(100%, 440px);
  }
}

/* 平板/桌面：更大的盘面 + 居中限宽的内容列 */
@media (min-width: 720px) {
  .board {
    width: min(100%, 62vh, 600px);
  }

  .screen-body {
    max-width: 680px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
  }

  #screen-poems .screen-body {
    max-width: 880px;
  }

  .mode-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .poem-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    align-content: start;
  }

  .game-top,
  .game-hud,
  .poem-panel,
  .math-prompt {
    width: 100%;
    max-width: 640px;
    margin-left: auto;
    margin-right: auto;
  }
}

/* 平板竖屏：双人上下堆叠时盘面也可以更大 */
@media (orientation: portrait) and (min-width: 720px) {
  .race-side .board {
    width: min(100%, 42vh, 480px);
  }
}

/* 横屏手机/矮窗口：纵向空间有限,压缩边距并按视口高度收紧盘面 */
@media (orientation: landscape) and (max-height: 520px) {
  .screen {
    padding-top: 6px;
    padding-bottom: 10px;
  }

  .board {
    width: min(100%, calc(100dvh - 225px), 440px);
  }

  .board-wrap {
    padding-top: 2px;
    padding-bottom: 6px;
  }

  .game-top {
    margin-bottom: 6px;
  }

  .game-hud {
    margin-bottom: 8px;
  }

  .hud-item {
    padding: 4px 8px;
  }

  .race-side .board {
    width: min(100%, calc(100dvh - 120px), 300px);
  }

  /* 古诗:面板移到棋盘侧边,不占纵向空间 */
  .poem-panel {
    position: fixed;
    right: 14px;
    top: 55%;
    transform: translateY(-50%);
    width: min(320px, 36vw);
    margin: 0;
    z-index: 5;
  }
}

/* Large board sizes: tighter gap + still-readable digits */
.board[data-size="6"] .cell {
  font-size: clamp(1.2rem, 5.4vw, 1.7rem);
}

.board[data-size="7"],
.board[data-size="8"],
.board[data-size="9"] {
  gap: 6px;
}

.board[data-size="7"] .cell {
  font-size: clamp(1.1rem, 5vw, 1.5rem);
}

.board[data-size="8"] .cell {
  font-size: clamp(1rem, 4.4vw, 1.35rem);
}

.board[data-size="9"] {
  gap: 5px;
}

.board[data-size="9"] .cell {
  border-radius: 10px;
  font-size: clamp(0.95rem, 4vw, 1.2rem);
}

/* Smaller grids: larger digits */
.board[data-size="3"] .cell {
  font-size: clamp(1.6rem, 8vw, 2.4rem);
}

.board[data-size="4"] .cell {
  font-size: clamp(1.5rem, 7vw, 2.15rem);
}

.board-sm[data-size="6"] .cell,
.board-sm[data-size="7"] .cell {
  font-size: clamp(0.95rem, 4vw, 1.25rem);
}

.board-sm[data-size="8"] .cell,
.board-sm[data-size="9"] .cell {
  font-size: clamp(0.85rem, 3.5vw, 1.1rem);
}
