:root {
  color-scheme: dark;
  --black: #03050a;
  --graphite: #090d18;
  --surface: #0b1020;
  --surface-strong: #0e1628;
  --line: #26334f;
  --muted: #91a4cd;
  --white: #f5f8ff;
  --cyan: #31e7ff;
  --violet: #9b72ff;
  --magenta: #ff4fc8;
  --pink: #ff4f8b;
  --blue: #4f8dff;
  --mode-accent: var(--cyan);
  --mode-accent-rgb: 49, 231, 255;
  --edge-space: clamp(14px, 2vw, 34px);
  --ui-font: "Segoe UI", "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", Arial, sans-serif;
  --display-font: "Arial Black", "Segoe UI Black", "Noto Sans KR", "Malgun Gothic", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  background: var(--black);
}

body {
  min-height: 100vh;
  min-height: 100svh;
  overflow: hidden;
  color: var(--white);
  font-family: var(--ui-font);
  font-variant-numeric: tabular-nums;
}

body[data-mode="sync"] {
  --mode-accent: var(--violet);
  --mode-accent-rgb: 155, 114, 255;
}

body[data-mode="surge"] {
  --mode-accent: var(--magenta);
  --mode-accent-rgb: 255, 79, 200;
}

body[data-mode="overdrive"] {
  --mode-accent: var(--blue);
  --mode-accent-rgb: 79, 141, 255;
}

button,
table {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.ambient-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(155, 114, 255, 0.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(49, 231, 255, 0.034) 1px, transparent 1px),
    radial-gradient(circle at 50% 42%, rgba(var(--mode-accent-rgb), 0.075), transparent 43%);
  background-size: 72px 72px, 96px 96px, 100% 100%;
  mask-image: linear-gradient(to bottom, transparent 1%, #000 18%, #000 100%);
}

.ambient-grid::before,
.ambient-grid::after {
  content: "";
  position: absolute;
  width: 86px;
  height: 24px;
  border-top: 2px solid rgba(49, 231, 255, 0.32);
}

.ambient-grid::before {
  top: var(--edge-space);
  left: var(--edge-space);
  border-left: 2px solid rgba(49, 231, 255, 0.32);
}

.ambient-grid::after {
  right: var(--edge-space);
  bottom: var(--edge-space);
  border-right: 2px solid rgba(255, 79, 200, 0.24);
  border-top-color: rgba(255, 79, 200, 0.24);
  transform: rotate(180deg);
}

.display-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: clamp(8px, 1.2vh, 14px);
  width: 100%;
  max-width: 1900px;
  height: 100vh;
  height: 100svh;
  margin: 0 auto;
  padding: clamp(12px, 2.1vh, 28px) var(--edge-space);
}

.hero {
  display: flex;
  align-items: end;
  justify-content: space-between;
  min-width: 0;
}

.brand-lockup {
  min-width: 0;
}

.eyebrow,
.display-title,
.panel-kicker,
.population-label,
.panel-footer {
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: clamp(9px, 0.72vw, 13px);
  font-weight: 700;
}

.eyebrow span,
h1 span,
h2 span {
  color: var(--magenta);
}

h1 {
  margin: 0;
  color: #dcfaff;
  font-family: var(--display-font);
  font-size: clamp(38px, 4.2vw, 76px);
  font-style: italic;
  font-weight: 900;
  letter-spacing: -0.055em;
  line-height: 0.92;
  text-transform: uppercase;
  text-shadow: 0 0 16px rgba(49, 231, 255, 0.16);
}

.display-title {
  margin: clamp(4px, 0.5vh, 8px) 0 0 0.18em;
  color: var(--violet);
  font-size: clamp(12px, 1.05vw, 20px);
  font-weight: 800;
}

.connection-status {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 10px;
  min-width: clamp(146px, 12vw, 205px);
  margin-bottom: 2px;
  padding: clamp(9px, 1vh, 13px) clamp(14px, 1.2vw, 22px);
  border: 1px solid rgba(255, 79, 139, 0.42);
  background: rgba(14, 22, 40, 0.9);
  color: #ffd6e2;
  font-size: clamp(11px, 0.9vw, 16px);
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.connection-status[data-state="live"] {
  border-color: rgba(49, 231, 255, 0.48);
  color: #dffcff;
}

.connection-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--pink);
  box-shadow: 0 0 10px rgba(255, 79, 139, 0.5);
}

.connection-status[data-state="live"] .connection-dot {
  background: var(--cyan);
  box-shadow: 0 0 10px rgba(49, 231, 255, 0.55);
}

.mode-selector {
  display: grid;
  grid-template-columns: 0.82fr 1px repeat(4, 1fr);
  gap: clamp(5px, 0.65vw, 12px);
  min-width: 0;
}

.mode-divider {
  width: 1px;
  height: 64%;
  margin: auto 0;
  background: rgba(145, 164, 205, 0.24);
}

.mode-button {
  position: relative;
  min-width: 0;
  min-height: clamp(38px, 4.8vh, 54px);
  padding: 0 clamp(8px, 1vw, 18px);
  overflow: hidden;
  border: 1px solid rgba(145, 164, 205, 0.25);
  border-radius: 2px;
  background: rgba(9, 13, 24, 0.9);
  color: #b9c7e6;
  cursor: pointer;
  font-size: clamp(11px, 1vw, 17px);
  font-weight: 850;
  letter-spacing: 0.09em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  transition: border-color 150ms ease, background-color 150ms ease, color 150ms ease;
  white-space: nowrap;
}

.button-index {
  margin-right: clamp(3px, 0.45vw, 8px);
  color: #67799f;
  font-size: 0.72em;
  font-weight: 700;
}

.mode-button:hover,
.mode-button:focus-visible {
  border-color: rgba(49, 231, 255, 0.7);
  color: var(--white);
  outline: none;
}

.mode-button:focus-visible {
  box-shadow: inset 0 0 0 2px rgba(255, 79, 200, 0.75);
}

.mode-button.is-mode-active {
  border-color: rgba(var(--mode-accent-rgb), 0.76);
  background: linear-gradient(90deg, rgba(var(--mode-accent-rgb), 0.15), rgba(14, 22, 40, 0.94));
  color: var(--white);
}

.mode-button.is-mode-active::after,
.mode-button[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  right: 8%;
  bottom: 0;
  left: 8%;
  height: 2px;
  background: var(--mode-accent);
}

.auto-button[aria-pressed="true"] {
  border-color: rgba(255, 79, 200, 0.72);
  background: rgba(255, 79, 200, 0.1);
  color: var(--white);
}

.auto-button[aria-pressed="true"]::after {
  background: var(--magenta);
}

.leaderboard-panel {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  border: 1px solid rgba(var(--mode-accent-rgb), 0.42);
  background: rgba(5, 9, 17, 0.94);
  box-shadow:
    0 0 0 5px rgba(var(--mode-accent-rgb), 0.018),
    inset 0 0 0 7px rgba(155, 114, 255, 0.025);
}

.corner {
  position: absolute;
  z-index: 3;
  width: 25px;
  height: 25px;
  pointer-events: none;
}

.corner-top-left {
  top: -2px;
  left: -2px;
  border-top: 3px solid var(--mode-accent);
  border-left: 3px solid var(--mode-accent);
}

.corner-top-right {
  top: -2px;
  right: -2px;
  border-top: 3px solid var(--mode-accent);
  border-right: 3px solid var(--mode-accent);
}

.corner-bottom-left {
  bottom: -2px;
  left: -2px;
  border-bottom: 3px solid var(--mode-accent);
  border-left: 3px solid var(--mode-accent);
}

.corner-bottom-right {
  right: -2px;
  bottom: -2px;
  border-right: 3px solid var(--mode-accent);
  border-bottom: 3px solid var(--mode-accent);
}

.panel-header {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  min-height: clamp(42px, 6.1vh, 66px);
  padding: clamp(6px, 0.8vh, 10px) clamp(14px, 1.5vw, 28px);
  border-bottom: 1px solid rgba(145, 164, 205, 0.17);
  background: linear-gradient(90deg, rgba(var(--mode-accent-rgb), 0.08), transparent 48%);
}

.panel-kicker {
  margin: 0 0 1px;
  color: var(--muted);
  font-size: clamp(8px, 0.62vw, 11px);
  font-weight: 700;
}

h2 {
  margin: 0;
  color: var(--white);
  font-size: clamp(18px, 1.65vw, 30px);
  font-weight: 900;
  letter-spacing: 0.04em;
  line-height: 1;
}

.population {
  display: flex;
  align-items: baseline;
  gap: clamp(8px, 0.8vw, 15px);
  text-align: right;
}

.population-label {
  color: var(--muted);
  font-size: clamp(8px, 0.65vw, 12px);
  font-weight: 700;
}

#population-value {
  color: var(--mode-accent);
  font-size: clamp(17px, 1.6vw, 29px);
  line-height: 1;
}

.table-stage {
  position: relative;
  min-height: 0;
  flex: 1 1 auto;
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.rank-column {
  width: 8%;
}

.player-column {
  width: 32%;
}

.rp-column {
  width: 10%;
}

.score-column {
  width: 18%;
}

.accuracy-column,
.combo-column {
  width: 16%;
}

thead tr {
  height: clamp(32px, 4vh, 44px);
}

th {
  padding: 0 clamp(6px, 1.1vw, 20px);
  border-bottom: 1px solid rgba(145, 164, 205, 0.25);
  color: #7f92ba;
  font-size: clamp(9px, 0.72vw, 13px);
  font-weight: 800;
  letter-spacing: 0.1em;
  text-align: right;
  white-space: nowrap;
}

th:nth-child(2),
td:nth-child(2) {
  text-align: left;
}

tbody tr {
  height: clamp(39px, 5.85vh, 68px);
  background: rgba(9, 13, 24, 0.54);
}

tbody tr:nth-child(even) {
  background: rgba(13, 20, 36, 0.54);
}

td {
  padding: 0 clamp(6px, 1.1vw, 20px);
  border-bottom: 1px solid rgba(145, 164, 205, 0.105);
  color: #dce6ff;
  font-size: clamp(15px, 1.55vw, 28px);
  font-weight: 700;
  line-height: 1.05;
  text-align: right;
  white-space: nowrap;
}

.player-cell {
  overflow-wrap: anywhere;
  white-space: normal;
}

.rank-cell {
  color: #93a5c9;
  font-weight: 900;
  text-align: center;
}

.rp-cell {
  color: var(--mode-accent);
}

.score-cell {
  color: var(--white);
  font-size: clamp(17px, 1.75vw, 32px);
  font-weight: 900;
  letter-spacing: 0.01em;
}

.accuracy-cell,
.combo-cell {
  color: #c5d3f1;
}

tbody tr[data-rank="1"],
tbody tr[data-rank="2"],
tbody tr[data-rank="3"] {
  background: linear-gradient(90deg, rgba(var(--mode-accent-rgb), 0.13), rgba(12, 18, 33, 0.78) 46%);
}

tbody tr[data-rank="1"] td:first-child,
tbody tr[data-rank="2"] td:first-child,
tbody tr[data-rank="3"] td:first-child {
  box-shadow: inset 3px 0 0 var(--mode-accent);
}

tbody tr[data-rank="1"] .rank-cell {
  color: var(--white);
  text-shadow: 0 0 9px rgba(var(--mode-accent-rgb), 0.65);
}

tbody tr[data-rank="2"] .rank-cell,
tbody tr[data-rank="3"] .rank-cell {
  color: var(--mode-accent);
}

tbody tr[data-rank="1"] .player-cell,
tbody tr[data-rank="2"] .player-cell,
tbody tr[data-rank="3"] .player-cell {
  color: var(--white);
  font-weight: 850;
}

.row-updated {
  animation: row-update 760ms ease-out both;
}

@keyframes row-update {
  from {
    background-color: rgba(var(--mode-accent-rgb), 0.22);
  }

  to {
    background-color: transparent;
  }
}

.empty-state {
  position: absolute;
  inset: clamp(32px, 4vh, 44px) 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 7px;
  background:
    linear-gradient(90deg, transparent, rgba(var(--mode-accent-rgb), 0.035), transparent),
    rgba(5, 9, 17, 0.96);
  text-align: center;
}

.empty-state[hidden] {
  display: none;
}

.empty-state strong {
  color: var(--white);
  font-size: clamp(20px, 2.2vw, 39px);
  font-weight: 900;
  letter-spacing: 0.08em;
}

.empty-state span {
  color: var(--muted);
  font-size: clamp(9px, 0.75vw, 13px);
  font-weight: 700;
  letter-spacing: 0.14em;
}

.panel-footer {
  display: flex;
  min-height: clamp(24px, 3.6vh, 38px);
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(14px, 1.5vw, 28px);
  border-top: 1px solid rgba(145, 164, 205, 0.16);
  color: #7284aa;
  font-size: clamp(7px, 0.58vw, 10px);
  font-weight: 700;
  white-space: nowrap;
}

.panel-footer b {
  color: var(--magenta);
}

#last-updated {
  color: #91a4cd;
}

.noscript-message {
  position: fixed;
  inset: auto 20px 20px;
  z-index: 10;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--pink);
  background: var(--surface-strong);
  text-align: center;
}

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  .display-shell {
    height: auto;
    min-height: 100svh;
  }

  .mode-selector {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .mode-divider,
  .button-index,
  .population-label,
  .panel-footer > span:first-child {
    display: none;
  }

  .mode-button {
    letter-spacing: 0.02em;
  }

  .leaderboard-panel {
    min-height: 590px;
  }

  .rank-column {
    width: 10%;
  }

  .player-column {
    width: 30%;
  }
}

@media (max-width: 620px) {
  .hero {
    align-items: start;
    gap: 8px;
  }

  .eyebrow,
  .display-title,
  .accuracy-column,
  .accuracy-cell {
    display: none;
  }

  .connection-status {
    min-width: 0;
    padding: 8px;
  }

  .mode-selector {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .auto-button {
    grid-column: 1 / -1;
  }

  .leaderboard-panel {
    min-height: 640px;
  }

  .rank-column {
    width: 13%;
  }

  .player-column {
    width: 35%;
  }

  .rp-column {
    width: 14%;
  }

  .score-column {
    width: 23%;
  }

  .combo-column {
    width: 15%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
