:root {
  --bg-0: #0f172a;
  --bg-1: #1e293b;
  --bg-2: #334155;
  --surface: rgba(15, 23, 42, 0.85);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #f97316;
  --good: #22c55e;
  --danger: #ef4444;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 80% 10%, rgba(249, 115, 22, 0.2), transparent 40%),
    radial-gradient(circle at 10% 90%, rgba(14, 165, 233, 0.2), transparent 35%),
    linear-gradient(160deg, var(--bg-0), var(--bg-1), var(--bg-2));
}

.app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 14px;
  padding: 16px;
  backdrop-filter: blur(8px);
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.row,
.actions,
.join {
  margin: 10px 0;
  display: flex;
  gap: 10px;
  align-items: center;
}

.build {
  margin-top: 12px;
}

.build-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 460px;
  margin-top: 10px;
}

.build-control {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  min-height: 54px;
  padding: 7px 8px 7px 14px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.7);
}

.build-control label {
  font-weight: 700;
}

.build-stepper {
  display: grid;
  grid-template-columns: 38px 48px 38px;
  align-items: center;
}

.build-stepper input {
  width: 48px;
  padding: 8px 4px;
  border: 0;
  border-radius: 0;
  background: transparent;
  text-align: center;
  font-size: 1rem;
  font-weight: 700;
  appearance: textfield;
}

.build-stepper input::-webkit-inner-spin-button,
.build-stepper input::-webkit-outer-spin-button {
  margin: 0;
  appearance: none;
}

.build-stepper .build-step {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 8px;
  font-size: 1.25rem;
  line-height: 1;
}

input,
button {
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  padding: 10px 12px;
  background: rgba(15, 23, 42, 0.7);
  color: var(--text);
}

button {
  cursor: pointer;
  background: linear-gradient(180deg, #fb923c, #ea580c);
  border-color: #fdba74;
  font-weight: 700;
  color: #111827;
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

.hint {
  color: var(--muted);
}

.hidden {
  display: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hud,
.race-meta {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hud {
  justify-content: space-between;
}

.status h2,
.race-meta p {
  margin-bottom: 0;
}

.player-label {
  font-weight: 700;
}

.position-label {
  padding: 6px 10px;
  border: 1px solid rgba(251, 146, 60, 0.65);
  border-radius: 999px;
  background: rgba(249, 115, 22, 0.16);
  color: #fed7aa;
  font-weight: 700;
}

.race .layout {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 14px;
}

#track {
  width: 100%;
  height: auto;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: linear-gradient(180deg, #0b1220, #1f2937);
}

.panel ul,
#player-list,
#cars-list,
#turn-log {
  list-style: none;
  margin: 0;
  padding: 0;
}

#player-list li,
#cars-list li,
#turn-log li {
  padding: 8px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
}

#turn-log {
  max-height: 260px;
  overflow: auto;
  color: #cbd5e1;
}

.speed-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.error {
  color: #fecaca;
  font-weight: 700;
  min-height: 20px;
}

.chat-panel {
  margin-top: 14px;
}

.chat-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.chat-heading h2,
.chat-heading p {
  margin-bottom: 0;
}

.chat-count {
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.chat-messages {
  min-height: 92px;
  max-height: 240px;
  margin: 14px 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
  border-top: 1px solid rgba(148, 163, 184, 0.2);
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
}

.chat-message {
  padding: 9px 10px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}

.chat-message:last-child {
  border-bottom: 0;
}

.chat-message-self {
  background: rgba(249, 115, 22, 0.08);
}

.chat-message-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 3px;
  font-size: 0.8rem;
  color: var(--muted);
}

.chat-author {
  font-weight: 700;
}

.chat-message p {
  margin: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.chat-empty {
  padding: 32px 10px;
  color: var(--muted);
  text-align: center;
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.chat-form input {
  width: 100%;
}

@media (max-width: 980px) {
  .hud {
    align-items: stretch;
    flex-direction: column;
  }

  .race .layout {
    grid-template-columns: 1fr;
  }

  .speed-controls {
    flex-wrap: wrap;
  }

  .chat-form {
    grid-template-columns: 1fr;
  }
}
