/* Jet Loop Duel. Logical properties, so RTL and LTR share one file; the sky itself stays LTR.
   Keyframes are prefixed jl- so they never clash with shared styles. */
:root {
    --bg: #06101f; --surface: #0f1d36; --surface2: #172a4d; --border: #29426e; --text: #eef6ff; --muted: #9fb4d8;
    --p1: #3ad0ff; --p2: #ff7a3d; --accent: #3ad0ff; --accent2: #ffd166; --hot: #ff4f6d; --ok: #4ade80; --ink: #04101e;
    --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(--accent2); outline-offset: 2px; }
#game:focus { outline: none; }
[hidden] { display: none !important; }

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

/* ---------- menus and end screens ---------- */
.screen {
    position: relative; overflow: hidden; border-radius: 18px; border: 1px solid var(--border); padding: 20px 16px 22px;
    background:
        radial-gradient(90% 60% at 15% 0%, rgba(58, 208, 255, .22), transparent 60%),
        radial-gradient(90% 60% at 85% 0%, rgba(255, 122, 61, .2), transparent 60%),
        linear-gradient(180deg, #10264a, #06101f 75%);
    text-align: center; min-block-size: 440px;
}
.screen > * { position: relative; }
.screen canvas.sky { position: absolute; inset: 0; inline-size: 100%; block-size: 100%; object-fit: cover; opacity: .32; pointer-events: none; }
.screen h2 { margin: 4px 0 6px; font-size: clamp(1.7rem, 5.4vw, 2.6rem); letter-spacing: .02em; text-shadow: 0 3px 0 #000, 0 0 26px rgba(58, 208, 255, .5); }
.screen h2.win { color: var(--accent2); text-shadow: 0 3px 0 #000, 0 0 30px rgba(255, 209, 102, .6); }
.screen h2.lose { color: #ffc0a8; }
.screen h3 { margin: 16px 0 8px; font-size: .95rem; color: var(--text); font-weight: 800; }
.screen h3 small { display: block; color: var(--muted); font-weight: 600; font-size: .8rem; margin-block-start: 2px; }
.screen p { margin: 6px auto; max-inline-size: 580px; color: var(--muted); line-height: 1.5; }
.screen p.unl { color: var(--accent2); font-weight: 800; animation: jl-glowtext 1s ease-in-out infinite alternate; }
@keyframes jl-glowtext { to { text-shadow: 0 0 16px rgba(255, 209, 102, .8); } }
.logo { display: inline-flex; align-items: center; gap: 10px; margin-block: 4px 2px; }
.logo .mark svg { inline-size: 58px; block-size: 58px; animation: jl-fly 3s ease-in-out infinite; filter: drop-shadow(0 0 12px rgba(58, 208, 255, .6)); }
.logo h2 { margin: 0; }
@keyframes jl-fly { 0%, 100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-6px) rotate(6deg); } }

.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 16px auto 4px; max-inline-size: 780px; }
.mode {
    border-radius: 16px; border: 2px solid var(--border); background: rgba(15, 29, 54, .85); padding: 14px 10px; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; gap: 6px; transition: transform .15s, border-color .15s, box-shadow .15s;
}
.mode svg { inline-size: 54px; block-size: 54px; }
.mode b { font-size: 1.1rem; }
.mode div { display: grid; gap: 4px; }
.mode small { color: var(--muted); font-size: .82rem; line-height: 1.35; }
.mode:hover, .mode:focus-visible { transform: translateY(-3px); border-color: var(--accent); box-shadow: 0 10px 30px rgba(58, 208, 255, .25); }
.mode.m2:hover { border-color: var(--p2); box-shadow: 0 10px 30px rgba(255, 122, 61, .25); }

.jets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; max-inline-size: 780px; margin: 4px auto; }
.jet {
    position: relative; border: 2px solid var(--border); border-radius: 14px; padding: 6px 8px 10px; background: rgba(15, 29, 54, .88); cursor: pointer;
    display: flex; flex-direction: column; align-items: center; gap: 2px; transition: transform .15s, border-color .15s;
}
.jet canvas { inline-size: 100%; max-inline-size: 160px; aspect-ratio: 160 / 70; }
.jet b { font-size: .98rem; }
.jet small { color: var(--muted); font-size: .74rem; min-block-size: 2.2em; }
.jet .bars { display: grid; grid-template-columns: auto 1fr; gap: 3px 6px; inline-size: 100%; align-items: center; font-size: .66rem; color: var(--muted); text-align: start; margin-block-start: 4px; }
.jet .bars i { display: block; block-size: 5px; border-radius: 3px; background: linear-gradient(90deg, var(--accent) var(--v), rgba(255, 255, 255, .1) 0); }
[dir="rtl"] .jet .bars i { background: linear-gradient(270deg, var(--accent) var(--v), rgba(255, 255, 255, .1) 0); }
.jet[aria-pressed="true"] { border-color: var(--accent2); box-shadow: 0 0 0 3px rgba(255, 209, 102, .22), 0 8px 24px rgba(255, 209, 102, .15); }
.jet:not([disabled]):hover { transform: translateY(-2px); }
.jet.locked { cursor: not-allowed; opacity: .6; filter: grayscale(.8); }
.jet .lock { position: absolute; inset-block-start: 14px; inset-inline: 0; margin-inline: auto; inline-size: 34px; block-size: 34px; }
.jets.p2 .jet[aria-pressed="true"] { border-color: var(--p2); box-shadow: 0 0 0 3px rgba(255, 122, 61, .25); }
.jets.p2 .bars i { background: linear-gradient(90deg, var(--p2) var(--v), rgba(255, 255, 255, .1) 0); }
.jets.small .bars { display: none; }
.jets.small small { min-block-size: 0; }

.seg { display: inline-flex; gap: 4px; padding: 4px; border-radius: 12px; background: rgba(0, 0, 0, .3); border: 1px solid var(--border); flex-wrap: wrap; justify-content: center; }
.seg button { border: 0; background: transparent; padding: 7px 14px; border-radius: 9px; cursor: pointer; font-weight: 700; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--ink); }
.opt { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 12px; margin-block: 10px; }
.opt > span { color: var(--muted); font-size: .9rem; font-weight: 700; }

.arenas { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; max-inline-size: 780px; margin: 4px auto; }
.arena { border: 2px solid var(--border); border-radius: 12px; padding: 4px; background: rgba(0, 0, 0, .25); cursor: pointer; display: grid; gap: 3px; font-size: .74rem; color: var(--muted); }
.arena canvas { inline-size: 100%; aspect-ratio: 16 / 9; border-radius: 8px; display: block; }
.arena[aria-pressed="true"] { border-color: var(--accent2); color: var(--text); box-shadow: 0 0 0 3px rgba(255, 209, 102, .2); }

.rivals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-inline-size: 780px; margin: 14px auto 6px; }
.rival {
    position: relative; border-radius: 16px; border: 2px solid var(--border); background: rgba(15, 29, 54, .88); padding: 8px 8px 12px; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; gap: 3px; transition: transform .15s, border-color .15s, box-shadow .15s; overflow: hidden;
}
.rival canvas { inline-size: 100%; aspect-ratio: 16 / 9; border-radius: 10px; }
.rival b { font-size: 1.05rem; }
.rival small { color: var(--muted); font-size: .78rem; }
.rival .num { position: absolute; inset-block-start: 12px; inset-inline-start: 14px; font-weight: 900; font-size: .8rem; background: rgba(0, 0, 0, .55); padding: 2px 8px; border-radius: 99px; }
.rival:not([disabled]):hover, .rival:not([disabled]):focus-visible { transform: translateY(-3px); border-color: var(--accent2); box-shadow: 0 10px 28px rgba(255, 209, 102, .2); }
.rival[disabled] { cursor: not-allowed; opacity: .55; filter: grayscale(.7); }
.rival .lock { position: absolute; inset-block-start: 22%; inset-inline: 0; margin-inline: auto; inline-size: 40px; block-size: 40px; }
.rival.next { border-color: var(--accent); animation: jl-glow 1.4s ease-in-out infinite alternate; }
@keyframes jl-glow { to { box-shadow: 0 0 0 4px rgba(58, 208, 255, .18), 0 0 30px rgba(58, 208, 255, .3); } }
.stars { display: inline-flex; gap: 2px; }
.stars svg { inline-size: 18px; block-size: 18px; fill: #2c3f68; }
.stars svg.on { fill: var(--accent2); filter: drop-shadow(0 0 4px rgba(255, 209, 102, .7)); }
.stars.big svg { inline-size: 44px; block-size: 44px; }
.stars.big svg.pop { animation: jl-starpop .5s cubic-bezier(.2, 1.7, .4, 1) both; }
@keyframes jl-starpop { 0% { transform: scale(0) rotate(-90deg); } 100% { transform: scale(1) rotate(0); } }

.actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-block: 16px 6px; }
.btn {
    border: 0; border-radius: 14px; padding: 12px 28px; font-weight: 900; font-size: 1.05rem; cursor: pointer;
    background: linear-gradient(180deg, #8ae8ff, var(--accent)); color: var(--ink); box-shadow: 0 4px 0 #11729a, 0 10px 26px rgba(58, 208, 255, .35);
    transition: transform .1s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #11729a; }
.btn.ghost { background: var(--surface2); color: var(--text); box-shadow: 0 4px 0 #040a14; border: 1px solid var(--border); }
.row { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 18px; margin-block: 8px; color: var(--muted); font-size: .92rem; }
.row b { color: var(--text); font-variant-numeric: tabular-nums; }
.tips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; font-size: .8rem; color: var(--muted); margin-block-start: 10px; }

.final { display: flex; align-items: center; justify-content: center; gap: 18px; margin-block: 6px; direction: ltr; }
.final b { font-size: clamp(2.8rem, 11vw, 4.6rem); font-weight: 900; font-variant-numeric: tabular-nums; text-shadow: 0 4px 0 #000; }
.final .a { color: var(--p1); text-shadow: 0 4px 0 #000, 0 0 30px rgba(58, 208, 255, .5); }
.final .b { color: var(--p2); text-shadow: 0 4px 0 #000, 0 0 30px rgba(255, 122, 61, .5); }
.final i { font-style: normal; font-size: 2rem; color: var(--muted); }
.final b.landed { animation: jl-land .45s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes jl-land { 0% { transform: scale(1.3); } 100% { transform: scale(1); } }
.statgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; max-inline-size: 620px; margin: 12px auto 4px; }
.statgrid div { background: rgba(15, 29, 54, .85); border: 1px solid var(--border); border-radius: 12px; padding: 8px 4px; display: grid; gap: 2px; }
.statgrid div > span { font-size: .74rem; color: var(--muted); }
.statgrid b { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.statgrid div.rec { border-color: var(--accent2); box-shadow: 0 0 18px rgba(255, 209, 102, .3); }
.statgrid.two b small { color: var(--p2); font-size: .8rem; }
.badge { display: inline-block; padding: 5px 14px; border-radius: 99px; font-weight: 900; background: var(--hot); color: #fff; animation: jl-badge 1s ease-in-out infinite alternate; }
@keyframes jl-badge { to { transform: scale(1.08); box-shadow: 0 0 22px rgba(255, 79, 109, .7); } }
.trophy { inline-size: 92px; block-size: 92px; margin-inline: auto; display: block; animation: jl-trophy 1.2s cubic-bezier(.2, 1.5, .4, 1) both; filter: drop-shadow(0 0 24px rgba(255, 209, 102, .6)); }
@keyframes jl-trophy { 0% { transform: translateY(40px) scale(.3); opacity: 0; } 100% { transform: none; opacity: 1; } }
.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti i { position: absolute; inset-block-start: -12px; inline-size: 9px; block-size: 14px; border-radius: 2px; animation: jl-fall linear forwards; }
@keyframes jl-fall { to { transform: translateY(640px) rotate(720deg); opacity: .2; } }

/* ---------- play area ---------- */
.hud { display: flex; align-items: stretch; gap: 8px; margin-block-end: 8px; direction: ltr; }
.side {
    flex: 1.4; min-inline-size: 0; display: grid; grid-template-columns: 1fr auto; grid-template-areas: "who pips" "hp hp" "bst xtra"; align-items: center; gap: 3px 8px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 5px 10px;
}
.side .who { grid-area: who; font-size: .8rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side .pips { grid-area: pips; }
.side .hp { grid-area: hp; }
.side .bst { grid-area: bst; }
.side .xtra { grid-area: xtra; }
.side.s1 { border-inline-start: 4px solid var(--p1); }
.side.s2 { border-inline-end: 4px solid var(--p2); grid-template-columns: auto 1fr; grid-template-areas: "pips who" "hp hp" "xtra bst"; text-align: end; }
.bar { display: block; block-size: 9px; border-radius: 5px; background: rgba(255, 255, 255, .1); position: relative; overflow: hidden; }
.bar::after { content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; inline-size: var(--v, 100%); border-radius: inherit; background: linear-gradient(90deg, #4ade80, #a3f06a); transition: inline-size .15s; }
.s2 .bar::after { inset-inline-start: auto; inset-inline-end: 0; }
.bar.low::after { background: linear-gradient(90deg, #ff4f6d, #ff8a5a); animation: jl-blink .5s steps(2) infinite; }
.bar.hurt { animation: jl-hurt .3s; }
@keyframes jl-hurt { 0% { box-shadow: 0 0 0 2px #ff4f6d; } 100% { box-shadow: none; } }
@keyframes jl-blink { 50% { opacity: .55; } }
.bar.bst { block-size: 5px; }
.bar.bst::after { background: linear-gradient(90deg, var(--p1), #b8f2ff); }
.s2 .bar.bst::after { background: linear-gradient(270deg, var(--p2), #ffd0b0); }
.bar.bst.nitro::after { background: linear-gradient(90deg, #c48bff, #ffffff, #c48bff); background-size: 200% 100%; animation: jl-nitro .6s linear infinite; }
@keyframes jl-nitro { to { background-position: -200% 0; } }
.xtra { display: flex; gap: 4px; font-size: .7rem; font-weight: 800; min-block-size: 14px; }
.s2 .xtra { justify-content: flex-start; }
.xtra span { display: inline-flex; align-items: center; gap: 2px; padding: 0 5px; border-radius: 99px; background: rgba(0, 0, 0, .4); }
.xtra svg { inline-size: 13px; block-size: 13px; }
.xtra .m { color: #ff8a8a; } .xtra .t { color: var(--accent2); } .xtra .s { color: #7ae6ff; }
.pips { display: flex; gap: 3px; }
.pips i { inline-size: 10px; block-size: 10px; border-radius: 50%; background: #23365e; }
.s1 .pips i.on { background: var(--p1); box-shadow: 0 0 6px var(--p1); }
.s2 .pips i.on { background: var(--p2); box-shadow: 0 0 6px var(--p2); }
.pips.bump { animation: jl-bump .45s cubic-bezier(.2, 1.8, .4, 1); }
@keyframes jl-bump { 0% { transform: scale(1.8); } 100% { transform: scale(1); } }
.mid { flex: 1; min-inline-size: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 900; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.mid #midTop.low { color: var(--hot); animation: jl-blink .5s steps(2) infinite; }
.mid small { color: var(--muted); font-weight: 600; font-size: .7rem; text-align: center; }
.icon { inline-size: 44px; flex: 0 0 44px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; display: grid; place-items: center; }
.icon svg { inline-size: 22px; block-size: 22px; }
.icon[aria-pressed="false"] { color: var(--muted); }

.stage { position: relative; border-radius: 18px; overflow: hidden; background: #000; touch-action: none; direction: ltr; }
.stage canvas { display: block; inline-size: 100%; block-size: 100%; cursor: crosshair; }
.stick { position: absolute; inline-size: 96px; block-size: 96px; margin: -48px 0 0 -48px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .45); background: rgba(58, 208, 255, .12); pointer-events: none; display: grid; place-items: center; }
.stick.p2 { background: rgba(255, 122, 61, .12); }
.stick i { inline-size: 40px; block-size: 40px; border-radius: 50%; background: rgba(255, 255, 255, .7); box-shadow: 0 0 14px rgba(58, 208, 255, .8); }
.stick.p2 i { box-shadow: 0 0 14px rgba(255, 122, 61, .8); }
.pad { position: absolute; inset-block-end: 10px; inset-inline-end: 10px; display: grid; grid-template-columns: auto auto; grid-template-areas: "msl fire" "bst fire"; gap: 8px; align-items: center; }
.pb { border-radius: 50%; border: 2px solid rgba(255, 255, 255, .5); background: rgba(10, 20, 40, .5); font-weight: 900; font-size: .72rem; color: #fff; touch-action: none; cursor: pointer; display: grid; place-items: center; }
.pb.fire { grid-area: fire; inline-size: 76px; block-size: 76px; font-size: .9rem; border-color: rgba(255, 209, 102, .85); }
.pb.bst { grid-area: bst; inline-size: 54px; block-size: 54px; border-color: rgba(58, 208, 255, .85); }
.pb.msl { grid-area: msl; inline-size: 54px; block-size: 54px; opacity: .45; position: relative; }
.pb.msl svg { inline-size: 24px; block-size: 24px; }
.pb.msl b { position: absolute; inset-block-start: -4px; inset-inline-end: -4px; background: var(--hot); border-radius: 99px; padding: 0 5px; font-size: .7rem; }
.pb.msl.ready { opacity: 1; border-color: rgba(255, 138, 138, .9); }
.pb.down { background: rgba(255, 255, 255, .35); transform: scale(.94); }
.banner {
    position: absolute; inset-inline: 0; inset-block-start: 34%; text-align: center; pointer-events: none; opacity: 0; color: #fff;
    font-weight: 900; font-size: clamp(1.8rem, 7.5vw, 4rem); letter-spacing: .04em; text-shadow: 0 4px 0 #000, 0 0 30px currentColor;
}
.banner small { display: block; font-size: .34em; letter-spacing: .1em; color: #fff; text-shadow: 0 2px 0 #000; }
.banner.show { animation: jl-banner 1.2s cubic-bezier(.2, 1.4, .4, 1) forwards; }
@keyframes jl-banner {
    0% { opacity: 0; transform: scale(2.2); }
    18% { opacity: 1; transform: scale(1); }
    75% { opacity: 1; transform: scale(1.04); }
    100% { opacity: 0; transform: scale(.9) translateY(-14px); }
}
.banner.p1 { color: var(--p1); } .banner.p2 { color: var(--p2); } .banner.gold { color: var(--accent2); } .banner.bad { color: #ff8a7a; }
.overlay { position: absolute; inset: 0; display: none; place-items: center; background: rgba(4, 10, 22, .72); backdrop-filter: blur(3px); text-align: center; padding: 16px; }
.overlay.on { display: grid; }
.overlay.ghost { background: transparent; backdrop-filter: none; pointer-events: none; }
.overlay h3 { margin: 0 0 10px; font-size: 2rem; }
.count { font-size: clamp(3rem, 12vw, 5.5rem); font-weight: 900; color: #fff; text-shadow: 0 0 30px var(--accent), 0 5px 0 #000; animation: jl-count .55s cubic-bezier(.2, 1.6, .4, 1); margin-block-start: 30%; }
@keyframes jl-count { 0% { transform: scale(2.4); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.keys { text-align: center; color: var(--muted); font-size: .8rem; margin: 8px 0 0; }

@media (max-width: 720px) {
    .modes { grid-template-columns: 1fr; }
    .mode { flex-direction: row; text-align: start; padding: 10px 12px; }
    .mode svg { inline-size: 44px; block-size: 44px; flex: none; }
    .mode div { display: grid; gap: 2px; }
    .jets { grid-template-columns: repeat(2, 1fr); }
    .rivals { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .arenas { grid-template-columns: repeat(3, 1fr); }
    .statgrid { grid-template-columns: repeat(2, 1fr); }
    .side { padding: 3px 7px; }
    .side .who { font-size: .7rem; }
    .side .who .jn { display: none; }
    .mid { font-size: .95rem; }
    .mid small { display: none; }
    .icon { inline-size: 36px; flex-basis: 36px; }
    .pb.fire { inline-size: 64px; block-size: 64px; }
    .pb.bst, .pb.msl { inline-size: 46px; block-size: 46px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
    .banner.show { animation: none; opacity: 1; }
    .confetti { display: none; }
}
