/* Ink Brawl. Logical properties, so RTL and LTR share one file; the fight view stays LTR.
   Keyframes are prefixed ib- so pasted shared CSS can never clash with them. */
:root {
    --paper: #f5efe1; --paper2: #ebe2cd; --line: #c9d8ef; --ink: #15131d; --ink2: #3b3746; --muted: #6d6578;
    --red: #e23d4f; --blue: #2f9bff; --gold: #ffb020; --ok: #2fa35a; --bg: #1a1722; --surface: #26212f; --border: #3d3549;
    --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(--ink); 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(--gold); 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: a sheet of notebook paper ---------- */
.screen {
    position: relative; overflow: hidden; border-radius: 16px; padding: 18px 16px 22px; text-align: center; min-block-size: 420px;
    background:
        linear-gradient(90deg, transparent 38px, rgba(226, 61, 79, .45) 38px, rgba(226, 61, 79, .45) 40px, transparent 40px),
        repeating-linear-gradient(180deg, transparent 0 31px, var(--line) 31px 32px),
        radial-gradient(120% 80% at 50% 0%, #fffaf0, var(--paper) 60%, var(--paper2));
    box-shadow: inset 0 0 60px rgba(120, 90, 40, .18);
}
.game[data-screen="play"] .screen { display: none; }
.screen h2 { margin: 6px 0 4px; font-size: clamp(1.9rem, 6vw, 2.9rem); font-weight: 900; letter-spacing: .01em; color: var(--ink); text-shadow: 3px 3px 0 rgba(226, 61, 79, .35); }
.screen h2.win { color: var(--red); text-shadow: 3px 3px 0 rgba(21, 19, 29, .25); }
.screen h3 { margin: 14px 0 6px; font-size: .95rem; color: var(--ink2); font-weight: 800; }
.screen p { margin: 6px auto; max-inline-size: 560px; color: var(--ink2); line-height: 1.5; }
.screen > *:not(.splats):not(.confetti) { position: relative; }
.splats { position: absolute; inset: 0; pointer-events: none; opacity: .9; object-fit: cover; }

.heroes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 12px auto 4px; max-inline-size: 620px; }
.hero {
    border-radius: 14px; border: 2.5px solid var(--ink); background: rgba(255, 252, 244, .9); padding: 6px 6px 10px; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; gap: 2px; transition: transform .15s, box-shadow .15s;
    box-shadow: 3px 4px 0 var(--ink);
}
.hero canvas { inline-size: 100%; max-inline-size: 150px; aspect-ratio: 1; }
.hero b { font-size: 1.05rem; }
.hero small { color: var(--muted); font-size: .78rem; font-weight: 700; }
.hero .bars { display: grid; gap: 3px; inline-size: 88%; margin-block-start: 4px; }
.hero .bar { display: grid; grid-template-columns: 4.6em 1fr; align-items: center; gap: 6px; font-size: .68rem; color: var(--muted); text-align: start; }
.hero .bar i { block-size: 6px; border-radius: 4px; background: var(--ink); inline-size: calc(var(--v) * 20%); }
.hero:hover { transform: translateY(-2px) rotate(-.6deg); }
.hero[aria-pressed="true"] { background: #fff; box-shadow: 5px 6px 0 var(--red); border-color: var(--ink); transform: translateY(-3px); }

.seg { display: inline-flex; flex-wrap: wrap; justify-content: center; gap: 4px; padding: 4px; border-radius: 12px; background: rgba(21, 19, 29, .07); border: 2px solid var(--ink); }
.seg button { border: 0; background: transparent; padding: 7px 13px; border-radius: 9px; cursor: pointer; font-weight: 800; color: var(--ink2); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.seg button:disabled { opacity: .4; cursor: not-allowed; }
.opts { display: flex; flex-direction: column; align-items: center; }
.note { font-size: .8rem; color: var(--muted); margin-block-start: 6px; }

.actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-block: 14px 6px; }
.btn {
    border: 2.5px solid var(--ink); border-radius: 14px; padding: 12px 28px; font-weight: 900; font-size: 1.08rem; cursor: pointer;
    background: var(--ink); color: var(--paper); box-shadow: 4px 5px 0 var(--red); transition: transform .1s, box-shadow .1s;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 5px 6px 0 var(--red); }
.btn:active { transform: translate(3px, 4px); box-shadow: 1px 1px 0 var(--red); }
.btn.ghost { background: #fffaf0; color: var(--ink); box-shadow: 4px 5px 0 var(--ink); }
.row { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 18px; margin-block: 8px; color: var(--ink2); font-size: .92rem; }
.row b { color: var(--ink); 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; }
.big { font-size: clamp(2.8rem, 11vw, 4.6rem); font-weight: 900; font-variant-numeric: tabular-nums; color: var(--ink); text-shadow: 4px 4px 0 rgba(226, 61, 79, .5); }
.big.landed { animation: ib-land .45s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes ib-land { 0% { transform: scale(1.3) rotate(-3deg); } 100% { transform: scale(1); } }
.badge { display: inline-block; padding: 5px 16px; border-radius: 6px; font-weight: 900; background: var(--red); color: #fff; transform: rotate(-3deg); box-shadow: 3px 3px 0 var(--ink); animation: ib-badge 1s ease-in-out infinite alternate; }
@keyframes ib-badge { to { transform: rotate(2deg) scale(1.08); } }
.ladder { display: flex; justify-content: center; gap: 8px; margin-block: 10px; flex-wrap: wrap; }
.ladder span { inline-size: 46px; block-size: 46px; border-radius: 50%; border: 2.5px solid var(--ink); display: grid; place-items: center; background: #fffaf0; font-weight: 900; font-size: .8rem; position: relative; }
.ladder span canvas { inline-size: 40px; block-size: 40px; }
.ladder span.on::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 3px solid var(--red); transform: rotate(-12deg); clip-path: polygon(0 0, 100% 0, 100% 70%, 0 100%); }
.ladder span.on { background: #fff; }
.ladder span.lost { opacity: .45; }
.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: ib-fall linear forwards; }
@keyframes ib-fall { to { transform: translateY(600px) rotate(720deg); opacity: .2; } }

/* ---------- play area ---------- */
.hud { display: flex; align-items: center; gap: 8px; margin-block-end: 8px; color: var(--paper); }
.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.4; }
.stat .k { font-size: .72rem; color: #b9b0c6; white-space: nowrap; }
.stat b { font-size: 1.1rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat b.bump { animation: ib-bump .3s ease-out; }
.stat b.warn { color: #ff6a7a; animation: ib-bump .4s ease-out; }
@keyframes ib-bump { 40% { transform: scale(1.22); color: var(--gold); } }
.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; color: var(--paper); }
.icon svg { inline-size: 22px; block-size: 22px; }

.stage { position: relative; inline-size: 100%; aspect-ratio: 16 / 9; border-radius: 14px; overflow: hidden; background: var(--paper); border: 2px solid var(--ink); touch-action: none; direction: ltr; }
.stage canvas#view { position: absolute; inset: 0; inline-size: 100%; block-size: 100%; display: block; }

.card { position: absolute; inset-block-end: 2.6%; display: flex; align-items: center; gap: 6px; padding: 4px 12px 4px 4px; border-radius: 12px; background: rgba(255, 251, 240, .9); border: 2.5px solid var(--ink); box-shadow: 3px 3px 0 var(--acc, var(--ink)); pointer-events: none; min-inline-size: 22%; }
.card.c0 { inset-inline-start: 2%; }
.card.c1 { inset-inline-end: 2%; }
.card .face { inline-size: clamp(30px, 5vw, 50px); block-size: clamp(30px, 5vw, 50px); flex: none; }
.card .info { display: flex; flex-direction: column; line-height: 1.05; }
.card .nm { font-size: clamp(.6rem, 1.4vw, .85rem); font-weight: 900; text-transform: uppercase; letter-spacing: .05em; color: var(--ink2); }
.card .pct { font-size: clamp(1.15rem, 3.6vw, 2.2rem); font-weight: 900; font-variant-numeric: tabular-nums; color: var(--pc, var(--ink)); text-shadow: 2px 2px 0 rgba(21, 19, 29, .25); }
.card .pct.pop { animation: ib-pct .3s ease-out; }
@keyframes ib-pct { 0% { transform: scale(1.4) rotate(-4deg); } }
.card .stk { display: flex; gap: 3px; min-block-size: 8px; }
.card .stk i { inline-size: clamp(7px, 1.2vw, 11px); block-size: clamp(7px, 1.2vw, 11px); border-radius: 50%; background: var(--acc, var(--ink)); border: 1.5px solid var(--ink); }
.card .stk i.gone { background: transparent; opacity: .35; }
.card.hurt { animation: ib-shake .35s; }
.card.out { opacity: .5; }
@keyframes ib-shake { 25% { transform: translateX(-5px) rotate(-1deg); } 50% { transform: translateX(5px) rotate(1deg); } 75% { transform: translateX(-2px); } }

.chain { position: absolute; inset-inline-start: 2.4%; inset-block-start: 4%; display: flex; flex-direction: column; align-items: flex-start; pointer-events: none; opacity: 0; transition: opacity .25s; }
.chain.on { opacity: 1; }
.chain b { font-size: clamp(1.4rem, 5vw, 3rem); font-weight: 900; line-height: 1; color: var(--red); text-shadow: 3px 3px 0 var(--ink); font-variant-numeric: tabular-nums; }
.chain b.pop { animation: ib-pop .18s ease-out; }
@keyframes ib-pop { 0% { transform: scale(1.45); } }
.chain span { font-size: clamp(.6rem, 1.4vw, .85rem); font-weight: 900; text-transform: uppercase; letter-spacing: .12em; color: var(--ink); }

.banner { position: absolute; inset-inline: 0; inset-block-start: 30%; text-align: center; pointer-events: none; opacity: 0; }
.banner.on { animation: ib-banner 2s ease-out forwards; }
.banner b { display: block; font-size: clamp(1.8rem, 7.4vw, 4.6rem); font-weight: 900; color: var(--ink); text-shadow: 4px 4px 0 var(--red), -2px -2px 0 #fff, 2px -2px 0 #fff, -2px 2px 0 #fff; letter-spacing: .02em; }
.banner small { display: block; font-size: clamp(.8rem, 2.2vw, 1.25rem); color: var(--ink2); font-weight: 800; text-shadow: 0 0 6px #fff, 0 0 2px #fff; }
.banner.ko b { color: var(--red); text-shadow: 5px 5px 0 var(--ink), -2px -2px 0 #fff, 2px -2px 0 #fff; }
@keyframes ib-banner { 0% { opacity: 0; transform: scale(1.8) rotate(-6deg); } 10% { opacity: 1; transform: scale(1) rotate(-2deg); } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-14px) rotate(-2deg); } }

.overlay { position: absolute; inset: 0; display: none; place-items: center; background: rgba(245, 239, 225, .82); backdrop-filter: blur(2px); }
.overlay.on { display: grid; }
.overlay .box { text-align: center; padding: 10px 16px; max-inline-size: 92%; }
.overlay h2 { margin: 0 0 6px; font-size: clamp(1.2rem, 4.4vw, 2.2rem); color: var(--ink); text-shadow: 3px 3px 0 rgba(226, 61, 79, .4); }
.overlay .actions { margin-block: 8px 0; }
.overlay .btn { padding: 9px 22px; font-size: .95rem; }
.overlay .row { font-size: .85rem; }
.tally { display: grid; grid-template-columns: auto auto; gap: 2px 20px; justify-content: center; font-size: clamp(.78rem, 2vw, 1.05rem); margin-block: 6px; }
.tally span { text-align: start; color: var(--ink2); opacity: 0; font-weight: 700; }
.tally b { text-align: end; font-variant-numeric: tabular-nums; opacity: 0; }
.tally .on { opacity: 1; animation: ib-tally .3s ease-out; }
.tally .total { color: var(--red); font-size: 1.25em; }
@keyframes ib-tally { from { transform: translateX(-10px); opacity: 0; } }

/* ---------- touch pad: below the view when the phone is upright, over it in landscape ---------- */
.pad { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 6px 4px; direction: ltr; touch-action: none; }
.stick { position: relative; inline-size: 136px; block-size: 136px; border-radius: 50%; background: radial-gradient(circle, rgba(255, 255, 255, .07), rgba(255, 255, 255, .02)); border: 2px solid rgba(255, 255, 255, .2); touch-action: none; flex: none; }
.stick::before { content: ""; position: absolute; inset: 28%; border-radius: 50%; border: 1px dashed rgba(255, 255, 255, .16); }
.stick i { position: absolute; inset-inline-start: 50%; inset-block-start: 50%; inline-size: 58px; block-size: 58px; margin: -29px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fffaf0, #cfc4ad); border: 3px solid var(--ink); box-shadow: 0 4px 12px rgba(0, 0, 0, .5); }
.acts { display: grid; grid-template-columns: 60px 60px 82px; grid-template-rows: 60px 60px; gap: 8px; align-items: center; justify-items: center; }
.pb { touch-action: none; -webkit-touch-callout: none; border-radius: 50%; border: 2.5px solid var(--ink); cursor: pointer; padding: 0; display: grid; place-items: center; align-content: center; color: var(--ink); background: #fffaf0; box-shadow: 0 3px 0 #000; }
.pb svg { inline-size: 24px; block-size: 24px; }
.pb span { font-size: .58rem; font-weight: 900; margin-block-start: -2px; }
.pb.at { grid-row: 1 / 3; grid-column: 3; inline-size: 82px; block-size: 82px; background: var(--red); color: #fff; }
.pb.at svg { inline-size: 32px; block-size: 32px; }
.pb.sm { grid-row: 1; grid-column: 2; inline-size: 60px; block-size: 60px; background: var(--ink); color: var(--gold); }
.pb.sm.charging { box-shadow: 0 0 18px var(--gold); }
.pb.jp { grid-row: 2; grid-column: 2; inline-size: 60px; block-size: 60px; }
.pb.dg { grid-row: 2; grid-column: 1; inline-size: 52px; block-size: 52px; }
.pb.down { filter: brightness(1.25); transform: scale(.92); box-shadow: 0 1px 0 #000; }
.pad-over .pad { position: fixed; inset-inline: 0; inset-block-end: 0; padding: 8px 16px; pointer-events: none; }
.pad-over .pad > * { pointer-events: auto; opacity: .7; }
.pad-over .stage { max-block-size: calc(100vh - 70px); max-inline-size: calc((100vh - 70px) * 16 / 9); margin-inline: auto; }
.pad-over .keys { display: none; }
/* landscape phone: the buttons sit over the bottom corners, so the cards move to the top */
.pad-over .card { inset-block-end: auto; inset-block-start: 2.6%; padding: 2px 8px 2px 4px; gap: 3px; border-width: 2px; min-inline-size: 0; border-radius: 9px; box-shadow: 2px 2px 0 var(--acc, var(--ink)); }
.pad-over .card .face { inline-size: 24px; block-size: 24px; }
.pad-over .card .nm { font-size: .55rem; }
.pad-over .card .pct { font-size: 1.1rem; }
.pad-over .chain { inset-block-start: 22%; }

.keys { margin: 8px 0 0; text-align: center; font-size: .82rem; color: #b9b0c6; line-height: 1.7; }
kbd { display: inline-block; min-inline-size: 1.6em; padding: 1px 5px; border-radius: 5px; border: 1px solid var(--border); border-block-end-width: 2px; background: var(--surface); font: inherit; font-size: .78rem; color: var(--paper); }

@media (max-width: 560px) {
    .game { padding: 4px; }
    .heroes { gap: 6px; }
    .hero { padding: 4px 3px 8px; }
    .hero .bar { grid-template-columns: 1fr; gap: 1px; }
    .hud { gap: 5px; }
    .stat .k { font-size: .64rem; }
    .stat b { font-size: .95rem; }
    .icon { inline-size: 40px; block-size: 40px; }
    .screen { padding: 14px 10px 18px; }
    .seg button { padding: 6px 9px; font-size: .88rem; }
    .card { padding: 2px 8px 2px 4px; gap: 3px; border-width: 2px; min-inline-size: 0; border-radius: 9px; box-shadow: 2px 2px 0 var(--acc, var(--ink)); }
    .card .face { display: none; }
    .card .nm { font-size: .55rem; letter-spacing: .02em; }
    .card .pct { font-size: 1.05rem; }
    .chain b { font-size: 1.2rem; }
    .acts { grid-template-columns: 52px 56px 74px; grid-template-rows: 56px 56px; }
    .pb.at { inline-size: 74px; block-size: 74px; }
    .pb.sm, .pb.jp { inline-size: 56px; block-size: 56px; }
    .pb.dg { inline-size: 48px; block-size: 48px; }
    .stick { inline-size: 124px; block-size: 124px; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
