:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #faf8f3;
  --border: #ddd6c8;
  --text: #1d1b17;
  --muted: #6b6457;
  --accent: #a8741a;
  --accent-text: #ffffff;
  --live: #2e9e5b;
  --danger: #c2412d;
  --row-hover: #f6efe0;
  --new: #fff3d1;}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121417; --surface: #1b1f24; --surface-2: #20252b; --border: #2f353d;
    --text: #e8e4dc; --muted: #9a9387; --accent: #d4a24c; --accent-text: #1b1f24;
    --row-hover: #252b33; --new: #3a3220;
  }
}
:root[data-theme="dark"] {
  --bg: #121417; --surface: #1b1f24; --surface-2: #20252b; --border: #2f353d;
  --text: #e8e4dc; --muted: #9a9387; --accent: #d4a24c; --accent-text: #1b1f24;
  --row-hover: #252b33; --new: #3a3220;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }

.top {
  position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; margin-right: auto; }
.brand h1 { font-size: 17px; margin: 0; letter-spacing: .2px; }
.status { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status.live .dot { background: var(--live); box-shadow: 0 0 0 3px color-mix(in srgb, var(--live) 25%, transparent); }
.status.error .dot { background: var(--danger); }
#search, #map-filter {
  flex: 1 1 220px; max-width: 340px; padding: 7px 10px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit;
}
#map-filter { flex: 0 1 200px; }
#map-filter.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.btn {
  padding: 7px 12px; border-radius: 6px; border: 1px solid var(--accent); background: var(--accent);
  color: var(--accent-text); font: inherit; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.small { padding: 4px 8px; font-size: 12px; }

.filters {
  display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center;
  padding: 12px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.filters[hidden] { display: none; }
.filters label { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.filters select, .filters input[type=number] {
  padding: 5px 8px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; width: auto;
}
.filters input[type=number] { width: 90px; }

main { padding: 12px 16px 24px; }
.lobbies { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.lobbies th, .lobbies td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.lobbies th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); background: var(--surface-2); user-select: none; }
.lobbies th[data-sort] { cursor: pointer; }
.lobbies th[aria-sort="ascending"]::after { content: " ▲"; }
.lobbies th[aria-sort="descending"]::after { content: " ▼"; }
.lobbies .num { text-align: right; font-variant-numeric: tabular-nums; }
.lobbies .icon { text-align: center; width: 1%; }
.lobbies .actions { text-align: right; white-space: nowrap; width: 1%; }
.lobbies .actions .btn { margin-left: 4px; }
tr.lobby { cursor: pointer; }
tr.lobby:hover { background: var(--row-hover); }
tr.lobby.new { background: var(--new); transition: background 2s; }
tr.lobby.hidden-lobby { opacity: .45; }
td.title { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
td.map { max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.host { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lobbies td.opt.wide { white-space: nowrap; }
.sub { display: block; font-weight: 400; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.full { color: var(--muted); }

tr.details > td { background: var(--surface-2); padding: 12px 14px; }
.facts { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--muted); margin-bottom: 10px; }
.facts b { color: var(--text); font-weight: 600; }
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 6px; }
.slot { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); min-width: 0; }
/* Player colour box, same numbers and colours as the game. */
.slot .color {
  min-width: 22px; height: 22px; border-radius: 4px; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; color: var(--muted); border: 1px solid var(--border); background: var(--surface-2);
}
.slot .color[class*=" c"] { border-color: transparent; color: #fff; }
.slot .color.c1 { background: #2f5bd8; } .slot .color.c2 { background: #d42a2a; }
.slot .color.c3 { background: #2c9b3c; } .slot .color.c4 { background: #f1d21c; color: #1d1b17; }
.slot .color.c5 { background: #1fc2c9; color: #1d1b17; } .slot .color.c6 { background: #9a3fc4; }
.slot .color.c7 { background: #8a8a8a; } .slot .color.c8 { background: #ee8a1c; color: #1d1b17; }
.slot .team-tag { font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.slot .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot:has(.player:hover, .player:focus-visible) { overflow: visible; }
.slot .who:has(.player:hover, .player:focus-visible) { overflow: visible; }
.player { position: relative; color: var(--text); font-weight: 600; text-decoration: none; }
.player:hover { color: var(--accent); }
/* Ratings tooltip on hover/keyboard focus. */
.player[data-tip]:hover::after, .player[data-tip]:focus-visible::after {
  content: attr(data-tip); position: absolute; left: 0; bottom: calc(100% + 6px); z-index: 20;
  white-space: pre; padding: 6px 9px; border-radius: 6px; font-size: 12px; font-weight: 500;
  font-variant-numeric: tabular-nums; line-height: 1.5;
  background: var(--text); color: var(--bg); box-shadow: 0 4px 12px rgb(0 0 0 / .25); pointer-events: none;
}
.slot.open, .slot.closed { color: var(--muted); font-style: italic; }

.balance {
  margin-top: 10px; padding: 8px 10px; border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 6px; background: var(--surface); display: grid; gap: 3px;
}
.balance-head { font-weight: 600; }

.empty { text-align: center; color: var(--muted); padding: 32px; }
footer { padding: 0 16px 24px; color: var(--muted); font-size: 12px; text-align: center; }

@media (max-width: 1150px) {
  .lobbies .wide { display: none; }
  td.title { max-width: 220px; }
  td.map { max-width: 160px; }
  td.host { max-width: 120px; }
}
@media (max-width: 760px) {
  /* Phones can't run the game, so joining happens from the details panel's copy link. */
  .lobbies .opt, .lobbies .icon, .lobbies .actions { display: none; }
  .lobbies { table-layout: fixed; }
  .lobbies th:first-child { width: 48px; }
  .lobbies th[data-sort="players"] { width: 64px; }
  td.title, td.map { max-width: none; }
  .lobbies th, .lobbies td { padding: 7px 6px; }
  main { padding: 8px 0 24px; }
  .lobbies { border-radius: 0; border-left: 0; border-right: 0; }
}
