:root {
  --bg: #0b0b0f;
  --panel: #15151f;
  --panel-2: #1d1d2b;
  --text: #e8e8f0;
  --muted: #9a9ab0;
  --accent: #4363d8;
  --accent-2: #3cb44b;
  --danger: #e6194b;
  --sidebar-w: 320px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* ---- in-match stage: playfield + right sidebar ---- */

#stage {
  position: fixed;
  inset: 0;
  display: flex;
}
#game {
  display: block;
  flex: 1 1 auto;
  min-width: 0; /* allow the canvas to shrink so the sidebar keeps its width */
  height: 100%;
  background: var(--bg);
}

#sidebar {
  flex: 0 0 var(--sidebar-w);
  width: var(--sidebar-w);
  height: 100%;
  display: flex;
  flex-direction: column;
  /* Shares the page/letterbox background so the sidebar and the chrome around
     the playfield read as one continuous surface. */
  background: var(--bg);
}

.sidebar-title {
  margin: 0 0 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

/* Leaderboard (top, fixed height to its content). */
#leaderboard {
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.lb-list {
  margin: 0;
  padding: 0;
  list-style: none;
}
.lb-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: 15px;
}
.lb-list .lb-rank {
  width: 18px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.lb-list .lb-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lb-list .lb-score {
  margin-left: auto;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.lb-list li.me .lb-name {
  color: #ffd76a;
}

/* Event log (below, fills remaining height, scrollable chat history). */
#event-log {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 14px 16px 0;
}
.log-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding-bottom: 14px;
}
.log-row {
  display: flex;
  align-items: baseline;
  gap: 7px;
  font-size: 14px;
  line-height: 1.35;
}
.log-row .log-time {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.log-row .log-swatch {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  align-self: center;
}
.log-row .log-text {
  min-width: 0;
}

/* ---- screens / panels ---- */

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.screen.overlay {
  background: rgba(6, 6, 12, 0.72);
  backdrop-filter: blur(2px);
}

/* In-match overlays (mid-game join, end results) appear over the play area only,
   leaving the right sidebar (leaderboard + event log) visible for review. */
#enter,
#endscreen {
  right: var(--sidebar-w);
}

.panel {
  width: 360px;
  max-width: 100%;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.panel.wide {
  width: 640px;
}

.logo {
  margin: 0 0 18px;
  font-size: 42px;
  letter-spacing: 2px;
  text-align: center;
  background: linear-gradient(90deg, #4363d8, #42d4f4, #3cb44b);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

h2 {
  margin: 0 0 12px;
}
h3 {
  margin: 18px 0 8px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}

.field {
  display: block;
  margin: 12px 0;
}
.field span {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type='text'],
input[type='number'],
select {
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  outline: none;
}
input:focus,
select:focus {
  border-color: var(--accent);
}
input:disabled,
select:disabled {
  opacity: 0.5;
}

button {
  cursor: pointer;
  font-size: 15px;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: var(--panel-2);
  color: var(--text);
  transition: background 0.15s, transform 0.05s;
}
button:hover {
  background: #262638;
}
button:active {
  transform: translateY(1px);
}
button.primary {
  background: var(--accent);
  border-color: transparent;
  font-weight: 600;
}
button.primary:hover {
  background: #5573e8;
}
button.ghost {
  background: transparent;
}
button.is-ready {
  background: var(--accent-2);
  border-color: transparent;
}

.divider {
  text-align: center;
  margin: 18px 0;
  color: var(--muted);
  position: relative;
}
.divider::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
}
.divider span {
  position: relative;
  background: var(--panel);
  padding: 0 10px;
  font-size: 13px;
}

#create-btn {
  width: 100%;
}
.join-row {
  display: flex;
  gap: 8px;
}
.join-row input {
  text-transform: uppercase;
  letter-spacing: 4px;
  text-align: center;
  font-weight: 700;
}

.error {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  margin: 10px 0 0;
}
.muted {
  color: var(--muted);
  font-size: 13px;
}

/* ---- lobby ---- */

.lobby-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.code-box {
  display: flex;
  align-items: center;
  gap: 10px;
}
.code {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 4px;
  color: #42d4f4;
}
.lobby-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
/* Let each track honor its 1fr share. Without this, a non-shrinkable child
   (the team-chip row) blows the column's min-content out past 1fr and squeezes
   the other column, wrapping the player rows. */
.lobby-grid > div {
  min-width: 0;
}
@media (max-width: 560px) {
  .lobby-grid {
    grid-template-columns: 1fr;
  }
}

/* Host settings: a compact two-column grid instead of a tall stack. The grid
   gap supplies the spacing, so the fields drop their own vertical margin. */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
}
.settings-grid .field {
  margin: 0;
}
@media (max-width: 560px) {
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

/* Non-host settings: one read-only summary line. */
.settings-summary {
  margin: 0;
  padding: 11px 13px;
  background: var(--panel-2);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
}

.player-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.player-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.swatch {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.2);
}
.player-name {
  flex: 1;
  min-width: 0; /* allow the name to shrink past its text so badges don't wrap the row */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.badge {
  flex: 0 0 auto; /* badges keep their size; the name yields space instead */
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
}
.badge.host {
  background: rgba(255, 215, 106, 0.18);
  color: #ffd76a;
}
.badge.ready {
  background: rgba(60, 178, 75, 0.18);
  color: #6ee787;
}
.badge.bot {
  background: rgba(99, 179, 237, 0.18);
  color: #7cc4f5;
}

.color-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.color-picker .chip {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}
.color-picker .chip.selected {
  border-color: #fff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25);
}
.color-picker .chip:disabled {
  cursor: not-allowed;
  opacity: 0.28;
}
.emoji-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.emoji-picker .emoji-chip {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 2px solid transparent;
  background: #1c1f2b;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.emoji-picker .emoji-chip.selected {
  border-color: #fff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25);
}
.emoji-picker .emoji-chip:disabled {
  cursor: not-allowed;
  opacity: 0.28;
}

.team-picker {
  display: flex;
  gap: 8px;
}
/* Equal-width chips in a single row: adding teams makes each chip narrower
   rather than growing the panel taller. */
.team-chip {
  flex: 1 1 0;
  min-width: 0; /* shrink below the label's intrinsic width instead of overflowing */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 8px 6px;
  font-size: 13px;
  color: #0b0b0f;
  font-weight: 600;
  cursor: pointer;
}
.team-chip.selected {
  border-color: #fff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.4);
}
.badge.team {
  color: #0b0b0f;
}

.lobby-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 22px;
}
.lobby-actions .ghost {
  margin-left: auto;
}

/* ---- results ---- */

.results {
  margin: 0;
  padding-left: 0;
  list-style: none;
}
.results li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 16px;
}
.results .rank {
  width: 22px;
  color: var(--muted);
}
.results .score {
  margin-left: auto;
  font-weight: 700;
}
.results li.me {
  color: #ffd76a;
}

/* ---- match highlights (end screen) ---- */

.highlights {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 18px 0 0;
}

/* ---- winner banner (end screen) ---- */

.winner {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 16px 18px;
  margin-bottom: 16px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(255, 215, 106, 0.16), rgba(255, 255, 255, 0.03));
  border: 1px solid rgba(255, 215, 106, 0.38);
  font-size: 22px;
  font-weight: 700;
}
.winner .crown {
  font-size: 28px;
  line-height: 1;
}
.winner .swatch {
  width: 20px;
  height: 20px;
}
.winner .who {
  color: #ffd76a;
}
.winner .winner-score {
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
}
.highlight {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.highlight .hl-icon {
  font-size: 20px;
  line-height: 1;
  flex: 0 0 auto;
}
.highlight .hl-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.highlight .hl-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.highlight .hl-winner {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
}
.highlight .hl-who {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@media (max-width: 480px) {
  .highlights {
    grid-template-columns: 1fr;
  }
}
