/* =====================================================================================================
   APEX GP v6.2 polish layer (loaded last). Compact, professional sizing for phones and desktop:
   small corner brand chip, slim controls, scrollable modals, no overlapping HUD, calm podium card.
   Specificity is raised with `html body` so it wins over the older rules without !important.
   ===================================================================================================== */
:root { --pad: clamp(6px, 1.6vmin, 14px); --ctl: clamp(30px, 7.5vmin, 38px); --fs: clamp(11px, 2.5vmin, 13.5px); }

/* ---------- loader: video background, thin progress, tap to start ---------- */
html body #loader .ld-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #07080b; }
html body #loader .ld-slides { display: none; }
html body #loader .ld-shade { background: linear-gradient(0deg, rgba(5,6,9,0.88) 0%, rgba(5,6,9,0.25) 42%, rgba(5,6,9,0.45) 100%); }
html body #loader .ld-ui { padding: calc(var(--safe-t) + var(--pad)) calc(var(--safe-r) + 18px) calc(var(--safe-b) + 14px) calc(var(--safe-l) + 18px); display: flex; flex-direction: column; justify-content: space-between; }
.ld-brand { display: flex; align-items: center; gap: 6px; width: max-content; padding: 5px 13px 5px 8px; border-radius: 12px; font-size: clamp(15px, 3.4vmin, 22px); font-weight: 900; font-style: italic; line-height: 1; background: rgba(8,10,14,0.5); border: 1px solid rgba(255,255,255,0.12); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
.ld-brand img { height: 1.7em; width: auto; } .ld-brand b { color: var(--accent); }
html body #loader .ld-bottom { width: min(380px, 78vw); }
html body #loader .ld-tip { font-size: clamp(10px, 2.2vmin, 12.5px); min-height: 2.5em; margin-bottom: 8px; }
html body #loader .ld-bar { height: 3px; transform: none; border-radius: 3px; background: rgba(255,255,255,0.18); }
html body #loader .ld-bar i { box-shadow: 0 0 10px var(--accent); }
html body #loader .ld-row { font-size: 10px; margin-top: 7px; }
#ldStart { width: auto; margin-top: 12px; animation: ldpulse 1.6s ease-in-out infinite; }
@keyframes ldpulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 22%, transparent), 0 8px 24px color-mix(in srgb, var(--accent) 40%, transparent); } }

/* ---------- one compact button size ---------- */
html body .cta, html body .ghost, html body .go { height: clamp(36px, 8.5vmin, 42px); padding: 0 20px; font-size: var(--fs); letter-spacing: 0.12em; border-radius: 11px; display: inline-flex; align-items: center; justify-content: center; line-height: 1; margin-top: 0; }
html body .card .cta, html body .card .ghost { width: 100%; margin-top: 8px; }
html body .seg button { height: clamp(30px, 7vmin, 34px); padding: 0 6px; font-size: var(--fs); }
html body .corner { height: clamp(30px, 7.2vmin, 36px); padding: 0 14px; font-size: clamp(10px, 2.2vmin, 12px); border-radius: 10px; letter-spacing: 0.12em; width: auto; min-width: 0; }
html body .corner .flagstrip { width: 22px; height: 12px; }
html body .sq-btn { width: var(--ctl); height: var(--ctl); border-radius: 11px; padding: 0; }
html body .sq-btn svg { width: 55%; height: 55%; }

/* ---------- header: small brand chip + player chip top-left, stats + icons top-right ---------- */
html body .v-home::before { display: none; }
html body .hdr { position: absolute; top: calc(var(--safe-t) + var(--pad)); left: calc(var(--safe-l) + var(--pad)); z-index: 4; display: flex; align-items: center; gap: 8px; max-width: calc(100% - 270px); }
html body .hdr .logo { position: static; transform: none; margin: 0; padding: 4px 12px 4px 7px; gap: 6px; font-size: clamp(14px, 3.3vmin, 20px); line-height: 1; font-weight: 900; font-style: italic; align-items: center; border-radius: 12px;
  background: rgba(8,10,14,0.55); border: 1px solid rgba(255,255,255,0.13); box-shadow: 0 6px 18px rgba(0,0,0,0.35); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); filter: none; flex: none; }
html body .hdr .logo .logo-mark { height: 1.75em; width: auto; margin: 0; }
html body .hdr .logo span { background: linear-gradient(180deg, #fff, #c4c9d1); -webkit-background-clip: text; background-clip: text; color: transparent; -webkit-text-stroke: 0; text-shadow: none; }
html body .hdr .logo b { color: var(--accent); text-shadow: none; -webkit-text-stroke: 0; }
html body .v-home .profile { position: static; display: flex; flex-direction: row; align-items: center; gap: 6px; padding: 4px 10px 4px 6px; border-radius: 12px; background: rgba(8,10,14,0.45); border: 1px solid rgba(255,255,255,0.1); min-width: 0; }
html body .v-home .profile svg { width: 20px; height: 20px; flex: none; }
html body .v-home .profile input { width: 8.5em; max-width: 26vw; font-size: clamp(11px, 2.3vmin, 12.5px); text-align: left; padding: 1px 2px; }
html body .record { top: calc(var(--safe-t) + var(--pad)); right: calc(var(--safe-r) + var(--pad) + 128px); gap: 14px; padding: 4px 14px; border-radius: 12px; background: rgba(8,10,14,0.45); border: 1px solid rgba(255,255,255,0.1); height: calc(var(--ctl) + 6px); align-items: center; }
html body .record span { font-size: 7.5px; letter-spacing: 0.14em; } html body .record b { font-size: clamp(13px, 3vmin, 17px); }
html body .pill { top: calc(var(--safe-t) + var(--pad)); right: calc(var(--safe-r) + var(--pad)); left: auto; bottom: auto; display: flex; flex-direction: row; gap: 4px; padding: 3px; width: auto; height: auto; border-radius: 13px; }
html body .pill button { width: var(--ctl); height: var(--ctl); padding: 0; border-radius: 10px; display: grid; place-items: center; }
html body .pill button svg { width: 52%; height: 52%; }

/* ---------- home: slim mode row ---------- */
html body .modes { position: absolute; left: calc(var(--safe-l) + var(--pad)); right: calc(var(--safe-r) + var(--pad)); bottom: calc(var(--safe-b) + var(--pad) + clamp(40px, 9vmin, 46px)); transform: none; width: auto; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: clamp(6px, 1.4vmin, 12px); padding: 0; }
html body .mode { width: auto; height: clamp(42px, 9.6vmin, 56px); padding: 0 12px; grid-template-columns: auto minmax(0, 1fr); column-gap: 10px; border-radius: 12px; align-items: center; }
html body .mode .mi { width: clamp(26px, 6vmin, 34px); height: clamp(26px, 6vmin, 34px); border-radius: 9px; }
html body .modes .mode span { font-size: clamp(10.5px, 2.35vmin, 14px); letter-spacing: 0.06em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
html body .mode em { font-size: clamp(8px, 1.75vmin, 10.5px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
html body .corner.left { left: calc(var(--safe-l) + var(--pad)); bottom: calc(var(--safe-b) + var(--pad)); }
html body .corner.right { right: calc(var(--safe-r) + var(--pad)); left: auto; bottom: calc(var(--safe-b) + var(--pad)); }
html body .ver { font-size: 9px; letter-spacing: 0.12em; bottom: calc(var(--safe-b) + var(--pad) + 4px); opacity: 0.55; }

/* ---------- car selection: nothing overlaps ---------- */
html body .tab { height: var(--ctl); padding: 0 14px 0 10px; font-size: 11px; left: calc(var(--safe-l) + var(--pad) + var(--ctl) + 8px); top: calc(var(--safe-t) + var(--pad)); }
html body #mBack { left: calc(var(--safe-l) + var(--pad)); top: calc(var(--safe-t) + var(--pad)); }
html body .tab span { font-size: 11px; }
html body .v-car .banner { top: calc(var(--safe-t) + var(--pad) + var(--ctl) + 12px); height: clamp(40px, 10vmin, 56px); }
html body .v-car .banner b { font-size: clamp(16px, 4.2vmin, 26px); } html body .v-car .banner .emb { font-size: clamp(9px, 2vmin, 12px); }
html body .arrow { width: var(--ctl); height: var(--ctl); top: 44%; }
html body .arrow.left { left: calc(var(--safe-l) + var(--pad)); } html body .arrow.right { right: calc(var(--safe-r) + var(--pad)); }
html body .stats-glass { width: clamp(150px, 24vmin, 200px); left: calc(var(--safe-l) + var(--pad)); bottom: calc(var(--safe-b) + var(--pad)); padding: 8px 10px; gap: 6px; border-radius: 12px; }
html body .stats-glass .stat label { font-size: 8px; margin-bottom: 2px; } html body .stats-glass .stat .t { height: 4px; }
html body .team-dots { bottom: calc(var(--safe-b) + var(--pad) + 22px); padding: 6px 10px; gap: 7px; }
html body .team-dots button { width: 14px; height: 14px; min-width: 14px; min-height: 14px; border-width: 2px; }
html body .drag-hint { bottom: calc(var(--safe-b) + var(--pad)); font-size: 8.5px; }
html body .go { position: absolute; right: calc(var(--safe-r) + var(--pad)); bottom: calc(var(--safe-b) + var(--pad)); width: auto; padding: 0 28px; }
html body .car-meta { top: calc(var(--safe-t) + var(--pad)); } html body .car-meta span { font-size: clamp(11px, 2.5vmin, 14px); } html body .car-meta b { font-size: 9px; } html body .car-meta small { font-size: 8px; }

/* ---------- modals: always fully reachable, compact ---------- */
html body .overlay { display: flex; align-items: flex-start; justify-content: center; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: calc(var(--safe-t) + 10px) 10px calc(var(--safe-b) + 10px); }
html body .overlay > .card { margin: auto; }
html body .overlay.hidden { display: none; }
html body .card { padding: clamp(12px, 3vmin, 18px) clamp(14px, 3.4vmin, 20px); border-radius: 16px; min-width: min(320px, 92vw); }
html body .card.wide { max-height: none; width: min(640px, 96%); }
html body .card h2 { font-size: 11.5px; letter-spacing: 0.24em; margin: 0 0 10px; opacity: 0.9; }
html body .field { margin-bottom: 10px; } html body .field > span { font-size: 9.5px; margin-bottom: 5px; }
html body #settings .card { max-height: none; padding: 12px 16px; }
html body .mp-card { max-height: none; }
html body .mp-join input { height: 38px; font-size: 18px; padding: 0 10px; border-radius: 11px; }
html body .mp-join .cta { width: 36%; margin: 0; }
html body .mp-top-btns .cta, html body .mp-top-btns .ghost { height: 34px; padding: 0 14px; font-size: 11px; width: auto; margin: 0; }
html body .mp-say .ghost { height: 34px; width: auto; margin: 0; padding: 0 14px; font-size: 11px; }
html body .mp-codebox b { font-size: clamp(22px, 5vmin, 30px); }
html body .mp-err { margin: 6px 2px 4px; }

/* ---------- results card ---------- */
html body #results .card { width: min(560px, 96%); }
html body #resultRows { max-height: min(56vh, calc(100% - 120px)); overflow-y: auto; margin-bottom: 10px; padding-right: 2px; }
html body .res { grid-template-columns: 24px 4px minmax(0, 1fr) auto auto; gap: 8px; padding: 6px 10px; font-size: 12.5px; border-radius: 10px; }
html body .res .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; } html body .res .nm small { display: none; }
html body .res .tm { font-size: 11.5px; white-space: nowrap; } html body .res .fl { max-width: 84px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; }
html body .result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; } html body .result-actions .cta, html body .result-actions .ghost { margin-top: 0; }

/* ---------- podium: title card bottom-left (never over the flags), cinematic bars ---------- */
html body #podiumUi { display: block; padding: 0; }
html body #podiumUi::before, html body #podiumUi::after { content: ""; position: absolute; left: 0; right: 0; height: 0; background: #000; animation: bars 1.2s 0.2s ease-out forwards; }
html body #podiumUi::before { top: 0; } html body #podiumUi::after { bottom: 0; }
@keyframes bars { to { height: clamp(18px, 7vh, 52px); } }
html body #pCard { position: absolute; left: calc(var(--safe-l) + var(--pad) + 4px); bottom: calc(var(--safe-b) + clamp(26px, 9vh, 62px)); max-width: min(46vw, 420px); padding: 9px 16px 9px 14px; border-radius: 12px; background: rgba(8,10,14,0.58); border-left: 3px solid var(--accent); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); animation: fadeup 0.8s 1s both; text-align: left; }
@keyframes fadeup { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
html body #pTitle { font-size: clamp(17px, 4.6vmin, 28px); font-weight: 900; font-style: italic; letter-spacing: 0.02em; text-shadow: none; animation: none; line-height: 1.05; }
html body #pSub { position: static; transform: none; font-size: clamp(8.5px, 1.9vmin, 11.5px); letter-spacing: 0.14em; margin-top: 3px; opacity: 0.85; text-shadow: none; white-space: normal; }
html body #podiumUi .cta { position: absolute; right: calc(var(--safe-r) + var(--pad) + 4px); bottom: calc(var(--safe-b) + clamp(26px, 9vh, 62px)); width: auto; padding: 0 26px; }

/* ---------- phone touch controls: smaller, tidier ---------- */
body.phone { --pedW: clamp(64px, 10vw, 86px); --pedH: clamp(84px, 26vh, 108px); --brkW: clamp(74px, 12vw, 98px); --brkH: clamp(46px, 14vh, 58px); --padW: clamp(56px, 9vw, 78px); --padH: clamp(50px, 14vh, 62px); --rb: clamp(36px, 10.5vh, 44px); --rs: clamp(30px, 8.5vh, 36px); }
html body.phone #icons button { width: 30px; height: 30px; padding: 6px; }

/* ---------- chat in race ---------- */
html body #chatBtn { width: 30px; height: 30px; font-size: 14px; }
html body #chatBar .q, html body #chatBar .send { min-width: 32px; padding: 5px 9px; font-size: 12px; }

/* results: the list scrolls, the buttons stay on screen */
html body #results.overlay { align-items: center; }
html body #results .card { display: flex; flex-direction: column; max-height: calc(100dvh - 20px); }
html.force-land body #results .card { max-height: calc(var(--fh) - 20px); }
html body #results #resultRows { flex: 1 1 auto; min-height: 0; max-height: none; }
html body #results .champ, html body #results .result-actions { flex: none; }
html body #results .result-actions { margin-top: 4px; }


/* ---------- v6.5 podium panel: top banner + glowing RESULTS pill (arena look), no cinematic bars ---------- */
html body #podiumUi::before, html body #podiumUi::after { display: none; }
html body #pCard { position: absolute; left: 50%; right: auto; top: calc(var(--safe-t, 0px) + clamp(6px, 2.4vh, 18px)); bottom: auto; transform: translateX(-50%); width: max-content; max-width: min(86vw, 700px); padding: 4px clamp(26px, 7vw, 64px) 7px; border: 0; border-radius: 0; background: linear-gradient(90deg, transparent, rgba(5,7,10,0.74) 16%, rgba(5,7,10,0.74) 84%, transparent); -webkit-backdrop-filter: none; backdrop-filter: none; text-align: center; animation: pdrop 0.8s 0.8s both; pointer-events: none; }
@keyframes pdrop { from { opacity: 0; transform: translateX(-50%) translateY(-14px); } to { opacity: 1; transform: translateX(-50%); } }
html body #pTitle, html body.phone #pTitle { font-size: clamp(22px, 7.4vmin, 54px); font-weight: 900; font-style: italic; letter-spacing: 0.01em; line-height: 1; color: #fff; text-shadow: 0 2px 16px rgba(0,0,0,0.75); animation: none; }
html body #pSub, html body.phone #pSub { position: static; font-size: clamp(8.5px, 1.9vmin, 13px); font-weight: 700; letter-spacing: 0.3em; margin-top: 5px; opacity: 0.94; text-shadow: 0 1px 8px rgba(0,0,0,0.8); }
html body #pDnf { font-size: clamp(8px, 1.6vmin, 11px); font-weight: 700; letter-spacing: 0.22em; color: #ff9aa2; margin-top: 3px; text-transform: uppercase; }
html body #pDnf:empty { display: none; }
html body #podiumUi #btnPodiumNext.rbtn, html body.phone #podiumUi #btnPodiumNext.rbtn { position: absolute; left: 50%; right: auto; bottom: calc(var(--safe-b, 0px) + clamp(12px, 4.5vh, 32px)); transform: translateX(-50%); min-width: clamp(130px, 24vw, 220px); height: clamp(34px, 9vh, 48px); padding: 0 30px; border-radius: 999px; border: 2px solid #4aa8ff; background: linear-gradient(180deg, rgba(14,36,72,0.92), rgba(4,12,28,0.94)); color: #fff; font-weight: 800; font-size: clamp(11px, 2.6vmin, 17px); letter-spacing: 0.16em; text-transform: uppercase; box-shadow: 0 0 18px rgba(74,168,255,0.6), inset 0 0 14px rgba(74,168,255,0.3); pointer-events: auto; cursor: pointer; animation: pillin 0.8s 1.3s both; }
@keyframes pillin { from { opacity: 0; transform: translateX(-50%) translateY(12px); } to { opacity: 1; transform: translateX(-50%); } }
html body #btnPodiumNext.rbtn { top: auto; }
html body #btnPodiumNext.rbtn::before, html body #btnPodiumNext.rbtn::after { content: ""; position: absolute; top: 50%; width: 38vw; height: 2px; margin-top: -1px; pointer-events: none; }
html body #btnPodiumNext.rbtn::before { right: 100%; margin-right: 4px; background: linear-gradient(270deg, #4aa8ff, rgba(74,168,255,0)); }
html body #btnPodiumNext.rbtn::after { left: 100%; margin-left: 4px; background: linear-gradient(90deg, #4aa8ff, rgba(74,168,255,0)); }
html body #btnPodiumNext.rbtn:active { filter: brightness(1.3); }
html body #pWait { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-b, 0px) + clamp(56px, 16vh, 90px)); padding: 6px 16px; border-radius: 999px; background: rgba(5,7,10,0.7); border: 1px solid rgba(74,168,255,0.5); font-size: clamp(10px, 2.1vmin, 13px); font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; white-space: nowrap; }

/* ---------- v6.5 online chat: bigger tap targets, unread badge, no iOS zoom on focus ---------- */
html body #chatBtn { width: 38px; height: 38px; font-size: 17px; }
html body #chatBtn[data-n]:not([data-n=""])::after { content: attr(data-n); position: absolute; top: -4px; right: -4px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: #ff3b4e; color: #fff; font: 800 10px/16px var(--font, sans-serif); text-align: center; box-sizing: border-box; }
html body #chatBtn { position: fixed; }
html body #chatBar input, html body .mp-say input { font-size: 16px; }
html body #chatBar .q, html body #chatBar .send { min-height: 36px; min-width: 40px; font-size: 14px; }
html body #chatBar { max-width: min(94vw, 560px); }
html body #chatFeed { max-width: min(46vw, 320px); }
html body .mp-chat { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.mp-p small .png { color: #7fe0a0; font-weight: 700; }

/* ---------- v6.5 online lobby on narrow phones: code on top, three equal buttons under it (nothing cut off) ---------- */
@media (max-width: 520px) {
  html body .mp-top { flex-direction: column; align-items: stretch; gap: 8px; }
  html body .mp-top-btns { display: grid; grid-template-columns: 1fr 1fr 1.7fr; gap: 6px; }
  html body .mp-top-btns .cta, html body .mp-top-btns .ghost { min-width: 0; width: 100%; padding: 0 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  html body .mp-codebox { text-align: center; }
}
