: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: #8899bb;
  --border-cell: rgba(255, 255, 255, 0.14);
  --text: #f4f6ff;
  --text-soft: #dde8f8;
  --muted: #b8c4d8;
  --muted-dim: #9aaccc;
  --accent: #506888;
  --accent-hover: #607898;
  --accent-link: #b8d4ff;
  --accent-stat: #c8e4ff;
  --diff-hyper-bg: #3f3620;
  --diff-hyper-fg: #f0c848;
  --diff-hyper-border: #9a8048;
  --diff-another-bg: #3c2228;
  --diff-another-fg: #ff5860;
  --diff-another-border: #a04850;
  --diff-legg-bg: #382030;
  --diff-legg-fg: #ff70b8;
  --diff-legg-border: #a05078;
  --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: #7eb8ff;
  --pie-1: #f0a8d0;
  --pie-2: #f5cc6a;
  --pie-3: #7de8b8;
  --pie-4: #c4a8ff;
  --pie-5: #ffaa94;
  --pie-6: #6ecfff;
  --pie-7: #e8b0ff;
  --pie-8: #b8f090;
  --pie-9: #ffb870;
  /* IIDX clear lamp tints (20% opacity, same palette as bms-uczelnie) */
  --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;
}

.level-tabs {
  display: flex;
  gap: .35rem;
  padding: 0.35rem;
  background: var(--bg-nav);
  border: 3px solid var(--border-strong);
}

.level-tabs button {
  font-family: var(--font-display);
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  background: transparent;
  color: var(--accent-link);
  border: 1px solid transparent;
  padding: .45rem 1rem;
  border-radius: 0;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.level-tabs button:hover {
  color: #ff6666;
}

.level-tabs button.active {
  background: var(--accent);
  border-color: var(--border-table);
  color: var(--text);
}

.table-toolbar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.65rem;
  margin-bottom: 0.65rem;
  flex-shrink: 0;
  position: relative;
  z-index: 3;
  background: var(--bg-panel);
}

.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;
}

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

.toolbar-level-group {
  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);
}

.sort-tabs {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.sort-tabs button {
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: #111;
  color: var(--muted);
  border: 1px solid var(--accent);
  padding: 0.3rem 0.65rem;
  border-radius: 0;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.sort-tabs button:hover {
  border-color: var(--border-table);
  color: var(--text);
  background: #1a1a2a;
}

.sort-tabs button.active {
  background: var(--accent);
  border-color: var(--border-table);
  color: var(--text);
}

.toolbar-filter {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-left: auto;
  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-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;
}

.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;
  gap: 0.65rem;
  overflow: hidden;
}

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

.stats-table-wrap .stats-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.player-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.08rem;
  line-height: 1.15;
  text-align: left;
}

.player-main {
  white-space: nowrap;
}

.player-subline {
  font-size: 0.68em;
  line-height: 1.1;
  opacity: 0.95;
}

.player-dan.dan-kaiden {
  color: #b8860b;
  font-weight: 600;
}

.player-dan.dan-chuuden {
  color: #6b7280;
  font-weight: 600;
}

.player-dan.dan-red {
  color: #b91c1c;
  font-weight: 600;
}

.player-dan.dan-blue {
  color: #1d4ed8;
  font-weight: 600;
}

.table-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  z-index: 0;
  isolation: isolate;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-radius: 0;
  border: 1px solid var(--border-table);
  line-height: 0;
}

.table-toolbar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -0.35rem;
  height: 0.35rem;
  background: var(--bg-panel);
  pointer-events: none;
}

/* ── Main leaderboard table ── */
table.leaderboard {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.82rem;
  table-layout: fixed;
  line-height: 1.4;
}

table.leaderboard thead {
  position: relative;
  z-index: 3;
}

table.leaderboard tbody {
  position: relative;
  z-index: 1;
}

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

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

table.leaderboard .score-pct {
  font-size: 0.62em;
  font-weight: 600;
  opacity: 0.9;
  white-space: nowrap;
  letter-spacing: -0.02em;
}

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

table.leaderboard .date-main {
  white-space: nowrap;
}

table.leaderboard col.col-tier   { width: 9%; }
table.leaderboard col.col-title  { width: 44%; }
table.leaderboard col.col-diff   { width: 3%; }
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-ver    { width: 4.5%; }
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: 0;
  z-index: 4;
  background: #556b8c;
  box-shadow: 0 1px 0 var(--border-table);
  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-tier {
  border-left: none;
  border-top: none;
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  padding-left: 0.45rem;
  padding-right: 0.45rem;
}

table.leaderboard tbody td.col-tier {
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1.15;
  text-align: center;
  white-space: normal;
  overflow: hidden;
  padding-left: 0.35rem;
  padding-right: 0.35rem;
}

table.leaderboard .tier-cell {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 0.05rem;
  max-width: 100%;
  line-height: 1.1;
}

table.leaderboard .tier-nc,
table.leaderboard .tier-hc,
table.leaderboard .tier-empty {
  display: block;
  max-width: 100%;
}

table.leaderboard .tier-nc {
  color: #5eb0ff;
}

table.leaderboard .tier-hc {
  color: #ff6b6b;
}

table.leaderboard .tier-sep,
table.leaderboard .tier-empty {
  color: rgba(255, 255, 255, 0.35);
  font-weight: 500;
}

table.leaderboard .tier-sep {
  display: 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 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: hidden;
  position: relative;
  cursor: pointer;
}

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

table.leaderboard .title-clip {
  overflow: hidden;
  contain: paint;
  max-width: 100%;
}

table.leaderboard .title-cell {
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
  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.94;
  line-height: 1.1;
}

table.leaderboard .title-artist-text {
  display: inline-block;
  max-width: 100%;
  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: 600;
  opacity: 0.72;
  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-diff,
table.leaderboard thead th.col-diff {
  padding-left: 0.2rem;
  padding-right: 0.2rem;
  font-size: 0.62rem;
  letter-spacing: 0;
}

table.leaderboard tbody td.col-diff {
  font-weight: 700;
}

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

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

table.leaderboard thead th.col-diff,
table.leaderboard thead th.col-bp,
table.leaderboard thead th.col-ver,
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 tbody td.col-score-stack {
  padding-left: 0.3rem;
  padding-right: 0.3rem;
}

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

@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;
}

/* ── Difficulty row colors (IIDX) — dark tints from official hues ── */
tr.diff-hyper td {
  background: var(--diff-hyper-bg);
  color: var(--diff-hyper-fg);
  border-color: var(--diff-hyper-border);
}

tr.diff-another td {
  background: var(--diff-another-bg);
  color: var(--diff-another-fg);
  border-color: var(--diff-another-border);
}

tr.diff-leggendaria td {
  background: var(--diff-legg-bg);
  color: var(--diff-legg-fg);
  border-color: var(--diff-legg-border);
}

tr[class^="diff-"] .title-ascii {
  opacity: 0.82;
}

tr[class^="diff-"] .title-artist {
  opacity: 0.96;
}

tr[class^="diff-"] .score-pct {
  opacity: 0.94;
}

tr[class^="diff-"] td:first-child {
  border-radius: 0;
}
tr[class^="diff-"] td:last-child {
  border-radius: 0;
}

/* ── 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: #4d6080;
}

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

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

table.stats-table tbody tr.player-filter-active {
  background: rgba(126, 184, 255, 0.28);
}

table.stats-table tbody tr.player-filter-active:hover {
  background: rgba(126, 184, 255, 0.36);
}

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

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

table.stats-table td:first-child {
  text-align: left;
  font-weight: 600;
  color: var(--text-soft);
}

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.72;
  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;
}

table.stats-table tbody tr.player-highlight:not(.player-filter-active) {
  background: rgba(126, 184, 255, 0.22);
}

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

.player-pie-wrap {
  flex: 1 1 auto;
  flex-shrink: 0;
  min-height: 9.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.55);
  stroke-width: 1.25;
  transition: opacity 0.05s, filter 0.05s;
  opacity: 1;
}

.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.42;
}

.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;
}

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);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  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.85rem 0.95rem 0.95rem;
}

#chart-modal .chart-modal-island {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#chart-modal .chart-modal-header {
  flex-shrink: 0;
}

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

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

.chart-modal-title-main {
  line-height: 1.3;
}

.chart-modal-title-ascii {
  font-family: ui-monospace, "Cascadia Mono", "SF Mono", "Consolas", "Liberation Mono", monospace;
  font-size: 0.72em;
  font-weight: 500;
  opacity: 0.72;
  margin-top: 0.2rem;
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.chart-modal-close {
  flex: 0 0 auto;
  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;
}

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

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

.chart-modal-body {
  overflow: visible;
}

#chart-modal .chart-modal-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.chart-modal-lb {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.chart-modal-lb-scroll {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.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: fixed;
}

table.chart-modal-table col.col-kto { width: 28%; }
table.chart-modal-table col.col-score-stack { width: 22%; }
table.chart-modal-table col.col-bp { width: 10%; }
table.chart-modal-table col.col-lamp { width: 22%; }
table.chart-modal-table col.col-kiedy { width: 18%; }

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: #2a3144;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.08);
  font-weight: 500;
}

table.chart-modal-table-head tbody tr.chart-modal-top td {
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.22);
}

table.chart-modal-table .col-kto,
table.chart-modal-table tbody td.col-kto {
  text-align: left;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
}

table.chart-modal-table .col-lamp {
  font-size: 0.58rem;
  letter-spacing: 0.02em;
  line-height: 1.15;
  max-width: 4.5rem;
  white-space: normal;
}

table.chart-modal-table tbody tr.chart-modal-best td {
  border-top: 2px solid rgba(200, 235, 255, 0.95);
  border-bottom: 2px solid rgba(200, 235, 255, 0.95);
}

table.chart-modal-table tbody tr.chart-modal-best td:first-child {
  border-left: 2px solid rgba(200, 235, 255, 0.95);
}

table.chart-modal-table tbody tr.chart-modal-best td:last-child {
  border-right: 2px solid rgba(200, 235, 255, 0.95);
}

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

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

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

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

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

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

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

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

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

table.chart-modal-table .modal-score-grade {
  display: block;
  font-size: 0.92em;
  opacity: 0.88;
  font-weight: 600;
  letter-spacing: -0.02em;
}

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

.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;
}

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

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

@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-tier { width: 12%; }
  table.leaderboard col.col-title { width: 41%; }
}

@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;
  }

  .site-header .level-tabs {
    display: none;
  }

  .toolbar-level-group {
    display: flex;
    width: 100%;
    margin-left: 0;
  }

  .toolbar-level-group .level-tabs {
    flex: 1;
    width: 100%;
    justify-content: stretch;
  }

  .toolbar-level-group .level-tabs button {
    flex: 1;
    font-size: 0.82rem;
    padding: 0.38rem 0.65rem;
  }

  .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-filter-group,
  .toolbar-filter {
    width: 100%;
    margin-left: 0;
  }

  .sort-tabs button {
    font-size: 0.82rem;
    padding: 0.38rem 0.65rem;
  }

  .table-wrap {
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    margin: 0;
    padding-bottom: 0;
  }

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

  table.leaderboard col.col-tier   { width: 15%; }
  table.leaderboard col.col-title  { width: 37%; }
  table.leaderboard col.col-player { width: 20%; }
  table.leaderboard col.col-score-stack { width: 14%; }
  table.leaderboard col.col-date-stack { width: 14%; }

  table.leaderboard .col-diff,
  table.leaderboard .col-bp,
  table.leaderboard .col-ver { 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 {
    padding-left: 0.5rem;
    padding-right: 0.35rem;
  }

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

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

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

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

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

  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: unset;
    white-space: normal;
    font-family: var(--font-condensed);
    font-stretch: condensed;
    font-size: 0.66rem;
    line-height: 1.12;
    word-break: break-word;
    overflow-wrap: anywhere;
    hyphens: auto;
    padding-left: 0.25rem;
    padding-right: 0.25rem;
    vertical-align: middle;
  }

  table.leaderboard tbody td.col-player .player-name-text {
    display: inline-block;
    max-width: 100%;
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  table.leaderboard thead th.col-tier {
    font-size: 0.58rem;
    padding-left: 0.2rem;
    padding-right: 0.2rem;
  }

  table.leaderboard tbody td.col-tier {
    font-size: 0.52rem;
    line-height: 1.08;
    padding-left: 0.18rem;
    padding-right: 0.18rem;
    overflow: hidden;
  }

  table.leaderboard .tier-cell {
    gap: 0.02rem;
  }

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

  table.leaderboard .date-main {
    font-size: 0.92em;
    letter-spacing: -0.01em;
  }

  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);
  }

  table.stats-table {
    font-size: 0.78rem;
  }
}
