/* ============================================================
   Battle Live — arena (the screen you capture into TikTok LIVE)

   Laid out for a 9:16 capture. The battlefield is canvas; everything
   with text in it is DOM, because crisp type and easy layout beat
   hand-drawing labels every time.
   ============================================================ */

:root {
  --a: #ff2d75;
  --a-soft: #ff7aa8;
  --a-deep: #7a0b30;
  --b: #16e0ff;
  --b-soft: #7cefff;
  --b-deep: #064a5c;

  --ink: #f4f7ff;
  --dim: rgba(244, 247, 255, 0.55);
  --faint: rgba(244, 247, 255, 0.28);

  --hud-pad: clamp(10px, 2.4vw, 22px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: #05060f;
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  isolation: isolate;
}

/* The canvas carries its own background gradient; this layer only adds the
   slow ambient wash so the scene never looks flat when the field is quiet. */
#field {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#app::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(60% 40% at 12% 45%, rgba(255, 45, 117, 0.16), transparent 70%),
    radial-gradient(60% 40% at 88% 45%, rgba(22, 224, 255, 0.16), transparent 70%);
}

/* Vignette + scanlines: cheap, and they make a flat capture read as "broadcast". */
#app::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  background:
    repeating-linear-gradient(180deg, rgba(0, 0, 0, 0.16) 0 1px, transparent 1px 3px),
    radial-gradient(120% 80% at 50% 50%, transparent 55%, rgba(0, 0, 0, 0.72) 100%);
  opacity: 0.5;
}

.hud {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  padding: var(--hud-pad);
  pointer-events: none;
}

/* ------------------------------------------------------------ header */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.round {
  font-size: clamp(10px, 2.2vw, 14px);
  font-weight: 800;
  letter-spacing: 0.22em;
  color: var(--faint);
  text-transform: uppercase;
}

.timer {
  font-size: clamp(26px, 7vw, 46px);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1;
  text-shadow: 0 0 24px rgba(255, 255, 255, 0.35);
}

.timer.urgent {
  color: #ffd166;
  animation: pulse 0.8s ease-in-out infinite;
}

@keyframes pulse {
  50% { opacity: 0.45; }
}

.phase {
  font-size: clamp(10px, 2.2vw, 14px);
  font-weight: 800;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(8px);
}

/* ------------------------------------------------------------ hp bars */

.bars {
  margin-top: clamp(8px, 2vw, 16px);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: clamp(6px, 1.6vw, 14px);
}

.side-name {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
  font-size: clamp(11px, 2.6vw, 16px);
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.side-b .side-name { flex-direction: row-reverse; }

.side-a .side-name { color: var(--a-soft); }
.side-b .side-name { color: var(--b-soft); }

.crowd {
  font-size: 0.72em;
  font-weight: 700;
  color: var(--dim);
  letter-spacing: 0.04em;
}

.track {
  position: relative;
  height: clamp(14px, 3.4vw, 22px);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.fill {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  transition: transform 260ms cubic-bezier(0.22, 1, 0.36, 1);
}

.side-a .fill {
  background: linear-gradient(90deg, var(--a-deep), var(--a) 65%, var(--a-soft));
  box-shadow: 0 0 18px rgba(255, 45, 117, 0.75) inset, 0 0 22px rgba(255, 45, 117, 0.45);
}

/* Team B drains toward the right edge so both bars empty toward the centre. */
.side-b .fill {
  transform-origin: right center;
  background: linear-gradient(270deg, var(--b-deep), var(--b) 65%, var(--b-soft));
  box-shadow: 0 0 18px rgba(22, 224, 255, 0.75) inset, 0 0 22px rgba(22, 224, 255, 0.45);
}

/* Ghost bar: lags behind the real value so a big hit reads as a chunk taken. */
.ghost {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.5);
  transform-origin: left center;
  transition: transform 900ms 180ms cubic-bezier(0.4, 0, 0.2, 1);
  opacity: 0.28;
}

.side-b .ghost { transform-origin: right center; }

.hp-num {
  margin-top: 5px;
  font-size: clamp(10px, 2.2vw, 13px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--dim);
}

.side-b .hp-num { text-align: right; }

.vs {
  font-size: clamp(14px, 3.4vw, 22px);
  font-weight: 900;
  font-style: italic;
  letter-spacing: -0.03em;
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
  transform: translateY(-2px);
}

.side.hit .track { animation: jolt 220ms ease-out; }

@keyframes jolt {
  30% { transform: translateX(-4px) scaleY(1.18); }
  60% { transform: translateX(3px) scaleY(0.94); }
}

/* ------------------------------------------------------------ cheers */

/* Free-engagement feed. Sits in the gap under the HP bars, which is otherwise
   dead space, so it never fights the battlefield or the leaderboards. */
.cheers {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: flex-start;
  min-height: clamp(30px, 8vw, 62px);
}

.cheer {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px 5px 6px;
  border-radius: 999px;
  font-size: clamp(10px, 2.4vw, 13px);
  font-weight: 800;
  background: rgba(10, 12, 26, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(6px);
  animation: cheerIn 320ms cubic-bezier(0.2, 1.2, 0.3, 1);
  white-space: nowrap;
  max-width: 100%;
}

.cheer.out { animation: cheerOut 380ms ease forwards; }

.cheer.side-B { align-self: flex-end; flex-direction: row-reverse; padding: 5px 6px 5px 12px; }

.cheer .who {
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 12ch;
}

.cheer .icon {
  width: 1.6em;
  height: 1.6em;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 0.95em;
}

.cheer.follow { border-color: rgba(255, 209, 102, 0.6); box-shadow: 0 0 18px rgba(255, 209, 102, 0.25); }
.cheer.follow .icon { background: rgba(255, 209, 102, 0.22); }
.cheer.share .icon { background: rgba(120, 200, 255, 0.22); }
.cheer.like .icon { background: rgba(255, 90, 140, 0.22); }

.cheer .heal { color: #6ee7a0; font-variant-numeric: tabular-nums; }

@keyframes cheerIn {
  from { opacity: 0; transform: translateY(-8px) scale(0.9); }
}

@keyframes cheerOut {
  to { opacity: 0; transform: translateX(-14px) scale(0.94); }
}

/* ------------------------------------------------------------ callout */

.callout {
  position: absolute;
  left: 0;
  right: 0;
  /* Clear of the entrance banner at 30%. A big gift fires both at once, and
     stacked on top of each other neither one is readable. */
  top: 47%;
  text-align: center;
  font-size: clamp(24px, 8vw, 54px);
  font-weight: 900;
  font-style: italic;
  letter-spacing: -0.03em;
  pointer-events: none;
  opacity: 0;
  z-index: 3;
}

.callout.fire {
  animation: callout 900ms cubic-bezier(0.16, 1.2, 0.3, 1);
}

@keyframes callout {
  0% { opacity: 0; transform: scale(2.2); filter: blur(14px); }
  22% { opacity: 1; transform: scale(1); filter: blur(0); }
  70% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.94); }
}

/* ------------------------------------------------------------ centre */

.middle {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.call {
  text-align: center;
  padding: 18px 26px;
  border-radius: 20px;
  background: rgba(6, 8, 22, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(10px);
  animation: rise 400ms cubic-bezier(0.22, 1, 0.36, 1);
}

.call.hidden { display: none; }

.call-title {
  font-size: clamp(18px, 5vw, 30px);
  font-weight: 900;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

.call-keys {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin: 14px 0 10px;
}

.key {
  min-width: clamp(52px, 14vw, 76px);
  padding: 10px 0;
  border-radius: 14px;
  font-size: clamp(22px, 6vw, 34px);
  font-weight: 900;
  line-height: 1;
}

.key-a {
  background: linear-gradient(160deg, var(--a), var(--a-deep));
  box-shadow: 0 0 26px rgba(255, 45, 117, 0.55);
}

.key-b {
  background: linear-gradient(160deg, var(--b), var(--b-deep));
  box-shadow: 0 0 26px rgba(22, 224, 255, 0.55);
}

.call-sub {
  font-size: clamp(11px, 2.8vw, 15px);
  font-weight: 600;
  color: var(--dim);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px) scale(0.96); }
}

/* ------------------------------------------------------------ boards */

.boards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(8px, 2vw, 18px);
  align-items: end;
}

.board {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: clamp(9px, 2.2vw, 12px);
}

.board-title {
  font-weight: 900;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 2px;
}

.board-b { align-items: flex-end; }

.row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  max-width: 100%;
  animation: rise 300ms ease-out;
}

.board-b .row { flex-direction: row-reverse; }

.row .nick {
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 11ch;
}

.row .dmg {
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.board-a .dmg { color: var(--a-soft); }
.board-b .dmg { color: var(--b-soft); }

.medal { font-size: 1.05em; }

/* ------------------------------------------------------------ entrance */

/* The big-spender moment. Sweeps across the arena, holds, and leaves.
   Deliberately loud — this is the reward the next rocket is buying. */
.entrance {
  position: absolute;
  left: 0;
  right: 0;
  top: 30%;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: clamp(8px, 2.4vw, 16px);
  padding: clamp(8px, 2vw, 14px) clamp(14px, 4vw, 26px);
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(90deg,
    rgba(0, 0, 0, 0) 0%,
    rgba(10, 10, 24, 0.94) 12%,
    rgba(10, 10, 24, 0.94) 88%,
    rgba(0, 0, 0, 0) 100%);
  border-top: 2px solid var(--ent, #ffd166);
  border-bottom: 2px solid var(--ent, #ffd166);
  box-shadow: 0 0 60px rgba(255, 209, 102, 0.35);
}

.entrance.show { animation: sweep 2600ms cubic-bezier(0.2, 0.9, 0.2, 1); }

@keyframes sweep {
  0% { opacity: 0; transform: translateX(-100%) skewX(-8deg); }
  14% { opacity: 1; transform: translateX(0) skewX(0); }
  80% { opacity: 1; transform: translateX(0); }
  100% { opacity: 0; transform: translateX(60%); }
}

.ent-avatar {
  width: clamp(38px, 11vw, 62px);
  height: clamp(38px, 11vw, 62px);
  flex: none;
  border-radius: 50%;
  border: 2px solid var(--ent, #ffd166);
  background-size: cover;
  background-position: center;
  display: grid;
  place-items: center;
  font-size: clamp(15px, 4vw, 24px);
  font-weight: 900;
  box-shadow: 0 0 24px rgba(255, 209, 102, 0.5);
}

.ent-text { min-width: 0; }

.ent-nick {
  font-size: clamp(15px, 4.4vw, 26px);
  font-weight: 900;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ent-gift {
  font-size: clamp(10px, 2.8vw, 15px);
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ent, #ffd166);
}

/* ------------------------------------------------------------ result */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 300ms ease;
  background: radial-gradient(60% 45% at 50% 50%, rgba(5, 6, 15, 0.82), rgba(5, 6, 15, 0.94));
}

.overlay.show { opacity: 1; }

.win {
  text-align: center;
  animation: slam 620ms cubic-bezier(0.16, 1.3, 0.3, 1);
}

.win-crown {
  font-size: clamp(30px, 9vw, 62px);
  line-height: 1;
  margin-bottom: 4px;
  filter: drop-shadow(0 0 20px rgba(255, 209, 102, 0.85));
  animation: crownDrop 700ms cubic-bezier(0.2, 1.4, 0.35, 1);
}

@keyframes crownDrop {
  0% { opacity: 0; transform: translateY(-60px) rotate(-25deg) scale(0.5); }
  100% { opacity: 1; transform: none; }
}

.win-label {
  font-size: clamp(11px, 2.8vw, 16px);
  font-weight: 800;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--dim);
}

.win-side {
  font-size: clamp(44px, 15vw, 108px);
  font-weight: 900;
  font-style: italic;
  letter-spacing: -0.04em;
  line-height: 0.95;
  margin: 6px 0 12px;
}

.win-side.A { color: var(--a); text-shadow: 0 0 50px rgba(255, 45, 117, 0.9); }
.win-side.B { color: var(--b); text-shadow: 0 0 50px rgba(22, 224, 255, 0.9); }
.win-side.draw { color: var(--ink); text-shadow: 0 0 50px rgba(255, 255, 255, 0.6); }

.win-mvp {
  font-size: clamp(12px, 3.2vw, 18px);
  font-weight: 700;
  color: var(--ink);
}

.win-mvp span { color: #ffd166; }

@keyframes slam {
  0% { opacity: 0; transform: scale(1.6); filter: blur(10px); }
  100% { opacity: 1; transform: scale(1); filter: blur(0); }
}

/* Wide screens: keep the 9:16 stage centred instead of stretching it. */
@media (min-aspect-ratio: 1/1) {
  #app {
    width: min(100vw, calc(100vh * 9 / 16));
    margin: 0 auto;
    box-shadow: 0 0 90px rgba(0, 0, 0, 0.85);
  }
  body { background: #02030a; }
}
