:root {
  --bg: #081120;
  --panel: rgba(13, 24, 42, 0.92);
  --panel-2: rgba(22, 38, 64, 0.86);
  --line: rgba(120, 165, 220, 0.22);
  --text: #e8f0fb;
  --dim: #93a8c4;
  --accent: #ff4d4d;
  --accent-2: #38b6ff;
  --good: #43d17a;
  --warn: #ffcc4d;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior: none;
}

.hidden { display: none !important; }

/* ------------------------------------------------------------- icons */

.li {
  width: 1.05em;
  height: 1.05em;
  flex: none;
  display: inline-block;
  vertical-align: -0.14em;
}
.i { display: inline-flex; align-items: center; }
h1 .i, h2 .i { margin-right: 6px; }
button .i { margin-right: 5px; }
button .i:only-child { margin-right: 0; }
.icon-btn .li { width: 1.15em; height: 1.15em; }
.ctl .li { width: 34px; height: 34px; color: #dfeaff; }
.feed-ic { width: 1.1em; height: 1.1em; color: #7fc4ff; }

.hearts { color: #ff6b6b; display: inline-flex; gap: 2px; align-items: center; vertical-align: -0.1em; }
.heart { width: 1.15em; height: 1.15em; }
.heart-full { fill: #ff4d4d; stroke: #ff8080; }
.heart-empty { fill: none; stroke: rgba(255, 120, 120, 0.5); }

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ------------------------------------------------------------ screens */

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  background:
    radial-gradient(1200px 600px at 20% 10%, rgba(56, 182, 255, 0.16), transparent 60%),
    radial-gradient(900px 500px at 85% 90%, rgba(255, 77, 77, 0.14), transparent 60%),
    var(--bg);
  z-index: 20;
  overflow-y: auto;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
  width: min(560px, 100%);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
}

/* -------------------------------------------------------- welcome screen */

.auth-screen {
  overflow-y: auto;
  background: #040e1a;
}

#auth-bg {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  filter: blur(11px) saturate(1.3) brightness(0.82);
  transform: scale(1.08);
  pointer-events: none;
}

.auth-veil {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(900px 620px at 20% 14%, rgba(56, 182, 255, 0.22), transparent 62%),
    radial-gradient(760px 520px at 84% 88%, rgba(255, 77, 77, 0.20), transparent 62%),
    linear-gradient(180deg, rgba(4, 10, 20, 0.5), rgba(4, 10, 20, 0.82));
}

.auth-card {
  position: relative;
  z-index: 1;
  background: rgba(10, 20, 36, 0.82);
  border-color: rgba(150, 195, 245, 0.26);
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(14px) saturate(1.2);
}

.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.brand-mark {
  width: 46px;
  height: 46px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(150deg, rgba(255, 90, 90, 0.95), rgba(211, 47, 47, 0.95));
  box-shadow: 0 8px 22px rgba(211, 47, 47, 0.35);
}
.brand-mark .li { width: 26px; height: 26px; color: #fff; }
.brand h1 { font-size: 23px; margin: 0; letter-spacing: -0.4px; }
.brand-sub {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--dim);
  display: flex;
  align-items: center;
  gap: 5px;
  letter-spacing: 0.02em;
}
.brand-sub .li { width: 13px; height: 13px; color: #9fd0ff; }

.auth-points { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.auth-points li { display: flex; align-items: flex-start; gap: 8px; font-size: 12.5px; color: var(--dim); line-height: 1.45; }
.auth-points .li { width: 15px; height: 15px; margin-top: 1px; color: #7fc4ff; flex: none; }

h1 { font-size: 22px; margin: 0 0 6px; letter-spacing: -0.2px; }
h2 { font-size: 18px; margin: 0; }
.sub { color: var(--dim); font-size: 13px; margin: 0 0 16px; line-height: 1.45; }
.tiny { font-size: 12px; line-height: 1.5; }
.dim { color: var(--dim); }

label {
  display: block;
  font-size: 12px;
  color: var(--dim);
  margin: 12px 0 0;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

input {
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
  text-transform: none;
  letter-spacing: 0;
}
input:focus { outline: 2px solid rgba(56, 182, 255, 0.5); border-color: transparent; }

button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  transition: transform 0.06s ease, background 0.15s ease;
}
button:active { transform: scale(0.985); }
button.primary {
  width: 100%;
  margin-top: 16px;
  background: linear-gradient(180deg, #ff5a5a, #d32f2f);
  border-color: rgba(255, 255, 255, 0.16);
  font-weight: 700;
  font-size: 16px;
}
button.primary.big { padding: 16px; font-size: 18px; }
button.ghost { background: transparent; }
button:disabled { opacity: 0.55; cursor: default; }

.tabs { display: flex; gap: 8px; margin-bottom: 6px; }
.tab { flex: 1; font-size: 13px; }
.tab.active { background: linear-gradient(180deg, #2c6fb8, #1b4b83); border-color: transparent; font-weight: 600; }

.error { color: #ff8a8a; font-size: 13px; min-height: 18px; margin-top: 10px; }
.warn {
  background: rgba(255, 204, 77, 0.12);
  border: 1px solid rgba(255, 204, 77, 0.4);
  color: var(--warn);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
  margin-top: 12px;
}

.btn-row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.btn-row button { flex: 1; min-width: 120px; font-size: 13px; }

/* --------------------------------------------------------------- lobby */

.lobby-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.lobby-ride {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 14px 0 0;
  font-size: 13px;
  color: var(--dim);
}
.lobby-ride .li { color: #9fd0ff; }
.lobby-ride b { color: var(--text); }

#btn-play { position: relative; overflow: hidden; animation: playPulse 2.8s ease-in-out infinite; }
#btn-play::after {
  content: "";
  position: absolute;
  top: -2px;
  bottom: -2px;
  left: -50%;
  width: 40%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.34), transparent);
  transform: skewX(-18deg);
  animation: playSheen 3.6s ease-in-out infinite;
  pointer-events: none;
}
@keyframes playPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 77, 77, 0.45); }
  50% { box-shadow: 0 0 0 11px rgba(255, 77, 77, 0); }
}
@keyframes playSheen {
  0% { left: -50%; }
  55%, 100% { left: 120%; }
}
@media (prefers-reduced-motion: reduce) {
  #btn-play, #btn-play::after { animation: none; }
}

.xp-wrap { margin-top: 14px; }
.xp-bar { height: 10px; border-radius: 999px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.xp-bar > div { height: 100%; width: 0; background: linear-gradient(90deg, #38b6ff, #43d17a); transition: width 0.4s ease; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(10, 20, 36, 0.78);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.chip .li { color: #9fd0ff; opacity: 0.95; }
.chip.hearts .li { color: inherit; }

/* ----------------------------------------------------------------- HUD */

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  padding: calc(10px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hud-top { display: flex; align-items: center; gap: 10px; }
.hud-top .icon-btn { pointer-events: auto; margin-left: auto; }
.icon-btn { padding: 8px 12px; font-size: 13px; border-radius: 10px; }

#hud-timer {
  font-size: 30px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
}
#hud-timer.low { color: #ff5a5a; animation: pulse 0.7s infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }

.hud-row { display: flex; gap: 8px; flex-wrap: wrap; }

#hud-objective {
  align-self: flex-start;
  background: rgba(10, 20, 36, 0.78);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent-2);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  max-width: 70%;
}

#feed {
  position: absolute;
  left: 12px;
  top: 46%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--dim);
  max-width: 45%;
}
#feed div { animation: fadein 0.3s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(-4px); } }

#hud-speed {
  position: absolute;
  right: 14px;
  bottom: calc(150px + env(safe-area-inset-bottom));
  font-size: 13px;
  font-weight: 700;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------- touch controls */

#touch-controls {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(14px + env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-between;
  padding: 0 16px;
  pointer-events: none;
}
.pad { display: flex; gap: 14px; pointer-events: auto; }
.ctl {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  font-size: 24px;
  background: rgba(16, 30, 52, 0.72);
  border: 2px solid rgba(140, 185, 235, 0.35);
  backdrop-filter: blur(4px);
  user-select: none;
  touch-action: none;
}
.ctl.held { background: rgba(56, 182, 255, 0.4); transform: scale(0.95); }

/* ---------------------------------------------------------------- modal */

#modal { z-index: 30; }
.modal-card { max-width: 480px; }
.modal-card h2 { margin-bottom: 6px; }
.modal-big { font-size: 34px; font-weight: 800; text-align: center; margin: 10px 0 2px; }
.modal-big.good { color: var(--good); }
.modal-big.bad { color: var(--accent); }
.modal-sub { text-align: center; color: var(--dim); font-size: 13px; margin: 0 0 8px; }
.rows { margin: 14px 0 4px; display: flex; flex-direction: column; gap: 6px; }
.rows div { display: flex; justify-content: space-between; font-size: 14px; }
.rows span:last-child { font-weight: 700; }

.vehicle-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
}
.vehicle-card.selected {
  border-color: rgba(67, 209, 122, 0.7);
  box-shadow: 0 0 0 1px rgba(67, 209, 122, 0.35) inset;
}
.vehicle-card.owned { background: rgba(20, 34, 58, 0.92); }
.thumb { line-height: 0; border-radius: 10px; overflow: hidden; }
.veh-name { display: flex; align-items: center; gap: 6px; font-size: 14px; margin-bottom: 6px; }
.veh-name .li { color: var(--good); }
.veh-name .tag {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--good);
  background: rgba(67, 209, 122, 0.16);
  border: 1px solid rgba(67, 209, 122, 0.45);
  border-radius: 999px;
  padding: 1px 7px;
}
.veh-stat {
  display: grid;
  grid-template-columns: 56px 1fr 36px;
  align-items: center;
  gap: 7px;
  font-size: 10.5px;
  color: var(--dim);
  margin-top: 3px;
}
.veh-stat-l { text-transform: uppercase; letter-spacing: 0.05em; }
.veh-stat-v { text-align: right; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.veh-bar { height: 6px; border-radius: 999px; background: rgba(255, 255, 255, 0.09); overflow: hidden; }
.veh-bar > i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, #38b6ff, #43d17a); }
.veh-act { min-width: 98px; display: flex; justify-content: flex-end; }
.veh-act button { padding: 8px 10px; font-size: 12px; }
#garage-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }

table.board { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 10px; }
table.board th { text-align: left; font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.06em; padding: 6px 4px; }
table.board td { padding: 8px 4px; border-top: 1px solid var(--line); }
table.board tr.me td { color: var(--good); font-weight: 700; }
table.board td.right, table.board th.right { text-align: right; }

#toast {
  position: absolute;
  left: 50%;
  bottom: 18%;
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  pointer-events: none;
}
#toast div {
  background: rgba(10, 20, 36, 0.9);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 13px;
  animation: fadein 0.25s ease;
}

@media (max-width: 560px) {
  .ctl { width: 68px; height: 68px; }
  h1 { font-size: 19px; }
  .brand h1 { font-size: 20px; }
  #hud-timer { font-size: 26px; }
  .vehicle-card { grid-template-columns: auto 1fr; }
  .veh-act { grid-column: 1 / -1; min-width: 0; }
  .veh-act button { width: 100%; }
  .thumb canvas { width: 84px !important; height: 50px !important; }
}
