:root {
  --bg: #ffffff;
  --surface: #f7f7f7;
  --surface-raised: #f0f0f0;
  --text: #1a1a1a;
  --text-2: #4a4a4a;
  --text-3: #6b6b6b;
  --text-muted: #999999;
  --border: #e5e5e5;
  --border-strong: #d4d4d4;
  --accent: #e87b35;
  --accent-hover: #d06a2a;
  --accent-light: #fdf0e6;
  --success: #2a9d5c;
  --danger: #c44536;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-lift: 0 4px 16px rgba(0,0,0,0.08);
  --font: "DM Sans", system-ui, -apple-system, sans-serif;
  --mono: "DM Mono", "SF Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text-2);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01", "ss02";
}

button, input, select { font-family: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; padding: 0; }

/* ——— Layout ——— */
.app {
  display: grid;
  grid-template-rows: 64px 1fr;
  height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.brand-mark {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
  color: var(--text);
}
.brand-sub {
  color: var(--text-muted);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.search {
  flex: 1;
  max-width: 400px;
  position: relative;
}
.search input {
  width: 100%;
  height: 36px;
  padding: 0 12px 0 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: var(--bg);
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}
.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.view-toggle {
  display: flex;
  background: var(--surface);
  border-radius: 6px;
  padding: 2px;
  gap: 2px;
}
.view-toggle button {
  padding: 6px 14px;
  font-size: 13px;
  border-radius: 4px;
  color: var(--text-3);
  font-weight: 500;
}
.view-toggle button.active {
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow);
}

.stat-pill {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.stat-pill strong {
  color: var(--text);
  font-weight: 600;
}

/* ——— Main grid ——— */
.main {
  display: grid;
  grid-template-columns: 240px 1fr 340px;
  min-height: 0;
}

/* ——— Sidebar ——— */
.sidebar {
  border-right: 1px solid var(--border);
  background: var(--bg);
  overflow-y: auto;
  padding: 20px 8px 20px 20px;
}
.sidebar-section {
  margin-bottom: 24px;
}
.sidebar-title {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 8px;
  padding: 0 8px 0 0;
}

.cat-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.cat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text-2);
  transition: background 0.1s;
  user-select: none;
}
.cat-row:hover { background: var(--surface); }
.cat-row.active {
  background: var(--accent-light);
  color: var(--accent-hover);
}
.cat-row.dim { opacity: 0.35; }
.cat-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}
.cat-name { flex: 1; }
.cat-count {
  font-size: 11.5px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.cat-row.active .cat-count { color: var(--accent-hover); }

.cat-clear {
  font-size: 12px;
  color: var(--text-muted);
  padding: 6px 8px;
  margin-top: 4px;
}
.cat-clear:hover { color: var(--accent); }

/* ——— Plot area ——— */
.plot-area {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}
.plot-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-wrap: wrap;
}
.axis-control {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-3);
}
.axis-control label {
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 11px;
}
.axis-control select {
  height: 28px;
  padding: 0 24px 0 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  font-size: 13px;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='%23999' d='M0 0l5 6 5-6z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
  cursor: pointer;
  transition: border-color 0.12s;
}
.axis-control select:hover { border-color: var(--border-strong); }
.axis-control select:focus { outline: none; border-color: var(--accent); }

.plot-canvas {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 0;
}
.plot-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.grid-line { stroke: var(--border); stroke-width: 1; }
.grid-line.major { stroke: var(--border-strong); }
.axis-label {
  font-family: var(--font);
  font-size: 11px;
  fill: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.axis-title {
  font-family: var(--font);
  font-size: 12px;
  fill: var(--text-3);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.game-dot {
  cursor: pointer;
  transition: r 0.12s ease, stroke-width 0.12s;
}
.game-dot:hover {
  stroke: var(--text);
  stroke-width: 1.5;
}
.game-dot.selected {
  stroke: var(--accent);
  stroke-width: 2.5;
}
.game-dot.dim { opacity: 0.12; }
.game-label {
  font-family: var(--font);
  font-size: 10.5px;
  fill: var(--text-2);
  pointer-events: none;
  text-anchor: middle;
}

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--text);
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  transform: translate(-50%, -100%);
  margin-top: -8px;
  opacity: 0;
  transition: opacity 0.1s;
  box-shadow: var(--shadow-lift);
}
.tooltip.visible { opacity: 1; }
.tooltip-cat {
  font-size: 11px;
  opacity: 0.7;
  font-weight: 400;
  margin-top: 2px;
}

/* ——— Detail panel ——— */
.detail {
  border-left: 1px solid var(--border);
  background: var(--bg);
  overflow-y: auto;
  padding: 24px;
}
.detail-empty {
  color: var(--text-muted);
  font-size: 13.5px;
  line-height: 1.6;
  margin-top: 80px;
  text-align: center;
}
.detail-empty-icon {
  font-size: 24px;
  margin-bottom: 12px;
  color: var(--border-strong);
}
.detail-cat-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 8px;
}
.detail-cat-dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
}
.detail-name {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-bottom: 6px;
}
.detail-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
}
.detail-desc {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-2);
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}
.stat {
  background: var(--surface);
  padding: 10px 12px;
  border-radius: 6px;
}
.stat-label {
  font-size: 10.5px;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
  margin-bottom: 2px;
}
.stat-value {
  font-size: 15px;
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.bar-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.bar-row {
  display: grid;
  grid-template-columns: 90px 1fr 20px;
  gap: 10px;
  align-items: center;
  font-size: 12px;
}
.bar-row-label {
  color: var(--text-3);
  font-weight: 500;
}
.bar-track {
  height: 6px;
  background: #eeeeee;
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}
.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.2s;
}
.bar-row-value {
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
}
.bar-poles {
  display: grid;
  grid-template-columns: 90px 1fr 20px;
  gap: 10px;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: -6px;
}
.bar-poles .poles {
  display: flex;
  justify-content: space-between;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ——— Grid view ——— */
.grid-view {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px 60px;
}
.grid-section {
  margin-bottom: 40px;
}
.grid-section-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.grid-section-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}
.grid-section-count {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.grid-section-bar {
  width: 4px;
  height: 18px;
  border-radius: 2px;
  align-self: center;
}
.game-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.game-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s, transform 0.08s;
  display: flex;
  flex-direction: column;
  min-height: 80px;
}
.game-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow);
}
.game-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.game-card-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
  letter-spacing: -0.01em;
}
.game-card-meta {
  font-size: 11.5px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  margin-top: auto;
}
.game-card-sub {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 500;
}

/* ——— Scrollbar styling ——— */
.sidebar::-webkit-scrollbar,
.detail::-webkit-scrollbar,
.grid-view::-webkit-scrollbar {
  width: 8px;
}
.sidebar::-webkit-scrollbar-thumb,
.detail::-webkit-scrollbar-thumb,
.grid-view::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
.sidebar::-webkit-scrollbar-track,
.detail::-webkit-scrollbar-track,
.grid-view::-webkit-scrollbar-track {
  background: transparent;
}

/* Responsive */
@media (max-width: 1100px) {
  .main { grid-template-columns: 220px 1fr 300px; }
}
@media (max-width: 900px) {
  .main { grid-template-columns: 200px 1fr; }
  .detail { display: none; }
}
