:root {
  --paper: #eef1f6;
  --panel: #ffffff;
  --ink: #14213d;
  --muted: #5b6785;
  --line: #d5dbe7;
  --accent: #2f4fd1;
  --rise: #0b8a6c;
  --fall: #b4235a;
  --flat: #8a93ab;
  --display: 'Bricolage Grotesque', system-ui, sans-serif;
  --body: 'Public Sans', system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0e1527; --panel: #151e35; --ink: #e6ebf7; --muted: #94a0bf; --line: #27324f;
    --accent: #7d97ff; --rise: #34c79f; --fall: #ff6f9c; --flat: #6c7594; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0e1527; --panel: #151e35; --ink: #e6ebf7; --muted: #94a0bf; --line: #27324f;
  --accent: #7d97ff; --rise: #34c79f; --fall: #ff6f9c; --flat: #6c7594; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 15px/1.5 var(--body); font-variant-numeric: tabular-nums;
}
h1, h2, h3 { font-family: var(--display); line-height: 1.1; margin: 0; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 24px;
  padding: 12px 24px; background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font: 800 18px var(--display); }
.mark { width: 18px; height: 18px; background: var(--accent); transform: rotate(14deg); border-radius: 3px; }
.tabs { display: flex; gap: 2px; overflow-x: auto; }
.tabs button {
  border: 0; background: none; padding: 6px 12px; border-radius: 6px; cursor: pointer; color: var(--muted); font-weight: 600;
}
.tabs button[aria-selected="true"] { background: var(--ink); color: var(--paper); }
.status { margin: 0 0 0 auto; color: var(--muted); font-size: 13px; }

main { padding: 28px 24px 80px; max-width: 1400px; margin: 0 auto; }

/* ---------- hero / niche map ---------- */
.intro { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px 40px; align-items: end; margin-bottom: 18px; }
.intro h1 { font-size: clamp(30px, 4.2vw, 52px); font-weight: 800; letter-spacing: -0.02em; max-width: 18ch; }
.intro p { margin: 8px 0 0; color: var(--muted); max-width: 60ch; }
.legend { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.legend .ramp { width: 160px; height: 10px; border-radius: 5px; background: linear-gradient(90deg, var(--fall), var(--flat), var(--rise)); }

.map { position: relative; width: 100%; height: min(62vh, 620px); min-height: 360px; border-radius: 10px; overflow: hidden; background: var(--line); }
.tile {
  position: absolute; padding: 8px 10px; color: #fff; overflow: hidden; cursor: pointer; border: 1px solid var(--paper);
  display: flex; flex-direction: column; justify-content: space-between; text-align: left; transition: filter .12s;
}
.tile:hover, .tile:focus-visible { filter: brightness(1.12); z-index: 1; }
.tile .t-name { font: 700 clamp(12px, 1.2vw, 17px)/1.15 var(--display); }
.tile .t-genre { font-size: 11px; opacity: .8; }
.tile .t-num { font: 800 clamp(14px, 1.8vw, 26px)/1 var(--display); }
.tile .t-sub { font-size: 11px; opacity: .85; }
.tile.small .t-genre, .tile.small .t-sub { display: none; }
.tile.tiny > * { display: none; }

/* ---------- tables ---------- */
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 16px; margin: 40px 0 12px; }
.section-head h2 { font-size: 24px; font-weight: 700; }
.section-head p { margin: 0; color: var(--muted); font-size: 14px; max-width: 75ch; }

.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 8px 12px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child, th.l, td.l { text-align: left; }
tbody tr:last-child td { border-bottom: 0; }
th { position: sticky; top: 0; background: var(--panel); font-weight: 600; color: var(--muted); font-size: 13px; cursor: pointer; user-select: none; }
th[aria-sort="descending"]::after { content: ' ↓'; color: var(--ink); }
th[aria-sort="ascending"]::after { content: ' ↑'; color: var(--ink); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.gname { display: flex; align-items: center; gap: 10px; max-width: 340px; }
.gname img { width: 32px; height: 32px; border-radius: 6px; flex: none; background: var(--line); }
.gname span { overflow: hidden; text-overflow: ellipsis; }
.gname small { display: block; color: var(--muted); font-size: 12px; }
.up { color: var(--rise); font-weight: 600; }
.down { color: var(--fall); font-weight: 600; }
.dim { color: var(--muted); }
.score { display: inline-block; min-width: 38px; padding: 1px 6px; border-radius: 5px; font-weight: 700; text-align: center; color: #fff; }
.pill { display: inline-block; padding: 0 7px; border-radius: 99px; font-size: 12px; border: 1px solid var(--line); color: var(--muted); }
.pill.active { border-color: var(--rise); color: var(--rise); }
.pill.warn { border-color: var(--fall); color: var(--fall); }

/* ---------- filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 14px; }
.filters label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.filters input, .filters select {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); min-width: 130px;
}
.filters input[type="search"] { min-width: 220px; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-top: 12px; color: var(--muted); font-size: 14px; }
.pager button, .btn {
  padding: 6px 12px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); cursor: pointer;
}
.pager button:disabled { opacity: .4; cursor: default; }

.note {
  background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: 8px; padding: 12px 16px; margin-bottom: 18px; max-width: 90ch; font-size: 14px;
}
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- drawer ---------- */
.scrim { position: fixed; inset: 0; background: rgb(10 15 30 / .35); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 9; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(620px, 100vw); z-index: 10; background: var(--panel);
  border-left: 1px solid var(--line); overflow-y: auto; padding: 24px; transform: translateX(100%); transition: transform .22s ease;
}
.drawer.open { transform: none; }
.drawer.open + .scrim { opacity: 1; pointer-events: auto; }
.close { position: absolute; top: 12px; right: 14px; border: 0; background: none; font-size: 28px; cursor: pointer; color: var(--muted); }
.d-head { display: flex; gap: 14px; align-items: center; margin-right: 30px; }
.d-head img { width: 72px; height: 72px; border-radius: 12px; background: var(--line); }
.d-head h2 { font-size: 24px; }
.d-head p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 14px 18px; margin: 22px 0; }
.stats div { border-top: 1px solid var(--line); padding-top: 6px; }
.stats dt { font-size: 12px; color: var(--muted); }
.stats dd { margin: 0; font: 700 19px var(--display); }
.chart { width: 100%; height: 180px; display: block; }
.chart .grid { stroke: var(--line); }
.chart .lineP { fill: none; stroke: var(--accent); stroke-width: 2; }
.chart .area { fill: color-mix(in srgb, var(--accent) 14%, transparent); }
.chart text { fill: var(--muted); font-size: 11px; }
.drawer h3 { font-size: 16px; margin: 22px 0 8px; }
.drawer .actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }

@media (max-width: 720px) {
  .top { padding: 10px 16px; }
  .status { width: 100%; margin: 0; }
  main { padding: 20px 16px 60px; }
  .intro { grid-template-columns: 1fr; }
  .map { height: 70vh; }
  .filters input[type="search"] { min-width: 0; width: 100%; }
  .filters label { flex: 1 1 140px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
