:root {
  --bg: #14161c;
  --bg-soft: #1c2029;
  --panel: rgba(30, 34, 44, 0.92);
  --line: rgba(255, 255, 255, 0.12);
  --text: #eef1f6;
  --muted: #9aa3b2;
  --accent: #ff8a3d;
  --accent2: #22c3c8;
  --ok: #7ddc8a;
  --warn: #ffcf4a;
  --crit: #ff5b4a;
  --radius: 14px;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app { position: relative; width: 100%; height: 100%; }

.screen {
  position: absolute;
  inset: 0;
  display: none;
  overflow: auto;
}
.screen.active { display: block; }
.screen.race.active { display: block; overflow: hidden; }

/* ------------------------------------------------------------------ menus */

#screen-title, #screen-lobby, #screen-results {
  background:
    radial-gradient(1200px 700px at 50% -10%, #2b3140 0%, transparent 60%),
    repeating-linear-gradient(90deg, #14161c 0 40px, #161920 40px 80px);
}

.title-wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: 42px 20px 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.logo {
  margin: 0;
  font-size: clamp(44px, 9vw, 76px);
  letter-spacing: -2px;
  line-height: 0.95;
  text-align: center;
  color: #fff;
  text-shadow: 0 5px 0 #b3341f, 0 10px 24px rgba(0, 0, 0, 0.55);
}
.logo span { color: var(--accent); }

.tagline {
  margin: -6px 0 6px;
  color: var(--muted);
  font-size: 15px;
  text-align: center;
}

.section-title {
  margin: 8px 0 0;
  font-size: 26px;
  color: #fff;
}

.panel {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}

.field { display: flex; flex-direction: column; gap: 7px; }
.field > span, .field label > span {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
}
.field.two { flex-direction: row; gap: 12px; }
.field.two > label { flex: 1; display: flex; flex-direction: column; gap: 7px; }

input[type="text"], select {
  width: 100%;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #12151b;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
}
input[type="text"]:focus, select:focus { border-color: var(--accent); }
input[readonly] { color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  flex: 1 1 150px;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #12151b;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.chip small { display: block; color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.chip:hover { transform: translateY(-1px); }
.chip.on { border-color: var(--accent); background: rgba(255, 138, 61, 0.14); }

.btn {
  padding: 12px 18px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: #232833;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease;
}
.btn:hover { transform: translateY(-1px); background: #2a3040; }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(180deg, #ff9f56, #ef6d24);
  border-color: #d5561a;
  color: #201004;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
}
.btn.primary:hover { background: linear-gradient(180deg, #ffad6c, #f5772c); }
.btn.ghost { background: transparent; }
.btn.small { padding: 8px 14px; font-size: 13px; }
.btn.full { width: 100%; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; transform: none; }

.actions { display: flex; gap: 10px; }
.actions .btn { flex: 1; }

.status { margin: 0; font-size: 13.5px; color: var(--muted); min-height: 18px; }
.status.error { color: var(--crit); }
.status.ok { color: var(--ok); }
.hint { margin: 0; font-size: 12.5px; color: var(--muted); }
.hidden { display: none !important; }

.players { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.players li {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 11px;
  border-radius: 9px;
  background: #12151b;
  font-size: 14px;
}
.players li b {
  width: 12px; height: 12px; border-radius: 4px; display: inline-block;
}
.players li .tag { margin-left: auto; font-size: 11px; color: var(--muted); }

.binds { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.binds li {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #12151b;
  border: 1px solid transparent;
}
.binds li.capturing { border-color: var(--accent); background: rgba(255, 138, 61, 0.12); }
.binds .act { flex: 1; font-size: 14px; }
.binds .def {
  min-width: 34px;
  text-align: center;
  padding: 3px 8px;
  border-radius: 6px;
  background: #262b36;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  font-size: 12.5px;
  color: var(--muted);
}
.binds .bind { min-width: 138px; font-size: 12.5px; padding: 7px 10px; }
.binds li.capturing .bind { border-color: var(--accent); color: var(--accent); }
.binds .clear { width: 34px; padding: 7px 0; text-align: center; background: transparent; }

.controls-help {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
}
kbd {
  display: inline-block;
  min-width: 22px;
  padding: 2px 6px;
  margin-right: 4px;
  border-radius: 5px;
  background: #262b36;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  text-align: center;
}

.results { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.results li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #12151b;
  font-size: 15px;
}
.results li.me { background: rgba(255, 138, 61, 0.16); }
.results .pos { width: 26px; font-weight: 700; color: var(--muted); }
.results li.p1 .pos { color: #ffd166; }
.results .swatch { width: 14px; height: 14px; border-radius: 5px; }
.results .name { flex: 1; }
.results .time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13.5px; }

/* ------------------------------------------------------------------- race */

#screen-race { background: #0f1116; }
#view { display: block; width: 100%; height: 100%; }

#hud { position: absolute; inset: 0; pointer-events: none; }
#hud-effects { position: absolute; inset: 0; transition: box-shadow 0.2s ease; }
#hud-effects.oiled { box-shadow: inset 0 0 140px rgba(125, 107, 224, 0.45); }
#hud-effects.turbo { box-shadow: inset 0 0 160px rgba(255, 150, 60, 0.35); }
#hud-effects.hurt { box-shadow: inset 0 0 180px rgba(255, 60, 40, 0.4); }

.hud-corner { position: absolute; display: flex; gap: 10px; }
.hud-corner.top-left { top: 14px; left: 14px; flex-direction: column; align-items: flex-start; }
.hud-corner.top-right { top: 14px; right: 14px; flex-direction: column; align-items: flex-end; }
.hud-corner.bottom-left { bottom: 14px; left: 14px; flex-direction: column; }
.hud-corner.bottom-right { bottom: 14px; right: 14px; }

.badge {
  background: rgba(20, 23, 30, 0.78);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px 14px;
  font-size: 15px;
  color: var(--muted);
  backdrop-filter: blur(3px);
}
.badge b { color: #fff; font-size: 26px; margin-right: 1px; }
.badge.place b { color: var(--accent); }
.badge small { font-size: 13px; }

.timebox {
  background: rgba(20, 23, 30, 0.78);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  min-width: 176px;
  backdrop-filter: blur(3px);
}
.timebox .row { display: flex; justify-content: space-between; gap: 14px; font-size: 13px; color: var(--muted); }
.timebox .row b { color: #fff; font-variant-numeric: tabular-nums; }
.timebox .row.best b { color: var(--ok); }

.standings {
  list-style: none;
  margin: 0;
  padding: 6px;
  background: rgba(20, 23, 30, 0.7);
  border: 1px solid var(--line);
  border-radius: 12px;
  min-width: 176px;
  backdrop-filter: blur(3px);
}
.standings li {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 3px 6px;
  border-radius: 7px;
  font-size: 12.5px;
  color: var(--muted);
}
.standings li.me { background: rgba(255, 138, 61, 0.18); color: #fff; }
.standings li.wrecked { opacity: 0.45; }
.standings li b { width: 9px; height: 9px; border-radius: 3px; }
.standings .pos { width: 14px; text-align: right; }
.standings .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 96px; }
.standings .lap { font-variant-numeric: tabular-nums; font-size: 11px; }

.damage {
  background: rgba(20, 23, 30, 0.78);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  width: 230px;
  backdrop-filter: blur(3px);
}
.damage-title { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 6px; }
.damage-title i { float: right; font-style: normal; color: #fff; }
.damage-bar { height: 11px; background: #0d0f14; border-radius: 6px; overflow: hidden; }
.damage-bar > div { height: 100%; width: 100%; border-radius: 6px; transition: width 0.15s linear, background 0.3s ease; }
.damage-bar > div.ok { background: linear-gradient(90deg, #4bbf6b, #7ddc8a); }
.damage-bar > div.warn { background: linear-gradient(90deg, #e0a52c, #ffcf4a); }
.damage-bar > div.crit { background: linear-gradient(90deg, #d1382a, #ff5b4a); }

.item-slot {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(20, 23, 30, 0.78);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  width: 230px;
  backdrop-filter: blur(3px);
  --item-color: #444;
}
.item-slot.filled { border-color: var(--item-color); box-shadow: 0 0 18px -6px var(--item-color); }
.item-slot canvas { width: 40px; height: 40px; }
.item-meta { flex: 1; min-width: 0; }
.item-meta span { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-slot em { font-style: normal; font-size: 10px; color: var(--muted); border: 1px solid var(--line); border-radius: 5px; padding: 2px 5px; }
.fuse { height: 4px; background: #0d0f14; border-radius: 3px; margin-top: 5px; overflow: hidden; }
.fuse i { display: block; height: 100%; background: var(--accent); transform-origin: left center; transition: transform 0.1s linear; }
.item-slot.expiring .fuse i { background: var(--crit); }

#minimap {
  width: 230px;
  height: 170px;
  background: rgba(20, 23, 30, 0.72);
  border: 1px solid var(--line);
  border-radius: 12px;
  backdrop-filter: blur(3px);
}

.hud-message {
  position: absolute;
  top: 22%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.7);
  font-size: 62px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.4), 0 12px 30px rgba(0, 0, 0, 0.6);
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
  text-align: center;
}
.hud-message small { display: block; font-size: 20px; font-weight: 400; color: var(--warn); }
.hud-message.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

.hud-toast {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, 6px);
  font-size: 22px;
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  text-shadow: 0 3px 12px rgba(0, 0, 0, 0.7);
}
.hud-toast.show { opacity: 1; transform: translate(-50%, 0); }

.btn.quit {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: auto;
  padding: 6px 14px;
  font-size: 12.5px;
  opacity: 0.5;
}
.btn.quit:hover { opacity: 1; }

@media (max-width: 720px) {
  .damage, .item-slot { width: 170px; }
  #minimap { width: 150px; height: 112px; }
  .hud-message { font-size: 44px; }
}
