/* Moto Stunt Ramps. Logical properties, so RTL and LTR share one file; the track and the
   touch pads stay left to right because the bike always rides to the right. */
:root {
    --bg: #0c1120; --surface: #161e33; --surface2: #1f2944; --border: #2d3a5e; --text: #eef2ff; --muted: #a3aed0;
    --accent: #ffcf4a; --hot: #ff5a36; --ink: #0b1020; --ok: #4ade80;
    --font: system-ui, "Segoe UI", Tahoma, "Noto Sans Arabic", "Noto Sans", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); }
body { -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
#game:focus { outline: none; }

.game { max-inline-size: 1000px; margin-inline: auto; padding: 8px; }

.hud { display: flex; align-items: stretch; gap: 6px; margin-block-end: 8px; }
.icon {
    flex: none; inline-size: 44px; min-block-size: 44px; border-radius: 12px; cursor: pointer; padding: 0;
    background: var(--surface); border: 1px solid var(--border); display: grid; place-items: center;
}
.icon svg { inline-size: 22px; block-size: 22px; }
.box {
    flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
    min-inline-size: 62px; padding: 3px 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
}
.box .k { font-size: .7rem; color: var(--muted); white-space: nowrap; }
.box b { font-size: 1.02rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.box.lvl { flex: 1; min-inline-size: 0; align-items: stretch; gap: 5px; padding-inline: 10px; }
.box.lvl .k { color: var(--text); font-weight: 800; font-size: .84rem; overflow: hidden; text-overflow: ellipsis; }
.prog { display: block; block-size: 7px; border-radius: 99px; background: #0b1020; overflow: hidden; direction: ltr; }
.prog i { display: block; block-size: 100%; inline-size: 0; border-radius: inherit; background: linear-gradient(90deg, #ff8f3d, var(--accent)); }
.box.mult b { color: var(--accent); }
.box.mult.hot { border-color: var(--accent); box-shadow: 0 0 14px rgba(255, 207, 74, .35); }

.stage {
    position: relative; inline-size: 100%; aspect-ratio: 16 / 9; border-radius: 16px; overflow: hidden;
    background: #1b2440; border: 1px solid var(--border); touch-action: none; direction: ltr;
}
.stage canvas { position: absolute; inset: 0; inline-size: 100%; block-size: 100%; display: block; touch-action: none; }
@media (max-width: 620px) { .stage { aspect-ratio: 3 / 4; } .stage.tall { aspect-ratio: auto; min-block-size: 640px; } }
@media (max-width: 620px) and (max-height: 520px) { .stage, .stage.tall { aspect-ratio: 16 / 9; min-block-size: 0; } }

.banner {
    position: absolute; inset-inline: 12px; inset-block-start: 14%; display: flex; flex-direction: column; align-items: center; gap: 6px;
    pointer-events: none; opacity: 0; transform: scale(.9); transition: opacity .2s, transform .2s;
}
.banner.on { opacity: 1; transform: none; }
.banner span {
    background: rgba(11, 16, 32, .78); border: 1px solid var(--accent); border-radius: 999px; padding: 7px 18px;
    font-weight: 900; font-size: 1.1rem; text-align: center; letter-spacing: .02em; box-shadow: 0 0 22px rgba(255, 207, 74, .3);
}
.banner.big span { font-size: 2.6rem; padding: 4px 30px; }
.banner.bad span { border-color: #ff6b81; box-shadow: 0 0 22px rgba(255, 107, 129, .35); }
.banner small { color: #fff; font-weight: 800; font-size: .92rem; text-shadow: 0 1px 4px #000; }
:root[dir="rtl"] .banner, :root[dir="rtl"] .overlay { direction: rtl; }

/* Touch pads: only on touch screens, and hidden while a menu is open. */
.touch { position: absolute; inset-inline: 0; inset-block-end: 0; display: none; justify-content: space-between; padding: 10px; pointer-events: none; }
@media (pointer: coarse) { .touch { display: flex; } }
.touch.off { display: none; }
.pad { display: flex; gap: 10px; pointer-events: auto; }
.tb {
    inline-size: 66px; block-size: 66px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .28); padding: 0;
    background: rgba(11, 16, 32, .42); display: grid; place-items: center; cursor: pointer; touch-action: none;
    backdrop-filter: blur(2px);
}
.tb svg { inline-size: 30px; block-size: 30px; }
.tb.on { background: rgba(255, 207, 74, .45); border-color: var(--accent); }
.tb.gas { inline-size: 78px; block-size: 78px; border-color: rgba(74, 222, 128, .6); }
.tb.gas.on { background: rgba(74, 222, 128, .45); border-color: var(--ok); }
@media (max-width: 380px) { .tb { inline-size: 58px; block-size: 58px; } .tb.gas { inline-size: 68px; block-size: 68px; } }

.overlay {
    position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: safe center;
    gap: 10px; padding: 14px; text-align: center; background: rgba(8, 12, 26, .66); backdrop-filter: blur(3px); overflow-y: auto;
}
.overlay.on { display: flex; }
.overlay h2 { margin: 0; font-size: 1.8rem; text-shadow: 0 0 18px rgba(255, 140, 60, .45); }
.overlay p { margin: 0; color: var(--muted); max-inline-size: 50ch; }
.overlay .big { font-size: 2.5rem; font-weight: 900; color: var(--accent); font-variant-numeric: tabular-nums; line-height: 1.05; }
.overlay table { border-collapse: collapse; font-size: .92rem; min-inline-size: 240px; }
.overlay td { padding: 3px 10px; font-variant-numeric: tabular-nums; text-align: start; }
.overlay td + td { text-align: end; font-weight: 700; }
.overlay tr.sum td { border-block-start: 1px solid var(--border); padding-block-start: 6px; font-size: 1.02rem; color: var(--accent); }
.badge { display: inline-block; padding: 3px 12px; border-radius: 999px; background: var(--accent); color: var(--ink); font-weight: 800; font-size: .85rem; }
.note { font-size: .8rem; }
.stars { display: flex; gap: 6px; justify-content: center; direction: ltr; }
.stars svg { inline-size: 44px; block-size: 44px; }
.stars .s { opacity: .22; transform: scale(.8); transition: opacity .3s, transform .3s; }
.stars .s.on { opacity: 1; transform: none; filter: drop-shadow(0 0 8px rgba(255, 207, 74, .7)); }
.total { color: var(--accent); font-weight: 800; }

.bikes { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.bike {
    display: flex; flex-direction: column; align-items: center; gap: 2px; inline-size: 128px; padding: 8px 6px; cursor: pointer;
    border-radius: 14px; background: rgba(22, 30, 51, .92); border: 2px solid var(--border);
}
.bike svg { inline-size: 84px; block-size: 46px; }
.bike b { font-size: .9rem; }
.bike small { font-size: .72rem; color: var(--muted); }
.bike[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 16px rgba(255, 207, 74, .3); background: rgba(31, 41, 68, .96); }
.bike:disabled { cursor: default; opacity: .5; }

.worlds { display: grid; gap: 10px; inline-size: min(100%, 640px); }
.world h3 { margin: 0 0 6px; font-size: .9rem; color: var(--muted); text-align: start; }
.lvls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.lv {
    display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 4px; border-radius: 12px; cursor: pointer;
    background: rgba(22, 30, 51, .92); border: 1px solid var(--border); min-block-size: 64px;
}
.lv b { font-size: 1.15rem; }
.lv .st { font-size: .8rem; color: var(--accent); letter-spacing: 1px; direction: ltr; }
.lv .st i { font-style: normal; color: #3a4668; }
.lv small { font-size: .7rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.lv:disabled { cursor: default; opacity: .45; }
.lv:not(:disabled):hover { border-color: var(--accent); }
.lv.w0 { background: linear-gradient(160deg, rgba(120, 52, 40, .55), rgba(22, 30, 51, .92)); }
.lv.w1 { background: linear-gradient(160deg, rgba(40, 110, 60, .55), rgba(22, 30, 51, .92)); }
.lv.w2 { background: linear-gradient(160deg, rgba(70, 50, 140, .6), rgba(22, 30, 51, .92)); }
.lv.w3 { background: linear-gradient(160deg, rgba(90, 150, 200, .5), rgba(22, 30, 51, .92)); }

.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-block-start: 4px; }
.btn {
    border: 0; border-radius: 12px; padding: 12px 26px; font-weight: 800; cursor: pointer; min-block-size: 46px;
    background: linear-gradient(135deg, #ffd65a, #ff8f3d); color: var(--ink); box-shadow: 0 6px 22px rgba(255, 160, 60, .3);
}
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); box-shadow: none; }

.keys { margin: 10px 0 0; text-align: center; font-size: .85rem; color: var(--muted); display: none; }
@media (hover: hover) and (pointer: fine) { .keys { display: block; } }
.keys kbd {
    display: inline-block; min-inline-size: 1.7em; padding: 1px 5px; border-radius: 6px; border: 1px solid var(--border);
    background: var(--surface); font: inherit; font-size: .8rem; color: var(--text);
}

@media (max-width: 620px) {
    .hud { gap: 4px; }
    .box { min-inline-size: 50px; padding-inline: 5px; }
    .box b { font-size: .9rem; }
    .box.lvl { padding-inline: 7px; }
    .overlay { gap: 8px; padding: 10px; }
    .overlay h2 { font-size: 1.4rem; }
    .overlay .big { font-size: 2rem; }
    .bike { inline-size: 100px; padding: 6px 4px; }
    .bike svg { inline-size: 66px; block-size: 36px; }
    .bike small { display: none; }
}
@media (max-width: 380px) {
    .icon { inline-size: 38px; }
    .box { min-inline-size: 44px; }
    #multBox { display: none; }
}

/* Polish: pops, bumps and the result card */
.banner.on span { animation: ms-pop .38s cubic-bezier(.2, 1.6, .4, 1); }
.banner.big.on span { animation-duration: .45s; }
@keyframes ms-pop { from { transform: scale(.55); opacity: 0; } to { transform: none; opacity: 1; } }
.box.bump { animation: ms-bump .32s ease-out; }
@keyframes ms-bump { 40% { transform: scale(1.14); border-color: var(--accent); } }
.stars .s { position: relative; }
.stars .s.on { animation: ms-star .5s cubic-bezier(.2, 1.7, .4, 1); }
.stars .s.on::after {
    content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 3px solid var(--accent);
    opacity: 0; animation: ms-ring .6s ease-out;
}
@keyframes ms-star { 0% { transform: scale(.2) rotate(-40deg); } 70% { transform: scale(1.25) rotate(8deg); } 100% { transform: none; } }
@keyframes ms-ring { 0% { opacity: .9; transform: scale(.5); } 100% { opacity: 0; transform: scale(1.6); } }
.overlay .rows tr { animation: ms-row .35s ease-out both; }
.overlay .rows tr:nth-child(2) { animation-delay: .08s; } .overlay .rows tr:nth-child(3) { animation-delay: .16s; }
.overlay .rows tr:nth-child(4) { animation-delay: .24s; } .overlay .rows tr:nth-child(5) { animation-delay: .32s; }
.overlay .rows tr:nth-child(6) { animation-delay: .44s; }
@keyframes ms-row { from { opacity: 0; transform: translateY(6px); } }
.badge.best { animation: ms-glow 1.1s ease-in-out infinite alternate; }
@keyframes ms-glow { from { box-shadow: 0 0 0 rgba(255, 207, 74, 0); } to { box-shadow: 0 0 22px rgba(255, 207, 74, .8); transform: scale(1.06); } }
.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti i {
    position: absolute; inset-block-start: -12px; inset-inline-start: var(--x); inline-size: 8px; block-size: 12px; background: var(--c);
    border-radius: 2px; animation: ms-fall 2.4s var(--d) cubic-bezier(.3, .4, .6, 1) both;
}
@keyframes ms-fall { from { transform: translateY(0) rotate(0); opacity: 1; } to { transform: translateY(520px) rotate(var(--r)); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
    .banner, .stars .s { transition: none; }
    .banner.on span, .box.bump, .stars .s.on, .stars .s.on::after, .overlay .rows tr, .badge.best { animation: none; }
}

/* ---------- polish 2: coach line, combo fire, rank, record stamp ---------- */
.coach {
    position: absolute; inset-inline: 0; inset-block-start: 6px; margin-inline: auto; inline-size: max-content; max-inline-size: calc(100% - 24px);
    padding: 6px 14px; border-radius: 999px; background: rgba(11, 16, 32, .78); border: 1px solid rgba(255, 207, 74, .6);
    color: #fff; font-weight: 800; font-size: .92rem; text-align: center; pointer-events: none;
    opacity: 0; transform: translateY(-8px); transition: opacity .25s, transform .25s;
}
.coach.on { opacity: 1; transform: none; }
:root[dir="rtl"] .coach { direction: rtl; }
.box.mult.fire { border-color: var(--hot); background: linear-gradient(0deg, rgba(255, 90, 54, .38), var(--surface) 75%); animation: ms-fire .5s ease-in-out infinite alternate; }
.box.mult.fire b { color: #ffd27a; text-shadow: 0 0 8px rgba(255, 120, 40, .9); }
@keyframes ms-fire { from { box-shadow: 0 0 10px rgba(255, 90, 54, .45); } to { box-shadow: 0 0 22px rgba(255, 140, 40, .8); } }
.overlay .rank { margin: -2px 0 0; font-weight: 900; font-size: .95rem; letter-spacing: .02em; color: var(--muted); }
.overlay .rank.r2 { color: #9fe8ff; }
.overlay .rank.r3 { color: var(--accent); text-shadow: 0 0 12px rgba(255, 207, 74, .55); }
.stamp {
    display: inline-block; padding: 4px 14px; border: 3px solid var(--hot); border-radius: 10px; color: var(--hot);
    font-weight: 900; font-size: 1.05rem; letter-spacing: .04em; text-transform: uppercase; transform: rotate(-7deg); opacity: 0;
}
.stamp.on { animation: ms-stamp .45s cubic-bezier(.2, 1.6, .4, 1) forwards; }
@keyframes ms-stamp { 0% { opacity: 0; transform: scale(2.6) rotate(-16deg); } 60% { opacity: 1; transform: scale(.92) rotate(-6deg); } 100% { opacity: 1; transform: scale(1) rotate(-7deg); box-shadow: 0 0 18px rgba(255, 90, 54, .5); } }
/* short landscape phones: keep the result card no taller than before the polish */
@media (max-height: 520px) {
    .overlay .rank { display: none; }
    .stars svg { inline-size: 34px; block-size: 34px; }
    .stamp { padding: 2px 12px; font-size: .95rem; border-width: 2px; }
    .coach { font-size: .82rem; padding: 4px 12px; }
}
@media (prefers-reduced-motion: reduce) {
    .box.mult.fire { animation: none; }
    .stamp { opacity: 1; } .stamp.on { animation: none; }
}
