:root {
  color-scheme: dark;
  --bg: #000;
  --bg-panel: rgba(17, 17, 17, 0.92);
  --bg-panel-deep: #0a0a20;
  --bg-header: #222;
  --bg-nav: #555;
  --border: #446;
  --border-strong: #333;
  --border-table: #7788aa;
  --border-cell: rgba(0, 0, 0, 0.18);
  --text: #eef;
  --text-soft: #ccddee;
  --muted: #aab;
  --muted-dim: #88a;
  --accent: #667799;
  --accent-hover: #778899;
  --accent-link: #aaccff;
  --accent-stat: #aaddff;
  --font-display: "Handel Gothic BT", "HandelGothic", "Handel Gothic", sans-serif;
  --font-body: "Montserrat", system-ui, sans-serif;
  --font-condensed: "Roboto Condensed", "Arial Narrow", "Liberation Sans Narrow", sans-serif;
  --pie-0: #667799;
  --pie-1: #556688;
  --pie-2: #7888aa;
  --pie-3: #4a5870;
  --pie-4: #8090b0;
  --pie-5: #5a6888;
  --pie-6: #8a9ab8;
  --pie-7: #607090;
  --pie-8: #6e829e;
  --pie-9: #7286a4;
  /* Tachi BMS lamp colours (COLOUR_SET @ 20% opacity) */
  --lamp-no-play-bg: rgba(105, 105, 105, 0.2);
  --lamp-failed-bg: rgba(170, 85, 85, 0.2);
  --lamp-assist-clear-bg: rgba(153, 50, 204, 0.2);
  --lamp-easy-clear-bg: rgba(50, 205, 50, 0.2);
  --lamp-clear-bg: rgba(70, 130, 180, 0.2);
  --lamp-hard-clear-bg: rgba(248, 148, 6, 0.2);
  --lamp-ex-hard-clear-bg: rgba(255, 215, 0, 0.2);
  --lamp-full-combo-bg: rgba(127, 255, 212, 0.2);
}

* { box-sizing: border-box; }

html {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  font-family: var(--font-body);
  font-weight: 500;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

.site-header {
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
  padding: 1rem 1.75rem;
  border-bottom: 3px solid var(--border-strong);
  background: var(--bg-header);
}

h1 {
  margin: 0 0 .35rem;
  font-family: var(--font-body);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--text);
}

.subtitle {
  margin: 0;
  color: var(--muted-dim);
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.header-level {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex: 0 0 auto;
  padding: 0.35rem;
  background: var(--bg-nav);
  border: 3px solid var(--border-strong);
}

.header-level select {
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text);
  background: #111;
  border: 1px solid var(--accent);
  padding: 0.32rem 0.55rem;
  border-radius: 0;
  outline: none;
  cursor: pointer;
  min-width: 6.5rem;
  max-width: min(16rem, 42vw);
}

.header-level select:hover,
.header-level select:focus {
  border-color: var(--border-table);
  background: #1a1a2a;
}

.table-toolbar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.65rem;
  margin-bottom: 0.65rem;
  flex-shrink: 0;
}

.toolbar-primary {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
}

.toolbar-filters-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  flex: 0 0 auto;
  min-height: 2.05rem;
  padding: 0.35rem 0.65rem;
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text);
  background: #111;
  border: 1px solid var(--accent);
  cursor: pointer;
}

.toolbar-filters-toggle-label {
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.toolbar-filters-summary {
  display: none;
  font-size: 0.66rem;
  font-weight: 500;
  color: var(--muted);
  max-width: 8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar-filters-panel {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  min-height: 2.05rem;
}

.toolbar-filters-panel-header {
  display: none;
}

.toolbar-filters-close {
  display: none;
}

.mobile-stats-fab {
  display: none;
}

.toolbar-label {
  font-family: var(--font-display);
  font-size: 0.76rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted-dim);
}

.toolbar-filter {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}

.toolbar-filter input {
  accent-color: var(--accent);
  cursor: pointer;
}

.toolbar-filter:hover {
  color: var(--text);
}

.toolbar-group-filter {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin-left: auto;
  flex-wrap: wrap;
}

.toolbar-radio {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.toolbar-radio input {
  accent-color: var(--accent);
  cursor: pointer;
}

.toolbar-radio:hover {
  color: var(--text);
}

.toolbar-search {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex: 1 1 11rem;
  min-width: 0;
  max-width: 16rem;
}

.toolbar-search input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text);
  background: #111;
  border: 1px solid var(--accent);
  padding: 0.32rem 0.55rem;
  border-radius: 0;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

.toolbar-search input::placeholder {
  color: var(--muted-dim);
  opacity: 0.85;
}

.toolbar-search input:hover {
  border-color: var(--border-table);
  background: #1a1a2a;
}

.toolbar-search input:focus {
  border-color: var(--border-table);
  background: #1a1a2a;
}

.toolbar-search input::-webkit-search-cancel-button {
  cursor: pointer;
}

.toolbar-table {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex: 0 0 auto;
}

.toolbar-table select {
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text);
  background: #111;
  border: 1px solid var(--accent);
  padding: 0.32rem 0.55rem;
  border-radius: 0;
  outline: none;
  cursor: pointer;
  min-width: 6.5rem;
}

.toolbar-table select:hover,
.toolbar-table select:focus {
  border-color: var(--border-table);
  background: #1a1a2a;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 240px;
  grid-template-rows: 1fr;
  align-items: stretch;
  gap: 1.25rem;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding: 1.25rem 1.75rem 1rem;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

.table-panel,
.stats-panel {
  background: var(--bg-panel);
  border: 2px solid var(--border);
  border-radius: 0;
  padding: 0.85rem;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.table-panel {
  display: flex;
  flex-direction: column;
}

.stats-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-panel-deep);
}

.stats-panel h2 {
  margin: 0 0 0.65rem;
  flex-shrink: 0;
  min-height: 2.05rem;
  display: flex;
  align-items: flex-end;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 400;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-soft);
  padding-bottom: 0.35rem;
  border-bottom: 1px solid #555;
}

.stats-player-viz {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  gap: 0.65rem;
}

.stats-table-wrap {
  flex: 0 1 auto;
  max-height: 50%;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  border: 1px solid var(--border-table);
  -webkit-overflow-scrolling: touch;
}

.stats-table-wrap table.stats-table {
  margin: 0;
}

.table-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border-radius: 0;
  border: 1px solid var(--border-table);
  -webkit-overflow-scrolling: touch;
  line-height: 0;
}

/* ── Main leaderboard table ── */
table.leaderboard {
  width: calc(100% + 2px);
  max-width: calc(100% + 2px);
  margin: -1px;
  border-collapse: collapse;
  font-size: 0.82rem;
  table-layout: fixed;
  line-height: 1.4;
}

table.leaderboard .score-cell {
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 0.04rem;
  line-height: 1.1;
  vertical-align: middle;
}

table.leaderboard .score-main {
  font-weight: 700;
}

table.leaderboard .score-pct {
  font-size: 0.68em;
  font-weight: 500;
  opacity: 0.75;
  white-space: nowrap;
}

table.leaderboard col.col-title  { width: 48%; }
table.leaderboard col.col-star   { width: 4%; }
table.leaderboard col.col-player { width: 11%; }
table.leaderboard col.col-score-stack { width: 7%; }
table.leaderboard col.col-bp     { width: 3.5%; }
table.leaderboard col.col-lamp   { width: 9%; }
table.leaderboard col.col-date-stack { width: 10%; }

table.leaderboard th,
table.leaderboard td {
  padding: 0.55rem 0.65rem;
  vertical-align: middle;
}

table.leaderboard thead th {
  position: sticky;
  top: -1px;
  z-index: 2;
  background: var(--accent);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
  border: 1px solid var(--border-table);
  white-space: nowrap;
}

table.leaderboard thead th.col-title {
  text-align: left;
  padding-left: 0.85rem;
  border-left: none;
  border-top: none;
}

table.leaderboard thead th.col-date-stack {
  border-right: none;
  border-top: none;
}

table.leaderboard thead th:not(.col-title):not(.col-date-stack) {
  border-top: none;
}

table.leaderboard tbody td {
  text-align: center;
  font-variant-numeric: tabular-nums;
  min-height: 2.55rem;
  height: 2.55rem;
  max-height: none;
  overflow: hidden;
  padding-top: 0.38rem;
  padding-bottom: 0.42rem;
  border: 1px solid var(--border-cell);
  vertical-align: middle;
}

table.leaderboard tbody td.col-star,
table.leaderboard tbody td.col-player,
table.leaderboard tbody td.col-score-stack,
table.leaderboard tbody td.col-bp,
table.leaderboard tbody td.col-lamp,
table.leaderboard tbody td.col-date-stack {
  text-align: center;
}

table.leaderboard tbody tr:has(.title-artist-wraps) td {
  height: auto;
  min-height: 2.55rem;
}

table.leaderboard tbody td.col-title {
  text-align: left;
  padding-left: 0.85rem;
  padding-right: 0.45rem;
  padding-bottom: 0.44rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  overflow: visible;
  cursor: pointer;
}

table.leaderboard tbody td.col-title:hover {
  background: rgba(255, 255, 255, 0.06);
}

table.leaderboard .title-cell {
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: visible;
  line-height: 1.2;
}

table.leaderboard .title-cell.has-subline .title-main {
  display: block;
  -webkit-line-clamp: unset;
  -webkit-box-orient: unset;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.25;
}

table.leaderboard .title-cell.has-subline {
  gap: 0.06rem;
}

table.leaderboard .title-subline {
  display: flex;
  flex-direction: row;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.35rem;
  min-width: 0;
}

table.leaderboard .title-subline.has-artist {
  gap: 0.4rem;
}

table.leaderboard .title-artist {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  text-align: right;
  font-family: var(--font-condensed);
  font-size: 0.82em;
  font-weight: 500;
  font-style: italic;
  font-stretch: condensed;
  opacity: 0.82;
  line-height: 1.1;
}

table.leaderboard .title-artist-text {
  display: inline-block;
  max-width: 100%;
  transform-origin: 100% 50%;
  white-space: nowrap;
}

table.leaderboard tbody tr.title-artist-wraps .title-artist-text {
  white-space: normal;
  word-break: break-word;
  overflow-wrap: break-word;
}

table.leaderboard .title-main {
  line-height: 1.25;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

table.leaderboard .title-ascii {
  font-family: ui-monospace, "Cascadia Mono", "SF Mono", "Consolas", "Liberation Mono", monospace;
  flex: 0 1 auto;
  max-width: 42%;
  min-width: 0;
  font-size: 0.66em;
  font-weight: 500;
  opacity: 0.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.1;
}

table.leaderboard .title-subtitle {
  flex: 0 1 auto;
  max-width: 42%;
  min-width: 0;
  font-size: 0.66em;
  font-weight: 500;
  opacity: 0.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.1;
}

table.leaderboard tbody td.col-date-stack {
  white-space: nowrap;
  font-size: 0.72rem;
}

table.leaderboard tbody td.col-star,
table.leaderboard thead th.col-star {
  padding-left: 0.2rem;
  padding-right: 0.2rem;
  font-size: 0.72rem;
  letter-spacing: 0;
  font-weight: 700;
}

table.leaderboard tbody td.col-lamp,
table.leaderboard thead th.col-lamp {
  padding-left: 0.25rem;
  padding-right: 0.25rem;
  font-size: 0.62rem;
  letter-spacing: 0;
  white-space: nowrap;
}

table.leaderboard thead th.col-star,
table.leaderboard thead th.col-bp,
table.leaderboard thead th.col-lamp,
table.leaderboard thead th.col-score-stack {
  font-size: 0.66rem;
  letter-spacing: 0.04em;
  padding-top: 0.45rem;
  padding-bottom: 0.45rem;
}

table.leaderboard thead th.col-star,
table.leaderboard thead th.col-title,
table.leaderboard thead th.col-player,
table.leaderboard thead th.col-score-stack,
table.leaderboard thead th.col-date-stack {
  padding: 0;
}

.th-sort {
  all: unset;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 0.55rem 0.65rem;
  cursor: pointer;
}

table.leaderboard thead th.col-title .th-sort {
  justify-content: flex-start;
  padding-left: 0.85rem;
}

table.leaderboard thead th.col-star .th-sort {
  padding: 0.45rem 0.2rem;
}

table.leaderboard thead th.col-score-stack .th-sort {
  padding-top: 0.45rem;
  padding-bottom: 0.45rem;
}

.th-sort:hover,
.th-sort.active {
  color: var(--accent-link);
}

.sort-arrow {
  display: inline-block;
  width: 0;
  overflow: hidden;
  font-size: 0.85em;
}

.sort-arrow::before {
  content: "▾";
}

.th-sort.active .sort-arrow {
  width: 0.85em;
  margin-left: 0.2em;
}

.th-sort.active.reversed .sort-arrow::before {
  content: "▴";
}

.test-status.is-hidden {
  display: none;
}

table.leaderboard tbody td.col-score-stack {
  padding-left: 0.3rem;
  padding-right: 0.3rem;
}

table.leaderboard tbody td.col-player {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

/* Tachi BMS lamp cell backgrounds — title + star stay neutral */
table.leaderboard tbody tr[data-lamp="no-play"] td:not(.col-title):not(.col-star) {
  background-color: var(--lamp-no-play-bg);
}

table.leaderboard tbody tr[data-lamp="failed"] td:not(.col-title):not(.col-star) {
  background-color: var(--lamp-failed-bg);
}

table.leaderboard tbody tr[data-lamp="assist-clear"] td:not(.col-title):not(.col-star) {
  background-color: var(--lamp-assist-clear-bg);
}

table.leaderboard tbody tr[data-lamp="easy-clear"] td:not(.col-title):not(.col-star) {
  background-color: var(--lamp-easy-clear-bg);
}

table.leaderboard tbody tr[data-lamp="clear"] td:not(.col-title):not(.col-star) {
  background-color: var(--lamp-clear-bg);
}

table.leaderboard tbody tr[data-lamp="hard-clear"] td:not(.col-title):not(.col-star) {
  background-color: var(--lamp-hard-clear-bg);
}

table.leaderboard tbody tr[data-lamp="ex-hard-clear"] td:not(.col-title):not(.col-star) {
  background-color: var(--lamp-ex-hard-clear-bg);
}

table.leaderboard tbody tr[data-lamp="full-combo"] td:not(.col-title):not(.col-star) {
  background-color: var(--lamp-full-combo-bg);
}

tr.lamp-low-priority td:not(.col-title):not(.col-star) {
  opacity: 0.42;
  color: var(--muted);
}

tr.lamp-low-priority .title-artist {
  opacity: 0.75;
}

tr.lamp-low-priority .score-pct {
  opacity: 0.85;
}

/* Chart score modal */
body.modal-open,
body.chart-modal-open,
body.stats-modal-open,
body.filters-modal-open {
  overflow: hidden;
}

.chart-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}

.chart-modal.is-open {
  display: flex;
}

.chart-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 10, 18, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.chart-modal-island {
  position: relative;
  z-index: 1;
  width: min(34rem, calc(100vw - 2rem));
  max-height: min(70vh, 32rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(28, 32, 44, 0.98), rgba(18, 20, 30, 0.98));
  border: 1px solid var(--border-table);
  box-shadow:
    0 24px 64px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(255, 255, 255, 0.04) inset;
  padding: 0;
}

.chart-modal-body {
  flex: 1 1 auto;
  overflow: auto;
  padding: 0 0.95rem 0.95rem;
}

#chart-modal .chart-modal-header {
  position: sticky;
  top: 0;
  z-index: 2;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: stretch;
  gap: 0.45rem;
  margin-bottom: 0;
  padding: 0.85rem 0.95rem 0.5rem;
  background: linear-gradient(180deg, rgba(28, 32, 44, 0.99), rgba(24, 28, 40, 0.96));
}

.chart-modal-header {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
}

.chart-modal-title {
  flex: 1;
  min-width: 0;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.35;
}

.chart-modal-header-row {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
}

.chart-modal-close {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border: 1px solid var(--border-table);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.chart-modal-close:hover,
.chart-modal-close:focus-visible {
  background: rgba(255, 255, 255, 0.14);
}

.stats-modal-island {
  width: min(22rem, calc(100vw - 1.5rem));
  max-height: min(82vh, 36rem);
  display: flex;
  flex-direction: column;
  padding: 0.85rem 0.95rem 0.95rem;
}

.stats-modal-body {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  min-height: 0;
  flex: 1;
}

.stats-modal-body .stats-player-viz {
  flex: 1;
  min-height: 0;
}

.stats-modal-body .stats-table-wrap {
  max-height: 50%;
}

.stats-modal-body .player-pie-wrap {
  min-height: 8rem;
}

.stats-modal-body .test-status {
  margin-top: 0;
}

.chart-modal-empty {
  font-size: 0.78rem;
  color: var(--muted);
  padding: 0.35rem 0.1rem;
}

table.chart-modal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.68rem;
  table-layout: auto;
}

table.chart-modal-table th,
table.chart-modal-table td {
  padding: 0.22rem 0.35rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
}

table.chart-modal-table thead th {
  font-family: var(--font-display);
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  font-weight: 500;
}

table.chart-modal-table tbody td:first-child {
  text-align: left;
  font-weight: 600;
  max-width: 8rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

table.chart-modal-table tbody tr.chart-modal-best {
  outline: 1px solid rgba(170, 221, 255, 0.45);
  outline-offset: -1px;
}

table.chart-modal-table .modal-score-main {
  font-weight: 700;
}

table.chart-modal-table .modal-score-pct {
  display: block;
  font-size: 0.92em;
  opacity: 0.72;
  font-weight: 500;
}

table.chart-modal-table tbody tr[data-lamp="no-play"] td:not(:first-child) {
  background: var(--lamp-no-play-bg);
}

table.chart-modal-table tbody tr[data-lamp="failed"] td:not(:first-child) {
  background: var(--lamp-failed-bg);
}

table.chart-modal-table tbody tr[data-lamp="assist-clear"] td:not(:first-child) {
  background: var(--lamp-assist-clear-bg);
}

table.chart-modal-table tbody tr[data-lamp="easy-clear"] td:not(:first-child) {
  background: var(--lamp-easy-clear-bg);
}

table.chart-modal-table tbody tr[data-lamp="clear"] td:not(:first-child) {
  background: var(--lamp-clear-bg);
}

table.chart-modal-table tbody tr[data-lamp="hard-clear"] td:not(:first-child) {
  background: var(--lamp-hard-clear-bg);
}

table.chart-modal-table tbody tr[data-lamp="ex-hard-clear"] td:not(:first-child) {
  background: var(--lamp-ex-hard-clear-bg);
}

table.chart-modal-table tbody tr[data-lamp="full-combo"] td:not(:first-child) {
  background: var(--lamp-full-combo-bg);
}

/* ── Stats sidebar ── */
table.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

table.stats-table th,
table.stats-table td {
  padding: 0.52rem 0.6rem;
  text-align: center;
  vertical-align: middle;
  border: 1px solid var(--border-table);
  line-height: 1.25;
}

table.stats-table th {
  font-family: var(--font-display);
  font-size: 0.76rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text);
  font-weight: 400;
  background: var(--accent);
  position: sticky;
  top: 0;
  z-index: 1;
}

table.stats-table tbody tr {
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  transition: background 0.05s;
}

table.stats-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.12);
}

table.stats-table tbody tr.player-filter-active {
  background: rgba(102, 119, 153, 0.35);
}

table.stats-table tbody tr.player-filter-active:hover {
  background: rgba(102, 119, 153, 0.45);
}

table.stats-table tbody tr:nth-child(even):not(.player-filter-active) {
  background: rgba(255, 255, 255, 0.07);
}

table.stats-table tbody tr:nth-child(even).player-filter-active {
  background: rgba(102, 119, 153, 0.35);
}

table.stats-table td:first-child {
  text-align: left;
  font-weight: 600;
}

table.stats-table .player-cell {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0;
}

table.stats-table .player-cell.has-subline {
  gap: 0.06rem;
}

table.stats-table .player-main {
  line-height: 1.25;
}

/* LR2 genocide insane dans — stairway.sakura.ne.jp/bms/LunaticRave2/?contents=grade */
table.stats-table .player-dan-genocide.dan-g4,
table.stats-table .player-dan-genocide.dan-g5,
table.stats-table .player-dan-genocide.dan-g6,
table.stats-table .player-dan-genocide.dan-g7 {
  color: #44ced9;
}

table.stats-table .player-dan-genocide.dan-g8,
table.stats-table .player-dan-genocide.dan-g9 {
  color: #ff3e43;
}

table.stats-table .player-dan-genocide.dan-g10 {
  color: #fff;
  font-weight: 700;
  text-shadow:
    4px 0 8px #3d89ff,
    -4px 0 8px #3d89ff,
    0 4px 8px #3d89ff,
    0 -4px 8px #3d89ff;
}

table.stats-table .player-dan-genocide.dan-g11 {
  color: #fff;
  font-weight: 700;
  text-shadow:
    0 0 8px #fff,
    4px 0 8px red,
    -4px 0 8px red,
    0 4px 8px red,
    0 -4px 8px red,
    0 -8px 12px red,
    0 -12px 16px red;
}

/* STSL dans — stellabms.xyz/skill-simulator (Satellite SL / Stella ST palettes) */
table.stats-table .player-dan-stsl.stsl-sl0,
table.stats-table .player-dan-stsl.stsl-sl6 {
  color: #16a34a;
}

table.stats-table .player-dan-stsl.stsl-sl1,
table.stats-table .player-dan-stsl.stsl-sl7 {
  color: #06b6d4;
}

table.stats-table .player-dan-stsl.stsl-sl2,
table.stats-table .player-dan-stsl.stsl-sl8 {
  color: #1d4ed8;
}

table.stats-table .player-dan-stsl.stsl-sl3,
table.stats-table .player-dan-stsl.stsl-sl9 {
  color: #c026d3;
}

table.stats-table .player-dan-stsl.stsl-sl4,
table.stats-table .player-dan-stsl.stsl-sl10 {
  color: #dc2626;
}

table.stats-table .player-dan-stsl.stsl-sl5,
table.stats-table .player-dan-stsl.stsl-sl11 {
  color: #d97706;
}

table.stats-table .player-dan-stsl.stsl-sl12 {
  color: #000;
  text-shadow:
    0 1px 0 #fde047,
    0 2px 2px #fde047;
}

table.stats-table .player-dan-stsl.stsl-sl6 {
  text-shadow:
    0 1px 0 #16a34a,
    0 2px 2px #16a34a;
}

table.stats-table .player-dan-stsl.stsl-sl7 {
  text-shadow:
    0 1px 0 #06b6d4,
    0 2px 2px #06b6d4;
}

table.stats-table .player-dan-stsl.stsl-sl8 {
  text-shadow:
    0 1px 0 #1d4ed8,
    0 2px 2px #1d4ed8;
}

table.stats-table .player-dan-stsl.stsl-sl9 {
  text-shadow:
    0 1px 0 #c026d3,
    0 2px 2px #c026d3;
}

table.stats-table .player-dan-stsl.stsl-sl10 {
  text-shadow:
    0 1px 0 #dc2626,
    0 2px 2px #dc2626;
}

table.stats-table .player-dan-stsl.stsl-sl11 {
  text-shadow:
    0 1px 0 #d97706,
    0 2px 2px #d97706;
}

table.stats-table .player-dan-stsl.stsl-st0 {
  color: #4ade80;
  text-shadow:
    -1px 0 #000,
    0 1px #000,
    1px 0 #000,
    0 -1px #000,
    2px 2px 1px #888;
}

table.stats-table .player-dan-stsl.stsl-st1 {
  color: #67e8f9;
  text-shadow:
    -1px 0 #000,
    0 1px #000,
    1px 0 #000,
    0 -1px #000,
    2px 2px 1px #888;
}

table.stats-table .player-dan-stsl.stsl-st2 {
  color: #3b82f6;
  text-shadow:
    -1px 0 #000,
    0 1px #000,
    1px 0 #000,
    0 -1px #000,
    2px 2px 1px #888;
}

table.stats-table .player-dan-stsl.stsl-st3 {
  color: #e879f9;
  text-shadow:
    -1px 0 #000,
    0 1px #000,
    1px 0 #000,
    0 -1px #000,
    2px 2px 1px #888;
}

table.stats-table .player-dan-stsl.stsl-st4 {
  color: #f87171;
  text-shadow:
    -1px 0 #000,
    0 1px #000,
    1px 0 #000,
    0 -1px #000,
    2px 2px 1px #888;
}

table.stats-table .player-dan-stsl.stsl-st5 {
  color: #fbbf24;
  text-shadow:
    -1px 0 #000,
    0 1px #000,
    1px 0 #000,
    0 -1px #000,
    2px 2px 1px #888;
}

table.stats-table .player-dan-stsl.stsl-st6 {
  color: #fff;
  font-weight: 700;
  text-shadow:
    -1px 0 #080,
    0 1px #080,
    1px 0 #080,
    0 -1px #080,
    0 0 10px #0cc;
}

table.stats-table .player-dan-stsl.stsl-st7 {
  color: #fff;
  font-weight: 700;
  text-shadow:
    -1px 0 #00f,
    0 1px #00f,
    1px 0 #00f,
    0 -1px #00f,
    0 0 10px #00f;
}

table.stats-table .player-dan-stsl.stsl-st8 {
  color: #fff;
  font-weight: 700;
  text-shadow:
    -1px 0 #f0f,
    0 1px #f0f,
    1px 0 #f0f,
    0 -1px #f0f,
    0 0 10px #f0f;
}

table.stats-table .player-dan-stsl.stsl-st9 {
  color: #fff;
  font-weight: 700;
  text-shadow:
    -1px 0 #f44,
    0 1px #f44,
    1px 0 #f44,
    0 -1px #f44,
    0 0 10px #f44;
}

table.stats-table .player-dan-stsl.stsl-st10 {
  color: #fde047;
  font-weight: 700;
  text-shadow:
    -1px 0 #630,
    0 1px #630,
    1px 0 #630,
    0 -1px #630,
    0 0 10px gold;
}

table.stats-table .player-dan-stsl.stsl-st11 {
  color: #6b7280;
  font-weight: 700;
  text-shadow:
    -1px 0 #333,
    0 1px #333,
    1px 0 #333,
    0 -1px #333,
    0 0 10px #333;
}

table.stats-table .player-dan-stsl.stsl-st12 {
  font-weight: 900;
  background: linear-gradient(
    to left,
    red,
    violet,
    indigo,
    blue,
    green,
    yellow,
    orange,
    red,
    violet
  );
  background-size: 800% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: stsl-st12-rainbow 3s ease-in-out infinite;
  text-shadow:
    -1px 0 rgba(191, 191, 191, 0.2),
    0 1px rgba(191, 191, 191, 0.2),
    1px 0 rgba(191, 191, 191, 0.2),
    0 -1px rgba(191, 191, 191, 0.2),
    0 0 10px rgba(191, 191, 191, 0.2);
}

@keyframes stsl-st12-rainbow {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

table.stats-table .player-subline {
  display: flex;
  flex-direction: row;
  align-items: baseline;
  flex-wrap: nowrap;
  gap: 0;
  min-width: 0;
  font-size: 0.66em;
  font-weight: 500;
  line-height: 1.1;
}

table.stats-table .player-dan-sep {
  opacity: 0.45;
  padding: 0 0.1em;
}

table.stats-table .player-dan-muted {
  opacity: 0.5;
}

table.stats-table .player-dan-client {
  opacity: 0.72;
  font-weight: 500;
  color: var(--text-soft);
}

table.stats-table .player-dan-walkure {
  font-weight: 600;
  color: var(--accent-link);
}

table.stats-table td.stat-pct {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--accent-stat);
  min-width: 4.5rem;
  white-space: nowrap;
}

table.stats-table .stat-count {
  font-size: 0.72em;
  font-weight: 500;
  opacity: 0.5;
  margin-left: 0.4em;
}

table.stats-table .stat-delta {
  font-size: 0.78em;
  font-weight: 700;
  margin-left: 0.35em;
}

table.stats-table .stat-delta-gain {
  color: #45d483;
}

table.stats-table .stat-delta-loss {
  color: #f07178;
}

@keyframes chart-row-new-breathe {
  0%,
  100% {
    box-shadow: inset 0 0 0 9999px rgba(255, 255, 255, 0.04);
  }

  50% {
    box-shadow: inset 0 0 0 9999px rgba(255, 255, 255, 0.16);
  }
}

table.leaderboard tbody tr.chart-row-new td {
  animation: chart-row-new-breathe 2.4s ease-in-out infinite;
}

.score-grade,
.modal-score-grade {
  display: block;
  font-size: 0.72em;
  font-weight: 600;
  opacity: 0.82;
  margin-top: 0.08em;
}

.chart-modal-wr-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.78);
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}

.chart-modal-wr-toggle input {
  accent-color: #ffd166;
}

table.chart-modal-table tbody tr.chart-modal-wr td {
  background: rgba(255, 209, 102, 0.08);
  border-top: 1px solid rgba(255, 209, 102, 0.22);
  border-bottom: 1px solid rgba(255, 209, 102, 0.22);
}

table.chart-modal-table tbody tr.chart-modal-wr td:first-child {
  box-shadow: inset 3px 0 0 rgba(255, 209, 102, 0.75);
}

table.chart-modal-table tbody tr.chart-modal-wr .modal-score-main {
  color: #ffe6a8;
}

table.stats-table tbody tr.player-highlight:not(.player-filter-active) {
  background: rgba(170, 221, 255, 0.16);
}

table.stats-table tbody tr:nth-child(even).player-highlight:not(.player-filter-active) {
  background: rgba(170, 221, 255, 0.2);
}

.player-pie-wrap {
  flex: 1 1 0;
  min-height: 7.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.player-pie-svg {
  width: 100%;
  max-width: 220px;
  height: auto;
  display: block;
}

.pie-slice {
  cursor: pointer;
  stroke: rgba(0, 0, 0, 0.45);
  stroke-width: 1;
  transition: opacity 0.05s, filter 0.05s;
  opacity: 0.88;
}

.stats-player-viz:has(.player-highlight) .pie-slice:not(.pie-slice-hover),
.stats-player-viz:has(.pie-slice:hover) .pie-slice:not(.pie-slice-hover):not(:hover) {
  opacity: 0.72;
}

.pie-slice-hover,
.pie-slice:hover {
  opacity: 1;
  filter: brightness(1.12);
}

.pie-slice-active {
  filter: brightness(1.25);
  stroke: var(--text);
  stroke-width: 2;
}

.test-status {
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-top: auto;
  padding: 0.52rem 0.6rem;
  border: 1px solid var(--border-table);
  background: rgba(255, 255, 255, 0.04);
  user-select: none;
  pointer-events: none;
}

.test-status-label {
  font-family: var(--font-display);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted-dim);
  text-align: left;
}

.test-status-value {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 0.84rem;
  color: var(--accent-stat);
  text-align: right;
  min-width: 4.5rem;
  white-space: nowrap;
}

@media (min-width: 901px) {
  .stats-modal {
    display: none !important;
  }
}

@media (max-width: 1100px) {
  table.leaderboard { font-size: 0.78rem; }
  table.leaderboard col.col-title { width: 51%; }
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr);
  }

  .stats-panel {
    display: none;
  }

  .mobile-stats-fab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    right: 0.85rem;
    bottom: calc(0.85rem + env(safe-area-inset-bottom, 0px));
    z-index: 900;
    min-height: 2.5rem;
    padding: 0.55rem 0.9rem;
    border: 1px solid var(--border-table);
    background: linear-gradient(180deg, rgba(36, 42, 58, 0.98), rgba(20, 24, 36, 0.98));
    color: var(--text);
    font-family: var(--font-display);
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    cursor: pointer;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  }

  .mobile-stats-fab:hover {
    filter: brightness(1.08);
  }

  .site-header { flex-direction: column; align-items: start; }
  table.leaderboard col.col-ver { width: 0; }
  table.leaderboard .col-ver { display: none; }
  table.leaderboard col.col-title { width: 53%; }
}

@media (max-width: 640px) {
  h1 {
    font-size: 0.95rem;
    letter-spacing: 0.04em;
  }

  .subtitle {
    font-size: 0.72rem;
    line-height: 1.35;
  }

  .site-header {
    padding: 0.75rem 0.85rem;
    gap: 0.55rem;
  }

  .header-level {
    width: 100%;
    justify-content: space-between;
  }

  .header-level select {
    flex: 1;
    min-width: 0;
    max-width: none;
    font-size: 0.82rem;
    padding: 0.42rem 0.55rem;
  }

  .layout {
    padding: 0.55rem 0.55rem calc(4.5rem + env(safe-area-inset-bottom, 0px));
    gap: 0.55rem;
  }

  .table-panel {
    padding: 0.5rem;
    border-radius: 6px;
    min-height: 0;
  }

  .table-toolbar {
    margin-bottom: 0.45rem;
    gap: 0.45rem;
  }

  .toolbar-primary {
    gap: 0.45rem;
  }

  .toolbar-search {
    flex: 1 1 auto;
    min-width: 0;
    max-width: none;
  }

  .toolbar-search input {
    font-size: 16px;
    padding: 0.48rem 0.6rem;
  }

  .toolbar-filters-toggle {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    min-width: 5.5rem;
    max-width: 42%;
    padding: 0.38rem 0.55rem;
  }

  .toolbar-filters-summary {
    display: block;
    max-width: 100%;
  }

  .toolbar-filters-panel {
    display: none;
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 1001;
    width: min(20rem, calc(100vw - 1.5rem));
    max-height: min(70vh, 28rem);
    overflow-y: auto;
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    padding: 0.85rem 0.9rem 0.95rem;
    background: linear-gradient(180deg, rgba(28, 32, 44, 0.98), rgba(18, 20, 30, 0.98));
    border: 1px solid var(--border-table);
    box-shadow:
      0 24px 64px rgba(0, 0, 0, 0.45),
      0 0 0 1px rgba(255, 255, 255, 0.04) inset;
  }

  body.filters-modal-open .toolbar-filters-panel {
    display: flex;
  }

  body.filters-modal-open::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(8, 10, 18, 0.55);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }

  .toolbar-filters-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    font-family: var(--font-display);
    font-size: 0.82rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-soft);
    padding-bottom: 0.15rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }

  .toolbar-filters-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    border: 1px solid var(--border-table);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    font-size: 1.15rem;
    line-height: 1;
    cursor: pointer;
    padding: 0;
  }

  .toolbar-group-filter,
  .toolbar-filter,
  .toolbar-table {
    width: 100%;
    margin-left: 0;
  }

  .toolbar-table select {
    font-size: 0.82rem;
    padding: 0.38rem 0.65rem;
  }

  .toolbar-group-filter {
    flex-wrap: wrap;
  }

  .table-wrap {
    flex: 1;
    min-height: 0;
    overflow: auto;
    margin: 0;
    padding-bottom: 0;
    -webkit-overflow-scrolling: touch;
  }

  table.leaderboard {
    table-layout: fixed;
    width: 100%;
    font-size: 0.74rem;
  }

  table.leaderboard col.col-star { width: 0; }
  table.leaderboard col.col-title  { width: 52%; }
  table.leaderboard col.col-player { width: 16%; }
  table.leaderboard col.col-score-stack { width: 14%; }
  table.leaderboard col.col-bp { width: 0; }
  table.leaderboard col.col-lamp { width: 0; }
  table.leaderboard col.col-date-stack { width: 18%; }

  table.leaderboard .col-star,
  table.leaderboard .col-bp,
  table.leaderboard .col-lamp { display: none; }

  table.leaderboard th,
  table.leaderboard td {
    padding: 0.42rem 0.35rem;
  }

  table.leaderboard thead th {
    font-size: 0.68rem;
    letter-spacing: 0.04em;
    padding-top: 0.42rem;
    padding-bottom: 0.42rem;
  }

  table.leaderboard thead th.col-title,
  table.leaderboard tbody td.col-title {
    position: static;
    box-shadow: none;
    padding-left: 0.5rem;
    padding-right: 0.35rem;
  }

  table.leaderboard tbody td {
    height: auto;
    min-height: 2.5rem;
    max-height: none;
    overflow: visible;
    padding-top: 0.38rem;
    padding-bottom: 0.38rem;
  }

  table.leaderboard tbody td.col-title {
    overflow: visible;
  }

  table.leaderboard .title-cell {
    overflow: visible;
    height: auto;
  }

  table.leaderboard .title-cell.has-subline .title-main {
    -webkit-line-clamp: unset;
  }

  table.leaderboard .title-main,
  table.leaderboard .title-subtitle,
  table.leaderboard .title-artist-text {
    white-space: normal;
    display: block;
    -webkit-line-clamp: unset;
    -webkit-box-orient: unset;
    text-overflow: unset;
    transform: none;
  }

  table.leaderboard .title-subline {
    flex-wrap: wrap;
  }

  table.leaderboard .title-artist {
    max-width: 100%;
    margin-left: 0;
    font-size: 0.82em;
  }

  table.leaderboard tbody td.col-player {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.7rem;
  }

  table.leaderboard tbody td.col-date-stack {
    font-size: 0.66rem;
    white-space: normal;
    line-height: 1.15;
  }

  tr[class^="diff-"] td.col-date-stack {
    border-radius: 0;
  }

  .chart-modal {
    padding: 0.75rem;
  }

  .chart-modal-island {
    width: min(100%, calc(100vw - 1.5rem));
    max-height: min(78vh, 34rem);
  }
}
