:root {
  --bg: #12121b;
  --bg-soft: #1b1b2e;
  --panel: #1f1f33;
  --panel-2: #262638;
  --line: #33334d;
  --text: #ece9f5;
  --text-dim: #a3a0bd;
  --accent: #f67c5f;
  --accent-2: #f2b179;
  --good: #6fcf97;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 80% -10%, #2a2440 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 10%, #1d2a3a 0%, transparent 55%),
    var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

/* ===== 顶部导航 ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px clamp(16px, 4vw, 48px);
  background: rgba(18, 18, 27, 0.72);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; letter-spacing: 0.5px; }
.brand img { border-radius: 10px; }
.topnav { display: flex; gap: 18px; font-size: 15px; color: var(--text-dim); }
.topnav a:hover { color: var(--text); }

/* ===== 主页 Hero ===== */
.hero {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: clamp(24px, 5vw, 64px);
  align-items: center;
  max-width: 1120px;
  margin: 0 auto;
  padding: clamp(40px, 8vw, 96px) clamp(16px, 4vw, 48px);
}
.kicker {
  font-size: 13px;
  letter-spacing: 3px;
  color: var(--accent-2);
  font-weight: 700;
  margin: 0 0 12px;
}
.hero h1 {
  font-size: clamp(44px, 9vw, 88px);
  line-height: 1;
  margin: 0 0 18px;
  background: linear-gradient(120deg, #fff 0%, var(--accent-2) 45%, var(--accent) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.lede { font-size: clamp(16px, 2.2vw, 19px); color: var(--text-dim); margin: 0 0 28px; }
.lede strong { color: var(--text); }
.hero-actions { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 30px; }
.hero-stats { list-style: none; display: flex; gap: 28px; padding: 0; margin: 0; }
.hero-stats li { display: flex; flex-direction: column; }
.hero-stats b { font-size: 26px; color: #fff; }
.hero-stats span { font-size: 13px; color: var(--text-dim); }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  padding: 12px 22px;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease, border-color 0.2s ease;
  font-family: inherit;
}
.btn:hover { transform: translateY(-1px); border-color: #4a4a6a; }
.btn:active { transform: translateY(0); }
.btn-primary { background: linear-gradient(120deg, var(--accent-2), var(--accent)); border: none; color: #1a1422; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: transparent; }
.btn.is-active { background: var(--good); color: #0c1a12; border-color: var(--good); }

/* Hero 艺术网格 */
.hero-art { display: flex; justify-content: center; }
.art-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  width: min(360px, 80%);
  aspect-ratio: 1;
  padding: 14px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
}
.art-grid .ac {
  border-radius: 10px;
  background: #23233a;
  animation: breathe 3.4s ease-in-out infinite;
}
.art-grid .ac.lit { background: var(--accent); }
.art-grid .ac.lit2 { background: var(--accent-2); }
.art-grid .ac:nth-child(2n) { animation-delay: 0.4s; }
.art-grid .ac:nth-child(3n) { animation-delay: 0.9s; }
@keyframes breathe { 0%, 100% { opacity: 0.5; } 50% { opacity: 1; } }

/* ===== 规则 ===== */
.rules {
  max-width: 1120px;
  margin: 0 auto;
  padding: clamp(32px, 6vw, 72px) clamp(16px, 4vw, 48px);
}
.rules h2 { font-size: clamp(28px, 5vw, 40px); margin: 0 0 12px; text-align: center; }
.rules-intro { text-align: center; color: var(--text-dim); max-width: 720px; margin: 0 auto 36px; }
.rule-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; }
.rule-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
}
.rule-card h3 { margin: 12px 0 10px; font-size: 19px; }
.rule-card p { color: var(--text-dim); margin: 0 0 10px; font-size: 15px; }
.rule-card ul { margin: 0; padding-left: 18px; color: var(--text-dim); font-size: 14px; }
.rule-card li { margin: 4px 0; }
.rule-card b { color: var(--text); }
.rule-num {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: linear-gradient(120deg, var(--accent-2), var(--accent));
  color: #1a1422; font-weight: 800;
}
.rules-tip {
  margin: 28px auto 0;
  max-width: 760px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 20px;
  color: var(--text-dim);
  font-size: 15px;
}
.rules-mode-note {
  max-width: 760px;
  margin: 22px auto 0;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent-2);
  border-radius: 14px;
  padding: 14px 20px;
  color: var(--text);
  font-size: 15px;
}
.rules-mode-note b { color: var(--accent-2); }

/* ===== 游戏区 ===== */
.game {
  max-width: 760px;
  margin: 0 auto;
  padding: clamp(24px, 5vw, 56px) clamp(16px, 4vw, 32px) 64px;
}
.game-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 16px; margin-bottom: 20px; }
.game-head h2 { font-size: clamp(26px, 5vw, 36px); margin: 0; }
.scores { display: flex; gap: 12px; }
.score-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 16px;
  min-width: 78px;
  text-align: center;
}
.score-label { display: block; font-size: 12px; color: var(--text-dim); letter-spacing: 1px; }
.score-value { display: block; font-size: 22px; font-weight: 800; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.tool-group { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-dim); }
select {
  appearance: none;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
}
.hint { color: var(--text-dim); font-size: 13px; margin: 0 0 14px; }
.ctl-group { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* 手动合并模式的十字方向键 */
.manual-controls { margin: 18px 0 6px; text-align: center; }
.manual-controls .hint { max-width: 640px; margin: 0 auto 14px; }
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 60px);
  grid-template-rows: repeat(3, 60px);
  gap: 10px;
  justify-content: center;
}
.dbtn {
  font-size: 22px;
  border: 1px solid var(--line);
  background: linear-gradient(120deg, var(--accent-2), var(--accent));
  color: #1a1422;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.2s ease;
}
.dbtn:hover { filter: brightness(1.06); }
.dbtn:active { transform: scale(0.93); }
.dbtn-up { grid-column: 2; grid-row: 1; }
.dbtn-left { grid-column: 1; grid-row: 2; }
.dbtn-down { grid-column: 2; grid-row: 3; }
.dbtn-right { grid-column: 3; grid-row: 2; }

.board-wrap { position: relative; }
.board {
  --cols: 8;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: clamp(4px, 1vw, 8px);
  width: min(92vw, 560px);
  aspect-ratio: 1;
  margin: 0 auto;
  padding: clamp(6px, 1.5vw, 12px);
  background: #16161f;
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  touch-action: manipulation;
}
.cell {
  position: relative;
  border-radius: 10px;
  background: #20202f;
  display: grid;
  place-items: center;
}
.cell.empty { cursor: pointer; }
.cell.empty:hover { background: #2a2a3d; }
.tile {
  position: absolute;
  inset: clamp(2px, 0.6vw, 5px);
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #fff;
  font-size: 20px;
  white-space: nowrap;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  user-select: none;
}
.tile.newborn { animation: birth 0.4s ease; }
.tile.decayed { animation: decay 0.4s ease; }
@keyframes decay {
  0% { transform: scale(1.14); filter: brightness(1.5) saturate(1.4); }
  100% { transform: scale(1); filter: brightness(1) saturate(1); }
}
@keyframes birth { 0% { transform: scale(0.2); opacity: 0; } 60% { transform: scale(1.15); } 100% { transform: scale(1); opacity: 1; } }

/* 覆盖层 */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(10, 10, 18, 0.78);
  backdrop-filter: blur(4px);
  border-radius: 18px;
  z-index: 20;
}
.overlay.hidden { display: none; }
.overlay-card { text-align: center; padding: 28px 32px; max-width: 340px; }
.overlay-card h3 { font-size: 26px; margin: 0 0 10px; }
.overlay-card p { color: var(--text-dim); margin: 0 0 20px; }
.overlay-actions { display: flex; gap: 12px; justify-content: center; }

.gen-counter { text-align: center; margin-top: 18px; color: var(--text-dim); font-size: 14px; }
.gen-counter b { color: var(--text); }

/* ===== 页脚 ===== */
.footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  padding: 32px 16px 48px;
  border-top: 1px solid var(--line);
  margin-top: 24px;
}

/* ===== 响应式 ===== */
@media (max-width: 760px) {
  .hero { grid-template-columns: 1fr; }
  .hero-art { order: -1; }
  .topnav { display: none; }
  .hero-stats { gap: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  .art-grid .ac, .tile, .tile.newborn { animation: none; }
}
