html, body { margin: 0; height: 100%; background: #111318; color: #f2f2f2; overflow: hidden;
  font-family: system-ui, -apple-system, sans-serif; -webkit-user-select: none; user-select: none; touch-action: none; }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px;
  background: rgba(20, 12, 44, 0.55);
  /* keep bottom UI clear of floating mobile browser toolbars (Arc, Safari) */
  padding: env(safe-area-inset-top) 16px calc(env(safe-area-inset-bottom) + 72px); }
.screen[hidden] { display: none; }
h1 { margin: 0; font-size: clamp(40px, 11vw, 84px); font-weight: 900; font-style: italic; letter-spacing: -0.01em; color: #ffd23a;
  text-shadow: 0 4px 0 #7a3a00, 0 10px 30px rgba(0,0,0,0.4); }
h1 small { font-size: 0.45em; color: #fff; text-shadow: none; }
button.big { font: inherit; font-size: 22px; font-weight: 800; padding: 14px 48px; border: 0; border-radius: 99px; background: #ffd23a; color: #1a1030;
  cursor: pointer; box-shadow: 0 4px 0 #a86b00; }
.hint { margin: 0; text-align: center; opacity: 0.9; line-height: 1.55; max-width: 420px; }
.hint.small { font-size: 14px; opacity: 0.75; }
.keys { opacity: 0.7; font-size: 14px; }
body.touch .keys { display: none; }
#errline { position: fixed; left: 0; right: 0; top: 0; z-index: 99999; background: #a00; color: #fff;
  font: 12px/1.3 monospace; padding: 4px 8px; white-space: pre-wrap; pointer-events: none; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; font-variant-numeric: tabular-nums; }
#hud[hidden] { display: none; }
.tl { position: absolute; left: 12px; top: calc(env(safe-area-inset-top) + 10px); width: min(190px, 46vw); }
.tr { position: absolute; right: 12px; top: calc(env(safe-area-inset-top) + 10px); width: min(150px, 38vw); }
#place { font-size: 52px; font-weight: 900; line-height: 1; text-shadow: 0 3px 10px rgba(0,0,0,0.5); }
#place small { font-size: 22px; opacity: 0.85; }
.lapbox, #board, .trackname, #minimap { background: rgba(18, 14, 40, 0.72); border: 1px solid rgba(255,255,255,0.12); border-radius: 10px; }
.lapbox { display: flex; align-items: baseline; gap: 8px; margin-top: 6px; padding: 5px 10px; font-size: 14px; }
.lapbox span { font-size: 11px; opacity: 0.7; }
.lapbox em { margin-left: auto; font-style: normal; font-weight: 600; }
#board { margin-top: 6px; padding: 4px 0; font-size: 12px; }
#board .row { display: flex; align-items: center; gap: 6px; padding: 2px 8px; }
#board .row i { width: 3px; height: 12px; border-radius: 2px; }
#board .row span { width: 14px; opacity: 0.8; }
#board .row b { font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#board .row em { font-style: normal; opacity: 0.8; font-size: 11px; }
#board .row.me { background: #ffd23a; color: #1a1030; }
#board .row.me em, #board .row.me span { opacity: 1; }
#board .gap { height: 6px; }
#minimap { display: block; width: 100%; height: auto; }
.trackname { margin-top: 5px; padding: 4px 8px; font-size: 12px; text-align: center; }
#feed { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; font-size: 11px; }
#feed div { background: rgba(60, 30, 110, 0.85); border: 1px solid rgba(176, 108, 255, 0.6); border-radius: 8px; padding: 5px 8px; }
#msg { position: absolute; top: 34%; width: 100%; text-align: center; font-size: clamp(64px, 20vw, 140px); font-weight: 900; font-style: italic;
  text-shadow: 0 5px 0 rgba(0,0,0,0.35), 0 10px 30px rgba(0,0,0,0.4); }
#sub { position: absolute; top: 28%; width: 100%; text-align: center; font-size: 24px; font-weight: 800; color: #ffd23a;
  text-shadow: 0 2px 0 #000, 0 0 12px rgba(0,0,0,0.6); }
.bottom { position: absolute; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 72px); display: flex; flex-direction: column; align-items: center; gap: 10px; }
#chips { display: flex; gap: 8px; pointer-events: auto; }
.chip-c { display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; border-radius: 99px; background: rgba(18, 14, 40, 0.8);
  border: 1px solid rgba(255,255,255,0.2); color: #fff; font: inherit; font-size: 16px; }
.chip-c i { font-style: normal; font-size: 12px; font-weight: 700; }
.chip-boost { background: #ff5fd2; border-color: #ffd0f3; font-size: 22px; padding: 8px 18px; cursor: pointer; animation: pulse 1.2s infinite; }
.chip-boost.on { background: #fff; color: #ff2fb8; animation: none; }
@keyframes pulse { 50% { transform: scale(1.08); } }
#speedo { text-align: center; text-shadow: 0 2px 10px rgba(0,0,0,0.6); }
#speed { font-size: 46px; font-weight: 900; line-height: 1; display: block; }
#speedo small { font-size: 11px; letter-spacing: 0.15em; opacity: 0.8; }
.barbg { width: 150px; height: 4px; border-radius: 2px; background: rgba(255,255,255,0.2); margin-top: 6px; overflow: hidden; }
#bar { height: 100%; width: 0; background: linear-gradient(90deg, #ff4d4d, #7dff7a); }
#bar.boost { background: #ff5fd2; }
#tags { position: absolute; inset: 0; overflow: hidden; }
.tag { position: absolute; left: 0; top: 0; display: none; padding: 2px 8px; border-radius: 99px; background: rgba(18, 14, 40, 0.75);
  font-size: 11px; font-weight: 600; white-space: nowrap; }
.tag i { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; }

/* card picker */
#picker { position: fixed; left: 0; right: 0; top: 40%; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 0 12px; }
#picker[hidden] { display: none; }
.ptitle { font-weight: 900; font-style: italic; font-size: 22px; text-shadow: 0 2px 0 #000; }
#cards { display: flex; gap: 10px; justify-content: center; }
.card { position: relative; width: min(31vw, 150px); padding: 12px 8px 14px; border-radius: 12px; border: 2px solid; background: rgba(18, 14, 40, 0.92);
  color: #fff; font: inherit; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; animation: pop 0.25s ease-out both; }
.card:nth-child(2) { animation-delay: 0.06s; } .card:nth-child(3) { animation-delay: 0.12s; }
@keyframes pop { from { transform: translateY(20px) scale(0.9); opacity: 0; } }
.card.r0 { border-color: #9aa3b5; } .card.r1 { border-color: #b06cff; box-shadow: 0 0 18px rgba(176,108,255,0.5); }
.card.r2 { border-color: #ffc23a; box-shadow: 0 0 24px rgba(255,194,58,0.6); background: linear-gradient(#3a2a10, rgba(18,14,40,0.95)); }
.card .rar { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; opacity: 0.8; }
.card.r1 .rar { color: #c99bff; } .card.r2 .rar { color: #ffd23a; }
.card .ico { font-size: 30px; }
.card b { font-size: 14px; }
.card .desc { font-size: 12px; opacity: 0.85; text-align: center; }
.card .key { position: absolute; top: 6px; right: 8px; font-size: 10px; opacity: 0.5; }
body.touch .card .key { display: none; }

/* modes */
.modes { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
button.big.alt { background: #b06cff; color: #fff; box-shadow: 0 4px 0 #5a2a9a; }

/* Card Battle */
body.cardmode #board, body.cardmode .bottom, body.cardmode #feed { display: none; }
body.cardmode #msg { top: 14%; font-size: clamp(44px, 13vw, 96px); }
body.cardmode #sub { top: 9%; font-size: 18px; }
#cardpanel { --cw: min(21vw, 15vh, 104px); position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 72px); display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: linear-gradient(rgba(20, 12, 44, 0), rgba(20, 12, 44, 0.92) 14%); touch-action: none; }
#cardpanel[hidden] { display: none; }
.kbar { width: calc(var(--cw) * 4 + 30px); display: flex; justify-content: space-between; font-weight: 700; font-size: 15px; }
.kdeck { opacity: 0.8; }
#kboard { display: flex; gap: 10px; }
.kslot { width: var(--cw); height: calc(var(--cw) * 1.36); border-radius: 10px; background: rgba(255,255,255,0.06); border: 1px dashed rgba(255,255,255,0.18); }
.kslot.sel .kcard { outline: 3px solid #ffd23a; transform: translateY(-6px); }
.kcard { position: relative; width: 100%; height: 100%; box-sizing: border-box; border-radius: 10px; border: 2px solid rgba(255,255,255,0.85);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: #fff; cursor: grab;
  box-shadow: 0 4px 0 rgba(0,0,0,0.35); transition: transform 0.12s; touch-action: none; }
.kcard.dragging { z-index: 20; transition: none; box-shadow: 0 14px 24px rgba(0,0,0,0.5); cursor: grabbing; }
.kcard .val { position: absolute; top: 4px; right: 6px; font-weight: 900; font-size: calc(var(--cw) * 0.24); text-shadow: 0 2px 0 rgba(0,0,0,0.4); }
.kcard .ic { font-size: calc(var(--cw) * 0.4); line-height: 1; }
.kcard .who { font-size: calc(var(--cw) * 0.12); font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; text-align: center; padding: 0 4px;
  display: flex; align-items: center; gap: 3px; }
.kcard .who i { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.k-rival { background: linear-gradient(160deg, #e0353b, #7a1020); }
.k-nitro { background: linear-gradient(160deg, #ff5fd2, #8a1f9e); }
.k-shield { background: linear-gradient(160deg, #3ab0f0, #1c4aa0); }
.k-repair { background: linear-gradient(160deg, #4ad07a, #17703a); }
.k-coins { background: linear-gradient(160deg, #ffc23a, #a8640a); }
.krow { display: flex; gap: 10px; align-items: flex-end; }
.khand, #khero, #ksell { width: var(--cw); height: calc(var(--cw) * 1.36); border-radius: 10px; box-sizing: border-box; position: relative; }
.khand { border: 2px dashed rgba(255,255,255,0.35); display: flex; align-items: center; justify-content: center; }
.khand .empty { font-size: 12px; opacity: 0.6; text-transform: uppercase; letter-spacing: 0.1em; }
.khand .cap { position: absolute; bottom: -9px; left: 50%; transform: translateX(-50%); background: #1a1030; border: 1px solid #ff5fd2;
  border-radius: 99px; font-size: 11px; font-weight: 800; padding: 1px 7px; }
.khand.sel .kcard { outline: 3px solid #ffd23a; }
#khero { background: linear-gradient(160deg, #8ee03a, #2f7a16); border: 3px solid #ffd23a; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 4px; color: #10200a; }
#khero .herocar { font-size: calc(var(--cw) * 0.42); }
#khero b { font-weight: 900; }
.hpbar { width: 78%; height: 6px; border-radius: 3px; background: rgba(0,0,0,0.3); overflow: hidden; }
#khpbar { height: 100%; background: #e0353b; transition: width 0.25s; }
#khp { font-weight: 900; font-size: 15px; }
#ksell { width: calc(var(--cw) * 0.62); height: calc(var(--cw) * 0.9); border: 2px dashed rgba(255,194,58,0.6); display: flex; align-items: center;
  justify-content: center; text-align: center; font-size: 12px; font-weight: 700; color: #ffd23a; }
.target { outline: 3px solid #7dff7a !important; outline-offset: 2px; animation: tpulse 0.8s infinite; }
@keyframes tpulse { 50% { outline-color: rgba(125,255,122,0.35); } }
.khelp { max-width: calc(var(--cw) * 4 + 30px); font-size: 12px; opacity: 0.8; text-align: center; line-height: 1.4; }
body.touch .khelp .keys { display: none; }
