/* Bubble Barrage. Logical properties, so RTL and LTR share one file; the stage itself stays LTR.
   Keyframes are prefixed bq- so they never clash with shared styles. */
:root {
    --bg: #0d0b24; --surface: #1a1740; --surface2: #262158; --border: #3f3a85; --text: #f6f4ff; --muted: #bcb6ea;
    --accent: #3a86ff; --accent2: #ffd23f; --pink: #ff5fa2; --mint: #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(--accent2); outline-offset: 2px; }
#game:focus { outline: none; }
[hidden] { display: none !important; }
.game { position: relative; max-inline-size: 1000px; margin-inline: auto; padding: 8px; }
svg { display: block; }

/* ---------- menus ---------- */
.screen {
    position: relative; overflow: hidden; border-radius: 18px; border: 1px solid var(--border); padding: 18px 14px 22px;
    background:
        radial-gradient(60% 45% at 50% 0%, rgba(58, 134, 255, .35), transparent 70%),
        radial-gradient(40% 40% at 90% 90%, rgba(255, 95, 162, .18), transparent 70%),
        radial-gradient(35% 35% at 8% 70%, rgba(255, 210, 63, .1), transparent 70%),
        linear-gradient(180deg, #1d1650, #0d0b24 85%);
    text-align: center; min-block-size: 460px;
}
.screen h2 { margin: 4px 0 10px; font-size: clamp(1.5rem, 4.6vw, 2.2rem); text-shadow: 0 3px 0 #000; }
.screen h2.win { color: var(--accent2); text-shadow: 0 3px 0 #000, 0 0 28px rgba(255, 210, 63, .55); }
.screen h2.lose { color: #ffb3c4; }
.screen .sub, .screen p { margin: 6px auto; max-inline-size: 600px; color: var(--muted); line-height: 1.5; }
.logo { position: relative; display: inline-flex; align-items: center; gap: 12px; margin-block-start: 6px; }
.logo .lb { position: relative; inline-size: 74px; block-size: 64px; }
.logo .lb canvas { position: absolute; animation: bq-bob 2.6s ease-in-out infinite; }
.logo .lb canvas:nth-child(1) { inset-inline-start: 0; inset-block-start: 6px; }
.logo .lb canvas:nth-child(2) { inset-inline-start: 38px; inset-block-start: 0; animation-delay: -.8s; }
.logo .lb canvas:nth-child(3) { inset-inline-start: 44px; inset-block-start: 36px; animation-delay: -1.6s; }
@keyframes bq-bob { 0%, 100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-7px) scale(1.06); } }
.logo h1 {
    margin: 0; font-size: clamp(2rem, 7.4vw, 3.4rem); font-weight: 900; letter-spacing: .01em;
    background: linear-gradient(180deg, #fff 30%, #bfe0ff); -webkit-background-clip: text; background-clip: text; color: transparent;
    filter: drop-shadow(0 4px 0 #000) drop-shadow(0 0 22px rgba(58, 134, 255, .6));
}
.floaters { position: absolute; inset: 0; pointer-events: none; }
.floaters canvas { position: absolute; opacity: .5; animation: bq-float 8s ease-in-out infinite; animation-delay: calc(var(--i) * -1s); }
.floaters canvas:nth-child(1) { inset-inline-start: 4%; inset-block-start: 8%; }
.floaters canvas:nth-child(2) { inset-inline-end: 6%; inset-block-start: 12%; }
.floaters canvas:nth-child(3) { inset-inline-start: 10%; inset-block-start: 46%; }
.floaters canvas:nth-child(4) { inset-inline-end: 9%; inset-block-start: 44%; }
.floaters canvas:nth-child(5) { inset-inline-start: 3%; inset-block-end: 8%; }
.floaters canvas:nth-child(6) { inset-inline-end: 4%; inset-block-end: 10%; }
.floaters canvas:nth-child(7) { inset-inline-start: 2%; inset-block-start: 28%; }
.floaters canvas:nth-child(8) { inset-inline-end: 2%; inset-block-start: 27%; }
@keyframes bq-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-22px); } }

.how { list-style: none; display: flex; justify-content: center; flex-wrap: wrap; gap: 8px 18px; margin: 10px auto 4px; padding: 0; color: var(--text); font-size: .92rem; }
.how li { display: inline-flex; align-items: center; gap: 6px; }
.how b { display: inline-grid; place-items: center; inline-size: 22px; block-size: 22px; border-radius: 50%; background: var(--accent); color: #fff; font-size: .8rem; }
.hi { position: relative; display: inline-block; inline-size: 30px; block-size: 26px; }
.hi::before, .hi::after { content: ""; position: absolute; border-radius: 50%; }
.hi-aim::before { inset-inline-start: 11px; inset-block-end: 0; inline-size: 9px; block-size: 9px; background: #ffc228; box-shadow: 0 0 6px #ffc228; animation: bq-shot 1.3s ease-in infinite; }
.hi-aim::after { inset-inline-start: 6px; inset-block-end: -2px; inline-size: 18px; block-size: 6px; border-radius: 4px; background: #a9bde6; }
@keyframes bq-shot { 0% { transform: translateY(0); opacity: 1; } 70% { transform: translateY(-20px); opacity: 1; } 100% { transform: translateY(-20px) scale(1.8); opacity: 0; } }
.hi-match::before { inset-block-start: 7px; inset-inline-start: 0; inline-size: 12px; block-size: 12px; background: #ff3d5a; box-shadow: 9px 0 0 #ff3d5a, 18px 0 0 #ff3d5a; animation: bq-pulse 1.3s ease-in-out infinite; }
@keyframes bq-pulse { 50% { transform: scale(.75); opacity: .5; } }
.hi-drop::before { inset-inline-start: 9px; inset-block-start: 0; inline-size: 12px; block-size: 12px; background: #25cf72; animation: bq-fallI 1.4s ease-in infinite; }
@keyframes bq-fallI { 0%, 25% { transform: translateY(0); } 100% { transform: translateY(16px); opacity: 0; } }

.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 16px auto 4px; max-inline-size: 820px; position: relative; }
.mode {
    border-radius: 16px; border: 2px solid var(--border); background: rgba(26, 23, 64, .9); padding: 14px 10px; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; gap: 6px; transition: transform .15s, border-color .15s, box-shadow .15s;
    animation: bq-rise .45s both; animation-delay: calc(var(--n, 0) * 70ms);
}
.mode:nth-child(2) { --n: 1; } .mode:nth-child(3) { --n: 2; }
.mode:hover, .mode:focus-visible { transform: translateY(-4px); border-color: var(--accent); box-shadow: 0 10px 26px rgba(58, 134, 255, .3); }
.mode b { font-size: 1.15rem; }
.mode small { color: var(--muted); line-height: 1.4; font-size: .86rem; }
.mode em { font-style: normal; display: inline-flex; align-items: center; gap: 4px; font-weight: 800; color: var(--accent2); font-size: .9rem; }
.mode em svg, .tot svg { inline-size: 16px; block-size: 16px; fill: var(--accent2); }
.mi { display: grid; place-items: center; block-size: 62px; }
@keyframes bq-rise { from { opacity: 0; transform: translateY(14px); } }

.top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.top h2 { margin: 0; }
.tot { display: inline-flex; align-items: center; gap: 4px; font-weight: 800; color: var(--accent2); }
.btn {
    border: 2px solid var(--border); background: var(--surface2); border-radius: 12px; padding: 11px 22px; cursor: pointer; font-weight: 800;
    transition: transform .12s, background .12s;
}
.btn:hover { transform: translateY(-2px); background: #332c72; }
.btn.primary { background: linear-gradient(180deg, #5aa0ff, #2563eb); border-color: #8ec0ff; color: #fff; box-shadow: 0 6px 0 #173d91; }
.btn.primary:active { transform: translateY(3px); box-shadow: 0 3px 0 #173d91; }
.btn.small { padding: 7px 14px; font-size: .9rem; }

.worlds { display: grid; gap: 12px; margin-block-start: 14px; }
.world { position: relative; border-radius: 16px; border: 2px solid var(--border); overflow: hidden; background: rgba(26, 23, 64, .9); animation: bq-rise .4s both; animation-delay: calc(var(--i) * 60ms); }
.world header { position: relative; display: flex; align-items: center; gap: 10px; padding: 10px 14px; min-block-size: 54px; }
.world header canvas { position: absolute; inset: 0; inline-size: 100% !important; block-size: 100% !important; opacity: .85; }
.world header b, .world header .tot { position: relative; text-shadow: 0 2px 4px rgba(0, 0, 0, .7); }
.world header b { flex: 1; text-align: start; font-size: 1.1rem; }
.world.locked header canvas { filter: grayscale(.9) brightness(.5); }
.lvls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 10px; }
.lvl {
    position: relative; border-radius: 12px; border: 2px solid var(--border); background: var(--surface2); padding: 8px 6px; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; gap: 3px; transition: transform .15s, border-color .15s;
}
.lvl:hover, .lvl:focus-visible { transform: translateY(-3px); border-color: var(--accent2); }
.lvl > b { font-size: 1.3rem; font-weight: 900; }
.lvl small { color: var(--muted); font-size: .74rem; line-height: 1.3; }
.lvl.locked { cursor: not-allowed; opacity: .6; }
.lvl .lock { inline-size: 22px; block-size: 22px; }
.lvl.nope { animation: bq-nope .35s; }
@keyframes bq-nope { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.stars { display: inline-flex; gap: 2px; }
.stars i svg { inline-size: 16px; block-size: 16px; fill: rgba(255, 255, 255, .18); }
.stars i.on svg { fill: var(--accent2); filter: drop-shadow(0 0 6px rgba(255, 210, 63, .7)); }
.stars.big { display: flex; justify-content: center; gap: 10px; margin: 2px 0 4px; }
.stars.big i svg { inline-size: 52px; block-size: 52px; }
.stars.big i.pop { animation: bq-star .5s cubic-bezier(.3, 1.8, .5, 1); }
@keyframes bq-star { from { transform: scale(0) rotate(-90deg); } }

.cannons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-inline-size: 640px; margin: 12px auto 0; }
.cannon {
    position: relative; border-radius: 14px; border: 2px solid var(--border); background: rgba(26, 23, 64, .92); padding: 10px; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; gap: 4px; transition: transform .15s, border-color .15s;
}
.cannon:hover { transform: translateY(-3px); }
.cannon.sel { border-color: var(--mint); box-shadow: 0 0 0 3px rgba(74, 222, 128, .25); }
.cannon small { color: var(--muted); }
.cannon.sel small { color: var(--mint); font-weight: 800; }
.cannon.locked { cursor: not-allowed; }
.cannon.locked canvas { opacity: .25; }
.cannon .lock { position: absolute; inset-block-start: 36px; inset-inline: 0; margin-inline: auto; inline-size: 28px; block-size: 28px; }

/* results */
.result { position: relative; z-index: 1; }
.result .place { margin: 0 auto; font-weight: 700; color: var(--muted); }
.total { display: flex; flex-direction: column; align-items: center; line-height: 1; margin: 4px 0; }
.total small { color: var(--muted); font-weight: 700; }
.total b { font-size: clamp(2.4rem, 9vw, 3.6rem); font-weight: 900; text-shadow: 0 4px 0 #000; font-variant-numeric: tabular-nums; }
.goals { font-size: .9rem; }
.record { display: inline-block; padding: 6px 16px; border-radius: 30px; background: linear-gradient(90deg, #ffd23f, #ff8a5c); color: #3a1300 !important; font-weight: 900; animation: bq-rec .9s ease-in-out infinite alternate; }
@keyframes bq-rec { to { transform: scale(1.08); box-shadow: 0 0 24px rgba(255, 210, 63, .6); } }
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; max-inline-size: 640px; margin: 12px auto; }
.stat { background: rgba(255, 255, 255, .05); border: 1px solid var(--border); border-radius: 12px; padding: 8px 4px; animation: bq-rise .4s both; }
.stat:nth-child(2) { animation-delay: .06s; } .stat:nth-child(3) { animation-delay: .12s; } .stat:nth-child(4) { animation-delay: .18s; } .stat:nth-child(5) { animation-delay: .24s; }
.stat small { display: block; color: var(--muted); font-size: .76rem; }
.stat b { font-size: 1.3rem; }
.note { color: #ffb3c4 !important; }
.unl p { color: var(--mint) !important; font-weight: 800; animation: bq-rise .4s both; }
.btns { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin-block-start: 14px; }
.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 2; }
.confetti i { position: absolute; inset-block-start: -12px; inset-inline-start: var(--x); inline-size: 9px; block-size: 14px; background: var(--c); border-radius: 2px; animation: bq-fall var(--t) var(--d) ease-in forwards; }
@keyframes bq-fall { to { transform: translateY(560px) rotate(var(--r)); opacity: .2; } }

/* ---------- play ---------- */
.hud { display: flex; align-items: center; gap: 10px; padding: 6px 4px 8px; }
.icon { flex: none; inline-size: 40px; block-size: 40px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; display: grid; place-items: center; padding: 8px; }
.icon svg { inline-size: 22px; block-size: 22px; }
.score { display: flex; align-items: baseline; gap: 6px; font-size: 1.45rem; font-weight: 900; min-inline-size: 92px; font-variant-numeric: tabular-nums; }
.score em { font-style: normal; font-size: .9rem; color: var(--mint); font-weight: 900; }
.score em.hot { color: var(--accent2); text-shadow: 0 0 10px rgba(255, 210, 63, .7); }
.bump { animation: bq-bump .25s; display: inline-block; }
@keyframes bq-bump { 50% { transform: scale(1.25); color: var(--accent2); } }
.goal { flex: 1; display: flex; align-items: center; gap: 10px; min-inline-size: 90px; }
.goal .gl { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; font-weight: 800; font-size: .92rem; }
.goal .gl svg { inline-size: 20px; block-size: 20px; color: #9fd8ff; }
.goal .bar { position: relative; flex: 1; block-size: 10px; border-radius: 6px; background: rgba(255, 255, 255, .1); }
.goal .bar i { display: block; block-size: 100%; inline-size: 0; background: linear-gradient(90deg, #3a86ff, #ffd23f); border-radius: 6px; transition: inline-size .25s; }
.goal .bar i.hot { background: linear-gradient(90deg, #ff8a5c, #ff3d5a); }
.goal .gs { position: absolute; inset-block-start: -6px; inset-inline-start: var(--p); transform: translateX(-50%); inline-size: 22px; block-size: 22px; }
[dir="rtl"] .goal .gs { transform: translateX(50%); }
.goal .gs svg { inline-size: 22px; block-size: 22px; fill: #3d3a6e; stroke: #000; stroke-width: 1; }
.goal .gs.on svg { fill: var(--accent2); animation: bq-star .45s cubic-bezier(.3, 1.8, .5, 1); filter: drop-shadow(0 0 6px rgba(255, 210, 63, .8)); }
.shots { display: flex; align-items: center; gap: 6px; font-size: 1.3rem; font-weight: 900; padding: 4px 10px; border-radius: 12px; background: rgba(255, 255, 255, .06); border: 1px solid var(--border); }
.shots .bi { inline-size: 20px; block-size: 20px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff 0 12%, #6fb0ff 30%, #1d4fbf 100%); }
.shots.low { border-color: #ff5a6e; }
.shots.low b { color: #ff8a9a; animation: bq-bump .6s infinite; }

.stage { position: relative; display: flex; justify-content: center; touch-action: none; border-radius: 16px; overflow: hidden; background: #000; }
.stage canvas { display: block; border-radius: 16px; cursor: crosshair; }
.banner {
    position: absolute; inset-inline: 0; inset-block-start: 36%; margin-inline: auto; inline-size: max-content; max-inline-size: 92%;
    text-align: center; pointer-events: none; opacity: 0; transform: scale(.6);
    padding: 10px 22px; border-radius: 16px; background: rgba(13, 11, 36, .8); border: 2px solid rgba(255, 255, 255, .2);
}
.banner.show { animation: bq-ban 1.2s ease-out forwards; }
.banner b { display: block; font-size: clamp(1.4rem, 5vw, 2.4rem); font-weight: 900; letter-spacing: .02em; text-shadow: 0 3px 0 #000; }
.banner small { display: block; font-size: .95rem; color: var(--muted); font-weight: 700; max-inline-size: 360px; }
.banner.go b { color: var(--accent2); font-size: clamp(2rem, 8vw, 3.2rem); }
.banner.fire { border-color: #ff8a2a; } .banner.fire b { color: #ffb347; text-shadow: 0 3px 0 #000, 0 0 20px rgba(255, 120, 30, .8); }
.banner.blue { border-color: #62c8ff; } .banner.blue b { color: #aee6ff; }
.banner.warn { border-color: #ff6b81; } .banner.warn b { color: #ffb3a1; }
.banner.tip { inset-block-start: auto; inset-block-end: 130px; padding: 8px 16px; border-color: var(--accent2); }
.banner.tip small { color: #fff; font-size: 1rem; }
.banner.tip.show { animation-name: bq-tip; }
@keyframes bq-ban { 0% { opacity: 0; transform: scale(.6); } 15% { opacity: 1; transform: scale(1.08); } 25% { transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: scale(1) translateY(-14px); } }
@keyframes bq-tip { 0% { opacity: 0; transform: translateY(10px); } 10%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }
.hint {
    position: absolute; inset-inline: 0; inset-block-end: 130px; margin-inline: auto; inline-size: max-content; max-inline-size: 86%;
    padding: 8px 16px; border-radius: 30px; background: rgba(13, 11, 36, .85); border: 2px solid var(--accent2);
    font-weight: 800; pointer-events: none; text-align: center; animation: bq-rise .4s both;
}
.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(8, 6, 24, .65); backdrop-filter: blur(3px); }
.overlay .card { display: flex; flex-direction: column; gap: 10px; min-inline-size: 220px; padding: 20px; border-radius: 18px; background: var(--surface); border: 1px solid var(--border); text-align: center; }
.overlay h2 { margin: 0 0 6px; }
.keys { margin: 8px 0 0; text-align: center; color: var(--muted); font-size: .85rem; }

@media (max-width: 720px) {
    .modes { grid-template-columns: 1fr; max-inline-size: 420px; }
    .mode { flex-direction: row; flex-wrap: wrap; text-align: start; justify-content: flex-start; padding: 10px 12px; gap: 4px 10px; }
    .mode .mi { block-size: 50px; inline-size: 60px; }
    .mode b { flex: 1; }
    .mode small { flex-basis: 100%; }
    .lvls { grid-template-columns: repeat(2, 1fr); }
    .cannons { grid-template-columns: repeat(2, 1fr); }
    .stats { grid-template-columns: repeat(3, 1fr); }
    .hud { gap: 6px; flex-wrap: wrap; }
    .goal { order: 9; flex-basis: 100%; }
    .score { font-size: 1.2rem; min-inline-size: 0; flex: 1; }
    .shots { font-size: 1.1rem; padding: 3px 8px; }
    .icon { inline-size: 36px; block-size: 36px; padding: 7px; }
    .banner.tip, .hint { inset-block-end: 110px; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01s !important; animation-iteration-count: 1 !important; transition: none !important; }
}
/* the stage is LTR for the canvas, but its Arabic messages read right to left */
[dir="rtl"] .stage .banner, [dir="rtl"] .stage .hint, [dir="rtl"] .stage .overlay { direction: rtl; }
