:root {
  --safe-t: max(env(safe-area-inset-top), var(--u-t, 0px));
  --safe-r: max(env(safe-area-inset-right), var(--u-r, 0px));
  --safe-b: max(env(safe-area-inset-bottom), var(--u-b, 0px));
  --safe-l: max(env(safe-area-inset-left), var(--u-l, 0px));
  --ink: #10131a;
  --panel: rgba(12, 16, 28, 0.82);
  --accent: #ffd60a;
  --font: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b0e16; color: #fff; font-family: var(--font); user-select: none; }
#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#labels, #hud, #screen, #banner { position: fixed; inset: 0; pointer-events: none; }
#screen > * { pointer-events: auto; }

.lbl { position: absolute; transform: translate(-50%, -100%); font-weight: 800; font-size: 13px; text-shadow: 0 2px 0 #000, 0 0 6px #000; white-space: nowrap; }
.danger { position: absolute; width: 34px; height: 34px; margin: -17px 0 0 -17px; border-radius: 50%; border: 4px solid; animation: pulse .35s infinite alternate; box-shadow: 0 0 14px currentColor; }
@keyframes pulse { from { transform: scale(.8); opacity: .6; } to { transform: scale(1.25); opacity: 1; } }

/* HUD (estilo do original: cartoes pequenos no canto, placa LAP compacta no topo) */
#hud .cards { position: absolute; top: calc(6px + var(--safe-t)); left: calc(6px + var(--safe-l)); display: flex; flex-direction: column; gap: 3px; }
.card-p { display: flex; align-items: stretch; gap: 0; height: 28px; min-width: 128px; filter: drop-shadow(0 2px 0 #0008); transition: opacity .3s, transform .2s; }
.card-p.dead { opacity: .45; filter: grayscale(.7); }
.card-p.pop { transform: scale(1.08) translateX(4px); }
.card-p .av { width: 28px; flex: none; display: flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 900; color: var(--c); background: #06142e; border: 3px solid var(--c); border-radius: 7px; text-shadow: 0 0 6px var(--c); }
.card-p .bd { flex: 1; margin-left: -3px; padding: 2px 6px 2px 8px; background: linear-gradient(rgba(70,150,235,.86), rgba(24,88,170,.86)); border: 2px solid #0a1a44; border-left: 0; border-radius: 0 8px 8px 0; display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.card-p .l1 { display: flex; align-items: baseline; gap: 6px; }
.card-p .nm { font: italic 900 11px var(--font); color: #fff; -webkit-text-stroke: 2px #0a1a44; paint-order: stroke fill; max-width: 70px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-p .rk { font: italic 900 10px var(--font); color: #ffe27a; -webkit-text-stroke: 2px #0a1a44; paint-order: stroke fill; }
.card-p .it { margin-left: auto; font-size: 12px; min-width: 14px; text-align: right; display: inline-flex; align-items: center; justify-content: flex-end; }
.card-p { position: relative; }
.card-p .pdelta { position: absolute; left: 100%; top: 50%; margin-left: 6px; transform: translateY(-50%); font: italic 900 18px var(--font); color: #ff5a4a; -webkit-text-stroke: 3px #0a1a44; paint-order: stroke fill; transition: opacity 1.2s ease-out; pointer-events: none; }
.card-p .pdelta.up { color: #7dff6a; }
.card-p .bar { display: flex; gap: 1px; }
.card-p .bar i { flex: 1; height: 5px; background: #0a1a44aa; border-radius: 1px; transform: skewX(-18deg); }
.card-p .bar i.on { background: linear-gradient(#ffe94a, #f2b800); box-shadow: 0 0 4px #ffd60a99; }
#hud .lap { position: absolute; top: calc(4px + var(--safe-t)); left: 50%; transform: translateX(-50%); min-width: 150px; text-align: center; padding: 3px 26px 4px; clip-path: polygon(0 0, 100% 0, 94% 100%, 6% 100%); background: linear-gradient(rgba(36,150,190,.9), rgba(16,84,130,.9)); border-bottom: 3px solid #0a1a44; filter: drop-shadow(0 2px 0 #0008); }
#hud .lap b { display: block; font: italic 900 20px var(--font); color: #fff; -webkit-text-stroke: 3px #0a1a44; paint-order: stroke fill; letter-spacing: 1px; line-height: 1; }
#hud .lap small { display: block; font: 700 10px var(--font); color: #cfe0ff; margin-top: 1px; }
.mine-ico { display: inline-block; width: 1em; height: .5em; border-radius: 50%; background: radial-gradient(circle at 50% 30%, #6a7080, #23262e 70%); position: relative; box-shadow: 0 1px 0 #000; }
.mine-ico::after { content: ""; position: absolute; left: 50%; top: -.2em; width: .28em; height: .28em; margin-left: -.14em; border-radius: 50%; background: #ff2222; box-shadow: 0 0 4px #f22; }
#hud .kill { position: absolute; top: calc(8px + var(--safe-t)); right: calc(14px + var(--safe-r)); text-align: right; font-weight: 800; font-size: 15px; text-shadow: 0 2px 0 #000; display: flex; flex-direction: column; gap: 4px; }
#hud .kill span { background: var(--panel); padding: 3px 10px; border-radius: 8px; animation: fadein .2s; }
@keyframes fadein { from { opacity: 0; transform: translateX(20px); } }

#banner { display: flex; align-items: center; justify-content: center; text-align: center; }
#banner .big { font-size: min(22vw, 260px); font-weight: 900; color: #fff; text-shadow: 0 8px 0 #000a, 0 0 40px #000a; animation: pop .5s ease-out; }
#banner .mid { font-size: min(7vw, 84px); font-weight: 900; text-shadow: 0 5px 0 #000a; animation: pop .4s ease-out; }
#banner .sub { font-size: min(3vw, 30px); font-weight: 700; margin-top: 6px; text-shadow: 0 2px 0 #000; }
@keyframes tlpop { from { transform: translateX(-50%) scale(1.7); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }
@keyframes pop { from { transform: scale(1.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* telas */
.scr { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: calc(clamp(10px, 3vh, 24px) + var(--safe-t)) calc(clamp(12px, 3vw, 24px) + var(--safe-r)) calc(clamp(10px, 3vh, 24px) + var(--safe-b)) calc(clamp(12px, 3vw, 24px) + var(--safe-l)); background: radial-gradient(ellipse at 50% 30%, #23324f 0%, #0b0e16 75%); text-align: center; gap: clamp(8px, 2vh, 18px); justify-content: safe center; overflow-y: auto; overflow-x: hidden; }
.scr.clear { background: rgba(6, 8, 14, .55); }
.logo { font-size: min(11vw, 16vh, 120px); font-weight: 900; letter-spacing: -2px; line-height: .9; font-style: italic; color: var(--accent); text-shadow: 0 6px 0 #b33a00, 0 12px 30px #000a; transform: skew(-6deg); }
.logo small { display: block; font-size: min(2.4vw, 3.2vh, 22px); color: #fff; letter-spacing: 4px; margin-top: 1.4vh; font-style: normal; text-shadow: 0 4px 0 #444; }
.hint { color: #b9c3dc; font-size: clamp(12px, 2.4vh, 18px); }
.hint b { color: #fff; }
.btn { pointer-events: auto; cursor: pointer; border: 0; background: var(--accent); color: #221a00; font: 900 clamp(15px, 3.2vh, 22px) var(--font); padding: clamp(6px, 1.6vh, 12px) clamp(16px, 3vw, 30px); flex: none; border-radius: 14px; box-shadow: 0 6px 0 #a8870a; }
.btn2 { display: inline-block; margin-top: 14px; text-decoration: none; background: #2b3a67; color: #fff; font-size: 17px; padding: 8px 22px; box-shadow: 0 5px 0 #151d3a; }
.btn:active { transform: translateY(3px); box-shadow: 0 3px 0 #a8870a; }
h2 { margin: 0; font-size: clamp(20px, 5vh, 34px); }
.lobby { display: flex; gap: clamp(16px, 4vw, 40px); align-items: center; flex-wrap: wrap; justify-content: center; }
.qr { background: #fff; padding: clamp(6px, 1.4vh, 12px); border-radius: 16px; }
.qr canvas, .qr img, .qr svg { display: block; width: min(26vh, 24vw, 260px); height: min(26vh, 24vw, 260px); image-rendering: pixelated; }
.code { font-size: min(9vw, 11vh, 84px); font-weight: 900; letter-spacing: 12px; color: var(--accent); }
.url { font-family: Consolas, monospace; font-size: clamp(11px, 2.6vh, 20px); background: #0006; padding: 6px 14px; border-radius: 8px; max-width: 90vw; overflow-wrap: anywhere; }
.slots { display: grid; grid-template-columns: repeat(2, minmax(min(190px, 42vw), 1fr)); gap: clamp(4px, 1vh, 8px); }
.slot { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-radius: 12px; background: #ffffff10; border: 3px dashed #ffffff30; min-height: clamp(30px, 6vh, 48px); font-weight: 800; font-size: clamp(12px, 2.4vh, 16px); }
.slot.on { border: 3px solid var(--c); background: var(--panel); }
.slot .dot { width: 20px; height: 20px; border-radius: 50%; background: var(--c); }
.avatar { width: 1.6em; height: 1.6em; border-radius: 50%; object-fit: cover; display: inline-flex; align-items: center; justify-content: center; flex: none; line-height: 1; }
.card-p .av .avatar { width: 100%; height: 100%; border-radius: 4px; font-size: 1.1em; }
.slot .tag { margin-left: auto; font-size: 12px; opacity: .8; }
.cards { display: flex; gap: clamp(8px, 2vw, 20px); flex-wrap: wrap; justify-content: center; }
.card { width: clamp(170px, 26vw, 240px); padding: clamp(10px, 2vh, 18px); border-radius: 18px; background: var(--panel); border: 4px solid #ffffff20; text-align: left; cursor: pointer; }
.card.sel { border-color: var(--accent); transform: scale(1.06); box-shadow: 0 0 30px #ffd60a55; }
.card.lock { opacity: .4; cursor: default; }
.card h3 { margin: 0 0 6px; font-size: clamp(16px, 3.6vh, 26px); }
.card p { margin: 0; color: #c7d0e6; font-size: clamp(11px, 2.2vh, 15px); line-height: 1.35; }
.table { border-collapse: collapse; min-width: min(420px, 90vw); }
.tables { display: flex; gap: clamp(12px, 3vw, 36px); flex-wrap: wrap; justify-content: center; align-items: flex-start; }
.tables h3 { margin: 0 0 4px; font-size: clamp(14px, 2.8vh, 20px); color: #b9c3dc; }
.table td { padding: clamp(3px, .9vh, 8px) clamp(8px, 1.4vw, 14px); font-size: clamp(14px, 3.2vh, 24px); font-weight: 800; border-bottom: 2px solid #ffffff18; }
.table tr.first td { color: var(--accent); font-size: clamp(16px, 3.8vh, 30px); }
.table .dot { display: inline-block; width: 18px; height: 18px; border-radius: 50%; background: var(--c); margin-right: 10px; vertical-align: -2px; }
.delta.up { color: #4dff88; } .delta.down { color: #ff6b6b; }
#mutes { position: fixed; bottom: calc(8px + var(--safe-t, 0px)); left: 8px; display: flex; gap: 6px; z-index: 50; }
#mutes button { width: 40px; height: 40px; border-radius: 10px; border: 0; background: #000a; color: #fff; font-size: 20px; cursor: pointer; }
#mutes button:hover { background: #000d; }
#mutes button.off { opacity: .55; }
#debug { position: fixed; bottom: 6px; right: 8px; font: 12px Consolas, monospace; background: #000a; padding: 4px 8px; border-radius: 6px; white-space: pre; }

/* tela dividida: HUD de cada celula (item, posicao, volta, pontos) */
body.split #hud .lap { display: none; }
body.split #hud .kill { top: auto; bottom: 8px; }
#vps { position: absolute; inset: 0; }
.vp { position: absolute; overflow: hidden; border: 3px solid var(--c); border-radius: 4px; box-shadow: inset 0 0 0 1px #0008; }
.vp-top { position: absolute; top: 6px; left: 8px; right: 8px; display: flex; justify-content: space-between; font: italic 900 14px var(--font); color: #fff; -webkit-text-stroke: 3px #0a1a44; paint-order: stroke fill; }
.vp-name { color: var(--c); max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vp-rank { position: absolute; right: 12px; bottom: 6px; font: italic 900 clamp(26px, 6vh, 64px) var(--font); color: #ffe27a; -webkit-text-stroke: 4px #0a1a44; paint-order: stroke fill; line-height: 1; }
.vp-rank.dead { color: #ff6b6b; }
.vp-item { position: absolute; left: 10px; bottom: 8px; width: clamp(34px, 8vh, 64px); height: clamp(34px, 8vh, 64px); display: flex; align-items: center; justify-content: center; font-size: clamp(18px, 4.5vh, 34px); border-radius: 12px; background: #0a1a4488; border: 3px solid #0a1a44; }
.vp-item.on { background: linear-gradient(rgba(70,150,235,.9), rgba(24,88,170,.9)); }
.vp-pts { position: absolute; left: 10px; top: 28px; font: 900 10px var(--font); letter-spacing: 1px; color: #ffe94a; text-shadow: 0 1px 0 #0a1a44; }
.vp-warn { position: absolute; left: 0; right: 0; top: 40%; text-align: center; font: italic 900 clamp(14px, 3vh, 26px) var(--font); color: #ff5a5a; -webkit-text-stroke: 3px #300; paint-order: stroke fill; animation: pulse .35s infinite alternate; display: none; }
#toast { position: fixed; top: calc(14px + var(--safe-t)); left: 50%; transform: translate(-50%, -20px); opacity: 0; transition: opacity .2s, transform .2s; background: var(--panel); border: 2px solid var(--accent); border-radius: 12px; padding: 8px 20px; font-weight: 800; font-size: 18px; z-index: 60; pointer-events: none; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }

/* semaforo da largada (estilo do original) */
#banner .tl { position: absolute; top: calc(92px + var(--safe-t)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 4px; animation: tlpop .3s ease-out; }
#banner .tl .lamps { display: flex; flex-direction: column; gap: 10px; padding: 10px 12px; background: linear-gradient(#f7892b, #d9560f); border: 5px solid #8f3508; border-radius: 22px; filter: drop-shadow(0 6px 0 #0008); }
#banner .tl .lamps i { width: 46px; height: 46px; border-radius: 50%; background: #15161c; box-shadow: inset 0 0 0 4px #0d0e12; }
#banner .tl .lamps i.on.r { background: radial-gradient(#ff9a9a, #ff2a2a 60%); box-shadow: 0 0 34px 10px #ff2a2aaa, inset 0 0 0 4px #7a0d0d; }
#banner .tl .lamps i.on.y { background: radial-gradient(#fff0a8, #ffb020 60%); box-shadow: 0 0 34px 10px #ffb020aa, inset 0 0 0 4px #7a5200; }
#banner .tl .lamps i.on.g { background: radial-gradient(#c8ffd8, #35ff6a 60%); box-shadow: 0 0 40px 14px #35ff6acc, inset 0 0 0 4px #0c6b2a; }
#banner .tl .num { font: italic 900 54px var(--font); color: #fff; -webkit-text-stroke: 8px #0a1a44; paint-order: stroke fill; }

@media (max-height: 560px) {
  .card-p { height: 24px; min-width: 110px; }
  .card-p .av { width: 24px; font-size: 12px; }
  #hud .lap { min-width: 120px; padding: 2px 20px 3px; }
  #hud .lap b { font-size: 16px; -webkit-text-stroke-width: 2px; }
  #hud .kill { font-size: 12px; }
}

/* seletor de pistas: grade que rola, com o rodape sempre visivel */
.scr.tracks { justify-content: flex-start; overflow: hidden; }
.tgrid { flex: 1 1 0; min-height: 0; width: 100%; max-width: 1400px; overflow-y: auto; display: flex; flex-wrap: wrap; justify-content: center; gap: clamp(6px, 1.2vw, 12px); padding: 8px 6px; align-content: start; scrollbar-width: thin; }
.tbreak { flex: 0 0 100%; height: 0; } /* "Em breve" vai para uma segunda linha, deixando as pistas jogaveis centralizadas */
.tcard { width: clamp(112px, 15vw, 190px); flex: 0 0 auto; position: relative; border-radius: 14px; background: var(--panel); border: 3px solid #ffffff20; padding: 6px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; text-align: left; min-width: 0; }
.tcard img { width: 100%; aspect-ratio: 5 / 3; object-fit: contain; border-radius: 9px; background: #0b0e16; display: block; }
.tcard .tn { font-weight: 900; font-size: clamp(11px, 2vh, 15px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tcard .ts { font-size: clamp(9px, 1.7vh, 12px); color: #aab6d3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tcard.sel { border-color: var(--accent); box-shadow: 0 0 22px #ffd60a66; background: #1a2a4aee; }
.tcard.lock { opacity: .4; cursor: default; }
.tcard .tl { position: absolute; top: 8px; right: 8px; background: #000b; border-radius: 6px; padding: 1px 6px; font-size: 11px; font-weight: 800; }
.tfoot { flex: none; display: flex; align-items: center; justify-content: center; gap: clamp(8px, 2vw, 20px); flex-wrap: wrap; width: 100%; }
.tinfo { flex: none; max-width: 100%; font-size: clamp(12px, 2.4vh, 17px); color: #c7d0e6; }
.tinfo b { color: #fff; font-size: clamp(14px, 3vh, 22px); }

/* HUD da corrida: sem barra de pontos, com posicao, volta e tempo */
#hud.race .card-p .bar { display: none; }
#hud.race .card-p { height: 22px; }

/* telas baixas (notebook pequeno, janela, TV com overscan): compacta o lobby para tudo caber sem rolar */
@media (max-height: 600px) {
  .scr { gap: 6px; }
  .scr > .logo { font-size: min(5vw, 8vh) !important; margin: 0; }
  .lobby { gap: 18px; flex-wrap: nowrap; }
  .lobby > div { gap: 5px !important; }
  .qr svg, .qr img, .qr canvas { width: min(20vh, 22vw, 200px); height: min(20vh, 22vw, 200px); }
  .code { font-size: min(7vw, 9vh, 60px); letter-spacing: 8px; }
  .slot { padding: 3px 10px; min-height: 26px; border-width: 2px; }
  .slot .dot { width: 14px; height: 14px; }
  .lobby .btn { padding-top: 4px !important; padding-bottom: 4px !important; }
  .hint { line-height: 1.15; }
}
.tcard.folder { border-color: #ffd60a66; background: #1d2a44; }
.logo img { display: block; margin: 0 auto 1vh; height: min(24vh, 220px); width: auto; transform: skew(6deg); filter: drop-shadow(0 6px 10px #0008); }
