/* ============================================================
   Race Battle — styles
   ============================================================ */
:root {
  --bg: #0b0e17;
  --bg-2: #121728;
  --panel: #171d30;
  --panel-2: #1f2740;
  --text: #e8ecf5;
  --muted: #8a94b0;
  --accent: #ff3b30;
  --accent-2: #ffb020;
  --gold: #ffd447;
  --green: #35d07f;
  --blue: #4aa8ff;
  --purple: #b46bff;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(255, 59, 48, 0.15), transparent 60%),
    radial-gradient(1000px 500px at -10% 110%, rgba(74, 168, 255, 0.12), transparent 60%),
    var(--bg);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

html.in-race,
body.in-race {
  overflow: hidden;
  height: 100%;
  overscroll-behavior: none;
  touch-action: none;
}

#app {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 20px 60px;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 4px;
  margin-bottom: 8px;
  backdrop-filter: blur(8px);
  background: linear-gradient(to bottom, rgba(11, 14, 23, 0.9), rgba(11, 14, 23, 0.4));
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  font-weight: 800;
  letter-spacing: 1px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 16px rgba(255, 59, 48, 0.35);
}

.brand-name {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.wallet {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.06);
  font-weight: 700;
  font-size: 16px;
}

.wallet .coin-icon {
  color: var(--gold);
  font-size: 18px;
}

.coin-label {
  color: var(--muted);
  font-weight: 500;
  font-size: 13px;
}

/* ---------- Screens ---------- */
.screen {
  display: none;
  animation: fade 0.25s ease;
}
.screen.active {
  display: block;
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- Main menu ---------- */
.menu-hero {
  text-align: center;
  padding: 90px 20px 40px;
}

.menu-title {
  font-size: clamp(48px, 9vw, 96px);
  font-weight: 900;
  letter-spacing: 4px;
  line-height: 0.95;
  text-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}
.menu-title span {
  color: transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
}

.menu-tagline {
  margin: 18px auto 40px;
  color: var(--muted);
  font-size: 18px;
  max-width: 520px;
}

.menu-buttons {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--panel-2);
  padding: 12px 22px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease, background 0.12s ease;
}
.btn:hover:not(:disabled) {
  transform: translateY(-2px);
  filter: brightness(1.1);
}
.btn:active:not(:disabled) {
  transform: translateY(0);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  color: #fff;
  box-shadow: 0 8px 20px rgba(255, 59, 48, 0.3);
}
.btn-ghost {
  background: transparent;
}
.btn-back {
  background: var(--panel);
  padding: 10px 16px;
}
.btn-disabled {
  background: var(--panel);
  color: var(--muted);
}
.btn-owned {
  background: var(--blue);
  border: none;
  color: #04213f;
}
.btn-equipped {
  background: var(--green);
  border: none;
  color: #063d22;
}

/* ---------- Screen head ---------- */
.screen-head {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 10px 0 6px;
}
.screen-title {
  font-size: 24px;
  font-weight: 800;
}
.screen-head-spacer {
  flex: 1;
}
.shop-hint {
  color: var(--muted);
  margin: 8px 2px 24px;
}

/* ---------- Shop grid ---------- */
.shop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 18px;
}

.card {
  position: relative;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, border-color 0.15s ease;
  overflow: hidden;
}
.card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--rarity-color, var(--muted));
}
.card:hover {
  transform: translateY(-4px);
  border-color: var(--rarity-color, rgba(255, 255, 255, 0.2));
}

.rarity-common {
  --rarity-color: #9aa4bd;
}
.rarity-rare {
  --rarity-color: var(--blue);
}
.rarity-epic {
  --rarity-color: var(--purple);
}
.rarity-legendary {
  --rarity-color: var(--gold);
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-icon {
  font-size: 40px;
  line-height: 1;
}
.rarity-badge {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 999px;
  color: var(--rarity-color);
  background: color-mix(in srgb, var(--rarity-color) 15%, transparent);
  border: 1px solid color-mix(in srgb, var(--rarity-color) 40%, transparent);
}

.card-name {
  margin-top: 14px;
  font-size: 19px;
  font-weight: 800;
}
.card-tagline {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.4;
  min-height: 38px;
}

.card-stats {
  list-style: none;
  margin: 14px 0 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.stat {
  display: flex;
  align-items: center;
  gap: 10px;
}
.stat-label {
  width: 34px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}
.stat-bar {
  flex: 1;
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.stat-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--rarity-color), #fff6);
}

.card-foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.price {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 800;
  font-size: 16px;
}
.price .coin-icon {
  color: var(--gold);
}
.price-low {
  color: var(--accent);
}
.card-action {
  padding: 10px 16px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%) translateY(20px);
  background: var(--panel-2);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text);
  padding: 12px 22px;
  border-radius: 999px;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.success {
  border-color: var(--green);
}
.toast.error {
  border-color: var(--accent);
}

.menu-controls {
  margin-top: 26px;
  color: var(--muted);
  font-size: 14px;
  letter-spacing: 0.5px;
}

/* ============================================================
   RACE SCREEN
   ============================================================ */
body.in-race .topbar {
  display: none;
}
body.in-race #app {
  max-width: none;
  padding: 0;
  height: 100%;
  overflow: hidden;
}
body.in-race #screen-race.active {
  display: block;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100svh;
  max-height: 100svh;
  overflow: hidden;
  z-index: 5;
}

.race-stage {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100svh;
  overflow: hidden;
  background: #16351f;
  user-select: none;
  touch-action: none;
  box-sizing: border-box;
}
#raceCanvas {
  position: absolute;
  inset: 0;
  display: block;
}

/* ---- HUD ---- */
.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  padding: 14px 16px;
}
.hud-top {
  display: flex;
  align-items: center;
  gap: 12px;
}
.hud-pill {
  pointer-events: none;
  background: rgba(11, 14, 23, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 8px 16px;
  border-radius: 999px;
  font-weight: 900;
  font-size: 22px;
  color: var(--gold);
  min-width: 78px;
  text-align: center;
}
.hud-pill span {
  font-size: 13px;
  color: var(--muted);
  font-weight: 700;
}
.hud-progress {
  flex: 1;
  height: 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.1);
  overflow: hidden;
}
.hud-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.1s linear;
}
.hud-quit {
  pointer-events: auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(11, 14, 23, 0.7);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}
.hud-quit:hover {
  background: var(--accent);
}
.hud-health {
  position: absolute;
  left: 16px;
  top: 70px;
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(280px, 45vw);
}
.hud-health-label {
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
}
.hud-health-bar {
  flex: 1;
  height: 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12);
  overflow: hidden;
}
.hud-health-fill {
  height: 100%;
  width: 100%;
  background: var(--green);
  transition: width 0.12s linear, background 0.2s;
}

/* ---- Kill / death feed ---- */
.killfeed {
  position: absolute;
  top: 64px;
  right: 16px;
  width: min(300px, 60vw);
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}
.killfeed-item {
  align-self: flex-end;
  background: rgba(11, 14, 23, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-left: 3px solid var(--muted);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  transition: opacity 0.8s ease;
  max-width: 100%;
}
.killfeed-item.kill-you {
  border-left-color: var(--green);
  color: #d7ffe9;
}
.killfeed-item.death-you {
  border-left-color: var(--accent);
  color: #ffd9d6;
}
.killfeed-item.block {
  border-left-color: var(--blue);
}
.killfeed-item.fade {
  opacity: 0;
}

/* ---- Ability bar ---- */
.ability-bar {
  position: absolute;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  pointer-events: auto;
  z-index: 11;
  max-width: calc(100vw - 160px);
  justify-content: center;
  flex-wrap: wrap;
}
.ability-slot {
  position: relative;
  width: 58px;
  height: 58px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(11, 14, 23, 0.8);
  overflow: hidden;
  cursor: pointer;
  color: var(--text);
  transition: transform 0.1s, box-shadow 0.15s;
}
.ability-slot.ready {
  box-shadow: 0 0 0 2px rgba(53, 208, 127, 0.6), 0 6px 16px rgba(0, 0, 0, 0.4);
}
.ability-slot:active {
  transform: scale(0.94);
}
.ability-key {
  position: absolute;
  top: 3px;
  left: 5px;
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
  z-index: 3;
}
.ability-icon {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 26px;
  z-index: 2;
}
.ability-cd {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 0%;
  background: rgba(0, 0, 0, 0.62);
  z-index: 2;
  transition: height 0.08s linear;
}
.ability-cd-text {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 800;
  color: #fff;
  z-index: 3;
  text-shadow: 0 1px 3px #000;
}
.ability-slot.locked {
  box-shadow: none;
  opacity: 0.8;
}
.ability-slot.used {
  box-shadow: none;
  opacity: 0.55;
  filter: grayscale(0.7);
}
.ability-slot.used .ability-cd-text {
  font-size: 10px;
  letter-spacing: 0.5px;
}
.ability-empty {
  background: rgba(11, 14, 23, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 12px 18px;
  border-radius: 12px;
  color: var(--muted);
  font-size: 13px;
}

/* ---- Mobile joystick ---- */
.joystick {
  position: absolute;
  left: max(12px, env(safe-area-inset-left, 0px));
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  width: 120px;
  height: 120px;
  border-radius: 50%;
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  opacity: 0.95;
  z-index: 30;
}
.joystick-base {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.22);
  background: rgba(11, 14, 23, 0.45);
  box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.35);
}
.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  margin-left: -24px;
  margin-top: -24px;
  border-radius: 50%;
  border: 2px solid rgba(127, 208, 255, 0.65);
  background: rgba(127, 208, 255, 0.35);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}
.joystick.is-active .joystick-knob {
  background: rgba(127, 208, 255, 0.7);
}
@media (hover: hover) and (pointer: fine) {
  .joystick {
    opacity: 0.28;
  }
}

/* ---- Grace / ceasefire banner ---- */
.grace-banner {
  position: absolute;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  padding: 10px 22px;
  border-radius: 999px;
  background: rgba(11, 14, 23, 0.82);
  border: 1px solid rgba(127, 208, 255, 0.5);
  color: #cfeaff;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: 0.4px;
  white-space: nowrap;
  z-index: 9;
  pointer-events: none;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}
.grace-banner.fight {
  border-color: var(--accent);
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-size: 22px;
  animation: countPop 0.35s ease;
}

/* ---- Countdown ---- */
.countdown {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  font-size: clamp(80px, 20vw, 200px);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  z-index: 10;
}
.countdown.pop {
  animation: countPop 0.4s ease;
}
@keyframes countPop {
  from {
    transform: scale(2.2);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* ---- Results ---- */
.results {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(6, 8, 14, 0.75);
  backdrop-filter: blur(4px);
  z-index: 20;
}
.results.show {
  display: grid;
  animation: fade 0.3s ease;
}
.results-card {
  width: min(420px, 90vw);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  box-shadow: var(--shadow);
}
.results-card h2 {
  font-size: 30px;
  font-weight: 900;
}
.results-place {
  margin: 6px 0 18px;
  font-size: 40px;
  font-weight: 900;
  color: var(--gold);
}
.results-place span {
  font-size: 16px;
  color: var(--muted);
  font-weight: 700;
}
.results-lines {
  list-style: none;
  text-align: left;
  margin: 0 auto 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.results-lines li {
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 8px;
  font-size: 14px;
}
.results-lines li span:first-child {
  color: var(--muted);
}
.results-earned {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 26px;
  font-weight: 900;
  margin-bottom: 20px;
}
.results-earned .coin-icon {
  color: var(--gold);
}
.results-earned-label {
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
}
.results-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ---------- Responsive ---------- */
@media (max-width: 520px) {
  .brand-name {
    display: none;
  }
  .menu-hero {
    padding-top: 50px;
  }
  .ability-slot {
    width: 46px;
    height: 46px;
  }
  .ability-icon {
    font-size: 20px;
  }
  .joystick {
    width: 112px;
    height: 112px;
    left: 10px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }
  .joystick-knob {
    width: 44px;
    height: 44px;
    margin-left: -22px;
    margin-top: -22px;
  }
}
