:root {
  --bg: #05070d;
  --panel: rgba(14, 19, 34, 0.72);
  --panel-solid: #0f1424;
  --line: rgba(140, 170, 255, 0.14);
  --text: #eef2ff;
  --muted: #8e9bbf;
  --accent: #33e07a;
  --accent2: #2ee6c8;
  --hot: #ff3b5c;
  --gold: #ffd23a;
  --radius: 18px;
  font-family: Nunito, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none; touch-action: none;
}
[hidden] { display: none !important; }
#game { position: fixed; inset: 0; display: block; cursor: crosshair; }
.vignette {
  position: fixed; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.55) 100%);
}

/* ---------- buttons & inputs ---------- */
.btn {
  font: inherit; font-weight: 800; letter-spacing: 0.02em; border: 0; cursor: pointer; color: var(--text);
  border-radius: 14px; padding: 13px 18px; transition: transform .08s ease, filter .15s ease, background .15s;
  width: 100%;
}
.btn:active { transform: scale(0.97); }
.btn.primary {
  color: #04140b; background: linear-gradient(180deg, #5bf59a, #20c463);
  box-shadow: 0 8px 28px rgba(51, 224, 122, 0.35), inset 0 1px 0 rgba(255,255,255,.5);
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.big { font-size: 22px; padding: 16px; font-weight: 900; letter-spacing: 0.08em; }
.btn.ghost { background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line); }
.btn.ghost:hover { background: rgba(255, 255, 255, 0.1); }
.btn.danger { color: #ff8a9e; }
.btn:disabled { opacity: .5; cursor: default; }

.icon-btn {
  width: 44px; height: 44px; flex: none; display: grid; place-items: center; cursor: pointer;
  border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,.06); color: var(--text);
}
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { background: rgba(255,255,255,.12); }

input {
  font: inherit; font-weight: 800; color: var(--text); background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line); border-radius: 12px; padding: 13px 14px; outline: none; width: 100%;
  -webkit-user-select: text; user-select: text;
}
input:focus { border-color: rgba(51, 224, 122, 0.7); box-shadow: 0 0 0 3px rgba(51, 224, 122, 0.15); }
kbd {
  font: inherit; font-size: 11px; font-weight: 800; padding: 2px 6px; border-radius: 6px;
  background: rgba(255,255,255,.08); border: 1px solid var(--line); color: var(--text);
}

/* ---------- lobby ---------- */
.screen { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; overflow-y: auto; touch-action: pan-y; }
.all-games-link {
  position: absolute; top: max(16px, env(safe-area-inset-top)); left: 16px; z-index: 2;
  color: var(--muted); text-decoration: none; font-weight: 800; padding: 8px;
}
.all-games-link:hover { color: var(--text); }
.lobby-card {
  width: min(440px, 100%); padding: 26px 24px 20px; border-radius: 26px;
  background: linear-gradient(180deg, rgba(20, 27, 48, 0.86), rgba(10, 14, 26, 0.9));
  border: 1px solid var(--line); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  display: flex; flex-direction: column; gap: 14px;
}
.brand { text-align: center; }
.brand h1 { margin: 0; font-size: 50px; line-height: 1; font-weight: 900; letter-spacing: 0.04em; }
.brand .b1 { color: #fff; text-shadow: 0 0 18px rgba(46, 230, 200, .8), 0 0 42px rgba(46, 230, 200, .45); }
.brand .b2 {
  margin-left: 8px; background: linear-gradient(90deg, #33e07a, #2ee6c8, #36b7ff, #9b5cff, #ff5fa8);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 14px rgba(155, 92, 255, .5));
}
.brand p { margin: 8px 0 0; color: var(--muted); font-weight: 700; }

.skin-picker { display: flex; align-items: center; gap: 8px; }
.skin-stage {
  flex: 1; position: relative; border-radius: 16px; overflow: hidden; height: 112px;
  background: radial-gradient(ellipse at center, rgba(46,230,200,.10), transparent 70%), rgba(0,0,0,.3);
  border: 1px solid var(--line);
}
.skin-stage canvas { width: 100%; height: 100%; display: block; }
.skin-name {
  position: absolute; left: 0; right: 0; bottom: 6px; text-align: center; font-weight: 900; font-size: 13px;
  letter-spacing: .14em; text-transform: uppercase; color: var(--muted);
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12px; font-weight: 800; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; padding-left: 2px; }

.invite {
  text-align: center; padding: 10px; border-radius: 12px; font-weight: 700;
  background: rgba(54, 183, 255, .12); border: 1px solid rgba(54, 183, 255, .35); color: #bfe6ff;
}
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .1em; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.friends { display: flex; flex-direction: column; gap: 10px; }
.create-row, .join-row { display: flex; gap: 10px; align-items: center; }
.create-row .btn { flex: 1.3; }
.bots { flex: 1; display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 800; color: var(--muted); }
.bots input { padding: 0; accent-color: var(--accent); border: 0; background: none; min-width: 60px; }
.bots b { color: var(--text); min-width: 18px; text-align: right; }
.join-row input { text-transform: uppercase; letter-spacing: .25em; text-align: center; }
.join-row .btn { width: 110px; flex: none; }
.err { margin: 0; min-height: 1em; color: #ff8a9e; font-weight: 700; text-align: center; font-size: 14px; }
.controls-help { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 14px; font-size: 12px; color: var(--muted); font-weight: 700; }
.net-status { position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%); font-size: 12px; color: var(--muted); font-weight: 700; }
.net-status.ok { color: #6ef0a5; }
.net-status.bad { color: #ff8a9e; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud button, #hud .room-pill { pointer-events: auto; }
.topbar { position: absolute; top: max(12px, env(safe-area-inset-top)); left: 12px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; max-width: calc(100% - 300px); }
.room-pill {
  display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 14px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--line); font-weight: 800; font-size: 14px; backdrop-filter: blur(8px);
}
.room-pill.small { color: var(--muted); font-size: 13px; }
.room-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.mini {
  font: inherit; font-size: 12px; font-weight: 800; cursor: pointer; color: #04140b; border: 0; border-radius: 8px;
  padding: 6px 10px; background: var(--accent2);
}
.hud-btn { background: var(--panel); backdrop-filter: blur(8px); }
#soundBtn .snd-off { display: none; }
#soundBtn.muted .snd-on { display: none; }
#soundBtn.muted .snd-off { display: block; }

.feed { position: absolute; top: 66px; left: 12px; display: flex; flex-direction: column; gap: 4px; }
.feed div {
  font-size: 13px; font-weight: 800; padding: 5px 10px; border-radius: 8px; background: rgba(0,0,0,.4); color: var(--muted);
  animation: feedIn .25s ease, feedOut .5s ease 4.5s forwards; width: fit-content;
}
.feed b { color: var(--text); }
.feed .me { color: var(--gold); }
@keyframes feedIn { from { opacity: 0; transform: translateX(-10px); } }
@keyframes feedOut { to { opacity: 0; } }

.leaderboard {
  position: absolute; top: max(12px, env(safe-area-inset-top)); right: 12px; width: 250px; padding: 12px 14px 10px;
  border-radius: 16px; background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(8px);
}
.leaderboard h3 { margin: 0 0 6px; font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.leaderboard ol { list-style: none; margin: 0; padding: 0; }
.leaderboard li, .lb-you {
  display: grid; grid-template-columns: 30px 1fr auto; gap: 6px; font-size: 14px; font-weight: 800; line-height: 1.6;
  color: rgba(238,242,255,.8);
}
.leaderboard li .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard li .r { color: var(--muted); }
.leaderboard li:nth-child(1) .r { color: var(--gold); }
.leaderboard li:nth-child(2) .r { color: #d7e0f5; }
.leaderboard li:nth-child(3) .r { color: #ff9e7a; }
.leaderboard li .m, .lb-you .m { font-variant-numeric: tabular-nums; }
.leaderboard li.you, .lb-you { color: var(--accent); }
.lb-you { margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--line); }

.stats { position: absolute; left: 16px; bottom: max(16px, env(safe-area-inset-bottom)); text-shadow: 0 2px 8px rgba(0,0,0,.8); }
.stat-len { font-size: 26px; font-weight: 900; }
.stat-len b { color: #fff; }
.stat-sub { font-size: 14px; font-weight: 800; color: var(--muted); }
.stat-sub b { color: var(--text); }

.boost-meter {
  position: absolute; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(8px); font-size: 12px; font-weight: 800; color: var(--muted);
  transition: box-shadow .2s, border-color .2s;
}
.boost-meter svg { width: 18px; height: 18px; fill: var(--muted); }
.boost-meter .bar { width: 120px; height: 8px; border-radius: 99px; background: rgba(255,255,255,.08); overflow: hidden; }
.boost-meter .bar i { display: block; height: 100%; width: 0%; border-radius: inherit; background: linear-gradient(90deg, #2ee6c8, #33e07a); transition: width .2s; }
.boost-meter.active { border-color: rgba(255, 210, 58, .7); box-shadow: 0 0 24px rgba(255, 210, 58, .35); color: var(--gold); }
.boost-meter.active svg { fill: var(--gold); }
.boost-meter.active .bar i { background: linear-gradient(90deg, #ffd23a, #ff7a2f); }
.boost-meter.empty { opacity: .55; }
.buffs {
  position: absolute; left: 50%; bottom: calc(max(18px, env(safe-area-inset-bottom)) + 48px); transform: translateX(-50%);
  display: flex; gap: 8px; pointer-events: none;
}
.buff {
  display: flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--c); box-shadow: 0 0 16px color-mix(in srgb, var(--c) 45%, transparent);
  font-size: 12px; font-weight: 800; color: #fff;
}
.buff b { color: var(--c); }

#minimap {
  position: absolute; right: 14px; bottom: max(14px, env(safe-area-inset-bottom)); width: 150px; height: 150px; border-radius: 50%;
}

.toast {
  position: absolute; top: 18%; left: 50%; transform: translate(-50%, -10px); opacity: 0; pointer-events: none;
  font-size: 24px; font-weight: 900; color: var(--gold); text-shadow: 0 0 18px rgba(255,210,58,.6), 0 3px 10px rgba(0,0,0,.8);
  transition: opacity .25s, transform .25s; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* touch controls */
.joystick, .boost-btn { display: none; }
body.touch .boost-btn {
  display: grid; place-items: center; position: absolute; right: 22px; bottom: calc(190px + env(safe-area-inset-bottom));
  width: 84px; height: 84px; border-radius: 50%; pointer-events: auto; border: 2px solid rgba(255,210,58,.45);
  background: radial-gradient(circle, rgba(255,210,58,.25), rgba(14,19,34,.7)); touch-action: none;
}
body.touch .boost-btn svg { width: 36px; height: 36px; fill: var(--gold); }
body.touch .boost-btn.on { transform: scale(.94); box-shadow: 0 0 34px rgba(255,210,58,.7); background: radial-gradient(circle, rgba(255,210,58,.6), rgba(14,19,34,.7)); }
body.touch .joystick {
  display: block; position: absolute; width: 128px; height: 128px; margin: -64px 0 0 -64px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.18); background: rgba(255,255,255,.05); opacity: 0; transition: opacity .15s;
}
body.touch .joystick.on { opacity: 1; }
.knob {
  position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; border-radius: 50%; transform: translate(-50%, -50%);
  background: rgba(255,255,255,.35); box-shadow: 0 0 20px rgba(255,255,255,.25);
}
body.touch .boost-meter span { display: none; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: rgba(3, 5, 10, 0.55);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); animation: fade .3s ease; overflow-y: auto; touch-action: pan-y;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  width: min(400px, 100%); padding: 26px 22px 20px; border-radius: 26px; text-align: center;
  background: linear-gradient(180deg, rgba(22, 29, 52, 0.95), rgba(11, 15, 28, 0.97));
  border: 1px solid var(--line); box-shadow: 0 30px 80px rgba(0,0,0,.6); display: flex; flex-direction: column; gap: 10px;
  animation: pop .35s cubic-bezier(.2,1.4,.4,1);
}
@keyframes pop { from { transform: scale(.9); opacity: 0; } }
.modal h2 { margin: 0 0 4px; font-size: 30px; font-weight: 900; }
.modal p { margin: 0 0 8px; color: var(--muted); font-weight: 700; }
.over-kicker { color: var(--muted); font-weight: 800; font-size: 14px; }
.over-kicker b { color: var(--hot); }
.over-title {
  font-size: 46px !important; letter-spacing: .06em; line-height: 1.05;
  background: linear-gradient(180deg, #fff, #ff8a9e 55%, #ff3b5c); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 18px rgba(255, 59, 92, .45));
}
.over-hero { padding: 14px; border-radius: 18px; background: rgba(51,224,122,.08); border: 1px solid rgba(51,224,122,.3); }
.over-hero span { display: block; font-size: 12px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.over-hero b { display: block; font-size: 48px; font-weight: 900; color: #6ef0a5; line-height: 1.1; font-variant-numeric: tabular-nums; }
.over-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-bottom: 6px; }
.over-grid div { padding: 10px 6px; border-radius: 14px; background: rgba(255,255,255,.04); border: 1px solid var(--line); }
.over-grid span { display: block; font-size: 10px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; min-height: 2.4em; }
.over-grid b { font-size: 20px; font-weight: 900; font-variant-numeric: tabular-nums; }

/* ---------- responsive ---------- */
@media (max-width: 720px) {
  .brand h1 { font-size: 40px; }
  .topbar { max-width: calc(100% - 170px); }
  .room-pill { height: 38px; padding: 0 10px; font-size: 12px; }
  .room-pill.small { display: none; }
  .icon-btn.hud-btn { width: 38px; height: 38px; }
  .leaderboard { width: 150px; padding: 8px 10px; }
  .leaderboard h3 { font-size: 10px; }
  .leaderboard li, .lb-you { font-size: 11px; grid-template-columns: 20px 1fr auto; line-height: 1.5; }
  .leaderboard li:nth-child(n+6) { display: none; }
  .stat-len { font-size: 20px; }
  .stat-sub { font-size: 12px; }
  #minimap { width: 110px; height: 110px; }
  .boost-meter { bottom: auto; top: calc(60px + env(safe-area-inset-top)); left: 12px; transform: none; padding: 6px 10px; }
  .boost-meter .bar { width: 70px; }
  .buffs { bottom: auto; top: calc(100px + env(safe-area-inset-top)); left: 12px; transform: none; }
  .feed { top: 104px; }
  .feed div { font-size: 11px; }
  .over-title { font-size: 38px !important; }
  .over-hero b { font-size: 40px; }
}
