*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background-color: #f2ede6;
  background-image: radial-gradient(#c9b8a8 1px, transparent 1px);
  background-size: 28px 28px;
  color: #1c1917;
}

/* ── Nav ──────────────────────────────────────────────────────────────── */
nav {
  background: #faf7f2;
  border-bottom: 3px solid #c84b2f;
  padding: 0 20px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky; top: 0; z-index: 20;
  flex-shrink: 0;
}
.nav-brand {
  font-weight: 800; font-size: 1.05rem; color: #c84b2f;
  text-decoration: none; letter-spacing: -0.01em;
}
.nav-user {
  font-size: 0.82rem; color: #6b6560;
  cursor: pointer; text-underline-offset: 2px;
}
.nav-user:hover { color: #c84b2f; text-decoration: underline dotted; }

/* ── Two-column layout ────────────────────────────────────────────────── */
.page-body {
  display: flex;
  height: calc(100vh - 50px);
}
.main-content {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
}
.right-sidebar {
  width: 260px;
  flex-shrink: 0;
  background: #faf7f2;
  border-left: 2px solid #d6cfc4;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-header {
  padding: 11px 14px;
  font-size: 0.75rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.07em;
  color: #8a8078;
  border-bottom: 1px solid #d6cfc4;
  flex-shrink: 0;
}

/* ── Chat ─────────────────────────────────────────────────────────────── */
.chat-messages {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 5px;
}
.chat-msg { font-size: 0.83rem; line-height: 1.45; word-break: break-word; }
.chat-name { font-weight: 700; margin-right: 4px; color: #c84b2f; }
.chat-system { font-size: 0.78rem; color: #8a8078; font-style: italic; }
.chat-input-row {
  padding: 8px 10px; border-top: 1px solid #d6cfc4;
  display: flex; gap: 6px; flex-shrink: 0;
}
.chat-input-row input {
  flex: 1; padding: 6px 8px;
  border: 1px solid #c8bdb4; border-radius: 4px;
  font-size: 0.85rem; font-family: inherit;
  background: #fff; color: #1c1917; outline: none;
  transition: border-color 150ms;
}
.chat-input-row input:focus { border-color: #c84b2f; }
.chat-input-row button {
  padding: 6px 10px; font-size: 0.82rem;
  box-shadow: 0 1px 0 #8c2e18;
}
.chat-input-row button:active { box-shadow: none; transform: translateY(1px); }

/* ── Online players list ──────────────────────────────────────────────── */
.online-list {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 8px 12px;
}
.online-player {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0; border-bottom: 1px solid #ede6de;
  font-size: 0.85rem;
}
.online-player:last-child { border-bottom: none; }
.online-dot { width: 7px; height: 7px; border-radius: 50%; background: #2d7a3f; flex-shrink: 0; }
.online-room { margin-left: auto; font-size: 0.75rem; color: #8a8078; white-space: nowrap; }

/* ── Layout / Container ───────────────────────────────────────────────── */
.container { max-width: 900px; margin: 0 auto; padding: 26px 16px; }
.page-title { font-size: 1.35rem; font-weight: 800; margin-bottom: 22px; color: #1c1917; letter-spacing: -0.02em; }

/* ── Cards ────────────────────────────────────────────────────────────── */
.card { background: #faf7f2; border: 1px solid #d6cfc4; border-radius: 5px; padding: 20px; }

/* ── Buttons ──────────────────────────────────────────────────────────── */
button, .btn {
  display: inline-block; background: #c84b2f; color: #fff;
  border: none; border-radius: 5px; padding: 8px 20px;
  cursor: pointer; font-size: 0.9rem; font-weight: 600;
  font-family: inherit; line-height: 1.4; text-decoration: none;
  box-shadow: 0 2px 0 #8c2e18;
  transition: background-color 150ms, box-shadow 150ms, transform 150ms;
  user-select: none;
}
button:hover, .btn:hover { background: #b03e24; }
button:active, .btn:active { background: #9a3620; box-shadow: none; transform: translateY(2px); }
button:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; transform: none; }
button.secondary { background: #e6dfd8; color: #1c1917; box-shadow: 0 2px 0 #bdb4aa; }
button.secondary:hover { background: #d9d0c7; }
button.secondary:active { background: #cac0b5; box-shadow: none; transform: translateY(2px); }
.btn-sm { padding: 5px 12px; font-size: 0.82rem; box-shadow: 0 1px 0 #8c2e18; }
.btn-sm.secondary { box-shadow: 0 1px 0 #bdb4aa; }
.btn-sm:active, .btn-sm.secondary:active { transform: translateY(1px); box-shadow: none; }

/* ── Home game grid ───────────────────────────────────────────────────── */
.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.game-card {
  background: #faf7f2; border: 1px solid #d6cfc4;
  border-left: 4px solid #d6cfc4; border-radius: 5px; padding: 18px 20px;
}
.game-card.game-race  { border-left-color: #c84b2f; }
.game-card.game-tanks { border-left-color: #2b527a; }
.game-card.game-pong  { border-left-color: #1a7a4a; }
.game-card.game-blob  { border-left-color: #7a2b7a; }
.game-card-name { font-size: 1.05rem; font-weight: 700; margin-bottom: 6px; }
.game-card-desc { font-size: 0.84rem; color: #6b6560; margin-bottom: 12px; line-height: 1.55; }
.game-card-meta { font-size: 0.82rem; color: #8a8078; margin-bottom: 14px; }
.player-count { font-weight: 700; color: #c84b2f; }

/* ── Waiting room ─────────────────────────────────────────────────────── */
.waiting-card, .spectator-card, .end-card { max-width: 480px; }
.room-title {
  font-size: 1.1rem; font-weight: 700; margin-bottom: 16px;
  padding-bottom: 10px; border-bottom: 2px solid #ede6de;
}
.player-list { list-style: none; margin-bottom: 18px; min-height: 60px; }
.player-list li {
  padding: 7px 0; border-bottom: 1px solid #ede6de;
  font-size: 0.9rem; display: flex; align-items: center; gap: 8px;
}
.player-list li:last-child { border-bottom: none; }
.color-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.room-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.room-hint { font-size: 0.8rem; color: #8a8078; margin-top: 12px; }

/* ── Settings panel ───────────────────────────────────────────────────── */
.settings-panel { margin-top: 18px; padding-top: 14px; border-top: 2px solid #ede6de; }
.settings-panel-title {
  font-size: 0.75rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.07em; color: #8a8078; margin-bottom: 10px;
}
.settings-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.settings-label { font-size: 0.88rem; flex: 1; }
.settings-control { display: flex; align-items: center; gap: 8px; }
.settings-control span { min-width: 26px; text-align: center; font-weight: 700; }
.settings-toggle { display: flex; border-radius: 4px; overflow: hidden; border: 1px solid #d6cfc4; }
.settings-toggle button {
  flex: 1; border-radius: 0; padding: 5px 10px; font-size: 0.82rem;
  box-shadow: none; background: #e6dfd8; color: #1c1917;
}
.settings-toggle button.active { background: #c84b2f; color: #fff; }
.settings-toggle button:active { transform: none; }

/* ── Canvas / Game screen ─────────────────────────────────────────────── */
.game-wrap { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; }
.game-top-row { display: flex; align-items: flex-start; gap: 12px; width: 100%; max-width: 800px; }
.game-top-row .scoreboard { flex: 1; min-width: 0; }
canvas {
  display: block; border: 2px solid #bdb4aa; border-radius: 4px;
  background: #222; max-width: 100%;
}
.canvas-wrap { position: relative; display: inline-block; max-width: 100%; }
.elim-overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px; pointer-events: none;
}
.elim-overlay.hidden { display: none !important; }
.elim-msg { text-align: center; color: #fff; font-weight: 700; font-size: 1.1rem; line-height: 1.6; }

/* ── Scoreboard ───────────────────────────────────────────────────────── */
.scoreboard {
  background: #faf7f2; border: 1px solid #d6cfc4;
  border-top: 3px solid #c84b2f; border-radius: 5px; padding: 12px 16px;
}
.scoreboard-title {
  font-size: 0.75rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.07em; color: #8a8078; margin-bottom: 9px;
}
.score-row {
  display: flex; align-items: center; gap: 10px;
  padding: 5px 0; border-bottom: 1px solid #ede6de; font-size: 0.9rem;
}
.score-row:last-child { border-bottom: none; }
.score-name { flex: 1; }
.score-stat { color: #6b6560; font-size: 0.85rem; }
.score-winner { font-weight: 700; color: #2d7a3f; }
.lives-dots { letter-spacing: 2px; }

/* ── Status banner ────────────────────────────────────────────────────── */
.status-banner {
  background: #faf7f2; border: 1px solid #d6cfc4; border-radius: 5px;
  padding: 11px 16px; font-size: 0.88rem; color: #6b6560; max-width: 800px;
}
.status-banner.accent { border-color: #c84b2f; color: #c84b2f; font-weight: 700; font-size: 0.95rem; }

/* ── Name modal ───────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-overlay.hidden { display: none; }
.modal { background: #faf7f2; border-radius: 6px; padding: 28px; width: 320px; border: 1px solid #d6cfc4; }
.modal h2 { font-size: 1.05rem; font-weight: 700; margin-bottom: 8px; }
.modal p { font-size: 0.85rem; color: #6b6560; margin-bottom: 16px; line-height: 1.55; }
.modal input {
  width: 100%; padding: 8px 10px; border: 1px solid #c8bdb4; border-radius: 5px;
  font-size: 0.9rem; font-family: inherit; background: #fff; color: #1c1917;
  margin-bottom: 14px; outline: none; transition: border-color 150ms;
}
.modal input:focus { border-color: #c84b2f; }

/* ── End screen ───────────────────────────────────────────────────────── */
.end-winner {
  font-size: 1rem; font-weight: 700; margin-bottom: 16px;
  padding: 12px 14px; background: #eef6ef; border-radius: 5px;
  border-left: 4px solid #2d7a3f; display: flex; align-items: center; gap: 8px;
}
.results-list { list-style: none; margin-bottom: 20px; }
.results-list li {
  padding: 7px 0; border-bottom: 1px solid #ede6de;
  font-size: 0.9rem; display: flex; align-items: center; gap: 10px;
}
.results-list li:last-child { border-bottom: none; }

/* ── Utility ──────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
