/* Battle tab: the arena hub (BattleSelector). Your rank (its tier colour is --el), streak, record and team lineup, a big
   FIGHT button in the last mode's colour (--mode), and four small mode tiles (--tile), all on one phone screen without
   scrolling. */

.ah {
    --mode: #ff5a4f;
    display: flex;
    flex-direction: column;
    gap: 10px;
    /* The whole tab panel, less its padding, so the hub never scrolls on a phone */
    height: calc(100dvh - var(--sc-topbar-height) - var(--sc-safe-top) - var(--sc-tabbar-height) - var(--sc-safe-bottom) - 44px);
    min-height: 540px;
    max-height: 820px;
    max-width: 560px;
    margin: 0 auto;
}

/* ---- The arena ---- */

.ah-arena {
    --el: var(--sc-primary);
    position: relative;
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    align-items: center;
    min-height: 0;
    padding: 12px 14px 14px;
    overflow: hidden;
    border: 1px solid color-mix(in srgb, var(--el) 30%, var(--sc-line));
    border-radius: var(--sc-radius-lg);
    background:
        radial-gradient(ellipse 60% 42% at 50% 52%, color-mix(in srgb, var(--el) 45%, transparent), transparent 72%),
        radial-gradient(circle at 50% 130%, color-mix(in srgb, var(--mode) 35%, transparent), transparent 55%),
        linear-gradient(180deg, color-mix(in srgb, var(--el) 20%, var(--sc-bg)), var(--sc-bg-elevated) 70%);
    box-shadow: var(--sc-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    transition: border-color 0.5s ease, background 0.5s ease;
    animation: ah-in 0.45s var(--sc-ease-out) both;
}

/* A barcode floor under the team, like the card's stage */
.ah-arena::after {
    content: "";
    position: absolute;
    inset: auto 0 0;
    height: 46%;
    background: repeating-linear-gradient(90deg, color-mix(in srgb, var(--el) 20%, transparent) 0 2px, transparent 2px 7px, color-mix(in srgb, var(--el) 12%, transparent) 7px 8px, transparent 8px 12px);
    mask: linear-gradient(180deg, transparent, #000 60%, transparent);
    -webkit-mask: linear-gradient(180deg, transparent, #000 60%, transparent);
    opacity: 0.5;
    pointer-events: none;
}

.ah-arena > * {
    position: relative;
    z-index: 1;
}

.ah-arena-rays {
    position: absolute !important;
    z-index: 0 !important;
    top: 38%;
    left: 50%;
    width: 150%;
    aspect-ratio: 1;
    translate: -50% -50%;
    background: repeating-conic-gradient(from 0deg, color-mix(in srgb, var(--el) 18%, transparent) 0 7deg, transparent 7deg 20deg);
    mask: radial-gradient(circle, #000 8%, transparent 55%);
    -webkit-mask: radial-gradient(circle, #000 8%, transparent 55%);
    animation: mc-rays 50s linear infinite;
    pointer-events: none;
}

.ah-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    align-self: stretch;
    gap: 10px;
}

.ah-title {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
}

.ah-title h2 {
    margin: 0;
    font-family: var(--sc-font-display);
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    text-shadow: 0 0 16px color-mix(in srgb, var(--el) 60%, transparent);
}

.ah-online {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: var(--sc-text-muted);
    font-size: 12px;
}

.ah-record {
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    border-radius: var(--sc-radius-pill);
    background: rgba(0, 0, 0, 0.28);
    box-shadow: inset 0 0 0 1px var(--sc-line);
    font-family: var(--sc-font-display);
    font-weight: 700;
}

.ah-record > span {
    display: inline-flex;
    align-items: baseline;
    gap: 2px;
    padding: 3px 10px;
    border-radius: var(--sc-radius-pill);
    font-size: 16px;
}

.ah-record small {
    font-size: 11px;
    opacity: 0.8;
}

.ah-record .is-win { background: var(--sc-success-soft); color: var(--sc-success); }
.ah-record .is-loss { background: var(--sc-danger-soft); color: #ff9b9b; }

/* This season's rank (tinted by the tier, --el) beside the win streak */
.ah-ladder {
    display: flex;
    align-self: stretch;
    gap: 8px;
    margin-top: 12px;
}

.ah-rank,
.ah-streak {
    display: flex;
    align-items: center;
    border-radius: var(--sc-radius);
    background: rgba(0, 0, 0, 0.26);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--el) 28%, var(--sc-line));
}

.ah-rank {
    flex: 1 1 auto;
    gap: 10px;
    min-width: 0;
    padding: 8px 12px 8px 10px;
}

.ah-rank-text {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.ah-rank-line {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
}

.ah-rank-name {
    color: var(--el);
    font-family: var(--sc-font-display);
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.05em;
    line-height: 1;
    text-transform: uppercase;
}

.ah-rating {
    font-family: var(--sc-font-display);
    font-size: 18px;
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

/* How far to the next rank */
.ah-rank-bar {
    position: relative;
    height: 5px;
    overflow: hidden;
    border-radius: var(--sc-radius-pill);
    background: rgba(255, 255, 255, 0.08);
}

.ah-rank-bar > span {
    position: absolute;
    inset: 0 auto 0 0;
    width: var(--w);
    border-radius: inherit;
    background: linear-gradient(90deg, color-mix(in srgb, var(--el) 60%, transparent), var(--el));
    box-shadow: 0 0 8px color-mix(in srgb, var(--el) 60%, transparent);
    transition: width 0.6s var(--sc-ease-out);
}

.ah-season {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--sc-text-muted);
    font-size: 11px;
    line-height: 1;
}

/* The streak: a flame that lights up while a run of wins is going */
.ah-streak {
    flex: none;
    flex-direction: column;
    justify-content: center;
    gap: 1px;
    width: 72px;
    padding: 6px 4px;
    color: var(--sc-text-muted);
}

.ah-flame {
    opacity: 0.55;
}

.ah-streak-count {
    font-family: var(--sc-font-display);
    font-size: 18px;
    font-weight: 700;
    line-height: 1;
}

.ah-streak small {
    font-size: 10px;
    line-height: 1;
}

.ah-streak.is-hot {
    color: #ffb340;
    box-shadow: inset 0 0 0 1px rgba(255, 150, 50, 0.45), 0 0 18px -6px rgba(255, 120, 40, 0.7);
}

.ah-streak.is-hot .ah-flame {
    opacity: 1;
    filter: drop-shadow(0 0 6px rgba(255, 120, 40, 0.8));
    transform-origin: 50% 90%;
    animation: ah-flicker 1.4s ease-in-out infinite;
}

.ah-streak.is-hot .ah-streak-count { color: #fff; }

/* The team on its scan pads, filling the arena's floor */
.ah-team {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    justify-content: center;
    align-self: stretch;
    min-height: 0;
    padding: 6px 2px 0;
}

.ah-team .tc-row {
    justify-content: center;
    gap: 4px;
}

.ah-team .tc-capsule {
    max-width: 58px;
}


/* FIGHT: starts the last mode in one tap, glowing in that mode's colour */
.ah-fight {
    position: relative;
    display: flex;
    flex: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: min(100%, 300px);
    height: 64px;
    margin-top: 12px;
    padding: 0;
    overflow: hidden;
    border: 0;
    border-radius: var(--sc-radius-pill);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.28), transparent 55%),
        linear-gradient(135deg, color-mix(in srgb, var(--mode) 75%, #fff) 0%, var(--mode) 45%, color-mix(in srgb, var(--mode) 70%, #000) 100%);
    color: #fff;
    box-shadow: 0 6px 0 color-mix(in srgb, var(--mode) 50%, #000), 0 10px 28px color-mix(in srgb, var(--mode) 55%, transparent);
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.4s ease;
    animation: ah-fight-pulse 1.8s ease-in-out infinite;
}

/* A shine sweeping across the button */
.ah-fight::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 -40%;
    width: 30%;
    background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.45), transparent);
    transform: skewX(-20deg);
    animation: ah-shine 2.8s ease-in-out infinite;
}

.ah-fight:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 color-mix(in srgb, var(--mode) 50%, #000), 0 6px 18px color-mix(in srgb, var(--mode) 50%, transparent);
}

.ah-fight-label {
    font-family: var(--sc-font-display);
    font-size: 30px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.14em;
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
}

.ah-fight-mode {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    opacity: 0.92;
}

.ah-fight-mode .sk-mode-icon {
    color: #fff;
}

/* ---- The mode tiles ---- */

.ah-modes {
    display: grid;
    flex: none;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.ah-tile {
    --tile: var(--sc-primary);
    position: relative;
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
    align-items: center;
    column-gap: 8px;
    row-gap: 6px;
    min-height: 92px;
    padding: 12px 10px 10px;
    overflow: hidden;
    border: 1px solid color-mix(in srgb, var(--tile) 30%, var(--sc-line));
    border-radius: var(--sc-radius);
    background:
        radial-gradient(circle at 18% 22%, color-mix(in srgb, var(--tile) 26%, transparent), transparent 60%),
        linear-gradient(160deg, var(--sc-surface-2, var(--sc-surface)), var(--sc-surface));
    color: var(--sc-text);
    text-align: left;
    cursor: pointer;
    transition: transform 0.15s var(--sc-ease-spring), border-color 0.25s ease, box-shadow 0.25s ease;
    animation: ah-tile-in 0.45s var(--sc-ease-spring) both;
    animation-delay: calc(0.08s + var(--i, 0) * 0.06s);
}

.ah-tile:active {
    transform: scale(0.96);
}

.ah-tile.is-current {
    border-color: var(--tile);
    box-shadow: 0 0 0 1px var(--tile), 0 0 18px color-mix(in srgb, var(--tile) 35%, transparent);
}

.ah-tile.is-current::after {
    content: "";
    position: absolute;
    top: 8px;
    right: 8px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--tile);
    box-shadow: 0 0 8px var(--tile);
}

.ah-tile-icon {
    display: grid;
    grid-row: span 1;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: color-mix(in srgb, var(--tile) 16%, rgba(0, 0, 0, 0.2));
    color: var(--tile);
}

.ah-tile-title {
    font-family: var(--sc-font-display);
    font-size: 16px;
    font-weight: 700;
    line-height: 1.1;
}

.ah-chips {
    display: flex;
    grid-column: 1 / -1;
    flex-wrap: nowrap;
    gap: 4px;
    min-width: 0;
    overflow: hidden;
}

.ah-chip {
    display: inline-flex;
    flex: none;
    align-items: center;
    gap: 3px;
    height: 22px;
    padding: 0 7px;
    border-radius: var(--sc-radius-pill);
    background: rgba(255, 255, 255, 0.06);
    color: var(--sc-text-muted);
    font-size: 11.5px;
    font-weight: 700;
    white-space: nowrap;
}

.ah-chip ion-icon {
    font-size: 13px;
}

.ah-chip .sc-coin {
    width: 13px;
    height: 13px;
}

.ah-chip.is-danger { background: var(--sc-danger-soft); color: #ff9b9b; }
.ah-chip.is-gold { background: var(--sc-gold-soft); color: var(--sc-gold); }
.ah-chip.is-safe { background: var(--sc-success-soft); color: var(--sc-success); }

.ah-live-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--sc-text-faint);
}

.ah-chip.is-live {
    background: var(--sc-success-soft);
    color: var(--sc-success);
}

.ah-chip.is-live .ah-live-dot {
    background: var(--sc-success);
    animation: ah-live 1.4s ease-in-out infinite;
}

/* ---- Mode icon motion (ModeIcon: QuickMatch, Practice, Friends, Coil) ---- */

.sk-mode-bolt-left { animation: sk-mode-bolt-left 2.4s var(--sc-ease-out) infinite; }
.sk-mode-bolt-right { animation: sk-mode-bolt-right 2.4s var(--sc-ease-out) infinite; }
.sk-mode-quickmatch .sk-mode-sparks { animation: sk-mode-sparks 2.4s ease-out infinite; }
.sk-mode-dummy { transform-box: view-box !important; transform-origin: 32px 58px !important; animation: sk-mode-wobble 2.6s ease-in-out infinite; }
.sk-mode-dummy * { transform-box: view-box; }
.sk-mode-hit { animation: sk-mode-hit 2.6s ease-out infinite; }
.sk-mode-vs-left { animation: sk-mode-vs-left 2.2s var(--sc-ease-out) infinite; }
.sk-mode-vs-right { animation: sk-mode-vs-right 2.2s var(--sc-ease-out) infinite; }
.sk-mode-arcs { opacity: 0.25; }
.sk-mode-coil.is-active .sk-mode-arcs { opacity: 1; animation: sk-mode-crackle 0.9s steps(1) infinite; }
.sk-mode-coil.is-active .sk-mode-coil-glow { animation: sk-mode-coil-glow 0.9s steps(1) infinite; }
.sk-mode-coil.is-active .sk-mode-torus { animation: sk-mode-torus 0.9s steps(1) infinite; }

@keyframes sk-mode-bolt-left {
    0%, 100% { transform: translateX(-3px) rotate(-6deg); }
    40% { transform: translateX(1px) rotate(2deg); }
    50% { transform: none; }
}

@keyframes sk-mode-bolt-right {
    0%, 100% { transform: translateX(3px) rotate(6deg); }
    40% { transform: translateX(-1px) rotate(-2deg); }
    50% { transform: none; }
}

@keyframes sk-mode-wobble {
    0%, 30%, 100% { transform: rotate(0); }
    36% { transform: rotate(9deg); }
    46% { transform: rotate(-6deg); }
    56% { transform: rotate(3deg); }
    64% { transform: rotate(0); }
}

@keyframes sk-mode-hit {
    0%, 30% { opacity: 0; transform: translateX(-4px); }
    36% { opacity: 1; transform: none; }
    60%, 100% { opacity: 0; transform: translateX(3px); }
}

@keyframes sk-mode-vs-left {
    0%, 100% { transform: translateX(-2px); }
    40% { transform: translateX(1px); }
    50% { transform: none; }
}

@keyframes sk-mode-vs-right {
    0%, 100% { transform: translateX(2px); }
    40% { transform: translateX(-1px); }
    50% { transform: none; }
}

@keyframes sk-mode-crackle {
    0% { opacity: 1; transform: none; }
    20% { opacity: 0.2; }
    35% { opacity: 1; transform: scaleX(-1); }
    55% { opacity: 0.4; }
    70% { opacity: 1; transform: none; }
    85% { opacity: 0; }
}

@keyframes sk-mode-coil-glow {
    0%, 35%, 70% { opacity: 0.22; }
    20%, 55%, 85% { opacity: 0; }
}

@keyframes sk-mode-torus {
    0%, 35%, 70% { filter: brightness(1.6); }
    20%, 55%, 85% { filter: none; }
}

/* ---- Hub motion ---- */

@keyframes ah-in {
    from { opacity: 0; transform: translateY(10px) scale(0.98); }
    to { opacity: 1; transform: none; }
}

@keyframes ah-tile-in {
    from { opacity: 0; transform: translateY(14px) scale(0.92); }
    to { opacity: 1; transform: none; }
}

@keyframes ah-fight-pulse {
    0%, 100% { scale: 1; }
    50% { scale: 1.04; }
}

@keyframes ah-shine {
    0%, 55% { left: -40%; }
    85%, 100% { left: 120%; }
}

@keyframes ah-flicker {
    0%, 100% { transform: scale(1) rotate(0); }
    30% { transform: scale(1.08, 0.95) rotate(-3deg); }
    60% { transform: scale(0.96, 1.06) rotate(2deg); }
}

@keyframes ah-live {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

/* A short screen (a small phone, or landscape) squeezes the tiles and the button first */
@media (max-height: 700px) {
    .ah-tile { min-height: 84px; padding-top: 10px; }
    .ah-tile-icon { width: 38px; height: 38px; }
    .ah-fight { height: 56px; margin-top: 8px; }
    .ah-fight-label { font-size: 26px; }
    .ah-ladder { margin-top: 8px; }
}

@media (prefers-reduced-motion: reduce) {
    .ah *, .ah, .ah *::before, .ah *::after {
        animation: none !important;
        transition: none !important;
    }
}

/* Paths positioned by their own SVG transform attribute: keep SVG's own origin so the rotation lands where drawn */
.sk-mode-icon .sk-mode-raw {
    transform-box: view-box;
    transform-origin: 0 0;
}
