:root {
  --bg: #f7f4ff;
  --bg-2: #ffffff;
  --ink: #1a1233;
  --ink-2: #4a4266;
  --accent: #5b2ed1;
  --accent-2: #ff4fa3;
  --accent-3: #ffc93c;
  --accent-4: #2ecc71;
  --shadow: 0 8px 24px rgba(91, 46, 209, 0.12);
  --radius: 18px;
  --radius-sm: 12px;
  --max: 1200px;
  --tap: 44px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: contain; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button { font: inherit; cursor: pointer; }

.wrap { max-width: var(--max); margin: 0 auto; padding: 0 16px; }
.hidden { display: none !important; }

/* Header */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: linear-gradient(135deg, #5b2ed1 0%, #ff4fa3 100%);
  color: #fff;
  box-shadow: 0 4px 14px rgba(0,0,0,.08);
}
.header-inner {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 16px;
}
.logo { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 20px; }
.logo-mark { font-size: 24px; }
.logo-text span { color: var(--accent-3); }

.search { position: relative; display: flex; align-items: center;
  background: rgba(255,255,255,.18); border-radius: 999px; padding: 4px 4px 4px 14px; }
.search input {
  flex: 1; width: 100%; min-width: 0;
  background: transparent; border: 0; outline: 0;
  color: #fff; font-size: 16px; padding: 8px 0; height: 36px;
}
.search input::placeholder { color: rgba(255,255,255,.75); }
.search button {
  width: 36px; height: 36px; border-radius: 50%; border: 0;
  background: #fff; color: var(--accent); font-size: 16px;
}
.top-nav { display: flex; gap: 6px; flex-wrap: nowrap; overflow-x: auto; }
.chip {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); min-width: var(--tap);
  padding: 0 14px; border-radius: 999px;
  background: rgba(255,255,255,.18); color: #fff;
  font-weight: 600; font-size: 14px; white-space: nowrap;
  transition: transform .15s ease, background .2s ease;
}
.chip:hover { background: rgba(255,255,255,.3); }
.chip.active { background: #fff; color: var(--accent); }

@media (max-width: 720px) {
  .header-inner { grid-template-columns: auto 1fr; grid-template-rows: auto auto; }
  .top-nav { grid-column: 1 / -1; padding-bottom: 6px; }
}

/* Hero */
.hero {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin: 20px 0 12px; padding: 20px 22px;
  background: linear-gradient(135deg, #fff 0%, #f1e7ff 100%);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.hero h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: -.5px; }
.hero p  { margin: 0; color: var(--ink-2); font-size: 15px; }
.hero-emoji { font-size: 36px; letter-spacing: 4px; }
@media (max-width: 560px) { .hero-emoji { display: none; } .hero h1 { font-size: 22px; } }

/* Categories */
.cats { margin: 10px 0 6px; }
.cat-scroll { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.cat-scroll::-webkit-scrollbar { display: none; }
.cat {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 14px; border-radius: 999px;
  background: #fff; color: var(--ink); border: 2px solid #eee;
  font-weight: 600; font-size: 14px; white-space: nowrap;
}
.cat.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Grid */
.section-title { margin: 16px 2px 10px; font-size: 20px; }
.grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
@media (min-width: 720px) { .grid { gap: 16px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); } }

.card {
  position: relative;
  display: block; border-radius: var(--radius);
  overflow: hidden; background: var(--bg-2);
  box-shadow: var(--shadow);
  transition: transform .15s ease;
  aspect-ratio: 1 / 1;
}
.card:hover, .card:focus { transform: translateY(-3px); outline: none; }
.card .thumb {
  width: 100%; height: 70%;
  display: flex; align-items: center; justify-content: center;
  font-size: 54px;
  background: linear-gradient(135deg, var(--c1, #8a5bff) 0%, var(--c2, #ff7ab6) 100%);
  color: #fff;
}
.card .meta {
  padding: 8px 10px; display: flex; flex-direction: column; justify-content: center;
  height: 30%;
}
.card .title { font-weight: 700; font-size: 14px; line-height: 1.2;
  display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.card .tag { font-size: 11px; color: var(--ink-2); }
.card .badge {
  position: absolute; top: 8px; right: 8px;
  background: var(--accent-3); color: #3a2a00;
  font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 999px;
}

.empty { text-align: center; padding: 30px; color: var(--ink-2); }

/* Footer */
.site-footer { margin-top: 32px; padding: 20px 0; text-align: center; color: var(--ink-2); font-size: 13px; }

/* --- Game page --- */
.game-shell {
  min-height: 100vh; display: flex; flex-direction: column;
  background: linear-gradient(180deg, #1a1233 0%, #2b1c5a 100%);
  color: #fff;
}
.game-top {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: rgba(0,0,0,.25); position: sticky; top: 0; z-index: 10;
}
.back-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; color: var(--accent); border: 0;
  min-height: var(--tap); padding: 0 14px; border-radius: 999px; font-weight: 700;
}
.game-title { font-size: 16px; font-weight: 700; flex: 1; }
.game-top .act { background: rgba(255,255,255,.15); color:#fff; border:0; min-height: var(--tap); min-width: var(--tap); border-radius: 999px; padding: 0 14px; font-weight: 700; }

.game-stage {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 10px; position: relative;
}
.game-stage canvas, .game-stage .board {
  width: 100%; max-width: 560px; aspect-ratio: 1 / 1;
  background: #0f0a2b; border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0,0,0,.35); touch-action: none;
}
.hud {
  display: flex; gap: 14px; justify-content: center; align-items: center;
  padding: 6px 10px; font-weight: 700;
}
.hud .pill { background: rgba(255,255,255,.12); padding: 8px 14px; border-radius: 999px; min-height: var(--tap); display: inline-flex; align-items: center; }

/* On-screen controls */
.dpad {
  display: grid; grid-template-columns: repeat(3, 72px); grid-template-rows: repeat(3, 72px);
  gap: 6px; margin: 10px auto;
}
.dpad button {
  background: rgba(255,255,255,.12); color: #fff; border: 0;
  border-radius: 14px; font-size: 28px; font-weight: 800;
  -webkit-user-select: none; user-select: none;
}
.dpad button:active { background: rgba(255,255,255,.28); }
.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; }
.dpad .act { grid-column: 2; grid-row: 2; background: var(--accent-2); }

.controls-row { display: flex; gap: 10px; justify-content: center; padding: 8px; flex-wrap: wrap; }
.controls-row button {
  background: var(--accent-2); color: #fff; border: 0;
  min-height: var(--tap); padding: 0 18px; border-radius: 999px; font-weight: 800;
}

.overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px;
  background: rgba(15, 10, 43, 0.85); color: #fff; text-align: center; padding: 20px;
  border-radius: var(--radius);
}
.overlay h2 { margin: 0; font-size: 24px; }
.overlay p { margin: 0; color: #cfc5ff; }
.overlay button {
  background: var(--accent-3); color: #3a2a00; border: 0;
  min-height: var(--tap); padding: 0 22px; border-radius: 999px; font-weight: 800; font-size: 16px;
}

@media (hover: none) { .dpad { display: grid; } }
@media (hover: hover) and (min-width: 720px) { .dpad { display: none; } }
