:root {
  --bg: #0a0d0f;
  --bg-alt: #0f1417;
  --panel: #12181c;
  --panel-border: #232b30;
  --text: #d7dee2;
  --text-dim: #8b979e;
  --text-faint: #5a666c;
  --accent: #35d0a0;
  --accent-dim: #1f7a5c;
  --up: #33d17a;
  --down: #e5534b;
  --new: #35a0ff;
  --mono: "JetBrains Mono", "SFMono-Regular", "Consolas", "Menlo", monospace;
  --sans: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --radius: 3px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  height: 100%;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 16px;
  height: 46px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--panel-border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.5px;
  color: var(--text);
}
.brand .accent { color: var(--accent); }

.tabs {
  display: flex;
  gap: 4px;
  flex: 1;
}

.tab-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  padding: 6px 12px;
  font-size: 12px;
  font-family: var(--sans);
  cursor: pointer;
  border-radius: var(--radius);
  letter-spacing: 0.3px;
}
.tab-btn:hover { color: var(--text); background: #1a2126; }
.tab-btn.active {
  color: var(--accent);
  background: #10221c;
  border-color: var(--accent-dim);
}

.topbar-meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
}

/* ---------- layout ---------- */

main { flex: 1; padding: 16px; }

.view { display: none; }
.view.active { display: block; }

.footer {
  padding: 8px 16px;
  font-size: 11px;
  color: var(--text-faint);
  border-top: 1px solid var(--panel-border);
  background: var(--bg-alt);
}

/* ---------- stat cards ---------- */

.stat-cards {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-faint);
  margin-bottom: 4px;
}

.stat-value {
  font-family: var(--mono);
  font-size: 22px;
  color: var(--accent);
}
.stat-value-small { font-size: 13px; color: var(--text); }

/* ---------- controls ---------- */

.controls-row {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.control {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-dim);
}

select, .search-input {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 5px 8px;
  font-size: 12px;
  font-family: var(--sans);
  border-radius: var(--radius);
}
select:focus, .search-input:focus {
  outline: none;
  border-color: var(--accent-dim);
}

.search-input { width: 240px; }

.btn {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 6px 14px;
  font-size: 12px;
  cursor: pointer;
  border-radius: var(--radius);
}
.btn:hover { border-color: var(--accent-dim); color: var(--accent); }
.btn:disabled { opacity: 0.4; cursor: default; }

.tag-filter {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  padding: 5px 10px;
  border-radius: var(--radius);
}
.tag-filter #gamesTagFilterName { color: var(--accent); font-family: var(--mono); }
.tag-filter button {
  background: transparent;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 12px;
}
.tag-filter button:hover { color: var(--down); }

/* ---------- panels ---------- */

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 16px;
}

.panel-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.panel-caption {
  margin: -6px 0 10px;
}

.panel-subtitle {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-faint);
  margin: 12px 0 8px;
}

.panel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.tags-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}

@media (max-width: 900px) {
  .panel-grid, .tags-layout { grid-template-columns: 1fr; }
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; max-height: 560px; overflow-y: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.data-table th {
  text-align: left;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-faint);
  padding: 6px 8px;
  border-bottom: 1px solid var(--panel-border);
  position: sticky;
  top: 0;
  background: var(--panel);
  white-space: nowrap;
}

.data-table.sortable th {
  cursor: pointer;
  user-select: none;
}
.data-table.sortable th:hover { color: var(--text); }
.data-table.sortable th.sorted { color: var(--accent); }

.data-table td {
  padding: 6px 8px;
  border-bottom: 1px solid #1a2226;
  vertical-align: middle;
}

.data-table tbody tr:hover { background: #161d21; }
.data-table tbody tr.clickable { cursor: pointer; }

.col-num, td.num { text-align: right; font-family: var(--mono); }
.col-rank, td.rank { text-align: right; font-family: var(--mono); width: 42px; }
.col-delta { text-align: center; width: 46px; }

.title-cell { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dev-cell { color: var(--text-dim); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.delta-up { color: var(--up); font-family: var(--mono); }
.delta-down { color: var(--down); font-family: var(--mono); }
.delta-flat { color: var(--text-faint); font-family: var(--mono); }

.badge-new {
  display: inline-block;
  background: #0f2b46;
  color: var(--new);
  border: 1px solid #1c4a73;
  font-size: 9px;
  font-family: var(--mono);
  padding: 1px 5px;
  border-radius: 2px;
  letter-spacing: 0.5px;
}

.tag-chip {
  display: inline-block;
  background: #182024;
  border: 1px solid #263238;
  color: var(--text-dim);
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  margin: 1px 2px 1px 0;
  cursor: pointer;
}
.tag-chip:hover { color: var(--accent); border-color: var(--accent-dim); }

.muted { color: var(--text-faint); font-size: 11px; }

.load-more-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 10px;
}

/* ---------- charts ---------- */

.chart-wrap { position: relative; height: 220px; margin-bottom: 4px; }

/* ---------- tag row selection ---------- */

#tagsTable tbody tr.selected { background: #10221c; }

/* ---------- scenes ---------- */

#sceneDetailContent .gd-tags { margin-bottom: 10px; }
#sceneDetailContent .tag-chip { transition: opacity 0.1s, border-width 0.1s; }
#sceneChildrenList { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 4px; }
#scenesTaxonomyCaption { font-family: var(--mono); }

.scene-stat-line {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  margin: 8px 0 14px;
}
.scene-stat-line b { color: var(--text); font-weight: 600; }
.scene-stat-line .up { color: var(--up); }
.scene-stat-line .down { color: var(--down); }

/* ---------- scenes: full-bleed map + HUD overlays ---------- */

/* main is 16px padding + topbar 46px; the viewport fills the remaining space */
.scene-viewport {
  position: relative;
  height: calc(100vh - 46px - 32px - 33px); /* topbar, main padding, footer */
  min-height: 420px;
  margin: -4px;
  overflow: hidden;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  background: var(--bg-alt);
}

.scene-map-fullbleed {
  position: absolute;
  inset: 0;
}
.scene-map-fullbleed svg { width: 100%; height: 100%; display: block; cursor: grab; }

.hud-panel {
  position: absolute;
  z-index: 2;
  background: rgba(18, 24, 28, 0.92);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 10px 12px;
  backdrop-filter: blur(2px);
}

.hud-panel-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-faint);
  margin-bottom: 8px;
}

/* Scene list panel: left side, may expand to the full viewport height. */
.scene-legend-hud {
  top: 12px;
  left: 12px;
  width: 300px;
  max-height: calc(100% - 24px);
  display: flex;
  flex-direction: column;
}
.scene-legend-hud .panel-title-toggle { margin-bottom: 0; cursor: pointer; }
.scene-legend-rebuild-btn {
  margin-top: 8px;
  width: 100%;
  font-size: 11px;
  padding: 5px 8px;
}
.scene-legend-body {
  margin-top: 8px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.scene-legend-body.collapsed { display: none; }

/* Details panel: top-right, wider than the old bottom-right HUD, may also
   extend to the full viewport height. */
.scene-details-hud {
  top: 12px;
  right: 12px;
  width: 380px;
  max-height: calc(100% - 24px);
  display: flex;
  flex-direction: column;
}
.scene-details-hud .panel-title-toggle { margin-bottom: 0; cursor: pointer; }
.scene-mode-indicator {
  margin-top: 4px;
  font-size: 10px;
  color: var(--text-faint);
}
.scene-mode-item { color: var(--text-faint); }
.scene-mode-item.active { color: var(--accent); font-weight: 600; }
.scene-details-body {
  margin-top: 8px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.scene-details-body.collapsed { display: none; }
.scene-details-content .gd-title { font-size: 15px; padding-right: 0; }
.scene-details-content .table-wrap { max-height: 220px; }
.scene-details-content .compare-add-link { display: inline-block; margin-top: 10px; }

.scene-legend-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 2px;
  cursor: pointer;
  border-bottom: 1px solid #1a2226;
}
.scene-legend-row:last-child { border-bottom: none; }
.scene-legend-row:hover .scene-legend-name,
.scene-legend-row.active .scene-legend-name { color: var(--accent); }
.scene-legend-row.active { background: #10221c; }

.scene-parent-row { font-weight: 600; }
.scene-child-row { padding-left: 20px; }

.scene-accordion-caret {
  flex: none;
  width: 12px;
  font-size: 9px;
  color: var(--text-faint);
  cursor: pointer;
  text-align: center;
  position: relative;
  top: 1px;
}
.scene-accordion-caret:hover { color: var(--text); }

.scene-legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
  position: relative;
  top: 2px;
}
.scene-legend-text { flex: 1; min-width: 0; }
.scene-legend-name {
  font-weight: 600;
  font-size: 12px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.scene-child-row .scene-legend-name { font-weight: 500; }
.scene-legend-meta {
  font-size: 10.5px;
  color: var(--text-faint);
  font-family: var(--mono);
}
.scene-legend-share {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  flex: none;
}

.scene-map-tooltip {
  display: none;
  position: absolute;
  z-index: 3;
  pointer-events: none;
  background: #0d1417;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 6px 9px;
  font-size: 11px;
  max-width: 240px;
  color: var(--text);
}
.scene-map-tooltip b { color: var(--accent); }
.scene-map-tooltip .m { color: var(--text-faint); font-size: 10.5px; }

.scene-map-msg {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: none;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
}
.scene-map-msg.show { display: flex; }

@media (max-width: 900px) {
  .scene-legend-hud { width: 220px; }
  .scene-details-hud { width: 260px; }
}

/* ---------- game detail slide-over ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  justify-content: flex-end;
}
.overlay.hidden { display: none; }

.overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
}

.slideover {
  position: relative;
  width: 480px;
  max-width: 92vw;
  height: 100%;
  background: var(--bg-alt);
  border-left: 1px solid var(--panel-border);
  padding: 20px;
  overflow-y: auto;
  box-shadow: -8px 0 30px rgba(0,0,0,0.4);
}

.slideover-close {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background: rgba(0,0,0,.55);
  border: none;
  border-radius: 50%;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
}
.slideover-close:hover { color: var(--down); background: rgba(0,0,0,.75); }

.gd-cover {
  display: block;
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  border-radius: var(--radius);
  margin-bottom: 12px;
}

.gd-title { font-size: 18px; color: var(--text); margin: 0 0 2px; padding-right: 24px; }
.gd-dev { color: var(--text-dim); font-size: 12px; margin-bottom: 10px; }
.gd-dev-link { color: var(--text-dim); font-size: 12px; margin-bottom: 10px; background: none; border: none; padding: 0; cursor: pointer; font-family: inherit; text-decoration: underline dotted; }
.gd-dev-link:hover { color: var(--accent); }
.gd-link { color: var(--accent); font-size: 12px; text-decoration: none; }
.gd-link:hover { text-decoration: underline; }

.gd-release-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: -4px 0 10px;
}
.gd-status-badge {
  display: inline-block;
  background: #182024;
  border: 1px solid #263238;
  color: var(--text-dim);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 1px 6px;
  border-radius: 10px;
}

.gd-section { margin-top: 16px; }
.gd-section-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-faint);
  margin-bottom: 6px;
}

.gd-tags { display: flex; flex-wrap: wrap; gap: 4px; }

.gd-feeds { display: flex; flex-wrap: wrap; gap: 4px; font-family: var(--mono); font-size: 11px; color: var(--text-dim); }

/* Tags column: keep rows compact */
td.tags-cell { min-width: 200px; }
.chip-more { font-size: 11px; margin-left: 4px; white-space: nowrap; }

/* ---------- tags table: inline compare affordance ---------- */

.tag-name-cell {
  position: relative;
  padding-right: 26px !important;
}

.tag-name-text { display: inline-block; }

.tag-compare-inline-add {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  display: none;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--panel-border);
  color: var(--text-faint);
  font-size: 11px;
  line-height: 1;
  width: 18px;
  height: 18px;
  border-radius: var(--radius);
  cursor: pointer;
  padding: 0;
}
.data-table tbody tr:hover .tag-compare-inline-add { display: inline-flex; }
.tag-compare-inline-add:hover { color: var(--accent); border-color: var(--accent-dim); }

.control-checkbox { cursor: pointer; }
.control-checkbox input { cursor: pointer; }

/* ---------- info icon + popover (shared) ---------- */

.info-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  margin: 0 0 0 2px;
  border: none;
  background: none;
  color: var(--text-faint);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
  vertical-align: middle;
  transition: color 0.15s ease;
}
.info-btn:hover, .info-btn.active { color: var(--text); }

.info-popover {
  position: fixed;
  z-index: 1000;
  max-width: 300px;
  background: rgba(18, 24, 28, 0.92);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 10px 12px;
  backdrop-filter: blur(2px);
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}
.info-popover-close {
  float: right;
  margin: -4px -4px 4px 8px;
  border: none;
  background: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  padding: 2px;
}
.info-popover-close:hover { color: var(--text); }
.info-popover-text { clear: both; }

/* ---------- misc panel chrome (shared) ---------- */

.panel-title-toggle {
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0;
}
.panel-title-toggle .chev { font-size: 9px; color: var(--text-faint); }

.panel-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

/* ---------- tag side panel subtabs ---------- */

.tag-side-panel { display: flex; flex-direction: column; }

.subtabs {
  display: inline-flex;
  gap: 3px;
  margin-bottom: 12px;
  background: var(--bg-alt);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 3px;
  align-self: flex-start;
}

.subtab-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  padding: 3px 10px;
  font-size: 11px;
  font-family: var(--sans);
  cursor: pointer;
  border-radius: var(--radius);
  letter-spacing: 0.3px;
}
.subtab-btn:hover { color: var(--text); background: #1a2126; }
.subtab-btn.active {
  color: var(--accent);
  background: #10221c;
  border-color: var(--accent-dim);
}

.subtab-panel { display: none; }
.subtab-panel.active { display: block; }

.compare-add-link {
  font-size: 11px;
  color: var(--text-dim);
  text-decoration: none;
  white-space: nowrap;
}
.compare-add-link:hover { color: var(--accent); }

.tag-compare-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
  min-height: 20px;
}

.tag-compare-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #182024;
  border: 1px solid #263238;
  color: var(--text);
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  cursor: pointer;
}
.tag-compare-chip:hover { border-color: var(--text-dim); }
.tag-compare-chip .swatch {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
}

.tag-compare-chart-wrap { height: 280px; }

/* ---------- tag jams section + overlay ---------- */

.tag-jam-overlay-row { margin: 4px 0 10px; }

.panel-subtitle-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.tag-jams-section { margin-bottom: 12px; }

.tag-jams-headline {
  font-size: 12px;
  color: var(--text);
  margin-bottom: 6px;
}

.tag-jams-warning {
  display: inline-block;
  background: #2b1f10;
  border: 1px solid #5c4620;
  color: #e5b84b;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: var(--radius);
  margin-bottom: 8px;
}

.tag-jams-list { display: flex; flex-direction: column; gap: 3px; }

.tag-jams-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  padding: 2px 0;
}

/* ---------- jams tab ---------- */

.jam-coverage-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  margin-left: 5px;
  vertical-align: middle;
}

.jam-status-badge {
  display: inline-block;
  background: #182024;
  border: 1px solid #263238;
  color: var(--text-dim);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 1px 6px;
  border-radius: 10px;
}
.jam-status-badge.active { color: var(--up); border-color: #1f5c3a; }
.jam-status-badge.upcoming { color: var(--new); border-color: #1c4a73; }
.jam-status-badge.ended { color: var(--text-faint); }

.jam-crossover-list { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.jam-crossover-row { font-size: 12px; color: var(--text-dim); }
.jam-crossover-row b { color: var(--text); }
