:root {
  color-scheme: dark;
  --bg: #0b1020;
  --bg-2: #121a33;
  --panel: rgba(255, 255, 255, 0.04);
  --panel-line: rgba(255, 255, 255, 0.10);
  --text: #eef2ff;
  --muted: #9aa6c4;
  --accent: #7c9cff;
  --accent-2: #06d6a0;
  --gold: #ffd166;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 700px at 15% -10%, #1b2950 0%, rgba(27,41,80,0) 60%),
    radial-gradient(900px 600px at 100% 0%, #14233f 0%, rgba(20,35,63,0) 55%),
    var(--bg);
}

.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 22px 18px 40px;
}

/* ---- top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { font-size: 28px; }
.brand h1 {
  margin: 0;
  font-size: clamp(22px, 4vw, 30px);
  letter-spacing: -0.5px;
}
.identity {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  padding: 7px 10px;
  border-radius: 999px;
}
.you-label { color: var(--muted); font-size: 13px; font-weight: 700; }
#nameInput {
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--panel-line);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 12px;
  font: inherit;
  font-size: 14px;
  width: 150px;
  outline: none;
}
#nameInput:focus { border-color: var(--accent); }
.identity button {
  border: 0;
  border-radius: 999px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 800;
  font-size: 13px;
  color: #0c1326;
  background: linear-gradient(180deg, #a8bcff, var(--accent));
  cursor: pointer;
}
.identity button.accent {
  background: linear-gradient(180deg, #8effd0, var(--accent-2));
  color: #07261c;
}
.acct-name { font-weight: 800; font-size: 14px; padding: 0 2px; }
.identity button#logoutBtn {
  background: rgba(255,255,255,0.08);
  color: var(--text);
}
/* guest vs registered visibility */
.acct-only { display: none; }
.identity.registered .guest-only { display: none; }
.identity.registered .acct-only { display: inline-flex; align-items: center; }

.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #f0a92d; box-shadow: 0 0 0 3px rgba(240,169,45,.18);
}
.dot.online { background: var(--accent-2); box-shadow: 0 0 0 3px rgba(6,214,160,.18); }
.dot.offline { background: var(--muted); box-shadow: 0 0 0 3px rgba(154,166,196,.18); }

/* ---- layout ---- */
.layout {
  display: grid;
  grid-template-columns: 1.55fr 1fr;
  gap: 18px;
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
}
.pane-title {
  margin: 0 0 12px;
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-weight: 800;
}

/* ---- game grid ---- */
.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}
.game-card {
  position: relative;
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 18px;
  overflow: hidden;
  transition: transform .12s ease, border-color .12s ease, background .12s ease;
}
.game-card:hover { transform: translateY(-3px); border-color: var(--accent); background: rgba(124,156,255,0.08); }
.game-card.selected { border-color: var(--accent-2); }
.game-thumb {
  height: 104px;
  display: grid;
  place-items: center;
  font-size: 46px;
  background: linear-gradient(135deg, rgba(124,156,255,0.25), rgba(6,214,160,0.18));
}
.game-thumb.image-thumb {
  padding: 0;
  overflow: hidden;
  background: #11182c;
}
.game-thumb.image-thumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}
.game-meta { padding: 12px 14px 14px; }
.game-meta h3 { margin: 0 0 4px; font-size: 17px; }
.game-meta p { margin: 0 0 10px; color: var(--muted); font-size: 13px; line-height: 1.35; }
.card-actions { display: flex; gap: 8px; align-items: center; }
.play-btn {
  border: 0; border-radius: 999px; padding: 8px 16px;
  font: inherit; font-weight: 800; font-size: 13px; cursor: pointer;
  color: #0c1326; background: linear-gradient(180deg, #8effd0, var(--accent-2));
}
.board-link {
  font-size: 12px; font-weight: 700; color: var(--muted);
  background: none; border: 0; cursor: pointer; padding: 6px;
}
.board-link:hover { color: var(--text); }

/* ---- leaderboard ---- */
.board-pane {
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 18px;
  padding: 16px;
  align-self: start;
}
.board-head { display: flex; align-items: center; justify-content: space-between; }
.ghost {
  background: none; border: 1px solid var(--panel-line); color: var(--muted);
  border-radius: 10px; width: 32px; height: 32px; cursor: pointer; font-size: 15px;
}
.ghost:hover { color: var(--text); border-color: var(--accent); }
.board-metrics { display: flex; gap: 8px; margin: 4px 0 2px; }
.board-metrics .metric-btn {
  flex: 1; padding: 8px 10px; border-radius: 10px;
  border: 1px solid var(--panel-line); background: rgba(255,255,255,0.04);
  color: var(--muted); font: inherit; font-weight: 800; font-size: 13px; cursor: pointer;
}
.board-metrics .metric-btn:hover { color: var(--text); border-color: var(--accent); }
.board-metrics .metric-btn.active { background: var(--accent); color: #0c1326; border-color: transparent; }
.board-bench {
  display: flex; gap: 9px; align-items: flex-start;
  margin: 8px 0 2px; padding: 10px 12px;
  border: 1px dashed rgba(255,209,102,0.55); border-radius: 12px;
  background: rgba(255,209,102,0.08); font-size: 13px; font-weight: 800; line-height: 1.35;
}
.board-bench em { font-style: normal; margin-left: 4px; padding: 1px 7px; border-radius: 999px; font-size: 10px; font-weight: 900; color: #2a2200; background: var(--gold); vertical-align: middle; }
.board-bench small { display: block; margin-top: 3px; color: var(--muted); font-weight: 700; }
.hidden { display: none; }
.leaderboard { list-style: none; margin: 6px 0 0; padding: 0; counter-reset: rank; }
.leaderboard li {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--panel-line);
}
.leaderboard li:last-child { border-bottom: 0; }
.leaderboard li.empty { color: var(--muted); font-size: 14px; justify-content: center; padding: 24px 8px; }
.rank {
  width: 26px; height: 26px; flex: 0 0 26px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 800; font-size: 13px;
  background: rgba(255,255,255,0.06); color: var(--muted);
}
.leaderboard li:nth-child(1) .rank { background: var(--gold); color: #2a2200; }
.leaderboard li:nth-child(2) .rank { background: #cdd7ee; color: #20283c; }
.leaderboard li:nth-child(3) .rank { background: #e0a06a; color: #2a1700; }
.lb-name { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-name.is-you { color: var(--accent-2); }
.lb-score { font-weight: 900; font-variant-numeric: tabular-nums; }

.empty { color: var(--muted); font-size: 14px; }
.foot { margin-top: 28px; text-align: center; color: var(--muted); font-size: 12px; }

/* ---- auth modal ---- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(4, 8, 18, 0.66); backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 20px;
}
.modal-overlay.hidden { display: none; }
.modal {
  width: min(92vw, 380px);
  background: var(--bg-2);
  border: 1px solid var(--panel-line);
  border-radius: 20px;
  padding: 20px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.5);
  animation: modalIn .18s ease;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-tabs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  background: rgba(0,0,0,0.25); padding: 4px; border-radius: 999px; margin-bottom: 14px;
}
.modal-tabs .tab {
  border: 0; background: transparent; color: var(--muted);
  font: inherit; font-weight: 800; font-size: 14px; padding: 9px; border-radius: 999px; cursor: pointer;
}
.modal-tabs .tab.active { background: var(--accent); color: #0c1326; }
.modal-hint { margin: 0 0 14px; color: var(--muted); font-size: 13px; line-height: 1.4; }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 12px; font-weight: 800; color: var(--muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .06em; }
.field input {
  width: 100%; background: rgba(0,0,0,0.28); border: 1px solid var(--panel-line);
  color: var(--text); border-radius: 12px; padding: 11px 12px; font: inherit; font-size: 15px; outline: none;
}
.field input:focus { border-color: var(--accent); }
.auth-error { color: var(--danger, #ef476f); font-size: 13px; font-weight: 700; min-height: 18px; margin-bottom: 6px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }
.modal-actions button { border: 0; border-radius: 12px; padding: 11px 18px; font: inherit; font-weight: 800; cursor: pointer; }
.modal-actions .ghost { background: rgba(255,255,255,0.08); color: var(--text); }
.modal-actions .primary { background: linear-gradient(180deg, #a8bcff, var(--accent)); color: #0c1326; }
.modal-actions .primary[disabled] { opacity: .6; cursor: default; }
:root { --danger: #ef476f; }
