:root {
  --bg: #0e1117;
  --bg-card: #171c26;
  --bg-card-2: #1d2430;
  --border: #2a3340;
  --text: #e6edf3;
  --text-dim: #8b97a7;
  --accent: #f0a500;
  --green: #3fb950;
  --red: #f85149;
  --blue: #58a6ff;
  --purple: #bc8cff;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 600px at 50% -10%, #1a2230 0%, var(--bg) 55%);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
}

header {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 20px 10px;
  text-align: center;
}

/* Hero banner (branding image; carries the title visually) */
.hero {
  margin: 0 auto 22px;
  max-width: 960px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow), 0 0 50px rgba(88, 166, 255, 0.08);
  line-height: 0;
  position: relative;
}

.hero img {
  display: block;
  width: 100%;
  height: auto;
}

/* Fade the bottom edge of the image into the page background. */
.hero::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 22%;
  background: linear-gradient(180deg, transparent, rgba(14, 17, 23, 0.55));
  pointer-events: none;
}

/* Visually hidden but available to screen readers (the image has the title). */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

h1 {
  margin: 0 0 16px;
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  letter-spacing: -0.02em;
}

h1::before { content: "🏁 "; }

.summary {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.pill {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.pill strong { color: var(--text); }
.pill.good { color: var(--green); border-color: rgba(63, 185, 80, 0.4); }
.pill.bad { color: var(--red); border-color: rgba(248, 81, 73, 0.4); }

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 18px;
}

.card {
  display: block;
  background: linear-gradient(180deg, var(--bg-card) 0%, var(--bg-card-2) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: transform 0.15s ease, border-color 0.15s ease;
  color: inherit;
  text-decoration: none;
}

.card:hover { transform: translateY(-2px); border-color: var(--accent); }

.card-more {
  margin-top: 14px;
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: right;
}
.card:hover .card-more { color: var(--accent); }
.card.online { border-color: rgba(63, 185, 80, 0.35); }
.card.offline { opacity: 0.85; }

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.card-name {
  font-size: 1.15rem;
  font-weight: 650;
  line-height: 1.2;
}

.card-sub {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 3px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

.badges { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }

.badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge.status-online { background: rgba(63, 185, 80, 0.15); color: var(--green); }
.badge.status-offline { background: rgba(248, 81, 73, 0.15); color: var(--red); }

.players {
  margin: 4px 0 14px;
}

.players-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}

.players-count { font-size: 1.05rem; font-weight: 600; }
.players-count .max { color: var(--text-dim); font-weight: 400; }
.players-label { font-size: 0.78rem; color: var(--text-dim); }

.bar {
  height: 8px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--green), #6fd47e);
  border-radius: 999px;
  transition: width 0.4s ease;
}

.bar.full > span { background: linear-gradient(90deg, var(--accent), #ffc94d); }

.info-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 14px;
  font-size: 0.86rem;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.info-grid dt { color: var(--text-dim); }
.info-grid dd { margin: 0; text-align: right; font-weight: 500; }

.state-racing { color: var(--accent); }
.state-lobby { color: var(--blue); }

.offline-msg {
  font-size: 0.82rem;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  padding-top: 12px;
  font-family: ui-monospace, monospace;
  word-break: break-word;
}

.empty { text-align: center; color: var(--text-dim); margin-top: 40px; }

footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.8rem;
  padding: 0 20px 40px;
}

footer a { color: var(--blue); text-decoration: none; }
footer a:hover { text-decoration: underline; }
.dot { margin: 0 8px; opacity: 0.5; }

.lock::before { content: "🔒 "; }

/* ---- connection status + join hint ------------------------------------- */

.conn.live { color: var(--green); }
.conn.down { color: var(--text-dim); }

.join {
  margin: 14px 0 0;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.join code, .join-code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 8px;
  color: var(--text);
}

/* ---- sparkline --------------------------------------------------------- */

.spark {
  display: block;
  width: 100%;
  height: 48px;
  margin: 8px 0 4px;
}
.spark-line {
  fill: none;
  stroke: var(--green);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}
.spark-area { fill: rgba(63, 185, 80, 0.12); stroke: none; }

/* ---- detail page ------------------------------------------------------- */

.detail-header { position: relative; }

.back {
  position: absolute;
  left: 20px;
  top: 24px;
  color: var(--blue);
  text-decoration: none;
  font-size: 0.85rem;
}
.back:hover { text-decoration: underline; }

.panel {
  background: linear-gradient(180deg, var(--bg-card) 0%, var(--bg-card-2) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 18px;
}

.panel-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 12px;
}
.panel-title .muted, .muted { color: var(--text-dim); font-weight: 400; }

#chart .spark { height: 140px; }

.chart-legend {
  display: flex;
  gap: 18px;
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-top: 8px;
}
.chart-legend strong { color: var(--text); }

.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}
.panel-grid .panel { margin-bottom: 0; }

.stat-label { font-size: 0.78rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: 1.5rem; font-weight: 650; margin: 6px 0 2px; }
.stat-sub { font-size: 0.78rem; color: var(--text-dim); }

.join-detail { font-size: 0.86rem; color: var(--text-dim); margin: 0 0 10px; }
.join-code { display: inline-block; font-size: 0.95rem; }

.tracks { list-style: none; margin: 0; padding: 0; }
.tracks li {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.tracks li:last-child { border-bottom: none; }
.track-ago { color: var(--text-dim); font-size: 0.8rem; }
