:root {
  --sk-blue: #2f6bff;
  --sk-blue-deep: #1e4fd6;
  --sk-green: #7dd63a;
  --sk-purple: #c44dff;
  --sk-asphalt: #6b6f76;
  --ink: #1a2240;
  --paper: #ffffff;
  --accent: #ff4d6d;
  --panel: rgba(255, 255, 255, 0.92);
  --font-display: "Fredoka", system-ui, sans-serif;
  --font-ui: "Nunito", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body, #app {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #87c8ff;
  color: var(--ink);
  font-family: var(--font-ui);
  user-select: none;
}

.screen { position: absolute; inset: 0; display: none; }
.screen.active { display: block; }

/* ——— Lobby ——— */
#lobby { position: relative; }

.lobby-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 50% 40% at 70% 20%, rgba(196, 77, 255, 0.35), transparent 60%),
    linear-gradient(180deg, #9fd4ff 0%, #b8e0ff 40%, #7dd63a 40%, #6bc92e 100%);
}

.lobby-bg::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 42%;
  background:
    repeating-linear-gradient(
      90deg,
      #6b6f76 0 48px,
      #757980 48px 96px
    );
  clip-path: polygon(0 18%, 100% 8%, 100% 100%, 0 100%);
  opacity: 0.95;
}

.lobby-layout {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 1.2rem;
  justify-content: center;
  align-items: flex-start;
  flex-wrap: wrap;
  padding: 4vh 1rem 2rem;
}

.lobby-panel, .leaderboard-panel, .live-panel, .waiting-card, .results-card, .scoreboard {
  background: var(--panel);
  border: 3px solid #fff;
  border-radius: 22px;
  box-shadow: 0 12px 0 rgba(30, 79, 214, 0.25), 0 20px 40px rgba(0, 0, 0, 0.18);
}

.lobby-panel {
  width: min(420px, 94vw);
  padding: 1.6rem 1.5rem 1.3rem;
}

.side-stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: min(300px, 94vw);
}

.leaderboard-panel,
.live-panel {
  width: 100%;
  padding: 1.2rem;
  max-height: 34vh;
  overflow: auto;
}

.leaderboard-panel h2,
.live-panel h2,
.room-list-wrap h2,
.params-card h3 {
  font-family: var(--font-display);
  color: var(--sk-blue);
  font-size: 1.15rem;
  margin-bottom: 0.7rem;
}

.live-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 0.4rem;
  margin-left: 0.35rem;
  border-radius: 999px;
  background: var(--sk-green);
  color: #143016;
  font-size: 0.85rem;
  vertical-align: middle;
}

#leaderboard,
#livePlayers {
  list-style: none;
  counter-reset: lb;
}
#leaderboard li,
#livePlayers li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.35rem;
  border-bottom: 2px solid rgba(47, 107, 255, 0.12);
  font-weight: 800;
  font-size: 0.9rem;
}
#leaderboard li::before {
  counter-increment: lb;
  content: counter(lb);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--sk-blue);
  color: #fff;
  font-size: 0.75rem;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
#livePlayers li::before { display: none; }
#leaderboard .lb-meta,
#livePlayers .lb-meta {
  margin-left: auto;
  color: var(--sk-blue-deep);
  font-size: 0.8rem;
}
#leaderboard .empty,
#livePlayers .empty { opacity: 0.55; justify-content: center; }
#leaderboard .empty::before { display: none; }

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.25);
  flex-shrink: 0;
}
.live-dot.waiting { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.25); }

.params-card {
  margin: 0.75rem 0 0.25rem;
  padding: 0.75rem 0.85rem;
  background: rgba(47, 107, 255, 0.08);
  border-radius: 14px;
  border: 2px solid rgba(47, 107, 255, 0.18);
}
.params-card.hidden { display: none; }
.params-card h3 {
  margin-bottom: 0.55rem;
  font-size: 0.95rem;
}
.params-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.45rem;
}
.param-pill {
  background: #fff;
  border-radius: 10px;
  padding: 0.4rem 0.35rem;
  text-align: center;
}
.param-pill .val {
  display: block;
  font-family: var(--font-display);
  font-size: 1.05rem;
  color: var(--sk-blue-deep);
  line-height: 1.1;
}
.param-pill .lbl {
  display: block;
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  opacity: 0.55;
  letter-spacing: 0.03em;
}

.logo {
  font-family: var(--font-display);
  font-size: clamp(2.5rem, 8vw, 3.4rem);
  font-weight: 700;
  text-align: center;
  color: var(--sk-blue);
  text-shadow: 0 3px 0 rgba(30, 79, 214, 0.2);
  line-height: 1;
}
.logo span { color: var(--accent); }

.tagline {
  text-align: center;
  margin: 0.45rem 0 1.2rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  color: var(--sk-blue);
  font-size: 0.85rem;
}

.profile-card {
  background: rgba(47, 107, 255, 0.1);
  border-radius: 12px;
  padding: 0.55rem 0.75rem;
  margin-bottom: 0.8rem;
  font-weight: 800;
  font-size: 0.85rem;
  color: var(--sk-blue-deep);
}
.profile-card.hidden { display: none; }

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.85rem;
}
.field span {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 900;
  color: var(--sk-blue);
}

input {
  font-family: var(--font-ui);
  font-weight: 800;
  font-size: 1rem;
  padding: 0.7rem 0.9rem;
  border-radius: 14px;
  border: 3px solid rgba(47, 107, 255, 0.25);
  background: #fff;
  color: var(--ink);
  outline: none;
}
input:focus { border-color: var(--sk-blue); }

.color-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 1.1rem;
  justify-content: center;
}

.swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
}
.swatch:hover { transform: scale(1.08); }
.swatch.selected { border-color: var(--sk-blue); outline: 2px solid #fff; }

.lobby-actions { display: flex; flex-direction: column; gap: 0.65rem; }
.join-row { display: flex; gap: 0.5rem; }
.join-row input {
  flex: 1;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  text-align: center;
}

.btn {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  padding: 0.75rem 1.15rem;
  border-radius: 14px;
  border: 3px solid rgba(47, 107, 255, 0.2);
  background: #eef3ff;
  color: var(--sk-blue-deep);
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(30, 79, 214, 0.2);
  transition: transform 0.1s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(30, 79, 214, 0.2); }
.btn.primary {
  background: linear-gradient(180deg, #4d84ff, var(--sk-blue));
  border-color: var(--sk-blue-deep);
  color: #fff;
}
.btn.ghost { background: transparent; box-shadow: none; }
.btn.active-ready {
  background: var(--sk-green);
  border-color: #4caf20;
  color: #14380a;
}

.room-list-wrap {
  margin-top: 1.2rem;
  border-top: 3px solid rgba(47, 107, 255, 0.12);
  padding-top: 0.9rem;
}
#roomList { list-style: none; max-height: 140px; overflow-y: auto; }
#roomList li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.6rem;
  border-radius: 12px;
  cursor: pointer;
  margin-bottom: 0.3rem;
  background: rgba(47, 107, 255, 0.08);
  font-weight: 800;
  font-size: 0.9rem;
}
#roomList li:hover { background: rgba(47, 107, 255, 0.18); }
#roomList .empty { opacity: 0.5; cursor: default; justify-content: center; }

.waiting {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(80, 150, 220, 0.45);
  backdrop-filter: blur(6px);
}
.waiting.hidden { display: none; }

.waiting-card {
  width: min(400px, 92vw);
  padding: 1.5rem;
}
.waiting-card h2 {
  font-family: var(--font-display);
  color: var(--sk-blue);
  margin-bottom: 0.3rem;
}
.code-line { font-weight: 800; margin-bottom: 1rem; color: #445; }
.code-line strong {
  font-family: var(--font-display);
  font-size: 1.45rem;
  letter-spacing: 0.12em;
  color: var(--sk-blue);
}
#playerList { list-style: none; margin-bottom: 1.1rem; }
#playerList li {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem 0;
  border-bottom: 2px solid rgba(47, 107, 255, 0.1);
  font-weight: 800;
}
.dot { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.badge-ready {
  margin-left: auto;
  font-size: 0.7rem;
  font-weight: 900;
  text-transform: uppercase;
  color: #2e7d32;
}
.waiting-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

/* ——— Game HUD (Smash Karts style) ——— */
#game { background: #9fd4ff; }
#c {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#hud { pointer-events: none; position: absolute; inset: 0; z-index: 2; }

.sk-hud-top {
  position: absolute;
  top: 0.85rem;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 0 1rem;
  gap: 1rem;
}

.sk-pill {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  background: linear-gradient(180deg, #4d84ff, var(--sk-blue));
  border: 3px solid #fff;
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.18);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.25rem;
  min-height: 46px;
}

.sk-heart {
  color: #ff4d6d;
  font-size: 1.35rem;
  filter: drop-shadow(0 1px 0 #fff);
  line-height: 1;
}

.sk-clock { font-size: 1.15rem; line-height: 1; }

.sk-track {
  width: min(160px, 28vw);
  height: 16px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 999px;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.9);
}

.sk-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #7dd63a, #b6ff6a);
  transition: width 0.12s;
}

.sk-hp-num {
  font-size: 0.85rem;
  min-width: 2rem;
  opacity: 0.95;
}

.sk-hud-side {
  position: absolute;
  top: 4.2rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.55rem;
}

.sk-kills-badge {
  background: rgba(255, 255, 255, 0.92);
  border: 3px solid var(--sk-blue);
  border-radius: 14px;
  padding: 0.3rem 0.7rem;
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--sk-blue-deep);
  box-shadow: 0 3px 0 rgba(30, 79, 214, 0.2);
}

.live-classement {
  width: min(200px, 46vw);
  background: rgba(255, 255, 255, 0.9);
  border: 3px solid #fff;
  border-radius: 14px;
  padding: 0.45rem 0.55rem 0.5rem;
  box-shadow: 0 4px 0 rgba(30, 79, 214, 0.18);
  color: var(--ink);
}
.live-classement h4 {
  font-family: var(--font-display);
  font-size: 0.85rem;
  color: var(--sk-blue);
  margin-bottom: 0.25rem;
}
.live-classement ol {
  list-style: none;
  margin: 0;
  padding: 0;
}
.live-classement li {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  font-size: 0.78rem;
  font-weight: 800;
  padding: 0.18rem 0;
  border-bottom: 1px solid rgba(26, 34, 64, 0.08);
}
.live-classement li:last-child { border-bottom: none; }
.live-classement .rank {
  color: var(--sk-purple);
  min-width: 1.2rem;
}
.live-classement .me { background: rgba(47, 107, 255, 0.12); border-radius: 6px; padding-left: 0.2rem; }
.live-classement .kd {
  margin-left: auto;
  opacity: 0.7;
  font-size: 0.72rem;
}

.hud-bottom {
  position: absolute;
  bottom: 3.4rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.8rem;
  width: min(420px, 92vw);
}

.weapon-slot {
  flex: 1;
  padding: 0.45rem 0.75rem;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 14px;
  border: 3px solid var(--sk-blue);
  text-align: center;
  font-weight: 900;
  color: var(--sk-blue-deep);
}
#weaponAmmo { display: block; font-size: 0.72rem; opacity: 0.7; }

.boost-wrap { width: 90px; }
.boost-bar {
  height: 14px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 999px;
  overflow: hidden;
  border: 2px solid #fff;
}
#boostFill {
  height: 100%;
  width: 50%;
  background: linear-gradient(90deg, #3ecfff, #7ef9ff);
  transition: width 0.1s;
}

.sk-banner {
  position: absolute;
  bottom: 0.7rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--sk-blue);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  padding: 0.45rem 1.4rem;
  border-radius: 10px;
  border: 3px solid #fff;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.2);
  white-space: nowrap;
}

/* Overhead nameplates */
.name-plate {
  position: absolute;
  transform: translate(-50%, -100%);
  text-align: center;
  pointer-events: none;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.35));
}
.nl-name {
  font-family: var(--font-ui);
  font-weight: 900;
  font-size: 16px;
  color: #fff;
  text-shadow: 0 1px 0 #000, 0 -1px 0 #000, 1px 0 0 #000, -1px 0 0 #000, 0 0 8px rgba(0,0,0,.55);
  line-height: 1.1;
  margin-bottom: 2px;
}
.nl-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.nl-lvl {
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 5px;
  background: #fff;
  color: var(--sk-blue-deep);
  font-size: 11px;
  font-weight: 900;
  display: grid;
  place-items: center;
  border: 2px solid var(--sk-blue);
}
.nl-hp-track {
  width: 56px;
  height: 8px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.7);
}
.nl-hp {
  height: 100%;
  background: linear-gradient(90deg, #3ecfff, #6ad4ff);
  border-radius: 999px;
}

#killFeed {
  position: absolute;
  top: 4.5rem;
  left: 1rem;
  width: 200px;
  font-size: 0.78rem;
  font-weight: 800;
}
#killFeed div {
  margin-bottom: 0.25rem;
  padding: 0.25rem 0.5rem;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 8px;
  color: var(--ink);
  border: 2px solid rgba(47, 107, 255, 0.25);
}

.overlay-msg {
  position: absolute;
  top: 42%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-display);
  font-size: 2rem;
  color: #fff;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}
.overlay-msg.hidden { display: none; }

.scoreboard {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 1.1rem 1.4rem;
  min-width: 260px;
  pointer-events: none;
}
.scoreboard.hidden { display: none; }
.scoreboard h3 {
  font-family: var(--font-display);
  color: var(--sk-blue);
  margin-bottom: 0.5rem;
  text-align: center;
}
.scoreboard table { width: 100%; border-collapse: collapse; }
.scoreboard th, .scoreboard td {
  text-align: left;
  padding: 0.3rem 0.4rem;
  font-weight: 800;
}
.scoreboard th {
  opacity: 0.55;
  font-size: 0.72rem;
  text-transform: uppercase;
}

#controlsHint {
  position: absolute;
  bottom: 3.5rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.7rem;
  opacity: 0.55;
  color: #fff;
  text-shadow: 0 1px 2px #000;
  white-space: nowrap;
}

.results {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(80, 150, 220, 0.55);
  pointer-events: auto;
}
.results.hidden { display: none; }
.results-card {
  width: min(380px, 92vw);
  padding: 1.6rem;
  text-align: center;
}
.results-card h2 {
  font-family: var(--font-display);
  font-size: 2rem;
  margin-bottom: 1rem;
  color: var(--sk-blue);
}
#resultsList {
  list-style: none;
  text-align: left;
  margin-bottom: 1.1rem;
}
#resultsList li {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem 0;
  border-bottom: 2px solid rgba(47, 107, 255, 0.12);
  font-weight: 800;
}

.hidden { display: none !important; }

@media (max-width: 700px) {
  .side-stack { order: 3; width: min(420px, 94vw); }
  .leaderboard-panel, .live-panel { max-height: 200px; }
  .sk-banner { font-size: 0.75rem; padding: 0.35rem 0.8rem; }
  #controlsHint { display: none; }
  .sk-track { width: 100px; }
}
