/* ===== 经典小游戏合集 全局样式 ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0f172a;
  --bg-2: #1e293b;
  --card: #1e293b;
  --card-border: #334155;
  --accent: #38bdf8;
  --accent-2: #818cf8;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --danger: #f87171;
  --success: #4ade80;
  --warn: #fbbf24;
  --radius: 14px;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  min-height: 100vh;
  line-height: 1.6;
}

a {
  color: var(--accent);
  text-decoration: none;
}

/* ===== 首页 ===== */
.site-header {
  background: linear-gradient(135deg, #0ea5e9 0%, #6366f1 100%);
  padding: 48px 20px 40px;
  text-align: center;
}

.site-title {
  font-size: 2.4rem;
  color: #fff;
  letter-spacing: 2px;
  text-shadow: 0 2px 10px rgba(0,0,0,.3);
}

.site-subtitle {
  margin-top: 10px;
  color: rgba(255,255,255,.85);
  font-size: 1.05rem;
}

.site-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 30px 20px 60px;
}

.cat-section {
  margin-bottom: 40px;
}

.cat-section h2 {
  font-size: 1.5rem;
  margin-bottom: 16px;
  padding-left: 12px;
  border-left: 4px solid var(--accent);
  color: #fff;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 16px;
}

.game-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  color: var(--text);
  transition: transform .25s ease, box-shadow .25s ease, border-color .25s ease, background .25s ease;
  opacity: 0;
  animation: cardIn .55s cubic-bezier(.22,.9,.35,1) forwards;
  animation-delay: calc(var(--anim-delay, 0) * 1ms);
}

.game-card:hover {
  transform: translateY(-6px) scale(1.03);
  box-shadow: 0 14px 30px rgba(56, 189, 248, .22);
  border-color: var(--accent);
  background: linear-gradient(145deg, var(--card), #273449);
}

.game-icon {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  display: block;
  margin-bottom: 10px;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,.35));
  transition: transform .25s ease, filter .25s ease;
  animation: iconFloat 3.2s ease-in-out infinite;
  animation-delay: calc(var(--anim-delay, 0) * 1ms);
}

.game-card:hover .game-icon {
  transform: scale(1.16) rotate(-6deg);
  filter: drop-shadow(0 6px 14px rgba(56,189,248,.45));
  animation-play-state: paused;
}

.game-card h3 {
  font-size: 1.05rem;
  margin-bottom: 6px;
  color: #fff;
}

.game-card p {
  font-size: .82rem;
  color: var(--text-dim);
  line-height: 1.5;
}

.site-footer {
  text-align: center;
  padding: 24px 16px;
  color: var(--text-dim);
  border-top: 1px solid var(--card-border);
  font-size: .9rem;
}

/* ===== 游戏页 ===== */
.game-header {
  background: linear-gradient(135deg, #0ea5e9 0%, #6366f1 100%);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.game-header h1 {
  color: #fff;
  font-size: 1.5rem;
  flex: 1;
}

.back-btn {
  background: rgba(255,255,255,.18);
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: .95rem;
  transition: background .2s;
}

.back-btn:hover {
  background: rgba(255,255,255,.3);
}

.tag {
  background: rgba(255,255,255,.22);
  color: #fff;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: .85rem;
}

.game-main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 30px 20px 60px;
  display: flex;
  gap: 30px;
  flex-wrap: wrap;
  justify-content: center;
}

.stage {
  background: #0b1220;
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 300px;
}

.stage canvas {
  max-width: 100%;
  height: auto;
  background: #0b1220;
  border-radius: 8px;
}

.panel {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 20px 22px;
  min-width: 260px;
  max-width: 340px;
  flex: 1;
}

.panel .desc {
  color: var(--text-dim);
  font-size: .95rem;
  margin-bottom: 16px;
}

.panel .score-line {
  margin: 8px 0;
  font-size: 1.05rem;
}

.panel .score-line strong {
  color: var(--accent);
  font-size: 1.2rem;
}

.btn-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 16px 0;
}

.btn {
  background: var(--accent);
  color: #0f172a;
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: filter .2s, transform .1s;
}

.btn:hover {
  filter: brightness(1.15);
}

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

.btn.secondary {
  background: var(--card-border);
  color: var(--text);
}

.hint {
  color: var(--text-dim);
  font-size: .85rem;
  margin-top: 8px;
}

.msg {
  margin-top: 12px;
  font-weight: 600;
  min-height: 24px;
}

.msg.ok { color: var(--success); }
.msg.err { color: var(--danger); }
.msg.warn { color: var(--warn); }

/* 棋盘类游戏通用 */
.board {
  display: grid;
  gap: 2px;
  background: var(--bg-2);
  padding: 8px;
  border-radius: 10px;
  border: 1px solid var(--card-border);
}

.cell {
  background: #0b1220;
  border: 1px solid var(--card-border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  user-select: none;
  cursor: pointer;
  transition: background .15s;
}

.cell:hover {
  background: #1e293b;
}

.cell.empty { cursor: default; }

/* 数字/字母键盘按钮 */
.key-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}

.key-btn {
  min-width: 40px;
  height: 40px;
  padding: 0 8px;
  background: var(--bg-2);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  transition: background .15s;
}

.key-btn:hover { background: var(--card-border); }
.key-btn:disabled { opacity: .35; cursor: default; }

/* Wordle 猜词专用 */
.word-cell {
  width: 60px;
  height: 60px;
  border: 2px solid var(--card-border);
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #fff;
  background: var(--bg-2);
  margin: 3px;
  user-select: none;
}

.word-cell.cell-green { background: #15803d; border-color: #15803d; }
.word-cell.cell-yellow { background: #a16207; border-color: #a16207; }
.word-cell.cell-gray { background: #475569; border-color: #475569; }
.word-cell.cell-current { border-color: var(--accent); }

/* 各棋盘游戏卡片字号微调（由页面专属类控制，避免内联样式） */
.klotski-board .cell { font-size: .95rem; }
.link-board .cell { font-size: 1.2rem; }
.memory-board .cell { font-size: 1.6rem; }
.minesweeper-board .cell { font-size: .8rem; }
.sliding-board .cell { font-size: 1.4rem; }
.sudoku-board .cell { font-size: 1rem; }
.tictactoe-board .cell { font-size: 2.2rem; }
.whack-board .mole-btn { font-size: 2rem; }

@media (max-width: 720px) {
  .site-title { font-size: 1.8rem; }
  .game-main { flex-direction: column; align-items: center; }
  .panel { max-width: 100%; width: 100%; }
}

/* ===== 增强：动画效果 ===== */
@keyframes cardIn {
  from { opacity: 0; transform: translateY(24px) scale(.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes iconFloat {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-5px); }
}

@keyframes sectionIn {
  from { opacity: 0; transform: translateX(-18px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes headerFlow {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

@keyframes popIn {
  from { opacity: 0; transform: scale(.9) translateY(12px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-16px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes arrowSlide {
  0%   { transform: translateX(0); opacity: .4; }
  100% { transform: translateX(5px); opacity: 1; }
}

@keyframes backPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(56,189,248,.45); }
  50%      { box-shadow: 0 0 0 7px rgba(56,189,248,0); }
}

/* 首页头部渐变流动 */
.site-header {
  background: linear-gradient(135deg, #0ea5e9, #6366f1, #a855f7, #0ea5e9);
  background-size: 300% 300%;
  animation: headerFlow 12s ease infinite;
}

/* 首页分类区块入场 */
.cat-section {
  animation: sectionIn .6s ease both;
}

/* 分类标题链接（点击跳转分区页） */
.cat-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  transition: color .2s ease, letter-spacing .2s ease;
}

.cat-link:hover {
  color: var(--accent);
  letter-spacing: .5px;
}

.cat-arrow {
  display: inline-block;
  color: var(--accent);
  animation: arrowSlide .8s ease-in-out infinite;
}

/* 游戏页元素入场 */
.anim-slide-down {
  animation: slideDown .5s ease both;
}

.anim-pop {
  animation: popIn .5s cubic-bezier(.22,.9,.35,1) both;
}

/* 游戏页按钮微动效 */
.btn {
  transition: filter .2s, transform .12s, box-shadow .2s;
}

.btn:hover {
  filter: brightness(1.15);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(56,189,248,.35);
}

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

.back-btn {
  transition: background .2s, transform .2s;
}

.back-btn:hover {
  transform: translateX(-3px);
  animation: backPulse 1.2s ease infinite;
}

/* ===== 增强：分类分区页 ===== */
.cat-header {
  background: linear-gradient(135deg, #0ea5e9, #6366f1, #a855f7, #0ea5e9);
  background-size: 300% 300%;
  animation: headerFlow 12s ease infinite;
  padding: 40px 20px 34px;
  text-align: center;
}

.cat-back {
  display: inline-block;
  background: rgba(255,255,255,.18);
  color: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  margin-bottom: 14px;
  font-size: .95rem;
  transition: background .2s, transform .2s;
}

.cat-back:hover {
  background: rgba(255,255,255,.32);
  transform: translateX(-3px);
}

.cat-count {
  display: inline-block;
  margin-top: 10px;
  background: rgba(255,255,255,.2);
  color: #fff;
  padding: 3px 14px;
  border-radius: 999px;
  font-size: .85rem;
}

/* 分区页卡片布局（同首页） */
.cat-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 30px 20px 60px;
}

.cat-title {
  font-size: 2rem;
  color: #fff;
  letter-spacing: 2px;
  text-shadow: 0 2px 10px rgba(0,0,0,.3);
}

.cat-sub {
  margin-top: 8px;
  color: rgba(255,255,255,.85);
  font-size: 1.02rem;
}

/* ===== 移动端适配（手机浏览器） ===== */
@media (max-width: 768px) {
  .site-header { padding: 14px; }
  .site-title { font-size: 1.5rem; }
  .cat-section h2 { font-size: 1.25rem; }
  /* 卡片单列展示 */
  .game-grid { grid-template-columns: 1fr; gap: 14px; }
  .game-card { flex-direction: row; text-align: left; gap: 14px; padding: 14px 16px; align-items: center; }
  .game-icon { width: 56px; height: 56px; flex: none; }
  .game-card h3 { font-size: 1.05rem; margin: 0 0 4px; }
  .game-card p { margin: 0; font-size: .88rem; line-height: 1.45; }
  /* 游戏页布局 */
  .game-main { padding: 14px 12px 60px; gap: 16px; }
  .game-header { padding: 12px 14px; gap: 10px; }
  .game-header h1 { font-size: 1.2rem; }
  .back-btn, .cat-back { min-height: 44px; display: inline-flex; align-items: center; font-size: .95rem; }
  .cat-title { font-size: 1.6rem; }
  .cat-sub { font-size: .95rem; }
  /* 舞台与画布自适应 */
  .stage { min-width: 0; width: 100%; padding: 8px; }
  .stage canvas { max-width: 100%; height: auto; }
  .board { max-width: 100%; overflow-x: auto; }
  /* 面板与按钮触控友好 */
  .panel { min-width: 0; max-width: none; width: 100%; padding: 16px; }
  .btn { min-height: 48px; padding: 12px 22px; font-size: 1rem; }
  .btn-row { gap: 8px; }
  .cat-main { padding: 14px 12px 60px; }
}

@media (max-width: 414px) {
  .site-title { font-size: 1.35rem; }
  .game-icon { width: 48px; height: 48px; }
  .game-card h3 { font-size: 1rem; }
  .panel .desc { font-size: .9rem; }
}

@media (max-width: 375px) {
  .stage { padding: 6px; }
  .game-main { padding-left: 8px; padding-right: 8px; }
  .btn { padding: 11px 16px; font-size: .95rem; }
}

/* ===== 触控操作区（D-pad 虚拟按键） ===== */
.touch-controls {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  background: rgba(10, 15, 30, .94);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid rgba(255,255,255,.1);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
body.tc-on .touch-controls { display: block; }
body.tc-on .game-main { padding-bottom: 130px; }

.tc-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
}
.tc-dpad {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(2, 52px);
  gap: 6px;
  flex: none;
}
.tc-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  min-height: 52px;
  border-radius: 12px;
  background: rgba(255,255,255,.14);
  border: 1px solid rgba(255,255,255,.22);
  color: #fff;
  font-size: 1.4rem;
  font-weight: 700;
  touch-action: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  box-sizing: border-box;
}
.tc-btn:active,
.tc-btn.tc-pressed { background: rgba(56,189,248,.55); transform: scale(.94); }
.tc-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; align-items: center; }
.tc-actions .tc-btn { min-width: 64px; font-size: 1.05rem; padding: 0 10px; }
.tc-dpad .tc-up { grid-column: 2; grid-row: 1; }
.tc-dpad .tc-down { grid-column: 2; grid-row: 2; }
.tc-dpad .tc-left { grid-column: 1; grid-row: 2; }
.tc-dpad .tc-right { grid-column: 3; grid-row: 2; }
.tc-hint { color: rgba(255,255,255,.45); font-size: .72rem; text-align: center; padding-top: 4px; }

/* ===== 增强：首页分类切换图片按钮（深底白钮横排极简风） ===== */
.cat-nav {
  background: #0b1220;
  border-bottom: 1px solid rgba(255,255,255,.08);
  position: relative;
  z-index: 5;
}
.cat-nav-track {
  display: flex;
  gap: 12px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 20px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.cat-nav-track::-webkit-scrollbar { display: none; }
.cat-nav-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  color: #111827;
  font-weight: 700;
  font-size: .95rem;
  padding: 8px 16px 8px 10px;
  border-radius: 14px;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
  text-decoration: none;
  transition: transform .2s ease, box-shadow .2s ease, filter .2s ease;
  animation: navFloat 5s ease-in-out infinite;
  animation-delay: calc(var(--nav-delay, 0) * 1ms);
  -webkit-tap-highlight-color: transparent;
}
.cat-nav-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 22px rgba(56,189,248,.35);
  filter: brightness(1.04);
}
.cat-nav-btn:active {
  transform: scale(.94);
}
.cat-nav-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  flex: none;
}

/* 字母键盘（触屏文字类游戏） */
.tc-letters {
  max-width: 600px;
  margin: 0 auto;
  display: grid;
  gap: 6px;
}
.tc-row {
  display: flex;
  gap: 6px;
  justify-content: center;
}
.tc-row .tc-btn {
  min-width: 36px;
  min-height: 46px;
  font-size: 1.05rem;
  padding: 0 4px;
  border-radius: 8px;
}
.tc-row .tc-wide {
  min-width: 64px;
  font-size: .78rem;
  font-weight: 600;
}

/* ===== 增强：全局移动动画 ===== */
@keyframes navFloat {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-2.5px); }
}

@keyframes bgOrbA {
  0%   { transform: translate(0, 0) scale(1); }
  50%  { transform: translate(46px, 26px) scale(1.18); }
  100% { transform: translate(0, 0) scale(1); }
}
@keyframes bgOrbB {
  0%   { transform: translate(0, 0) scale(1); }
  50%  { transform: translate(-40px, 30px) scale(1.12); }
  100% { transform: translate(0, 0) scale(1); }
}
@keyframes titleFloat {
  0%, 100% { transform: translateY(0); text-shadow: 0 2px 10px rgba(0,0,0,.3); }
  50%      { transform: translateY(-3px); text-shadow: 0 6px 18px rgba(56,189,248,.55); }
}
@keyframes iconDrift {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  30%      { transform: translateY(-5px) rotate(-3deg); }
  70%      { transform: translateY(2px) rotate(3deg); }
}
@keyframes btnGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(56,189,248,.35); }
  50%      { box-shadow: 0 0 14px 3px rgba(56,189,248,.45); }
}
@keyframes stageRing {
  0%, 100% { opacity: .35; transform: scale(.98); }
  50%      { opacity: .7;  transform: scale(1); }
}

/* 背景光斑：首页/分区/游戏页 */
.site-main, .cat-main, .game-main {
  position: relative;
}
.site-main::before, .cat-main::before, .game-main::before {
  content: "";
  position: absolute;
  top: -70px;
  right: -80px;
  width: 300px;
  height: 300px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(56,189,248,.16), transparent 70%);
  filter: blur(30px);
  pointer-events: none;
  animation: bgOrbA 16s ease-in-out infinite;
  z-index: 0;
}
.site-main::after, .cat-main::after, .game-main::after {
  content: "";
  position: absolute;
  bottom: -60px;
  left: -80px;
  width: 260px;
  height: 260px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(129,140,248,.14), transparent 70%);
  filter: blur(30px);
  pointer-events: none;
  animation: bgOrbB 18s ease-in-out infinite;
  z-index: 0;
}
.site-main > *, .cat-main > *, .game-main > * {
  position: relative;
  z-index: 1;
}

/* 首页标题浮动 */
.site-title {
  animation: titleFloat 5s ease-in-out infinite;
}

/* 图标增强：浮动 + 轻微旋转 */
.game-icon {
  animation: iconDrift 4s ease-in-out infinite;
  animation-delay: calc(var(--anim-delay, 0) * 1ms);
}

/* 主按钮光晕脉冲（非 secondary） */
.btn:not(.secondary) {
  animation: btnGlow 2.8s ease-in-out infinite;
}

/* 舞台内圈呼吸光 */
.stage::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 10px;
  box-shadow: inset 0 0 26px rgba(56,189,248,.16);
  pointer-events: none;
  animation: stageRing 5s ease-in-out infinite;
}
.stage {
  position: relative;
}

/* 移动端：分类导航横滑提示 */
@media (max-width: 768px) {
  .cat-nav-track { padding: 12px 14px; gap: 10px; }
  .cat-nav-btn { font-size: .9rem; padding: 7px 13px 7px 9px; border-radius: 12px; }
  .cat-nav-icon { width: 26px; height: 26px; border-radius: 7px; }
  .game-card:active { transform: scale(.97); }
}

/* ===== 增强：单/双人模式切换（多人对战游戏） ===== */
.mode-switch {
  display: flex;
  gap: 6px;
  margin: 0 0 16px;
  background: var(--bg-2);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  padding: 4px;
  width: 100%;
}
.mode-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: .9rem;
  font-weight: 600;
  padding: 9px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .2s, color .2s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.mode-btn:hover {
  color: var(--text);
}
.mode-btn:active {
  transform: scale(.96);
}
.mode-btn.active {
  background: var(--accent);
  color: #0f172a;
}
@media (max-width: 768px) {
  .mode-btn { min-height: 44px; font-size: .95rem; }
}
