:root {
  --asphalt: #12151a;
  --slate: #2b333c;
  --cream: #efe4cd;
  --yellow: #e0a92a;
  --green: #1e3a34;
  --red: #c2452c;
  --steel: #8f98a3;
  --ink: #141518;
  --display: "Big Shoulders Stencil", "Arial Narrow", sans-serif;
  --body: "Archivo", system-ui, sans-serif;
  --mono: "Martian Mono", "Courier New", monospace;
  --rain: 1;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #08090b; color: var(--cream);
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
}
#app { position: fixed; inset: 0; }
#stage { position: absolute; inset: 0; }
#stage canvas { display: block; }
.screen { position: absolute; inset: 0; }
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
.note { appearance: none; -webkit-appearance: none; font-family: var(--body); }

/* ---------------- title ---------------- */
#title { overflow: hidden; background: #08090b; }
.title-bg {
  position: absolute; inset: -6%;
  background: url("../assets/title_tall.webp") center 42% / cover no-repeat;
  filter: brightness(.72) saturate(.9) contrast(1.02);
  animation: drift 34s ease-in-out infinite alternate;
}
@media (min-aspect-ratio: 1/1) {
  .title-bg {
    background-image: url("../assets/title_wide.webp");
    background-position: 58% 58%;
    background-size: cover;
  }
}
@keyframes drift { from { transform: scale(1.03) translate(0,0); } to { transform: scale(1.11) translate(-1.4%, -1%); } }
.title-stripe { display: none; }
.title-rain {
  position: absolute; inset: -20%;
  background:
    repeating-linear-gradient(103deg, rgba(220,232,240,.11) 0 1px, transparent 1px 34px),
    repeating-linear-gradient(103deg, rgba(220,232,240,.055) 0 1px, transparent 1px 17px);
  background-size: 220px 220px, 130px 130px;
  animation: rain 1.1s linear infinite;
  opacity: .55;
  pointer-events: none;
}
@keyframes rain { from { transform: translate(0, -140px); } to { transform: translate(-26px, 0); } }
.title-shade {
  position: absolute; inset: 0;
  background:
    radial-gradient(130% 100% at 50% 30%, transparent 42%, rgba(4,6,8,.55) 92%),
    linear-gradient(180deg, rgba(4,6,8,.6), transparent 22%, rgba(4,6,8,.72) 62%, #07080a 100%);
}
.title-content {
  position: absolute; left: 50%; bottom: clamp(20px, 5vh, 62px); transform: translateX(-50%);
  width: min(880px, 88vw); display: flex; flex-direction: column; align-items: center; gap: clamp(8px, 1.6vh, 18px);
  text-align: center;
}
.title-type {
  width: min(620px, 76vw); height: auto;
  filter: drop-shadow(0 22px 34px rgba(0,0,0,.65));
  margin-bottom: clamp(2px, .6vh, 8px);
}
.title-line {
  margin: 0; font-weight: 600; font-size: clamp(13px, 1.5vw, 20px); line-height: 1.4;
  color: var(--yellow); max-width: 40ch; letter-spacing: .01em;
}
.title-foot {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: clamp(6px, 1.6vh, 18px);
  font-family: var(--mono); font-size: clamp(8px, .8vw, 11px); letter-spacing: .18em;
  color: rgba(239,228,205,.42); white-space: normal; width: max-content;
  max-width: 92vw; text-align: center; line-height: 1.5;
}
.hint { margin: 0; font-size: clamp(10px, 1vw, 12px); letter-spacing: .08em; color: rgba(239,228,205,.6); }

/* ---------------- shared plate button ---------------- */
.plate-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 12px;
  padding: clamp(10px, 1.5vh, 16px) clamp(18px, 2.4vw, 32px);
  background: #191c1f; color: var(--cream);
  border: 2px solid rgba(239,228,205,.28);
  border-radius: 0;
  font-family: var(--display); font-weight: 700;
  font-size: clamp(16px, 1.8vw, 24px); letter-spacing: .16em; text-transform: uppercase;
  box-shadow: 0 10px 0 -2px rgba(0,0,0,.55), inset 0 0 0 1px rgba(0,0,0,.6);
  transition: transform .09s ease, background .15s ease, color .15s ease;
  position: relative;
}
.plate-btn::after {
  content: ""; position: absolute; inset: 6px; border: 1px solid rgba(239,228,205,.12); pointer-events: none;
}
.plate-btn:hover { background: var(--yellow); color: #17181a; border-color: rgba(0,0,0,.5); }
.plate-btn:active { transform: translateY(2px); background: var(--yellow); color: #17181a; }
.plate-btn.big { padding-inline: clamp(22px, 3vw, 42px); }
.plate-btn.ghost { background: transparent; }
.plate-btn.small { font-size: clamp(10px, 1vw, 13px); padding: 8px 12px; letter-spacing: .14em; }
.plate-btn:disabled { opacity: .38; cursor: not-allowed; }
.btn-icon {
  width: clamp(26px, 3vw, 38px); height: clamp(22px, 2.6vw, 32px);
  background: center / contain no-repeat; display: inline-block;
}

/* ---------------- pit wall ---------------- */
#pit { overflow: hidden; background: #0a0b0d; }
.pit-bg {
  position: absolute; inset: 0;
  background: url("../assets/pit_wall_board.webp") center / cover no-repeat;
  filter: brightness(.92) saturate(.9);
}
.pit-bg::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(6,8,9,.55), rgba(6,8,9,.1) 22%, rgba(6,8,9,.2) 70%, rgba(6,8,9,.8));
}
.pit-wrap {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  padding: calc(clamp(10px, 2vw, 30px) + env(safe-area-inset-top, 0px)) calc(clamp(10px, 2vw, 30px) + env(safe-area-inset-right, 0px)) calc(clamp(10px, 2vw, 30px) + env(safe-area-inset-bottom, 0px)) calc(clamp(10px, 2vw, 30px) + env(safe-area-inset-left, 0px)); gap: clamp(8px, 1.4vh, 16px);
  overflow: hidden;
}
.pit-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; flex: 0 0 auto; }
.team { display: flex; gap: clamp(8px, 1vw, 14px); align-items: center; }
.team-mark {
  font-family: var(--display); font-weight: 800; font-size: clamp(30px, 4.4vw, 58px); line-height: .9;
  color: var(--yellow); border: 3px solid rgba(224,169,42,.55); padding: 3px clamp(6px, .8vw, 12px);
  background: rgba(12,14,16,.55); text-shadow: 0 2px 0 rgba(0,0,0,.6);
}
.team h1 {
  margin: 0; font-family: var(--display); font-weight: 800; text-transform: uppercase;
  font-size: clamp(18px, 2.2vw, 30px); letter-spacing: .12em; color: var(--cream);
  text-shadow: 0 2px 8px rgba(0,0,0,.8);
}
.team p { margin: 2px 0 0; font-size: clamp(10px, .95vw, 13px); color: rgba(239,228,205,.82); }

.money-plate { width: clamp(150px, 17vw, 232px); flex: 0 0 auto; }
.plate { position: relative; }
.plate > img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill;
  filter: brightness(.55) saturate(.6) contrast(1.05);
}
.plate-face {
  position: relative; inset: 0; padding: 12% 8%;
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
}
.plate-face .k {
  font-family: var(--display); font-weight: 700; font-size: clamp(8px, .8vw, 11px);
  letter-spacing: .22em; color: rgba(239,228,205,.6);
}
.plate-face .v {
  font-family: var(--mono); font-weight: 600; font-size: clamp(13px, 1.35vw, 20px);
  color: var(--cream); line-height: 1.2; letter-spacing: -.02em;
}
.money-plate { aspect-ratio: 382 / 265; }
.money-plate .veil { position: absolute; inset: 13% 9%; background: linear-gradient(150deg, rgba(14,16,18,.93), rgba(8,10,12,.97)); }
.money-plate .plate-face { position: absolute; inset: 13% 9%; }
.money-plate::after {
  content: ""; position: absolute; inset: 0; border: 1px solid rgba(0,0,0,.45);
  box-shadow: 0 12px 26px rgba(0,0,0,.5); pointer-events: none;
}

.pit-grid {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden;
  display: grid; grid-template-columns: .86fr 1.6fr .86fr; gap: clamp(10px, 1.6vw, 24px);
  align-items: start; align-content: start; padding-right: 4px;
  scrollbar-width: thin;
}
.board-panel {
  position: relative; padding: clamp(8px, 1.1vw, 16px);
  background: linear-gradient(180deg, rgba(9,11,13,.72), rgba(9,11,13,.55));
  border: 1px solid rgba(239,228,205,.13);
  box-shadow: 0 16px 40px rgba(0,0,0,.35);
}
.board-panel h2 {
  margin: 0 0 10px; font-family: var(--display); font-weight: 800; text-transform: uppercase;
  font-size: clamp(15px, 1.5vw, 21px); letter-spacing: .2em; color: var(--yellow);
  display: flex; align-items: baseline; gap: 10px;
}
.board-panel h2 span {
  font-family: var(--body); font-weight: 500; font-size: clamp(9px, .72vw, 11px);
  letter-spacing: .06em; color: rgba(239,228,205,.5); text-transform: none;
}

/* season notes */
.pit-notice {
  display: none; margin: 0 0 10px; padding: 7px 10px;
  background: rgba(224,169,42,.14); border-left: 3px solid var(--yellow);
  font-family: var(--display); font-weight: 700; font-size: clamp(10px, 1vw, 13px);
  letter-spacing: .12em; text-transform: uppercase; color: var(--yellow);
}
.pit-notice.on { display: block; }
.race-notes { display: flex; flex-direction: column; gap: 10px; }
.note {
  position: relative; background: var(--cream); color: #23211c;
  padding: 10px 12px 11px; box-shadow: 0 6px 14px rgba(0,0,0,.35);
  transform: rotate(-.7deg);
}
.note:nth-child(2n) { transform: rotate(.6deg); }
.note::before {
  content: ""; position: absolute; left: 50%; top: -7px; width: 56px; height: 15px;
  transform: translateX(-50%) rotate(-2deg); background: rgba(226,220,199,.5);
  box-shadow: 0 1px 2px rgba(0,0,0,.15);
}
.note .row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.note .name { font-family: var(--display); font-weight: 800; font-size: clamp(12px, 1.1vw, 16px); letter-spacing: .1em; text-transform: uppercase; }
.note .res { font-family: var(--mono); font-size: clamp(10px, .9vw, 13px); font-weight: 700; }
.note .sub { margin-top: 3px; font-size: clamp(9px, .8vw, 11px); letter-spacing: .04em; color: #5b574b; }
.note.done { opacity: .92; }
.note.done .name { text-decoration: line-through; text-decoration-thickness: 2px; text-decoration-color: rgba(194,69,44,.85); }
.note.next { outline: 2px solid rgba(224,169,42,.75); outline-offset: 2px; }
.note.locked { background: #cfc6ae; color: #3c3931; opacity: .9; }
.note.locked .name { color: #4d4a41; }
.note .flag { width: 10px; height: 10px; display: inline-block; background: var(--red); }

.ledger { margin-top: 14px; }
.ledger h3 {
  margin: 0 0 6px; font-family: var(--display); font-weight: 700; font-size: 11px;
  letter-spacing: .24em; color: rgba(239,228,205,.75);
}
.ledger-lines { display: flex; flex-direction: column; gap: 3px; }
.ledger-line {
  display: flex; justify-content: space-between; gap: 10px; padding: 3px 6px;
  font-family: var(--mono); font-size: clamp(9px, .78vw, 11px);
  background: rgba(239,228,205,.06); border-left: 2px solid rgba(239,228,205,.14);
}
.ledger-line .amt.minus { color: #e2a08e; }
.ledger-line .amt.plus { color: #b8d6a4; }
.ledger-empty { font-size: 11px; color: rgba(239,228,205,.72); letter-spacing: .04em; }
.record { margin-top: 12px; }
.record h3 {
  margin: 0 0 6px; font-family: var(--display); font-weight: 700; font-size: 11px;
  letter-spacing: .24em; color: rgba(239,228,205,.75);
}
.record-lines { display: flex; flex-direction: column; gap: 3px; }
.record-line {
  display: flex; align-items: baseline; gap: 8px; padding: 4px 6px;
  font-family: var(--mono); font-size: clamp(9px, .78vw, 11px);
  background: rgba(239,228,205,.05); border-left: 2px solid rgba(224,169,42,.4);
}
.record-line .rank { color: var(--yellow); width: 1.6em; }
.record-line a, .record-line span.name { color: var(--cream); text-decoration: none; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.record-line a:hover { color: var(--yellow); }
.record-line .time { color: rgba(239,228,205,.75); }
.record-line.mine { background: rgba(224,169,42,.14); }

/* garage */
.upgrade-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(7px, .8vw, 12px);
}
.up {
  position: relative; background: var(--cream); color: #201f1a;
  padding: 8px 10px 9px; display: flex; gap: 9px; align-items: flex-start;
  box-shadow: 0 6px 12px rgba(0,0,0,.32);
  transform: rotate(-.35deg);
}
.up:nth-child(3n) { transform: rotate(.4deg); }
.up::before {
  content: ""; position: absolute; left: 8px; right: 8px; top: 0; height: 1px;
  background: rgba(0,0,0,.12);
}
.up-icon { width: clamp(34px, 3.2vw, 48px); flex: 0 0 auto; mix-blend-mode: multiply; }
.up-main { flex: 1; min-width: 0; }
.up-name {
  font-family: var(--display); font-weight: 800; font-size: clamp(11px, 1vw, 14px);
  letter-spacing: .1em; text-transform: uppercase; line-height: 1.1;
}
.up-pips { display: flex; gap: 3px; margin: 4px 0 3px; }
.pip { width: 14px; height: 5px; background: rgba(32,31,26,.22); }
.pip.on { background: var(--green); }
.up-price { font-family: var(--mono); font-size: clamp(9px, .8vw, 11px); font-weight: 700; }
.up-price.maxed { color: #4f6b46; }
.up-buy {
  margin-top: 5px; padding: 4px 8px; width: 100%;
  font-family: var(--display); font-weight: 700; font-size: clamp(10px, .85vw, 12px);
  letter-spacing: .18em; text-transform: uppercase;
  background: #22201b; color: var(--cream); border: 0;
  box-shadow: 0 3px 0 rgba(0,0,0,.35);
}
.up-buy:hover:not(:disabled) { background: var(--yellow); color: #191a1c; }
.up { cursor: pointer; }
.up:active { filter: brightness(1.12); transform: rotate(0deg) scale(.985); }
.note:active { filter: brightness(1.1); }
.up-buy:disabled { background: rgba(32,31,26,.14); color: rgba(32,31,26,.45); box-shadow: none; cursor: not-allowed; }
.up-buy.affordable { background: var(--green); }
.up-buy.affordable:hover { background: var(--yellow); color: #191a1c; }

/* target + trophy */
.target h2 { margin-bottom: 30px; }
.target-photo {
  margin-top: 6px;
  position: relative; background: #0d0f11; padding: 6px 6px 26px;
  box-shadow: 0 10px 22px rgba(0,0,0,.5); transform: rotate(1.2deg);
  border: 1px solid rgba(239,228,205,.18);
}
.target-photo img { display: block; width: 100%; height: auto; filter: saturate(.7) brightness(.95); }
.target-photo .circle {
  position: absolute; left: 14%; right: 16%; top: 16%; bottom: 22%;
  border: 3px solid rgba(194,69,44,.85); border-radius: 50%;
  transform: rotate(-6deg); filter: blur(.3px);
}
.target-photo::after {
  content: ""; position: absolute; left: 50%; top: -8px; width: 44px; height: 16px;
  transform: translateX(-50%) rotate(-3deg); background: rgba(226,220,199,.42);
}
.target-note {
  margin: 10px 0 0; font-size: clamp(10px, .85vw, 12px); line-height: 1.45;
  color: rgba(239,228,205,.72);
}
.trophy-slot { margin-top: 12px; display: flex; justify-content: center; }
.trophy-slot img { width: min(150px, 60%); filter: drop-shadow(0 10px 18px rgba(0,0,0,.6)); }
.trophy-line { font-family: var(--display); font-size: 11px; letter-spacing: .2em; color: var(--yellow); text-align: center; }

.pit-foot {
  flex: 0 0 auto; display: flex; align-items: center; gap: clamp(10px, 2vw, 26px);
  padding-top: 4px; flex-wrap: wrap;
}
.next-race { display: flex; flex-direction: column; gap: 3px; }
.next-race .k { font-family: var(--display); font-size: 10px; letter-spacing: .24em; color: rgba(239,228,205,.55); }
.next-race .v {
  font-family: var(--display); font-weight: 800; font-size: clamp(15px, 1.6vw, 22px);
  letter-spacing: .1em; color: var(--cream);
}
.pit-foot .hint { margin-left: auto; }

/* ---------------- HUD ---------------- */
#raceUI { pointer-events: none; }
.race-rain {
  position: absolute; inset: -20%;
  background:
    repeating-linear-gradient(103deg, rgba(226,236,244,.10) 0 1px, transparent 1px 40px),
    repeating-linear-gradient(103deg, rgba(226,236,244,.05) 0 1px, transparent 1px 19px);
  background-size: 260px 260px, 150px 150px;
  animation: rain 1.15s linear infinite;
  pointer-events: none;
  opacity: calc(.2 * var(--rain, 1));
}
.race-light {
  position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(120% 85% at 50% 28%, rgba(224,169,42,.06), transparent 58%),
    radial-gradient(130% 100% at 50% 55%, transparent 58%, rgba(3,4,6,.42) 100%);
}
.hud { position: absolute; inset: 0; }
.plate { position: relative; }
.plate > img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill;
  filter: brightness(.5) saturate(.55) contrast(1.12);
}
.hud .veil {
  position: absolute; inset: 13% 9%;
  background: linear-gradient(155deg, rgba(14,16,18,.96), rgba(8,10,12,.985));
  box-shadow: inset 0 0 24px rgba(0,0,0,.7);
}
.plate-face { position: absolute; inset: 13% 9%; display: flex; flex-direction: column; justify-content: center; }

/* painted steel plates */
.plate-metal {
  position: relative;
  aspect-ratio: 1 / 1;
  filter: drop-shadow(0 14px 22px rgba(0,0,0,.55));
}
.plate-metal::after {
  content: ""; position: absolute; inset: 0; z-index: 3; pointer-events: none;
  border: 1px solid rgba(0,0,0,.55);
  box-shadow: inset 0 0 0 2px rgba(0,0,0,.22), inset 0 0 26px rgba(0,0,0,.24);
}
.plate-surface {
  position: absolute; inset: 0; background-size: cover; background-position: center;
}
.plate-surface.cream {
  background-image: url("../assets/hud_plate_cream.webp");
  filter: brightness(.97) contrast(1.05) saturate(.86);
}
.plate-surface.steel {
  background-image: url("../assets/hud_plate_steel.webp");
  filter: brightness(.72) contrast(1.1) saturate(.55);
}
.hud-face { position: absolute; inset: 0; z-index: 2; display: flex; flex-direction: column; }

.hud-pos {
  position: absolute; top: calc(clamp(10px, 1.6vw, 26px) + env(safe-area-inset-top, 0px));
  left: calc(clamp(10px, 1.6vw, 26px) + env(safe-area-inset-left, 0px));
  width: clamp(136px, 13.5vw, 208px);
}
.hud-gap {
  position: absolute; top: calc(clamp(10px, 1.6vw, 26px) + env(safe-area-inset-top, 0px));
  right: calc(clamp(10px, 1.6vw, 26px) + env(safe-area-inset-right, 0px));
  width: clamp(150px, 15vw, 226px);
}

.pos-face { justify-content: space-between; padding: 28% 12% 12% 17%; }
.pos-face .stat { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.pos-face .stat.pos { flex-direction: column; gap: 1px; }
.pos-face .k {
  font-family: var(--display); font-weight: 800; font-size: clamp(8px, .78vw, 12px);
  letter-spacing: .22em; color: #1b1a15; opacity: 1; padding-top: 2px;
  text-shadow: 0 0 3px rgba(250,243,226,.95), 0 0 1px rgba(250,243,226,.9);
}
.pos-face .stat.pos .v {
  font-family: var(--display); font-weight: 800; font-size: clamp(32px, 3.9vw, 62px);
  line-height: .82; letter-spacing: .01em; color: #191813;
  text-shadow: 0 1px 0 rgba(255,252,238,.35);
}
.pos-face .stat.lap {
  align-items: baseline; margin-top: 2px; padding-top: 6px;
  border-top: 2px solid rgba(38,36,29,.32);
}
.pos-face .stat.lap .v {
  font-family: var(--mono); font-weight: 700; font-size: clamp(15px, 1.55vw, 25px);
  color: #1c1b16; letter-spacing: -.04em;
}

.gap-face { justify-content: center; gap: 6%; padding: 12.5% 9.5%; }
.gap-face .stat { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.gap-face .k {
  font-family: var(--display); font-weight: 700; font-size: clamp(8px, .82vw, 13px);
  letter-spacing: .2em; color: rgba(239,228,205,.6);
}
.gap-face .stat .v {
  font-family: var(--mono); font-weight: 600; font-size: clamp(13px, 1.3vw, 23px);
  color: var(--cream); letter-spacing: -.05em; line-height: 1.15;
}
.gap-face .stat .v.yellow { color: var(--yellow); text-shadow: 0 0 10px rgba(224,169,42,.25); }
.gap-rule { height: 1px; background: rgba(239,228,205,.22); }
.gap-caption {
  font-family: var(--display); font-size: clamp(6px, .54vw, 8px);
  letter-spacing: .2em; color: rgba(239,228,205,.38); text-align: right;
}

.hud-dial-wrap {
  position: absolute; left: calc(clamp(10px, 1.6vw, 26px) + env(safe-area-inset-left, 0px));
  bottom: calc(clamp(10px, 1.6vw, 26px) + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: flex-end; gap: clamp(6px, .8vw, 12px);
}
.dial {
  position: relative; width: clamp(118px, 13vw, 182px); aspect-ratio: 1;
  border-radius: 50%;
  box-shadow: 0 14px 24px rgba(0,0,0,.55), 0 0 0 2px rgba(0,0,0,.45);
}
.dial > img {
  position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 50%;
  object-fit: cover; filter: brightness(.96) contrast(1.05) saturate(.9);
}
.needle {
  position: absolute; left: 50%; top: 50%; width: clamp(3px, .3vw, 5px); height: 35%;
  background: linear-gradient(180deg, #c2452c, #6d1d12);
  transform-origin: 50% 100%; transform: translate(-50%, -100%) rotate(-120deg);
  box-shadow: 0 0 5px rgba(0,0,0,.6);
}
.dial::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 8%; height: 8%;
  transform: translate(-50%, -50%); background: #1d1c17; border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(239,228,205,.55), 0 0 0 4px rgba(0,0,0,.45);
}
.dial-read {
  position: absolute; left: 50%; bottom: 20%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; line-height: 1;
}
.dial-read span {
  font-family: var(--mono); font-weight: 700; font-size: clamp(20px, 2.4vw, 34px);
  color: #1b1a15; text-shadow: 0 1px 0 rgba(255,252,238,.32);
}
.dial-read small {
  font-family: var(--display); font-size: clamp(6px, .58vw, 9px);
  letter-spacing: .2em; color: #4a463a; margin-top: 3px;
}
.gear { width: clamp(78px, 8.4vw, 118px); }
.gear-face { align-items: center; justify-content: center; }
.gear-face small {
  font-family: var(--display); font-weight: 800; font-size: clamp(7px, .68vw, 10px);
  letter-spacing: .22em; color: #3a362c; margin-bottom: 2px;
}
.gear-face span {
  font-family: var(--display); font-weight: 800; font-size: clamp(36px, 4.2vw, 64px);
  line-height: .8; color: #191813; text-shadow: 0 1px 0 rgba(255,252,238,.35);
}

.hud-status {
  position: absolute; right: calc(clamp(10px, 1.6vw, 26px) + env(safe-area-inset-right, 0px));
  bottom: calc(clamp(10px, 1.6vw, 26px) + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; align-items: flex-end; gap: clamp(6px, .8vw, 12px);
}
.damage-plate {
  position: relative; width: clamp(200px, 23vw, 330px); aspect-ratio: 960 / 240;
  box-shadow: 0 14px 24px rgba(0,0,0,.55);
  border: 1px solid rgba(0,0,0,.5);
}
.damage-plate > img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  filter: brightness(.86) contrast(1.06) saturate(.92);
}
.damage-plate::before {
  content: ""; position: absolute; inset: 0 0 34% 0; z-index: 1; background: linear-gradient(180deg, rgba(14,8,6,.55), rgba(14,8,6,0)); pointer-events: none;
}
.damage-plate::after {
  content: ""; position: absolute; inset: 0; box-shadow: inset 0 0 22px rgba(0,0,0,.4); pointer-events: none;
}
.dmg-face {
  position: absolute; inset: 7% 4% 36%; z-index: 2; padding: 0 2%;
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  background: linear-gradient(180deg, rgba(12,8,6,.66), rgba(12,8,6,.12));
}
.dmg-face .k {
  font-family: var(--display); font-weight: 800; font-size: clamp(9px, .82vw, 13px);
  letter-spacing: .2em; color: rgba(255,244,226,.95); text-shadow: 0 1px 2px rgba(0,0,0,.8);
  background: rgba(12,8,6,.72); padding: 1px 5px; border-left: 2px solid rgba(194,69,44,.8);
}
.dmg-face .v {
  font-family: var(--mono); font-weight: 700; font-size: clamp(12px, 1.1vw, 18px);
  color: #fff2d6; text-shadow: 0 1px 2px rgba(0,0,0,.7);
}
.dmg-track {
  position: absolute; left: 6%; right: 6%; bottom: 14%; height: 18%;
  background: rgba(20,12,10,.9); border: 1px solid rgba(255,238,214,.32);
  box-shadow: inset 0 2px 5px rgba(0,0,0,.7);
}
.dmg-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #7a2a1d, #e0563a 60%, #f2a08a);
  transition: width .25s ease;
}
.cash { width: clamp(112px, 11.6vw, 168px); }
.cash-face { justify-content: center; padding: 12% 8%; gap: 2px; }
.cash-face .k {
  font-family: var(--display); font-weight: 800; font-size: clamp(8px, .74vw, 11px);
  letter-spacing: .22em; color: #3a362c;
}
.cash-face .v {
  font-family: var(--mono); font-weight: 700; font-size: clamp(15px, 1.45vw, 23px);
  color: #1a1914; letter-spacing: -.03em;
}

.race-controls {
  position: absolute; top: 50%; right: clamp(10px, 1.6vw, 26px); transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 8px; pointer-events: auto;
}
.icon-plate {
  position: relative; width: clamp(44px, 3.6vw, 58px); height: clamp(44px, 3.6vw, 58px); padding: 0;
  background:
    linear-gradient(155deg, rgba(30,34,37,.96), rgba(10,12,14,.98));
  border: 1px solid rgba(239,228,205,.2);
  box-shadow: 0 6px 0 rgba(0,0,0,.42), inset 0 0 0 1px rgba(0,0,0,.7);
}
.icon-plate::after {
  content: ""; position: absolute; inset: 4px; border: 1px solid rgba(239,228,205,.09); pointer-events: none;
}
.icon-plate img {
  position: absolute; inset: 17%; width: 66%; height: 66%; object-fit: contain;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.6));
}
.icon-plate:hover { border-color: var(--yellow); }
.icon-plate:hover img { filter: drop-shadow(0 0 8px rgba(224,169,42,.35)); }

.touch { display: none; }
.race-hint {
  position: absolute; left: 50%; bottom: clamp(4px, .8vh, 10px); transform: translateX(-50%);
  font-size: clamp(8px, .7vw, 10px); letter-spacing: .14em; color: rgba(239,228,205,.45);
  white-space: nowrap;
}
.light-bar {
  position: absolute; left: 50%; top: 15%; transform: translateX(-50%);
  display: flex; gap: clamp(6px, .8vw, 12px); padding: 10px 14px;
  background: rgba(8,9,11,.78); border: 1px solid rgba(239,228,205,.18);
  opacity: 0; transition: opacity .2s ease;
}
.light-bar.on { opacity: 1; }
.lamp { width: clamp(14px, 1.6vw, 22px); height: clamp(14px, 1.6vw, 22px); border-radius: 50%; background: #3a1d17; box-shadow: inset 0 0 6px #000; }
.lamp.red { background: #d8382a; box-shadow: 0 0 14px rgba(216,56,42,.75), inset 0 0 6px rgba(0,0,0,.4); }
.lamp.go { background: #8fce6a; box-shadow: 0 0 18px rgba(143,206,106,.8); }
.wrongway { font-family: var(--display); font-weight: 800; font-size: clamp(14px, 1.6vw, 20px); letter-spacing: .2em; color: var(--red); }

/* pause + result */
.modal {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(6,8,9,.72); backdrop-filter: blur(3px); pointer-events: auto;
}
.card {
  background: var(--cream); color: #1c1d1a; padding: clamp(18px, 3vw, 34px);
  min-width: min(360px, 86vw); text-align: center; box-shadow: 0 24px 60px rgba(0,0,0,.6);
  transform: rotate(-.4deg);
}
.card h2 { margin: 0; font-family: var(--display); font-size: clamp(22px, 3vw, 34px); letter-spacing: .16em; }
.card p { margin: 6px 0 18px; font-size: 13px; color: #565245; }
.card-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.card .plate-btn { color: var(--cream); }
.card .plate-btn.ghost { color: #1c1d1a; border-color: rgba(28,29,26,.4); }
.card .plate-btn.ghost:hover { background: #1c1d1a; color: var(--cream); }

.result-screen {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(7,9,11,.5); pointer-events: auto;
}
.result-panel {
  position: relative; width: min(520px, 90vw); background: rgba(12,14,16,.94);
  border: 2px solid rgba(239,228,205,.2); padding: clamp(16px, 3vw, 30px);
  box-shadow: 0 30px 80px rgba(0,0,0,.7);
}
.result-kicker { margin: 0; font-family: var(--display); font-weight: 700; letter-spacing: .24em; color: var(--yellow); font-size: 12px; }
.result-pos { display: flex; align-items: baseline; gap: 10px; margin: 6px 0 14px; }
.result-pos span { font-family: var(--display); font-weight: 800; font-size: clamp(58px, 9vw, 104px); line-height: .85; color: var(--cream); }
.result-pos small { font-family: var(--mono); font-size: 12px; color: rgba(239,228,205,.55); letter-spacing: .12em; }
.result-rows { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 18px; margin-bottom: 14px; }
.result-rows div { display: flex; justify-content: space-between; gap: 10px; padding: 6px 8px; background: rgba(239,228,205,.05); border-left: 2px solid rgba(239,228,205,.16); }
.result-rows span { font-family: var(--display); font-size: 10px; letter-spacing: .18em; color: rgba(239,228,205,.55); align-self: center; }
.result-rows b { font-family: var(--mono); font-size: 13px; color: var(--cream); }
.result-line { margin: 0 0 18px; font-size: 12px; line-height: 1.5; color: rgba(239,228,205,.6); }
.chequer-wash {
  position: absolute; inset: -20% -40%;
  background: repeating-conic-gradient(rgba(239,228,205,.5) 0 25%, rgba(10,12,14,.4) 0 50%) 0 0 / 90px 90px;
  transform: translateX(-120%) skewX(-12deg);
  animation: wash 1.1s cubic-bezier(.5,.05,.3,1) forwards;
  pointer-events: none;
}
@keyframes wash { to { transform: translateX(120%) skewX(-12deg); } }

/* toast */
.toast {
  position: absolute; left: 50%; top: clamp(72px, 12vh, 118px); bottom: auto; transform: translateX(-50%);
  background: var(--cream); color: #1c1d1a; padding: 9px 16px;
  font-family: var(--display); font-weight: 700; letter-spacing: .14em; font-size: 14px;
  box-shadow: 0 12px 30px rgba(0,0,0,.5); z-index: 30;
  animation: toastin .25s ease;
}
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------------- responsive ---------------- */
@media (pointer: coarse), (max-width: 900px) {
  .touch { display: block; }
  .touch-btn {
    position: absolute; bottom: clamp(8px, 2vh, 20px);
    background: rgba(12,14,16,.55); border: 1px solid rgba(239,228,205,.22);
    color: var(--cream); padding: 0; pointer-events: auto; touch-action: none;
    user-select: none; -webkit-user-select: none;
  }
  .touch-btn.steer {
    width: clamp(52px, 12vw, 76px); height: clamp(52px, 12vw, 76px);
    font-family: var(--display); font-size: clamp(26px, 6vw, 38px); line-height: 1;
    color: rgba(239,228,205,.9); border-color: rgba(239,228,205,.38);
  }
  .touch-btn.steer[data-key="left"] { left: clamp(8px, 2vw, 20px); }
  .touch-btn.steer[data-key="right"] { left: calc(clamp(8px, 2vw, 20px) + clamp(58px, 13.4vw, 84px)); }
  .touch-btn.pedal {
    width: clamp(58px, 14vw, 88px); height: clamp(56px, 13vw, 82px);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    background: rgba(14,16,18,.78); border: 1px solid rgba(239,228,205,.38);
  }
  .pedal-mark { width: 44%; height: 3px; background: var(--cream); opacity: .5; }
  .touch-btn.pedal.go .pedal-mark { background: var(--yellow); opacity: .9; }
  .pedal-label {
    font-family: var(--display); font-weight: 800; font-size: clamp(11px, 2.6vw, 16px);
    letter-spacing: .12em; color: var(--cream); line-height: 1;
  }
  .touch-btn.active { background: rgba(224,169,42,.72) !important; border-color: var(--yellow); box-shadow: 0 0 12px rgba(224,169,42,.35); }
  .touch-btn.active .pedal-label, .touch-btn.active span { color: #141517; }
  .touch-btn.active .pedal-label { color: #17181a; }
  .touch-btn.pedal[data-key="brake"] { right: calc(clamp(8px, 2vw, 20px) + clamp(60px, 14.4vw, 90px)); }
  .touch-btn.pedal[data-key="throttle"] { right: clamp(8px, 2vw, 20px); }
  .touch-btn.active { background: rgba(224,169,42,.55); border-color: var(--yellow); }
  .hud-dial-wrap { bottom: calc(clamp(6px, 1.4vw, 20px) + 82px); }
  .hud-status { bottom: calc(clamp(6px, 1.4vw, 20px) + 82px); }
  .race-hint { display: none; }
  .race-controls {
    top: calc(clamp(6px, 1.4vw, 20px) + env(safe-area-inset-top, 0px)); bottom: auto;
    left: 50%; right: auto; transform: translateX(-50%);
    flex-direction: row; gap: 6px;
  }
  .pit-grid { grid-template-columns: 1fr 1.55fr; }
  .target { display: none; }
  .pit-foot .hint { display: none; }
}
@media (max-width: 700px) {
  .hud-pos { width: 118px; }
  .hud-gap { width: 132px; }
  .hud-pos { top: calc(8px + env(safe-area-inset-top, 0px)); left: 8px; }
  .hud-gap { top: calc(8px + env(safe-area-inset-top, 0px)); right: 8px; }
  .pos-face { padding: 28% 11% 11% 17%; }
  .pos-face .stat.pos .v { font-size: 34px; }
  .pos-face .stat.lap .v { font-size: 14px; }
  .pos-face .k, .gap-face .k { font-size: 7px; letter-spacing: .14em; }
  .gap-face { padding: 12% 8%; gap: 7%; }
  .gap-face .stat .v { font-size: 11px; }
  .gap-caption { display: none; }
  .dial { width: 92px; }
  .dial-read span { font-size: 20px; }
  .gear { width: 64px; }
  .gear-face span { font-size: 34px; }
  .damage-plate { width: 168px; }
  .cash { width: 96px; }
  .cash-face .v { font-size: 14px; }
  .icon-plate { width: 40px; height: 40px; }
  .pit-wrap { padding: 10px 10px 16px; }
  .team p { display: none; }
  .money-plate { width: 138px; }
  .upgrade-grid { grid-template-columns: 1fr 1fr; }
  .up { padding: 7px 8px; gap: 7px; }
  .up-icon { width: 32px; }
  .pit-grid { grid-template-columns: 1fr; }
  .note { padding: 7px 9px; }
  .result-rows { grid-template-columns: 1fr; }
  .title-content { bottom: 7vh; }
}
@media (max-height: 560px) and (orientation: landscape) {
  .gap-caption { display: none; }
  .hud-pos { width: clamp(112px, 15vh, 142px); }
  .hud-gap { width: clamp(124px, 18vh, 158px); }
  .damage-plate { width: clamp(160px, 32vh, 230px); }
  .cash { width: clamp(82px, 14vh, 116px); }
  .dial { width: clamp(88px, 22vh, 122px); }
  .gear { width: clamp(62px, 15vh, 86px); }
  .pos-face .stat.pos .v { font-size: clamp(26px, 8.5vh, 46px); }
  .pos-face .stat.lap .v { font-size: clamp(12px, 3.4vh, 18px); }
  .gap-face .stat .v { font-size: clamp(9px, 2.6vh, 14px); }
  .pos-face .k, .gap-face .k { font-size: clamp(6px, 1.8vh, 9px); }
  .cash-face .v { font-size: clamp(11px, 3.2vh, 16px); }
  .dmg-face .k { font-size: clamp(7px, 2vh, 10px); }
  .dmg-face .v { font-size: clamp(10px, 2.8vh, 14px); }
  .dial-read span { font-size: clamp(16px, 5vh, 24px); }
  .gear-face span { font-size: clamp(24px, 7vh, 40px); }
  .gear-face small { font-size: clamp(6px, 1.7vh, 8px); }
  .icon-plate { width: clamp(38px, 10vh, 48px); height: clamp(38px, 10vh, 48px); }
  .title-content { bottom: 2vh; gap: 5px; }
  .title-type { width: min(560px, 56vw); }
  .title-line { font-size: 12px; }
  .title-foot { display: none; }
  .pit-wrap { padding: 6px 10px 8px; gap: 6px; }
  .team-mark { font-size: 26px; padding: 2px 6px; border-width: 2px; }
  .team h1 { font-size: 15px; }
  .team p { display: none; }
  .money-plate { width: 120px; }
  .pit-head { align-items: center; }
  .board-panel { padding: 6px 8px; }
  .board-panel h2 { margin-bottom: 5px; font-size: 12px; letter-spacing: .14em; }
  .board-panel h2 span { display: none; }
  .pit-grid { gap: 8px; grid-template-columns: .95fr 2fr; }
  .race-notes { gap: 5px; }
  .note { padding: 5px 7px; }
  .note .name { font-size: 10px; }
  .note .res { font-size: 9px; }
  .note .sub { font-size: 8px; margin-top: 1px; }
  .ledger { margin-top: 6px; }
  .ledger h3 { display: none; }
  .upgrade-grid { grid-template-columns: repeat(4, minmax(0,1fr)); gap: 5px; }
  .up { padding: 4px 5px; gap: 4px; flex-direction: column; }
  .up-icon { width: 26px; }
  .up-name { font-size: 9px; letter-spacing: .06em; }
  .up-pips { margin: 2px 0; }
  .pip { width: 9px; height: 4px; }
  .up-price { font-size: 8px; }
  .up-buy { font-size: 8px; padding: 2px 3px; margin-top: 3px; letter-spacing: .1em; }
  .pit-foot { gap: 10px; padding-top: 0; }
  .next-race .v { font-size: 13px; }
  .plate-btn { font-size: 14px; padding: 7px 14px; }
  .hud-dial-wrap { bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
  .hud-status { bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
  .touch-btn { bottom: 6px; }
  .race-hint { display: none; }
}


/* ---------------- portrait pit: clean scroll + fixed action bar ---------------- */
@media (orientation: portrait) and (max-width: 900px) {
  .pit-wrap {
    display: flex; flex-direction: column;
    overflow-y: auto; -webkit-overflow-scrolling: touch;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
  .pit-head { order: 1; flex: 0 0 auto; margin-bottom: 10px; }
  .pit-foot {
    order: 2; flex: 0 0 auto;
    position: static; padding: 8px 0; margin-bottom: 10px;
    background: rgba(8,10,12,.55);
    border-top: 1px solid rgba(239,228,205,.18);
    border-bottom: 1px solid rgba(239,228,205,.18);
    box-shadow: none; flex-wrap: wrap; gap: 8px;
  }
  .pit-grid {
    order: 3; flex: 0 0 auto;
    display: flex; flex-direction: column;
    overflow: visible; gap: 12px; padding-right: 0;
  }
  .pit-grid > .board-panel { width: 100%; }
  .pit-foot .next-race { min-width: 0; }
  .pit-foot .next-race .v { font-size: clamp(12px, 3.6vw, 16px); }
  .pit-foot .plate-btn.big { font-size: 15px; padding: 9px 14px; }
  .pit-foot .plate-btn.small { font-size: 11px; padding: 7px 10px; }
  .pit-foot .hint { display: none; }
  .target { display: none; }
}
