:root {
  --bg: #070a14;
  --panel: rgba(16, 22, 44, 0.92);
  --panel-solid: #111831;
  --line: #26305a;
  --text: #eef2ff;
  --muted: #9aa6d1;
  --accent: #5fb0ff;
  --accent-2: #8b7bff;
  --good: #46e39a;
  --bad: #ff5d73;
  --gold: #ffd43b;
  --radius: 12px;
  --header-h: 48px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a {
  color: var(--accent);
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  touch-action: manipulation;
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.page {
  padding: 8px 8px 40px;
}

/* ---------- Game layout ---------- */

.game-root {
  position: relative;
  margin: 0 auto;
  width: 100%;
  max-width: 1400px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  background: #0b1020;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.stage {
  position: relative;
  width: 100%;
  height: calc(100vh - var(--header-h) - 18px);
  height: calc(100dvh - var(--header-h) - 18px);
  min-height: 440px;
  max-height: 900px;
}

.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ---------- HUD ---------- */

.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hud-me {
  position: absolute;
  left: 10px;
  top: 10px;
  padding: 6px 12px 8px;
  background: rgba(8, 12, 28, 0.62);
  border: 1px solid rgba(120, 150, 255, 0.18);
  border-radius: 12px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.hud-pct {
  font-size: 30px;
  font-weight: 900;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
}

.hud-pct small {
  font-size: 16px;
  margin-left: 2px;
  color: var(--muted);
}

.hud-pct.bump {
  animation: bump 0.35s ease-out;
}

@keyframes bump {
  0% {
    transform: scale(1.25);
    color: var(--good);
  }
  100% {
    transform: scale(1);
  }
}

.hud-sub {
  display: flex;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.hud-sub b {
  color: var(--text);
}

.hud-rank {
  color: var(--gold);
  font-weight: 800;
}

.board {
  position: absolute;
  right: 10px;
  top: 10px;
  margin: 0;
  padding: 6px 8px;
  list-style: none;
  min-width: 170px;
  background: rgba(8, 12, 28, 0.62);
  border: 1px solid rgba(120, 150, 255, 0.18);
  border-radius: 12px;
  font-size: 13px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.board li {
  display: grid;
  grid-template-columns: 18px 10px 1fr auto;
  align-items: center;
  gap: 6px;
  padding: 2px 2px;
  font-variant-numeric: tabular-nums;
}

.board li.me {
  color: #fff;
  font-weight: 800;
}

.board li.gap {
  display: block;
  text-align: center;
  color: var(--muted);
  line-height: 0.6;
  padding: 0 0 4px;
}

.board .rk {
  color: var(--muted);
  text-align: right;
}

.board .sw {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.board .nm {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 110px;
}

.board .pc {
  color: var(--muted);
}

.board li.me .pc {
  color: var(--text);
}

.hud-buttons {
  position: absolute;
  left: 10px;
  bottom: 10px;
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid rgba(120, 150, 255, 0.25);
  background: rgba(8, 12, 28, 0.7);
  display: grid;
  place-items: center;
  padding: 0;
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

.net-note {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  font-size: 12px;
  color: var(--muted);
  background: rgba(8, 12, 28, 0.7);
  border: 1px solid rgba(120, 150, 255, 0.18);
  padding: 4px 10px;
  border-radius: 999px;
  pointer-events: none;
  white-space: nowrap;
  z-index: 3;
}

.net-note .dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 6px;
  background: var(--muted);
  vertical-align: 1px;
}

.net-note.online .dot {
  background: var(--good);
  box-shadow: 0 0 6px var(--good);
}

/* ---------- Toasts ---------- */

.toasts {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  z-index: 4;
  width: max-content;
  max-width: 90%;
}

.toast {
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(10, 14, 32, 0.88);
  border: 1px solid rgba(120, 150, 255, 0.3);
  font-weight: 700;
  font-size: 14px;
  animation: toastIn 0.25s ease-out, toastOut 0.4s ease-in forwards;
  animation-delay: 0s, var(--life, 2.4s);
  text-align: center;
}

.toast.gold {
  border-color: var(--gold);
  color: var(--gold);
}

.toast.good {
  border-color: var(--good);
  color: var(--good);
}

.toast.bad {
  border-color: var(--bad);
  color: #ffc2cb;
}

@keyframes toastIn {
  from {
    transform: translateY(-10px) scale(0.9);
    opacity: 0;
  }
}

@keyframes toastOut {
  to {
    transform: translateY(-8px);
    opacity: 0;
  }
}

/* ---------- Joystick ---------- */

.joy {
  position: absolute;
  width: 110px;
  height: 110px;
  margin: -55px 0 0 -55px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  background: radial-gradient(circle, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
  pointer-events: none;
  z-index: 2;
}

.joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}

/* ---------- Overlay screens ---------- */

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 14px;
  z-index: 5;
  overflow-y: auto;
  background: radial-gradient(ellipse at center, rgba(7, 10, 20, 0.45), rgba(7, 10, 20, 0.82));
}

.overlay.show {
  display: flex;
}

.overlay.dim {
  background: rgba(7, 10, 20, 0.55);
}

.card {
  width: min(560px, 100%);
  max-height: 100%;
  overflow-y: auto;
  margin: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: cardIn 0.25s ease-out;
}

@keyframes cardIn {
  from {
    transform: translateY(12px) scale(0.98);
    opacity: 0;
  }
}

.logo {
  font-size: clamp(38px, 9vw, 58px);
  font-weight: 900;
  letter-spacing: 3px;
  text-align: center;
  margin: 2px 0 0;
  line-height: 1;
  background: linear-gradient(100deg, #5fb0ff 0%, #a78bfa 45%, #ff6b9b 80%, #ffd43b 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.5));
}

.tagline {
  text-align: center;
  color: var(--muted);
  margin: 6px 0 14px;
  font-size: 15px;
}

.row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.name-row input {
  flex: 1;
  min-width: 0;
  padding: 12px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #0a0f22;
  font-size: 16px;
  font-weight: 700;
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 12px 18px;
  font-weight: 800;
  background: #1c2550;
  border: 1px solid var(--line);
}

.btn:hover {
  filter: brightness(1.12);
}

.btn:focus-visible,
.icon-btn:focus-visible,
.skin:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.btn-play {
  background: linear-gradient(180deg, #5fb0ff, #3d7bff);
  border: 0;
  color: #fff;
  font-size: 20px;
  padding: 14px 26px;
  box-shadow: 0 6px 0 #2549a8, 0 10px 24px rgba(61, 123, 255, 0.35);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
  transition: transform 0.08s;
}

.btn-play:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 #2549a8;
}

.btn-wide {
  width: 100%;
}

.btn-row {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.btn-row .btn {
  flex: 1;
}

.section-title {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--muted);
  margin: 16px 0 8px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.section-title .hint {
  letter-spacing: 0;
  text-transform: none;
  font-weight: 600;
}

.level-box {
  margin-top: 14px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  align-items: center;
}

.level-badge {
  grid-row: span 2;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 20px;
  background: linear-gradient(160deg, #8b7bff, #3d7bff);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.25);
}

.level-meta {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
  gap: 8px;
}

.level-meta b {
  color: var(--text);
}

.bar {
  height: 12px;
  background: #0a0f22;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}

.bar-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #5fb0ff, #a78bfa);
  transition: width 0.9s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.bar.near .bar-fill {
  background: linear-gradient(90deg, #a78bfa, #ffd43b);
  box-shadow: 0 0 12px rgba(255, 212, 59, 0.6);
}

.bar.small {
  height: 7px;
}

.streak {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  margin-top: 10px;
}

.streak svg {
  width: 18px;
  height: 18px;
  flex: none;
}

.streak b {
  color: #ffb347;
}

.missions {
  display: grid;
  gap: 8px;
}

.mission {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  gap: 4px 10px;
  align-items: center;
  font-size: 14px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.mission .check {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 2px solid var(--line);
  grid-row: span 2;
  display: grid;
  place-items: center;
}

.mission.done .check {
  background: var(--good);
  border-color: var(--good);
}

.mission.done .check::after {
  content: '';
  width: 5px;
  height: 10px;
  border: solid #07220f;
  border-width: 0 3px 3px 0;
  transform: rotate(45deg) translate(-1px, -1px);
}

.mission.done .mtext {
  color: var(--muted);
  text-decoration: line-through;
}

.mission .mxp {
  font-size: 12px;
  color: var(--gold);
  font-weight: 800;
}

.mission .bar {
  grid-column: 2 / span 2;
}

.skins {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 8px;
}

.skin {
  position: relative;
  aspect-ratio: 1;
  border-radius: 12px;
  border: 2px solid transparent;
  background: #0a0f22;
  padding: 0;
  overflow: hidden;
}

.skin canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.skin.selected {
  border-color: #fff;
  box-shadow: 0 0 0 3px rgba(95, 176, 255, 0.5);
}

.skin.locked canvas {
  filter: grayscale(0.9) brightness(0.45);
}

.skin .lock {
  position: absolute;
  inset: auto 0 3px 0;
  font-size: 10px;
  font-weight: 800;
  color: #cbd5ff;
  text-shadow: 0 1px 2px #000;
}

.skin-name {
  font-size: 13px;
  color: var(--muted);
  margin-top: 6px;
  min-height: 18px;
}

.link-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 14px;
  flex-wrap: wrap;
}

.link-btn {
  background: none;
  border: 0;
  color: var(--accent);
  font-weight: 700;
  padding: 6px 8px;
  font-size: 14px;
}

.status-line {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin-top: 10px;
}

/* ---------- Death / results ---------- */

.results h2 {
  margin: 0;
  font-size: 26px;
  text-align: center;
}

.results .cause {
  text-align: center;
  color: var(--muted);
  margin: 4px 0 12px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.stat {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 10px 6px;
  text-align: center;
}

.stat .v {
  font-size: 22px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.stat .k {
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
}

.near-miss {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 179, 71, 0.1);
  border: 1px solid rgba(255, 179, 71, 0.45);
  color: #ffd29a;
  font-weight: 700;
  text-align: center;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-top: 12px;
}

.badge {
  font-size: 12px;
  font-weight: 800;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.badge.gold {
  color: var(--gold);
  border-color: rgba(255, 212, 59, 0.5);
}

.badge.good {
  color: var(--good);
  border-color: rgba(70, 227, 154, 0.45);
}

.xp-gain {
  margin-top: 14px;
}

.xp-gain .level-meta {
  margin-bottom: 4px;
}

.kbd-hint {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}

.ach-list {
  display: grid;
  gap: 6px;
}

.ach {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 2px 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  opacity: 0.55;
}

.ach.got {
  opacity: 1;
  background: rgba(255, 212, 59, 0.07);
}

.ach .ico {
  grid-row: span 2;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: #1c2550;
  display: grid;
  place-items: center;
  font-weight: 900;
  color: var(--muted);
}

.ach.got .ico {
  background: var(--gold);
  color: #3a2a00;
}

.ach .an {
  font-weight: 800;
}

.ach .ad {
  font-size: 13px;
  color: var(--muted);
}

.today-board {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 14px;
}

.today-board li {
  display: flex;
  justify-content: space-between;
  padding: 3px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.today-board li.me {
  color: var(--gold);
  font-weight: 800;
}

/* ---------- Ads & about ---------- */

.ad-slot:empty {
  display: none;
}

.ad-slot {
  margin: 12px auto;
  max-width: 1400px;
  min-height: 90px;
}

.about {
  max-width: 820px;
  margin: 26px auto 0;
  padding: 0 8px;
  line-height: 1.6;
  color: #d5dcf5;
}

.about h1 {
  font-size: 28px;
  margin: 0 0 8px;
}

.about h2 {
  font-size: 20px;
  margin: 22px 0 6px;
}

.about li {
  margin: 6px 0;
}

kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  font-size: 12px;
  background: #0d1330;
}

/* ---------- Small screens ---------- */

@media (max-width: 600px) {
  .page {
    padding: 0 0 30px;
  }
  .game-root {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }
  .stage {
    height: calc(100vh - var(--header-h));
    height: calc(100dvh - var(--header-h));
    min-height: 400px;
  }
  .hud-pct {
    font-size: 24px;
  }
  .hud-me {
    left: 6px;
    top: 6px;
    padding: 4px 9px 6px;
  }
  .board {
    right: 6px;
    top: 6px;
    min-width: 132px;
    font-size: 12px;
    padding: 4px 6px;
  }
  .board .nm {
    max-width: 72px;
  }
  .card {
    padding: 14px;
    border-radius: 16px;
  }
  .stats {
    grid-template-columns: repeat(2, 1fr);
  }
  .about {
    padding: 0 16px;
  }
}
