/* Missile Dodge. Logical properties, so RTL and LTR share one file; the sky view stays LTR. */
:root {
    --bg: #120f2e; --surface: #1d1946; --surface2: #282260; --border: #383070; --text: #f6f1ff; --muted: #b6acd8;
    --accent: #ff8a4c; --accent2: #ff4d6d; --gold: #ffc847; --ink: #04121a; --ok: #4ade80; --bad: #ff6b6b;
    --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: 520px; margin-inline: auto; padding: 8px; }

.hud { display: flex; align-items: center; gap: 8px; margin-block-end: 8px; }
.stat {
    flex: 1; min-inline-size: 0; display: flex; flex-direction: column; align-items: center;
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding-block: 4px;
}
.stat.wide { flex: 1.6; }
.stat .k, .power .k { font-size: .72rem; color: var(--muted); }
.stat b { font-size: 1.1rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat b.bump { animation: bump .25s ease-out; }
.stat b.hot { color: var(--gold); text-shadow: 0 0 10px rgba(255, 200, 71, .6); }
@keyframes bump { 40% { transform: scale(1.18); color: var(--accent); } }
.icon {
    flex: none; inline-size: 44px; block-size: 44px; border-radius: 12px; cursor: pointer;
    background: var(--surface); border: 1px solid var(--border); display: grid; place-items: center; padding: 0;
}
.icon svg { inline-size: 22px; block-size: 22px; }

/* The sky view is 4:5 and fits the width. */
.stage {
    position: relative; inline-size: 100%; aspect-ratio: 4 / 5; border-radius: 16px; overflow: hidden;
    background: #1a2a6c; border: 1px solid var(--border); touch-action: none;
}
.stage canvas { display: block; inline-size: 100%; block-size: 100%; touch-action: none; cursor: crosshair; }
.stage.playing canvas { cursor: none; }

.banner {
    position: absolute; inset-inline: 12px; inset-block-start: 22%; display: flex; justify-content: center;
    pointer-events: none; opacity: 0; transform: scale(.9); transition: opacity .25s, transform .25s;
}
.banner.on { opacity: 1; transform: none; }
.banner span {
    background: rgba(18, 12, 46, .8); border: 1px solid var(--accent); border-radius: 999px; padding: 8px 18px;
    font-weight: 800; font-size: 1.05rem; letter-spacing: .02em; box-shadow: 0 0 22px rgba(255, 138, 76, .25);
}
.banner.warn span { border-color: var(--bad); color: #ffd6d6; box-shadow: 0 0 26px rgba(255, 80, 80, .45); }
.banner.gold span { border-color: var(--gold); color: #fff1c9; box-shadow: 0 0 22px rgba(255, 200, 71, .35); }

.overlay {
    position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: safe center;
    gap: 10px; padding: 18px; text-align: center; background: rgba(14, 10, 40, .62); backdrop-filter: blur(3px);
    overflow-y: auto;
}
.overlay.on { display: flex; }
.overlay h2 { margin: 0; font-size: 1.7rem; letter-spacing: .02em; text-shadow: 0 0 18px rgba(255, 138, 76, .55); }
.overlay p { margin: 0; color: var(--muted); max-inline-size: 34ch; }
.overlay .big { font-size: 3rem; font-weight: 900; color: var(--accent); font-variant-numeric: tabular-nums; line-height: 1.05; text-shadow: 0 0 20px rgba(255, 138, 76, .45); }
.overlay .row { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; color: var(--muted); font-size: .92rem; }
.overlay .row b { color: var(--text); }
.how { margin: 0; padding-inline-start: 1.3em; max-inline-size: 38ch; text-align: start; font-size: .9rem; color: var(--text); display: grid; gap: 4px; }
.how li::marker { color: var(--accent); font-weight: 800; }
.how 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); text-align: center;
}
.legend { display: grid; grid-template-columns: repeat(2, auto); gap: 6px 16px; font-size: .82rem; color: var(--muted); text-align: start; }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend i { inline-size: 12px; block-size: 12px; border-radius: 4px; display: inline-block; flex: none; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-block-start: 4px; }
.btn {
    border: 0; border-radius: 12px; padding: 12px 24px; font-weight: 800; cursor: pointer; min-block-size: 46px;
    background: linear-gradient(135deg, #ffb35c, var(--accent2)); color: var(--ink); box-shadow: 0 6px 22px rgba(255, 138, 76, .3);
}
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); box-shadow: none; }
.note { font-size: .9rem; }
.note.ok { color: var(--ok); }
.note.bad { color: var(--bad); }

.banner.cool span { border-color: #8ff6ff; color: #e2fdff; box-shadow: 0 0 22px rgba(143, 246, 255, .35); }

/* Afterburner: a round button in the bottom corner with the fuel left as a ring. */
.boost {
    position: absolute; inset-inline-end: 12px; inset-block-end: 12px; inline-size: 76px; block-size: 76px; border-radius: 50%;
    border: 0; padding: 0; cursor: pointer; touch-action: none; display: grid; place-items: center;
    background: radial-gradient(circle at 40% 35%, rgba(255, 170, 110, .5), rgba(120, 30, 60, .55));
    box-shadow: 0 4px 16px rgba(0, 0, 0, .35); font-size: .78rem; font-weight: 900; letter-spacing: .03em;
    transition: transform .05s, opacity .15s;
}
.boost .ring {
    --f: 1; position: absolute; inset: 0; border-radius: 50%;
    background: conic-gradient(var(--gold) calc(var(--f) * 360deg), rgba(255, 255, 255, .14) 0);
    -webkit-mask: radial-gradient(circle, transparent 31px, #000 32px); mask: radial-gradient(circle, transparent 31px, #000 32px);
}
.boost .label { position: relative; }
.boost.on { transform: scale(.93); background: radial-gradient(circle at 40% 35%, rgba(190, 245, 255, .7), rgba(40, 120, 200, .6)); }
.boost.empty { opacity: .5; }
@media (hover: hover) and (pointer: fine) { .boost { opacity: .75; } }

.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);
}
.mode { margin: 8px 0 0; min-block-size: 1.2em; text-align: center; font-size: .85rem; color: var(--muted); }

@media (max-width: 380px) {
    .overlay .legend { display: none; }
    .overlay { gap: 8px; padding: 12px; }
    .overlay h2 { font-size: 1.4rem; }
    .overlay .big { font-size: 2.4rem; }
}

/* ---------- polish: banners pop in with a glint, a new best glows ---------- */
.banner span { position: relative; overflow: hidden; }
.banner.on span { animation: md-pop .4s cubic-bezier(.2, 1.5, .4, 1) both; }
.banner.on span::after {
    content: ""; position: absolute; inset-block: 0; inset-inline-start: -40%; inline-size: 30%;
    background: linear-gradient(100deg, transparent, rgba(255, 255, 255, .4), transparent); animation: md-glint .9s .12s ease-out both;
}
:root[dir="rtl"] .banner.on span::after { animation-name: md-glint-rtl; }
.banner.warn.on span { animation: md-pop .4s cubic-bezier(.2, 1.5, .4, 1) both, md-alarm .5s .4s ease-in-out 2; }
@keyframes md-pop { from { transform: scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes md-glint { from { transform: translateX(0); } to { transform: translateX(560%); } }
@keyframes md-glint-rtl { from { transform: translateX(0); } to { transform: translateX(-560%); } }
@keyframes md-alarm { 50% { box-shadow: 0 0 36px rgba(255, 80, 80, .8); } }
.overlay h2, .overlay .big { animation: md-pop .45s cubic-bezier(.2, 1.5, .4, 1) both; }
.overlay .big.best { color: #fff1c9; animation: md-pop .45s cubic-bezier(.2, 1.5, .4, 1) both, md-best 1.4s .5s ease-in-out infinite; }
@keyframes md-best { 50% { text-shadow: 0 0 34px rgba(255, 210, 63, .95), 0 0 8px #fff; } }
.boost.on .ring { filter: drop-shadow(0 0 8px rgba(160, 230, 255, .9)); }

@media (prefers-reduced-motion: reduce) {
    .banner, .boost { transition: none; }
    .stat b.bump, .banner.on span, .banner.on span::after, .banner.warn.on span, .overlay h2, .overlay .big, .overlay .big.best { animation: none; }
}

/* ---------- polish 2: music button, record moments, rank and record stamp on the end card ---------- */
@media (max-width: 420px) {
    .hud { gap: 6px; }
    .icon { inline-size: 38px; block-size: 38px; border-radius: 11px; }
    .icon svg { inline-size: 20px; block-size: 20px; }
    .stat .k { font-size: .66rem; }
    .stat b { font-size: 1rem; }
}
.stat.rec { animation: md-rec 1.2s ease-out; }
@keyframes md-rec {
    0%, 100% { box-shadow: none; }
    25% { border-color: var(--gold); box-shadow: 0 0 18px rgba(255, 200, 71, .7); transform: scale(1.06); }
}
.banner.record span { border-color: var(--gold); color: #fff3cf; background: linear-gradient(135deg, rgba(90, 58, 0, .85), rgba(18, 12, 46, .85)); box-shadow: 0 0 30px rgba(255, 200, 71, .55); }
.overlay .rank { margin: -4px 0 0; }
.overlay .rank span {
    display: inline-block; padding: 3px 12px; border-radius: 999px; font-size: .82rem; font-weight: 800; letter-spacing: .03em;
    color: #fff1c9; background: rgba(255, 200, 71, .14); border: 1px solid rgba(255, 200, 71, .45);
}
.overlay .big { position: relative; }
.overlay .stamp {
    position: absolute; inset-block-start: -12px; inset-inline-end: -64px; padding: 3px 9px; border-radius: 8px;
    font-size: .74rem; font-weight: 900; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; line-height: 1.3;
    color: #2a1a00; background: linear-gradient(135deg, #ffe08a, #ffb020); box-shadow: 0 4px 14px rgba(255, 176, 32, .5);
    transform: rotate(-12deg) scale(0); opacity: 0; text-shadow: none;
}
.overlay .stamp.on { opacity: 1; transform: rotate(-12deg) scale(1); animation: md-stamp .45s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes md-stamp { from { transform: rotate(-30deg) scale(2.4); opacity: 0; } }
@media (max-width: 380px) { .overlay .stamp { inset-inline-end: -46px; inset-block-start: auto; inset-block-end: -6px; } }
[dir="rtl"] .overlay .stamp { transform: rotate(12deg) scale(0); }
[dir="rtl"] .overlay .stamp.on { transform: rotate(12deg) scale(1); animation-name: md-stamp-rtl; }
@keyframes md-stamp-rtl { from { transform: rotate(30deg) scale(2.4); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .stat.rec, .overlay .stamp.on { animation: none; } }
