:root {
  --bg: #f7f8f6;
  --surface: #ffffff;
  --ink: #0e1b24;
  --ink-soft: #4a5a66;
  --line: #dfe4e2;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --accent: #f2a541;
  --danger: #d9480f;
  --board: #e7ecea;
  --radius: 14px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a141b;
    --surface: #111e27;
    --ink: #e8eef0;
    --ink-soft: #9fb0ba;
    --line: #1f313c;
    --brand: #2dd4bf;
    --brand-ink: #062a27;
    --danger: #ff8a5c;
    --board: #16252f;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button { font: inherit; }

.wrap { width: 100%; max-width: 1040px; margin: 0 auto; padding: 0 16px; }

/* Header */
.site-header { border-bottom: 1px solid var(--line); background: var(--surface); }
.site-header .wrap { display: flex; align-items: center; gap: 16px; height: 60px; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; text-decoration: none; }
.logo img { width: 26px; height: 26px; }
.logo small { font-weight: 500; color: var(--ink-soft); font-size: 14px; }
.site-header nav { margin-left: auto; display: flex; gap: 18px; }
.site-header nav a { text-decoration: none; color: var(--ink-soft); font-size: 14px; }
.site-header nav a:hover { color: var(--ink); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  text-decoration: none; font-weight: 600; cursor: pointer;
  background: var(--brand); color: var(--brand-ink); border: 0;
  padding: 10px 20px; border-radius: 999px; font-size: 15px;
  transition: transform .15s ease, opacity .15s ease;
}
.btn:hover { transform: translateY(-1px); opacity: .92; }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }

/* Hub */
.hub-hero { padding: 48px 0 24px; }
.hub-hero h1 { font-size: clamp(28px, 5vw, 40px); margin: 0 0 8px; letter-spacing: -0.02em; }
.hub-hero p { margin: 0; color: var(--ink-soft); }
.games { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; padding: 16px 0 64px; }
.card {
  display: flex; flex-direction: column; text-decoration: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; transition: transform .15s ease, box-shadow .15s ease;
}
.card:hover { transform: translateY(-3px); box-shadow: 0 10px 30px rgba(0,0,0,.08); }
.card .thumb { aspect-ratio: 16 / 10; display: grid; place-items: center; background: var(--board); }
.card .thumb svg { width: 70%; height: auto; }
.card .body { padding: 16px 18px 20px; }
.card h2 { margin: 0 0 4px; font-size: 20px; }
.card h2 small { font-size: 14px; font-weight: 500; color: var(--ink-soft); margin-left: 6px; }
.card p { margin: 0; color: var(--ink-soft); font-size: 14px; }
.card.soon { opacity: .55; pointer-events: none; }

.site-footer { border-top: 1px solid var(--line); padding: 20px 0 32px; color: var(--ink-soft); font-size: 13px; }

/* Game shell */
.game { padding: 20px 0 48px; }
.game-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px; }
.game-head h1 { margin: 0; font-size: 24px; }
.stats { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 4px 12px; font-size: 13px; color: var(--ink-soft); min-width: 64px; text-align: center;
}
.stat b { display: block; font-size: 18px; color: var(--ink); font-variant-numeric: tabular-nums; }
.controls { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; justify-content: center; }
.help { color: var(--ink-soft); font-size: 14px; text-align: center; margin-top: 12px; }

.progress { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; margin-bottom: 14px; }
.progress > i { display: block; height: 100%; width: 0; background: var(--brand); transition: width .3s ease; }

canvas { display: block; touch-action: none; user-select: none; -webkit-user-select: none; }

/* Overlay dialog */
.overlay {
  position: fixed; inset: 0; display: none; place-items: center; padding: 16px;
  background: rgba(5, 15, 20, .55); z-index: 20;
}
.overlay.show { display: grid; }
.dialog {
  background: var(--surface); border-radius: 18px; padding: 28px 24px; width: 100%; max-width: 360px;
  text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.dialog h2 { margin: 0 0 6px; font-size: 24px; }
.dialog p { margin: 0 0 18px; color: var(--ink-soft); }
.dialog .controls { margin-top: 0; }

.notfound { min-height: 80vh; display: grid; place-content: center; text-align: center; padding: 16px; }
.notfound h1 { font-size: 64px; margin: 0; }

@media (max-width: 560px) {
  .site-header nav { display: none; }
  .stats { margin-left: 0; width: 100%; }
  .stat { flex: 1; }
}
