:root {
  --bg: #070910;
  --cyan: #3dfff3;
  --magenta: #ff4dff;
  --gold: #ffd15c;
  --glass: rgba(10, 16, 32, 0.72);
  --line: rgba(61, 255, 243, 0.42);
  --ink: #f4fbff;
  --muted: rgba(244, 251, 255, 0.68);
  --safe-top: max(12px, env(safe-area-inset-top));
  --safe-right: max(12px, env(safe-area-inset-right));
  --safe-bottom: max(12px, env(safe-area-inset-bottom));
  --safe-left: max(12px, env(safe-area-inset-left));
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(0, 0, 0, 0.5) 100%);
}

#gameCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
  background: var(--bg);
  z-index: 0;
}

#hud {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

.hud-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
}

.stat-stack {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-content: flex-start;
  min-width: 0;
}

.badge,
.leaderboard,
.emotes,
.menu-card,
#boostBtn,
.toast {
  background: var(--glass);
  border: 1px solid var(--line);
  box-shadow:
    0 0 0 1px rgba(255, 77, 255, 0.08),
    0 10px 30px rgba(0, 0, 0, 0.35),
    inset 0 0 22px rgba(61, 255, 243, 0.05);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.badge {
  pointer-events: none;
  min-width: 92px;
  padding: 8px 10px 9px;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.badge .label,
.leaderboard h2,
.field,
.skin-field legend,
.best-line,
.mystery-status,
.tagline,
.how {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.badge strong {
  font-size: 1.15rem;
  line-height: 1.1;
  text-shadow: 0 0 10px rgba(61, 255, 243, 0.35);
}

.badge small {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: none;
}

.rank-badge {
  border-color: rgba(182, 255, 59, 0.7);
  color: #b6ff3b;
}

.combo-badge.hot {
  animation: comboPulse 0.55s ease-in-out infinite;
  border-color: var(--magenta);
  color: #ffe6ff;
}

.power-badge.on {
  border-color: var(--gold);
  color: var(--gold);
  box-shadow:
    0 0 16px rgba(255, 209, 92, 0.35),
    inset 0 0 18px rgba(255, 209, 92, 0.08);
}

.rank-badge.pop {
  animation: rankPop 0.45s ease;
}

.leaderboard {
  width: min(168px, 46vw);
  padding: 10px 10px 8px;
  border-radius: 16px;
  pointer-events: auto;
}

.leaderboard h2 {
  margin: 0 0 6px;
  line-height: 1.3;
}

.leaderboard ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.leaderboard li {
  display: grid;
  grid-template-columns: 1.1em minmax(0, 1fr) auto;
  gap: 4px;
  align-items: center;
  font-size: 12px;
  padding: 2px 4px;
}

.leaderboard li em {
  font-style: normal;
  opacity: 0.65;
}

.leaderboard li span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard li strong {
  font-variant-numeric: tabular-nums;
}

.leaderboard li:nth-child(1) span { color: var(--gold); }
.leaderboard li:nth-child(2) span { color: #d5e4ee; }
.leaderboard li:nth-child(3) span { color: #ffb08a; }

.leaderboard li.me {
  background: rgba(61, 255, 243, 0.14);
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgba(61, 255, 243, 0.35);
}

.leaderboard li.empty {
  display: block;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
  line-height: 1.35;
}

.rival-line {
  margin: 8px 0 0;
  color: var(--cyan);
  font-size: 11px;
  letter-spacing: 0.02em;
  line-height: 1.3;
}

.hud-bottom {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
}

.emotes {
  pointer-events: auto;
  display: flex;
  gap: 8px;
  padding: 8px;
  border-radius: 999px;
}

.emotes button,
#boostBtn,
#playBtn,
#mysteryBtn,
.swatch {
  font: inherit;
  color: white;
  cursor: pointer;
}

.emotes button {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid rgba(61, 255, 243, 0.45);
  background: rgba(7, 9, 16, 0.55);
  font-size: 22px;
  line-height: 1;
}

#boostBtn {
  pointer-events: auto;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: 2px solid var(--cyan);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-shadow: 0 0 8px rgba(61, 255, 243, 0.8);
}

#boostBtn.ready {
  animation: comboPulse 1.15s ease-in-out infinite;
}

#boostBtn:disabled {
  opacity: 0.55;
  animation: none;
  cursor: default;
}

#menuOverlay {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  background: rgba(4, 6, 12, 0.58);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

#menuOverlay[hidden] {
  display: none !important;
}

.menu-card {
  width: min(440px, 100%);
  max-height: calc(100vh - 24px);
  overflow: auto;
  border-radius: 22px;
  padding: 18px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  touch-action: auto;
  pointer-events: auto;
}

.kicker {
  margin: 0;
  text-align: center;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--cyan);
  font-size: 12px;
}

.menu-card h1 {
  margin: 0;
  text-align: center;
  font-size: clamp(1.7rem, 7vw, 2.5rem);
  line-height: 0.95;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #eaffff;
  text-shadow:
    0 0 12px rgba(61, 255, 243, 0.85),
    0 0 28px rgba(255, 77, 255, 0.45);
}

.tagline,
.best-line,
.mystery-status {
  margin: 0;
  text-align: center;
  letter-spacing: 0.04em;
  text-transform: none;
  line-height: 1.4;
}

#gameOverStats {
  text-align: center;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255, 77, 255, 0.45);
  background: rgba(255, 77, 255, 0.08);
}

#gameOverStats p {
  margin: 0;
}

#finalScoreLine {
  font-size: 1.15rem;
  font-weight: 800;
}

#finalDetailLine {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.92rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  letter-spacing: 0.12em;
}

input {
  user-select: text;
  -webkit-user-select: text;
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(61, 255, 243, 0.45);
  background: rgba(0, 0, 0, 0.35);
  color: white;
  font: 700 1.05rem/1.2 "Trebuchet MS", "Segoe UI", sans-serif;
  letter-spacing: 0.04em;
  padding: 12px 12px;
  outline: none;
}

input:focus {
  box-shadow: 0 0 0 3px rgba(61, 255, 243, 0.25);
}

.skin-field {
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
}

.skin-field legend {
  padding: 0;
  margin-bottom: 8px;
}

.skin-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: radial-gradient(circle at 35% 30%, #ffffff, var(--c) 42%, #070910 78%);
  box-shadow: 0 0 10px var(--c);
}

.swatch.active {
  border-color: white;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.12), 0 0 16px var(--c);
}

#mysteryBtn,
#playBtn {
  width: 100%;
  border-radius: 14px;
  padding: 12px 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 800;
}

#mysteryBtn {
  border: 1px solid rgba(255, 209, 92, 0.7);
  background: linear-gradient(90deg, rgba(61, 255, 243, 0.16), rgba(255, 77, 255, 0.2), rgba(255, 209, 92, 0.18));
  background-size: 180% 100%;
  animation: shimmer 3.5s linear infinite;
}

#mysteryBtn.equipped {
  box-shadow: 0 0 18px rgba(255, 209, 92, 0.45);
}

#playBtn {
  border: 0;
  background: linear-gradient(90deg, #14d6c8, #7d5cff 55%, #ff4dff);
  box-shadow: 0 0 22px rgba(61, 255, 243, 0.35);
  font-size: 1.05rem;
  padding: 14px 16px;
}

.how {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-transform: none;
  letter-spacing: 0;
  line-height: 1.35;
}

.friends-launch,
.friend-search button,
.friend-actions button,
#friendsClose {
  font: inherit;
  color: white;
  cursor: pointer;
}

.friends-launch {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-radius: 14px;
  padding: 10px 12px;
  border: 1px solid rgba(61, 255, 243, 0.55);
  background: rgba(10, 16, 32, 0.72);
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  box-shadow:
    0 0 16px rgba(61, 255, 243, 0.2),
    inset 0 0 18px rgba(155, 140, 255, 0.1);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.count-badge {
  min-width: 1.5em;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--cyan);
  color: #071018;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-align: center;
  line-height: 1.3;
}

.count-badge-quiet {
  background: rgba(255, 77, 255, 0.2);
  color: #ffd6ff;
  box-shadow: inset 0 0 0 1px rgba(255, 77, 255, 0.55);
}

.count-badge.has-requests {
  background: var(--magenta);
  color: white;
}

.friends-modal {
  position: fixed;
  inset: 0;
  z-index: 7;
  display: grid;
  place-items: center;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  background: rgba(4, 6, 12, 0.66);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.friends-modal[hidden] {
  display: none !important;
}

.friends-card {
  width: min(520px, 100%);
  max-height: min(680px, calc(100vh - 24px));
  overflow: auto;
  border-radius: 22px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: rgba(10, 16, 32, 0.82);
  border: 1px solid rgba(61, 255, 243, 0.5);
  box-shadow:
    0 0 0 1px rgba(255, 77, 255, 0.28),
    0 16px 50px rgba(0, 0, 0, 0.45),
    inset 0 0 28px rgba(61, 255, 243, 0.06);
  touch-action: auto;
}

.friends-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.friends-head h2 {
  margin: 0;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 1.2rem;
  text-shadow: 0 0 12px rgba(61, 255, 243, 0.65);
}

.friends-head p,
.friend-empty,
.friend-note {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
}

#friendsClose {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(255, 77, 255, 0.55);
  background: rgba(0, 0, 0, 0.35);
  font-size: 1.3rem;
  line-height: 1;
}

.friend-tabs {
  display: flex;
  gap: 6px;
  overflow: auto;
}

.friend-tabs button {
  flex: 1 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 999px;
  border: 1px solid rgba(61, 255, 243, 0.28);
  background: rgba(0, 0, 0, 0.28);
  color: white;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 8px 10px;
  cursor: pointer;
  white-space: nowrap;
}

.friend-tabs button[aria-selected="true"] {
  border-color: var(--magenta);
  box-shadow: 0 0 14px rgba(255, 77, 255, 0.35);
  background: rgba(255, 77, 255, 0.12);
}

.friend-search {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.friend-search input {
  min-width: 0;
}

.friend-search button,
.friend-actions button,
.profile-back {
  border-radius: 999px;
  border: 1px solid rgba(61, 255, 243, 0.5);
  background: rgba(61, 255, 243, 0.1);
  color: white;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 8px 10px;
  cursor: pointer;
}

.friend-actions button.good,
.friend-search button {
  border-color: rgba(182, 255, 59, 0.65);
}

.friend-actions button.danger {
  border-color: rgba(255, 93, 122, 0.75);
  background: rgba(255, 93, 122, 0.1);
}

.friend-actions button:disabled {
  opacity: 0.55;
  cursor: default;
}

.friend-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.friend-row,
.friend-profile {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px 10px;
  align-items: center;
  padding: 10px;
  border-radius: 16px;
  border: 1px solid rgba(61, 255, 243, 0.28);
  background: rgba(0, 0, 0, 0.28);
  box-shadow: inset 0 0 16px rgba(155, 140, 255, 0.05);
}

.friend-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #071018;
  background: radial-gradient(circle at 35% 30%, #ffffff, var(--c, #3dfff3) 42%, #070910 80%);
  box-shadow: 0 0 12px var(--c, #3dfff3);
}

.friend-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.friend-meta strong,
.friend-profile strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.friend-meta small,
.friend-profile small {
  color: var(--muted);
  font-size: 11px;
}

.status-pill {
  justify-self: start;
  font-style: normal;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid transparent;
}

.status-online {
  color: #b6ff3b;
  border-color: rgba(182, 255, 59, 0.5);
}

.status-ingame {
  color: #ffd15c;
  border-color: rgba(255, 209, 92, 0.55);
}

.status-offline {
  color: rgba(244, 251, 255, 0.55);
  border-color: rgba(244, 251, 255, 0.2);
}

.friend-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.friend-profile {
  grid-template-columns: auto minmax(0, 1fr);
}

.friend-profile p {
  grid-column: 1 / -1;
  margin: 0;
}

.profile-back {
  grid-column: 1 / -1;
  justify-self: start;
}

@media (min-width: 560px) {
  .friend-row {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .friend-actions {
    grid-column: auto;
    justify-content: flex-end;
  }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 108px);
  transform: translateX(-50%) translateY(8px);
  z-index: 8;
  margin: 0;
  padding: 8px 12px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

@media (min-width: 800px) {
  .badge {
    min-width: 120px;
    padding: 10px 14px 12px;
    border-radius: 16px;
  }

  .badge strong {
    font-size: 1.45rem;
  }

  .leaderboard {
    width: 240px;
    padding: 14px 14px 12px;
  }

  .leaderboard li {
    font-size: 14px;
  }

  #boostBtn {
    width: 104px;
    height: 104px;
    font-size: 1rem;
  }

  .menu-card {
    padding: 26px 24px 20px;
    gap: 12px;
  }
}

@media (hover: hover) {
  .emotes button:hover,
  #mysteryBtn:hover,
  #playBtn:hover,
  .friends-launch:hover,
  .swatch:hover {
    transform: translateY(-1px);
  }

  #boostBtn:hover:not(:disabled) {
    transform: scale(1.05);
  }
}

@keyframes comboPulse {
  0%,
  100% {
    transform: scale(1);
    box-shadow: 0 0 10px rgba(255, 77, 255, 0.35);
  }
  50% {
    transform: scale(1.08);
    box-shadow: 0 0 22px rgba(255, 77, 255, 0.85);
  }
}

@keyframes rankPop {
  0% { transform: scale(0.9); }
  45% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

@keyframes shimmer {
  0% { background-position: 0% 50%; }
  100% { background-position: 180% 50%; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
