/* Tốc Độ — giao diện đua xe: tối, vàng cam, chữ nghiêng mạnh */
:root {
  --bg: #11131c;
  --panel: rgba(20, 23, 34, 0.92);
  --panel2: #232838;
  --line: rgba(255, 255, 255, 0.1);
  --text: #f2f4fb;
  --muted: #9aa2bd;
  --hot: #ffcf33;
  --red: #ff4d5e;
  --green: #4dff88;
}
* {
  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;
}
#cv {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.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, #ffd84d, #ff9f1a);
  color: #241500;
  border-color: transparent;
  box-shadow: 0 6px 20px rgba(255, 170, 30, 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;
}
.btn:disabled {
  opacity: 0.4;
}
.icon-btn {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(20, 23, 34, 0.75);
  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;
}

/* ---------- 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, 170, 30, 0.14), transparent 60%), rgba(12, 14, 22, 0.86);
}
.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: 18px;
  padding: 0 16px 24px;
  text-align: center;
}
.logo {
  margin: 0;
  font-size: clamp(54px, 12vw, 104px);
  font-weight: 900;
  font-style: italic;
  letter-spacing: -2px;
  line-height: 1;
  color: #fff;
  text-shadow: 6px 6px 0 #ff4d5e;
}
.logo span {
  color: var(--hot);
}
.tag {
  margin: 0;
  color: var(--muted);
  max-width: 460px;
}
.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, #2a3045, #1b1f2d);
  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: 18px;
  flex-wrap: wrap;
  justify-content: center;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}
.settings input {
  accent-color: var(--hot);
  width: 16px;
  height: 16px;
  vertical-align: -3px;
}

/* ---------- chọn ---------- */
.setup-body {
  width: min(980px, 100%);
  margin: 0 auto;
  padding: 0 16px 24px;
}
.setup-body h3 {
  margin: 8px 0 10px;
  font-size: 15px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.picks {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 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: 110px;
}
.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, 207, 51, 0.25);
}
.pick.locked {
  opacity: 0.45;
}
.pick .lock {
  position: absolute;
  right: 8px;
  top: 8px;
  font-size: 18px;
}
.pick.cup .cupico {
  font-size: 44px;
  text-align: center;
  padding: 14px 0 0;
}
.pick.cup .tracks {
  display: flex;
  gap: 4px;
  padding: 6px 8px 0;
}
.pick.cup .tracks canvas {
  height: 48px;
  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 {
  margin: 2px 0;
}
.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: 52px 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, #ff9f1a, #ffd84d);
}
.car.on {
  border-color: var(--hot);
  box-shadow: 0 0 0 3px rgba(255, 207, 51, 0.25);
}
.car.locked {
  opacity: 0.4;
}
.car .lock {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 800;
  background: rgba(10, 12, 20, 0.55);
  border-radius: 12px;
}
.row-end {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 16px;
}
.seg {
  display: flex;
  align-items: center;
  gap: 4px;
  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 14px;
  font-weight: 800;
  color: var(--muted);
}
.seg button.on {
  background: var(--hot);
  color: #241500;
}

/* ---------- HUD ---------- */
.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.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);
}
.hud-c {
  position: absolute;
  left: 50%;
  top: max(10px, env(safe-area-inset-top));
  translate: -50% 0;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px 14px 5px;
}
.hud-c b {
  display: block;
  font-size: 22px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.hud-c small {
  font-size: 11px;
  color: var(--muted);
  font-weight: 700;
}
.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;
}
.hud-r .icon-btn {
  pointer-events: auto;
}
.mini {
  width: 150px;
  height: 110px;
  background: rgba(10, 12, 20, 0.55);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.speedo {
  position: absolute;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 6px 14px 8px;
  text-align: right;
  min-width: 120px;
}
.speedo b {
  font-size: 34px;
  font-weight: 900;
  font-style: italic;
  font-variant-numeric: tabular-nums;
}
.speedo small {
  margin-left: 4px;
  color: var(--muted);
  font-weight: 700;
}
.boostbar {
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}
.boostbar i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #3ec6ff, #7fe7ff);
}
.boostbar i.on {
  background: linear-gradient(90deg, #ff9f1a, #ffd84d);
}

/* ---------- 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(14px, 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;
  margin-bottom: 78px;
}
.tb {
  width: 76px;
  height: 76px;
  border-radius: 20px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  background: rgba(20, 23, 34, 0.55);
  font-size: 28px;
  font-weight: 900;
  touch-action: none;
}
.tb.small {
  width: 84px;
  height: 52px;
  font-size: 13px;
  letter-spacing: 1px;
}
.tb.on {
  background: rgba(255, 207, 51, 0.45);
  border-color: var(--hot);
}

/* ---------- kết quả ---------- */
.result {
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.res-card {
  width: min(560px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 22px 18px 18px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.res-ico {
  font-size: 52px;
  line-height: 1;
}
.res-card h2 {
  margin: 6px 0 2px;
  font-size: 30px;
  font-weight: 900;
  font-style: italic;
  color: var(--hot);
}
.res-sub {
  margin: 0 0 12px;
  color: var(--muted);
}
.table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
  font-size: 14px;
}
.table th {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 1px;
  font-weight: 800;
  text-align: left;
  padding: 4px 8px;
}
.table td {
  padding: 7px 8px;
  border-top: 1px solid var(--line);
  text-align: left;
  font-variant-numeric: tabular-nums;
}
.table td:last-child,
.table th:last-child {
  text-align: right;
}
.table tr.me td {
  background: rgba(255, 207, 51, 0.12);
  font-weight: 800;
}
.table .dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
}
.table .rec {
  color: var(--green);
  font-weight: 800;
}

/* ---------- phủ ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 10, 18, 0.6);
  backdrop-filter: blur(3px);
}
.sheet {
  position: relative;
  width: min(460px, 100%);
  max-height: 100%;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 22px 20px 18px;
  text-align: center;
}
.sheet h2 {
  margin: 0 0 12px;
  font-weight: 900;
  font-style: italic;
}
.sheet ul {
  text-align: left;
  padding-left: 18px;
  font-size: 14px;
  line-height: 1.55;
}
.close {
  position: absolute;
  right: 10px;
  top: 10px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  font-size: 20px;
}
.toast {
  position: absolute;
  left: 50%;
  bottom: 30px;
  translate: -50% 0;
  z-index: 30;
  background: rgba(20, 23, 34, 0.95);
  border: 1px solid var(--line);
  padding: 10px 18px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 14px;
  pointer-events: none;
}

/* ---------- điện thoại ---------- */
@media (max-width: 760px) {
  .modes {
    grid-template-columns: 1fr;
    width: min(380px, 100%);
  }
  .mode {
    flex-direction: row;
    gap: 12px;
    padding: 14px 16px;
    text-align: left;
  }
  .mode span {
    font-size: 28px;
  }
  .cars {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .picks {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .pick canvas {
    height: 80px;
  }
  .mini {
    width: 104px;
    height: 78px;
  }
  .pill b,
  .hud-c b {
    font-size: 17px;
  }
  .pill {
    min-width: 52px;
    padding: 4px 9px;
  }
  .speedo {
    bottom: auto;
    top: 64px;
    right: auto;
    left: max(10px, env(safe-area-inset-left));
    min-width: 0;
    padding: 3px 10px 5px;
  }
  .speedo b {
    font-size: 20px;
  }
  .hud-c {
    top: 60px;
    left: auto;
    right: 10px;
    translate: none;
    top: auto;
    bottom: auto;
  }
}
@media (max-width: 760px) and (orientation: portrait) {
  .hud-c {
    position: absolute;
    top: 64px;
    left: 50%;
    right: auto;
    translate: -50% 0;
  }
  .hud-r .mini {
    margin-top: 0;
  }
}
@media (max-height: 500px) and (orientation: landscape) {
  .home-body {
    gap: 10px;
  }
  .logo {
    font-size: 52px;
  }
  .tag {
    display: none;
  }
  .modes {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: min(720px, 100%);
  }
  .mode {
    flex-direction: column;
    padding: 10px;
    text-align: center;
  }
  .tb {
    width: 64px;
    height: 64px;
  }
  .tb.small {
    width: 74px;
    height: 44px;
  }
  .touch .tr {
    flex-direction: row;
    margin-bottom: 0;
    align-items: flex-end;
  }
  .mini {
    width: 110px;
    height: 80px;
  }
  .speedo {
    top: auto;
    bottom: 90px;
    right: max(14px, env(safe-area-inset-right));
    left: auto;
  }
  .hud-c {
    top: max(10px, env(safe-area-inset-top));
    left: 50%;
    translate: -50% 0;
  }
  .cars {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
  .car small {
    display: none;
  }
  .picks {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .pick canvas {
    height: 64px;
  }
}
