:root {
  --color-primary: #dc2626;
  --color-secondary: #2563eb;
  --color-accent: #22c55e;
  --bg: #0f172a;
  --bg-deep: #080d18;
  --bg-card: rgba(255, 255, 255, 0.05);
  --bg-card-2: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: #ffffff;
  --muted: #93a0b8;
  --dim: #64748b;
  --amber: #f59e0b;
  --violet: #a855f7;
  --sand: #e6c68c;
  --forest: #2c7a45;
  --snow: #dbe6f1;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 24px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --font-ar: 'Cairo', 'Tajawal', system-ui, -apple-system, sans-serif;
  --font-num: 'Orbitron', 'Cairo', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
  color-scheme: dark;
}
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html,
body {
  height: 100%;
}
body {
  font-family: var(--font-ar);
  background:
    radial-gradient(ellipse at 50% -10%, rgba(220, 38, 38, 0.22), transparent 55%),
    radial-gradient(ellipse at 80% 100%, rgba(37, 99, 235, 0.18), transparent 55%),
    var(--bg-deep);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}
button {
  font-family: inherit;
  color: inherit;
  cursor: pointer;
}
.num {
  font-family: var(--font-num);
  letter-spacing: 0.02em;
}

/* ── shell ── */
.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  animation: fadeUp 0.45s ease both;
}
.wrap {
  width: min(1120px, 100% - 2rem);
  margin-inline: auto;
}
.row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.row.between {
  justify-content: space-between;
}
.grow {
  flex: 1;
}
.muted {
  color: var(--muted);
}
.tiny {
  font-size: 0.78rem;
}
.icon {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon.solid {
  fill: currentColor;
  stroke: none;
}

/* ── buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.7rem 1.35rem;
  border-radius: 999px;
  border: 1px solid transparent;
  background: var(--bg-card-2);
  font-size: 0.92rem;
  font-weight: 700;
  transition: transform 0.15s ease, box-shadow 0.18s ease, background 0.2s ease, opacity 0.2s;
}
.btn:hover:not(:disabled) {
  transform: translateY(-2px);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn-primary {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #fff;
  box-shadow: 0 8px 30px rgba(220, 38, 38, 0.35);
}
.btn-blue {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #fff;
  box-shadow: 0 8px 30px rgba(37, 99, 235, 0.3);
}
.btn-green {
  background: linear-gradient(135deg, #22c55e, #15803d);
  color: #04180d;
  box-shadow: 0 8px 30px rgba(34, 197, 94, 0.3);
}
.btn-ghost {
  border-color: var(--border-strong);
  background: transparent;
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg-card);
}
.btn-sm {
  padding: 0.45rem 0.9rem;
  font-size: 0.8rem;
}
.btn-lg {
  padding: 0.95rem 1.9rem;
  font-size: 1.05rem;
}

/* ── cards / chips / inputs ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
  padding: 1.1rem 1.25rem;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s;
}
.card-hover:hover {
  transform: translateY(-3px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.32rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.18s ease;
}
.chip.active {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.14);
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: rgba(37, 99, 235, 0.18);
  color: #93c5fd;
}
.badge.red {
  background: rgba(220, 38, 38, 0.18);
  color: #fca5a5;
}
.badge.green {
  background: rgba(34, 197, 94, 0.16);
  color: #86efac;
}
.badge.amber {
  background: rgba(245, 158, 11, 0.16);
  color: #fcd34d;
}
input[type='text'],
select {
  width: 100%;
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-family: inherit;
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
input[type='text']:focus,
select:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.2);
}
label.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
}

/* ── menu ── */
.hero {
  text-align: center;
  padding: 3rem 1rem 1.5rem;
}
.hero h1 {
  font-family: var(--font-num);
  font-size: clamp(2rem, 7vw, 4rem);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.02em;
  background: linear-gradient(120deg, #fff 20%, #fca5a5 55%, #93c5fd);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero .sub {
  font-size: clamp(1rem, 3vw, 1.3rem);
  font-weight: 900;
  color: var(--color-primary);
  margin-top: 0.5rem;
}
.hero .tag {
  color: var(--muted);
  max-width: 620px;
  margin: 0.9rem auto 0;
  font-size: 1rem;
  line-height: 1.8;
}
.crew {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.9rem;
  margin-top: 1.6rem;
}
.crew .card {
  text-align: right;
}
.crew h3 {
  font-size: 1.02rem;
  margin-bottom: 0.35rem;
}
.crew .role-ico {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  margin-bottom: 0.6rem;
}
.role-ico.driver {
  background: rgba(220, 38, 38, 0.18);
  color: #fca5a5;
}
.role-ico.nav {
  background: rgba(37, 99, 235, 0.18);
  color: #93c5fd;
}
.role-ico.gunner {
  background: rgba(34, 197, 94, 0.18);
  color: #86efac;
}
.maps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.9rem;
}
.map-card {
  position: relative;
  overflow: hidden;
  cursor: pointer;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  padding: 1rem;
  min-height: 132px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  transition: transform 0.2s ease, border-color 0.2s;
}
.map-card:hover {
  transform: translateY(-3px);
}
.map-card.sel {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.22);
}
.map-card h3 {
  font-size: 1.05rem;
  position: relative;
}
.map-card p {
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.82);
  position: relative;
}
.map-card .swatch {
  position: absolute;
  inset: 0;
  opacity: 0.9;
}

/* ── race stage + HUD ── */
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
}
.stage canvas#game {
  width: 100%;
  height: 100%;
  display: block;
  background: #0b1220;
  border-radius: 0;
  touch-action: none;
}
.hud {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 0.7rem;
  gap: 0.6rem;
  pointer-events: none;
}
.hud > * {
  pointer-events: auto;
}
.hud-mid {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.6rem;
}
.panel {
  background: rgba(8, 13, 24, 0.74);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.55rem 0.7rem;
}
.panel h4 {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 0.35rem;
  letter-spacing: 0.02em;
}
.lb {
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
  min-width: 230px;
}
.lb-row {
  display: grid;
  grid-template-columns: 18px 10px 1fr auto;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.8rem;
  padding: 0.15rem 0.3rem;
  border-radius: 8px;
}
.lb-row.me {
  background: rgba(255, 255, 255, 0.1);
}
.lb-row .rk {
  font-family: var(--font-num);
  font-weight: 900;
  font-size: 0.8rem;
  color: var(--muted);
}
.lb-row .dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}
.lb-row .lap {
  font-family: var(--font-num);
  font-size: 0.72rem;
  color: var(--muted);
}
.pips {
  display: inline-flex;
  gap: 2px;
  margin-inline-start: 4px;
  vertical-align: middle;
}
.pips i {
  width: 5px;
  height: 10px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.2);
  display: block;
}
.pips i.on {
  background: var(--color-accent);
}

.roles {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.role-tab {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.7rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.18s ease;
}
.role-tab:hover {
  background: rgba(255, 255, 255, 0.1);
}
.role-tab.active {
  color: #fff;
  border-color: var(--border-strong);
  background: rgba(255, 255, 255, 0.16);
}
.role-tab .kbd {
  margin-inline-start: auto;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--dim);
}
.deck {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: flex-end;
}
.key {
  min-width: 58px;
  min-height: 52px;
  padding: 0.3rem 0.5rem;
  border-radius: 14px;
  border: 1px solid var(--border-strong);
  background: rgba(8, 13, 24, 0.8);
  color: #fff;
  font-weight: 800;
  font-size: 0.78rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  user-select: none;
  touch-action: manipulation;
  transition: transform 0.1s ease, background 0.15s ease;
}
.key:active,
.key.down {
  transform: scale(0.94);
  background: rgba(220, 38, 38, 0.35);
}
.key .sm {
  font-size: 0.6rem;
  color: var(--muted);
  font-weight: 700;
}
.key.fire {
  background: rgba(220, 38, 38, 0.28);
  border-color: rgba(248, 113, 113, 0.5);
}
.key.miss {
  background: rgba(245, 158, 11, 0.25);
}
.gauge {
  height: 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.14);
  overflow: hidden;
  margin-top: 0.3rem;
}
.gauge i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #22c55e, #fbbf24, #ef4444);
  transition: width 0.12s linear;
}
.feed {
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.feed-item {
  font-size: 0.8rem;
  background: rgba(8, 13, 24, 0.72);
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--color-secondary);
  border-radius: 10px;
  padding: 0.4rem 0.6rem;
  animation: slideIn 0.3s ease both;
}
.feed-item.hit {
  border-inline-start-color: var(--color-primary);
}
.feed-item.luck {
  border-inline-start-color: var(--amber);
}
.feed-item.oil {
  border-inline-start-color: var(--violet);
}
.minimap-wrap {
  background: rgba(8, 13, 24, 0.8);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.35rem;
}
canvas#minimap {
  width: 210px;
  height: 140px;
  display: block;
  border-radius: 10px;
}

/* ── lobby ── */
.seat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(228px, 1fr));
  gap: 0.7rem;
}
.seat-car {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-card);
  padding: 0.6rem;
}
.seat-car h3 {
  font-size: 0.92rem;
  margin-bottom: 0.45rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.seat-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.seat {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.5rem;
  border-radius: 10px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.04);
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.16s ease, transform 0.16s ease;
}
.seat:hover {
  background: rgba(255, 255, 255, 0.1);
}
.seat.mine {
  border-color: var(--color-accent);
  background: rgba(34, 197, 94, 0.14);
}
.seat.bot {
  color: var(--muted);
  cursor: default;
}
.seat .who {
  margin-inline-start: auto;
  font-size: 0.74rem;
  color: var(--muted);
}
.room-code {
  font-family: var(--font-num);
  font-size: 1.4rem;
  letter-spacing: 0.28em;
  padding: 0.3rem 0.7rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px dashed var(--border-strong);
}

/* ── results ── */
.podium {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  align-items: end;
  margin: 1rem 0;
}
.pod {
  border-radius: 14px 14px 0 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.03));
  border: 1px solid var(--border);
  border-bottom: none;
  padding: 0.8rem 0.6rem;
  text-align: center;
}
.pod.p1 {
  height: 138px;
  border-color: rgba(245, 158, 11, 0.5);
}
.pod.p2 {
  height: 108px;
}
.pod.p3 {
  height: 88px;
}
.pod .place {
  font-family: var(--font-num);
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--amber);
}
.res-row {
  display: grid;
  grid-template-columns: 26px 12px 1fr auto auto;
  gap: 0.5rem;
  align-items: center;
  padding: 0.45rem 0.6rem;
  border-radius: 10px;
  font-size: 0.84rem;
}
.res-row:nth-child(odd) {
  background: rgba(255, 255, 255, 0.04);
}

/* ── toast / modal / misc ── */
.toast-wrap {
  position: fixed;
  bottom: 1rem;
  inset-inline-start: 1rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.toast {
  padding: 0.6rem 1rem;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 700;
  box-shadow: var(--shadow);
  animation: fadeUp 0.28s ease both;
  background: rgba(34, 197, 94, 0.16);
  border: 1px solid rgba(34, 197, 94, 0.4);
  color: #86efac;
}
.toast.err {
  background: rgba(220, 38, 38, 0.16);
  border-color: rgba(220, 38, 38, 0.4);
  color: #fca5a5;
}
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 5, 12, 0.72);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 150;
  animation: fadeUp 0.25s ease both;
}
.modal {
  width: min(560px, 100%);
  background: #0d1425;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 1.4rem;
  box-shadow: var(--shadow);
  max-height: 90dvh;
  overflow: auto;
}
.divider {
  height: 1px;
  background: var(--border);
  margin: 1rem 0;
}
.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.9rem;
}
.stack {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.center {
  text-align: center;
}
.stat-num {
  font-family: var(--font-num);
  font-size: 1.5rem;
  font-weight: 900;
}
.stat-lbl {
  font-size: 0.72rem;
  color: var(--muted);
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}
.pulse {
  animation: pulse 1.6s infinite;
}
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── race screen sizing ── */
.screen.race {
  padding: 0;
  height: 100dvh;
  flex: 0 0 auto;
}
.screen.race .stage {
  height: 100%;
}
.show-sm {
  display: none;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.55rem 1rem;
  border-bottom: 1px solid var(--border);
  background: rgba(8, 13, 24, 0.6);
  backdrop-filter: blur(10px);
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 900;
  font-size: 0.95rem;
}
.brand .lg {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, #ef4444, #2563eb);
  display: grid;
  place-items: center;
  color: #fff;
}
main.page {
  flex: 1;
  padding: 1.2rem 0 3rem;
}

@media (max-width: 900px) {
  .lb {
    min-width: 176px;
  }
  .lb-row {
    font-size: 0.72rem;
  }
  .feed {
    max-width: 210px;
  }
  .feed-item {
    font-size: 0.72rem;
  }
  .roles {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .role-tab .kbd {
    display: none;
  }
  .minimap-wrap {
    display: none;
  }
  .show-sm {
    display: block;
  }
}
@media (max-width: 640px) {
  .hud {
    padding: 0.4rem;
  }
  .panel {
    padding: 0.45rem;
  }
  .feed {
    display: none;
  }
  .key {
    min-width: 50px;
    min-height: 48px;
  }
  .hero {
    padding: 1.8rem 0.5rem 1rem;
  }
}
