/* ============================================================
   Hill Dash — styles
   ============================================================ */
:root {
  --ink: #0d1420;
  --ink-2: #16202e;
  --panel: rgba(22, 32, 46, 0.94);
  --line: rgba(255, 255, 255, 0.1);
  --text: #f2f6fb;
  --muted: #93a3b8;
  --orange: #ff8b3d;
  --orange-2: #ff6b1a;
  --green: #46d17a;
  --gold: #ffcf4d;
  --red: #ff5252;
  --radius: 18px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--text);
  font-family: var(--font);
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

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

.hidden {
  display: none !important;
}

/* ============================================================
   HUD
   ============================================================ */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.hud-top {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0 14px;
  gap: 10px;
}

.hud-left,
.hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: 999px;
  background: rgba(13, 20, 32, 0.66);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.3px;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

.pill em {
  font-style: normal;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  margin-left: -3px;
}

.distance-pill #distValue {
  min-width: 20px;
  text-align: right;
}

.coin-pill {
  color: var(--gold);
}

.coin-pill span {
  color: var(--text);
}

/* fuel */
.fuel-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 13px 7px 15px;
  border-radius: 999px;
  background: rgba(13, 20, 32, 0.66);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

.fuel-track {
  width: 92px;
  height: 9px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.14);
  overflow: hidden;
}

.fuel-bar {
  height: 100%;
  width: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #46d17a, #9ae66e);
  transition: width 0.18s linear, background 0.3s;
}

.fuel-bar.low {
  background: linear-gradient(90deg, #ff8b3d, #ffcf4d);
}

.fuel-bar.critical {
  background: linear-gradient(90deg, #ff2d2d, #ff7b3d);
  animation: pulse 0.7s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.45;
  }
}

.fuel-icon {
  font-size: 13px;
  line-height: 1;
}

/* bottom hud */
.hud-bottom {
  position: absolute;
  bottom: max(14px, env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 16px;
  gap: 12px;
}

.speedo {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 8px 15px;
  border-radius: 14px;
  background: rgba(13, 20, 32, 0.6);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-variant-numeric: tabular-nums;
  position: relative;
  overflow: hidden;
}

.speedo #speedValue {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.5px;
  min-width: 38px;
  text-align: right;
}

.speedo em {
  font-style: normal;
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.speedo-arc {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: 100%;
  background: rgba(255, 255, 255, 0.12);
}

.speedo-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green), var(--gold), var(--red));
  transition: width 0.1s linear;
}

.pedals {
  display: flex;
  gap: 12px;
  pointer-events: auto;
}

.pedal {
  width: 74px;
  height: 74px;
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(22, 32, 46, 0.72);
  color: var(--text);
  font-size: 26px;
  display: grid;
  place-items: center;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  transition: transform 0.08s, background 0.12s, border-color 0.12s;
  padding: 0;
}

.pedal span {
  line-height: 1;
  transform: translateY(-1px);
}

.pedal.gas {
  background: linear-gradient(180deg, rgba(255, 139, 61, 0.95), rgba(255, 107, 26, 0.95));
  border-color: rgba(255, 200, 150, 0.5);
  color: #241202;
}

.pedal.gas.active {
  transform: scale(0.93);
  box-shadow: 0 0 0 4px rgba(255, 139, 61, 0.35);
}

.pedal.brake.active {
  transform: scale(0.93);
  background: rgba(255, 255, 255, 0.28);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.2);
}

@media (hover: hover) and (pointer: fine) {
  .pedal:hover {
    border-color: rgba(255, 255, 255, 0.35);
  }
  .pedal {
    width: 64px;
    height: 64px;
  }
}

/* toasts */
.toast-layer {
  position: absolute;
  top: 20%;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.5px;
  background: rgba(13, 20, 32, 0.82);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  animation: toastIn 0.35s cubic-bezier(0.2, 1.5, 0.5, 1) both;
  white-space: nowrap;
}

.toast.gold {
  color: var(--gold);
  border-color: rgba(255, 207, 77, 0.4);
}

.toast.green {
  color: var(--green);
  border-color: rgba(70, 209, 122, 0.4);
}

.toast.muted {
  color: var(--muted);
}

.toast.out {
  animation: toastOut 0.45s ease-in forwards;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(-14px) scale(0.9);
  }
}

@keyframes toastOut {
  to {
    opacity: 0;
    transform: translateY(-16px) scale(0.95);
  }
}

/* ============================================================
   Screens & panels
   ============================================================ */
.screen {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(
      circle at 50% 30%,
      rgba(13, 20, 32, 0.35),
      rgba(9, 14, 22, 0.82)
    );
  animation: screenIn 0.25s ease-out both;
  overflow-y: auto;
}

@keyframes screenIn {
  from {
    opacity: 0;
  }
}

.panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 24px;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  animation: panelIn 0.32s cubic-bezier(0.2, 1.3, 0.5, 1) both;
}

@keyframes panelIn {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.97);
  }
}

.panel h2 {
  margin: 0 0 16px;
  font-size: 19px;
  letter-spacing: 3px;
  font-weight: 800;
  text-align: center;
  color: var(--text);
}

.menu-panel {
  text-align: center;
  padding: 32px 26px 26px;
}

.logo h1 {
  margin: 0;
  font-size: clamp(38px, 11vw, 54px);
  line-height: 0.92;
  letter-spacing: -1.5px;
  font-weight: 900;
  text-shadow: 0 6px 0 rgba(0, 0, 0, 0.28);
}

.logo h1 span {
  color: var(--orange);
  display: inline-block;
}

.tagline {
  margin: 10px 0 0;
  font-size: 12.5px;
  color: var(--muted);
  letter-spacing: 0.4px;
  font-weight: 600;
}

.bank {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 18px 0 4px;
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(255, 207, 77, 0.12);
  border: 1px solid rgba(255, 207, 77, 0.32);
  color: var(--gold);
  font-weight: 800;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.bank.small {
  margin: 0;
  font-size: 14px;
  padding: 5px 13px;
}

.btn {
  display: block;
  width: 100%;
  padding: 15px 18px;
  margin-top: 12px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 1.6px;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.13);
  border-color: rgba(255, 255, 255, 0.24);
}

.btn:active {
  transform: scale(0.975);
}

.btn.primary {
  background: linear-gradient(180deg, var(--orange), var(--orange-2));
  border-color: rgba(255, 200, 150, 0.4);
  color: #2a1403;
  box-shadow: 0 8px 22px rgba(255, 107, 26, 0.3);
}

.btn.primary:hover {
  filter: brightness(1.07);
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
}

.btn.danger {
  background: rgba(255, 82, 82, 0.16);
  border-color: rgba(255, 82, 82, 0.4);
  color: #ff9c9c;
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  filter: grayscale(0.5);
}

.row2 {
  display: flex;
  gap: 10px;
}

.row2 .btn {
  flex: 1;
}

.best {
  margin: 16px 0 0;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.5px;
}

.best strong {
  color: var(--text);
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(13, 20, 32, 0.66);
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  display: grid;
  place-items: center;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: background 0.15s;
  padding: 0;
  font-family: var(--font);
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.16);
}

.icon-btn.close {
  font-size: 15px;
  width: 36px;
  height: 36px;
}

/* ============================================================
   Garage
   ============================================================ */
.garage-panel {
  width: min(700px, 100%);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: min(90vh, 720px);
}

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

.panel-head h2 {
  margin: 0;
  flex: 1;
  text-align: left;
  font-size: 17px;
}

.garage-body {
  display: grid;
  grid-template-columns: 190px 1fr;
  gap: 14px;
  min-height: 0;
  flex: 1;
}

.car-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  padding-right: 4px;
  max-height: 46vh;
}

.car-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.05);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  text-align: left;
  color: inherit;
  font-family: var(--font);
  width: 100%;
}

.car-item:hover {
  background: rgba(255, 255, 255, 0.1);
}

.car-item.active {
  border-color: var(--orange);
  background: rgba(255, 139, 61, 0.16);
}

.car-item canvas {
  width: 52px;
  height: 30px;
  flex: none;
}

.car-item .ci-meta {
  min-width: 0;
  flex: 1;
}

.car-item .ci-name {
  font-size: 12.5px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.2px;
}

.car-item .ci-sub {
  font-size: 10.5px;
  color: var(--muted);
  font-weight: 600;
}

.car-item .ci-tag {
  font-size: 9.5px;
  font-weight: 800;
  padding: 3px 7px;
  border-radius: 99px;
  letter-spacing: 0.4px;
  flex: none;
}

.ci-tag.owned {
  background: rgba(70, 209, 122, 0.16);
  color: var(--green);
}

.ci-tag.locked {
  background: rgba(255, 255, 255, 0.1);
  color: var(--muted);
}

.ci-tag.equipped {
  background: rgba(255, 139, 61, 0.2);
  color: var(--orange);
}

.car-detail {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  overflow-y: auto;
  max-height: 46vh;
  padding-right: 4px;
}

.detail-hero {
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  display: flex;
  justify-content: center;
}

.detail-hero canvas {
  width: 200px;
  height: 96px;
}

.detail-name {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.4px;
  margin: 0;
}

.detail-desc {
  font-size: 11.5px;
  color: var(--muted);
  margin: 0;
  line-height: 1.45;
  font-weight: 500;
}

.stat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.stat-row .bars {
  flex: 1;
  display: flex;
  gap: 3px;
}

.stat-row .seg {
  flex: 1;
  height: 7px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.1);
}

.stat-row .seg.on {
  background: linear-gradient(90deg, var(--orange), var(--orange-2));
}

.upgrades {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.upgrade-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
}

.upgrade-row .up-icon {
  font-size: 15px;
  width: 20px;
  text-align: center;
  flex: none;
}

.upgrade-row .up-meta {
  flex: 1;
  min-width: 0;
}

.upgrade-row .up-name {
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.3px;
}

.upgrade-row .up-level {
  display: flex;
  gap: 2px;
  margin-top: 4px;
}

.upgrade-row .up-level i {
  width: 12px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.14);
}

.upgrade-row .up-level i.on {
  background: var(--green);
}

.up-grade-btn {
  padding: 7px 11px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.09);
  color: var(--text);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
  flex: none;
  transition: background 0.15s, opacity 0.15s;
  letter-spacing: 0.2px;
}

.up-grade-btn:hover:not(:disabled) {
  background: rgba(255, 139, 61, 0.28);
  border-color: rgba(255, 139, 61, 0.55);
}

.up-grade-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.up-grade-btn.maxed {
  color: var(--green);
  border-color: rgba(70, 209, 122, 0.35);
  opacity: 1;
}

.panel-foot {
  display: flex;
  gap: 10px;
}

.panel-foot .btn {
  flex: 1;
  margin: 0;
}

/* ============================================================
   Game over
   ============================================================ */
.over-panel {
  text-align: center;
}

.crash-badge {
  font-size: 40px;
  line-height: 1;
  margin-bottom: 6px;
  animation: pop 0.5s cubic-bezier(0.2, 1.8, 0.5, 1) both;
}

@keyframes pop {
  from {
    transform: scale(0.2) rotate(-25deg);
    opacity: 0;
  }
}

.over-panel h2 {
  margin-bottom: 4px;
  color: var(--orange);
}

.over-reason {
  margin: 0 0 18px;
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 600;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.stat {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.stat-k {
  font-size: 9.5px;
  letter-spacing: 1.1px;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 800;
}

.stat-v {
  font-size: 16px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.stat-v b {
  color: var(--orange);
  font-size: 19px;
}

.new-record {
  margin: 0 0 14px;
  color: var(--gold);
  font-weight: 900;
  letter-spacing: 2.5px;
  font-size: 12.5px;
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.45;
  }
}

.small-panel {
  width: min(320px, 100%);
  text-align: center;
}

/* ============================================================
   Help
   ============================================================ */
.help-panel {
  width: min(460px, 100%);
}

.help-list {
  list-style: none;
  margin: 0 0 6px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.help-list li {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
  padding-left: 14px;
  position: relative;
  font-weight: 500;
}

.help-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 7px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--orange);
}

.help-list b {
  color: var(--text);
}

kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-bottom-width: 2px;
  font-family: var(--font);
  font-size: 10.5px;
  font-weight: 800;
  color: var(--text);
  margin: 0 1px;
}

/* rotate hint */
#rotateHint {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: var(--ink-2);
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-align: center;
  padding: 30px;
}

@media (max-width: 620px) {
  .garage-body {
    grid-template-columns: 1fr;
  }
  .car-list {
    flex-direction: row;
    max-height: none;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 6px;
  }
  .car-item {
    flex-direction: column;
    width: 92px;
    flex: none;
    gap: 4px;
    text-align: center;
    align-items: center;
  }
  .car-item .ci-meta {
    text-align: center;
  }
  .car-item .ci-tag {
    display: none;
  }
  .car-detail {
    max-height: 40vh;
  }
  .detail-hero canvas {
    width: 160px;
    height: 78px;
  }
  .panel {
    padding: 20px 18px;
  }
}

@media (orientation: landscape) and (max-height: 460px) {
  .menu-panel {
    padding: 16px 20px;
  }
  .logo h1 {
    font-size: 30px;
  }
  .tagline,
  .best {
    display: none;
  }
  .bank {
    margin: 10px 0 2px;
  }
  .btn {
    padding: 10px 16px;
    margin-top: 8px;
  }
  .hud-bottom {
    bottom: 8px;
  }
  .pedal {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    font-size: 20px;
  }
  .garage-panel {
    padding: 14px;
    max-height: 94vh;
  }
  .car-list {
    max-height: 30vh;
  }
  .car-detail {
    max-height: 30vh;
  }
}
