* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #9cc7ef;
  font-family: "Avenir Next", "Trebuchet MS", system-ui, sans-serif;
  color: #fff;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* the world takes every finger itself: no scrolling, no zooming */
canvas { display: block; position: fixed; inset: 0; touch-action: none; }

button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }

.hidden { display: none !important; }

/* ---------- while you drive ---------- */

#hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
#hud button { pointer-events: auto; }

#info {
  position: absolute;
  /* the arcade's back button sits in the top left corner */
  top: max(56px, calc(env(safe-area-inset-top) + 48px));
  left: max(14px, env(safe-area-inset-left));
  min-width: 170px;
  padding: 8px 14px 10px;
  border-radius: 14px;
  background: rgba(12, 18, 32, 0.62);
  backdrop-filter: blur(4px);
}

#modeLabel { font-size: 11px; letter-spacing: 2.5px; font-weight: 700; opacity: 0.9; }
#big { font-size: 32px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
#sub { font-size: 12px; letter-spacing: 1px; opacity: 0.95; max-width: 220px; }

#health, #meter {
  position: relative;
  height: 14px;
  margin-top: 7px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.18);
  overflow: hidden;
}
#healthFill, #meterFill { position: absolute; inset: 0 auto 0 0; width: 100%; background: #3fd46b; transition: background 0.3s; }
#meterFill { background: #ff3b4a; width: 0; }
#health span, #meter span {
  position: relative;
  display: block;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 2px;
  line-height: 14px;
  text-align: center;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

#topMid {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
}

#topMid button, #topRight button {
  padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  background: rgba(12, 18, 32, 0.6);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1.5px;
  white-space: nowrap;
}

#topRight {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 30;
}

#toast {
  position: absolute;
  top: 24%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: clamp(22px, 5vw, 38px);
  font-weight: 800;
  letter-spacing: 2px;
  text-shadow: 0 2px 10px rgba(0, 10, 30, 0.8);
  opacity: 0;
  transition: opacity 0.25s;
  padding: 0 16px;
}
#toast.on { opacity: 1; }

#countdown {
  position: absolute;
  top: 12%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: clamp(70px, 18vw, 140px);
  font-weight: 900;
  color: #ffd94a;
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
}

/* ---------- the buttons you drive with ---------- */

.hold, #gears button, #doorBtn {
  border: 2px solid rgba(255, 255, 255, 0.55);
  background: rgba(12, 18, 32, 0.45);
  font-weight: 800;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}
.hold.down { background: rgba(255, 217, 74, 0.75); color: #2a1e00; }

#steer {
  position: absolute;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(22px, env(safe-area-inset-bottom));
  display: flex;
  gap: 14px;
}
#steer button { width: 92px; height: 92px; border-radius: 22px; font-size: 38px; }

#pedals {
  position: absolute;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(22px, env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  gap: 14px;
}
#brakeBtn { width: 86px; height: 86px; border-radius: 50%; font-size: 13px; letter-spacing: 1px; line-height: 1.2; }
#gasBtn { width: 92px; height: 140px; border-radius: 18px; font-size: 20px; letter-spacing: 2px; }

#gears {
  position: absolute;
  right: max(18px, env(safe-area-inset-right));
  top: 50%;
  transform: translateY(-62%);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#gears button { width: 52px; height: 40px; border-radius: 10px; font-size: 18px; }
#gears button.on { background: #ffd94a; color: #2a1e00; border-color: #ffd94a; }
#gears button[data-gear="0"].on { background: #ff5a5a; border-color: #ff5a5a; color: #fff; }

#updown {
  position: absolute;
  right: max(18px, env(safe-area-inset-right));
  top: 50%;
  transform: translateY(-62%);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#updown button { width: 72px; height: 72px; border-radius: 18px; font-size: 30px; }

#speedo {
  position: absolute;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 6px 16px;
  border-radius: 14px;
  background: rgba(12, 18, 32, 0.55);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2px;
  text-align: center;
  white-space: nowrap;
}
#mph { font-size: 30px; font-variant-numeric: tabular-nums; }
#gearShow {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 9px;
  border-radius: 8px;
  background: #ffd94a;
  color: #2a1e00;
  font-size: 18px;
}
#shift { font-size: 11px; color: #ffd94a; height: 14px; visibility: hidden; }
#shift.on { visibility: visible; animation: blink 0.5s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

#doorBtn {
  position: absolute;
  left: 50%;
  bottom: calc(max(22px, env(safe-area-inset-bottom)) + 84px);
  transform: translateX(-50%);
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 15px;
  letter-spacing: 2px;
  background: rgba(40, 120, 255, 0.75);
}

/* ---------- the title, and the phone ---------- */

#title {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 0;
  right: 0;
  z-index: 10;
  text-align: center;
  pointer-events: none;
  text-shadow: 0 3px 14px rgba(0, 10, 40, 0.65);
}
#title h1 { margin: 0; font-size: clamp(30px, 7vw, 58px); letter-spacing: 5px; font-weight: 900; }
#title .tag { margin: 2px 0 0; font-size: 15px; }
#title b, .tag b { color: #ffd94a; }

#phone {
  position: fixed;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 20;
  width: min(330px, calc(100vw - 32px));
  height: min(560px, calc(100vh - 120px));
  display: flex;
  flex-direction: column;
  padding: 10px 12px 8px;
  border: 5px solid #1b1d22;
  border-radius: 38px;
  background: linear-gradient(160deg, #2c3c74, #18213f 60%, #10162c);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55), inset 0 0 0 2px #3a3e48;
}
#phone.closed { display: none; }

#phoneTop {
  display: flex;
  justify-content: space-between;
  padding: 2px 14px 8px;
  font-size: 13px;
  font-weight: 700;
}

#phoneScreen { flex: 1; overflow-y: auto; padding: 4px 4px 8px; -webkit-overflow-scrolling: touch; }

#phoneHome {
  align-self: center;
  width: 100%;
  height: 22px;
  border: 0;
  background: none;
  display: grid;
  place-items: center;
}
#phoneHome span { display: block; width: 120px; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.75); }

.where { text-align: center; font-size: 13px; letter-spacing: 1px; margin-bottom: 10px; opacity: 0.95; }
.where b { color: #ffd94a; }

.apps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 6px; }
.app { border: 0; background: none; padding: 0; display: flex; flex-direction: column; align-items: center; gap: 5px; font-size: 11px; font-weight: 700; letter-spacing: 0.5px; }
.app .ico {
  width: 62px;
  height: 62px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-size: 32px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
}
.app:active .ico { transform: scale(0.92); }

.screenHead { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.screenHead h2 { margin: 0; font-size: 20px; letter-spacing: 2px; }
.backBtn { border: 0; background: rgba(255, 255, 255, 0.14); border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 700; }

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  margin-bottom: 8px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.09);
}
.row .icon { font-size: 28px; width: 36px; text-align: center; }
.row .words { flex: 1; min-width: 0; }
.row .name { font-weight: 800; font-size: 15px; }
.row .what { font-size: 11px; opacity: 0.85; }
.row button, .chip, .goBtn {
  border: 0;
  border-radius: 999px;
  padding: 7px 12px;
  background: #ffd94a;
  color: #2a1e00;
  font-weight: 800;
  font-size: 13px;
  white-space: nowrap;
}
.row button:disabled { opacity: 0.4; }
.row button.plain { background: rgba(255, 255, 255, 0.18); color: #fff; }

.typeRow { display: flex; gap: 8px; margin-bottom: 12px; }
.typeRow input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-size: 16px;
  color: #111;
  -webkit-user-select: text;
  user-select: text;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: rgba(255, 255, 255, 0.16); color: #fff; }
.note { font-size: 12px; opacity: 0.85; margin: 10px 2px; line-height: 1.4; }
.money { color: #7dff9a; font-weight: 800; }

/* ---------- cards ---------- */

.card {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 25;
  width: min(420px, calc(100vw - 32px));
  padding: 22px 22px 24px;
  border-radius: 24px;
  background: rgba(14, 20, 38, 0.88);
  backdrop-filter: blur(6px);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.card h1 { margin: 0 0 6px; font-size: clamp(28px, 7vw, 42px); letter-spacing: 3px; }
.card .tag { margin: 0 0 16px; font-size: 16px; }
#endMedal, #brokeIcon { font-size: 64px; line-height: 1.1; }

.buttons { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.big {
  border: 0;
  border-radius: 16px;
  padding: 12px 22px;
  background: #ffd94a;
  color: #2a1e00;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 2px;
  box-shadow: 0 5px 0 #c79a00;
}
.big:active { transform: translateY(3px); box-shadow: 0 2px 0 #c79a00; }
.big.plain { background: rgba(255, 255, 255, 0.16); color: #fff; box-shadow: 0 5px 0 rgba(0, 0, 0, 0.35); }

#confetti { pointer-events: none; z-index: 40; }

/* small screens: smaller driving buttons */
@media (max-height: 520px) {
  #steer button { width: 74px; height: 74px; font-size: 30px; }
  #gasBtn { width: 78px; height: 112px; }
  #brakeBtn { width: 72px; height: 72px; font-size: 11px; }
  #gears button { height: 32px; width: 46px; font-size: 15px; }
  #doorBtn { bottom: calc(max(22px, env(safe-area-inset-bottom)) + 70px); }
}
