:root {
  --gold: rgb(185, 159, 85);
  --gold-bright: #e8ce86;
  --gold-dim: rgba(185, 159, 85, 0.35);
  --gold-faint: rgba(185, 159, 85, 0.12);
  --ink: #050505;
  --panel: rgba(12, 11, 9, 0.62);
  --line: rgba(232, 206, 134, 0.14);
  --text: #efe9dc;
  --muted: #9b9486;
  --ok: #8fd18f;
  --warn: #e8b85a;
  --err: #ef7d6b;
  --radius: 14px;
  --sans: "Space Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: var(--mono); }
.hidden { display: none !important; }

#unity-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  background: var(--ink);
  outline: none;
  cursor: none;
}
body.is-menu #unity-canvas { cursor: default; }

/* ---------- Brand ---------- */
.brand {
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
  font-weight: 700;
  letter-spacing: 0.18em;
  font-size: 15px;
  user-select: none;
}
.brand__poly { color: var(--gold); }
.brand__pong { color: var(--text); }
.brand__tag {
  margin-left: 10px;
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.brand--big { font-size: clamp(28px, 6vw, 52px); }
.brand--card { font-size: 26px; margin-bottom: 6px; }

/* ---------- Glass ---------- */
.glass {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(14px) saturate(120%);
  -webkit-backdrop-filter: blur(14px) saturate(120%);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

/* ---------- Loader ---------- */
.loader {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 22px;
  background: radial-gradient(ellipse at center, #14110b 0%, var(--ink) 70%);
  z-index: 50;
  transition: opacity 0.5s ease;
}
.loader.is-done { opacity: 0; pointer-events: none; }
.loader__bar {
  width: min(320px, 70vw);
  height: 2px;
  background: var(--gold-faint);
  border-radius: 2px;
  overflow: hidden;
}
.loader__fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--gold), var(--gold-bright));
  box-shadow: 0 0 12px var(--gold);
  transition: width 0.2s ease;
}
.loader__text { font-size: 11px; color: var(--muted); letter-spacing: 0.08em; }

/* ---------- Top bar & HUD ---------- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 18px 20px;
  pointer-events: none;
  z-index: 10;
}
.topbar > * { pointer-events: auto; }

.hud { padding: 12px 14px; width: 308px; display: grid; gap: 10px; }
.hud__row { display: flex; align-items: center; gap: 8px; }
.hud__row .btn { margin-left: auto; }
.hud__grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.hud__grid label { display: block; font-size: 9px; letter-spacing: 0.14em; color: var(--muted); }
.hud__grid strong { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; }
.hud__url { font-size: 10.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spark { width: 100%; height: 44px; display: block; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px 4px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
}
.pill i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.pill b { font-weight: 600; letter-spacing: 0.02em; }
.pill--ghost { color: var(--muted); font-size: 10.5px; }
.pill.is-connected i { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.pill.is-connecting i { background: var(--warn); animation: blink 0.9s infinite; }
.pill.is-disconnected i { background: var(--err); }
.pill--tls { color: var(--gold-bright); border-color: var(--gold-dim); }

/* ---------- Scoreboard ---------- */
.scoreboard {
  position: fixed;
  left: 20px;
  top: 64px;
  width: 210px;
  padding: 12px 12px 8px;
  z-index: 10;
}
.scoreboard h3 {
  margin: 0 0 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}
.scoreboard ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.scoreboard li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 9px;
  border-radius: 9px;
  font-size: 14px;
  transition: background 0.3s ease;
}
.scoreboard li .rank { font-family: var(--mono); font-size: 10px; color: var(--muted); width: 14px; }
.scoreboard li .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scoreboard li .score { font-family: var(--mono); font-weight: 600; }
.scoreboard li.me { background: var(--gold-faint); }
.scoreboard li.me .name, .scoreboard li.me .score { color: var(--gold-bright); }
.scoreboard li.bump .score { animation: bump 0.6s ease; }

/* ---------- Labels ---------- */
.labels { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.label {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--text);
  opacity: 0.75;
  white-space: nowrap;
  text-shadow: 0 0 10px rgba(0, 0, 0, 0.9);
  transition: opacity 0.3s ease;
}
.label b { font-family: var(--mono); margin-left: 6px; color: var(--muted); }
.label.me { color: var(--gold-bright); opacity: 1; }
.label.me b { color: var(--gold); }
.labels.is-morphing .label { opacity: 0; }

/* ---------- Banner ---------- */
.banner {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  z-index: 6;
  display: grid;
  justify-items: center;
  gap: 10px;
}
.banner .btn { pointer-events: auto; }
.banner__big {
  font-size: clamp(56px, 12vw, 120px);
  font-weight: 700;
  line-height: 1;
  color: var(--gold-bright);
  text-shadow: 0 0 30px rgba(185, 159, 85, 0.55);
}
.banner__big.tick { animation: pop 0.5s ease; }
.banner__big.is-text { font-size: clamp(22px, 4vw, 34px); letter-spacing: 0.06em; }
.banner__small { font-size: 13px; color: var(--muted); letter-spacing: 0.08em; }

/* ---------- Connect modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(ellipse at center, rgba(20, 17, 11, 0.55), rgba(0, 0, 0, 0.8));
  z-index: 30;
}
.card { width: min(420px, 100%); padding: 28px 26px 22px; display: grid; gap: 14px; }
.card__lead { margin: 0 0 4px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.card__hint { margin: 2px 0 0; text-align: center; font-size: 10.5px; color: var(--muted); letter-spacing: 0.04em; }

.field { display: grid; gap: 6px; }
.field span { font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }
.field input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.45);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.field input:not(.mono) { font-family: var(--sans); }
.field input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-faint); }

.recent { display: flex; flex-wrap: wrap; gap: 6px; margin-top: -6px; }
.recent button {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.recent button:hover { color: var(--gold-bright); border-color: var(--gold-dim); }

.note { font-size: 12.5px; line-height: 1.45; padding: 9px 11px; border-radius: 9px; }
.note--warn { color: var(--warn); background: rgba(232, 184, 90, 0.08); border: 1px solid rgba(232, 184, 90, 0.25); }
.note--error { color: var(--err); background: rgba(239, 125, 107, 0.08); border: 1px solid rgba(239, 125, 107, 0.25); }

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--sans);
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}
.btn:active { transform: translateY(1px); }
.btn--gold {
  position: relative;
  padding: 13px 18px;
  font-size: 15px;
  letter-spacing: 0.04em;
  color: #16130b;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  box-shadow: 0 6px 24px rgba(185, 159, 85, 0.25);
}
.btn--gold:hover { filter: brightness(1.06); }
.btn--gold:disabled { cursor: progress; filter: saturate(0.6) brightness(0.85); }
.btn--ghost { background: transparent; color: var(--muted); border-color: var(--line); }
.btn--ghost:hover { color: var(--gold-bright); border-color: var(--gold-dim); }
.btn--small { padding: 5px 10px; font-size: 11.5px; }
.btn--tiny { padding: 2px 8px; font-size: 10px; border-radius: 7px; }

.spinner {
  display: none;
  width: 14px;
  height: 14px;
  margin-left: 10px;
  vertical-align: -2px;
  border: 2px solid rgba(22, 19, 11, 0.3);
  border-top-color: #16130b;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.btn.is-busy .spinner { display: inline-block; }

/* ---------- Log ---------- */
.log {
  position: fixed;
  left: 20px;
  bottom: 20px;
  width: min(460px, calc(100vw - 40px));
  z-index: 10;
  overflow: hidden;
}
.log__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.log__actions { display: flex; gap: 6px; }
.log__list {
  list-style: none;
  margin: 0;
  padding: 8px 12px 10px;
  max-height: 168px;
  overflow-y: auto;
  font-size: 11px;
  line-height: 1.65;
  display: flex;
  flex-direction: column-reverse;
}
.log.is-collapsed .log__list { display: none; }
.log.is-collapsed .log__head { border-bottom: none; }
.log__list li { display: flex; gap: 10px; }
.log__list time { color: #6c665a; flex: none; }
.log__list .k { flex: none; width: 44px; text-transform: uppercase; font-size: 9.5px; padding-top: 1px; color: var(--muted); }
.log__list .k-join { color: var(--ok); }
.log__list .k-leave { color: var(--warn); }
.log__list .k-goal { color: var(--gold-bright); }
.log__list .k-error { color: var(--err); }
.log__list .k-warn { color: var(--warn); }
.log__list .t { color: var(--text); word-break: break-word; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 20px);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  color: #16130b;
  background: var(--gold-bright);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 40;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Motion ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 50% { opacity: 0.25; } }
@keyframes pop { 0% { transform: scale(1.35); opacity: 0.2; } 100% { transform: scale(1); opacity: 1; } }
@keyframes bump { 0% { transform: scale(1); } 35% { transform: scale(1.5); color: var(--gold-bright); } 100% { transform: scale(1); } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- Small screens ---------- */
@media (max-width: 720px) {
  .topbar { padding: 12px 16px; }
  .brand__tag { display: none; }
  .hud { width: auto; padding: 8px 10px; gap: 6px; }
  .hud__grid { grid-template-columns: repeat(2, auto); column-gap: 14px; }
  .spark, .hud__url { display: none; }
  .scoreboard { left: 16px; top: auto; bottom: 60px; width: 170px; }
  .log { left: 16px; bottom: 16px; width: calc(100vw - 32px); }
  .log__list { max-height: 90px; }
}
