:root {
  --bg: #0b0f14;
  --panel: #111827;
  --panel-2: #0f172a;
  --border: #223044;
  --text: #e5eefb;
  --muted: #8b98ac;
  --accent: #7c5cff;
  --accent-2: #22c55e;
  --danger: #ef4444;
  --cell-light: #e8edf6;
  --cell-dark: #8ea0b6;
  --cell-selected: #f59e0b;
  --cell-last: #22c55e;
  --shadow: 0 18px 40px rgba(0,0,0,.28);
  --radius: 22px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(124,92,255,.18), transparent 25%),
    radial-gradient(circle at top right, rgba(34,197,94,.12), transparent 22%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input {
  font: inherit;
}

button {
  border: 0;
  border-radius: 16px;
  padding: 14px 16px;
  background: #1f2937;
  color: var(--text);
  cursor: pointer;
  transition: transform .12s ease, opacity .12s ease, background .12s ease;
}

button:hover { transform: translateY(-1px); }
button:active { transform: translateY(0); opacity: .92; }

button.primary {
  background: linear-gradient(135deg, var(--accent), #5b8cff);
  box-shadow: 0 10px 24px rgba(124,92,255,.22);
}

button.ghost {
  background: transparent;
  border: 1px solid var(--border);
}

input {
  width: 100%;
  margin-top: 8px;
  padding: 14px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #0b1220;
  color: var(--text);
  outline: none;
}

input:focus {
  border-color: rgba(124,92,255,.8);
  box-shadow: 0 0 0 4px rgba(124,92,255,.12);
}

.hidden { display: none !important; }

.shell {
  width: min(1400px, calc(100% - 24px));
  margin: 0 auto;
  padding: 14px 0 22px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 8px 0 18px;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
}

.logo {
  width: 52px;
  height: 52px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), #5b8cff);
  font-size: 1.4rem;
  font-weight: 800;
  box-shadow: var(--shadow);
}

.brand h1 {
  margin: 0;
  font-size: 1.2rem;
}

.brand p, .muted {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: .95rem;
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pill, .badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 11px 14px;
  border-radius: 999px;
  background: rgba(17, 24, 39, .78);
  border: 1px solid var(--border);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(300px, .85fr);
  gap: 16px;
  align-items: start;
}

.left-col {
  display: grid;
  gap: 16px;
}

.card {
  background: rgba(17, 24, 39, .92);
  border: 1px solid rgba(34, 48, 68, .85);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  backdrop-filter: blur(10px);
}

.auth-grid,
.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-form h2,
.section-head h2,
.section-head h3 {
  margin: 0;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.section-head.compact {
  margin-bottom: 12px;
}

.queue-badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.clean-list {
  margin: 12px 0 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.6;
}

.leaderboard-list {
  margin: 10px 0 0;
  padding-left: 20px;
  color: var(--text);
}

.leaderboard-list li {
  margin: 10px 0;
  color: var(--muted);
}

.leaderboard-list strong {
  color: var(--text);
}

.board-wrap {
  display: grid;
  place-items: center;
  margin: 10px 0 12px;
}

.board {
  width: min(100%, 760px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  border-radius: 24px;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: 0 20px 50px rgba(0,0,0,.3);
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 0;
  border: 0;
  width: 100%;
  aspect-ratio: 1;
}

.square.light { background: var(--cell-light); color: #111827; }
.square.dark { background: var(--cell-dark); color: #111827; }

.square.selected {
  outline: 4px solid rgba(245, 158, 11, .95);
  outline-offset: -4px;
}

.square.last-move {
  box-shadow: inset 0 0 0 5px rgba(34, 197, 94, .9);
}

.piece {
  font-size: clamp(1.7rem, 4.2vw, 3rem);
  line-height: 1;
  user-select: none;
}

.coord {
  position: absolute;
  top: 7px;
  left: 8px;
  font-size: 11px;
  opacity: .5;
  user-select: none;
}

.chat-shell {
  display: grid;
  grid-template-rows: auto minmax(280px, 1fr) auto;
  gap: 12px;
  min-height: 520px;
}

.chat-log {
  overflow: auto;
  min-height: 280px;
  max-height: 70vh;
  padding-right: 4px;
}

.chat-item {
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(15, 23, 42, .85);
  border: 1px solid rgba(34, 48, 68, .85);
  margin-bottom: 10px;
}

.chat-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: .86rem;
}

.chat-name {
  color: var(--text);
  font-weight: 700;
}

.chat-form {
  display: flex;
  gap: 10px;
}

.chat-form input {
  margin-top: 0;
  flex: 1;
}

.status-banner {
  margin-bottom: 14px;
  padding: 13px 14px;
  border-radius: 16px;
  background: rgba(34, 197, 94, .12);
  border: 1px solid rgba(34, 197, 94, .28);
  color: #bbf7d0;
}

.center { text-align: center; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  padding: 12px 16px;
  border-radius: 999px;
  background: rgba(17, 24, 39, .95);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 50;
  max-width: calc(100vw - 20px);
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .chat-shell {
    min-height: 420px;
  }
}

@media (max-width: 760px) {
  .topbar,
  .section-head,
  .auth-grid,
  .two-col,
  .chat-form {
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .topbar {
    align-items: stretch;
  }

  .topbar-meta {
    justify-content: space-between;
  }

  .auth-grid,
  .two-col {
    grid-template-columns: 1fr;
  }

  .button-row {
    display: grid;
    grid-template-columns: 1fr;
  }

  .board {
    width: 100%;
  }

  .chat-log {
    max-height: 55vh;
  }
}