* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
}

body {
    background-color: #0b0c10;
    background-image: radial-gradient(circle at 50% 0%, #1a1c2a 0%, #0b0c10 65%);
    color: #fff;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

#game-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #15161e;
    padding: 16px;
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.7);
}

/* --- Screen State Machine --- */
.screen {
    display: none;
}

.screen.active {
    display: flex;
    flex-direction: column;
}

/* --- Buttons --- */
.menu-btn {
    padding: 12px 20px;
    font-size: 0.95rem;
    font-weight: 800;
    letter-spacing: 0.5px;
    border-radius: 8px;
    border: 1px solid #2d3244;
    background: #1f222e;
    color: #fff;
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}

.menu-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}

.menu-btn.primary {
    background: linear-gradient(180deg, #f5c542, #e0a92f);
    border-color: #f5c542;
    color: #17181f;
}

.menu-btn.primary.ready {
    animation: ready-pulse 1.6s ease-in-out infinite;
}

.menu-btn.ghost {
    background: transparent;
    color: #a0a5b8;
}

.menu-btn.ghost:hover:not(:disabled) {
    color: #fff;
    border-color: #4a5164;
}

.menu-btn.disabled,
.menu-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

@keyframes ready-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(245, 197, 66, 0.45); }
    50% { box-shadow: 0 0 16px 3px rgba(245, 197, 66, 0.35); }
}

/* --- SCREEN 1: Main Menu --- */
.screen-menu {
    width: 680px;
    min-height: 400px;
    align-items: center;
    justify-content: center;
}

.menu-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.menu-logo {
    display: flex;
    gap: 10px;
    margin-bottom: 18px;
}

.logo-ball {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.1rem;
    color: #fff;
    border: 2px solid rgba(255, 255, 255, 0.35);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5);
}

.ball-neeko { background: #8a2be2; }
.ball-aatrox { background: #c0392b; }
.ball-mario { background: #e74c3c; }
.ball-sans { background: #4a69bd; }

.game-title {
    font-size: 2.6rem;
    letter-spacing: 2px;
    background: linear-gradient(180deg, #ffffff, #8f9bb3);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-align: center;
}

.game-subtitle {
    margin-top: 6px;
    color: #6b7288;
    font-size: 0.75rem;
    letter-spacing: 3px;
    text-transform: uppercase;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 26px;
    width: 320px;
}

/* --- SCREEN 2: Character & Loadout --- */
.screen-select {
    width: 680px;
}

.screen-header {
    text-align: center;
}

.screen-title {
    font-size: 1.15rem;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.screen-hint {
    margin-top: 2px;
    color: #6b7288;
    font-size: 0.72rem;
}

.section-title {
    margin: 14px 0 6px;
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: #a0a5b8;
}

.section-hint {
    color: #f5c542;
}

.card-grid {
    display: grid;
    gap: 10px;
}

.champion-grid {
    grid-template-columns: repeat(4, 1fr);
}

.item-grid {
    grid-template-columns: repeat(3, 1fr);
}

.champion-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 12px 10px;
    border-radius: 10px;
    border: 2px solid #2d3244;
    background: #1f222e;
    color: #fff;
    cursor: pointer;
    text-align: left;
    transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}

.champion-card:hover {
    transform: translateY(-3px) scale(1.02);
    border-color: #4a5164;
}

.champion-card.selected {
    transform: translateY(-3px) scale(1.02);
    border-color: #f5c542;
    box-shadow: 0 0 0 1px rgba(245, 197, 66, 0.4), 0 0 20px rgba(245, 197, 66, 0.35);
}

.card-avatar {
    position: relative;
    overflow: hidden;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.15rem;
    color: #fff;
    border: 2px solid rgba(255, 255, 255, 0.35);
}

/* The sprite of the champion. It covers the initial of the ring, the
   initial stays visible when the sprite is missing or broken. */
.avatar-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    z-index: 1;
    pointer-events: none;
}

.avatar-letter {
    position: relative;
    line-height: 1;
}

.card-name {
    font-weight: 800;
    font-size: 0.88rem;
    letter-spacing: 0.5px;
}

.card-title {
    font-size: 0.6rem;
    font-style: italic;
    color: #6b7288;
}

.card-stats {
    display: flex;
    gap: 8px;
    margin-top: 3px;
    font-family: monospace;
    font-size: 0.58rem;
    color: #8b91a5;
}

.card-stats b {
    color: #f5c542;
    margin-right: 2px;
}

.card-kit {
    display: flex;
    flex-direction: column;
    gap: 5px;
    width: 100%;
    margin-top: 7px;
    padding-top: 7px;
    border-top: 1px solid #2d3244;
}

.kit-row {
    display: flex;
    gap: 5px;
    align-items: flex-start;
    font-size: 0.57rem;
    line-height: 1.35;
    color: #9aa0b4;
}

.kit-tag {
    flex-shrink: 0;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 0.48rem;
    font-weight: 800;
    letter-spacing: 0.5px;
}

.kit-tag.passive {
    background: rgba(138, 43, 226, 0.25);
    color: #c39cf0;
}

.kit-tag.skill {
    background: rgba(245, 197, 66, 0.18);
    color: #f5c542;
}

.kit-text b {
    color: #fff;
}

.item-card {
    padding: 9px 11px;
    border-radius: 8px;
    border: 2px solid #2d3244;
    background: #1f222e;
    color: #fff;
    cursor: pointer;
    text-align: left;
    transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
}

.item-card:hover:not(:disabled) {
    transform: translateY(-2px) scale(1.03);
    border-color: #4a5164;
}

.item-card.selected {
    border-color: #f5c542;
    box-shadow: 0 0 16px rgba(245, 197, 66, 0.3);
    transform: translateY(-2px) scale(1.02);
}

.item-card.locked {
    opacity: 0.35;
    cursor: not-allowed;
}

.item-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.item-name {
    font-size: 0.76rem;
    font-weight: 800;
}

.item-role {
    flex-shrink: 0;
    padding: 1px 5px;
    border-radius: 3px;
    background: rgba(245, 197, 66, 0.16);
    border: 1px solid rgba(245, 197, 66, 0.4);
    color: #f5c542;
    font-size: 0.46rem;
    font-weight: 800;
    letter-spacing: 0.5px;
}

.item-desc {
    margin-top: 2px;
    font-size: 0.63rem;
    color: #8b91a5;
}

.select-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 14px;
}

.cpu-preview {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px dashed #3a4054;
    background: #1a1c26;
}

.cpu-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    background: #2d3244;
    color: #7b8196;
}

.cpu-text {
    display: flex;
    flex-direction: column;
}

.cpu-name {
    font-size: 0.8rem;
    font-weight: 800;
}

.cpu-note {
    font-size: 0.62rem;
    color: #6b7288;
}

.select-actions {
    display: flex;
    gap: 10px;
}

/* --- SCREEN 3: Battle --- */
.screen-battle {
    width: 680px;
}

#hud {
    display: flex;
    width: 680px;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.fighter-card {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1 1 0;
    max-width: 360px;
    background: #1f222e;
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid #2d3244;
}

.avatar-ring {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #555;
    flex-shrink: 0;
}

.avatar-icon {
    position: relative;
    overflow: hidden;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.2rem;
    background: #555;
}

.fighter-info {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.name-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.hp-text {
    font-family: monospace;
    color: #a0a5b8;
}

.bar-container {
    width: 100%;
    height: 12px;
    background: #0d0e12;
    border-radius: 6px;
    overflow: hidden;
}

.hp-bar {
    height: 100%;
    transition: width 0.15s ease-out;
    background: linear-gradient(90deg, #666, #999);
}

.status-row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.72rem;
    color: #7b8196;
}

.status {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.champion-title {
    font-size: 0.65rem;
    color: #565c6e;
    letter-spacing: 0.4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.item-badge {
    padding: 2px 6px;
    border-radius: 999px;
    background: rgba(245, 197, 66, 0.14);
    border: 1px solid rgba(245, 197, 66, 0.45);
    color: #f5c542;
    font-size: 0.56rem;
    font-weight: 800;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

#match-timer {
    font-weight: 900;
    font-size: 1.4rem;
    color: #4f566b;
}

/* --- Arena Canvas --- */
#canvas-wrapper {
    position: relative;
    width: 680px;
    height: 400px;
}

canvas {
    background: #111218;
    border: 2px solid #2d3244;
    border-radius: 8px;
    display: block;
}

.surrender-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 5px 10px;
    font-size: 0.64rem;
    font-weight: 700;
    color: #b9bece;
    background: rgba(13, 14, 18, 0.78);
    border: 1px solid #3a4054;
    border-radius: 6px;
    cursor: pointer;
    transition: color 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}

.surrender-btn:hover {
    color: #fff;
    background: rgba(192, 57, 43, 0.85);
    border-color: #c0392b;
}

/* The sound toggle of the battle screen */
.sound-btn {
    position: absolute;
    top: 8px;
    left: 8px;
    padding: 5px 10px;
    font-size: 0.64rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: #b9bece;
    background: rgba(13, 14, 18, 0.78);
    border: 1px solid #3a4054;
    border-radius: 6px;
    cursor: pointer;
    transition: color 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}
.sound-btn:hover {
    color: #fff;
    background: rgba(245, 197, 66, 0.85);
    border-color: #f5c542;
}
.sound-btn.muted {
    color: #6b7280;
    border-color: #2d3244;
}

/* --- Match Results Modal --- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(8, 9, 13, 0.82);
}

.modal.hidden {
    display: none !important;
}

.modal-card {
    width: 380px;
    padding: 26px 24px 22px;
    border-radius: 12px;
    background: #1f222e;
    border: 1px solid #2d3244;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
    animation: modal-pop 0.22s ease-out;
}

@keyframes modal-pop {
    from { transform: scale(0.92) translateY(8px); opacity: 0; }
    to { transform: scale(1) translateY(0); opacity: 1; }
}

.modal-card h1 {
    font-size: 2rem;
    letter-spacing: 2px;
    color: #f5c542;
}

.modal-card h1.defeat {
    color: #ff6b6b;
}

.modal-subtitle {
    margin-top: 4px;
    color: #8b91a5;
    font-size: 0.78rem;
}

.result-stats {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 18px 0;
}

.result-stat {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    border-radius: 6px;
    background: #15161e;
    font-size: 0.78rem;
}

.rs-label {
    color: #8b91a5;
}

.rs-value {
    font-family: monospace;
    font-weight: 800;
}

.modal-actions {
    display: flex;
    gap: 10px;
}

.modal-actions .menu-btn {
    flex: 1;
}

/* --- SCREEN 3: Multiplayer lobby --- */
.hidden {
    display: none !important;
}

.screen-lobby {
    width: 680px;
    min-height: 400px;
    padding: 18px 0;
    gap: 18px;
}

.lobby-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 20px;
    border-radius: 12px;
    background: #1a1c26;
    border: 1px solid #2d3244;
}

.lobby-join {
    display: flex;
    gap: 10px;
    align-items: center;
}

.lobby-input {
    min-width: 140px;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid #2d3244;
    background: #15161e;
    color: #fff;
    font-family: monospace;
    font-size: 0.95rem;
    letter-spacing: 2px;
    text-align: center;
}

.lobby-input:focus {
    outline: none;
    border-color: #f5c542;
}

.lobby-status {
    min-height: 1.2em;
    color: #8b91a5;
    font-size: 0.85rem;
    text-align: center;
}

.lobby-code-line {
    font-size: 1rem;
    color: #a0a5b8;
    margin: 0;
}

.lobby-code-line strong {
    color: #f5c542;
    font-family: monospace;
    font-size: 1.35rem;
    letter-spacing: 3px;
}

.lobby-side {
    margin: 0;
    color: #8b91a5;
    font-size: 0.85rem;
}

.lobby-loadout {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
}

.lobby-label {
    font-size: 0.75rem;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: #8b91a5;
}

.lobby-items {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

.lobby-item {
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid #2d3244;
    background: #15161e;
    color: #a0a5b8;
    cursor: pointer;
    font-size: 0.82rem;
}

.lobby-item.selected {
    border-color: #f5c542;
    color: #f5c542;
    background: rgba(245, 197, 66, 0.1);
}

.lobby-actions {
    display: flex;
    gap: 10px;
}
