:root {
  color-scheme: dark;
  --bg: #050b18;
  --panel: #0c1a35;
  --gold: #e8c065;
  --gold-2: #c9a24a;
  --gold-dim: #6e5a2a;
  --text: #e8edf7;
  --muted: #8d9cbb;
  --line: rgba(201, 162, 74, 0.25);
  --side-a: #4a9bff;
  --side-b: #ff5a4a;
  --hp: #3fe06a;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  color: var(--text);
  font: 16px/1.45 'Alegreya Sans', system-ui, sans-serif;
  background:
    radial-gradient(1000px 500px at 50% -10%, rgba(60, 120, 230, 0.25), transparent 60%),
    radial-gradient(800px 600px at 100% 100%, rgba(232, 192, 101, 0.08), transparent 60%),
    var(--bg);
}
button { font: inherit; }

/* ---------- header ---------- */
.top { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 22px 16px 6px; }
.top img { filter: drop-shadow(0 0 12px rgba(120, 170, 255, 0.5)); }
.top h1 {
  margin: 0; font: 900 44px/1 'Cinzel Decorative', 'Cinzel', serif; letter-spacing: 0.04em;
  background: linear-gradient(100deg, #8d6427, #f5d98c 25%, #fff6d8 32%, #e8c065 45%, #8d6427 60%, #f5d98c 80%);
  background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: shimmer 8s linear infinite;
}
.top p { margin: 0; color: var(--gold-2); font: 700 12px 'Cinzel', serif; letter-spacing: 0.2em; text-transform: uppercase; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- pickers ---------- */
.pickers {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 14px 18px; align-items: start;
  width: min(1100px, calc(100% - 24px)); margin: 14px auto 18px;
}
.picker {
  padding: 14px; border-radius: 12px; border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(20, 42, 85, 0.85), rgba(8, 18, 40, 0.9));
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}
.picker.side-a { box-shadow: inset 3px 0 0 var(--side-a), 0 12px 30px rgba(0, 0, 0, 0.45); }
.picker.side-b { box-shadow: inset -3px 0 0 var(--side-b), 0 12px 30px rgba(0, 0, 0, 0.45); }
.picker label { display: block; margin-bottom: 6px; color: var(--muted); font: 700 11px 'Cinzel', serif; letter-spacing: 0.12em; text-transform: uppercase; }
.picker input {
  width: 100%; height: 44px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--gold-dim);
  background: #050c1c; color: var(--text); font: 600 17px 'Alegreya Sans', sans-serif; outline: none;
}
.picker input:focus { border-color: var(--gold); box-shadow: 0 0 14px rgba(232, 192, 101, 0.3); }
.preview { display: flex; align-items: center; gap: 10px; min-height: 58px; margin-top: 10px; }
.preview img { width: 52px; height: 52px; border-radius: 50%; object-fit: cover; box-shadow: 0 0 0 2px var(--gold-dim); }
.preview .pv-name { font: 700 18px 'Cinzel', serif; }
.preview .pv-sub { color: var(--muted); font-size: 13.5px; }
.preview.loading { color: var(--muted); }
.preview.error { color: #ff9b8a; font-size: 14px; }
.vs { align-self: center; display: grid; place-items: center; }
.vs span {
  display: grid; place-items: center; width: 62px; height: 62px; border-radius: 50%;
  font: 900 22px 'Cinzel', serif; color: var(--gold);
  background: radial-gradient(circle at 50% 35%, #1f3f80, #081430); border: 2px solid var(--gold);
  box-shadow: 0 0 24px rgba(232, 192, 101, 0.35); animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 50% { box-shadow: 0 0 38px rgba(232, 192, 101, 0.6); transform: scale(1.05); } }
.fight-btn {
  grid-column: 1 / -1; justify-self: center; padding: 12px 38px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--gold); color: #1a1205; font: 900 18px 'Cinzel', serif; letter-spacing: 0.08em; text-transform: uppercase;
  background: linear-gradient(180deg, #ffe7a8, #e8c065 45%, #b98b32); box-shadow: 0 6px 20px rgba(232, 192, 101, 0.35);
  transition: transform 0.15s, filter 0.2s;
}
.fight-btn:hover { transform: translateY(-2px); filter: brightness(1.08); }
.fight-btn:disabled { filter: grayscale(0.7) brightness(0.7); cursor: wait; transform: none; }
.msg { grid-column: 1 / -1; margin: 0; min-height: 20px; text-align: center; color: #ff9b8a; }

/* ---------- arena ---------- */
.arena-wrap { width: min(1100px, calc(100% - 16px)); margin: 0 auto 24px; }
.arena {
  position: relative; overflow: hidden; aspect-ratio: 16 / 9; min-height: 300px; border-radius: 14px;
  border: 2px solid var(--gold-dim); box-shadow: 0 0 0 1px #000, 0 24px 60px rgba(0, 0, 0, 0.6);
  isolation: isolate;
}
.arena.shake { animation: shake 0.32s ease-in-out; }
@keyframes shake { 20% { transform: translate(-6px, 3px); } 40% { transform: translate(5px, -4px); } 60% { transform: translate(-4px, 2px); } 80% { transform: translate(3px, -1px); } }
.sky { position: absolute; inset: 0; background: radial-gradient(60% 70% at 50% 0%, #26407a, #0b1630 60%, #050a16); }
.wall {
  position: absolute; left: -5%; right: -5%; top: 18%; height: 46%;
  background:
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.35) 0 2px, transparent 2px 70px),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.3) 0 2px, transparent 2px 34px),
    linear-gradient(180deg, #3a3a4a, #23232e);
  border-radius: 50% 50% 0 0 / 30% 30% 0 0;
  box-shadow: inset 0 -30px 40px rgba(0, 0, 0, 0.6), inset 0 10px 20px rgba(255, 255, 255, 0.05);
}
.floor {
  position: absolute; left: 0; right: 0; bottom: 0; height: 42%;
  background:
    radial-gradient(60% 80% at 50% 10%, rgba(232, 192, 101, 0.16), transparent 70%),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.18) 0 1px, transparent 1px 60px),
    linear-gradient(180deg, #6b5536, #3a2c1a 70%, #20170d);
  transform-origin: top; transform: perspective(600px) rotateX(28deg);
}
.torch { position: absolute; top: 24%; width: 18px; height: 54px; border-radius: 4px; background: linear-gradient(#5a4020, #2a1c0c); }
.torch::before {
  content: ''; position: absolute; left: 50%; top: -26px; width: 26px; height: 34px; translate: -50% 0;
  border-radius: 50% 50% 45% 45%; background: radial-gradient(circle at 50% 70%, #fff3c4, #ffb03a 45%, rgba(255, 90, 20, 0) 75%);
  animation: flicker 0.18s ease-in-out infinite alternate;
}
.torch::after { content: ''; position: absolute; left: 50%; top: -60px; width: 220px; height: 220px; translate: -50% 0; border-radius: 50%; background: radial-gradient(circle, rgba(255, 170, 60, 0.22), transparent 65%); pointer-events: none; }
.torch.t1 { left: 12%; } .torch.t2 { right: 12%; }
@keyframes flicker { to { transform: scale(1.08, 0.94) translateY(1px); opacity: 0.85; } }
.sparks { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* fighters: official renders cropped around the body (main-raw is 1600x1200, body ~x 39-59 %, y 31-82 %) */
.fighter { position: absolute; bottom: 7%; width: 30%; height: 82%; z-index: 2; transition: left 0.3s, right 0.3s; }
.fighter.f-a { left: 14%; } .fighter.f-b { right: 14%; }
.fighter .body { position: absolute; inset: 0; overflow: hidden; }
.fighter .body img {
  position: absolute; left: 50%; top: -25%; height: 138.9%; width: auto; max-width: none;
  translate: -50% 0; filter: drop-shadow(0 12px 18px rgba(0, 0, 0, 0.6));
}
.fighter.f-b .body img { transform: scaleX(-1); }
.fighter .body .no-render { position: absolute; left: 50%; bottom: 10%; translate: -50% 0; width: 46%; aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; font: 900 42px 'Cinzel', serif; color: var(--gold); background: radial-gradient(circle, #1f3f80, #081430); border: 2px solid var(--gold); }
.fighter::after { content: ''; position: absolute; left: 22%; right: 22%; bottom: -2%; height: 7%; border-radius: 50%; background: radial-gradient(rgba(0, 0, 0, 0.7), transparent 70%); z-index: -1; }
.fighter .aura { position: absolute; inset: 10% 15% 0; border-radius: 50%; opacity: 0; transition: opacity 0.25s, box-shadow 0.25s; pointer-events: none; }
.fighter.casting .aura { opacity: 1; box-shadow: 0 0 60px 10px var(--school, #fff), inset 0 0 40px var(--school, #fff); }
.fighter.immune .body::before { content: ''; position: absolute; inset: 8% 12% 0; border-radius: 48% 48% 40% 40%; border: 3px solid rgba(255, 230, 140, 0.9); box-shadow: 0 0 30px rgba(255, 220, 120, 0.8), inset 0 0 30px rgba(255, 220, 120, 0.5); z-index: 3; animation: pulse 1.2s infinite; }
.fighter.shielded .body::after { content: ''; position: absolute; inset: 10% 14% 2%; border-radius: 50%; background: radial-gradient(circle, transparent 55%, rgba(140, 200, 255, 0.35) 70%, transparent 72%); box-shadow: 0 0 24px rgba(140, 200, 255, 0.6); z-index: 3; }
.fighter.lunge-a { animation: lungeA 0.32s ease-out; } .fighter.lunge-b { animation: lungeB 0.32s ease-out; }
@keyframes lungeA { 40% { transform: translateX(32%) rotate(3deg); } }
@keyframes lungeB { 40% { transform: translateX(-32%) rotate(-3deg); } }
.fighter.hit .body img { animation: hitflash 0.3s; }
@keyframes hitflash { 30% { filter: brightness(2.2) sepia(1) hue-rotate(-30deg) saturate(4) drop-shadow(0 0 10px red); } }
.fighter.hit { animation: recoil 0.25s; }
@keyframes recoil { 40% { transform: translateX(var(--recoil, 0)); } }
.fighter.f-a.hit { --recoil: -4%; } .fighter.f-b.hit { --recoil: 4%; }
.fighter.cc .body img { filter: grayscale(0.6) brightness(0.8) drop-shadow(0 12px 18px rgba(0, 0, 0, 0.6)); }
.fighter .ccmark { position: absolute; left: 50%; top: 4%; translate: -50% 0; font-size: 26px; animation: spin 1s linear infinite; z-index: 4; }
@keyframes spin { to { transform: rotate(360deg); } }
.fighter.dead { animation: fall 1.1s ease-in forwards; }
@keyframes fall { to { transform: translateY(14%) rotate(var(--fall, 80deg)); opacity: 0.25; filter: grayscale(1); } }
.fighter.f-a.dead { --fall: -80deg; }
.fighter.victor .body img { animation: victory 1.4s ease-in-out infinite; }
@keyframes victory { 50% { transform: var(--flip, none) translateY(-3%); filter: drop-shadow(0 0 22px rgba(255, 220, 120, 0.9)); } }
.fighter.f-b.victor { --flip: scaleX(-1); }
.castbar { position: absolute; left: 22%; right: 22%; bottom: -5%; height: 14px; border-radius: 7px; background: rgba(0, 0, 0, 0.7); border: 1px solid var(--gold-dim); overflow: hidden; opacity: 0; transition: opacity 0.15s; z-index: 5; }
.fighter.casting .castbar { opacity: 1; }
.castbar i { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, var(--gold-2), #ffe9a8); }
.castbar span { position: absolute; inset: 0; display: grid; place-items: center; font: 700 10px 'Alegreya Sans', sans-serif; color: #fff; text-shadow: 0 1px 2px #000; white-space: nowrap; }

/* HUD */
.hud { position: absolute; top: 3%; width: 38%; z-index: 6; }
.hud-a { left: 2.5%; } .hud-b { right: 2.5%; text-align: right; }
.hud .who { display: flex; align-items: center; gap: 8px; }
.hud-b .who { flex-direction: row-reverse; }
.hud img.av { width: 42px; height: 42px; border-radius: 50%; object-fit: cover; box-shadow: 0 0 0 2px var(--c, var(--gold)), 0 0 14px rgba(0, 0, 0, 0.6); }
.hud .nm { font: 700 clamp(13px, 1.8vw, 20px) 'Cinzel', serif; text-shadow: 0 2px 3px #000; line-height: 1.1; }
.hud .sb { font-size: clamp(10px, 1.2vw, 13px); color: #c9d3e6; text-shadow: 0 1px 2px #000; }
.hpbar { position: relative; height: clamp(12px, 1.8vw, 18px); margin-top: 6px; border-radius: 9px; background: rgba(0, 0, 0, 0.7); border: 1px solid rgba(255, 255, 255, 0.18); overflow: hidden; }
.hpbar i { position: absolute; inset: 0 auto 0 0; width: 100%; background: linear-gradient(180deg, #7dff9a, #24a947); transition: width 0.25s ease-out, background 0.4s; }
.hud-b .hpbar i { inset: 0 0 0 auto; }
.hpbar i.mid { background: linear-gradient(180deg, #ffe27a, #c99a1a); }
.hpbar i.low { background: linear-gradient(180deg, #ff8a7a, #c22a1a); }
.hpbar b { position: absolute; inset: 0; display: grid; place-items: center; font: 800 clamp(9px, 1.1vw, 12px) 'Alegreya Sans', sans-serif; text-shadow: 0 1px 2px #000; }
.clock { position: absolute; top: 3%; left: 50%; translate: -50% 0; z-index: 6; padding: 3px 12px; border-radius: 999px; background: rgba(0, 0, 0, 0.55); border: 1px solid var(--gold-dim); color: var(--gold); font: 700 clamp(11px, 1.4vw, 15px) 'Cinzel', serif; }

/* floating combat text, projectiles, effects */
.fx { position: absolute; inset: 0; pointer-events: none; z-index: 7; }
.fct { position: absolute; translate: -50% 0; font: 800 clamp(14px, 2.2vw, 26px) 'Alegreya Sans', sans-serif; color: #fff; text-shadow: 0 2px 0 #000, 0 0 10px rgba(0, 0, 0, 0.8); white-space: nowrap; animation: float 1.1s ease-out forwards; }
.fct.crit { font-size: clamp(20px, 3.4vw, 40px); color: #ffd84a; animation: critpop 1.3s ease-out forwards; }
.fct.small { font-size: clamp(11px, 1.5vw, 17px); opacity: 0.9; }
.fct.heal { color: #5dff7d; }
.fct.word { color: #e6ebf5; font-style: italic; font-size: clamp(12px, 1.7vw, 19px); }
.fct.label { color: var(--gold); font: 700 clamp(10px, 1.3vw, 15px) 'Cinzel', serif; }
@keyframes float { from { transform: translateY(0); opacity: 1; } to { transform: translateY(-70px); opacity: 0; } }
@keyframes critpop { 0% { transform: scale(0.4); opacity: 1; } 15% { transform: scale(1.35); } 30% { transform: scale(1); } 100% { transform: translateY(-80px); opacity: 0; } }
.proj { position: absolute; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%; background: radial-gradient(circle, #fff, var(--c) 45%, transparent 70%); box-shadow: 0 0 18px 6px var(--c); }
.proj.arrow { width: 34px; height: 4px; margin: -2px 0 0 -17px; border-radius: 2px; background: linear-gradient(90deg, transparent, #e6d3a3 30%, #fff); box-shadow: 0 0 8px rgba(255, 240, 200, 0.6); }
.burst { position: absolute; width: 90px; height: 90px; margin: -45px 0 0 -45px; border-radius: 50%; background: radial-gradient(circle, var(--c), transparent 65%); animation: burst 0.45s ease-out forwards; }
@keyframes burst { from { transform: scale(0.2); opacity: 1; } to { transform: scale(1.6); opacity: 0; } }
.slash { position: absolute; width: 110px; height: 110px; margin: -55px 0 0 -55px; border-radius: 50%; border-top: 5px solid rgba(255, 255, 255, 0.9); filter: drop-shadow(0 0 8px #fff); animation: slash 0.28s ease-out forwards; }
@keyframes slash { from { transform: rotate(-60deg) scale(0.6); opacity: 1; } to { transform: rotate(80deg) scale(1.1); opacity: 0; } }
.sparkle { position: absolute; width: 8px; height: 8px; border-radius: 50%; background: #9dffb0; box-shadow: 0 0 10px #5dff7d; animation: rise 1s ease-out forwards; }
@keyframes rise { to { transform: translateY(-90px); opacity: 0; } }

.banner {
  position: absolute; left: 50%; top: 40%; translate: -50% -50%; z-index: 8; padding: 12px 34px; text-align: center;
  font: 900 clamp(26px, 5.5vw, 64px) 'Cinzel Decorative', 'Cinzel', serif; color: var(--gold);
  text-shadow: 0 4px 0 #000, 0 0 30px rgba(232, 192, 101, 0.7); animation: bannerIn 0.6s cubic-bezier(.2, 1.4, .4, 1) both; white-space: nowrap;
}
.banner small { display: block; font: 700 clamp(12px, 1.8vw, 20px) 'Cinzel', serif; color: #fff; letter-spacing: 0.08em; }
@keyframes bannerIn { from { transform: scale(2.2); opacity: 0; } }

/* controls, result, log */
.controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 12px 0; }
.controls button, .speed button { padding: 7px 14px; border-radius: 8px; border: 1px solid var(--gold-dim); background: rgba(12, 26, 53, 0.9); color: var(--gold); cursor: pointer; font-weight: 700; }
.controls button:hover { border-color: var(--gold); }
.speed { display: flex; gap: 0; }
.speed button { border-radius: 0; }
.speed button:first-child { border-radius: 8px 0 0 8px; } .speed button:last-child { border-radius: 0 8px 8px 0; }
.speed button.on { background: rgba(232, 192, 101, 0.18); color: #fff; }
.result { padding: 16px; border-radius: 12px; border: 1px solid var(--line); background: linear-gradient(180deg, rgba(20, 42, 85, 0.85), rgba(8, 18, 40, 0.9)); animation: rise2 0.4s ease-out; }
@keyframes rise2 { from { opacity: 0; transform: translateY(8px); } }
.result h2 { margin: 0 0 10px; text-align: center; font: 700 20px 'Cinzel', serif; color: var(--gold); }
.result table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.result th, .result td { padding: 6px 8px; border-bottom: 1px solid rgba(201, 162, 74, 0.12); text-align: center; }
.result th { color: var(--muted); font: 700 11px 'Cinzel', serif; letter-spacing: 0.1em; text-transform: uppercase; }
.result td:first-child, .result th:first-child { text-align: left; color: var(--muted); }
.odds { margin-top: 14px; }
.odds-bar { display: flex; height: 22px; border-radius: 11px; overflow: hidden; border: 1px solid rgba(255, 255, 255, 0.15); }
.odds-bar i { display: grid; place-items: center; font: 800 12px 'Alegreya Sans', sans-serif; font-style: normal; color: #fff; text-shadow: 0 1px 2px #000; }
.odds-bar i.a { background: linear-gradient(90deg, #1d4f9a, var(--side-a)); }
.odds-bar i.b { background: linear-gradient(90deg, var(--side-b), #8a1f14); }
.odds p { margin: 6px 0 0; text-align: center; color: var(--muted); font-size: 13.5px; }
.log { margin-top: 12px; border: 1px solid var(--line); border-radius: 10px; background: rgba(5, 12, 28, 0.6); }
.log summary { padding: 10px 14px; cursor: pointer; color: var(--gold); font: 700 13px 'Cinzel', serif; letter-spacing: 0.08em; }
.log ol { max-height: 300px; overflow-y: auto; margin: 0; padding: 0 14px 12px 40px; font-size: 13.5px; color: #c9d3e6; }
.log li { padding: 1px 0; }
.log .t { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 6px; }

.foot { width: min(900px, calc(100% - 24px)); margin: 10px auto 30px; text-align: center; color: var(--muted); font-size: 13px; }
.foot .legal { font-size: 11.5px; opacity: 0.75; }
.toast { position: fixed; left: 50%; bottom: 20px; translate: -50% 20px; padding: 10px 18px; border-radius: 8px; border: 1px solid var(--gold); background: #10234a; color: var(--gold); font-weight: 700; opacity: 0; transition: opacity 0.2s, translate 0.25s; pointer-events: none; z-index: 50; }
.toast.show { opacity: 1; translate: -50% 0; }

@media (max-width: 700px) {
  .pickers { grid-template-columns: 1fr; }
  .vs { order: 0; }
  .top h1 { font-size: 34px; }
  .fighter { width: 40%; }
  .fighter.f-a { left: 6%; } .fighter.f-b { right: 6%; }
  .hud { width: 44%; }
  .hud img.av { width: 30px; height: 30px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
