* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  background: #16213e;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: #fff;
  user-select: none;
}
#gameCanvas {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100vw;
  height: 100vh;
}
#overlayCanvas {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 2;
}
#overlayCanvas.show {
  display: block;
}
#gameCanvas.show {
  animation: canvasReveal 0.4s ease-out forwards;
}
@keyframes canvasReveal {
  0% { transform: scale(0.3); opacity: 0; border-radius: 50%; }
  60% { transform: scale(1.05); opacity: 1; border-radius: 0; }
  100% { transform: scale(1); opacity: 1; border-radius: 0; }
}

/* ── Leaderboard Buttons ── */
#leaderboardBtns {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
}
.lb-btn {
  padding: 8px 14px;
  font-size: 13px;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  background: rgba(255,255,255,0.06);
  color: #bbc;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.lb-btn:hover { background: rgba(255,255,255,0.12); color: #fff; border-color: rgba(255,255,255,0.3); }

/* ── Leaderboard Modal ── */
.lb-tab {
  flex: 1;
  padding: 8px 0;
  font-size: 13px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  background: transparent;
  color: #889;
  cursor: pointer;
  transition: all 0.15s;
}
.lb-tab:hover { background: rgba(255,255,255,0.06); color: #bbc; }
.lb-type-tab {
  flex: 1;
  padding: 6px 0;
  font-size: 12px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 6px;
  background: transparent;
  color: #667;
  cursor: pointer;
  transition: all 0.15s;
}
.lb-type-tab:hover { background: rgba(255,255,255,0.05); color: #889; }
.lb-type-tab.active {
  background: rgba(77,171,247,0.12);
  border-color: rgba(77,171,247,0.25);
  color: #6af;
  font-weight: 600;
}
.lb-tab.active {
  background: rgba(77,171,247,0.15);
  border-color: rgba(77,171,247,0.3);
  color: #4dabf7;
}
.lb-row {
  display: flex;
  align-items: center;
  padding: 7px 10px;
  font-size: 13px;
  border-radius: 6px;
  transition: background 0.1s;
}
.lb-row:hover { background: rgba(255,255,255,0.04); }
.lb-row.is-me { background: rgba(255,215,0,0.08); }
.lb-row .rank {
  width: 36px;
  text-align: center;
  font-weight: 600;
  color: #667;
}
.lb-row .rank.top1 { color: #ffd700; }
.lb-row .rank.top2 { color: #c0c0c0; }
.lb-row .rank.top3 { color: #cd7f32; }
.lb-row .name {
  flex: 1;
  color: #ddd;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lb-row.is-me .name { color: #ffd700; font-weight: 600; }
.lb-row .val {
  text-align: right;
  color: #aab;
  font-variant-numeric: tabular-nums;
}
.lb-row .val-len { width: 52px; }
.lb-row .val-kill { width: 46px; }
.lb-row .val-surv { width: 58px; }
.lb-row .val.val-accent { color: #ffd700; font-weight: 600; }
.lb-row.is-me .val { color: #ffd700; }
.lb-row.is-me .val.val-accent { color: #ffd700; font-weight: 700; }

#nameScreen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: rgba(22,33,62,0.7);
  position: relative;
  z-index: 1;
}
#nameScreen h1 {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 48px;
  margin-bottom: 8px;
  background: linear-gradient(135deg, #ff6b6b, #fcc419, #51cf66, #4dabf7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
#nameScreen h1 img {
  flex-shrink: 0;
  margin-top: 3px;
}
#nameScreen .subtitle {
  color: #889;
  margin-bottom: 28px;
  font-size: 15px;
}
#nameInput {
  padding: 12px 20px;
  font-size: 18px;
  border: 2px solid #445;
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
  color: #fff;
  outline: none;
  width: 260px;
  text-align: center;
  transition: border-color 0.2s;
}
#nameInput:focus { border-color: #4dabf7; }
#nameInput::placeholder { color: #667; }
#joinBtn {
  margin-top: 16px;
  padding: 12px 40px;
  font-size: 18px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, #4dabf7, #51cf66);
  color: #fff;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}
#joinBtn:hover { opacity: 0.85; }
#joinBtn:active { transform: scale(0.97); }

/* ── Room Screen ── */
#roomScreen { background: #16213e; }
.room-layout {
  display: flex; gap: 24px; width: 640px; max-width: 94vw; height: 400px;
}
.room-list-panel { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.room-list-panel h2 { font-size: 20px; font-weight: 600; margin-bottom: 12px; }
.room-list-scroll { flex: 1; overflow-y: auto; min-height: 0; }
.room-list-scroll::-webkit-scrollbar { width: 4px; }
.room-list-scroll::-webkit-scrollbar-track { background: transparent; }
.room-list-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }
.room-empty { color: #445; font-size: 13px; text-align: center; padding: 40px 0; }

.room-row {
  display: flex; align-items: center; padding: 10px 10px; border-radius: 8px;
  cursor: pointer; transition: background 0.12s; gap: 10px;
}
.room-row:hover { background: rgba(255,255,255,0.04); }
.room-row:active { background: rgba(255,255,255,0.07); }
.room-mode-dot {
  width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
}
.room-mode-dot.scorpion { background: #845ef7; }
.room-mode-dot.chicken  { background: #ff922b; }
.room-info { flex: 1; min-width: 0; }
.room-name { font-size: 14px; font-weight: 500; color: #e8e8f0; }
.room-meta { font-size: 11px; color: #5a6a8a; margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; }
.room-meta span { white-space: nowrap; }
.room-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.room-players { font-size: 12px; color: #7a8aaa; font-weight: 500; min-width: 30px; text-align: right; }
.room-status-dot {
  width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0;
}
.room-status-dot.waiting  { background: #51cf66; }
.room-status-dot.playing  { background: #fcc419; }
.room-share-btn {
  background: none; border: none; color: #445; cursor: pointer; font-size: 13px;
  padding: 2px 4px; border-radius: 4px; transition: color 0.12s, background 0.12s;
  line-height: 1;
}
.room-share-btn:hover { color: #6af; background: rgba(77,171,247,0.1); }

/* ── Create Room Panel ── */
.create-room-btn {
  padding: 8px 16px; font-size: 13px; border: none; border-radius: 8px;
  background: linear-gradient(135deg,#4dabf7,#51cf66); color: #fff;
  cursor: pointer; transition: opacity 0.15s; white-space: nowrap;
}
.create-room-btn:hover { opacity: 0.85; }
.room-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px;
}
.room-header-actions { display: flex; gap: 6px; align-items: center; }

/* ── Create Room Modal ── */
#createRoomPanel {
  display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  z-index: 50; align-items: center; justify-content: center; background: rgba(0,0,0,0.6);
}
#createRoomPanel.show { display: flex; }
.cr-content {
  background: #1a2340; border-radius: 16px; padding: 24px; width: 420px;
  border: 1px solid rgba(255,255,255,0.08); display: flex; flex-direction: column; gap: 14px;
}
.cr-title { font-size: 18px; font-weight: 600; margin-bottom: 4px; }
.cr-field { display: flex; flex-direction: column; gap: 4px; }
.cr-label { font-size: 12px; color: #6b7a99; font-weight: 500; }
.cr-input {
  padding: 8px 12px; font-size: 13px; border: 1px solid #334; border-radius: 6px;
  background: rgba(255,255,255,0.04); color: #fff; outline: none; transition: border-color 0.15s;
}
.cr-input:focus { border-color: #4dabf7; }
.cr-input::placeholder { color: #445; }
.cr-radio-group { display: flex; gap: 8px; }
.cr-radio {
  flex: 1; padding: 6px 0; text-align: center; font-size: 12px;
  border: 1px solid #334; border-radius: 6px; background: transparent; color: #6b7a99;
  cursor: pointer; transition: all 0.12s;
}
.cr-radio:hover { border-color: #556; color: #aab; }
.cr-radio.active {
  border-color: rgba(77,171,247,0.3); background: rgba(77,171,247,0.1); color: #6af;
}
.cr-range-row { display: flex; align-items: center; gap: 8px; }
.cr-range {
  flex: 1; -webkit-appearance: none; height: 4px; border-radius: 2px;
  background: #334; outline: none;
}
.cr-range::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%;
  background: #4dabf7; cursor: pointer;
}
.cr-range-val { font-size: 13px; color: #aab; min-width: 20px; text-align: center; }
.cr-skill-grid { display: flex; gap: 6px; flex-wrap: wrap; }
.cr-skill-btn {
  padding: 4px 10px; font-size: 11px; border: 1px solid #334; border-radius: 5px;
  background: transparent; color: #5a6a8a; cursor: pointer; transition: all 0.12s;
}
.cr-skill-btn:hover { border-color: #556; color: #889; }
.cr-skill-btn.active {
  border-color: rgba(77,171,247,0.25); background: rgba(77,171,247,0.08); color: #6af;
}
.cr-actions { display: flex; gap: 8px; margin-top: 4px; }
.cr-confirm {
  flex: 1; padding: 9px 0; font-size: 14px; border: none; border-radius: 8px;
  background: linear-gradient(135deg,#4dabf7,#51cf66); color: #fff; cursor: pointer;
  transition: opacity 0.15s;
}
.cr-confirm:hover { opacity: 0.85; }
.cr-cancel {
  padding: 9px 16px; font-size: 13px; border: 1px solid #334; border-radius: 8px;
  background: transparent; color: #6b7a99; cursor: pointer; transition: all 0.12s;
}
.cr-cancel:hover { border-color: #556; color: #aab; }

#deathOverlay {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 10;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease-in-out;
}
#deathOverlay.show {
  opacity: 1;
  pointer-events: auto;
}
#deathCard {
  background: rgba(22,33,62,0.92);
  border: 1px solid rgba(255,68,68,0.3);
  border-radius: 16px;
  padding: 30px 48px;
  text-align: center;
  box-shadow: 0 0 40px rgba(255,68,68,0.2);
}
#deathCard h2 {
  font-size: 36px;
  color: #ff4444;
  text-shadow: 0 0 20px #ff4444;
  margin-bottom: 16px;
}
#deathOverlayStats {
  color: #ccc;
  font-size: 15px;
  line-height: 2;
}
#deathDismiss {
  margin-top: 20px;
  font-size: 13px;
  color: #667;
  animation: blink 1.5s infinite;
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ── Name Row (input + skin button) ── */
#nameRow {
  display: flex; align-items: center; gap: 8px;
}
#nameRow #nameInput {
  flex: 1;
  height: 50px;
  box-sizing: border-box;
}
#skinBtn {
  height: 50px;
  padding: 0 16px;
  font-size: 18px;
  display: flex; align-items: center;
  border: 2px solid #445;
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
  color: #889;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
#skinBtn:hover { background: rgba(255,255,255,0.1); color: #aab; border-color: #667; }
#skinBtn:focus { border-color: #4dabf7; outline: none; }

/* ── Skin Modal ── */
#skinModalPreview {
  display: block;
  width: 300px; height: 200px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(0,0,0,0.3);
}
#skinModalGrid::-webkit-scrollbar { width: 4px; }
#skinModalGrid::-webkit-scrollbar-track { background: transparent; }
#skinModalGrid::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }
#lbPanel::-webkit-scrollbar { width: 5px; }
#lbPanel::-webkit-scrollbar-track { background: transparent; }
#lbPanel::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
#lbPanel::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }
.skinThumb {
  width: 56px; height: 56px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer; transition: border-color 0.12s, transform 0.12s;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
  justify-self: center;
}
.skinThumb:hover { transform: scale(1.15); }
.skinThumb.selected {
  border-color: #ffd700;
  box-shadow: 0 0 10px rgba(255,215,0,0.4);
}
.skinThumb canvas {
  width: 100%; height: 100%; display: block;
}

/* ── Game Over Chart ── */
#gameOverChart {
  display: block;
  width: 400px;
  height: 120px;
  border-radius: 10px;
  background: rgba(0,0,0,0.35);
  border: 1px solid rgba(255,255,255,0.06);
  margin: 0 auto;
  flex-shrink: 0;
}
