:root {
  --bg:       #16181D;
  --bg2:      #1E2128;
  --bg3:      #252830;
  --line:     #353945;
  --line2:    #424859;
  --text:     #E8E4DC;
  --text2:    #A8A49C;
  --text3:    #6A6760;
  --r:  6px;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { overflow-x: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}
.hero {
  background: var(--bg2);
  border-bottom: 1px solid var(--line);
  padding: 2rem 2rem 1.8rem;
  text-align: center;
  margin-bottom: 0;
}
.hero-logo {
  height: 40px;
  margin-bottom: 0.8rem;
}
.hero-eyebrow {
  font-family: 'DM Mono', monospace;
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #C8952E;
  margin-bottom: 0.5rem;
}
.hero-title {
  font-family: 'DM Serif Display', serif;
  font-size: clamp(2rem, 5vw, 2.8rem);
  font-weight: 400;
  color: var(--text);
  margin-bottom: 0;
  letter-spacing: -.01em;
  line-height: 1.2;
}
.hero-accent {
  color: #C8952E;
  font-style: italic;
}
.hero-sub {
  display: none;
}

/* Toolbar */
.toolbar {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 0.5rem;
}
.toolbar-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  width: 100%;
}
.toolbar-controls {
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
}
#game-search {
  flex: 1;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 0.75rem 1.1rem;
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 0.95rem;
  color: var(--text);
  outline: none;
  transition: border-color .2s;
}
#game-search::placeholder { color: var(--text3); }
#game-search:focus { border-color: #C8952E; }
.search-count {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text);
  white-space: nowrap;
  font-weight: 500;
}

/* Filter groups */
.filter-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.filter-label {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text);
  white-space: nowrap;
  font-weight: 500;
}
.filter-chips {
  display: flex;
  gap: 0.3rem;
}
/* Browse mode toggle */
.browse-toggle-wrapper {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  margin-bottom: 0.75rem;
}
.browse-toggle {
  display: inline-flex;
  background: var(--bg);
  border: 1.5px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
}
.browse-btn {
  padding: 0.5rem 1.1rem;
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 12px;
  font-weight: 500;
  color: var(--text3);
  background: none;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.browse-btn:not(:last-child) { border-right: 1px solid var(--line); }
.browse-btn:hover { color: var(--text2); background: var(--bg2); }
.browse-btn.active {
  color: var(--text);
  background: var(--bg3);
  font-weight: 600;
}
.browse-btn.active.mode-shelf { color: #C8952E; }
.browse-btn.active.mode-category { color: #c17f3e; }

/* Category panel */
.category-wrapper {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  margin-bottom: 0.75rem;
}
.category-toggle {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 13px;
  font-weight: 500;
  padding: 0.65rem 1.2rem;
  border-radius: var(--r);
  border: 1.5px solid var(--line2);
  background: var(--bg2);
  color: var(--text2);
  cursor: pointer;
  transition: all .2s;
}
.category-toggle:hover { border-color: #c17f3e; color: var(--text); }
.category-active-cat {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  letter-spacing: .04em;
  color: #c17f3e;
}
.category-toggle .shelf-arrow { color: var(--text3); }
.category-toggle.open .shelf-arrow { transform: rotate(180deg); }
.category-panel {
  display: none;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.5rem;
  padding-top: 0.6rem;
  width: 100%;
}
.category-panel.open { display: grid; }
.cat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.65rem 0.3rem;
  border-radius: 8px;
  border: 1.5px solid var(--line);
  background: var(--bg);
  cursor: pointer;
  transition: all .2s;
}
.cat-item:hover {
  border-color: var(--cc-color);
  background: var(--bg3);
}
.cat-item.active {
  border-color: var(--cc-color);
  background: var(--bg3);
  box-shadow: inset 0 0 0 1px var(--cc-color);
}
.cat-item.active .ci-name { color: var(--text); }
.cat-item.active .ci-count { color: var(--cc-color); }
.ci-emoji { font-size: 1.3rem; line-height: 1; }
.ci-name {
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text3);
  text-align: center;
  white-space: nowrap;
  transition: color .2s;
}
.ci-count {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  color: var(--text3);
  transition: color .2s;
}

/* Shelf collapsible panel */
.shelf-wrapper {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  margin-bottom: 0.75rem;
}
.shelf-toggle {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 13px;
  font-weight: 500;
  padding: 0.65rem 1.2rem;
  border-radius: var(--r);
  border: 1.5px solid var(--line2);
  background: var(--bg2);
  color: var(--text2);
  cursor: pointer;
  transition: all .2s;
}
.shelf-toggle:hover { border-color: #C8952E; color: var(--text); }
.shelf-active-cat {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  letter-spacing: .04em;
  color: #C8952E;
}
.shelf-arrow {
  font-size: 10px;
  margin-left: auto;
  transition: transform .25s;
  color: var(--text3);
}
.shelf-toggle.open .shelf-arrow { transform: rotate(180deg); }
.shelf-panel {
  display: none;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.5rem;
  padding-top: 0.6rem;
  width: 100%;
}
.shelf-panel.open { display: grid; }
.shelf-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.65rem 0.3rem;
  border-radius: 8px;
  border: 1.5px solid var(--line);
  background: var(--bg);
  cursor: pointer;
  transition: all .2s;
}
.shelf-item:hover {
  border-color: var(--sc-color);
  background: var(--bg3);
}
.shelf-item.active {
  border-color: var(--sc-color);
  background: var(--bg3);
  box-shadow: inset 0 0 0 1px var(--sc-color);
}
.shelf-item.active .si-name { color: var(--text); }
.shelf-item.active .si-count { color: var(--sc-color); }
.si-emoji { font-size: 1.3rem; line-height: 1; }
.si-name {
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text3);
  text-align: center;
  white-space: nowrap;
  transition: color .2s;
}
.si-count {
  font-family: 'DM Mono', monospace;
  font-size: 8px;
  color: var(--text3);
  transition: color .2s;
}

.chip {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  letter-spacing: .05em;
  text-transform: uppercase;
  padding: 0.35rem 0.65rem;
  border-radius: 100px;
  border: 1px solid var(--line2);
  background: transparent;
  color: var(--text2);
  cursor: pointer;
  transition: all .2s;
}
.chip:hover { border-color: #C8952E; color: var(--text); }
.chip.active { background: #C8952E; border-color: #C8952E; color: #fff; }

/* Sort select */
#sort-select {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  letter-spacing: .05em;
  padding: 0.4rem 0.6rem;
  border-radius: var(--r);
  border: 1px solid var(--line2);
  background: var(--bg2);
  color: var(--text);
  cursor: pointer;
  outline: none;
}
#sort-select:focus { border-color: #C8952E; }
#sort-select option {
  background: var(--bg2);
  color: var(--text);
}

/* View toggle */
.view-toggle {
  display: flex;
  gap: 0.25rem;
}
.view-btn {
  padding: 0.4rem;
  border-radius: var(--r);
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text3);
  cursor: pointer;
  transition: all .2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.view-btn:hover { color: var(--text2); border-color: var(--line2); }
.view-btn.active { background: var(--bg3); color: var(--text); border-color: var(--line2); }

/* Grid view */
.grid {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem 4rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1.5rem;
}
.card {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0;
  text-decoration: none;
  color: inherit;
  transition: transform .2s, box-shadow .2s;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}
.card-img-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  background: var(--bg3);
  overflow: hidden;
  display: block;
  text-decoration: none;
}
.card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.card-img-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  color: var(--text3);
}
.card-body {
  padding: 0.8rem 1rem 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.card-weight-badge,
.card-complexity-badge {
  position: absolute;
  top: 8px;
  padding: 3px 8px;
  border-radius: 6px;
  font-family: 'DM Mono', monospace;
  font-weight: 600;
  color: #fff;
  line-height: 1.4;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
  box-shadow: 0 2px 8px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.15);
}
.card-weight-badge {
  right: 8px;
  font-size: 0.7rem;
}
.card-complexity-badge {
  left: 8px;
  font-size: 0.6rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.card-category {
  font-family: 'DM Mono', monospace;
  font-size: 0.65rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent-color, var(--text3));
  margin-bottom: 0.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}
.card-shelf-id {
  font-family: 'DM Mono', monospace;
  font-size: 0.6rem;
  font-weight: 700;
  color: #FF6B35;
  background: rgba(255, 107, 53, 0.1);
  border: 1px solid rgba(255, 107, 53, 0.25);
  border-radius: 4px;
  padding: 1px 6px;
  letter-spacing: .08em;
  text-transform: uppercase;
  white-space: nowrap;
  flex-shrink: 0;
}
.card-desc {
  font-size: 0.75rem;
  color: var(--text3);
  line-height: 1.45;
  margin-bottom: 0.4rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card::before {
  display: none;
}
.card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}
.card-name {
  font-family: 'DM Serif Display', serif;
  font-size: 1.05rem;
  font-weight: 400;
  color: var(--text);
  margin-bottom: 0.25rem;
  line-height: 1.3;
}
.card-meta {
  display: flex;
  gap: 0.6rem;
  font-size: 0.72rem;
  color: var(--text3);
  margin-bottom: 0.4rem;
  flex-wrap: wrap;
}
.card-meta span {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}
.rulebook-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: rgba(232,220,200,0.08);
  color: rgba(232,220,200,0.5);
  cursor: pointer;
  transition: all 0.2s;
}
.rulebook-icon:hover {
  background: rgba(192,57,43,0.25);
  color: #e8dcc8;
}
.rules-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: rgba(232,220,200,0.4);
  transition: color 0.2s;
}
.rules-link:hover {
  color: #e8dcc8;
}
.th-rules, .td-rules {
  text-align: center;
  width: 60px;
}
.weight-tag {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .05em;
}

/* List / Table view */
.list-view {
  display: block !important;
  grid-template-columns: none !important;
}
.game-table {
  width: 100%;
  border-collapse: collapse;
}
.game-table thead th {
  font-family: 'DM Mono', monospace;
  font-size: 8px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text3);
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--line2);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 1;
}
.sortable {
  cursor: pointer;
  user-select: none;
  transition: color .2s;
}
.sortable:hover {
  color: var(--text2);
}
.game-table .th-players,
.game-table .th-time,
.game-table .th-weight,
.game-table .th-complexity,
.game-table .th-rank {
  text-align: center;
}
.game-row {
  cursor: pointer;
  transition: background .15s;
}
.game-row:hover {
  background: var(--bg3);
}
.game-row td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.td-name {
  font-family: 'DM Serif Display', serif;
  font-size: 1rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.row-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--accent-color);
  display: inline-block;
}
.td-category {
  font-family: 'DM Mono', monospace;
  font-size: 9px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text3);
}
.td-players,
.td-time,
.td-rank,
.td-complexity {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: var(--text2);
  text-align: center;
}
.td-weight {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  font-weight: 500;
  text-align: center;
}

/* Responsive */
@media (max-width: 768px) {
  .hero { padding: 1.5rem 1.5rem 1.2rem; }
  .hero-title { font-size: 1.8rem; }
  .toolbar { padding: 1rem 1rem 0.5rem; }
  .toolbar-row { flex-direction: column; gap: 0.5rem; }
  #game-search { width: 100%; }
  .toolbar-controls { flex-direction: column; align-items: center; gap: 0.75rem; }
  .filter-group { flex-wrap: wrap; justify-content: center; width: 100%; }
  .filter-label { width: 100%; text-align: center; }
  .filter-chips { flex-wrap: wrap; justify-content: center; }
  .shelf-panel { grid-template-columns: repeat(3, 1fr); }
  .category-panel { grid-template-columns: repeat(3, 1fr); }
  .shelf-toggle, .category-toggle { font-size: 12px; padding: 0.7rem 1.1rem; }
  .browse-toggle-wrapper { padding: 0 1rem; }
  .category-wrapper { padding: 0 1rem; }
  .view-toggle { margin-left: 0; }
  .browse-btn { padding: 0.65rem 1.2rem; }
  .chip { padding: 0.45rem 0.75rem; }
  .filter-chips { gap: 0.4rem; }
  .th-category, .td-category,
  .th-complexity, .td-complexity,
  .th-rank, .td-rank { display: none; }
  /* Table scroll wrapper for mobile */
  .game-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}
/* Ensure minimum 2 cards per row on all screens */
.grid:not(.list-view) {
  grid-template-columns: repeat(auto-fill, minmax(min(160px, 45%), 1fr));
}
@media (max-width: 480px) {
  .hero { padding: 1.2rem 1rem 1rem; }
  .hero-title { font-size: 1.5rem; }
  .grid { padding: 0 0.75rem 3rem; gap: 0.75rem; }
  .grid:not(.list-view) {
    grid-template-columns: repeat(2, 1fr);
  }
  .th-category, .td-category,
  .th-complexity, .td-complexity,
  .th-rank, .td-rank,
  .th-time, .td-time { display: none; }
  .card-name { font-size: 0.85rem; }
  .card-body { padding: 0.5rem 0.6rem 0.7rem; }
  .card { border-radius: 10px; }
  .card-img-placeholder { font-size: 2.2rem; }
  .shelf-panel, .category-panel { grid-template-columns: repeat(2, 1fr); }
  .shelf-item, .cat-item { padding: 0.7rem 0.4rem; }
  .browse-btn { padding: 0.6rem 1rem; font-size: 12px; }
  .chip { padding: 0.45rem 0.7rem; font-size: 11px; }
}
