:root {
  color-scheme: dark;
  --bg: #070908;
  --side: #0b0e0c;
  --surface: #111412;
  --surface-2: #171c19;
  --surface-3: #1f2621;
  --border: rgba(255, 255, 255, 0.07);
  --border-2: rgba(255, 255, 255, 0.12);
  --text: #f1f5f2;
  --text-2: #b4beb8;
  --muted: #7c8781;
  --grid: #1f2622;
  --accent: #2fd27a;
  --accent-ink: #04140b;
  --accent-soft: rgba(47, 210, 122, 0.12);
  --s1: #1fa463;
  --s2: #3987e5;
  --s3: #d95926;
  --s4: #9085e9;
  --s5: #c98500;
  --up: #2fd27a;
  --down: #ef6b6b;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
a { color: inherit; }
code { background: var(--surface-3); padding: 1px 6px; border-radius: 5px; font-size: 12px; }

.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }

/* ---------- sidebar */
.sidebar {
  background: var(--side); border-right: 1px solid var(--border);
  padding: 22px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 22px;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 0 8px; }
.brand strong { display: block; font-size: 15px; }
.brand small { color: var(--muted); font-size: 11.5px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); flex: none;
}
.nav { display: flex; flex-direction: column; gap: 3px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 10px;
  text-decoration: none; color: var(--text-2); font-weight: 500; transition: background .15s, color .15s;
}
.nav a svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.on { background: var(--accent-soft); color: var(--accent); }
.side-note { margin-top: auto; color: var(--muted); font-size: 12px; padding: 0 8px; }

/* ---------- main */
.main { padding: 26px 30px 40px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.topbar h1 { font-size: 24px; }
.sub { margin: 4px 0 0; color: var(--muted); }
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.presets, .seg, .chips { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--border); padding: 4px; border-radius: 11px; flex-wrap: wrap; }
.presets button, .seg button, .chips button {
  background: transparent; border: 0; color: var(--text-2); font: inherit; font-size: 13px; font-weight: 500;
  padding: 6px 11px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.presets button:hover, .seg button:hover, .chips button:hover { color: var(--text); background: var(--surface-2); }
.presets button.on, .seg button.on, .chips button.on { background: var(--accent); color: var(--accent-ink); }
.chips { background: transparent; border: 0; padding: 0; margin-bottom: 12px; gap: 6px; }
.chips button { border: 1px solid var(--border-2); }
.sel { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
select, input[type="search"] {
  background: var(--surface); color: var(--text); border: 1px solid var(--border-2); border-radius: 9px;
  padding: 7px 10px; font: inherit; font-size: 13px;
}
select:focus, input:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.sec { display: flex; flex-direction: column; gap: 16px; }
.sec[hidden] { display: none; }
.grid { display: grid; gap: 16px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; min-width: 0; }
.card-h { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.card-h h3 { font-size: 14.5px; }
.hint { color: var(--muted); font-size: 12px; }
.link { color: var(--accent); text-decoration: none; font-size: 12.5px; font-weight: 500; }
.chart { position: relative; }
.h-240 { height: 240px; } .h-260 { height: 260px; } .h-300 { height: 300px; } .h-320 { height: 320px; }
.h-340 { height: 340px; } .h-420 { height: 420px; }

/* ---------- KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 16px 14px; position: relative; overflow: hidden; }
.kpi:first-child { background: linear-gradient(150deg, #0f3a24 0%, var(--surface) 75%); border-color: rgba(47, 210, 122, 0.25); }
.kpi .lbl { color: var(--text-2); font-size: 12.5px; font-weight: 500; }
.kpi .val { font-size: 23px; font-weight: 700; margin-top: 6px; letter-spacing: -0.02em; white-space: nowrap; }
.kpi .foot { margin-top: 4px; font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.delta { font-weight: 600; }
.delta.up { color: var(--up); } .delta.down { color: var(--down); }

/* ---------- mini ranking */
.minirank { display: flex; flex-direction: column; gap: 11px; }
.mr-row { display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; align-items: center; }
.mr-pos { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.mr-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mr-bar { height: 4px; background: var(--surface-3); border-radius: 4px; margin-top: 5px; overflow: hidden; }
.mr-bar span { display: block; height: 100%; background: var(--s1); border-radius: 4px; }
.mr-val { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- ABC */
.abc { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.abc div { background: var(--surface-2); border-radius: 10px; padding: 10px; }
.abc b { display: block; font-size: 18px; }
.abc span { color: var(--muted); font-size: 11.5px; }
.abc .cls { color: var(--accent); font-weight: 700; font-size: 12px; }

/* ---------- CFOP */
.split { display: flex; height: 14px; border-radius: 7px; overflow: hidden; gap: 2px; margin: 6px 0 16px; }
.split span { display: block; height: 100%; }
.legend-rows { display: flex; flex-direction: column; gap: 12px; }
.lr { display: grid; grid-template-columns: 12px 1fr auto; gap: 10px; align-items: start; }
.lr i { width: 12px; height: 12px; border-radius: 3px; margin-top: 3px; }
.lr b { display: block; }
.lr small { color: var(--muted); }
.lr .v { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- heatmap */
.heat { display: grid; gap: 3px; font-size: 11px; overflow-x: auto; }
.heat .hl { color: var(--muted); display: flex; align-items: center; }
.heat .hh { color: var(--muted); text-align: center; }
.heat .c { height: 30px; border-radius: 4px; min-width: 18px; cursor: default; }
.heat-scale { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11.5px; margin-top: 12px; }
.heat-scale .ramp { width: 140px; height: 8px; border-radius: 4px; }

/* ---------- tables */
.tbl-tools { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 10px; flex-wrap: wrap; }
.tbl-tools input { min-width: 240px; }
.tbl-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 12px; text-align: left; white-space: nowrap; }
th { background: var(--surface-2); color: var(--text-2); font-weight: 600; font-size: 12px; position: sticky; top: 0; cursor: pointer; user-select: none; }
th:hover { color: var(--text); }
th.sorted { color: var(--accent); }
td { border-top: 1px solid var(--border); font-variant-numeric: tabular-nums; }
td.num, th.num { text-align: right; }
td.wrap { white-space: normal; min-width: 220px; }
tbody tr:hover td { background: rgba(255, 255, 255, 0.025); }
tbody tr.click { cursor: pointer; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; color: var(--muted); font-size: 12.5px; }
.btn {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border-2); border-radius: 8px;
  padding: 6px 11px; font: inherit; font-size: 12.5px; cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.acc { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 20px; font-size: 11.5px; font-weight: 600; }
.tag.a { background: var(--accent-soft); color: var(--accent); }
.tag.b { background: rgba(57, 135, 229, .15); color: #7fb2f0; }
.tag.c { background: rgba(255, 255, 255, .07); color: var(--text-2); }
.tag.off { background: rgba(255, 255, 255, .06); color: var(--muted); }
.neg { color: var(--down); }
.pos { color: var(--up); }
.muted { color: var(--muted); }

/* ---------- modal & tooltip */
dialog {
  background: var(--surface); color: var(--text); border: 1px solid var(--border-2); border-radius: 16px;
  padding: 20px; width: min(980px, calc(100vw - 32px)); max-height: 85vh;
}
dialog::backdrop { background: rgba(0, 0, 0, .7); }
.modal-h { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 10px; }
.modal-meta { display: flex; gap: 18px; flex-wrap: wrap; color: var(--text-2); font-size: 12.5px; margin-bottom: 14px; }
.modal-meta b { color: var(--text); }
.x { background: var(--surface-2); color: var(--text); border: 0; width: 32px; height: 32px; border-radius: 8px; cursor: pointer; }
.tip {
  position: fixed; pointer-events: none; z-index: 50; background: #050605; border: 1px solid var(--border-2);
  border-radius: 8px; padding: 7px 10px; font-size: 12px; opacity: 0; transition: opacity .1s; white-space: nowrap;
}
.tip.show { opacity: 1; }

.foot { margin-top: 28px; color: var(--muted); font-size: 12px; }
.empty { color: var(--muted); padding: 20px; text-align: center; }

/* ---------- responsive */
@media (max-width: 1150px) {
  .g-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-2-1 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar, .nav { min-width: 0; }
  .filters { width: 100%; }
  .sidebar { position: sticky; height: auto; z-index: 10; padding: 12px 16px; gap: 10px; }
  .side-note { display: none; }
  .nav { flex-direction: row; overflow-x: auto; scrollbar-width: none; }
  .nav a { white-space: nowrap; padding: 8px 10px; }
  .main { padding: 18px 16px 30px; }
  .g-2, .g-3 { grid-template-columns: 1fr; }
  .tbl-tools input { min-width: 0; width: 100%; }
}
