/* ============================================================
   battle-search.css
   Styling for the shared Battle matchmaking component
   (js/live-rush/battle-search.js): the Searching-for-opponent
   screen and the VS transition.

   Self-contained on purpose — the component mounts as a fixed
   overlay on ANY page (the startup screen's Battle hero and the
   Live Rush screen both use it), so nothing here may depend on
   the Dual/Live Rush shells (.crdm-* / .crlr-menu). Pair it with
   css/player-avatar.css for the avatars.
   ============================================================ */

/* Interactive space backdrop (js/live-rush/space-backdrop.js). A full-screen
   canvas sibling that sits BEHIND the transparent overlay so the player can
   drag to pan and pinch/wheel to zoom the starfield — the Adventure Rush map
   feel. touch-action:none keeps touch drags on the canvas instead of scrolling
   the page. z-index one below the overlay, both above host chrome (nav 9999). */
.crbs-bg {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  pointer-events: auto;
  cursor: grab;
  /* Base fill in case the canvas context is unavailable. */
  background: radial-gradient(circle at 50% 42%, #150a3a 0%, #0a0326 45%, #04010f 100%);
  animation: crbsVeilIn 180ms ease both;
}

.crbs-bg:active { cursor: grabbing; }

/* The overlay is transparent and non-interactive except its controls, so an
   empty-space drag falls through to the canvas below; only .crbs-btn captures. */
.crbs-overlay {
  position: fixed;
  inset: 0;
  z-index: 10001;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    calc(env(safe-area-inset-top, 0px) + 14px)
    clamp(12px, 4vw, 24px)
    calc(env(safe-area-inset-bottom, 0px) + 14px);
  box-sizing: border-box;
  background: transparent;
  pointer-events: none;
  animation: crbsVeilIn 180ms ease both;
}

.crbs-panel {
  width: min(560px, 100%);
  max-height: 100%;
  box-sizing: border-box;
}

@keyframes crbsVeilIn { from { opacity: 0; } }

/* Component-owned controls (no .crdm-btn dependency). */
.crbs-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.crbs-btn {
  /* The overlay is pointer-events:none so drags reach the canvas backdrop;
     the interactive controls opt back in. */
  pointer-events: auto;
  min-height: 42px;
  padding: 10px 22px;
  border: 2px solid transparent;
  border-radius: 999px;
  background:
    linear-gradient(rgba(7, 0, 22, .92), rgba(7, 0, 22, .92)) padding-box,
    linear-gradient(100deg, #815cff 0%, #f044d9 100%) border-box;
  color: #fff;
  font: 950 .92rem/1 var(--font-ui-heavy, system-ui);
  text-shadow: 0 2px 0 rgba(0, 0, 0, .7);
  cursor: pointer;
  box-shadow: 0 0 14px rgba(137, 92, 255, .28);
}

.crbs-btn--primary {
  background: linear-gradient(100deg, #41efff 0%, #815cff 50%, #f044d9 100%);
  border-color: rgba(255, 255, 255, .74);
}

.crbs-btn:disabled { opacity: .6; cursor: default; }
.crbs-btn:active:not(:disabled) { transform: scale(.97); }

.crbs-spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(83, 216, 255, .25);
  border-top-color: #53d8ff;
  animation: crbsSpin .8s linear infinite;
}

@keyframes crbsSpin { to { transform: rotate(360deg); } }

.crbs-message {
  min-height: 18px;
  margin: 0;
  text-align: center;
  color: #9ef0ff;
  font-size: .82rem;
  font-weight: 800;
}

.crbs-message--error { color: #ff9aaa; }

/* Friend invite expiry countdown */
.crbs-invite-timer {
  margin: 4px 0 12px;
  text-align: center;
  color: #9ef0ff;
  font-size: .86rem;
  font-weight: 700;
  letter-spacing: .02em;
}
.crbs-invite-count {
  display: inline-block;
  min-width: 1.4em;
  padding: 1px 7px;
  margin: 0 1px;
  border-radius: 8px;
  background: rgba(0, 229, 255, 0.14);
  color: #eaf6ff;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

/* ── Searching / VS panels ─────────────────────────────────────
   Frameless: no border, no card fill, no spinning energy field — the
   overlay's starfield and pulsing rings ARE the background, and the content
   floats directly on them. Sized to the viewport so nothing ever scrolls. */
.crlr-search,
.crlr-vs {
  position: relative;
  width: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 1.6vh, 13px);
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
  text-align: center;
}

.crlr-search-kicker,
.crlr-vs-kicker {
  margin: 0;
  color: #8ff9ff;
  font-size: .68rem;
  font-weight: 950;
  letter-spacing: .22em;
  text-transform: uppercase;
}

.crlr-search h1,
.crlr-vs h1 {
  max-width: 100%;
  margin: 0;
  color: #fff;
  font: 950 clamp(2rem, 9vw, 4.2rem)/.92 var(--font-ui-heavy, Impact, system-ui);
  text-transform: uppercase;
  text-shadow: 0 0 13px rgba(42,246,255,.72), 0 0 32px rgba(255,71,222,.48);
}

.crlr-search-config,
.crlr-vs-config {
  margin: 0;
  color: rgba(223, 246, 255, .72);
  font-size: clamp(.68rem, 3vw, .88rem);
  font-weight: 850;
}

.crlr-search-stage,
.crlr-vs-stage {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(72px, .7fr) minmax(0, 1fr);
  align-items: center;
  margin: clamp(16px, 4vh, 30px) 0;
}

.crlr-search-player,
.crlr-vs-player {
  min-width: 0;
  display: grid;
  justify-items: center;
  gap: 10px;
}

.crlr-search-player .player-avatar { --avatar-size: clamp(78px, 22vw, 112px); }
.crlr-vs-player .player-avatar { --avatar-size: clamp(88px, 25vw, 126px); border-width: 2px; }
.crlr-vs-player--opponent .player-avatar { border-color: rgba(255, 91, 111, .82); --avatar-glow: rgba(255, 47, 88, .6); }

.crlr-search-player strong,
.crlr-vs-player strong {
  max-width: 100%;
  overflow: hidden;
  color: #f4fdff;
  font-size: clamp(.72rem, 3.2vw, .98rem);
  text-overflow: ellipsis;
  text-shadow: 0 2px 7px #000;
  white-space: nowrap;
}

.crlr-search-player--empty .player-avatar {
  border-style: dashed;
  color: rgba(209, 244, 255, .48);
  background: rgba(9, 18, 42, .6);
  animation: crlrEmptySlot 1.5s ease-in-out infinite;
}

.crlr-search-link { position: relative; height: 4px; background: rgba(93,236,255,.16); }
.crlr-search-link span { position: absolute; inset: 0; background: linear-gradient(90deg, transparent, #6af6ff, transparent); animation: crlrLinkSweep 1.2s linear infinite; }
.crlr-search-link i { position: absolute; left: 50%; top: 50%; width: 11px; height: 11px; border-radius: 50%; background: #fff; box-shadow: 0 0 14px #2af6ff; transform: translate(-50%,-50%); }

.crlr-searching-dots { display: flex; gap: 7px; margin-bottom: 6px; }
.crlr-searching-dots i { width: 7px; height: 7px; border-radius: 50%; background: #74f7ff; box-shadow: 0 0 9px #2af6ff; animation: crlrDot 1.1s ease-in-out infinite; }
.crlr-searching-dots i:nth-child(2) { animation-delay: .16s; }
.crlr-searching-dots i:nth-child(3) { animation-delay: .32s; }

.crlr-vs-player--local { animation: crlrPlayerInLeft .55s cubic-bezier(.2,.9,.22,1) both; }
.crlr-vs-player--opponent { animation: crlrPlayerInRight .55s cubic-bezier(.2,.9,.22,1) both; }
.crlr-vs-player small { display: inline-flex; align-items: center; gap: 6px; color: rgba(213,244,255,.58); font-size: .58rem; font-weight: 850; text-transform: uppercase; }
.crlr-vs-player small i { width: 6px; height: 6px; border-radius: 50%; background: #58ff9d; box-shadow: 0 0 8px #58ff9d; }

.crlr-vs-impact {
  position: relative;
  display: grid;
  place-items: center;
  width: clamp(68px, 19vw, 100px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0 3%, #58eaff 8%, #7638c8 34%, transparent 68%);
  filter: drop-shadow(0 0 22px rgba(104, 232, 255, .88));
  animation: crlrVsImpact .78s .42s cubic-bezier(.1,.8,.2,1.3) both;
}

.crlr-vs-impact::before,
.crlr-vs-impact::after { content: ""; position: absolute; left: 50%; top: 50%; width: 160%; height: 2px; background: linear-gradient(90deg, transparent, #fff, transparent); transform: translate(-50%,-50%) rotate(26deg); }
.crlr-vs-impact::after { transform: translate(-50%,-50%) rotate(-26deg); }
.crlr-vs-impact span { color: #fff; font: 950 clamp(2rem, 9vw, 3.5rem)/1 var(--font-ui-heavy, Impact, system-ui); transform: skew(-8deg); -webkit-text-stroke: 1px rgba(255,255,255,.9); text-shadow: 3px 3px 0 #7f174f, -3px -3px 0 #087cad, 0 0 18px #fff; }

.crlr-vs-ready { margin: 0; color: #fff; font: 950 clamp(1.2rem, 5vw, 1.7rem)/1 var(--font-ui-heavy, system-ui); letter-spacing: .16em; text-transform: uppercase; text-shadow: 0 0 14px #2af6ff; animation: crlrReadyPulse .9s 1.1s ease-in-out infinite; }
.crlr-vs-load { width: min(260px, 70%); height: 4px; overflow: hidden; border-radius: 999px; background: rgba(147,230,255,.14); }
.crlr-vs-load span { display: block; width: 100%; height: 100%; background: linear-gradient(90deg, #2af6ff, #fff, #ff47de); transform-origin: left; animation: crlrLoad 2.8s linear both; }

.crlr-disconnect-icon { display: grid; place-items: center; width: 72px; height: 72px; border: 2px solid #ff6687; border-radius: 50%; color: #fff; background: rgba(255,49,90,.16); font: 950 2.4rem/1 var(--font-ui-heavy, system-ui); box-shadow: 0 0 24px rgba(255,49,90,.42); }

@keyframes crlrEmptySlot { 50% { opacity: .48; transform: scale(.94); } }
@keyframes crlrLinkSweep { from { transform: translateX(-55%); } to { transform: translateX(55%); } }
@keyframes crlrDot { 50% { opacity: .25; transform: translateY(-5px); } }
@keyframes crlrPlayerInLeft { from { opacity: 0; transform: translateX(-80px) scale(.82); } }
@keyframes crlrPlayerInRight { from { opacity: 0; transform: translateX(80px) scale(.82); } }
@keyframes crlrVsImpact { from { opacity: 0; transform: scale(2.2) rotate(-16deg); filter: brightness(3) drop-shadow(0 0 50px #fff); } }
@keyframes crlrReadyPulse { 50% { opacity: .56; } }
@keyframes crlrLoad { from { transform: scaleX(.04); } }

@media (max-height: 720px) and (orientation: portrait) {
  .crlr-search-stage,
  .crlr-vs-stage { margin: 8px 0; }
  .crlr-search-player .player-avatar,
  .crlr-vs-player .player-avatar { --avatar-size: 76px; }
}

@media (prefers-reduced-motion: reduce) {
  .crbs-overlay::after,
  .crlr-search-player--empty .player-avatar,
  .crlr-search-link span,
  .crlr-searching-dots i,
  .crlr-vs-player,
  .crlr-vs-impact,
  .crlr-vs-ready,
  .crlr-vs-load span { animation: none !important; }
  .crlr-vs-player,
  .crlr-vs-impact { opacity: 1; transform: none; }
}
