@font-face { font-family: Cairo; font-weight: 500; font-display: swap; src: url(assets/fonts/cairo-arabic-500-normal.woff2) format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: Cairo; font-weight: 700; font-display: swap; src: url(assets/fonts/cairo-arabic-700-normal.woff2) format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: Cairo; font-weight: 900; font-display: swap; src: url(assets/fonts/cairo-arabic-900-normal.woff2) format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: Cairo; font-weight: 500; font-display: swap; src: url(assets/fonts/cairo-latin-500-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+2000-206F, U+2190-21FF, U+25A0-25FF; }
@font-face { font-family: Cairo; font-weight: 700; font-display: swap; src: url(assets/fonts/cairo-latin-700-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+2000-206F, U+2190-21FF, U+25A0-25FF; }
@font-face { font-family: Cairo; font-weight: 900; font-display: swap; src: url(assets/fonts/cairo-latin-900-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+2000-206F, U+2190-21FF, U+25A0-25FF; }

:root {
  --gold: #f3c560; --gold2: #ffdf8a; --ink: #fff8ea; --glass: rgba(22, 14, 8, .52); --glass2: rgba(22, 14, 8, .72);
  --green: #2fd27a; --red: #ff5148; --amber: #ffb02e;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px); --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
  --jb: min(34vw, 23vh, 150px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1a0f08; color: var(--ink); font-family: Cairo, system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: none; overscroll-behavior: none; }
canvas#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
button { font-family: inherit; color: inherit; border: 0; cursor: pointer; touch-action: manipulation; }
.hidden { display: none !important; }
svg { display: block; }

/* ---------------------------------------------------------------- loading */
#loading { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: radial-gradient(ellipse at 50% 60%, #6b3a17, #1a0f08 70%); transition: opacity .6s; }
#loading.done { opacity: 0; pointer-events: none; }
.ld-logo { font-weight: 900; font-size: 44px; color: var(--gold2); text-shadow: 0 4px 30px rgba(255, 170, 60, .5); }
.ld-bar { width: 180px; height: 4px; border-radius: 4px; background: rgba(255, 255, 255, .12); overflow: hidden; }
.ld-bar i { display: block; height: 100%; width: 40%; background: var(--gold); border-radius: 4px; animation: ld 1.1s ease-in-out infinite; }
@keyframes ld { 0% { transform: translateX(-120%); } 100% { transform: translateX(320%); } }

/* ---------------------------------------------------------------- screens */
.screen { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  padding: calc(16px + var(--sat)) calc(16px + var(--sar)) calc(16px + var(--sab)) calc(16px + var(--sal)); }
#title { background: linear-gradient(180deg, rgba(20, 10, 4, .15) 0%, rgba(20, 10, 4, 0) 35%, rgba(20, 10, 4, .55) 75%, rgba(20, 10, 4, .85) 100%); align-items: flex-end; }
.title-inner { width: min(560px, 100%); display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.brand h1 { margin: 0; font-size: clamp(46px, 13vw, 84px); line-height: 1.02; font-weight: 900; color: #fff4d6;
  text-shadow: 0 2px 0 #b06a1e, 0 6px 26px rgba(0, 0, 0, .5), 0 0 60px rgba(255, 170, 60, .35); }
.brand h2 { margin: 2px 0 0; font-size: clamp(16px, 4.4vw, 22px); letter-spacing: .38em; font-weight: 900; color: var(--gold); }
html[lang=en] .brand h2 { letter-spacing: .1em; }
.tagline { margin: 0 0 4px; font-size: 15px; font-weight: 700; opacity: .92; max-width: 420px; text-shadow: 0 1px 8px rgba(0, 0, 0, .6); }
.modes { display: flex; gap: 12px; width: 100%; }
.mode { flex: 1; min-height: 96px; padding: 14px 12px; border-radius: 22px; text-align: center; display: flex; flex-direction: column; gap: 4px; align-items: center; justify-content: center;
  background: linear-gradient(180deg, #ffd977, #eaa53a); color: #2b1606; box-shadow: 0 10px 30px rgba(0, 0, 0, .35), inset 0 -3px 0 rgba(0, 0, 0, .15); transition: transform .12s; }
.mode.alt { background: linear-gradient(180deg, rgba(255, 248, 234, .2), rgba(255, 248, 234, .08)); color: var(--ink); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border: 1px solid rgba(255, 255, 255, .22); }
.mode:active { transform: scale(.97); }
.mode b { font-size: 24px; font-weight: 900; line-height: 1.1; }
.mode span { font-size: 13px; font-weight: 700; line-height: 1.35; opacity: .85; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.pill { padding: 10px 20px; border-radius: 999px; font-size: 15px; font-weight: 800; background: rgba(255, 248, 234, .14); border: 1px solid rgba(255, 255, 255, .2);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.pill.solid { background: linear-gradient(180deg, #ffd977, #eaa53a); color: #2b1606; border: 0; }
.pill.ghost { background: transparent; }
.pill.big { width: 100%; padding: 14px 20px; font-size: 18px; }
.row .pill.big { width: auto; flex: 1; }
.credit { margin: 4px 0 0; font-size: 11px; opacity: .55; }

/* ---------------------------------------------------------------- HUD */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#topbar { position: absolute; top: calc(8px + var(--sat)); left: calc(10px + var(--sal)); right: calc(10px + var(--sar)); display: flex; gap: 8px; align-items: stretch; }
.card { background: var(--glass); border: 1px solid rgba(255, 255, 255, .14); border-radius: 16px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 4px 18px rgba(0, 0, 0, .25); }
.card.pos { padding: 4px 14px 6px; display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 78px; }
.card small { font-size: 11px; font-weight: 800; opacity: .75; letter-spacing: .04em; }
.card.pos b { font-size: 34px; font-weight: 900; line-height: 1; color: var(--gold2); direction: ltr; }
.card.pos b i { font-style: normal; font-size: 16px; opacity: .7; }
.card.prog { flex: 1; padding: 8px 14px 4px; display: flex; flex-direction: column; justify-content: center; gap: 2px; min-width: 0; }
#h-prog { position: relative; height: 22px; }
#h-prog .rail { position: absolute; left: 0; right: 0; top: 9px; height: 4px; border-radius: 4px; background: rgba(255, 255, 255, .22); }
#h-prog .rail::after { content: ''; position: absolute; top: -5px; bottom: -5px; width: 3px; border-radius: 2px; background: repeating-linear-gradient(#fff 0 3px, #111 3px 6px); }
html[dir=ltr] #h-prog .rail::after { right: 0; } html[dir=rtl] #h-prog .rail::after { left: 0; }
#h-prog .lapmark { position: absolute; top: 4px; width: 2px; height: 14px; background: rgba(255, 255, 255, .45); border-radius: 2px; }
#h-prog .dot { position: absolute; top: 4px; width: 14px; height: 14px; margin-inline-start: -7px; border-radius: 50%; border: 2px solid rgba(0, 0, 0, .45); }
#h-prog .dot.me { width: 22px; height: 22px; top: 0; margin-inline-start: -11px; border: 3px solid #fff; z-index: 2; box-shadow: 0 0 12px rgba(255, 255, 255, .6); }
#h-lap { font-size: 12px; font-weight: 800; text-align: center; opacity: .9; }
.card.icon { width: 52px; pointer-events: auto; display: flex; align-items: center; justify-content: center; }
.card.icon svg { width: 24px; height: 24px; fill: var(--ink); }

#banner { position: absolute; left: 0; right: 0; top: 22%; text-align: center; font-weight: 900; font-size: clamp(64px, 20vw, 140px); line-height: 1;
  color: #fff4d6; text-shadow: 0 4px 0 #b06a1e, 0 10px 40px rgba(0, 0, 0, .5); opacity: 0; }
#banner.small { font-size: clamp(26px, 7vw, 46px); }
#banner.pop { animation: pop 1.1s cubic-bezier(.2, .9, .3, 1.2) forwards; }
#banner.hold { animation: pophold .35s cubic-bezier(.2, .9, .3, 1.2) forwards; }
@keyframes pop { 0% { opacity: 0; transform: scale(2.2); } 18% { opacity: 1; transform: scale(1); } 75% { opacity: 1; } 100% { opacity: 0; transform: scale(.92); } }
@keyframes pophold { 0% { opacity: 0; transform: scale(1.8); } 100% { opacity: 1; transform: scale(1); } }
#warn { position: absolute; top: calc(128px + var(--sat)); left: 50%; transform: translateX(-50%); padding: 8px 18px; border-radius: 999px; font-weight: 900; font-size: 15px;
  background: rgba(200, 30, 30, .82); white-space: nowrap; opacity: 0; transition: opacity .2s; max-width: 92vw; overflow: hidden; text-overflow: ellipsis; }
#warn.on { opacity: 1; animation: blink 1s infinite; }
#warn.info { background: rgba(14, 122, 79, .85); animation: none; }
@keyframes blink { 50% { opacity: .65; } }

/* zones */
.zone { position: absolute; pointer-events: auto; touch-action: none; }
#zone-j { left: 0; right: 0; bottom: 0; height: 50%; }
#zone-d { display: none; }
#jwrap { position: absolute; left: 50%; bottom: calc(26px + var(--sab)); width: var(--jb); height: var(--jb); transform: translateX(-50%); pointer-events: none; }
#jbtn { position: absolute; inset: 0; border-radius: 50%; background: radial-gradient(circle at 50% 35%, rgba(255, 230, 160, .38), rgba(60, 32, 10, .78) 70%);
  border: 3px solid rgba(255, 223, 138, .85); box-shadow: 0 10px 30px rgba(0, 0, 0, .45), inset 0 0 22px rgba(255, 200, 90, .25); transition: transform .08s; }
#jbtn.hit { transform: scale(.92); }
#jbtn.hot { border-color: #fff; box-shadow: 0 0 34px rgba(255, 215, 110, .9), inset 0 0 26px rgba(255, 220, 120, .5); }
#jbtn.dead { filter: grayscale(.8) brightness(.7); }
#jbtn .energy { position: absolute; inset: -12px; width: calc(100% + 24px); height: calc(100% + 24px); transform: rotate(-90deg); }
#jbtn .energy circle { fill: none; stroke-width: 5; stroke-linecap: round; }
#jbtn .energy .bg { stroke: rgba(255, 255, 255, .15); }
#jbtn .energy .fg { stroke: var(--green); stroke-dasharray: 289; stroke-dashoffset: 0; transition: stroke .3s; }
#jbtn .energy .fg.low { stroke: var(--red); }
.jin { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; }
.jin b { font-size: calc(var(--jb) * .3); font-weight: 900; direction: ltr; }
.jin small { font-size: 12px; font-weight: 800; opacity: .8; margin-top: 2px; }
.jin em { font-style: normal; font-size: 13px; font-weight: 900; color: var(--gold2); margin-top: 6px; letter-spacing: .06em; }
#ring { position: absolute; inset: 0; border-radius: 50%; border: 6px solid var(--gold); box-shadow: 0 0 18px rgba(255, 200, 80, .8); will-change: transform, opacity; }
#ring.dead { border-color: rgba(255, 255, 255, .25); box-shadow: none; }
#judge { position: absolute; left: 0; right: 0; bottom: calc(var(--jb) + 56px + var(--sab)); text-align: center; font-weight: 900; font-size: 34px; opacity: 0;
  text-shadow: 0 3px 0 rgba(0, 0, 0, .35), 0 6px 20px rgba(0, 0, 0, .4); pointer-events: none; }
#judge.show { animation: judge .6s ease-out forwards; }
#judge.perfect { color: var(--gold2); font-size: 42px; } #judge.good { color: #b8ffcf; } #judge.miss, #judge.early, #judge.late { color: #ffd0c8; } #judge.over, #judge.tired, #judge.nosignal { color: #ff8a80; }
@keyframes judge { 0% { opacity: 0; transform: translateY(14px) scale(.8); } 15% { opacity: 1; transform: translateY(0) scale(1.08); } 70% { opacity: 1; } 100% { opacity: 0; transform: translateY(-16px); } }

/* driver pad (2 players) */
body.coop #zone-d { display: block; left: 0; width: 50%; bottom: 0; height: 52%; }
body.coop #zone-j { left: 50%; width: 50%; right: 0; height: 52%; }
#sigwrap { position: absolute; top: calc(74px + var(--sat)); left: 50%; transform: translateX(-50%); width: min(300px, 70vw); display: flex; flex-direction: column; align-items: center; gap: 5px; pointer-events: none; }
#sig { display: flex; align-items: center; gap: 8px; width: 100%; }
.siglbl { font-size: 12px; font-weight: 900; opacity: .9; white-space: nowrap; text-shadow: 0 1px 4px rgba(0,0,0,.6); }
.sigbar { position: relative; flex: 1; height: 12px; border-radius: 8px; background: rgba(0, 0, 0, .45); border: 1px solid rgba(255, 255, 255, .2); overflow: hidden; }
.sigbar i { position: absolute; inset-inline-start: 0; top: 0; bottom: 0; width: 100%; background: var(--green); border-radius: 8px; transition: background .3s; }
.sigrow { display: flex; gap: 6px; align-items: center; justify-content: center; flex-wrap: wrap; }
#h-gap { font-size: 13px; font-weight: 900; padding: 2px 10px; border-radius: 999px; background: var(--glass2); white-space: nowrap; }
.chip { pointer-events: auto; font-size: 13px; font-weight: 900; padding: 6px 12px; min-height: 32px; border-radius: 999px; background: rgba(28, 16, 8, .78); border: 1.5px solid var(--gold2); color: #fff4d6; white-space: nowrap; }
body.coop .chip { display: none; }
body.tutorial #sigwrap { display: none; }
.zlabel { position: absolute; top: 0; left: 50%; transform: translateX(-50%); font-size: 13px; font-weight: 900; padding: 4px 12px; border-radius: 999px; background: rgba(0,0,0,.5); border: 1px solid rgba(255,255,255,.22); white-space: nowrap; pointer-events: none; display: none; }
body.coop .zlabel, body.manual #zone-d .zlabel { display: block; }
#zone-j .zlabel { top: auto; bottom: calc(var(--jb) + 46px + var(--sab)); }
.jhint { position: absolute; left: 50%; bottom: -24px; transform: translateX(-50%); font-size: 12px; font-weight: 900; white-space: nowrap; color: #fff4d6; text-shadow: 0 1px 4px rgba(0,0,0,.8); }
body.coop .jhint { display: none; }
#rotate-hint { display: none; position: absolute; top: calc(140px + var(--sat)); left: 50%; transform: translateX(-50%); padding: 6px 14px; border-radius: 999px; background: rgba(0,0,0,.55); font-size: 13px; font-weight: 800; white-space: nowrap; pointer-events: none; animation: fadeout 7s forwards; }
@media (orientation: portrait) { body.coop #rotate-hint { display: block; } }
@keyframes fadeout { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }
body.manual #zone-d { display: block; left: 0; width: 50%; bottom: 0; height: 52%; }
body.manual #zone-j { left: 50%; width: 50%; right: 0; height: 52%; }
.dpad { position: absolute; left: calc(10px + var(--sal)); right: 6px; bottom: calc(12px + var(--sab)); display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 58px 1fr; gap: 8px; height: calc(100% - 44px); max-height: 210px; max-width: 300px; direction: ltr; }
.db { border-radius: 20px; background: rgba(20, 12, 6, .38); border: 2px solid rgba(255, 255, 255, .25); font-weight: 900; font-size: 18px; display: flex; align-items: center; justify-content: center; touch-action: none; }
.db svg { width: 30px; height: 30px; fill: none; stroke: var(--ink); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.db.down { background: rgba(255, 223, 138, .45); border-color: var(--gold2); transform: scale(.97); }
.db.gas { background: linear-gradient(180deg, rgba(47, 210, 122, .55), rgba(20, 90, 50, .7)); }
.db.brake { background: linear-gradient(180deg, rgba(255, 81, 72, .5), rgba(110, 20, 15, .7)); }
.db.gas.down, .db.brake.down { filter: brightness(1.35); }
body.coop #jwrap, body.manual #jwrap { bottom: calc(40px + var(--sab)); }
body.coop #judge { bottom: calc(var(--jb) + 66px + var(--sab)); }

/* landscape: put the jockey button under the right thumb */
@media (orientation: landscape) {
  :root { --jb: min(26vh, 20vw, 150px); }
  #zone-j { height: 62%; }
  body:not(.coop):not(.manual) #jwrap { left: auto; right: calc(30px + var(--sar)); transform: none; }
  body:not(.coop):not(.manual) #judge { left: auto; right: calc(14px + var(--sar)); width: calc(var(--jb) + 60px); }
  #banner { top: 18%; }
  body.coop #zone-d, body.coop #zone-j, body.manual #zone-d, body.manual #zone-j { height: 64%; }
  .dpad { max-height: 170px; grid-template-rows: 52px 1fr; max-width: 280px; }
  #sigwrap { top: calc(70px + var(--sat)); }
  .card.pos b { font-size: 28px; }
}

#fx-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }

/* ---------------------------------------------------------------- tutorial */
#tut { position: fixed; inset: 0; z-index: 15; pointer-events: none; }
#tut-spot { position: absolute; border-radius: 50%; box-shadow: 0 0 0 200vmax rgba(10, 5, 2, .58); transition: width .4s, height .4s, border-radius .4s, opacity .4s, left .12s linear, top .12s linear; border: 3px solid var(--gold2); }
#tut-arrow { position: absolute; width: 0; height: 0; border-left: 18px solid transparent; border-right: 18px solid transparent; border-top: 26px solid var(--gold2);
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, .5)); animation: bob .8s ease-in-out infinite alternate; transition: left .45s, top .45s; }
@keyframes bob { to { transform: translateY(10px); } }
.tut-card { position: absolute; left: 50%; transform: translateX(-50%); top: calc(82px + var(--sat)); width: min(440px, calc(100% - 24px)); pointer-events: auto;
  background: rgba(28, 16, 8, .9); border: 1px solid rgba(255, 223, 138, .35); border-radius: 22px; padding: 14px 18px 14px; box-shadow: 0 16px 40px rgba(0, 0, 0, .45); }
.tut-step { font-size: 12px; font-weight: 900; color: var(--gold); letter-spacing: .08em; }
.tut-card h3 { margin: 2px 0 4px; font-size: 22px; font-weight: 900; color: #fff4d6; }
.tut-card p { margin: 0; font-size: 15px; font-weight: 700; line-height: 1.5; opacity: .95; }
#tut-goal { margin-top: 8px; font-size: 16px; font-weight: 900; color: var(--gold2); min-height: 0; }
#tut-goal:empty { display: none; }
.tut-btns { display: flex; justify-content: space-between; gap: 10px; margin-top: 12px; }
.tut-btns .pill { padding: 9px 18px; }
@media (orientation: landscape) { .tut-card { left: calc(12px + var(--sal)); transform: none; top: calc(76px + var(--sat)); width: min(420px, 52vw); } html[dir=rtl] .tut-card { left: auto; right: calc(12px + var(--sar)); } }

/* ---------------------------------------------------------------- pause / finish */
#pause, #finish { background: rgba(14, 8, 4, .5); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.card-lg { width: min(440px, 100%); max-height: 100%; overflow: auto; background: rgba(28, 16, 8, .92); border: 1px solid rgba(255, 223, 138, .3); border-radius: 26px; padding: 20px;
  display: flex; flex-direction: column; gap: 12px; align-items: stretch; text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, .5); touch-action: pan-y; }
.card-lg h3 { margin: 0 0 4px; font-size: 26px; font-weight: 900; }
.place { display: flex; align-items: baseline; justify-content: center; gap: 12px; }
.place b { font-size: 76px; font-weight: 900; line-height: 1; color: var(--gold2); text-shadow: 0 4px 0 #8a5216; }
.place span { font-size: 28px; font-weight: 900; }
#f-msg { margin: 0; font-size: 17px; font-weight: 800; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stats div { background: rgba(255, 255, 255, .07); border-radius: 14px; padding: 8px; display: flex; flex-direction: column; }
.stats small { font-size: 12px; font-weight: 800; opacity: .7; } .stats b { font-size: 20px; font-weight: 900; direction: ltr; }
body:not(.coop):not(.manual) .coop-only { display: none !important; }
#f-stand { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; }
#f-stand li { display: flex; align-items: center; gap: 10px; padding: 6px 12px; border-radius: 12px; background: rgba(255, 255, 255, .05); font-weight: 800; font-size: 15px; }
#f-stand li.me { background: rgba(255, 223, 138, .2); color: var(--gold2); }
#f-stand .sw { width: 14px; height: 14px; border-radius: 4px; flex: none; }
#f-stand .nm { flex: 1; text-align: start; } #f-stand .tm { direction: ltr; opacity: .85; } #f-stand .tm.racing { direction: inherit; opacity: .6; }
.finish-card.reveal { animation: reveal .6s cubic-bezier(.2, .9, .3, 1.1); }
@keyframes reveal { from { opacity: 0; transform: translateY(30px) scale(.96); } }

#dbg { position: fixed; left: 4px; right: 4px; top: 70px; z-index: 99; margin: 0; padding: 6px; font: 10px/1.3 monospace; color: #ff0; background: rgba(0, 0, 0, .6); white-space: pre-wrap; pointer-events: none; }

body.tutorial #topbar { visibility: hidden; }

#judge.hold { opacity: 1 !important; animation: none !important; }

/* results in short landscape screens: two columns so the buttons are always visible */
@media (orientation: landscape) and (max-height: 820px) {
  #finish { padding: calc(8px + var(--sat)) calc(10px + var(--sar)) calc(8px + var(--sab)) calc(10px + var(--sal)); }
  .finish-card { width: min(820px, 100%); display: grid; grid-template-columns: 1.15fr 1fr; grid-template-areas: "place stand" "msg stand" "stats stand" "stats btns"; gap: 8px 16px; padding: 14px 18px; align-content: start; }
  .finish-card .place { grid-area: place; } .finish-card #f-msg { grid-area: msg; }
  .finish-card .stats { grid-area: stats; grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .finish-card .stats div { padding: 6px; } .finish-card .stats b { font-size: 17px; }
  .finish-card #f-stand { grid-area: stand; gap: 3px; } .finish-card #f-stand li { padding: 4px 10px; font-size: 13px; }
  .finish-card .row { grid-area: btns; align-self: end; }
  .finish-card .row .pill.big { padding-top: 10px; padding-bottom: 10px; min-height: 0; font-size: 16px; }
  .place b { font-size: 54px; } .place span { font-size: 22px; } #f-msg { font-size: 15px; }
}

/* title on short landscape phones: everything fits above the fold */
@media (orientation: landscape) and (max-height: 500px) {
  #title { padding-top: calc(8px + var(--sat)); padding-bottom: calc(8px + var(--sab)); }
  .title-inner { gap: 7px; width: min(620px, 100%); }
  .brand h1 { font-size: clamp(34px, 11vh, 52px); }
  .brand h2 { font-size: 14px; }
  .tagline { font-size: 13px; margin: 0; }
  .mode { min-height: 72px; padding: 8px 12px; }
  .mode b { font-size: 20px; }
  .mode span { font-size: 12px; }
  .pill { padding: 7px 16px; }
  .credit { margin: 0; }
}
@media (orientation: landscape) {
  #zone-d .zlabel { top: auto; bottom: calc(190px + var(--sab)); left: calc(150px + var(--sal)); }
}

/* ================================================================ v3: commentary, name tags, standings, owner setup, podium */
input { font-family: inherit; -webkit-user-select: text; user-select: text; touch-action: manipulation; }
body.solo:not(.manual) #h-gap { display: none; }
@media (orientation: portrait) { #banner { top: 34%; } }

/* live commentary bubble */
#comm { position: fixed; z-index: 12; left: 50%; top: calc(136px + var(--sat)); transform: translateX(-50%); width: min(560px, calc(100% - 20px)); pointer-events: none; }
#comm .comm-in { position: relative; background: linear-gradient(180deg, rgba(16, 70, 46, .9), rgba(10, 44, 30, .9)); border: 1.5px solid rgba(255, 223, 138, .55); border-radius: 18px;
  padding: 6px 14px 8px; box-shadow: 0 8px 26px rgba(0, 0, 0, .35); }
#comm .comm-in::after { content: ''; position: absolute; bottom: -9px; inset-inline-start: 26px; border: 9px solid transparent; border-top-color: rgba(10, 44, 30, .92); border-bottom: 0; }
.comm-head { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 900; color: var(--gold2); letter-spacing: .04em; }
.comm-head svg { width: 15px; height: 15px; fill: none; stroke: var(--gold2); stroke-width: 2; stroke-linecap: round; }
.comm-head .live { width: 7px; height: 7px; border-radius: 50%; background: #ff4d42; box-shadow: 0 0 8px #ff4d42; animation: blink 1s infinite; }
#comm-txt { margin: 1px 0 0; font-size: 14.5px; font-weight: 800; line-height: 1.45; color: #fffaf0; text-shadow: 0 1px 4px rgba(0, 0, 0, .5); }
#comm-txt b { color: var(--gold2); font-weight: 900; unicode-bidi: isolate; }
#comm.pop { animation: commIn .45s cubic-bezier(.2, .9, .3, 1.25) both; }
#comm.hot .comm-in { background: linear-gradient(180deg, rgba(150, 92, 18, .94), rgba(96, 52, 8, .94)); border-color: #ffe7a0; }
#comm.hot .comm-in::after { border-top-color: rgba(96, 52, 8, .94); }
#comm.hot #comm-txt { font-size: 17px; }
#comm.out { opacity: 0; transform: translateX(-50%) translateY(-10px); transition: opacity .5s, transform .5s; }
@keyframes commIn { 0% { opacity: 0; transform: translateX(-50%) translateY(-16px) scale(.94); } 100% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); } }

/* name tags above camels */
#tags { position: fixed; inset: 0; z-index: 9; pointer-events: none; overflow: hidden; }
.tag { position: absolute; left: 0; top: 0; display: flex; flex-direction: column; align-items: center; padding: 2px 10px 3px; border-radius: 10px; white-space: nowrap;
  background: rgba(20, 12, 6, .62); border-bottom: 3px solid var(--c, #fff); line-height: 1.15; will-change: transform; transform-origin: 50% 100%; }
.tag b { font-size: 13px; font-weight: 900; color: #fff8ea; }
.tag small { font-size: 10px; font-weight: 700; opacity: .8; }
.tag.me { background: rgba(120, 76, 14, .78); }
.tag.me b { color: var(--gold2); }

/* HUD standings */
#h-stand { position: absolute; top: calc(236px + var(--sat)); inset-inline-end: calc(8px + var(--sal)); display: flex; flex-direction: column; gap: 3px; width: min(168px, 42vw); pointer-events: none; }
.hs-r { display: flex; align-items: center; gap: 6px; padding: 3px 8px; border-radius: 10px; background: var(--glass); border: 1px solid rgba(255, 255, 255, .1); min-width: 0; }
.hs-r.me { background: rgba(120, 76, 14, .72); border-color: rgba(255, 223, 138, .6); }
.hs-r .n { font-size: 13px; font-weight: 900; color: var(--gold2); width: 12px; text-align: center; }
.hs-r .sw { width: 9px; height: 22px; border-radius: 3px; flex: none; }
.hs-r .nm { display: flex; flex-direction: column; min-width: 0; line-height: 1.12; }
.hs-r .nm b, .hs-r .nm small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hs-r .nm b { font-size: 12px; font-weight: 900; } .hs-r .nm small { font-size: 10px; font-weight: 700; opacity: .75; }
body.tutorial #h-stand { display: none; }

@media (orientation: landscape) {
  #sigwrap { width: min(480px, 52vw); flex-direction: row; gap: 8px; top: calc(72px + var(--sat)); }
  #sig { flex: 1; min-width: 120px; }
  .sigrow { flex-wrap: nowrap; }
  #comm { top: calc(112px + var(--sat)); width: min(500px, 54vw); }
  #comm-txt { font-size: 14px; } #comm.hot #comm-txt { font-size: 15px; }
  #h-stand { top: calc(76px + var(--sat)); width: min(170px, 20vw); }
}

/* owner / camel setup */
#owner { align-items: flex-end; background: linear-gradient(180deg, rgba(14, 8, 4, 0) 25%, rgba(14, 8, 4, .5) 100%); }
.owner-card { width: min(520px, 100%); max-height: 64%; text-align: start; gap: 10px; padding: 14px 16px 0; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.owner-card.reveal { animation: reveal .5s cubic-bezier(.2, .9, .3, 1.1); }
.ow-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.ow-head h3 { margin: 0; font-size: 22px; line-height: 1.2; }
.ow-head small { font-size: 12px; font-weight: 700; opacity: .7; }
.pill.rand { display: inline-flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 900; padding: 10px 18px; white-space: nowrap; box-shadow: 0 6px 20px rgba(234, 165, 58, .45); flex: none; }
.pill.rand .dice-ic { width: 24px; height: 24px; }
.pill.rand:active, .dice:active { transform: scale(.94); }
.dice-ic { width: 22px; height: 22px; }
.dice-ic rect { fill: none; stroke: currentColor; stroke-width: 2; } .dice-ic circle { fill: currentColor; }
.ow-field { border-radius: 14px; padding: 4px; margin: -4px; }
.ow-field.rolled { animation: rolled .6s ease-out; }
@keyframes rolled { 0% { background: rgba(255, 223, 138, .32); } 100% { background: transparent; } }
.ow-field > label, .ow-lbl { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 800; margin-bottom: 5px; }
.ow-field > label small { font-weight: 700; opacity: .6; }
.ow-lbl .dice, .ow-lbl .pill { margin-inline-start: auto; }
.ow-val { color: var(--gold2); font-size: 12px; font-weight: 800; }
.ow-in { display: flex; gap: 8px; }
.ow-in input { flex: 1; min-width: 0; font-size: 16px; font-weight: 800; padding: 9px 12px; border-radius: 12px; color: var(--ink); background: rgba(255, 255, 255, .09); border: 1.5px solid rgba(255, 255, 255, .2); outline: none; }
.ow-in input:focus { border-color: var(--gold2); background: rgba(255, 255, 255, .13); }
.ow-in input::placeholder { color: rgba(255, 248, 234, .4); }
.dice { width: 44px; height: 44px; flex: none; border-radius: 12px; display: flex; align-items: center; justify-content: center; color: var(--gold2); background: rgba(255, 223, 138, .14); border: 1.5px solid rgba(255, 223, 138, .45); transition: transform .1s; }
.dice.sm { width: 34px; height: 34px; border-radius: 10px; } .dice.sm .dice-ic { width: 18px; height: 18px; }
.pill.sm { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; font-size: 13px; color: var(--gold2); border-color: rgba(255, 223, 138, .45); }
.pill.sm .dice-ic { width: 16px; height: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip2 { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; min-height: 38px; border-radius: 12px; background: rgba(255, 255, 255, .07); border: 1.5px solid rgba(255, 255, 255, .14); font-size: 14px; }
.chip2 b { font-weight: 900; } .chip2 small { font-size: 11px; font-weight: 700; opacity: .62; }
.chip2.on { border-color: var(--gold2); background: rgba(255, 223, 138, .2); color: #fff4d6; }
.chip2 .sw { width: 16px; height: 16px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, .45); box-shadow: inset 0 1px 2px rgba(255, 255, 255, .3); }
.swatches { display: flex; flex-wrap: wrap; gap: 9px; }
.swatch { width: 36px; height: 36px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .35); box-shadow: 0 2px 6px rgba(0, 0, 0, .3); }
.swatch.on { outline: 3px solid var(--gold2); outline-offset: 2px; }
#ow-rivals { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; }
#ow-rivals li { display: flex; align-items: center; gap: 8px; padding: 5px 10px; border-radius: 10px; background: rgba(255, 255, 255, .05); font-size: 13px; }
#ow-rivals.rolled li { animation: rolled .6s ease-out; }
#ow-rivals .n { font-weight: 900; color: var(--gold); width: 12px; }
#ow-rivals .sw { width: 18px; height: 18px; border-radius: 5px; flex: none; }
#ow-rivals .nm { flex: 1; min-width: 0; display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
#ow-rivals .nm small { opacity: .65; font-size: 12px; }
#ow-rivals .br { font-size: 11px; opacity: .6; }
.ow-btns { position: sticky; bottom: 0; margin: 2px -16px 0; padding: 10px 16px calc(14px); background: linear-gradient(180deg, rgba(28, 16, 8, 0), rgba(28, 16, 8, .97) 30%); }
@media (orientation: landscape) {
  #owner { align-items: stretch; justify-content: flex-start; background: linear-gradient(90deg, rgba(14, 8, 4, .1), rgba(14, 8, 4, .45)); padding-top: calc(8px + var(--sat)); padding-bottom: calc(8px + var(--sab)); }
  html[dir=ltr] #owner { justify-content: flex-start; }
  .owner-card { width: min(480px, 56vw); max-height: 100%; }
}

/* podium overlay */
#podium { position: fixed; inset: 0; z-index: 11; pointer-events: none; }
.pd-title { position: absolute; top: calc(10px + var(--sat)); left: 50%; transform: translateX(-50%); text-align: center; white-space: nowrap; }
.pd-title b { display: block; font-size: clamp(28px, 8vw, 42px); font-weight: 900; color: #fff4d6; line-height: 1.1; text-shadow: 0 3px 0 #b06a1e, 0 8px 30px rgba(0, 0, 0, .55); }
.pd-title small { font-size: 14px; font-weight: 900; color: var(--gold2); text-shadow: 0 1px 6px rgba(0, 0, 0, .7); }
body.podium-on #comm { top: calc(84px + var(--sat)); }
.pd-card { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(12px + var(--sab)); width: min(520px, calc(100% - 20px)); pointer-events: auto;
  background: rgba(28, 16, 8, .88); border: 1px solid rgba(255, 223, 138, .35); border-radius: 20px; padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 8px; box-shadow: 0 16px 40px rgba(0, 0, 0, .45); animation: reveal .6s cubic-bezier(.2, .9, .3, 1.1) .6s both; }
#pd-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; }
#pd-list li { display: flex; align-items: center; gap: 10px; padding: 4px 8px; border-radius: 12px; background: rgba(255, 255, 255, .05); }
#pd-list li.me { background: rgba(255, 223, 138, .18); }
.medal { width: 30px; height: 30px; flex: none; border-radius: 50%; display: grid; place-items: center; font-weight: 900; color: #2b1606; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .2); }
.m1 .medal { background: radial-gradient(circle at 35% 30%, #fff0b8, #d9a032); } .m2 .medal { background: radial-gradient(circle at 35% 30%, #ffffff, #9aa3ad); } .m3 .medal { background: radial-gradient(circle at 35% 30%, #ffd2a8, #a8622f); }
#pd-list .nm { flex: 1; min-width: 0; display: flex; flex-direction: column; text-align: start; line-height: 1.2; }
#pd-list .nm b { font-size: 15px; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#pd-list .nm small { font-size: 12px; opacity: .72; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#pd-list .tm { direction: ltr; font-weight: 800; opacity: .85; font-size: 14px; }
.pd-card .pill.big { padding: 11px 20px; }
@media (orientation: landscape) and (max-height: 600px) {
  .pd-title b { font-size: 26px; } .pd-title small { font-size: 12px; }
  body.podium-on #comm { top: calc(62px + var(--sat)); }
  .pd-card { width: min(760px, calc(100% - 20px)); flex-direction: row; align-items: center; padding: 8px 10px; }
  #pd-list { flex-direction: row; flex: 1; min-width: 0; }
  #pd-list li { flex: 1; min-width: 0; padding: 4px 6px; gap: 6px; }
  #pd-list .tm { display: none; }
  .pd-card .pill.big { width: auto; flex: none; padding: 10px 18px; }
}

/* results: owner under the camel name */
#f-stand .nm { display: flex; align-items: baseline; gap: 6px; min-width: 0; overflow: hidden; }
#f-stand .nm b { font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#f-stand .nm small { font-size: 11px; opacity: .65; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (orientation: landscape) and (max-height: 500px) {
  .owner-card { gap: 8px; padding-top: 10px; }
  .ow-in input { padding: 6px 10px; } .dice { width: 38px; height: 38px; }
  .ow-btns { padding-top: 6px; padding-bottom: 8px; } .ow-btns .pill.big { padding: 8px 16px; font-size: 16px; }
  .pill.rand { padding: 7px 14px; font-size: 16px; }
}
@media (orientation: landscape) { body.coop #h-stand, body.manual #h-stand { inset-inline-end: auto; inset-inline-start: calc(8px + var(--sar)); } }
body.coop #h-stand, body.manual #h-stand { inset-inline-end: auto; inset-inline-start: calc(8px + var(--sar)); }
#warn { top: calc(352px + var(--sat)); z-index: 3; }
@media (orientation: landscape) { #warn { top: calc(170px + var(--sat)); } }

/* ================================================================ v4: garage (تجهيز الهجين) */
.pill.gar-open { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 10px 14px; font-size: 16px; font-weight: 900; color: var(--gold2); border: 1.5px solid rgba(255, 223, 138, .55); background: rgba(255, 223, 138, .12); }
.pill.gar-open .gic { font-size: 18px; line-height: 1; }
#garage { align-items: flex-end; padding: 0; background: linear-gradient(180deg, rgba(14, 8, 4, 0) 40%, rgba(14, 8, 4, .45) 100%); }
#gar-view { position: absolute; inset: 0; touch-action: none; cursor: grab; }
#gar-view:active { cursor: grabbing; }
.gar-hint { position: absolute; top: calc(10px + var(--sat)); left: 50%; transform: translateX(-50%); padding: 5px 12px; border-radius: 99px; background: rgba(20, 12, 6, .55); font-size: 12px; font-weight: 800; white-space: nowrap; pointer-events: none; opacity: .9; }
.gar-card { position: relative; width: min(560px, 100%); height: 56%; max-height: 56%; display: flex; flex-direction: column; gap: 8px; padding: 12px 14px 0; border-radius: 24px 24px 0 0; margin: 0 calc(0px + var(--sar)) 0 calc(0px + var(--sal)); overflow: hidden; text-align: start; }
.gar-card .ow-head h3 { font-size: 20px; }
.gar-tabs { display: flex; gap: 6px; flex: none; }
.gar-tab { flex: 1; padding: 8px 6px; border-radius: 12px; font-size: 15px; font-weight: 900; background: rgba(255, 255, 255, .07); border: 1.5px solid rgba(255, 255, 255, .14); }
.gar-tab.on { border-color: var(--gold2); background: rgba(255, 223, 138, .22); color: #fff4d6; }
.gar-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 10px; padding: 2px 2px 8px; }
.gar-cat { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 800; opacity: .9; }
.gar-cat .pill.sm { margin-inline-start: auto; }
.gopt { border-radius: 12px; padding: 3px; margin: -3px; }
.gopt.rolled { animation: rolled .6s ease-out; }
.gopt > .lbl { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 800; margin-bottom: 5px; }
.gopt > .lbl .val { color: var(--gold2); font-size: 12px; font-weight: 800; margin-inline-start: auto; }
.gsw { display: flex; flex-wrap: wrap; gap: 7px; padding: 3px 2px 3px; }
.gsw::-webkit-scrollbar { display: none; }
.gsw .swatch { width: 32px; height: 32px; flex: none; }
.gsw .swatch.on { outline-width: 3px; }
.gchips { display: flex; flex-wrap: wrap; gap: 6px; }
.gchips .chip2 { min-height: 36px; padding: 5px 10px; }
.gpat { width: 22px; height: 22px; border-radius: 6px; flex: none; border: 1px solid rgba(0, 0, 0, .4); }
.gnum { display: flex; align-items: center; gap: 8px; }
.gnum button { width: 40px; height: 36px; border-radius: 10px; font-size: 20px; font-weight: 900; background: rgba(255, 255, 255, .09); border: 1.5px solid rgba(255, 255, 255, .2); }
.gnum b { min-width: 46px; text-align: center; font-size: 20px; font-weight: 900; direction: ltr; padding: 2px 8px; border-radius: 8px; background: #fbf7ee; color: #111; }
.tog { min-width: 64px; min-height: 34px; padding: 4px 12px; border-radius: 99px; font-size: 13px; font-weight: 900; background: rgba(255, 255, 255, .08); border: 1.5px solid rgba(255, 255, 255, .2); }
.tog.on { background: var(--green); border-color: var(--green); color: #062b14; }
.gslider { display: flex; align-items: center; gap: 8px; font-size: 11px; font-weight: 800; opacity: .9; }
.gslider input { flex: 1; accent-color: var(--gold); height: 28px; }
.gar-card .ow-btns { margin: 0 -14px; padding: 8px 14px calc(10px + var(--sab)); flex: none; }
@media (orientation: landscape) {
  #garage { align-items: stretch; justify-content: flex-start; background: linear-gradient(90deg, rgba(14, 8, 4, .45), rgba(14, 8, 4, 0) 60%); }
  .gar-card { width: min(440px, 50vw); height: 100%; max-height: 100%; border-radius: 0 22px 22px 0; padding-top: calc(10px + var(--sat)); padding-inline-start: calc(14px + var(--sar)); }
  html[dir=ltr] .gar-card { border-radius: 0 22px 22px 0; padding-inline-start: calc(14px + var(--sal)); }
  html[dir=rtl] .gar-card { border-radius: 22px 0 0 22px; }
  .gar-hint { left: auto; transform: none; inset-inline-end: calc(14px + var(--sar)); }
}
@media (orientation: landscape) and (max-height: 500px) {
  .gar-card { gap: 6px; padding-top: calc(8px + var(--sat)); }
  .gar-card .ow-head h3 { font-size: 17px; }
  .gar-tab { padding: 5px 6px; font-size: 14px; }
  .gsw .swatch { width: 28px; height: 28px; }
  .gar-card .ow-btns { padding-top: 6px; padding-bottom: calc(6px + var(--sab)); } .gar-card .ow-btns .pill.big { padding: 7px 14px; font-size: 15px; }
}
