/* Star Squadron. Logical properties, so RTL and LTR share one file; the space view stays LTR. */
:root {
    --bg: #07061a; --surface: #12113a; --surface2: #1b1950; --border: #2c2a6e; --text: #f1f0ff; --muted: #a9a6d8;
    --accent: #5cf2ff; --accent2: #ff4fa0; --gold: #ffcf4a; --ink: #090722; --ok: #4ade80; --bad: #ff6b81;
    --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: 420px; 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); white-space: nowrap; }
.stat b { font-size: 1.1rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat b.bump { animation: bump .25s ease-out; }
@keyframes bump { 40% { transform: scale(1.18); color: var(--accent); } }
.pips { display: flex; gap: 3px; align-items: center; block-size: 1.4em; }
.pips i { inline-size: 9px; block-size: 13px; border-radius: 3px; background: #2a2860; transition: background-color .2s; }
.pips i.on { background: var(--accent); box-shadow: 0 0 6px rgba(92, 242, 255, .7); }
.pips.low i.on { background: var(--bad); box-shadow: 0 0 6px rgba(255, 107, 129, .8); }
.pips i.sh { background: transparent; border: 2px solid #8fd8ff; border-radius: 50%; inline-size: 12px; block-size: 12px; box-shadow: 0 0 6px rgba(143, 216, 255, .8); }
.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 space view is portrait (3:5) and fits the width. */
.stage {
    position: relative; inline-size: 100%; aspect-ratio: 3 / 5; border-radius: 16px; overflow: hidden;
    background: #070620; border: 1px solid var(--border); touch-action: none; direction: ltr;
}
.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: 24%; display: flex; flex-direction: column; align-items: center; gap: 6px;
    pointer-events: none; opacity: 0; transform: scale(.9); transition: opacity .25s, transform .25s;
}
.banner.on { opacity: 1; transform: none; }
.banner span {
    background: rgba(9, 7, 34, .82); 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(92, 242, 255, .25); text-align: center;
}
.banner small { color: var(--muted); font-weight: 700; font-size: .85rem; text-shadow: 0 1px 4px #000; }
.banner.boss span { border-color: var(--bad); color: #ffd8e0; box-shadow: 0 0 26px rgba(255, 80, 120, .5); animation: warn .5s steps(2) infinite; }
.banner.gold span { border-color: var(--gold); color: #fff1c9; box-shadow: 0 0 22px rgba(255, 207, 74, .35); }
@keyframes warn { 50% { border-color: transparent; } }

.overlay {
    position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: safe center;
    gap: 10px; padding: 16px; text-align: center; background: rgba(6, 5, 26, .7); backdrop-filter: blur(3px);
    overflow-y: auto; direction: inherit;
}
:root[dir="rtl"] .overlay, :root[dir="rtl"] .banner, :root[dir="rtl"] .bar { direction: rtl; }
.overlay.on { display: flex; }
.overlay h2 { margin: 0; font-size: 1.7rem; letter-spacing: .02em; text-shadow: 0 0 18px rgba(92, 242, 255, .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(92, 242, 255, .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); font-variant-numeric: tabular-nums; }
.badge { display: inline-block; padding: 3px 12px; border-radius: 999px; background: var(--gold); color: var(--ink); font-weight: 800; font-size: .85rem; }

.ships { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; inline-size: 100%; }
.ship {
    display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; cursor: pointer;
    background: rgba(18, 17, 58, .85); border: 2px solid var(--border); border-radius: 14px; min-inline-size: 0;
}
.ship canvas { inline-size: 56px; block-size: 56px; }
.ship b { font-size: .88rem; }
.ship small { font-size: .7rem; color: var(--muted); }
.ship .meter { display: flex; gap: 2px; margin-block-start: 2px; }
.ship .meter i { inline-size: 10px; block-size: 4px; border-radius: 2px; background: #2a2860; }
.ship .meter i.on { background: var(--accent); }
.ship .meter.hp i.on { background: var(--ok); }
.ship[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 16px rgba(92, 242, 255, .35); background: rgba(27, 25, 80, .95); }
.ship .mk { font-size: .62rem; color: var(--muted); }

.legend { display: grid; grid-template-columns: repeat(3, auto); gap: 6px 12px; font-size: .78rem; color: var(--muted); text-align: start; }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend i {
    inline-size: 16px; block-size: 16px; border-radius: 50%; display: inline-grid; place-items: center; flex: none;
    font-style: normal; font-size: .62rem; font-weight: 900; color: var(--ink);
}
.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, var(--accent), #8a6bff); color: var(--ink); box-shadow: 0 6px 22px rgba(92, 242, 255, .3);
}
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); box-shadow: none; }

/* Inside the view, bottom corners: weapon level and the overdrive button. */
.bar {
    position: absolute; inset-inline: 10px; inset-block-end: 10px; display: flex; align-items: flex-end;
    justify-content: space-between; gap: 10px; pointer-events: none;
}
.power {
    display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 5px 9px;
    background: rgba(9, 7, 34, .55); border: 1px solid rgba(255, 255, 255, .12); border-radius: 12px;
}
.lv { display: flex; gap: 3px; }
.lv i { inline-size: 12px; block-size: 7px; border-radius: 3px; background: rgba(255, 255, 255, .16); transition: background-color .2s; }
.lv i.on { background: var(--w, var(--accent)); box-shadow: 0 0 6px var(--w, var(--accent)); }
.od {
    --p: 0; pointer-events: auto; position: relative; display: grid; place-items: center;
    inline-size: 66px; block-size: 66px; border-radius: 50%; border: 0; padding: 0; cursor: pointer; touch-action: none;
    background: conic-gradient(var(--gold) calc(var(--p) * 1%), rgba(255, 255, 255, .14) 0);
    font-size: .7rem; font-weight: 900; transition: transform .05s; box-shadow: 0 4px 16px rgba(0, 0, 0, .35);
}
.od::before { content: ""; position: absolute; inset: 5px; border-radius: 50%; background: radial-gradient(circle at 40% 35%, #3b2f7d, #140f3c); }
.od .label { position: relative; max-inline-size: 52px; line-height: 1.1; }
.od.ready { animation: glow 1s ease-in-out infinite; }
.od.ready::before { background: radial-gradient(circle at 40% 35%, #ffd965, #c46a00); }
.od.ready .label { color: var(--ink); }
.od.active::before { background: radial-gradient(circle at 40% 35%, #fff4c0, #ffb300); }
.od:active { transform: scale(.94); }
@keyframes glow { 50% { box-shadow: 0 0 26px rgba(255, 207, 74, .8); } }

.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: 380px) {
    .overlay .legend { display: none; }
    .overlay { gap: 7px; padding: 10px; }
    .overlay h2 { font-size: 1.4rem; }
    .overlay .big { font-size: 2.4rem; }
    .ship canvas { inline-size: 44px; block-size: 44px; }
}

@media (prefers-reduced-motion: reduce) { .banner, .od, .lv i { transition: none; animation: none; } .stat b.bump, .banner.boss span, .od.ready { animation: none; } }

/* ---------- polish: entrances and feedback (all of it off with reduced motion) ---------- */
.overlay.on > * { animation: rise .42s cubic-bezier(.2, .9, .3, 1.2) both; }
.overlay.on > :nth-child(2) { animation-delay: .06s; }
.overlay.on > :nth-child(3) { animation-delay: .12s; }
.overlay.on > :nth-child(4) { animation-delay: .18s; }
.overlay.on > :nth-child(n+5) { animation-delay: .24s; }
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.96); } }
.overlay h2 {
    background: linear-gradient(180deg, #ffffff 30%, #a9f7ff 70%, #c9a8ff); -webkit-background-clip: text; background-clip: text; color: transparent;
    filter: drop-shadow(0 0 14px rgba(92, 242, 255, .5)); text-shadow: none;
}
.overlay .btn:not(.ghost) { animation: rise .42s .2s cubic-bezier(.2, .9, .3, 1.2) both, glowpulse 2.2s .8s ease-in-out infinite; }
@keyframes glowpulse { 50% { box-shadow: 0 6px 30px rgba(92, 242, 255, .6), 0 0 0 4px rgba(92, 242, 255, .14); } }
.overlay .big.landed { animation: land .38s ease-out; }
@keyframes land { 40% { transform: scale(1.16); color: #fff; text-shadow: 0 0 30px rgba(92, 242, 255, .9); } }
.overlay .badge { animation: rise .4s .2s both, badge 1.4s .6s ease-in-out infinite; }
@keyframes badge { 50% { box-shadow: 0 0 22px rgba(255, 207, 74, .85); transform: scale(1.06); } }
.ship { transition: transform .18s, border-color .18s, box-shadow .18s; }
.ship:hover { transform: translateY(-2px); }
.ship[aria-pressed="true"] canvas { animation: hover 2.4s ease-in-out infinite; }
@keyframes hover { 50% { transform: translateY(-4px); } }
.banner.on span { animation: pop .38s cubic-bezier(.2, .9, .3, 1.4); position: relative; overflow: hidden; }
.banner.on span::after {
    content: ""; position: absolute; inset: 0; transform: translateX(-120%);
    background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, .35) 50%, transparent 70%); animation: sheen .9s .15s ease-out forwards;
}
.banner.boss.on span { animation: pop .38s cubic-bezier(.2, .9, .3, 1.4), warn .5s steps(2) infinite; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
@keyframes sheen { to { transform: translateX(120%); } }
.stat.hurt { animation: hurt .45s ease-out; }
@keyframes hurt {
    0%, 100% { transform: none; }
    20% { transform: translateX(-4px); background: #4a1630; border-color: var(--bad); }
    40% { transform: translateX(4px); }
    60% { transform: translateX(-2px); }
}
.pips.low i.on { animation: lowpulse .8s ease-in-out infinite; }
@keyframes lowpulse { 50% { opacity: .45; } }
.lv.up i.on { animation: lvup .6s ease-out; }
@keyframes lvup { 30% { background: #fff; box-shadow: 0 0 12px #fff; } }

@media (prefers-reduced-motion: reduce) {
    .overlay.on > *, .overlay .btn:not(.ghost), .overlay .big.landed, .overlay .badge, .ship[aria-pressed="true"] canvas,
    .banner.on span, .banner.on span::after, .banner.boss.on span, .stat.hurt, .pips.low i.on, .lv.up i.on { animation: none; }
    .banner.on span::after { display: none; }
    .ship, .ship:hover { transition: none; transform: none; }
}

/* ---------- polish 2: pilot rank on the end screen, a roomier HUD on small phones ---------- */
.rank { display: inline-flex; align-items: center; gap: 8px; padding: 5px 14px; border-radius: 999px; font-size: .9rem; color: var(--muted);
    background: rgba(27, 25, 80, .8); border: 1px solid var(--border); }
.rank b { color: var(--text); }
.rank .stars { display: inline-flex; gap: 3px; }
.rank .stars i { inline-size: 12px; block-size: 12px; background: var(--gold); clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }
.rank.r3, .rank.r4 { border-color: var(--gold); box-shadow: 0 0 16px rgba(255, 207, 74, .3); }
.rank.r4 b { color: var(--gold); }
.overlay .row b.landed { animation: land .38s ease-out; display: inline-block; }
@media (max-width: 440px) {
    .hud { gap: 5px; }
    .stat { padding-inline: 2px; }
    .pips { gap: 2px; }
    .pips i { inline-size: 7px; }
    .hud .icon { inline-size: 38px; block-size: 38px; border-radius: 10px; }
    .hud .icon svg { inline-size: 19px; block-size: 19px; }
}
@media (prefers-reduced-motion: reduce) { .overlay .row b.landed { animation: none; } }
