/* Header Duel. Logical properties, so RTL and LTR share one file; the pitch itself stays LTR. */
:root {
    --bg: #07101f; --surface: #0f1d36; --surface2: #16284a; --border: #29426e; --text: #f1f6ff; --muted: #a3b5d6;
    --accent: #4ade80; --accent2: #ffd166; --hot: #ff4f6d; --p1: #38e1ff; --p2: #ff4fa3; --ink: #04101c;
    --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: 1040px; margin-inline: auto; padding: 8px; }
.pf { display: inline-block; line-height: 0; }

/* ---------- menus ---------- */
.screen {
    position: relative; overflow: hidden; border-radius: 18px; border: 1px solid var(--border); padding: 18px 14px 22px;
    background:
        radial-gradient(80% 50% at 50% 0%, rgba(74, 222, 128, .2), transparent 70%),
        repeating-linear-gradient(90deg, rgba(255, 255, 255, .025) 0 60px, transparent 60px 120px),
        linear-gradient(180deg, #10264a, #07101f 80%);
    text-align: center; min-block-size: 440px;
}
.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, 209, 102, .6); }
.screen h2.lose { color: #ffb3c4; }
.screen h3 { margin: 14px 0 6px; font-size: .92rem; color: var(--muted); }
.screen .sub, .screen p { margin: 6px auto; max-inline-size: 580px; color: var(--muted); line-height: 1.5; }
.hero-strip { display: flex; justify-content: center; gap: 2px; margin-block: 2px -6px; }
.hero-strip canvas { inline-size: min(74px, 14.5vw) !important; block-size: auto !important; }
.hero-strip .pf { animation: hd-bob 1.6s ease-in-out infinite; animation-delay: calc(var(--i) * -.27s); }
@keyframes hd-bob { 50% { transform: translateY(-7px); } }
.logo { display: inline-flex; align-items: center; gap: 12px; }
.logo h1 { margin: 0; font-size: clamp(2rem, 7vw, 3.2rem); font-weight: 900; letter-spacing: .01em; text-shadow: 0 4px 0 #000, 0 0 30px rgba(74, 222, 128, .45); }
.logo .ball {
    inline-size: 44px; block-size: 44px; border-radius: 50%; flex: none;
    background: radial-gradient(circle at 50% 50%, #1f2433 0 22%, transparent 23%), radial-gradient(circle at 35% 30%, #fff, #cfd6e2 70%);
    box-shadow: 0 0 0 3px #000, 0 6px 0 rgba(0, 0, 0, .4); animation: hd-roll 2.2s ease-in-out infinite;
}
@keyframes hd-roll { 0%, 100% { transform: translateY(0) rotate(0); } 40% { transform: translateY(-16px) rotate(200deg); } 60% { transform: translateY(0) rotate(300deg); } }

.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 16px auto 6px; max-inline-size: 780px; }
.mode {
    border-radius: 16px; border: 2px solid var(--border); background: rgba(15, 29, 54, .88); padding: 14px 10px; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; gap: 8px; transition: transform .15s, border-color .15s, box-shadow .15s;
}
.mode > svg { inline-size: 56px; block-size: 56px; }
.mode .two { display: inline-flex; }
.mode .two .pf + .pf { margin-inline-start: -10px; }
.mode b { font-size: 1.12rem; }
.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(74, 222, 128, .25); }
.records { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 18px; margin-block-start: 14px; color: var(--muted); font-size: .9rem; }
.records span { display: inline-flex; align-items: center; gap: 6px; }
.records svg { inline-size: 18px; block-size: 18px; fill: var(--accent2); }
.records b { color: var(--text); }

.btns { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-block-start: 16px; }
.btns.col { flex-direction: column; align-items: stretch; }
.btn { border: 2px solid var(--border); background: var(--surface2); border-radius: 12px; padding: 10px 20px; font-weight: 800; cursor: pointer; min-inline-size: 120px; transition: transform .12s, filter .12s; }
.btn:hover { transform: translateY(-2px); filter: brightness(1.1); }
.btn.primary { background: linear-gradient(180deg, #5ef09a, #22b45a); border-color: #8bf5b5; color: var(--ink); box-shadow: 0 6px 18px rgba(74, 222, 128, .35); }
.btn.ghost { background: transparent; }

/* hero picker */
.hgrid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; max-inline-size: 820px; margin: 6px auto; }
.hcard {
    position: relative; border: 2px solid var(--border); border-radius: 14px; padding: 8px 4px 10px; cursor: pointer;
    background: linear-gradient(180deg, color-mix(in srgb, var(--kit) 30%, #0f1d36), #0f1d36 70%); display: grid; justify-items: center; gap: 2px;
    transition: transform .15s, border-color .15s, box-shadow .15s;
}
.hcard b { font-size: 1rem; }
.hcard small { color: var(--muted); font-size: .78rem; }
.hcard .sp { font-size: .68rem; font-weight: 800; color: var(--sp); letter-spacing: .02em; }
.hcard em { font-style: normal; font-size: .66rem; color: var(--muted); display: grid; justify-items: center; gap: 2px; }
.hcard .lock { inline-size: 18px; block-size: 18px; }
.hcard.sel { border-color: var(--accent2); box-shadow: 0 0 0 3px rgba(255, 209, 102, .25), 0 10px 26px rgba(0, 0, 0, .4); transform: translateY(-3px); }
.hcard.sel .pf { animation: hd-bob 1s ease-in-out infinite; }
.hcard.locked { cursor: not-allowed; filter: grayscale(.85) brightness(.6); }
.hinfo { max-inline-size: 560px; margin: 10px auto 0; padding: 10px 14px; border-radius: 14px; border: 1px solid var(--border); background: rgba(0, 0, 0, .25); text-align: start; }
.hinfo > b { color: var(--sp); }
.hinfo p { margin: 4px 0 8px; text-align: start; max-inline-size: none; }
.bars { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 6px 10px; align-items: center; font-size: .82rem; color: var(--muted); }
.bar { block-size: 8px; border-radius: 4px; background: rgba(255, 255, 255, .1); overflow: hidden; }
.bar i { display: block; block-size: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 4px; }

/* cup ladder */
.ladder { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; max-inline-size: 760px; margin: 12px auto 0; }
.rung {
    display: flex; align-items: center; gap: 10px; text-align: start; padding: 8px 12px; border-radius: 14px; cursor: pointer;
    border: 2px solid var(--border); background: linear-gradient(90deg, color-mix(in srgb, var(--kit) 32%, #0f1d36), #0f1d36 65%);
    transition: transform .15s, border-color .15s;
}
.rung:hover:not(.locked) { transform: translateY(-2px); border-color: var(--accent); }
.rung .num { font-weight: 900; font-size: 1.3rem; color: var(--muted); inline-size: 22px; }
.rung .rt { flex: 1; display: grid; gap: 2px; }
.rung .rt small { color: var(--muted); font-weight: 400; font-size: .78rem; }
.rung.locked { cursor: not-allowed; opacity: .55; filter: grayscale(.7); }
.rung.done { border-color: rgba(255, 209, 102, .55); }
.stars { display: inline-flex; gap: 2px; }
.stars svg { inline-size: 18px; block-size: 18px; fill: rgba(255, 255, 255, .18); }
.stars .lock { fill: none; }
.stars .on svg { fill: var(--accent2); filter: drop-shadow(0 0 4px rgba(255, 209, 102, .7)); }
.stars.big { justify-content: center; margin-block: 6px 2px; gap: 6px; }
.stars.big svg { inline-size: 44px; block-size: 44px; }
.stars.big span { animation: hd-star .5s cubic-bezier(.3, 1.6, .5, 1) both; animation-delay: var(--d); }
.stars.big span:not(.on) { animation: none; }
@keyframes hd-star { 0% { transform: scale(0) rotate(-90deg); opacity: 0; } 100% { transform: scale(1) rotate(0); opacity: 1; } }

/* setup */
.hrow { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; max-inline-size: 640px; margin: 0 auto; }
.mini { position: relative; border: 2px solid var(--border); border-radius: 12px; padding: 4px 2px 6px; background: rgba(0, 0, 0, .25); cursor: pointer; display: grid; justify-items: center; }
.mini small { font-size: .72rem; color: var(--muted); }
.mini.sel { border-color: var(--accent2); background: color-mix(in srgb, var(--kit) 28%, transparent); }
.mini.sel small { color: var(--text); }
.mini.locked { cursor: not-allowed; filter: grayscale(.9) brightness(.55); }
.mini .lock { position: absolute; inset-block-start: 4px; inset-inline-end: 4px; inline-size: 16px; block-size: 16px; }
.stads { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; max-inline-size: 760px; margin: 0 auto; }
.stad { border: 2px solid var(--border); border-radius: 12px; padding: 4px; background: rgba(0, 0, 0, .25); cursor: pointer; display: grid; gap: 3px; }
.stad canvas { inline-size: 100%; block-size: auto; border-radius: 8px; display: block; }
.stad small { font-size: .72rem; color: var(--muted); }
.stad.sel { border-color: var(--accent2); }
.stad.sel small { color: var(--text); }
.opts { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 20px; margin-block-start: 8px; }
.opt { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; margin-block: 6px; }
.opt > span { color: var(--muted); font-size: .9rem; font-weight: 700; }
.seg { display: inline-flex; gap: 4px; padding: 4px; border-radius: 12px; background: rgba(0, 0, 0, .3); border: 1px solid var(--border); }
.seg button { border: 0; background: transparent; padding: 7px 13px; border-radius: 9px; cursor: pointer; font-weight: 700; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--ink); }

/* result */
.result { position: relative; padding-block-start: 4px; }
.result .trophy { inline-size: 84px; block-size: 84px; animation: hd-pop .7s cubic-bezier(.3, 1.6, .5, 1) both; filter: drop-shadow(0 0 18px rgba(255, 209, 102, .6)); }
.result h2 { animation: hd-pop .55s cubic-bezier(.3, 1.6, .5, 1) both; }
@keyframes hd-pop { 0% { transform: scale(.3); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.final { display: inline-flex; align-items: center; gap: 14px; font-size: clamp(2.4rem, 9vw, 3.6rem); font-weight: 900; margin-block: 2px 4px; }
.final i { font-style: normal; color: var(--muted); }
.result.lose .final .pf:first-child { filter: grayscale(.6); }
.result.win .final .pf:first-child { animation: hd-bob .8s ease-in-out infinite; }
.stats { display: grid; gap: 6px; max-inline-size: 420px; margin: 12px auto 0; }
.stat { display: grid; grid-template-columns: 1fr auto 3.4em auto 1fr; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 10px; background: rgba(0, 0, 0, .25); }
.stat span { grid-column: 3; grid-row: 1; font-size: .78rem; color: var(--muted); text-align: center; white-space: nowrap; }
.stat b:first-of-type { grid-column: 1 / 3; grid-row: 1; text-align: start; font-size: 1.2rem; color: var(--p1); }
.stat b:last-of-type { grid-column: 4 / 6; grid-row: 1; text-align: end; font-size: 1.2rem; color: var(--p2); }
.stat i { display: none; }
.record { color: var(--accent2) !important; font-weight: 800; animation: hd-glow 1.2s ease-in-out infinite alternate; }
@keyframes hd-glow { to { text-shadow: 0 0 16px rgba(255, 209, 102, .8); } }
.unlock { display: inline-flex; align-items: center; gap: 10px; margin-block: 10px 0; padding: 8px 16px 8px 10px; border-radius: 40px; background: rgba(255, 209, 102, .14); border: 2px solid rgba(255, 209, 102, .6); animation: hd-pop .6s .9s cubic-bezier(.3, 1.6, .5, 1) both; }
.hint { font-size: .85rem; }

/* ---------- play ---------- */
.hud { display: flex; align-items: center; gap: 8px; margin-block-end: 6px; direction: ltr; }
.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: 0; }
.icon svg { inline-size: 22px; block-size: 22px; }
.side { flex: 1; display: flex; align-items: center; gap: 8px; min-inline-size: 0; }
.side.s2 { justify-content: flex-end; text-align: end; }
.face { flex: none; inline-size: 40px; block-size: 40px; border-radius: 50%; background: rgba(255, 255, 255, .08); line-height: 0; }
.who { display: grid; gap: 3px; min-inline-size: 0; flex: 1; max-inline-size: 240px; }
.who b { font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.s1 .who b { color: var(--p1); }
.s2 .who b { color: var(--p2); }
.pow { position: relative; block-size: 12px; border-radius: 6px; background: rgba(255, 255, 255, .1); overflow: hidden; border: 1px solid rgba(255, 255, 255, .15); }
.s2 .pow i { margin-inline-start: auto; }
.pow i { display: block; block-size: 100%; inline-size: 0; background: linear-gradient(90deg, color-mix(in srgb, var(--sp, #4ade80) 60%, #fff), var(--sp, #4ade80)); transition: inline-size .2s; }
.pow em { position: absolute; inset: 0; font-style: normal; font-size: .58rem; font-weight: 900; line-height: 11px; text-align: center; color: #000; letter-spacing: .03em; }
.pow.full { animation: hd-full .5s ease-in-out infinite alternate; }
.pow.charged i { background: repeating-linear-gradient(45deg, var(--sp), var(--sp) 6px, #fff 6px, #fff 10px); animation: hd-stripe .5s linear infinite; background-size: 28px 28px; }
@keyframes hd-full { to { box-shadow: 0 0 12px var(--sp); border-color: #fff; } }
@keyframes hd-stripe { to { background-position: 28px 0; } }
.mid { flex: none; display: grid; justify-items: center; gap: 1px; min-inline-size: 96px; }
.score { font-size: 1.7rem; font-weight: 900; line-height: 1; display: flex; gap: 6px; }
.score i { font-style: normal; color: var(--muted); }
.score span:first-child { color: var(--p1); }
.score span:last-child { color: var(--p2); }
.score span.bump { animation: hd-bump .6s cubic-bezier(.3, 1.8, .5, 1); }
@keyframes hd-bump { 0% { transform: scale(2.2); } 100% { transform: scale(1); } }
.clock { font-size: .9rem; font-weight: 800; padding: 1px 10px; border-radius: 8px; background: rgba(0, 0, 0, .35); font-variant-numeric: tabular-nums; }
.clock.hot { color: #fff; background: var(--hot); animation: hd-hot .5s ease-in-out infinite alternate; }
.clock.gold { color: #000; background: var(--accent2); font-size: .72rem; }
@keyframes hd-hot { to { transform: scale(1.12); } }

.stage { position: relative; border-radius: 14px; overflow: hidden; background: #000; display: flex; justify-content: center; touch-action: none; }
#view { display: block; }
.banner { position: absolute; inset-inline: 0; inset-block-start: 26%; display: grid; justify-items: center; pointer-events: none; opacity: 0; direction: ltr; }
.banner b { font-size: clamp(2.2rem, 9vw, 5rem); font-weight: 900; letter-spacing: .03em; color: #fff; -webkit-text-stroke: 2px rgba(0, 0, 0, .55); text-shadow: 0 5px 0 rgba(0, 0, 0, .55), 0 0 30px rgba(255, 255, 255, .45); }
.banner b i { font-style: normal; font-size: .5em; color: var(--accent2); vertical-align: middle; margin-inline: .3em; }
.banner small { font-size: clamp(.9rem, 2.6vw, 1.3rem); font-weight: 800; color: var(--accent2); text-shadow: 0 2px 0 #000; }
.banner.show { animation: hd-banner 1.6s cubic-bezier(.2, 1.4, .4, 1) both; }
.banner.left b { color: var(--p1); }
.banner.right b { color: var(--p2); }
.banner.gold b { color: var(--accent2); }
.banner.go b { color: var(--accent); }
.banner.intro b { font-size: clamp(1.6rem, 6vw, 3.2rem); }
@keyframes hd-banner { 0% { opacity: 0; transform: scale(.3) rotate(-6deg); } 12% { opacity: 1; transform: scale(1.12) rotate(2deg); } 22% { transform: scale(1) rotate(0); } 80% { opacity: 1; } 100% { opacity: 0; transform: scale(1.05); } }
.overlay { position: absolute; inset: 0; display: none; place-items: center; background: rgba(4, 10, 20, .6); backdrop-filter: blur(2px); }
.overlay.show { display: grid; }
.card { padding: 18px 22px; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); min-inline-size: 220px; text-align: center; }
.card h3 { margin: 0 0 4px; }
.keys { margin: 6px 0 0; font-size: .8rem; color: var(--muted); text-align: center; }
.touch .keys { display: none; }

/* touch pad: over the bottom corners of the pitch in landscape, under it on a tall screen */
.pad { position: absolute; inset-inline: 0; inset-block-end: 0; display: flex; justify-content: space-between; align-items: flex-end; padding: 8px; pointer-events: none; direction: ltr; }
.cluster { display: flex; gap: 8px; pointer-events: auto; }
.pb {
    inline-size: 58px; block-size: 58px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .55); background: rgba(10, 20, 40, .42);
    display: grid; place-items: center; padding: 0; color: #fff; touch-action: none; backdrop-filter: blur(2px);
}
.pb svg { inline-size: 26px; block-size: 26px; }
.pb.on { background: rgba(255, 255, 255, .45); transform: scale(.94); }
.pb.kk { inline-size: 66px; block-size: 66px; border-color: #8bf5b5; }
.pb.pw { border-color: var(--accent2); color: var(--accent2); }
.acts { align-items: flex-end; }
.acts .pb:nth-child(2) { margin-block-end: 26px; }
.pad.duel .half { display: flex; gap: 6px; align-items: flex-end; }
.pad.duel .pb { inline-size: 46px; block-size: 46px; }
.pad.duel .pb svg { inline-size: 20px; block-size: 20px; }
.pad.duel .acts .pb:nth-child(2) { margin-block-end: 18px; }
@media (orientation: portrait) and (max-width: 760px) {
    .touch .stage { flex-direction: column; align-items: center; }
    .touch .pad { position: static; padding: 10px 6px 6px; background: linear-gradient(180deg, #0c2a18, #07101f); inline-size: 100%; }
    .touch .pb { background: rgba(255, 255, 255, .08); }
}

.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }
.confetti i { position: absolute; inset-block-start: -12px; inline-size: 8px; block-size: 14px; border-radius: 2px; animation-name: hd-fall; animation-timing-function: linear; animation-fill-mode: forwards; }
@keyframes hd-fall { to { transform: translateY(620px) rotate(720deg); opacity: .2; } }

@media (max-width: 720px) {
    .modes { grid-template-columns: 1fr; max-inline-size: 420px; }
    .mode { flex-direction: row; text-align: start; }
    .hgrid { grid-template-columns: repeat(3, 1fr); }
    .ladder { grid-template-columns: 1fr; }
    .hrow { grid-template-columns: repeat(6, 1fr); gap: 4px; }
    .mini small { font-size: .62rem; }
    .stads { grid-template-columns: repeat(3, 1fr); }
    .who { max-inline-size: none; }
    .face { inline-size: 32px; block-size: 32px; }
    .face canvas { inline-size: 32px !important; block-size: 32px !important; }
    .mid { min-inline-size: 70px; }
    .score { font-size: 1.35rem; }
    .icon { inline-size: 34px; block-size: 34px; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
