/* BloxWorlds! — Roblox-inspired clean UI */
:root {
  --bg: #1b1c22;
  --bg-2: #23252d;
  --panel: #2b2e38;
  --panel-2: #33373f;
  --accent: #00a2ff;
  --accent-2: #00b4ff;
  --accent-dark: #0084d1;
  --text: #f2f3f5;
  --text-dim: #a0a4ad;
  --gold: #ffce4a;
  --danger: #ff4d4d;
  --green: #2ecc71;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Source Sans Pro", system-ui, -apple-system, Arial, sans-serif;
  user-select: none;
}

#renderCanvas {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  outline: none; touch-action: none;
  display: block;
}

.hidden { display: none !important; }

/* ---------- Buttons ---------- */
.btn {
  border: none; cursor: pointer; font-weight: 700;
  font-family: inherit; border-radius: var(--radius-sm);
  padding: 12px 20px; font-size: 15px; color: var(--text);
  transition: transform 0.08s ease, filter 0.15s ease, background 0.15s ease;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); }
.btn-ghost { background: var(--panel-2); color: var(--text); }
.btn-ghost:hover { background: #3d414b; }
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn-block { width: 100%; }

/* ---------- Home ---------- */
.home-screen {
  position: fixed; inset: 0; z-index: 50;
  background: linear-gradient(160deg, #23252d 0%, #15161a 100%);
  display: flex; flex-direction: column; padding: 22px 28px;
  overflow-y: auto;
}
.home-top {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 26px; flex-wrap: wrap; gap: 14px;
}
.brand { font-size: 36px; font-weight: 800; letter-spacing: -0.5px; }
.brand-bang { color: var(--accent); }
.player-info { display: flex; align-items: center; gap: 12px; background: var(--panel); padding: 8px 16px 8px 8px; border-radius: var(--radius); }
.avatar-chip { width: 42px; height: 42px; border-radius: var(--radius-sm); background: var(--accent); flex-shrink: 0; }
.player-meta { display: flex; flex-direction: column; }
.player-name { font-weight: 700; font-size: 15px; }
.coins-display { font-size: 13px; color: var(--gold); display: flex; align-items: center; gap: 5px; }
.coin-icon { color: var(--gold); font-size: 12px; line-height: 1; }

.home-body { display: flex; gap: 26px; flex: 1; align-items: flex-start; }
.home-main { flex: 1; min-width: 0; }
.home-side { width: 280px; flex-shrink: 0; background: var(--panel); border-radius: var(--radius); padding: 16px; }

.section-title { font-size: 18px; font-weight: 800; margin-bottom: 14px; }
.section-title.small { font-size: 14px; margin-bottom: 10px; }

/* Game cards */
.game-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; }
.game-card {
  background: var(--panel); border-radius: var(--radius); overflow: hidden;
  cursor: pointer; transition: transform 0.12s ease, background 0.15s ease;
  border: 2px solid transparent;
}
.game-card:hover { transform: translateY(-4px); background: var(--panel-2); border-color: var(--accent); }
.game-thumb { height: 140px; display: flex; align-items: center; justify-content: center; font-size: 52px; position: relative; }
.game-info { padding: 14px 16px; }
.game-name { font-weight: 800; font-size: 17px; }
.game-desc { color: var(--text-dim); font-size: 13px; margin-top: 3px; }
.game-tag {
  position: absolute; top: 10px; right: 10px;
  background: rgba(0, 0, 0, 0.5); color: #fff; font-size: 11px; font-weight: 700;
  padding: 4px 9px; border-radius: 99px;
}
.game-card .play-btn {
  margin-top: 12px; width: 100%;
}

/* Friends */
.friends-list, .online-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.friend-item, .online-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; background: var(--bg-2); border-radius: var(--radius-sm); font-size: 13px;
}
.friend-avatar { width: 30px; height: 30px; border-radius: var(--radius-sm); flex-shrink: 0; }
.friend-name { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.status-online { background: var(--green); }
.status-offline { background: #555; }
.empty-text { color: var(--text-dim); font-size: 13px; padding: 6px 2px; }

/* ---------- HUD ---------- */
.game-hud { position: fixed; inset: 0; z-index: 40; pointer-events: none; }
.hud-top {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 16px; pointer-events: auto;
}
.hud-title { font-weight: 800; font-size: 18px; background: rgba(0,0,0,0.4); padding: 8px 18px; border-radius: 99px; backdrop-filter: blur(6px); }
.player-count { background: rgba(0,0,0,0.4); padding: 8px 14px; border-radius: 99px; font-size: 13px; backdrop-filter: blur(6px); }
.hud-side {
  position: absolute; top: 16px; right: 16px; width: 200px;
  background: rgba(0,0,0,0.4); border-radius: var(--radius); padding: 12px;
  backdrop-filter: blur(6px); pointer-events: auto;
}
.room-players { display: flex; flex-direction: column; gap: 6px; }
.room-player { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.room-player .dot { width: 8px; height: 8px; border-radius: 50%; }
.hud-bottom-right { position: absolute; bottom: 16px; right: 16px; pointer-events: auto; }
.coins-hud { background: rgba(0,0,0,0.4); padding: 8px 14px; border-radius: 99px; font-size: 14px; font-weight: 700; backdrop-filter: blur(6px); }

#leaveGameBtn { position: absolute; top: 16px; left: 16px; pointer-events: auto; }

/* ---------- Chat ---------- */
.chat-panel {
  position: fixed; bottom: 16px; left: 16px; z-index: 41; width: 320px; max-width: 80vw;
  background: rgba(0,0,0,0.45); border-radius: var(--radius); padding: 10px;
  backdrop-filter: blur(8px); pointer-events: auto;
}
.chat-messages { max-height: 150px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.chat-messages::-webkit-scrollbar { width: 5px; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 99px; }
.chat-msg { font-size: 13px; line-height: 1.35; word-break: break-word; }
.chat-name { font-weight: 700; }
.chat-form { display: flex; gap: 6px; }
.chat-input {
  flex: 1; background: rgba(0,0,0,0.4); border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius-sm); padding: 8px 12px; color: var(--text); font-family: inherit; font-size: 13px;
}
.chat-input:focus { outline: none; border-color: var(--accent); }

/* ---------- Obby stats ---------- */
.obby-stats {
  position: fixed; top: 64px; left: 16px; z-index: 41;
  display: flex; gap: 10px; pointer-events: none;
}
.obby-stat { background: rgba(0,0,0,0.45); padding: 8px 14px; border-radius: var(--radius-sm); backdrop-filter: blur(6px); display: flex; flex-direction: column; align-items: center; }
.stat-label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-val { font-size: 16px; font-weight: 800; }

/* ---------- Modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(0,0,0,0.65); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-box {
  background: var(--panel); border-radius: var(--radius); padding: 30px 34px;
  max-width: 420px; width: 100%; text-align: center; box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.modal-title { font-size: 24px; font-weight: 800; }
.modal-sub { color: var(--text-dim); font-size: 14px; }
.modal-time { font-size: 32px; font-weight: 800; color: var(--accent); }
.modal-coins { color: var(--gold); font-weight: 700; }
.modal-actions { display: flex; gap: 10px; margin-top: 12px; }
.name-input {
  background: var(--bg-2); border: 2px solid transparent; border-radius: var(--radius-sm);
  padding: 12px 14px; color: var(--text); font-family: inherit; font-size: 16px; text-align: center; width: 100%;
}
.name-input:focus { outline: none; border-color: var(--accent); }
.color-picker { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.color-swatch { width: 36px; height: 36px; border-radius: 50%; cursor: pointer; border: 3px solid transparent; transition: transform 0.1s; }
.color-swatch:hover { transform: scale(1.1); }
.color-swatch.selected { border-color: #fff; transform: scale(1.12); }

/* ---------- Toasts ---------- */
.toasts { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); z-index: 95; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  background: var(--panel); color: var(--text); padding: 10px 18px; border-radius: 99px;
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow);
  animation: toastIn 0.25s ease, toastOut 0.3s ease 2.7s forwards;
  border-left: 4px solid var(--accent);
}
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-10px); } }

/* ---------- Jump button (mobile) ---------- */
.jump-btn {
  position: fixed; bottom: 24px; right: 24px; z-index: 42;
  width: 68px; height: 68px; border-radius: 50%; border: none;
  background: rgba(0, 162, 255, 0.85); color: #fff; font-size: 28px;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  box-shadow: var(--shadow); backdrop-filter: blur(4px);
}
.jump-btn:active { transform: scale(0.92); }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .home-body { flex-direction: column; }
  .home-side { width: 100%; }
  .chat-panel { width: calc(100% - 32px); }
  .hud-side { width: 150px; }
  .brand { font-size: 28px; }
  .home-screen { padding: 16px; }
}
