:root {
  --pink: #ff4fa3;
  --yellow: #ffd23f;
  --blue: #3ec5ff;
  --ink: #1b1340;
  --card: rgba(255, 255, 255, 0.94);
  --font: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #6ec6ff; font-family: var(--font); color: var(--ink); user-select: none; touch-action: none; }
html { -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; }
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
canvas#overlay { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
.muted { color: #6a6490; font-size: 14px; }

/* ------------------------------------------------ Phòng chờ */
.screen { position: fixed; inset: 0; overflow: auto; padding: 24px 16px 40px; }
#lobby { background: linear-gradient(180deg, rgba(20, 10, 60, 0.35), rgba(20, 10, 60, 0.65)); }
.home-card { width: min(440px, 100%); margin: 8vh auto 0; text-align: center; }
.home-card .logo { font-size: clamp(34px, 8vw, 58px); }
.home-card #room-code-input { text-align: center; text-transform: uppercase; letter-spacing: 5px; }
.join-divider { display: flex; align-items: center; gap: 10px; color: #6a6490; font-size: 13px; margin: 22px 0 4px; }
.join-divider::before, .join-divider::after { content: ''; height: 2px; background: #d9d4ed; flex: 1; }
.logo { text-align: center; margin: 8px 0 0; font-size: clamp(38px, 6vw, 72px); font-weight: 900; letter-spacing: 2px; color: var(--yellow);
  text-shadow: 0 4px 0 #e0561b, 0 8px 0 var(--ink), 0 12px 20px rgba(0, 0, 0, 0.4); transform: rotate(-2deg); }
.logo span { color: var(--pink); text-shadow: 0 4px 0 #9c1d6b, 0 8px 0 var(--ink), 0 12px 20px rgba(0, 0, 0, 0.4); }
.tagline { text-align: center; color: #fff; font-weight: 700; margin: 18px 0 20px; text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5); }
.lobby-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 18px; max-width: 1180px; margin: 0 auto; }
.card { background: var(--card); border-radius: 22px; padding: 18px 20px; box-shadow: 0 6px 0 var(--ink), 0 14px 30px rgba(0, 0, 0, 0.3); border: 3px solid var(--ink); }
.card h2 { margin: 0 0 10px; font-size: 22px; }
.card h2 small { font-size: 15px; color: #6a6490; }
.label { display: block; font-weight: 800; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: #6a6490; margin: 14px 0 6px; }
#name-input { width: 100%; font: inherit; font-size: 20px; font-weight: 700; padding: 10px 14px; border-radius: 12px; border: 3px solid var(--ink); outline: none; }
#name-input:focus { border-color: var(--pink); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 38px; height: 38px; border-radius: 50%; border: 3px solid var(--ink); position: relative; }
.swatch.sel { box-shadow: 0 0 0 4px var(--yellow); transform: scale(1.1); }
.swatch.taken { opacity: 0.25; cursor: not-allowed; }
.bodies { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.body-btn { border: 3px solid var(--ink); border-radius: 14px; background: #fff; padding: 8px 4px; font-weight: 800; font-size: 14px; }
.body-btn small { display: block; font-weight: 400; font-size: 11px; color: #6a6490; }
.body-btn .emoji { font-size: 26px; display: block; }
.body-btn.sel { background: var(--yellow); }
button.big { width: 100%; margin-top: 16px; font-size: 22px; font-weight: 900; padding: 12px; border-radius: 16px; border: 3px solid var(--ink);
  background: #fff; box-shadow: 0 5px 0 var(--ink); transition: transform 0.08s; }
button.big:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
button.big.on { background: #3ddc84; }
button.big.go { background: var(--pink); color: #fff; }
button.big:disabled { opacity: 0.45; cursor: not-allowed; }
#player-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
#player-list li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; background: #f1eefc; font-weight: 700; }
#player-list li.me { outline: 3px solid var(--blue); }
#player-list .dot { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--ink); flex: none; }
#player-list .st { margin-left: auto; font-size: 13px; }
#track-list { display: grid; gap: 8px; }
.track-btn { text-align: left; border: 3px solid var(--ink); border-radius: 14px; background: #fff; padding: 8px 12px; font-weight: 800; font-size: 16px; }
.track-btn small { display: block; font-weight: 400; font-size: 12px; color: #6a6490; }
.track-btn.sel { background: var(--blue); }
.track-btn:disabled { cursor: default; }
.row { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; font-weight: 800; }
.stepper, .split-stepper { display: flex; align-items: center; gap: 10px; }
.stepper button, .split-stepper button { width: 34px; height: 34px; border-radius: 10px; border: 3px solid var(--ink); background: #fff; font-size: 20px; font-weight: 900; line-height: 1; }
.stepper button:disabled, .split-stepper button:disabled { opacity: 0.3; }
.stepper b, .split-stepper b { min-width: 22px; text-align: center; font-size: 20px; }
#lan-urls { margin-top: 12px; font-size: 13px; color: #6a6490; }
#lan-urls code { background: #f1eefc; padding: 2px 6px; border-radius: 6px; color: var(--ink); font-weight: 700; user-select: all; }
.room-share-row { display: flex; gap: 12px; align-items: center; }
#room-qr { background: #fff; border-radius: 10px; border: 2px solid var(--ink); image-rendering: pixelated; flex: none; }
.room-share-copy { min-width: 0; display: grid; gap: 7px; flex: 1; }
#lan-url-select, #room-share-copy button { width: 100%; min-height: 40px; border: 2px solid var(--ink); border-radius: 9px; background: #fff; color: var(--ink); font: inherit; font-size: 12px; }
#room-url-label { display: block; overflow-wrap: anywhere; font-size: 11px; user-select: all; }
#copy-room-url { padding: 6px 8px; font-weight: 800; cursor: pointer; }
#connection-status { margin: 0 0 10px; font-size: 12px; font-weight: 800; color: #6a6490; }
.room-code-display { display: inline-block; margin: -4px 0 10px; padding: 5px 9px; border-radius: 9px; background: #fff2b2; border: 2px solid var(--ink); font-size: 12px; letter-spacing: 1px; }
.room-code-display b { letter-spacing: 3px; }
#connection-status[data-status="connected"] { color: #16834a; }
#connection-status[data-status="reconnecting"] { color: #b57400; }
#room-counts { margin: -6px 0 8px; }
.controls table { border-collapse: collapse; width: 100%; font-size: 14px; }
.controls td { padding: 4px 4px; vertical-align: top; }
.controls td:first-child { white-space: nowrap; }
kbd { display: inline-block; min-width: 24px; padding: 2px 6px; margin: 1px; border: 2px solid var(--ink); border-bottom-width: 4px; border-radius: 7px; background: #fff; font-family: inherit; font-weight: 800; font-size: 12px; text-align: center; }
.tip { font-size: 13px; margin: 8px 0 0; }
.tutorial-link { display: block; margin: 10px auto 0; border: 0; background: transparent; color: #6a6490; font-weight: 800; text-decoration: underline; }
#tutorial, #trial-menu { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 18px; background: rgba(20, 10, 60, 0.68); }
.tutorial-card { width: min(420px, 100%); background: #fff; border: 3px solid var(--ink); border-radius: 24px; padding: 24px; text-align: center; box-shadow: 0 8px 0 var(--ink); }
.tutorial-progress { text-align: right; color: #6a6490; font-weight: 900; }
#tutorial-icon { font-size: 68px; margin: 10px 0; }
.tutorial-card h2 { margin: 0 0 8px; }
.tutorial-card p { min-height: 48px; margin: 0; line-height: 1.45; }
.tutorial-actions { display: grid; grid-template-columns: 1fr 1.3fr; gap: 10px; align-items: center; margin-top: 18px; }
.tutorial-actions button { min-height: 48px; border-radius: 14px; border: 3px solid var(--ink); font: inherit; font-weight: 900; }
.tutorial-actions .big { margin-top: 0; box-shadow: 0 4px 0 var(--ink); }
.trial-track-list { display: grid; gap: 8px; margin-top: 14px; text-align: left; }
#item-legend { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; margin-top: 10px; font-size: 12px; }

/* ------------------------------------------------ HUD */
#hud { position: fixed; inset: 0; pointer-events: none; color: #fff; font-weight: 900; }
.outline { text-shadow: -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink), 2px 2px 0 var(--ink), 0 4px 0 var(--ink); }
#hud-pos { position: absolute; left: 22px; top: 12px; font-size: 76px; line-height: 1; }
#hud-pos #pos-total { font-size: 30px; }
#hud-pos, #hud-lap, #hud-time, #speedo, #bigtext, #countdown, #spectate {
  text-shadow: -3px -3px 0 var(--ink), 3px -3px 0 var(--ink), -3px 3px 0 var(--ink), 3px 3px 0 var(--ink), 0 5px 0 var(--ink); }
#hud-pos.p1 { color: var(--yellow); }
#hud-lap { position: absolute; left: 26px; top: 94px; font-size: 26px; }
#hud-time { position: absolute; left: 26px; top: 126px; font-size: 22px; font-variant-numeric: tabular-nums; }
#standings { position: absolute; left: 20px; top: 170px; margin: 0; padding: 0; list-style: none; font-size: 15px; display: grid; gap: 3px; }
#standings li { background: rgba(27, 19, 64, 0.6); padding: 3px 10px 3px 6px; border-radius: 8px; display: flex; align-items: center; gap: 6px; min-width: 150px; }
#standings li.me { background: rgba(255, 79, 163, 0.85); }
#standings li .n { width: 18px; text-align: right; opacity: 0.8; }
#standings li .dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid #fff; }
#standings li .fin { margin-left: auto; }
#item-slot { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); width: 104px; height: 104px; border-radius: 22px; border: 4px solid #fff;
  background: rgba(27, 19, 64, 0.55); box-shadow: 0 0 0 4px var(--ink), 0 8px 18px rgba(0, 0, 0, 0.35); display: grid; place-items: center; }
#item-slot.ready { animation: pulse 0.9s ease-in-out infinite; }
#item-slot.rolling #item-icon { filter: blur(0.5px); }
#item-icon { font-size: 62px; line-height: 1; }
#item-uses { position: absolute; right: 6px; bottom: 2px; font-size: 22px; }
#item-key { position: absolute; left: -12px; bottom: -12px; background: var(--yellow); color: var(--ink); border: 3px solid var(--ink); border-radius: 10px; font-size: 14px; padding: 1px 7px; }
@keyframes pulse { 50% { transform: translateX(-50%) scale(1.07); } }
#minimap { position: absolute; right: 16px; top: 16px; width: 220px; height: 220px; }
#feed { position: absolute; right: 18px; top: 250px; display: grid; gap: 6px; justify-items: end; font-size: 16px; }
#feed div { background: rgba(27, 19, 64, 0.7); padding: 5px 12px; border-radius: 10px; animation: feedIn 0.25s ease-out; }
@keyframes feedIn { from { transform: translateX(40px); opacity: 0; } }
#speedo { position: absolute; right: 26px; bottom: 22px; font-size: 54px; text-align: right; line-height: 1; font-variant-numeric: tabular-nums; }
#speedo span { display: block; font-size: 18px; }
#bigtext { position: absolute; left: 0; right: 0; top: 30%; text-align: center; font-size: 64px; opacity: 0; transition: opacity 0.2s; }
#bigtext.show { opacity: 1; animation: pop 0.35s ease-out; }
@keyframes pop { from { transform: scale(0.4); } 70% { transform: scale(1.15); } }
#countdown { position: fixed; left: 0; right: 0; top: 26%; text-align: center; font-size: 150px; font-weight: 900; color: var(--yellow); pointer-events: none; }
#countdown.go { color: #3ddc84; }
#countdown.tick { animation: pop 0.4s ease-out; }
#spectate { position: absolute; bottom: 70px; left: 0; right: 0; text-align: center; font-size: 24px; }
#trial-exit { position: absolute; right: 18px; bottom: 18px; pointer-events: auto; border: 3px solid #fff; border-radius: 10px; background: rgba(27,19,64,.75); color: #fff; padding: 8px 12px; font: inherit; font-size: 12px; font-weight: 900; }
#hint { position: absolute; left: 0; right: 0; bottom: 8px; text-align: center; font-size: 12px; font-weight: 700; opacity: 0.8; text-shadow: 0 1px 3px #000; }
#touch-controls { display: none; position: fixed; inset: 0; z-index: 5; pointer-events: none; touch-action: none; }
.touch-btn { appearance: none; border: 3px solid rgba(27, 19, 64, 0.9); border-radius: 18px; background: rgba(255, 255, 255, 0.78); color: var(--ink);
  box-shadow: 0 5px 0 rgba(27, 19, 64, 0.85), 0 8px 18px rgba(0, 0, 0, 0.24); font: inherit; font-weight: 900; touch-action: none; user-select: none; -webkit-user-select: none;
  pointer-events: auto; transition: transform 0.08s, background 0.08s, box-shadow 0.08s; }
.touch-btn:active, .touch-btn.pressed { transform: translateY(4px); box-shadow: 0 1px 0 rgba(27, 19, 64, 0.85), 0 4px 10px rgba(0, 0, 0, 0.2); background: var(--yellow); }
#item-slot[data-touch-action] { pointer-events: auto; cursor: pointer; touch-action: none; }

/* ------------------------------------------------ Kết quả */
#results { position: fixed; right: 4vw; top: 50%; transform: translateY(-50%); width: min(520px, 92vw); max-height: 90vh; overflow: auto;
  background: var(--card); border: 3px solid var(--ink); border-radius: 22px; padding: 18px 22px; box-shadow: 0 6px 0 var(--ink), 0 14px 30px rgba(0, 0, 0, 0.35); }
#results h2 { margin: 0 0 10px; font-size: 30px; }
#results-table { width: 100%; border-collapse: collapse; font-size: 15px; }
#results-table th { text-align: left; font-size: 12px; color: #6a6490; text-transform: uppercase; padding: 4px; }
#results-table td { padding: 6px 4px; border-top: 2px solid #eee; font-weight: 700; }
#results-table .medal { font-size: 22px; }
#results-table .dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--ink); margin-right: 6px; vertical-align: -1px; }
#results-table td.stats { font-weight: 400; font-size: 13px; color: #555; }
#results-table tr.me td { background: #ffe6f2; }
#results-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

#gp-board h3 { margin: 14px 0 6px; font-size: 20px; }
#gp-table { width: 100%; border-collapse: collapse; font-size: 15px; margin-bottom: 12px; }
#gp-table td { padding: 5px 4px; border-top: 2px solid #eee; font-weight: 700; }
#gp-table .dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--ink); margin-right: 6px; vertical-align: -1px; }
#gp-table td.pts { text-align: right; font-size: 17px; }
#gp-table td.pts small { color: #2e9e5b; font-weight: 800; margin-left: 4px; }
#gp-table tr.me td { background: #ffe6f2; }
#gp-table tr.champ td { background: #fff3c4; }
.toggle { min-width: 64px; height: 34px; padding: 0 12px; border-radius: 10px; border: 3px solid var(--ink); background: #fff; font: inherit; font-weight: 900; }
.toggle[aria-pressed="true"] { background: var(--yellow); }
.toggle:disabled { opacity: 0.3; }
#hud-gp { position: absolute; top: 134px; left: 50%; transform: translateX(-50%); background: rgba(27, 19, 64, 0.8); color: #fff; padding: 4px 12px; border-radius: 12px; font-weight: 900; font-size: 14px; pointer-events: none; }

#hud-delta { position: absolute; top: 168px; left: 50%; transform: translateX(-50%); background: rgba(27, 19, 64, 0.8); color: #fff; padding: 4px 14px; border-radius: 12px; font-weight: 900; font-size: 20px; pointer-events: none; font-variant-numeric: tabular-nums; }
#hud-delta.ahead { color: #6dff9a; }
#hud-delta.behind { color: #ff7a7a; }

#hud-balloons { letter-spacing: 2px; }
#hud-lap.nolap #lap-part { display: none; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
#hud-elim { position: absolute; top: 126px; left: 50%; transform: translateX(-50%); display: grid; gap: 6px; justify-items: center; font-size: 22px; text-align: center; pointer-events: none; }
#elim-timer, #elim-warn { background: rgba(27, 19, 64, 0.8); padding: 4px 14px; border-radius: 12px; }
#elim-warn { background: #ff4d4d; animation: pop 0.35s ease-out; }

/* ------------------------------------------------ Chia đôi màn hình */
#split-menu { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(27, 19, 64, 0.55); padding: 16px; overflow: auto; }
#split-menu.hidden { display: none; }
#split-menu p { font-size: 14px; line-height: 1.5; }
#split-hud { position: absolute; inset: 0; pointer-events: none; }
#split-hud.hidden { display: none; }
.split-panel { position: absolute; bottom: 36px; background: rgba(27, 19, 64, 0.82); color: #fff; padding: 6px 12px; border-radius: 12px; font-weight: 900; font-size: 15px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.split-panel b { color: var(--yellow); margin-right: 6px; }
.split-panel .dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 2px solid #fff; margin-right: 6px; vertical-align: -1px; }
#split-p1 { left: 14px; }
#split-p2 { left: calc(50% + 14px); }
#split-divider { position: absolute; background: var(--ink); left: calc(50% - 2px); top: 0; bottom: 0; width: 4px; }
#split-hud.portrait #split-p1 { left: 14px; bottom: auto; top: calc(50% - 46px); }
#split-hud.portrait #split-p2 { left: 14px; }
#split-hud.portrait #split-divider { left: 0; right: 0; top: calc(50% - 2px); bottom: auto; width: auto; height: 4px; }
#hud.split #hud-pos, #hud.split #hud-lap, #hud.split #speedo, #hud.split #item-slot, #hud.split #touch-controls, #hud.split #hud-gp, #hud.split #hud-delta { display: none; }

.track-btn.mine { box-shadow: 0 0 0 3px var(--pink, #ff4fa3) inset; }
.track-btn .votes { display: flex; align-items: center; gap: 3px; margin-top: 4px; }
.track-btn .vdot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--ink); }
.track-btn .votes b { margin-left: 4px; font-size: 13px; }

/* ------------------------------------------------ Chat & điểm nhấn */
#chat-box { margin-top: 10px; }
#chat-log { height: 96px; overflow-y: auto; background: #f4f1ff; border: 2px solid var(--ink); border-radius: 12px; padding: 6px 8px; font-size: 14px; display: flex; flex-direction: column; gap: 3px; }
#chat-log .msg { word-break: break-word; }
#chat-log .msg b { margin-right: 4px; }
#chat-log .msg.me { text-align: right; }
#chat-log .empty { color: #6a6490; font-size: 13px; }
.chat-quick { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chat-quick button { border: 2px solid var(--ink); border-radius: 999px; background: #fff; padding: 4px 10px; font: inherit; font-weight: 800; font-size: 13px; min-height: 32px; }
.chat-quick button:active { background: var(--yellow); }
#chat-form { display: flex; gap: 6px; }
#chat-form input { flex: 1; min-width: 0; }
#chat-form button { border: 3px solid var(--ink); border-radius: 12px; background: var(--yellow); font: inherit; font-weight: 900; padding: 0 14px; min-height: 40px; }
#highlights h3 { margin: 14px 0 6px; font-size: 20px; }
#highlight-list { display: grid; gap: 6px; margin-bottom: 8px; }
.hl { display: flex; align-items: center; gap: 8px; background: #fff7d6; border: 2px solid var(--ink); border-radius: 12px; padding: 5px 10px; font-weight: 700; font-size: 14px; }
.hl .icon { font-size: 22px; }
.hl .who { font-weight: 900; }
.hl .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--ink); margin-right: 4px; }
.hl small { display: block; font-weight: 400; color: #555; }

/* ------------------------------------------------ Hồ sơ & huy hiệu */
#profile-box { margin-top: 12px; border: 3px solid var(--ink); border-radius: 14px; background: #fff; padding: 6px 10px; }
#profile-box summary { cursor: pointer; font-weight: 900; }
#profile-box summary span { color: #6a6490; font-weight: 800; margin-left: 4px; }
#profile-stats { font-size: 13px; font-weight: 700; margin: 8px 0; color: #4a4570; line-height: 1.6; }
#badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; max-height: 220px; overflow-y: auto; padding-bottom: 4px; }
.badge { display: grid; grid-template-columns: 28px 1fr; column-gap: 6px; align-items: center; border: 2px solid #ccc7e6; border-radius: 10px; padding: 4px 6px; opacity: 0.45; filter: grayscale(0.8); }
.badge.on { opacity: 1; filter: none; border-color: var(--ink); background: #fff7d6; }
.badge .icon { font-size: 22px; grid-row: span 2; text-align: center; }
.badge b { font-size: 13px; }
.badge small { font-size: 11px; color: #555; }
.swatch.locked { opacity: 0.35; position: relative; cursor: not-allowed; }
.swatch.locked::after { content: '🔒'; position: absolute; inset: 0; display: grid; place-items: center; font-size: 14px; }

#toast { position: fixed; left: 50%; bottom: 60px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 14px; font-weight: 800; opacity: 0; transition: opacity 0.3s; pointer-events: none; z-index: 10; }
#toast.show { opacity: 1; }
#connecting { display: grid; place-items: center; background: #6ec6ff; font-size: 28px; font-weight: 900; color: #fff; text-shadow: 0 3px 0 var(--ink); z-index: 20; }
#connecting > div { text-align: center; }
#connecting > button { width: min(300px, 90vw); font-size: 18px; }

@media (max-width: 800px) {
  #hud-pos { font-size: 52px; }
  #standings, #feed { display: none; }
  #minimap { width: 140px; height: 140px; }
  #hint { display: none; }
}

@media (pointer: coarse), (max-width: 800px) {
  .screen { padding: max(16px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  .lobby-grid { grid-template-columns: minmax(0, 1fr); max-width: 560px; }
  .card { border-radius: 18px; padding: 16px; }
  .lobby-grid .controls { order: 3; }
  .swatch { width: 44px; height: 44px; }
  .body-btn, .track-btn, .stepper button, .split-stepper button, .toggle, #copy-room-url { min-height: 44px; }
  #touch-controls { display: block; }
  #hud-pos { left: max(66px, calc(54px + env(safe-area-inset-left))); top: max(10px, env(safe-area-inset-top)); font-size: 48px; }
  #hud-lap { left: max(68px, calc(56px + env(safe-area-inset-left))); top: 70px; font-size: 20px; }
  #hud-time { left: max(68px, calc(56px + env(safe-area-inset-left))); top: 96px; font-size: 17px; }
  #hud-elim { top: 94px; font-size: 15px; max-width: 46vw; }
  #item-slot { top: max(12px, env(safe-area-inset-top)); width: 76px; height: 76px; border-radius: 18px; }
  #item-icon { font-size: 42px; }
  #item-key { left: -8px; bottom: -9px; font-size: 11px; padding: 1px 5px; }
  #minimap { right: max(10px, env(safe-area-inset-right)); top: max(10px, env(safe-area-inset-top)); width: 118px; height: 118px; }
  #speedo { right: max(14px, env(safe-area-inset-right)); bottom: calc(156px + env(safe-area-inset-bottom)); font-size: 38px; }
  #speedo span { font-size: 14px; }
  #countdown { top: 24%; font-size: clamp(82px, 25vw, 128px); }
  #bigtext { top: 32%; font-size: clamp(34px, 9vw, 56px); }
  #touch-controls { padding: 0 max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); }
  .touch-steer, .touch-drive, .touch-actions { position: absolute; bottom: max(16px, env(safe-area-inset-bottom)); display: flex; align-items: end; gap: 10px; }
  .touch-steer { left: max(14px, env(safe-area-inset-left)); }
  .touch-drive { right: max(14px, env(safe-area-inset-right)); }
  .touch-actions { left: 50%; transform: translateX(-50%); bottom: max(18px, env(safe-area-inset-bottom)); gap: 8px; }
  .touch-steer-btn, .touch-drive-btn { width: 66px; height: 66px; font-size: 27px; }
  .touch-drive-btn { width: 62px; height: 62px; }
  .touch-drive-btn.gas { background: rgba(61, 220, 132, 0.82); }
  .touch-drive-btn.brake { background: rgba(255, 255, 255, 0.78); }
  .touch-action-btn { min-width: 54px; height: 46px; padding: 0 10px; border-radius: 14px; font-size: 13px; }
  .touch-emotes { position: absolute; top: max(140px, calc(128px + env(safe-area-inset-top))); right: max(14px, env(safe-area-inset-right)); display: flex; flex-direction: column; gap: 6px; }
  .touch-emote-btn { width: 42px; height: 42px; font-size: 20px; border-radius: 12px; padding: 0; }
  .touch-sound-btn { position: absolute; top: max(14px, env(safe-area-inset-top)); left: max(14px, env(safe-area-inset-left)); width: 42px; height: 42px; font-size: 20px; border-radius: 12px; padding: 0; }
}

@media (max-width: 520px) and (orientation: portrait) {
  .touch-actions { bottom: max(96px, calc(84px + env(safe-area-inset-bottom))); }
  #speedo { bottom: calc(228px + env(safe-area-inset-bottom)); }
  #spectate { bottom: 150px; font-size: 18px; }
}
