:root {
  --bg: #0b0f1a;
  --bg-elev: #121826;
  --bg-card: #162033;
  --bg-card-hover: #1c2940;
  --text: #e8eefc;
  --text-dim: #8b9bb8;
  --accent: #5b8cff;
  --accent-2: #35d0ba;
  --accent-warm: #ff8a5b;
  --border: rgba(255,255,255,0.08);
  --shadow: 0 12px 40px rgba(0,0,0,0.35);
  --radius: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px 16px calc(32px + var(--safe-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0 20px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(180deg, var(--bg) 70%, transparent);
  backdrop-filter: blur(8px);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid;
  place-items: center;
  font-size: 20px;
  box-shadow: 0 8px 20px rgba(91,140,255,0.35);
}
.brand-text h1 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
}
.brand-note {
  margin: 2px 0 0;
  font-size: 0.72rem;
  color: var(--text-dim);
}
.theme-toggle {
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.85rem;
}

.hero {
  background:
    radial-gradient(600px 220px at 10% 0%, rgba(91,140,255,0.25), transparent 60%),
    radial-gradient(500px 200px at 90% 20%, rgba(53,208,186,0.18), transparent 55%),
    var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 6px);
  padding: 28px 22px;
  margin-bottom: 22px;
  box-shadow: var(--shadow);
}
.hero h2 {
  margin: 0 0 8px;
  font-size: clamp(1.4rem, 4vw, 2rem);
}
.hero p {
  margin: 0;
  color: var(--text-dim);
  max-width: 36em;
  line-height: 1.55;
}

.cats {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 14px;
  margin-bottom: 8px;
  scrollbar-width: none;
}
.cats::-webkit-scrollbar { display: none; }
.cat {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 8px 16px;
  transition: 0.15s ease;
}
.cat.active, .cat:hover {
  color: var(--text);
  border-color: rgba(91,140,255,0.5);
  background: linear-gradient(135deg, rgba(91,140,255,0.25), rgba(53,208,186,0.12));
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 8px 0 14px;
}
.section-title h3 { margin: 0; font-size: 1.05rem; }
.section-title span { color: var(--text-dim); font-size: 0.8rem; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}
@media (min-width: 720px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 18px; }
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
  display: flex;
  flex-direction: column;
  min-height: 210px;
}
.card:hover, .card:focus-within {
  transform: translateY(-3px);
  background: var(--bg-card-hover);
  border-color: rgba(91,140,255,0.4);
}
.card-thumb {
  aspect-ratio: 16 / 11;
  display: grid;
  place-items: center;
  font-size: 3.2rem;
  background:
    linear-gradient(145deg, rgba(91,140,255,0.18), transparent 50%),
    linear-gradient(325deg, rgba(53,208,186,0.12), transparent 45%),
    #0f1628;
  position: relative;
}
.card-thumb .badge {
  position: absolute;
  top: 10px;
  left: 10px;
  font-size: 0.7rem;
  background: rgba(0,0,0,0.45);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 999px;
  color: var(--text-dim);
}
.card-body {
  padding: 12px 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}
.card-body h4 {
  margin: 0;
  font-size: 1rem;
}
.card-body p {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.8rem;
  line-height: 1.4;
}
.card-cta {
  margin-top: auto;
  padding-top: 10px;
  font-size: 0.82rem;
  color: var(--accent-2);
  font-weight: 600;
}

.empty {
  color: var(--text-dim);
  text-align: center;
  padding: 40px 12px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.footer {
  margin-top: 36px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.78rem;
  line-height: 1.5;
}

/* Light theme */
body.light {
  --bg: #f4f7fb;
  --bg-elev: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f7faff;
  --text: #152238;
  --text-dim: #5d6f8a;
  --border: rgba(20,40,80,0.1);
  --shadow: 0 10px 30px rgba(30,50,90,0.08);
}
body.light .card-thumb {
  background:
    linear-gradient(145deg, rgba(91,140,255,0.2), transparent 50%),
    linear-gradient(325deg, rgba(53,208,186,0.15), transparent 45%),
    #e8eef8;
}
body.light .hero {
  background:
    radial-gradient(600px 220px at 10% 0%, rgba(91,140,255,0.18), transparent 60%),
    radial-gradient(500px 200px at 90% 20%, rgba(53,208,186,0.14), transparent 55%),
    #fff;
}

/* Shared game shell */
.game-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.game-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}
.game-bar .back {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 999px;
  padding: 8px 12px;
}
.game-bar .title { font-weight: 700; }
.game-bar .stats {
  display: flex;
  gap: 12px;
  color: var(--text-dim);
  font-size: 0.9rem;
}
.game-bar .stats strong { color: var(--text); }
.game-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
  gap: 12px;
}
.game-stage canvas {
  width: min(92vw, 440px);
  height: auto;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #0a1020;
  touch-action: none;
  box-shadow: var(--shadow);
}
.game-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.game-actions button {
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  background: linear-gradient(135deg, var(--accent), #6a5cff);
  color: white;
  font-weight: 600;
}
.game-actions button.secondary {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
}
.hint {
  color: var(--text-dim);
  font-size: 0.82rem;
  text-align: center;
  max-width: 28em;
  line-height: 1.45;
}
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(3, 52px);
  gap: 6px;
  margin-top: 4px;
}
.dpad button {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  border-radius: 14px;
  font-size: 1.1rem;
}
.dpad .up { grid-column: 2; grid-row: 1; }
.dpad .left { grid-column: 1; grid-row: 2; }
.dpad .right { grid-column: 3; grid-row: 2; }
.dpad .down { grid-column: 2; grid-row: 3; }
.overlay {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(5,8,16,0.72);
  color: white;
  text-align: center;
  border-radius: 16px;
  padding: 20px;
}
.overlay.show { display: grid; }
.stage-wrap { position: relative; }
