* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b1020; font-family: system-ui, -apple-system, "Segoe UI", sans-serif; color: #fff; }
canvas#game { display: block; width: 100vw; height: 100vh; touch-action: none; }
.hidden { display: none !important; }

#hud { position: fixed; inset: 0; pointer-events: none; text-shadow: 0 2px 4px #000a; }
#title { position: absolute; top: 8px; left: 12px; font-weight: 800; letter-spacing: .08em; color: #19e6ff; font-size: 13px; }
#scoreboard { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); display: flex; gap: 14px; align-items: center;
  background: #0009; padding: 6px 14px; border-radius: 10px; font-weight: 800; font-size: 18px; }
#scoreboard .blue { color: #4f8bff; } #scoreboard .orange { color: #ff8a1f; }
#scoreboard b { font-size: 24px; } #clock { min-width: 64px; text-align: center; }
#banner { position: absolute; top: 28%; width: 100%; text-align: center; font-size: clamp(28px, 6vw, 64px); font-weight: 900; letter-spacing: .04em; }
#boostWrap { position: absolute; right: 16px; bottom: 16px; width: 120px; height: 120px; border-radius: 50%; background: #0008;
  display: grid; place-items: center; font-weight: 800; font-size: 12px; overflow: hidden; }
#boostBar { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(#ffb02e, #ff5a00); height: 33%; }
#boostWrap span { position: relative; }
#hubInfo { position: absolute; top: 52px; left: 50%; transform: translateX(-50%); background: #000a; padding: 8px 14px; border-radius: 10px;
  font-size: 14px; text-align: center; max-width: 92vw; white-space: pre-line; }
#hubInfo:empty { display: none; }
#hint { position: absolute; bottom: 14px; left: 14px; font-size: 13px; opacity: .85; max-width: 60vw; }
#menuBtn { position: absolute; top: 6px; right: 8px; pointer-events: auto; background: #0008; color: #fff; border: 0; border-radius: 8px;
  font-size: 20px; padding: 4px 10px; cursor: pointer; }

#menu { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: radial-gradient(ellipse at center, #13306acc, #050814f0); text-align: center; padding: 16px; z-index: 5; }
#menu h1 { margin: 0; font-size: clamp(30px, 7vw, 64px); line-height: 1; color: #19e6ff; letter-spacing: .05em; text-shadow: 0 4px 0 #ff8a1f; }
#menu h1 small { font-size: .55em; color: #fff; }
#menu .tag { margin: 4px 0 8px; opacity: .85; }
#menu .modes { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
#menu .modes .match-only { display: none; }
body.in-match #menu .modes .match-only { display: block; }
#menu .modes button { font-size: 18px; font-weight: 800; padding: 14px 18px; border-radius: 12px; border: 0; cursor: pointer;
  background: #ff8a1f; color: #1a0d00; box-shadow: 0 4px 0 #a64e00; }
#menu .modes #resumeBtn { background: #19e6ff; box-shadow: 0 4px 0 #0b7e8c; color: #002a30; }
#menu .modes button:active { transform: translateY(3px); box-shadow: none; }
#menu .controls { display: grid; grid-template-columns: repeat(2, auto); gap: 4px 18px; font-size: 13px; margin-top: 10px; opacity: .9; text-align: left; }
#menu .small { font-size: 12px; opacity: .7; }
#homeArrow { position: absolute; top: 52px; right: 12px; background: #000a; padding: 6px 12px; border-radius: 10px; font-weight: 800;
  display: flex; align-items: center; gap: 8px; font-size: 14px; }
#homeArrow b { display: inline-block; color: #ffd23f; font-size: 20px; transition: transform .15s linear; }
#fade { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; transition: opacity .3s; z-index: 7; }
#fade.on { opacity: 1; }
kbd { background: #fff2; border-radius: 4px; padding: 1px 5px; font-family: inherit; }

#tablet { position: fixed; inset: 0; display: grid; place-items: center; background: #0007; z-index: 4; }
.tablet-frame { width: min(560px, 94vw); background: #111; border: 10px solid #222; border-radius: 26px; padding: 12px; box-shadow: 0 20px 60px #000c; }
.tablet-top, .tablet-bottom { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.tablet-top b { color: #ff8a1f; font-size: 20px; }
#mergeCash { color: #ffd23f; font-weight: 800; }
#tabletClose { background: #333; color: #fff; border: 0; border-radius: 8px; padding: 4px 10px; cursor: pointer; }
#mergeGrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0; }
.slot { aspect-ratio: 4/3; background: #2a2f3a; border-radius: 10px; display: grid; place-items: center; cursor: pointer; position: relative;
  border: 3px solid transparent; user-select: none; }
.slot.held { border-color: #ffd23f; } .slot.cursor { border-color: #19e6ff; }
.car { width: 70%; height: 38%; border-radius: 4px; position: relative; }
.car::before { content: ""; position: absolute; left: 25%; width: 45%; height: 70%; top: -60%; background: inherit; filter: brightness(1.2); border-radius: 3px; }
.car::after { content: ""; position: absolute; bottom: -22%; left: 8%; right: 8%; height: 30%;
  background: radial-gradient(circle at 15% 50%, #111 30%, transparent 32%), radial-gradient(circle at 85% 50%, #111 30%, transparent 32%); }
.lvl { position: absolute; bottom: 3px; right: 6px; font-size: 11px; font-weight: 800; opacity: .9; }
#buyCar { background: #2ecc71; border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 800; cursor: pointer; }
#mergeRate { font-size: 13px; opacity: .85; }
#mergeMsg { min-height: 20px; text-align: center; font-weight: 700; color: #7dffb0; margin-top: 8px; }

#touch { position: fixed; inset: auto 0 0 0; height: 0; z-index: 3; }
#stickZone { position: fixed; left: 0; bottom: 0; width: 50vw; height: 75vh; touch-action: none; }
#stick { position: absolute; left: calc(24px + env(safe-area-inset-left)); bottom: calc(24px + env(safe-area-inset-bottom));
  width: min(150px, 34vmin); height: min(150px, 34vmin); border-radius: 50%; background: #ffffff22; border: 3px solid #19e6ffaa;
  display: grid; place-items: center; pointer-events: none; opacity: .95; box-shadow: 0 0 18px #19e6ff55; }
#stick::after { content: 'STEER'; position: absolute; bottom: -18px; font: 900 10px system-ui, sans-serif; letter-spacing: .12em; color: #bff6ff; opacity: .8; }
#stick.on::after { display: none; }
#stick.on { bottom: auto; background: #19e6ff26; border-color: #19e6ff99; opacity: 1; }
#knob { width: 44%; height: 44%; border-radius: 50%; background: #ffffffaa; box-shadow: 0 2px 10px #0008; pointer-events: none; }
#throttle { position: fixed; right: calc(20px + env(safe-area-inset-right)); bottom: calc(20px + env(safe-area-inset-bottom));
  width: min(84px, 19vmin); height: min(280px, 60vh); border-radius: 42px; background: #ffffff1c; border: 2px solid #ffffff40;
  touch-action: none; overflow: hidden; }
#throttle.on { border-color: #19e6ff99; background: #19e6ff1f; }
#throttleBoost { position: absolute; top: 0; left: 0; right: 0; height: 10%; display: grid; place-items: center;
  font-size: min(22px, 5vmin); border-bottom: 2px dashed #ffffff40; overflow: hidden; }
#throttleBoost i { position: absolute; bottom: 0; left: 0; right: 0; height: 33%; background: linear-gradient(#ffb02e, #ff5a00); opacity: .55; }
#throttleBoost span { position: relative; }
#throttle.boost #throttleBoost i { opacity: 1; }
#throttleMid { position: absolute; top: 50%; left: 18%; right: 18%; border-top: 2px solid #ffffff55; }
#lever { position: absolute; top: 50%; left: 50%; width: 76%; aspect-ratio: 1; transform: translate(-50%, -50%); border-radius: 50%;
  background: #ffffffaa; box-shadow: 0 2px 10px #0008; pointer-events: none; }
#throttle.on #lever { background: #bff6ff; }
#throttle::before, #throttle::after { position: absolute; left: 0; right: 0; text-align: center; font-size: 14px; opacity: .6; pointer-events: none; }
#throttle::before { content: "▲"; top: 16%; } #throttle::after { content: "▼"; bottom: 6%; }
.tpad { position: fixed; display: flex; gap: 10px; align-items: flex-end; }
.tpad.right { right: calc(20px + min(84px, 19vmin) + 14px + env(safe-area-inset-right)); bottom: calc(20px + env(safe-area-inset-bottom)); flex-direction: column; }
.tpad.side { right: calc(14px + env(safe-area-inset-right)); top: 56px; flex-direction: column; }
.tpad button { width: min(66px, 15vmin); height: min(66px, 15vmin); border-radius: 50%; border: 2px solid #ffffff40; background: #ffffff26;
  color: #fff; font-size: min(26px, 6vmin); touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; padding: 0; }
.tpad button.big { width: min(84px, 19vmin); height: min(84px, 19vmin); font-size: min(34px, 8vmin); }
.tpad button.on { background: #19e6ff88; transform: scale(.94); }
.tpad.side button { width: min(52px, 12vmin); height: min(52px, 12vmin); font-size: min(22px, 5vmin); }
.house-only, .match-only { display: none; }
body.in-house .house-only, body.in-match .match-only { display: flex; }
.touch-help { display: none !important; }
body.touch #touch.hidden { display: block !important; }
body.touch #boostWrap { display: none; }

/* start card */
#start { position: fixed; inset: 0; z-index: 6; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: radial-gradient(ellipse at center, #0b3a8a 0%, #03122e 55%, #000613 100%); padding: 16px; text-align: center; }
#startCard { padding: 0; border: 0; background: none; cursor: pointer; border-radius: 22%; line-height: 0;
  width: min(70vmin, 420px); animation: pulse 2.4s ease-in-out infinite; -webkit-tap-highlight-color: transparent; }
#startCard img { width: 100%; height: auto; border-radius: 22%; box-shadow: 0 0 40px #19a8ff88, 0 20px 60px #000c; }
#startCard:hover img, #startCard:focus-visible img { box-shadow: 0 0 60px #19e6ffcc, 0 20px 60px #000c; }
#startCard:active { transform: scale(.96); }
#startTap { margin: 0; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; color: #bff6ff; font-size: clamp(14px, 3.4vmin, 22px); }
#startCredit { margin: 0; font-size: 12px; opacity: .6; }
@keyframes pulse { 50% { transform: scale(1.03); } }
@media (prefers-reduced-motion: reduce) { #startCard { animation: none; } }

@media (pointer: coarse) {
  #touch.hidden { display: block !important; }
  #boostWrap { display: none; }
  html, body { touch-action: none; -webkit-user-select: none; user-select: none; overscroll-behavior: none; }
  #hint { left: 50%; transform: translateX(-50%); bottom: auto; top: 110px; max-width: 70vw; text-align: center; background: #0008;
    padding: 4px 10px; border-radius: 8px; }
  #hint:empty { display: none; }
  #boostWrap { width: 84px; height: 84px; right: calc(16px + env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom)); }
  #menuBtn { font-size: 26px; padding: 6px 14px; }
  #title { font-size: 11px; }
  #scoreboard { font-size: 14px; gap: 10px; padding: 4px 10px; } #scoreboard b { font-size: 18px; }
  #menu { overflow-y: auto; justify-content: safe center; }
  #menu .key-help, #menu .small { display: none !important; }
  .touch-help { display: grid !important; grid-template-columns: 1fr; }
  .tablet-frame { max-height: 92vh; overflow-y: auto; }
  #tabletClose { font-size: 20px; padding: 6px 14px; }
}
/* boost gauge sits right of the action buttons; keep them clear on narrow phones */
/* short sideways phones: a flatter tablet so Buy car stays on screen */
@media (pointer: coarse) and (max-height: 520px) {
  .tablet-frame { width: min(560px, 94vw, 150vh); padding: 8px; border-width: 6px; }
  #mergeGrid { gap: 6px; margin: 6px 0; } .slot { aspect-ratio: 2 / 1; }
}
/* phone held upright: action buttons stack above the boost gauge, clear of the stick */
@media (pointer: coarse) and (orientation: portrait) {
  #throttle { height: min(280px, 40vh); }
  #title { display: none; }
  #scoreboard { top: 8px; }
  #hubInfo { font-size: 12px; top: 58px; max-width: 70vw; }
}
/* sideways: home buttons run in a row along the top, clear of the slider */
@media (orientation: landscape) { .tpad.side { flex-direction: row; } }
@media (pointer: coarse) { #homeArrow { right: auto; left: calc(12px + env(safe-area-inset-left)); top: 34px; font-size: 12px; padding: 4px 10px; } }

/* block charges: three pips; the next one fills as it recharges */
#blockPips { position: absolute; left: 50%; bottom: 44px; transform: translateX(-50%); display: flex; gap: 8px; }
body.in-house #blockPips, body.in-mini #blockPips { display: none; }
#blockPips i { width: 34px; height: 12px; border-radius: 6px; background: #0008; border: 2px solid #19e6ff66; overflow: hidden; position: relative; }
#blockPips i.full { background: #19e6ff; border-color: #bff6ff; box-shadow: 0 0 8px #19e6ff; }
#blockPips i.fill::after { content: ""; position: absolute; inset: 0 auto 0 0; width: var(--fill, 0%); background: #19e6ff88; }
#blockPips.ultra i.full { background: #ffd23f; border-color: #fff3b0; box-shadow: 0 0 10px #ffd23f; }
#banner { white-space: pre-line; }
.tpad button[data-k="block"] { background: #19e6ff40; border-color: #19e6ffaa; }
.tpad button[data-k="block"].ultra { background: #ffd23f66; border-color: #ffd23f; }
.tpad button[data-k="block"].empty { opacity: .45; }
@media (pointer: coarse) { #blockPips { bottom: calc(10px + env(safe-area-inset-bottom)); } #blockPips i { width: 26px; height: 10px; } }
