/* Tay Lái Việt — giao diện: tối, cam đỏ hoàng hôn, chữ nghiêng mạnh */
:root {
  --bg: #0f1118;
  --panel: rgba(16, 18, 27, 0.78);
  --panel2: #222736;
  --line: rgba(255, 255, 255, 0.12);
  --text: #f3f4fa;
  --muted: #a0a7c0;
  --hot: #ffb627;
  --hot2: #ff5e3a;
  --red: #ff4d5e;
  --green: #52f08d;
  --blue: #45c8ff;
}
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
[hidden] {
  display: none !important;
}
html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Be Vietnam Pro", system-ui, sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}
button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  background: radial-gradient(ellipse at 50% 120%, #ff7a3a55, transparent 60%), linear-gradient(180deg, #1c2340, #0f1118 70%);
}
#gl,
#fx {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
#fx {
  pointer-events: none;
}
.grow {
  flex: 1;
}

/* ---------- nút ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--panel2);
  border-radius: 12px;
  padding: 11px 18px;
  font-weight: 800;
  font-size: 15px;
  transition: transform 0.08s;
}
.btn:active {
  transform: scale(0.96);
}
.btn.primary {
  background: linear-gradient(180deg, #ffc94d, #ff6a2a);
  color: #2a0f00;
  border-color: transparent;
  box-shadow: 0 6px 20px rgba(255, 120, 40, 0.35);
}
.btn.big {
  font-size: 18px;
  padding: 13px 28px;
}
.btn.danger {
  background: transparent;
  color: var(--red);
  border-color: rgba(255, 77, 94, 0.4);
  font-size: 13px;
}
.icon-btn {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(16, 18, 27, 0.7);
  font-size: 16px;
  font-weight: 800;
}
.back {
  color: var(--muted);
  text-decoration: none;
  font-weight: 700;
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.07);
}
.btns {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}
.seg {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: var(--panel2);
  border-radius: 12px;
  padding: 4px;
  border: 1px solid var(--line);
}
.seg span {
  padding: 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.seg button {
  border: 0;
  background: transparent;
  border-radius: 9px;
  padding: 7px 12px;
  font-weight: 800;
  font-size: 14px;
  color: var(--muted);
}
.seg button.on {
  background: var(--hot);
  color: #2a1400;
}

/* ---------- màn ---------- */
.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  overflow: auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: radial-gradient(ellipse at 50% 0%, rgba(255, 140, 40, 0.16), transparent 60%), rgba(10, 12, 20, 0.62);
  backdrop-filter: blur(2px);
}
.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
}
.bar h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 900;
  font-style: italic;
}
.home-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 0 16px 24px;
  text-align: center;
}
.logo {
  margin: 0;
  font-size: clamp(46px, 10vw, 96px);
  font-weight: 900;
  font-style: italic;
  letter-spacing: -2px;
  line-height: 1;
  color: #fff;
  text-shadow: 5px 5px 0 #c4301a, 0 10px 40px rgba(0, 0, 0, 0.5);
}
.logo span {
  color: var(--hot);
}
.tag {
  margin: 0;
  color: #d6dbea;
  max-width: 480px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
}
.modes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  width: min(720px, 100%);
}
.mode {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 18px 10px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: linear-gradient(160deg, rgba(48, 54, 78, 0.92), rgba(24, 27, 40, 0.92));
  transition:
    transform 0.12s,
    border-color 0.15s;
}
.mode:hover {
  transform: translateY(-3px) skewX(-2deg);
  border-color: var(--hot);
}
.mode span {
  font-size: 34px;
}
.mode b {
  font-size: 18px;
  font-style: italic;
}
.mode small {
  color: var(--muted);
  font-size: 12.5px;
}
.settings {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.checks {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  color: #cfd5e6;
  font-size: 14px;
  font-weight: 600;
}
.checks input {
  accent-color: var(--hot);
  width: 16px;
  height: 16px;
  vertical-align: -3px;
}
.nogl {
  color: var(--red);
  max-width: 460px;
  font-weight: 700;
}

/* ---------- chọn ---------- */
.setup-body {
  width: min(1000px, 100%);
  margin: 0 auto;
  padding: 0 16px 24px;
}
.setup-body h3 {
  margin: 8px 0 10px;
  font-size: 14px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.picks {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
}
.pick {
  position: relative;
  padding: 0;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: var(--panel2);
  overflow: hidden;
  text-align: left;
}
.pick canvas {
  display: block;
  width: 100%;
  height: 104px;
}
.pick .pi {
  padding: 7px 10px 9px;
}
.pick .pi b {
  display: block;
  font-size: 14px;
}
.pick .pi small {
  color: var(--muted);
  font-size: 12px;
}
.pick.on {
  border-color: var(--hot);
  box-shadow: 0 0 0 3px rgba(255, 182, 39, 0.25);
}
.pick.locked {
  opacity: 0.45;
}
.pick .lock {
  position: absolute;
  right: 8px;
  top: 8px;
  font-size: 18px;
}
.pick .wx {
  position: absolute;
  left: 8px;
  top: 8px;
  font-size: 16px;
  background: rgba(0, 0, 0, 0.45);
  border-radius: 8px;
  padding: 1px 6px;
}
.pick.cup .cupico {
  font-size: 40px;
  text-align: center;
  padding: 12px 0 0;
}
.pick.cup .tracks {
  display: flex;
  gap: 4px;
  padding: 6px 8px 0;
}
.pick.cup .tracks canvas {
  height: 46px;
  border-radius: 6px;
}
.cars {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}
.car {
  position: relative;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: var(--panel2);
  padding: 8px 8px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
}
.car canvas {
  width: 100%;
  max-width: 150px;
  height: auto;
}
.car b {
  font-size: 14px;
}
.car small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}
.car .stats {
  width: 100%;
  display: grid;
  gap: 2px;
  margin-top: 4px;
}
.car .stats div {
  display: grid;
  grid-template-columns: 54px 1fr;
  align-items: center;
  font-size: 10px;
  color: var(--muted);
  text-align: left;
}
.car .stats i {
  height: 5px;
  border-radius: 3px;
  background: linear-gradient(90deg, #ff6a2a, #ffc94d);
}
.car.on {
  border-color: var(--hot);
  box-shadow: 0 0 0 3px rgba(255, 182, 39, 0.25);
}
.car.locked {
  opacity: 0.45;
}
.car .lock {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 800;
  background: rgba(10, 12, 20, 0.6);
  border-radius: 12px;
  padding: 6px;
}
.row-end {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 16px;
}
.segs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------- HUD ---------- */
.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}
.hud-l {
  position: absolute;
  left: max(10px, env(safe-area-inset-left));
  top: max(10px, env(safe-area-inset-top));
  display: flex;
  gap: 8px;
}
.pill {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 5px 12px 6px;
  text-align: center;
  min-width: 64px;
}
.pill small {
  display: block;
  font-size: 10px;
  font-weight: 800;
  color: var(--muted);
  letter-spacing: 1px;
}
.pill b {
  font-size: 22px;
  font-weight: 900;
  font-style: italic;
  font-variant-numeric: tabular-nums;
}
.pill.p1 b {
  color: var(--hot);
}
.pill.wide {
  min-width: 110px;
}
.pill i {
  display: block;
  font-style: normal;
  font-weight: 900;
  font-size: 13px;
  color: var(--hot);
  min-height: 15px;
}
.hud-c {
  min-width: 112px;
}
.hud-c b {
  display: block;
  font-size: 20px;
  font-style: normal;
}
.hud-c b.low {
  color: var(--red);
}
.hud-c small + b + small {
  font-size: 10px;
  letter-spacing: 0;
  min-height: 12px;
}
.trip {
  height: 5px;
  margin-top: 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.15);
  overflow: hidden;
  width: 160px;
}
.trip i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--blue), var(--green));
}
.hud-r {
  position: absolute;
  right: max(10px, env(safe-area-inset-right));
  top: max(10px, env(safe-area-inset-top));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}
.btnrow {
  display: flex;
  gap: 6px;
}
.hud-r .icon-btn {
  pointer-events: auto;
}
.mini {
  width: 130px;
  height: 110px;
  background: rgba(10, 12, 20, 0.5);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.speed {
  position: absolute;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  translate: -50% 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 2px 14px 4px 34px;
  text-align: right;
  min-width: 120px;
}
.speed b {
  font-size: 32px;
  font-weight: 900;
  font-style: italic;
  font-variant-numeric: tabular-nums;
}
.speed small {
  margin-left: 4px;
  color: var(--muted);
  font-weight: 700;
}
.speed span {
  position: absolute;
  left: 10px;
  top: 6px;
  font-weight: 900;
  color: var(--hot);
  font-size: 14px;
}
.msg {
  position: absolute;
  left: 50%;
  top: 30%;
  translate: -50% -50%;
  font-size: clamp(48px, 11vw, 110px);
  font-weight: 900;
  font-style: italic;
  color: #fff;
  text-shadow: 0 4px 0 #c4301a, 0 8px 30px rgba(0, 0, 0, 0.6);
  opacity: 0;
  transition: opacity 0.2s;
  white-space: nowrap;
}
.msg.on {
  opacity: 1;
}
.msg.small {
  font-size: clamp(26px, 5vw, 44px);
}
.pop {
  position: absolute;
  left: 50%;
  top: 44%;
  translate: -50% 0;
  font-size: 26px;
  font-weight: 900;
  font-style: italic;
  color: var(--hot);
  text-shadow: 0 3px 10px rgba(0, 0, 0, 0.7);
  opacity: 0;
  white-space: nowrap;
}
.pop.on {
  animation: pop 1.1s ease-out;
}
@keyframes pop {
  0% {
    opacity: 0;
    transform: translateY(10px) scale(0.8);
  }
  15% {
    opacity: 1;
    transform: translateY(0) scale(1.1);
  }
  70% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(-30px) scale(1);
  }
}
.warn {
  position: absolute;
  left: 50%;
  top: 20%;
  translate: -50% 0;
  background: rgba(200, 30, 30, 0.85);
  padding: 8px 18px;
  border-radius: 12px;
  font-weight: 900;
  font-size: 22px;
  animation: blink 0.6s infinite alternate;
}
@keyframes blink {
  to {
    opacity: 0.4;
  }
}
.mirror {
  position: absolute;
  z-index: 4;
  border: 5px solid #16171b;
  border-radius: 14px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45), inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  pointer-events: none;
}

/* ---------- nút cảm ứng ---------- */
.touch {
  position: absolute;
  inset: auto 0 0 0;
  z-index: 6;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  pointer-events: none;
}
.touch .tl,
.touch .tr {
  display: flex;
  gap: 10px;
  pointer-events: auto;
}
.touch .tr {
  flex-direction: column;
  align-items: flex-end;
}
.trow {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.tb {
  width: 78px;
  height: 78px;
  border-radius: 20px;
  border: 2px solid rgba(255, 255, 255, 0.28);
  background: rgba(16, 18, 27, 0.5);
  font-size: 28px;
  font-weight: 900;
  touch-action: none;
}
.tb.small {
  width: 100px;
  height: 40px;
  font-size: 12px;
  letter-spacing: 1px;
}
.tb.pedal {
  font-size: 12px;
  letter-spacing: 0;
}
.tb.gas {
  height: 104px;
  background: rgba(40, 140, 70, 0.45);
}
.tb.brk {
  background: rgba(160, 40, 40, 0.45);
}
.tb.on {
  background: rgba(255, 182, 39, 0.55);
}
.touch.has-hud-c {
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

/* ---------- đang dựng ---------- */
.loading {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  background: rgba(10, 12, 20, 0.88);
  font-size: 18px;
}
.spin {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 5px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--hot);
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- kết quả ---------- */
.result {
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.res-card {
  width: min(520px, 100%);
  background: rgba(20, 23, 34, 0.94);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px 18px 20px;
  text-align: center;
  margin: auto;
}
.res-ico {
  font-size: 54px;
  line-height: 1;
}
.res-card h2 {
  margin: 6px 0 4px;
  font-size: 28px;
  font-weight: 900;
  font-style: italic;
}
.res-sub {
  margin: 0 0 12px;
  color: var(--muted);
}
.table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 14px;
  font-size: 14px;
}
.table th {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 1px;
  text-align: left;
  padding: 4px 8px;
}
.table td {
  padding: 5px 8px;
  border-top: 1px solid var(--line);
  text-align: left;
  font-variant-numeric: tabular-nums;
}
.table tr.me td {
  color: var(--hot);
  font-weight: 800;
}
.table .dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: 0;
}
.rec {
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
}

/* ---------- lớp phủ ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(6, 8, 14, 0.7);
  padding: 16px;
}
.sheet {
  position: relative;
  width: min(560px, 100%);
  max-height: 100%;
  overflow: auto;
  background: rgba(22, 25, 37, 0.97);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px 20px 20px;
}
.sheet h2 {
  margin: 0 0 14px;
  font-style: italic;
  text-align: center;
}
.sheet ul {
  padding-left: 18px;
  margin: 0 0 16px;
  color: #d5dae8;
  font-size: 14px;
  line-height: 1.55;
}
.sheet li {
  margin-bottom: 6px;
}
.close {
  position: absolute;
  right: 10px;
  top: 8px;
  border: 0;
  background: transparent;
  font-size: 28px;
  color: var(--muted);
}
.toast {
  position: absolute;
  left: 50%;
  bottom: 24px;
  translate: -50% 0;
  z-index: 40;
  background: rgba(20, 23, 34, 0.95);
  border: 1px solid var(--line);
  padding: 10px 16px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 14px;
  max-width: 90vw;
  text-align: center;
}
.rotate {
  position: absolute;
  left: 50%;
  top: 46%;
  translate: -50% 0;
  z-index: 7;
  background: rgba(20, 23, 34, 0.85);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
}

/* ---------- màn hẹp ---------- */
@media (max-width: 720px) {
  .modes {
    grid-template-columns: 1fr;
    max-width: 380px;
  }
  .mode {
    flex-direction: row;
    gap: 12px;
    padding: 12px 16px;
    text-align: left;
  }
  .mode span {
    font-size: 28px;
  }
  .mode small {
    margin-left: auto;
    text-align: right;
  }
  .cars {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  }
  .mini {
    width: 96px;
    height: 80px;
  }
  .pill b {
    font-size: 18px;
  }
  .tb {
    width: 66px;
    height: 66px;
  }
  .tb.gas {
    height: 90px;
  }
}
@media (max-height: 520px) {
  .home-body {
    gap: 10px;
    justify-content: flex-start;
    padding-top: 4px;
  }
  .logo {
    font-size: 44px;
  }
  .tag {
    display: none;
  }
  .mode {
    padding: 10px 8px;
  }
  .mode span {
    font-size: 24px;
  }
  .mini {
    width: 100px;
    height: 76px;
  }
  .tb {
    width: 64px;
    height: 64px;
  }
  .tb.gas {
    height: 84px;
  }
  .tb.small {
    height: 34px;
  }
}
