:root {
  --bg: #121212;
  --sidebar: #181818;
  --surface: #1d1d1d;
  --card: #222222;
  --border: #2e2e2e;
  --border-hi: #424242;
  --text: #f0f0f0;
  --muted: #9a9a9a;
  --accent: #e5482e;
  --accent-hi: #f25c43;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

[data-theme="light"] {
  --bg: #efefef;
  --sidebar: #f8f8f8;
  --surface: #ffffff;
  --card: #ffffff;
  --border: #dcdcdc;
  --border-hi: #b8b8b8;
  --text: #161616;
  --muted: #606060;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.4;
}

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

/* Compact Utilitarian Header (itch.io / Steam catalog feel) */
.site-header {
  position: sticky;
  top: 0;
  z-index: 60;
  height: 56px;
  background: var(--sidebar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  gap: 16px;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 1.12rem;
  letter-spacing: -0.03em;
  white-space: nowrap;
}
.wordmark-tag {
  background: var(--accent);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 800;
  padding: 2px 5px;
  border-radius: 3px;
  letter-spacing: 0.03em;
}

.header-search {
  flex: 1;
  max-width: 520px;
}
.search-input {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.88rem;
  outline: none;
}
.search-input:focus { border-color: var(--border-hi); }

.header-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
}
.btn:hover { border-color: var(--border-hi); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-hi); }
.btn-sm { padding: 5px 10px; font-size: 0.78rem; }

/* App Shell: Left Genre Sidebar + Dense Game Wall */
.app-shell {
  display: grid;
  grid-template-columns: 224px 1fr;
  min-height: calc(100vh - 56px);
}
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
}

.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
@media (max-width: 900px) {
  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    gap: 10px;
  }
}

.side-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 0 8px 6px;
}

.genre-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
@media (max-width: 900px) {
  .genre-list { flex-direction: row; flex-wrap: wrap; gap: 6px; }
}

.genre-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 7px 10px;
  border-radius: 5px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
}
@media (max-width: 900px) {
  .genre-btn { width: auto; border: 1px solid var(--border); padding: 5px 10px; font-size: 0.8rem; }
}
.genre-btn:hover { background: var(--card); }
.genre-btn.active { background: var(--accent); color: #fff; font-weight: 600; }
.genre-btn .gcount { font-size: 0.75rem; opacity: 0.7; font-family: var(--mono); margin-left: 8px; }

.side-select {
  width: 100%;
  padding: 7px 9px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.83rem;
}

/* Main Content Area */
.main-area {
  padding: 20px 24px 40px;
  min-width: 0;
}

.shelf-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.shelf-header h2 {
  font-size: 1.12rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.shelf-meta {
  font-size: 0.8rem;
  color: var(--muted);
  font-family: var(--mono);
}

/* Top Featured Shelf (6 diverse 3D titles) */
.featured-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  margin-bottom: 26px;
}
@media (max-width: 1280px) { .featured-row { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 640px) { .featured-row { grid-template-columns: repeat(2, 1fr); } }

/* Main Game Grid */
.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
}

/* Clean Image-First Game Card */
.game-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: transform 0.14s ease, border-color 0.14s ease;
}
.game-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-hi);
}

.game-thumb {
  position: relative;
  aspect-ratio: 16 / 10;
  background: #0c0c0c;
  overflow: hidden;
}
.game-thumb svg { display: block; width: 100%; height: 100%; transition: transform 0.2s ease; }
.game-card:hover .game-thumb svg { transform: scale(1.04); }

.card-embed-btn {
  position: absolute;
  top: 7px;
  right: 7px;
  padding: 3px 7px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(14, 14, 14, 0.86);
  color: #fff;
  font-size: 0.7rem;
  font-family: var(--mono);
  font-weight: 700;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}
.game-card:hover .card-embed-btn, .card-embed-btn:focus { opacity: 1; }
.card-embed-btn:hover { background: var(--accent); border-color: var(--accent); }

.card-play-badge {
  position: absolute;
  bottom: 7px;
  left: 7px;
  background: rgba(14, 14, 14, 0.82);
  color: #f0f0f0;
  font-size: 0.67rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 3px;
}

.game-info {
  padding: 9px 10px 10px;
}
.game-title {
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.game-sub {
  font-size: 0.74rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.load-more-wrap { text-align: center; margin: 28px 0 8px; }

/* Player Modal & Shell */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  z-index: 120;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 14px;
}
.modal-backdrop.open { display: flex; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 100%;
  max-width: 1020px;
  max-height: 95vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.modal-body { padding: 12px; overflow-y: auto; flex: 1; }

.player-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  background: #0a0a0a;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.player-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 8px 12px;
  background: #161616;
  border-bottom: 1px solid #2b2b2b;
  color: #f0f0f0;
  font-size: 0.82rem;
}
.hud-left { display: flex; align-items: center; gap: 8px; }
.hud-title { font-weight: 700; }
.hud-chip { font-size: 0.7rem; background: #262626; padding: 2px 6px; border-radius: 3px; color: #bbb; }
.hud-scores { display: flex; gap: 14px; font-family: var(--mono); }
.hud-scores b { color: #facc15; }
.hud-controls { display: flex; gap: 6px; flex-wrap: wrap; }

.player-stage {
  position: relative;
  width: 100%;
  height: 530px;
  background: #090909;
  user-select: none;
  touch-action: none;
  overflow: hidden;
}
@media (max-width: 720px) { .player-stage { height: 420px; } }

.player-stage canvas.h5g-hud-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

/* =========================================================
   IN-GAME 3D TITLE MENU, PAUSE & END-OF-RUN OVERLAYS
   ========================================================= */
.gmenu-screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  background: rgba(10, 10, 12, 0.62);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
.gmenu-screen.hidden { display: none; }

.gmenu-card {
  width: 100%;
  max-width: 470px;
  background: rgba(20, 20, 22, 0.94);
  border: 1px solid #35353a;
  border-radius: 10px;
  padding: 22px 24px;
  color: #f4f4f4;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
}
.gmenu-compact { max-width: 370px; text-align: center; }

.gmenu-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.74rem;
  color: #a6a6a6;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.gmenu-cat {
  color: #fff;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 3px;
  font-size: 0.7rem;
  text-transform: uppercase;
}
.gmenu-id { margin-left: auto; font-family: var(--mono); opacity: 0.7; }

.gmenu-title {
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.15;
  margin-bottom: 6px;
}
.gmenu-desc {
  font-size: 0.85rem;
  color: #b8b8b8;
  margin-bottom: 14px;
}

.gmenu-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.gmenu-stat {
  background: #141416;
  border: 1px solid #2c2c30;
  border-radius: 6px;
  padding: 8px 10px;
}
.gmenu-stat-lbl { display: block; font-size: 0.68rem; color: #8c8c8c; text-transform: uppercase; }
.gmenu-stat strong { font-family: var(--mono); font-size: 1.05rem; color: #fff; }

.gmenu-medals {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.medal-pill {
  font-size: 0.72rem;
  font-family: var(--mono);
  padding: 3px 8px;
  border-radius: 4px;
  background: #171719;
  border: 1px solid #2f2f34;
  color: #777;
}
.medal-pill.earned.bronze { background: #3b2416; border-color: #b45309; color: #fbbf24; }
.medal-pill.earned.silver { background: #262930; border-color: #94a3b8; color: #e2e8f0; }
.medal-pill.earned.gold { background: #3b2f0b; border-color: #eab308; color: #fde047; font-weight: 700; }

.gmenu-mode-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.gmenu-label { font-size: 0.78rem; font-weight: 600; color: #bbb; }
.gmenu-modes { display: flex; gap: 4px; }
.mode-btn {
  padding: 5px 10px;
  border-radius: 4px;
  border: 1px solid #35353a;
  background: #151517;
  color: #bbb;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}
.mode-btn.active { background: #f4f4f4; color: #111; border-color: #f4f4f4; }

.gmenu-controls-box {
  background: #141416;
  border: 1px solid #2b2b30;
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 16px;
}
.gmenu-keys { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.gmenu-key {
  background: #252529;
  border: 1px solid #404048;
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 2px 7px;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: #f0f0f0;
}
.gmenu-ctrl-text { font-size: 0.78rem; color: #9c9c9c; }

.gmenu-actions { display: flex; gap: 8px; }
.btn-play-main {
  flex: 1;
  padding: 11px 18px;
  border-radius: 6px;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
}
.btn-play-main:hover { background: var(--accent-hi); }

/* Embed Studio Section */
.embed-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 20px;
  margin-top: 32px;
}
.embed-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
  gap: 16px;
  margin-top: 14px;
}
.embed-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px;
}
.embed-card h3 { font-size: 0.96rem; margin-bottom: 4px; }
.embed-card p { font-size: 0.82rem; color: var(--muted); margin-bottom: 10px; }

.code-label { font-size: 0.72rem; font-family: var(--mono); color: var(--muted); margin-top: 10px; }
.code-block {
  background: #0b0b0c;
  color: #e4e4e7;
  border: 1px solid #262626;
  border-radius: 5px;
  padding: 10px;
  font-family: var(--mono);
  font-size: 0.76rem;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 5px 0 8px;
}

.form-row { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 8px; }
.form-row label { display: flex; flex-direction: column; gap: 3px; font-size: 0.72rem; color: var(--muted); font-family: var(--mono); }
.form-row input, .form-row select {
  padding: 6px 9px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.82rem;
}

.toast {
  position: fixed;
  bottom: 18px;
  right: 18px;
  background: #f0f0f0;
  color: #111;
  font-weight: 700;
  font-size: 0.82rem;
  padding: 9px 14px;
  border-radius: 5px;
  z-index: 200;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: all 0.16s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
