/* ============ 全局 ============ */
:root {
  --bg: #0a0e1a;
  --panel: rgba(255, 255, 255, .055);
  --panel-strong: rgba(255, 255, 255, .09);
  --line: rgba(255, 255, 255, .1);
  --text: #eef1f8;
  --muted: #9aa4bd;
  --accent: #7c5cff;
  --accent2: #22d3ee;
  --danger: #ff5c7a;
  --ok: #35d07f;
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

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

.bg-glow {
  position: fixed;
  inset: -20% -20% auto -20%;
  height: 70vh;
  background:
    radial-gradient(45% 45% at 20% 30%, rgba(124, 92, 255, .35), transparent 70%),
    radial-gradient(40% 40% at 80% 10%, rgba(34, 211, 238, .22), transparent 70%);
  filter: blur(10px);
  pointer-events: none;
  z-index: 0;
}

/* ============ 首页 ============ */
body.hub { padding: 40px 20px 24px; align-items: center; justify-content: center; }

.hub-head { width: 100%; max-width: 980px; position: relative; z-index: 1; }

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

.brand-mark {
  font-size: 30px;
  width: 58px; height: 58px;
  display: grid; place-items: center;
  border-radius: 16px;
  background: linear-gradient(140deg, rgba(124, 92, 255, .35), rgba(34, 211, 238, .2));
  border: 1px solid var(--line);
}

.brand h1 { margin: 0; font-size: 26px; letter-spacing: .5px; }

.sub { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; }

.hub-grid {
  width: 100%;
  max-width: 980px;
  margin: 34px 0 0;
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  position: relative;
  z-index: 1;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform .18s ease, border-color .18s ease, background .18s ease;
  backdrop-filter: blur(8px);
}

.card:hover, .card:focus-visible {
  transform: translateY(-4px);
  border-color: rgba(124, 92, 255, .55);
  background: var(--panel-strong);
  outline: none;
}

.card-icon {
  font-size: 26px;
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border-radius: 14px;
  border: 1px solid var(--line);
  margin-bottom: 4px;
}
.card-icon.snake  { background: rgba(53, 208, 127, .14); }
.card-icon.tetris { background: rgba(124, 92, 255, .16); }
.card-icon.g2048  { background: rgba(255, 176, 32, .15); }
.card-icon.mines  { background: rgba(255, 92, 122, .14); }

.card h2 { margin: 0; font-size: 18px; }

.card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; flex: 1; }

.card-go { font-size: 13px; color: var(--accent2); font-weight: 600; }

.site-foot {
  margin-top: 36px;
  color: var(--muted);
  font-size: 12.5px;
  display: flex; gap: 8px; align-items: center;
  position: relative; z-index: 1;
}

/* ============ 游戏页通用 ============ */
body.game {
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  align-items: center;
  justify-content: center;
}

.topbar {
  width: 100%;
  max-width: 760px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  position: relative; z-index: 1;
}

.back {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13.5px; color: var(--muted);
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  transition: color .15s, border-color .15s;
  white-space: nowrap;
}
.back:hover { color: var(--text); border-color: rgba(255, 255, 255, .25); }

.topbar h1 { font-size: 17px; margin: 0; font-weight: 650; }

.topbar .spacer { flex: 1; }

.best-chip {
  font-size: 12.5px; color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 11px;
  background: var(--panel);
  white-space: nowrap;
}
.best-chip b { color: var(--accent2); font-variant-numeric: tabular-nums; }

.stage {
  position: relative;
  z-index: 1;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: center;
  max-width: 100%;
}

canvas {
  display: block;
  border-radius: 12px;
  touch-action: none;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 72vh;
}

.hint { color: var(--muted); font-size: 12.5px; margin-top: 12px; text-align: center; line-height: 1.7; z-index: 1; }
.hint kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 5px;
  background: rgba(255, 255, 255, .06);
  color: var(--text);
}

/* 弹层 */
.overlay {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  background: rgba(8, 11, 20, .78);
  backdrop-filter: blur(6px);
  display: none;
  place-items: center;
  text-align: center;
  padding: 20px;
  z-index: 5;
}
.overlay.show { display: grid; }
.overlay h2 { margin: 0 0 6px; font-size: 22px; }
.overlay p { margin: 0 0 16px; color: var(--muted); font-size: 13.5px; }

.btn {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: #0a0e1a;
  background: linear-gradient(135deg, var(--accent2), #7ef0c0);
  border: 0;
  border-radius: 11px;
  padding: 11px 20px;
  cursor: pointer;
  transition: filter .15s, transform .1s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(.97); }
.btn.ghost {
  background: transparent; color: var(--text);
  border: 1px solid var(--line);
}

/* 分数条 */
.stats { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-bottom: 12px; z-index: 1; }
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 8px 14px;
  min-width: 84px;
  text-align: center;
}
.stat span { display: block; font-size: 11px; color: var(--muted); letter-spacing: .5px; }
.stat b { font-size: 19px; font-variant-numeric: tabular-nums; }

/* 触屏方向键 */
.pad {
  display: none;
  margin-top: 14px;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  z-index: 1;
}
.pad button {
  font-size: 20px;
  width: 62px; height: 54px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--text);
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}
.pad button:active { background: rgba(124, 92, 255, .3); }

@media (hover: none) and (pointer: coarse) {
  .pad { display: flex; }
}

@media (max-width: 720px) {
  body.hub { padding: 24px 14px 18px; justify-content: flex-start; }
  body.game { justify-content: flex-start; }
  .brand h1 { font-size: 22px; }
  .hub-grid { grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 22px; }
  .card { padding: 15px; }
  .card h2 { font-size: 16px; }
  .card p { font-size: 12px; }
  .stage { padding: 12px; gap: 10px; }
  .topbar h1 { font-size: 15.5px; }
  .best-chip { font-size: 11.5px; padding: 6px 9px; }
  .back { padding: 7px 10px; font-size: 12.5px; }
  .stat { padding: 6px 10px; min-width: 70px; }
  .stat b { font-size: 16px; }
}

@media (max-width: 380px) {
  .hub-grid { grid-template-columns: 1fr; }
}

/* 竖屏小屏提示 */
.rotate-note { display: none; }
@media (max-width: 720px) and (orientation: portrait) {
  .rotate-note { display: block; color: var(--muted); font-size: 12px; margin-top: 8px; text-align: center; }
}
