/* ==========================================================================
   OSRS-style Duel Arena scene.
   Purely decorative layer over the real, server-backed duel simulation.
   Player model and attack/victory frames come from OSRS Wiki files stored
   locally in /assets/wiki; nothing is hotlinked and CSP stays tight.
   ========================================================================== */
.arena-stage.rs-scene-on {
    background: #1a1109;
    overflow: hidden;
}

.rs-scene {
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
    image-rendering: pixelated;
}

.rs-scene > div { position: absolute; }

/* Sky and sandstone arena walls */
.rs-scene-sky {
    inset: 0 0 46% 0;
    background: linear-gradient(180deg, #20160f 0%, #3a2717 55%, #5a4023 100%);
}

.rs-scene-wall {
    left: 0;
    right: 0;
    top: 8%;
    height: 46%;
    background:
        repeating-linear-gradient(0deg, rgba(0,0,0,.24) 0 2px, transparent 2px 26px),
        repeating-linear-gradient(90deg, rgba(0,0,0,.22) 0 2px, transparent 2px 54px),
        linear-gradient(180deg, #8a6a3a 0%, #6b4e2a 48%, #4a3420 100%);
    box-shadow: inset 0 12px 26px rgba(0,0,0,.55);
    opacity: .82;
}

.rs-scene-wall::before,
.rs-scene-wall::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 26px;
    background: repeating-linear-gradient(0deg, #7d5c31 0 22px, #5a3f22 22px 26px);
    border-left: 3px solid #3b2816;
    border-right: 3px solid #3b2816;
}
.rs-scene-wall::before { left: 12%; }
.rs-scene-wall::after { right: 12%; }

.rs-torch {
    top: 20%;
    width: 10px;
    height: 34px;
    background: #4a2c14;
    box-shadow: 0 4px 0 #2c1a0d;
}
.rs-torch.left { left: 7%; }
.rs-torch.right { right: 7%; }
.rs-torch::before {
    content: '';
    position: absolute;
    left: -4px;
    top: -18px;
    width: 18px;
    height: 22px;
    background: radial-gradient(ellipse at 50% 70%, #fff3a6 0 18%, #ffb52e 38%, #e8621a 62%, transparent 72%);
    animation: rsTorchFlicker .42s steps(2, end) infinite alternate;
}
.rs-torch::after {
    content: '';
    position: absolute;
    left: -46px;
    top: -58px;
    width: 100px;
    height: 100px;
    background: radial-gradient(circle, rgba(255,170,60,.22), transparent 68%);
}
@keyframes rsTorchFlicker {
    from { transform: scale(.9) translateY(1px); opacity: .82; }
    to   { transform: scale(1.12) translateY(-2px); opacity: 1; }
}

/* Crowd of spectators behind the duellists */
.rs-scene-crowd {
    left: 3%;
    right: 3%;
    top: 34%;
    height: 22%;
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    opacity: .72;
}
.rs-spectator {
    width: 12px;
    height: 26px;
    background: #1d130c;
    box-shadow: inset 0 5px 0 #2f2014, 0 -3px 0 -1px #3a2718;
    animation: rsCrowdBob 1.1s steps(2, end) infinite alternate;
}
.rs-spectator:nth-child(3n) { height: 21px; animation-delay: -.35s; }
.rs-spectator:nth-child(4n) { height: 30px; animation-delay: -.7s; background: #241a10; }
.rs-spectator:nth-child(5n) { animation-delay: -.15s; }
@keyframes rsCrowdBob {
    from { transform: translateY(0); }
    to   { transform: translateY(-3px); }
}

/* Sand floor */
.rs-scene-floor {
    left: -6%;
    right: -6%;
    bottom: -12%;
    height: 56%;
    background:
        radial-gradient(ellipse at 50% 0%, rgba(255, 214, 110, .14), transparent 60%),
        repeating-linear-gradient(90deg, rgba(90,60,20,.16) 0 3px, transparent 3px 18px),
        repeating-linear-gradient(0deg, rgba(0,0,0,.12) 0 2px, transparent 2px 14px),
        linear-gradient(180deg, #a8804a 0%, #8a6537 45%, #5d4324 100%);
    transform: perspective(380px) rotateX(48deg);
    transform-origin: bottom center;
    border-top: 3px solid rgba(255, 220, 140, .28);
}

/* Duel Arena Master */
.rs-scene-npc {
    left: 50%;
    bottom: 16%;
    width: 42px;
    height: 62px;
    transform: translateX(-50%);
    background:
        linear-gradient(180deg, transparent 0 12%, #b8342f 12% 22%, #d9b06a 22% 40%, #6d4726 40% 72%, #3a2a1c 72% 100%);
    border: 2px solid #2a1a0e;
    box-shadow: 0 5px 0 rgba(0,0,0,.45);
    opacity: .9;
}
.rs-scene-npc::before {
    content: 'Duel Arena Master';
    position: absolute;
    left: 50%;
    top: -22px;
    transform: translateX(-50%);
    white-space: nowrap;
    font-family: 'MedievalSharp', cursive;
    font-size: 9px;
    color: #ffe9a8;
    text-shadow: 1px 1px 0 #000, -1px -1px 0 #000;
}
.rs-scene-npc::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 24px;
    width: 16px;
    height: 3px;
    transform: translateX(-50%);
    background: #e3bb54;
}

/* Staked whips on the duel table */
.rs-scene-stake {
    left: 50%;
    bottom: 5%;
    transform: translateX(-50%);
    width: 168px;
    height: 46px;
    border: 3px solid #c8a24a;
    background: linear-gradient(180deg, #4a2c1c, #241408);
    box-shadow: 0 0 22px rgba(212,175,55,.25), inset 0 0 12px #000;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    z-index: 1;
}
.rs-scene-stake::before {
    content: 'STAKED WHIPS';
    position: absolute;
    top: -17px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 8px;
    letter-spacing: 1.4px;
    color: #ffe9a8;
    text-shadow: 1px 1px 0 #000;
}
.rs-stake-whip {
    width: 28px;
    height: 28px;
    filter: drop-shadow(0 2px 0 #000);
    animation: rsStakeRest 2.4s ease-in-out infinite alternate;
}
.rs-stake-whip:nth-child(even) { animation-delay: -1.2s; }
@keyframes rsStakeRest {
    from { transform: rotate(-6deg) translateY(0); }
    to   { transform: rotate(6deg) translateY(-2px); }
}
.rs-scene-stake.settled { box-shadow: 0 0 36px rgba(255,220,120,.75), inset 0 0 16px #000; }

/* "FIGHT!" banner */
.rs-scene-banner {
    left: 0;
    right: 0;
    top: 42%;
    text-align: center;
    font-family: 'MedievalSharp', cursive;
    font-size: clamp(2.2rem, 6vw, 4.6rem);
    color: #ffe066;
    text-shadow: 4px 4px 0 #000, 0 0 26px rgba(255,180,40,.85);
    letter-spacing: 6px;
    opacity: 0;
    transform: scale(.5);
}
.rs-scene-banner.show {
    animation: rsFightBanner .75s steps(6, end) forwards;
}
@keyframes rsFightBanner {
    0%   { opacity: 0; transform: scale(.4) rotate(-4deg); }
    35%  { opacity: 1; transform: scale(1.14) rotate(2deg); }
    70%  { opacity: 1; transform: scale(1) rotate(0); }
    100% { opacity: 0; transform: scale(1.05); }
}

/* Whips flying to the stake table during the ceremony */
.rs-flying-whip {
    position: absolute;
    z-index: 4;
    width: 38px;
    height: 38px;
    pointer-events: none;
    filter: drop-shadow(0 3px 0 #000);
}
.rs-flying-whip.left {
    left: 22%;
    top: 40%;
    animation: rsWhipToPotLeft .68s steps(8, end) forwards;
}
.rs-flying-whip.right {
    right: 22%;
    top: 40%;
    animation: rsWhipToPotRight .68s steps(8, end) forwards;
}
@keyframes rsWhipToPotLeft {
    to { left: 47%; top: 68%; transform: rotate(220deg) scale(.65); opacity: .25; }
}
@keyframes rsWhipToPotRight {
    to { right: 47%; top: 68%; transform: rotate(-220deg) scale(.65); opacity: .25; }
}

/* Wiki-sourced player models and sprite-sheet animations */
.fighter .fighter-avatar { z-index: 2; }
.rs-fighter-sprite {
    position: relative;
    width: 118px;
    height: 138px;
    margin: 0 auto;
    image-rendering: pixelated;
    shape-rendering: crispEdges;
    filter: drop-shadow(0 5px 0 rgba(0,0,0,.5));
    animation: rsIdleBob 1.4s steps(2, end) infinite alternate;
}
@keyframes rsIdleBob {
    from { transform: translateY(0); }
    to   { transform: translateY(-3px); }
}
.rs-fighter-shadow {
    position: absolute;
    bottom: 2px;
    left: 50%;
    width: 76px;
    height: 12px;
    transform: translateX(-50%);
    background: radial-gradient(ellipse at center, rgba(0,0,0,.62), transparent 70%);
    z-index: 0;
}
.rs-fighter-idle {
    position: absolute;
    left: 50%;
    bottom: 0;
    height: 100%;
    width: auto;
    max-width: none;
    transform: translateX(-50%);
    transform-origin: 50% 90%;
    image-rendering: pixelated;
    z-index: 1;
    transition: opacity .12s linear;
}
.rs-fighter-right .rs-fighter-idle {
    transform: translateX(-50%) scaleX(-1);
    filter: hue-rotate(22deg) saturate(1.15) brightness(1.05);
}
.rs-fighter-attack,
.rs-fighter-victory {
    position: absolute;
    bottom: 0;
    left: 50%;
    height: 138px;
    transform: translateX(-50%);
    background-repeat: no-repeat;
    background-position: 0 0;
    image-rendering: pixelated;
    opacity: 0;
    z-index: 2;
    pointer-events: none;
}
.rs-fighter-right .rs-fighter-attack,
.rs-fighter-right .rs-fighter-victory {
    transform: translateX(-50%) scaleX(-1);
}
.rs-fighter-attack {
    width: 79px;
    background-image: url('/assets/wiki/player-attack-sheet.png?v=scene4');
    background-size: 3634px 138px;
}
.rs-fighter-victory {
    width: 82px;
    background-image: url('/assets/wiki/player-victory-sheet.png?v=scene4');
    background-size: 7134px 138px;
}
.fighter.attacking .rs-fighter-idle,
.fighter.winner .rs-fighter-idle { opacity: 0; }
.fighter.attacking .rs-fighter-attack {
    opacity: 1;
    animation: rsWikiAttack .76s steps(46, end);
}
.fighter.attacking.special .rs-fighter-attack {
    filter: brightness(1.45) saturate(1.3) drop-shadow(0 0 10px #ffd75e);
}
.fighter.winner .rs-fighter-victory {
    opacity: 1;
    animation: rsWikiVictory 1.6s steps(87, end) infinite;
}
@keyframes rsWikiAttack {
    from { background-position-x: 0; }
    to   { background-position-x: -3634px; }
}
@keyframes rsWikiVictory {
    from { background-position-x: 0; }
    to   { background-position-x: -7134px; }
}
.fighter.struck .rs-fighter-sprite {
    animation: rsHitFlash .36s steps(2, end);
}
@keyframes rsHitFlash {
    0%, 100% { filter: drop-shadow(0 5px 0 rgba(0,0,0,.5)); }
    30%, 60% { filter: brightness(2.6) saturate(.25) drop-shadow(0 0 12px #fff); }
}
.fighter.defeated .rs-fighter-sprite {
    animation: rsDefeat .7s steps(4, end) forwards;
}
@keyframes rsDefeat {
    to { transform: translateY(16px) rotate(14deg); opacity: .55; }
}
.fighter.winner .rs-fighter-sprite {
    animation: rsVictoryHop .5s steps(2, end) 3 alternate;
}
@keyframes rsVictoryHop {
    to { transform: translateY(-12px); }
}

/* OSRS-style damage numbers */
.rs-scene-on .hitsplat {
    font-family: 'MedievalSharp', cursive;
    font-size: 1.9rem;
    color: #ff3b30;
    text-shadow: 2px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 0 0 10px #000;
}
.rs-scene-on .hitsplat.miss { color: #c8d4ff; font-size: 1.3rem; }
.rs-scene-on .hitsplat.special { color: #ffe066; font-size: 2.2rem; }
.rs-scene-on .hitsplat.heal { color: #69db7c; }
.rs-scene-on .hitsplat.prayer { color: #74c0fc; }

/* Keep the HUD readable above the scene */
.arena-stage.rs-scene-on .fighter,
.arena-stage.rs-scene-on .arena-center {
    position: relative;
    z-index: 2;
}
.arena-stage.rs-scene-on .fighter {
    background: linear-gradient(180deg, rgba(30,20,12,.94), rgba(12,8,5,.96));
    border-color: #b8941f;
}
.arena-stage.rs-scene-on .arena-center .center-pot {
    box-shadow: 0 0 18px rgba(212,175,55,.3), inset 0 0 12px #000;
}
.arena-stage.rs-scene-on .round-pill { background: rgba(20,15,10,.85); }

/* Combat chat box flavour */
.rs-scene-on + .arena-bottom .combat-log {
    border-color: #b8941f;
    box-shadow: inset 0 0 24px rgba(0,0,0,.6);
}

@media (prefers-reduced-motion: reduce) {
    .rs-scene *, .rs-fighter-sprite, .rs-stake-whip,
    .fighter.attacking .rs-fighter-attack, .fighter.winner .rs-fighter-victory,
    .fighter.struck .rs-fighter-sprite,
    .fighter.winner .rs-fighter-sprite, .fighter.defeated .rs-fighter-sprite {
        animation: none !important;
    }
}

@media (max-width: 760px) {
    .rs-scene-crowd { top: 30%; height: 16%; }
    .rs-scene-npc { bottom: 12%; transform: translateX(-50%) scale(.8); }
    .rs-scene-stake { width: 128px; bottom: 2%; }
    .arena-stage.rs-scene-on .fighter-avatar { height: 138px; }
    .rs-fighter-sprite { width: 118px; height: 138px; }
}
