*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:      #0d1117;
  --surface: #161b22;
  --card:    #21262d;
  --border:  #30363d;
  --accent:  #58a6ff;
  --text:    #c9d1d9;
  --dim:     #6e7681;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Courier New', Courier, monospace;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2.5rem 1.5rem 4rem;
}

/* ── Screens ── */
.screen {
  display: none;
  flex-direction: column;
  align-items: stretch;
  gap: 1.4rem;
  width: 100%;
  max-width: 820px;
}
.screen.active { display: flex; }

h1 {
  font-size: 1.85rem;
  letter-spacing: 0.3em;
  color: var(--accent);
  text-align: center;
}

/* ── Setup ── */
.config-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  font-size: 0.8rem;
  color: var(--dim);
}

.config-bar input {
  width: 72px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.3rem 0.5rem;
  text-align: center;
}
.config-bar input:focus { outline: none; border-color: var(--accent); }

.lanes-list { display: flex; flex-direction: column; gap: 0.55rem; }

.lane-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 1rem;
}

.color-swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

.lane-tag {
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
  width: 68px;
  flex-shrink: 0;
}

.name-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.82rem;
  padding: 0.35rem 0.65rem;
}
.name-input:focus { outline: none; border-color: var(--accent); }

.remove-btn {
  background: none;
  border: none;
  color: var(--dim);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.2rem 0.35rem;
  line-height: 1;
  border-radius: 3px;
  transition: color 0.12s;
}
.remove-btn:hover { color: #f87171; }

.setup-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 0.2rem;
}

/* ── Buttons ── */
.btn-accent {
  background: var(--accent);
  color: #0d1117;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: bold;
  letter-spacing: 0.1em;
  padding: 0.6rem 1.4rem;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-accent:hover { opacity: 0.82; }

.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  padding: 0.55rem 1.1rem;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

/* ── Race ── */
.race-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.race-header h1 { text-align: left; }

.timer {
  font-size: 2rem;
  font-weight: bold;
  color: var(--accent);
  letter-spacing: 0.05em;
  font-variant-numeric: tabular-nums;
  min-width: 5ch;
  text-align: right;
}

.timer.urgent { color: #f87171; }

.track { display: flex; flex-direction: column; gap: 0.55rem; }

.track-lane {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
}

.lane-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  width: 56px;
  flex-shrink: 0;
}

.badge-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
}

.badge-name {
  font-size: 0.57rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--dim);
  text-align: center;
  word-break: break-word;
  line-height: 1.25;
  max-width: 56px;
}

/* track road */
.road {
  flex: 1;
  position: relative;
  height: 52px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}

/* lane stripe */
.road::before {
  content: '';
  position: absolute;
  left: 0; right: 0;
  top: 50%;
  transform: translateY(-50%);
  height: 1px;
  background: var(--border);
  opacity: 0.5;
}

.racer {
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  line-height: 0;
  will-change: left;
}

.finish-flag {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  background: repeating-linear-gradient(
    to bottom,
    #ccc 0px, #ccc 5px,
    #111 5px, #111 10px
  );
  opacity: 0.75;
}

/* ── Results ── */
.results-list { display: flex; flex-direction: column; gap: 0.6rem; }

.result-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.8rem 1.2rem;
}

.result-row.winner {
  border-color: #eab308;
  box-shadow: 0 0 16px rgba(234,179,8,0.18);
}

.medal { font-size: 1.4rem; width: 36px; text-align: center; flex-shrink: 0; }

.res-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.res-name {
  flex: 1;
  font-size: 0.88rem;
  letter-spacing: 0.05em;
}

#again-btn { align-self: center; margin-top: 0.5rem; }
